pub struct TensorSpan<'a, T, const MAX_RANK: usize = DEFAULT_MAX_RANK> { /* private fields */ }Expand description
A mutable view into a Tensor.
Implementations§
Source§impl<'a, T, const MAX_RANK: usize> TensorSpan<'a, T, MAX_RANK>
impl<'a, T, const MAX_RANK: usize> TensorSpan<'a, T, MAX_RANK>
Sourcepub unsafe fn from_raw_parts(
data: *mut T,
shape: &[usize],
strides_bytes: &[isize],
) -> Self
pub unsafe fn from_raw_parts( data: *mut T, shape: &[usize], strides_bytes: &[isize], ) -> Self
Create a mutable view from a raw pointer, shape, and byte strides.
§Safety
datamust be valid for reads and writes over the region described byshapeandstrides_bytes.- The pointed-to memory must outlive
'a. shape.len()must be<= MAX_RANK.shape.len()must equalstrides_bytes.len().- No other references to the memory may exist for the duration of
'a.
§Panics
Panics if shape.len() > MAX_RANK or shape.len() != strides_bytes.len().
Sourcepub fn numel(&self) -> usize
pub fn numel(&self) -> usize
Returns the total number of logical elements (computed from shape).
Sourcepub fn stride_bytes(&self, dim: usize) -> isize
pub fn stride_bytes(&self, dim: usize) -> isize
Returns the stride in bytes for the given dimension.
Sourcepub fn as_mut_ptr(&mut self) -> *mut T
pub fn as_mut_ptr(&mut self) -> *mut T
Returns a mutable pointer to the first element.
Sourcepub fn has_contiguous_rows(&self) -> bool
pub fn has_contiguous_rows(&self) -> bool
Check if the view has contiguous rows.
Sourcepub fn is_contiguous(&self) -> bool
pub fn is_contiguous(&self) -> bool
Check if the entire view is contiguous in memory.
Sourcepub fn as_view(&self) -> TensorView<'_, T, MAX_RANK>
pub fn as_view(&self) -> TensorView<'_, T, MAX_RANK>
Reborrow as immutable view.
Sourcepub fn try_flat<I: VectorIndex>(&self, index: I) -> Result<&T, TensorError>
pub fn try_flat<I: VectorIndex>(&self, index: I) -> Result<&T, TensorError>
Try to get an element by flat logical row-major index.
Sourcepub fn try_flat_mut<I: VectorIndex>(
&mut self,
index: I,
) -> Result<&mut T, TensorError>
pub fn try_flat_mut<I: VectorIndex>( &mut self, index: I, ) -> Result<&mut T, TensorError>
Try to get a mutable element by flat logical row-major index.
Sourcepub fn try_coords<C: TensorCoordinates>(
&self,
coords: C,
) -> Result<&T, TensorError>
pub fn try_coords<C: TensorCoordinates>( &self, coords: C, ) -> Result<&T, TensorError>
Try to get an element by exact coordinates.
Sourcepub fn try_coords_mut<C: TensorCoordinates>(
&mut self,
coords: C,
) -> Result<&mut T, TensorError>
pub fn try_coords_mut<C: TensorCoordinates>( &mut self, coords: C, ) -> Result<&mut T, TensorError>
Try to get a mutable element by exact coordinates.
Sourcepub fn try_scalar(&self) -> Result<&T, TensorError>
pub fn try_scalar(&self) -> Result<&T, TensorError>
Try to access the scalar value of a rank-0 tensor span.
Sourcepub fn try_scalar_mut(&mut self) -> Result<&mut T, TensorError>
pub fn try_scalar_mut(&mut self) -> Result<&mut T, TensorError>
Try to access the mutable scalar value of a rank-0 tensor span.
Sourcepub fn slice_leading<I: VectorIndex>(
&self,
index: I,
) -> Result<TensorView<'_, T, MAX_RANK>, TensorError>
pub fn slice_leading<I: VectorIndex>( &self, index: I, ) -> Result<TensorView<'_, T, MAX_RANK>, TensorError>
Slice the leading axis by one index, reducing rank by one.
Sourcepub fn slice_leading_mut<I: VectorIndex>(
&mut self,
index: I,
) -> Result<TensorSpan<'_, T, MAX_RANK>, TensorError>
pub fn slice_leading_mut<I: VectorIndex>( &mut self, index: I, ) -> Result<TensorSpan<'_, T, MAX_RANK>, TensorError>
Slice the leading axis mutably by one index, reducing rank by one.
Sourcepub fn slice(
&self,
spec: impl SliceSpec,
) -> Result<TensorView<'_, T, MAX_RANK>, TensorError>
pub fn slice( &self, spec: impl SliceSpec, ) -> Result<TensorView<'_, T, MAX_RANK>, TensorError>
Slice the span along multiple dimensions.
Accepts tuples of Rust range types or &[SliceRange].
Sourcepub fn slice_mut(
&mut self,
spec: impl SliceSpec,
) -> Result<TensorSpan<'_, T, MAX_RANK>, TensorError>
pub fn slice_mut( &mut self, spec: impl SliceSpec, ) -> Result<TensorSpan<'_, T, MAX_RANK>, TensorError>
Slice the span mutably along multiple dimensions.
Accepts tuples of Rust range types or &[SliceRange].
Source§impl<'a, T: StorageElement, const MAX_RANK: usize> TensorSpan<'a, T, MAX_RANK>
impl<'a, T: StorageElement, const MAX_RANK: usize> TensorSpan<'a, T, MAX_RANK>
Sourcepub fn storage_len(&self) -> usize
pub fn storage_len(&self) -> usize
Number of storage values (for sub-byte types, less than numel).
Sourcepub fn as_contiguous_slice(&self) -> Option<&[T]>
pub fn as_contiguous_slice(&self) -> Option<&[T]>
Convert to slice (only valid for contiguous views).
Sourcepub fn as_contiguous_slice_mut(&mut self) -> Option<&mut [T]>
pub fn as_contiguous_slice_mut(&mut self) -> Option<&mut [T]>
Convert to mutable slice (only valid for contiguous views).
Source§impl<'a, T: StorageElement, const MAX_RANK: usize> TensorSpan<'a, T, MAX_RANK>
impl<'a, T: StorageElement, const MAX_RANK: usize> TensorSpan<'a, T, MAX_RANK>
Sourcepub fn transpose(&self) -> Result<TensorSpan<'a, T, MAX_RANK>, TensorError>
pub fn transpose(&self) -> Result<TensorSpan<'a, T, MAX_RANK>, TensorError>
Transpose (reverse all dimensions, no data copy).
Returns an error for sub-byte types with ndim >= 2.
Sourcepub fn reshape(
&self,
new_shape: &[usize],
) -> Result<TensorSpan<'a, T, MAX_RANK>, TensorError>
pub fn reshape( &self, new_shape: &[usize], ) -> Result<TensorSpan<'a, T, MAX_RANK>, TensorError>
Reshape the span (must have same total elements, contiguous only).
Returns an error for sub-byte types.
Sourcepub fn flatten(&self) -> Result<TensorSpan<'a, T, MAX_RANK>, TensorError>
pub fn flatten(&self) -> Result<TensorSpan<'a, T, MAX_RANK>, TensorError>
Flatten to 1D (requires contiguous layout).
Sourcepub fn squeeze(&self) -> TensorSpan<'a, T, MAX_RANK>
pub fn squeeze(&self) -> TensorSpan<'a, T, MAX_RANK>
Remove dimensions of size 1.
Source§impl<'a, T: Clone + StorageElement, const MAX_RANK: usize> TensorSpan<'a, T, MAX_RANK>
impl<'a, T: Clone + StorageElement, const MAX_RANK: usize> TensorSpan<'a, T, MAX_RANK>
Source§impl<'a, T, const MAX_RANK: usize> TensorSpan<'a, T, MAX_RANK>
impl<'a, T, const MAX_RANK: usize> TensorSpan<'a, T, MAX_RANK>
Sourcepub fn axis_spans<I: VectorIndex>(
&mut self,
axis: I,
) -> Result<AxisIteratorMut<'a, T, MAX_RANK>, TensorError>
pub fn axis_spans<I: VectorIndex>( &mut self, axis: I, ) -> Result<AxisIteratorMut<'a, T, MAX_RANK>, TensorError>
Iterate mutably along the given axis, yielding sub-tensor spans with rank-1.
Source§impl<'a, T: FloatConvertible, const MAX_RANK: usize> TensorSpan<'a, T, MAX_RANK>
impl<'a, T: FloatConvertible, const MAX_RANK: usize> TensorSpan<'a, T, MAX_RANK>
Sourcepub fn iter(&self) -> TensorViewIterator<'_, T, MAX_RANK> ⓘ
pub fn iter(&self) -> TensorViewIterator<'_, T, MAX_RANK> ⓘ
Returns a lazy iterator over all logical scalars in row-major order.
Yields (position, DimRef) pairs. Use .iter().dims() for just dimensions.
For sub-byte types, the innermost dimension is expanded.
Sourcepub fn iter_mut(&mut self) -> TensorSpanIterator<'_, T, MAX_RANK> ⓘ
pub fn iter_mut(&mut self) -> TensorSpanIterator<'_, T, MAX_RANK> ⓘ
Returns a mutable iterator over all logical scalars in row-major order.
Yields (position, DimMut) pairs. Use .iter_mut().dims() for just dimensions.
Trait Implementations§
Source§impl<'a, I0: VectorIndex, I1: VectorIndex, T, const MAX_RANK: usize> Index<(I0, I1)> for TensorSpan<'a, T, MAX_RANK>
impl<'a, I0: VectorIndex, I1: VectorIndex, T, const MAX_RANK: usize> Index<(I0, I1)> for TensorSpan<'a, T, MAX_RANK>
Source§impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, T, const MAX_RANK: usize> Index<(I0, I1, I2)> for TensorSpan<'a, T, MAX_RANK>
impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, T, const MAX_RANK: usize> Index<(I0, I1, I2)> for TensorSpan<'a, T, MAX_RANK>
Source§impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, T, const MAX_RANK: usize> Index<(I0, I1, I2, I3)> for TensorSpan<'a, T, MAX_RANK>
impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, T, const MAX_RANK: usize> Index<(I0, I1, I2, I3)> for TensorSpan<'a, T, MAX_RANK>
Source§impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, I4: VectorIndex, T, const MAX_RANK: usize> Index<(I0, I1, I2, I3, I4)> for TensorSpan<'a, T, MAX_RANK>
impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, I4: VectorIndex, T, const MAX_RANK: usize> Index<(I0, I1, I2, I3, I4)> for TensorSpan<'a, T, MAX_RANK>
Source§impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, I4: VectorIndex, I5: VectorIndex, T, const MAX_RANK: usize> Index<(I0, I1, I2, I3, I4, I5)> for TensorSpan<'a, T, MAX_RANK>
impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, I4: VectorIndex, I5: VectorIndex, T, const MAX_RANK: usize> Index<(I0, I1, I2, I3, I4, I5)> for TensorSpan<'a, T, MAX_RANK>
Source§impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, I4: VectorIndex, I5: VectorIndex, I6: VectorIndex, T, const MAX_RANK: usize> Index<(I0, I1, I2, I3, I4, I5, I6)> for TensorSpan<'a, T, MAX_RANK>
impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, I4: VectorIndex, I5: VectorIndex, I6: VectorIndex, T, const MAX_RANK: usize> Index<(I0, I1, I2, I3, I4, I5, I6)> for TensorSpan<'a, T, MAX_RANK>
Source§impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, I4: VectorIndex, I5: VectorIndex, I6: VectorIndex, I7: VectorIndex, T, const MAX_RANK: usize> Index<(I0, I1, I2, I3, I4, I5, I6, I7)> for TensorSpan<'a, T, MAX_RANK>
impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, I4: VectorIndex, I5: VectorIndex, I6: VectorIndex, I7: VectorIndex, T, const MAX_RANK: usize> Index<(I0, I1, I2, I3, I4, I5, I6, I7)> for TensorSpan<'a, T, MAX_RANK>
Source§impl<'a, I: VectorIndex, T, const MAX_RANK: usize> Index<I> for TensorSpan<'a, T, MAX_RANK>
impl<'a, I: VectorIndex, T, const MAX_RANK: usize> Index<I> for TensorSpan<'a, T, MAX_RANK>
Source§impl<'a, I0: VectorIndex, I1: VectorIndex, T, const MAX_RANK: usize> IndexMut<(I0, I1)> for TensorSpan<'a, T, MAX_RANK>
impl<'a, I0: VectorIndex, I1: VectorIndex, T, const MAX_RANK: usize> IndexMut<(I0, I1)> for TensorSpan<'a, T, MAX_RANK>
Source§impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, T, const MAX_RANK: usize> IndexMut<(I0, I1, I2)> for TensorSpan<'a, T, MAX_RANK>
impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, T, const MAX_RANK: usize> IndexMut<(I0, I1, I2)> for TensorSpan<'a, T, MAX_RANK>
Source§impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, T, const MAX_RANK: usize> IndexMut<(I0, I1, I2, I3)> for TensorSpan<'a, T, MAX_RANK>
impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, T, const MAX_RANK: usize> IndexMut<(I0, I1, I2, I3)> for TensorSpan<'a, T, MAX_RANK>
Source§impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, I4: VectorIndex, T, const MAX_RANK: usize> IndexMut<(I0, I1, I2, I3, I4)> for TensorSpan<'a, T, MAX_RANK>
impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, I4: VectorIndex, T, const MAX_RANK: usize> IndexMut<(I0, I1, I2, I3, I4)> for TensorSpan<'a, T, MAX_RANK>
Source§impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, I4: VectorIndex, I5: VectorIndex, T, const MAX_RANK: usize> IndexMut<(I0, I1, I2, I3, I4, I5)> for TensorSpan<'a, T, MAX_RANK>
impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, I4: VectorIndex, I5: VectorIndex, T, const MAX_RANK: usize> IndexMut<(I0, I1, I2, I3, I4, I5)> for TensorSpan<'a, T, MAX_RANK>
Source§impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, I4: VectorIndex, I5: VectorIndex, I6: VectorIndex, T, const MAX_RANK: usize> IndexMut<(I0, I1, I2, I3, I4, I5, I6)> for TensorSpan<'a, T, MAX_RANK>
impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, I4: VectorIndex, I5: VectorIndex, I6: VectorIndex, T, const MAX_RANK: usize> IndexMut<(I0, I1, I2, I3, I4, I5, I6)> for TensorSpan<'a, T, MAX_RANK>
Source§impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, I4: VectorIndex, I5: VectorIndex, I6: VectorIndex, I7: VectorIndex, T, const MAX_RANK: usize> IndexMut<(I0, I1, I2, I3, I4, I5, I6, I7)> for TensorSpan<'a, T, MAX_RANK>
impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, I4: VectorIndex, I5: VectorIndex, I6: VectorIndex, I7: VectorIndex, T, const MAX_RANK: usize> IndexMut<(I0, I1, I2, I3, I4, I5, I6, I7)> for TensorSpan<'a, T, MAX_RANK>
Source§impl<'a, I: VectorIndex, T, const MAX_RANK: usize> IndexMut<I> for TensorSpan<'a, T, MAX_RANK>
impl<'a, I: VectorIndex, T, const MAX_RANK: usize> IndexMut<I> for TensorSpan<'a, T, MAX_RANK>
Source§impl<'a, T: FloatConvertible, const MAX_RANK: usize> IntoIterator for &'a TensorSpan<'a, T, MAX_RANK>
impl<'a, T: FloatConvertible, const MAX_RANK: usize> IntoIterator for &'a TensorSpan<'a, T, MAX_RANK>
Source§impl<'a, T: FloatConvertible, const MAX_RANK: usize> IntoIterator for &'a mut TensorSpan<'a, T, MAX_RANK>
impl<'a, T: FloatConvertible, const MAX_RANK: usize> IntoIterator for &'a mut TensorSpan<'a, T, MAX_RANK>
Source§impl<'a, T: FloatConvertible, const MAX_RANK: usize> PartialEq for TensorSpan<'a, T, MAX_RANK>
impl<'a, T: FloatConvertible, const MAX_RANK: usize> PartialEq for TensorSpan<'a, T, MAX_RANK>
Source§impl<'a, T: StorageElement, const R: usize> TensorMut<T, R> for TensorSpan<'a, T, R>
impl<'a, T: StorageElement, const R: usize> TensorMut<T, R> for TensorSpan<'a, T, R>
fn as_mut_ptr(&mut self) -> *mut T
Source§impl<'a, T: StorageElement, const R: usize> TensorRef<T, R> for TensorSpan<'a, T, R>
impl<'a, T: StorageElement, const R: usize> TensorRef<T, R> for TensorSpan<'a, T, R>
fn shape(&self) -> &[usize]
fn ndim(&self) -> usize
fn stride_bytes(&self, dim: usize) -> isize
fn as_ptr(&self) -> *const T
Source§fn view(&self) -> TensorView<'_, T, R>
fn view(&self) -> TensorView<'_, T, R>
TensorView.