pub struct VectorSpan<'a, T: StorageElement> { /* private fields */ }Expand description
Mutable, possibly strided, non-owning view into a vector.
Implementations§
Source§impl<'a, T: StorageElement> VectorSpan<'a, T>
impl<'a, T: StorageElement> VectorSpan<'a, T>
Sourcepub unsafe fn from_raw_parts(
data: *mut T,
dims: usize,
stride_bytes: isize,
) -> Self
pub unsafe fn from_raw_parts( data: *mut T, dims: usize, stride_bytes: isize, ) -> Self
Create a mutable view from a raw pointer, dimension count, and byte stride.
§Safety
datamust be valid for reads and writes ofdimselements at the given stride.- The pointed-to memory must outlive
'a. stride_bytesmust be non-zero for non-empty views.- No other references to the memory may exist for the duration of
'a.
Sourcepub fn stride_bytes(&self) -> isize
pub fn stride_bytes(&self) -> isize
Stride in bytes.
Sourcepub fn is_contiguous(&self) -> bool
pub fn is_contiguous(&self) -> bool
Returns true if contiguous.
Sourcepub fn as_mut_ptr(&mut self) -> *mut T
pub fn as_mut_ptr(&mut self) -> *mut T
Get the mutable underlying pointer.
Sourcepub fn as_view(&self) -> VectorView<'_, T>
pub fn as_view(&self) -> VectorView<'_, T>
Reborrow as an immutable view, sharing the same data pointer and stride.
Sourcepub fn try_get<I: VectorIndex>(
&self,
idx: I,
) -> Result<T::DimScalar, TensorError>where
T: FloatConvertible,
pub fn try_get<I: VectorIndex>(
&self,
idx: I,
) -> Result<T::DimScalar, TensorError>where
T: FloatConvertible,
Try to get element at index.
Sourcepub fn try_set<I: VectorIndex>(
&mut self,
idx: I,
val: T::DimScalar,
) -> Result<(), TensorError>where
T: FloatConvertible,
pub fn try_set<I: VectorIndex>(
&mut self,
idx: I,
val: T::DimScalar,
) -> Result<(), TensorError>where
T: FloatConvertible,
Try to set the element at idx.
Accepts the native DimScalar type. For sub-byte types, uses value_index
for stride-based pointer walks to avoid buffer overwrite.
Sourcepub fn fill(&mut self, val: T)
pub fn fill(&mut self, val: T)
Fill all elements with a value, respecting the stride between elements.
Iterates over storage values (not logical dimensions) to avoid buffer overwrite for sub-byte types.
Sourcepub fn as_contiguous_slice(&self) -> Option<&[T]>
pub fn as_contiguous_slice(&self) -> Option<&[T]>
Get a contiguous slice, if this span is contiguous.
Sourcepub fn as_contiguous_slice_mut(&mut self) -> Option<&mut [T]>
pub fn as_contiguous_slice_mut(&mut self) -> Option<&mut [T]>
Get a mutable contiguous slice, if this span is contiguous.
Sourcepub fn iter(&self) -> VectorViewIterator<'_, T> ⓘwhere
T: FloatConvertible,
pub fn iter(&self) -> VectorViewIterator<'_, T> ⓘwhere
T: FloatConvertible,
Returns an iterator over logical dimension values, yielding DimRef proxies.
Sourcepub fn iter_mut(&mut self) -> VectorSpanIterator<'_, T> ⓘwhere
T: FloatConvertible,
pub fn iter_mut(&mut self) -> VectorSpanIterator<'_, T> ⓘwhere
T: FloatConvertible,
Returns a mutable iterator over logical dimension values, yielding DimMut proxies.