Macro extendr_api::prelude::unzipped
macro_rules! unzipped { ($head: pat $(,)?) => { ... }; ($head: pat, $($tail: pat),* $(,)?) => { ... }; }
Expand description
Used to undo the zipping by the zipped!
macro.
ยง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));
}
}