Skip to main content

copy_into

Function copy_into 

Source
pub fn copy_into<T: Copy + Send + Sync + 'static>(
    dest: &mut StridedViewMut<'_, T>,
    src: &StridedView<'_, T>,
    exec: Exec<'_>,
) -> Result<()>
Expand description

Copy elements from source to destination: dest[i] = src[i].

Uses HPTT-inspired blocked permutation with bilateral dimension fusion, cache-aware blocking, and optimal loop ordering. The permutation is split across the budget of exec, at the width the token’s dispatch cost justifies for the copy (copy_ns_per_element times its elements); a small copy stays on the calling thread. A caller that wants a large copy on one thread passes [Exec::serial] or narrows the token with [Exec::limit]. A contiguous copy uses one memcpy per range of the narrowed token, or a single memcpy on the calling thread when that token is serial.

This is a plain copy: no element operation is applied. For a conjugation on the same engine use copy_conj_into; for other element operations (transpose, scale, …) use the strided_kernel element-map entries.

§Errors

Returns [StridedError::RankMismatch] or [StridedError::ShapeMismatch] when the views describe different extents, [StridedError::OffsetOverflow] when the layout cannot be expressed in isize stride arithmetic or a fused extent overflows, and [StridedError::NonInjectiveOutputLayout] when two destination elements map onto the same memory offset, or the layout span is not representable. Nothing is written unless validation succeeds.

§Examples

use threadteam::Exec;
use strided_perm::copy_into;
use strided_view::StridedArray;

let src = StridedArray::<f64>::from_fn_col_major(&[2, 3], |idx| (idx[0] * 10 + idx[1]) as f64);
let mut dst = StridedArray::<f64>::col_major(&[2, 3]);
copy_into(&mut dst.view_mut(), &src.view(), Exec::serial()).unwrap();
assert_eq!(dst.get(&[1, 2]), 12.0);