pub fn bmat<'a, T>(
blocks: &[Vec<Option<&'a dyn SparseArray<T>>>],
format: &str,
) -> SparseResult<Box<dyn SparseArray<T>>>
Expand description
Construct a sparse array from sparse sub-blocks
§Arguments
blocks
- 2D array of sparse arrays or None. None entries are treated as zero blocks.format
- Format of the output array (“csr” or “coo”)
§Returns
A sparse array constructed from the given blocks
§Examples
use scirs2_sparse::construct::eye_array;
use scirs2_sparse::combine::bmat;
let a = eye_array::<f64>(2, "csr").unwrap();
let b = eye_array::<f64>(2, "csr").unwrap();
let blocks = vec![
vec![Some(&*a), Some(&*b)],
vec![None, Some(&*a)],
];
let c = bmat(&blocks, "csr").unwrap();
assert_eq!(c.shape(), (4, 4));
// Values from first block row
assert_eq!(c.get(0, 0), 1.0);
assert_eq!(c.get(1, 1), 1.0);
assert_eq!(c.get(0, 2), 1.0);
assert_eq!(c.get(1, 3), 1.0);
// Values from second block row
assert_eq!(c.get(2, 0), 0.0);
assert_eq!(c.get(2, 2), 1.0);
assert_eq!(c.get(3, 3), 1.0);