pub struct ErasedRawStridedMut<'a> { /* private fields */ }Expand description
Borrowed dtype-erased raw strided output layout.
dims, strides, and offset are expressed in dtype elements, not bytes.
Implementations§
Source§impl<'a> ErasedRawStridedMut<'a>
impl<'a> ErasedRawStridedMut<'a>
Sourcepub fn from_slice_mut<T: KernelStorageElement>(
data: &'a mut [T],
dims: &'a [usize],
strides: &'a [isize],
offset: isize,
) -> Result<Self>
pub fn from_slice_mut<T: KernelStorageElement>( data: &'a mut [T], dims: &'a [usize], strides: &'a [isize], offset: isize, ) -> Result<Self>
Create an erased output descriptor from typed, initialized storage.
§Errors
Returns StridedError::StrideLengthMismatch when dims and
strides have different lengths, and
StridedError::OffsetOverflow when a reachable offset is not
representable: dim - 1 of a non-unit extent does not fit isize, a
stride times that last index or the accumulated offsets overflow
isize or go negative, or the highest reachable offset is not below
the buffer length. A layout with a zero extent skips this check. The
byte-length and alignment checks
cannot fail for a typed &mut [T].
Sourcepub unsafe fn from_raw_parts(
dtype: KernelDType,
data: NonNull<u8>,
byte_len: usize,
dims: &'a [usize],
strides: &'a [isize],
offset: isize,
) -> Result<Self>
pub unsafe fn from_raw_parts( dtype: KernelDType, data: NonNull<u8>, byte_len: usize, dims: &'a [usize], strides: &'a [isize], offset: isize, ) -> Result<Self>
Construct from erased storage.
§Safety
data..data + byte_len must be an aligned, writable allocation valid
for 'a, with valid initialized values for dtype throughout the
complete byte extent; its provenance, extent, lifetime, and exclusive
aliasing must be upheld by the caller.
The alignment requirement is on the allocation, not merely the observed
address. The caller must retain exclusive access: no mutable alias or
concurrent mutation may exist while this descriptor is used.
§Errors
Returns StridedError::ByteLengthMismatch when byte_len is not
a whole number of dtype elements, and
StridedError::DataAlignmentMismatch when a non-empty data is
not aligned for dtype. Returns
StridedError::InvalidBoolByte when dtype is Bool and a byte
of the extent is neither 0 nor 1. Returns
StridedError::StrideLengthMismatch when dims and strides
have different lengths, and StridedError::OffsetOverflow when
a reachable offset is not representable: dim - 1 of a non-unit
extent does not fit isize, a stride times that last index or the
accumulated offsets overflow isize or go negative, or the highest
reachable offset is not below the storage length. A layout with a zero
extent skips this check.
Sourcepub fn data_as<T: KernelStorageElement>(&self) -> Result<&[T]>
pub fn data_as<T: KernelStorageElement>(&self) -> Result<&[T]>
Borrow initialized storage as its concrete scalar type.
§Errors
Returns StridedError::DTypeMismatch when T is not the
descriptor’s dtype.
Sourcepub fn data_as_mut<T: KernelStorageElement>(&mut self) -> Result<&mut [T]>
pub fn data_as_mut<T: KernelStorageElement>(&mut self) -> Result<&mut [T]>
Borrow initialized storage mutably as its concrete scalar type.
§Errors
Returns StridedError::DTypeMismatch when T is not the
descriptor’s dtype.