Skip to main content

replay_map_raw_fused

Function replay_map_raw_fused 

Source
pub fn replay_map_raw_fused<D, S, F>(
    dest: &mut RawStridedMut<'_, D>,
    src: &RawStridedRef<'_, S>,
    f: F,
    exec: Exec<'_>,
) -> Result<()>
where D: Copy + Send + Sync, S: Copy + Send + Sync, F: Fn(&mut D, S) + Send + Sync,
Expand description

f(&mut dest[i], src[i]) after fusing the two layouts inside the call.

replay_map_raw replays the axes exactly as given, so a caller that holds an unfused layout has to fuse it first and pays that pass per call. This entry performs the same fusion copy_scale_raw does before choosing the route, then replays with the caller’s token; the small-block fusion cost is therefore inside the crate, once, instead of at every call site.

The traversal, width, callback and allocation contracts are those of replay_map_raw: the visit order is unspecified, and a successful call allocates nothing at any rank on a serial token, or on a pooled token whose replay is not tiled above RAW_FUSED_RANK_LIMIT moving axes. The fusion itself holds its scratch on the stack, so it does not allocate either.

§Errors

As replay_map_raw.

§Examples

use strided_basic::{replay_map_raw_fused, Exec, RawStridedMut, RawStridedRef};

let src = [1.0f64, 2.0, 3.0, 4.0];
let mut acc = [10.0f64, 20.0, 30.0, 40.0];
let source = RawStridedRef::new(&src, &[2, 2], &[2, 1], 0).unwrap();
// The destination is transposed relative to the source; the fused entry
// fuses the two layouts before it walks them.
let mut dst = RawStridedMut::new(&mut acc, &[2, 2], &[1, 2], 0).unwrap();
replay_map_raw_fused(&mut dst, &source, |d, s| *d += s, Exec::serial()).unwrap();
assert_eq!(acc, [11.0, 23.0, 32.0, 44.0]);