Skip to main content

zip_update2_into

Function zip_update2_into 

Source
pub fn zip_update2_into<D, A, OpD, OpA>(
    dest: &mut StridedViewMut<'_, D>,
    a: &StridedView<'_, A, OpA>,
    f: impl Fn(D, A) -> D + MaybeSync,
) -> Result<(), StridedError>
where D: Copy + MaybeSendSync, A: Copy + MaybeSendSync, OpD: ElementOp<D>, OpA: ElementOp<A>,
Expand description

Update in place from one input: dest[i] = f(OpD(dest[i]), OpA(a[i])).

§Errors

StridedError::ShapeMismatch for unequal shapes and StridedError::NonInjectiveOutputLayout, both before any write.

§Examples

use strided_basic::{zip_update2_into, Identity, StridedArray};
let a = StridedArray::<f64>::from_fn_col_major(&[3], |i| i[0] as f64);
let mut d = StridedArray::<f64>::from_fn_col_major(&[3], |_| 10.0);
// d = 2 * a + 0.5 * d
zip_update2_into::<_, _, Identity, Identity>(&mut d.view_mut(), &a.view(), |d, a| {
    2.0 * a + 0.5 * d
})
.unwrap();
assert_eq!(d.get(&[2]), 9.0);