zip

Macro zip 

Source
macro_rules! zip {
    ($head: expr $(,)?) => { ... };
    ($head: expr, $($tail: expr),* $(,)?) => { ... };
}
Expand description

zips together matrix of the same size, so that coefficient-wise operations can be performed on their elements.

§note

the order in which the matrix elements are traversed is unspecified.

§example

use faer::{Mat, mat, unzip, zip};

let nrows = 2;
let ncols = 3;

let a = mat![[1.0, 3.0, 5.0], [2.0, 4.0, 6.0]];
let b = mat![[7.0, 9.0, 11.0], [8.0, 10.0, 12.0]];
let mut sum = Mat::<f64>::zeros(nrows, ncols);

zip!(&mut sum, &a, &b).for_each(|unzip!(sum, a, b)| {
	*sum = a + b;
});

for i in 0..nrows {
	for j in 0..ncols {
		assert_eq!(sum[(i, j)], a[(i, j)] + b[(i, j)]);
	}
}