Macro faer_core::zipped

source ·
macro_rules! zipped {
    ($first: expr $(, $rest: 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_core::{mat, zipped, Mat};

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);

zipped!(sum.as_mut(), a.as_ref(), b.as_ref()).for_each(|mut sum, a, b| {
    let a = a.read();
    let b = b.read();
    sum.write(a + b);
});

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