Struct ErasedRawStridedRef
pub struct ErasedRawStridedRef<'a> { /* private fields */ }Expand description
Borrowed dtype-erased raw strided input layout.
dims, strides, and offset are expressed in dtype elements, not bytes.
Implementations§
§impl<'a> ErasedRawStridedRef<'a>
impl<'a> ErasedRawStridedRef<'a>
pub fn from_slice<T>(
data: &'a [T],
dims: &'a [usize],
strides: &'a [isize],
offset: isize,
) -> Result<ErasedRawStridedRef<'a>, StridedError>where
T: KernelStorageElement,
pub fn from_slice<T>(
data: &'a [T],
dims: &'a [usize],
strides: &'a [isize],
offset: isize,
) -> Result<ErasedRawStridedRef<'a>, StridedError>where
T: KernelStorageElement,
Create an erased input 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 &[T].
pub unsafe fn from_raw_parts(
dtype: KernelDType,
data: NonNull<u8>,
byte_len: usize,
dims: &'a [usize],
strides: &'a [isize],
offset: isize,
) -> Result<ErasedRawStridedRef<'a>, StridedError>
pub unsafe fn from_raw_parts( dtype: KernelDType, data: NonNull<u8>, byte_len: usize, dims: &'a [usize], strides: &'a [isize], offset: isize, ) -> Result<ErasedRawStridedRef<'a>, StridedError>
Construct from erased storage.
§Safety
data must be the start of an allocation aligned for dtype; the
allocation must contain byte_len initialized, readable bytes for
'a, and every byte extent must represent valid values for dtype.
The allocation and metadata must outlive 'a; no mutable alias may
exist while this descriptor is used. Alignment is an allocation
property and must not be inferred from the observed address alone.
§Errors
Returns StridedError::ByteLengthMismatch when byte_len is not
a whole number of dtype elements, and
StridedError::DataAlignmentMismatch when data is
not aligned for dtype. 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.
Bool bytes are the caller’s responsibility here, per the safety
contract.
pub fn data_as<T>(&self) -> Result<&[T], StridedError>where
T: KernelStorageElement,
pub fn data_as<T>(&self) -> Result<&[T], StridedError>where
T: KernelStorageElement,
Borrow the initialized storage as its concrete scalar type.
§Errors
Returns StridedError::DTypeMismatch when T is not the
descriptor’s dtype.
pub fn dtype(&self) -> KernelDType
pub fn dims(&self) -> &'a [usize]
pub fn strides(&self) -> &'a [isize]
pub fn offset(&self) -> isize
Trait Implementations§
§impl<'a> Clone for ErasedRawStridedRef<'a>
impl<'a> Clone for ErasedRawStridedRef<'a>
§fn clone(&self) -> ErasedRawStridedRef<'a>
fn clone(&self) -> ErasedRawStridedRef<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<'a> Copy for ErasedRawStridedRef<'a>
Auto Trait Implementations§
impl<'a> Freeze for ErasedRawStridedRef<'a>
impl<'a> RefUnwindSafe for ErasedRawStridedRef<'a>
impl<'a> Send for ErasedRawStridedRef<'a>
impl<'a> Sync for ErasedRawStridedRef<'a>
impl<'a> Unpin for ErasedRawStridedRef<'a>
impl<'a> UnsafeUnpin for ErasedRawStridedRef<'a>
impl<'a> UnwindSafe for ErasedRawStridedRef<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more