Skip to main content

VectorSpan

Struct VectorSpan 

Source
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>

Source

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
  • data must be valid for reads and writes of dims elements at the given stride.
  • The pointed-to memory must outlive 'a.
  • stride_bytes must be non-zero for non-empty views.
  • No other references to the memory may exist for the duration of 'a.
Source

pub fn dims(&self) -> usize

Number of logical dimensions.

Source

pub fn size(&self) -> usize

Number of logical dimensions (alias for dims).

Source

pub fn is_empty(&self) -> bool

Returns true if empty.

Source

pub fn stride_bytes(&self) -> isize

Stride in bytes.

Source

pub fn is_contiguous(&self) -> bool

Returns true if contiguous.

Source

pub fn as_ptr(&self) -> *const T

Get the underlying pointer.

Source

pub fn as_mut_ptr(&mut self) -> *mut T

Get the mutable underlying pointer.

Source

pub fn as_view(&self) -> VectorView<'_, T>

Reborrow as an immutable view, sharing the same data pointer and stride.

Source

pub fn try_get<I: VectorIndex>( &self, idx: I, ) -> Result<T::DimScalar, TensorError>

Try to get element at index.

Source

pub fn try_set<I: VectorIndex>( &mut self, idx: I, val: T::DimScalar, ) -> Result<(), TensorError>

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.

Source

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.

Source

pub fn as_contiguous_slice(&self) -> Option<&[T]>

Get a contiguous slice, if this span is contiguous.

Source

pub fn as_contiguous_slice_mut(&mut self) -> Option<&mut [T]>

Get a mutable contiguous slice, if this span is contiguous.

Source

pub fn iter(&self) -> VectorViewIterator<'_, T>

Returns an iterator over logical dimension values, yielding DimRef proxies.

Source

pub fn iter_mut(&mut self) -> VectorSpanIterator<'_, T>

Returns a mutable iterator over logical dimension values, yielding DimMut proxies.

Source§

impl<'a, T: FloatConvertible> VectorSpan<'a, T>

Source

pub fn allclose(&self, other: &Self, atol: f64, rtol: f64) -> bool

Check if all elements are within tolerance of other.

Uses the formula |a - b| <= atol + rtol * |b| per element. Returns false if dimensions differ.

Trait Implementations§

Source§

impl<'a, T: FloatConvertible> Debug for VectorSpan<'a, T>
where T::DimScalar: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, I: VectorIndex, T: StorageElement> Index<I> for VectorSpan<'a, T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, idx: I) -> &T

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, I: VectorIndex, T: StorageElement> IndexMut<I> for VectorSpan<'a, T>

Source§

fn index_mut(&mut self, idx: I) -> &mut T

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a, T: FloatConvertible> IntoIterator for &'a VectorSpan<'a, T>

Source§

type Item = DimRef<'a, T>

The type of the elements being iterated over.
Source§

type IntoIter = VectorViewIterator<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T: FloatConvertible> IntoIterator for &'a mut VectorSpan<'a, T>

Source§

type Item = DimMut<'a, T>

The type of the elements being iterated over.
Source§

type IntoIter = VectorSpanIterator<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T: FloatConvertible> PartialEq for VectorSpan<'a, T>
where T::DimScalar: PartialEq,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T: StorageElement + Send> Send for VectorSpan<'a, T>

Source§

impl<'a, T: StorageElement + Sync> Sync for VectorSpan<'a, T>

Auto Trait Implementations§

§

impl<'a, T> Freeze for VectorSpan<'a, T>

§

impl<'a, T> RefUnwindSafe for VectorSpan<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Unpin for VectorSpan<'a, T>

§

impl<'a, T> UnsafeUnpin for VectorSpan<'a, T>

§

impl<'a, T> !UnwindSafe for VectorSpan<'a, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.