pub fn eye_array<T>(
n: usize,
format: &str,
) -> SparseResult<Box<dyn SparseArray<T>>>
Expand description
Creates a sparse identity array of size n x n
§Arguments
n
- Size of the square arrayformat
- Format of the output array (“csr” or “coo”)
§Returns
A sparse array representing the identity matrix
§Examples
use scirs2_sparse::construct::eye_array;
let eye: Box<dyn scirs2_sparse::SparseArray<f64>> = eye_array(3, "csr").unwrap();
assert_eq!(eye.shape(), (3, 3));
assert_eq!(eye.nnz(), 3);
assert_eq!(eye.get(0, 0), 1.0);
assert_eq!(eye.get(1, 1), 1.0);
assert_eq!(eye.get(2, 2), 1.0);
assert_eq!(eye.get(0, 1), 0.0);