pub struct CopyPlan { /* private fields */ }Expand description
A compiled copy traversal for one (dims, dst_strides, src_strides)
layout pair.
compile proves the layout facts once (rank agreement, extent overflow,
destination injectivity) and fuses/orders the loop nest; each execute*
call then only re-checks the per-call facts (that the supplied views carry
exactly the compiled layout) and selects the cache blocks for its element
type before replaying the prepared loops. The order in which elements are
visited is unspecified.
Overlapping src/dest memory is not supported, matching the rest of the
crate.
Ranks above RAW_FUSED_RANK_LIMIT are supported by the same fused
traversal, which then stores its axes in one rank-bounded allocation.
§Example
use strided_basic::{CopyPlan, Exec, RawStridedMut, RawStridedRef};
let dims = [2usize, 3];
let src_strides = [3isize, 1];
let dst_strides = [1isize, 2]; // transposed destination
let plan = CopyPlan::compile(&dims, &dst_strides, &src_strides).unwrap();
let src = [0.0f64, 1.0, 2.0, 10.0, 11.0, 12.0];
let mut dst = [0.0f64; 6];
let src_ref = RawStridedRef::new(&src, &dims, &src_strides, 0).unwrap();
let mut dst_mut = RawStridedMut::new(&mut dst, &dims, &dst_strides, 0).unwrap();
plan.execute(&mut dst_mut, &src_ref, Exec::serial()).unwrap();
assert_eq!(dst, [0.0, 10.0, 1.0, 11.0, 2.0, 12.0]);Implementations§
Source§impl CopyPlan
impl CopyPlan
Sourcepub fn compile(
dims: &[usize],
dst_strides: &[isize],
src_strides: &[isize],
) -> Result<Self>
pub fn compile( dims: &[usize], dst_strides: &[isize], src_strides: &[isize], ) -> Result<Self>
Compile a copy plan for the given layout pair.
Performs the layout validation and traversal construction (fuse + order) once.
§Errors
Returns StridedError::StrideLengthMismatch when dims,
dst_strides, and src_strides do not all have the same length,
StridedError::OffsetOverflow when the total element count does not
fit usize, and StridedError::NonInjectiveOutputLayout when the
destination layout cannot be proven injective (aliasing elements, or a
span the check cannot represent).
Sourcepub fn execute_uninit<T>(
&self,
dest: &mut RawStridedMut<'_, MaybeUninit<T>>,
src: &RawStridedRef<'_, T>,
exec: Exec<'_>,
) -> Result<()>
pub fn execute_uninit<T>( &self, dest: &mut RawStridedMut<'_, MaybeUninit<T>>, src: &RawStridedRef<'_, T>, exec: Exec<'_>, ) -> Result<()>
dest = src into a potentially uninitialized destination.
On success every reachable logical destination element is initialized. Non-reachable holes in the backing allocation are not written.
§Errors
Returns StridedError::PlanLayoutMismatch when the views do not
carry the compiled layout, before any write.
Sourcepub fn execute<T>(
&self,
dest: &mut RawStridedMut<'_, T>,
src: &RawStridedRef<'_, T>,
exec: Exec<'_>,
) -> Result<()>
pub fn execute<T>( &self, dest: &mut RawStridedMut<'_, T>, src: &RawStridedRef<'_, T>, exec: Exec<'_>, ) -> Result<()>
dest = src. Allocation-free for fused ranks at most
RAW_FUSED_RANK_LIMIT.
§Errors
Returns StridedError::PlanLayoutMismatch when the views do not
carry the compiled layout, before any write.
Sourcepub fn execute_scale<T>(
&self,
dest: &mut RawStridedMut<'_, T>,
src: &RawStridedRef<'_, T>,
scale: T,
exec: Exec<'_>,
) -> Result<()>
pub fn execute_scale<T>( &self, dest: &mut RawStridedMut<'_, T>, src: &RawStridedRef<'_, T>, scale: T, exec: Exec<'_>, ) -> Result<()>
dest = scale * src. Allocation-free for fused ranks at most
RAW_FUSED_RANK_LIMIT.
§Errors
Returns StridedError::PlanLayoutMismatch when the views do not
carry the compiled layout, before any write.
Sourcepub fn execute_conj<T>(
&self,
dest: &mut RawStridedMut<'_, T>,
src: &RawStridedRef<'_, T>,
exec: Exec<'_>,
) -> Result<()>
pub fn execute_conj<T>( &self, dest: &mut RawStridedMut<'_, T>, src: &RawStridedRef<'_, T>, exec: Exec<'_>, ) -> Result<()>
dest = conj(src). Allocation-free for fused ranks at most
RAW_FUSED_RANK_LIMIT.
§Errors
Returns StridedError::PlanLayoutMismatch when the views do not
carry the compiled layout, before any write.