Skip to main content

map_raw_into_validated

Function map_raw_into_validated 

Source
pub unsafe fn map_raw_into_validated<D, A, Op>(
    dest: &mut RawStridedMut<'_, D>,
    src: &RawStridedRef<'_, A>,
    f: impl Fn(A) -> D + MaybeSync,
    validated: ValidatedDestinationLayout,
) -> Result<(), StridedError>
where D: Copy + MaybeSendSync, A: Copy + MaybeSendSync, Op: ElementOp<A>,
Expand description

Prevalidated map raw into validated for kernel-family implementations.

§Safety

All input shapes must match the destination. validated must have been obtained for this destination’s current geometry, proving injectivity; possessing a marker from another layout is not sufficient. View/descriptor bounds and aliasing contracts must continue to hold throughout replay.

§Examples

use strided_basic::execution::*;
// SAFETY: the example supplies matching bounded layouts and disjoint storage.
use strided_basic::{RawStridedRef, RawStridedMut, Identity};
let values = [2.0_f64; 2];
let src = RawStridedRef::new(&values, &[2], &[1], 0).unwrap();
let mut output = [0.0; 2];
let mut dst = RawStridedMut::new(&mut output, &[2], &[1], 0).unwrap();
let checked = validate_destination_layout_without_alloc(&[2], &[1]).unwrap();
unsafe { map_raw_into_validated::<f64, f64, Identity>(&mut dst, &src, |a| a, checked) }.unwrap();
assert_eq!(output, [2.0; 2]);

§Errors

Forwards errors from the owning kernel or callback; callers must still satisfy the safety contract before invoking this prevalidated entry.