kron

Function kron 

Source
pub fn kron<'a, T>(
    a: &'a dyn SparseArray<T>,
    b: &'a dyn SparseArray<T>,
    format: &str,
) -> SparseResult<Box<dyn SparseArray<T>>>
where T: 'a + Float + Add<Output = T> + AddAssign + Sub<Output = T> + Mul<Output = T> + Div<Output = T> + Debug + Copy + 'static,
Expand description

Kronecker product of sparse arrays

Computes the Kronecker product of two sparse arrays. The Kronecker product is a non-commutative operator which is defined for arbitrary matrices of any size.

For given arrays A (m x n) and B (p x q), the Kronecker product results in an array of size (mp, nq).

§Arguments

  • a - First sparse array
  • b - Second sparse array
  • format - Format of the output array (“csr” or “coo”)

§Returns

A sparse array representing the Kronecker product A ⊗ B

§Examples

use scirs2_sparse::construct::eye_array;
use scirs2_sparse::combine::kron;

let a = eye_array::<f64>(2, "csr").unwrap();
let b = eye_array::<f64>(2, "csr").unwrap();
let c = kron(&*a, &*b, "csr").unwrap();

assert_eq!(c.shape(), (4, 4));
// Kronecker product of two identity matrices is an identity matrix of larger size
assert_eq!(c.get(0, 0), 1.0);
assert_eq!(c.get(1, 1), 1.0);
assert_eq!(c.get(2, 2), 1.0);
assert_eq!(c.get(3, 3), 1.0);