Macro extendr_api::prelude::zipped

macro_rules! zipped {
    ($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, unzipped, 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(|unzipped!(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));
    }
}