Skip to main content

map_update_into

Function map_update_into 

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

Update in place: dest[i] = f(OpD(dest[i])).

OpD is applied lazily to the old value before f sees it.

§Errors

StridedError::NonInjectiveOutputLayout when dest maps two indices to one element (checked before any write).

§Examples

use strided_basic::{map_update_into, Identity, StridedArray};
let mut d = StridedArray::<f64>::from_fn_col_major(&[2, 2], |i| (i[0] + 2 * i[1]) as f64);
map_update_into::<_, Identity>(&mut d.view_mut(), |x| 2.0 * x + 1.0).unwrap();
assert_eq!(d.get(&[1, 1]), 7.0);