pub fn kronsum<'a, T>(
a: &'a dyn SparseArray<T>,
b: &'a dyn SparseArray<T>,
format: &str,
) -> SparseResult<Box<dyn SparseArray<T>>>
Expand description
Kronecker sum of square sparse arrays
Computes the Kronecker sum of two square sparse arrays. The Kronecker sum of two matrices A and B is the sum of the two Kronecker products: kron(I_n, A) + kron(B, I_m) where A has shape (m,m), B has shape (n,n), and I_m and I_n are identity matrices of shape (m,m) and (n,n), respectively.
The resulting array has shape (mn, mn).
§Arguments
a
- First square sparse arrayb
- Second square sparse arrayformat
- Format of the output array (“csr” or “coo”)
§Returns
A sparse array representing the Kronecker sum of A and B
§Examples
use scirs2_sparse::construct::eye_array;
use scirs2_sparse::combine::kronsum;
let a = eye_array::<f64>(2, "csr").unwrap();
let b = eye_array::<f64>(2, "csr").unwrap();
let c = kronsum(&*a, &*b, "csr").unwrap();
// Verify the shape of Kronecker sum
assert_eq!(c.shape(), (4, 4));
// Verify there is a non-zero element by checking the number of non-zeros
let (rows, cols, data) = c.find();
assert!(rows.len() > 0);
assert!(cols.len() > 0);
assert!(data.len() > 0);