Skip to main content

TensorView

Struct TensorView 

Source
pub struct TensorView<'a> { /* private fields */ }
Expand description

An immutable zero-copy view of a multi-dimensional f64 tensor.

This struct is Send and Sync because all its components (&[f64], Shape, Strides, and usize) are Send and Sync.

Implementations§

Source§

impl<'a> TensorView<'a>

Source

pub fn new(data: &'a [f64], shape: Shape, storage_offset: usize) -> Self

Constructs a new TensorView.

§Panics

Panics if the buffer is smaller than the maximum addressable index implied by the strides and storage offset.

Source

pub fn new_default(data: &'a [f64], shape: Shape) -> Self

Constructs a new TensorView with default storage_offset of 0.

Source

pub fn with_strides( data: &'a [f64], shape: Shape, strides: Strides, storage_offset: usize, ) -> Self

Constructs a view with explicit (possibly non-contiguous) strides.

§Panics

Panics if shape.rank() != strides.as_slice().len(), or if the backing buffer is too small to safely access the largest flat index addressable by these strides.

Source

pub fn with_strides_default( data: &'a [f64], shape: Shape, strides: Strides, ) -> Self

Constructs a new TensorView with explicit strides and default storage_offset of 0.

Source

pub const fn shape(&self) -> &Shape

Returns a reference to the Shape.

Source

pub const fn strides(&self) -> &Strides

Returns a reference to the Strides.

Source

pub fn get(&self, idx: &[usize]) -> Option<f64>

Returns the element at the multi-dimensional index.

Returns None if any index component is out of bounds.

Source

pub unsafe fn get_unchecked(&self, idx: &[usize]) -> f64

Returns the element at the multi-dimensional index without bounds checking.

§Safety

The caller must guarantee that idx is a valid multi-dimensional index for this tensor view.

Source

pub fn rank(&self) -> usize

Returns the rank (number of dimensions).

Source

pub fn numel(&self) -> usize

Returns the total number of elements.

Source

pub fn is_contiguous(&self) -> bool

Returns true if this view has a contiguous layout.

Source

pub const fn as_raw_slice(&self) -> &[f64]

Returns the flat backing buffer (the entire underlying memory). Use as_slice() to get the view’s active segment.

Source

pub fn as_slice(&self) -> &[f64]

Returns the active slice of this view.

§Panics

Panics if the view is not contiguous.

Source

pub fn iter_elements(&self) -> ElementIter<'_>

Iterates over all elements in row-major order.

This is the fundamental building block for element-wise operations and vectorized kernel dispatch.

Trait Implementations§

Source§

impl<'a> Index<&[usize]> for TensorView<'a>

Source§

type Output = f64

The returned type after indexing.
Source§

fn index(&self, index: &[usize]) -> &Self::Output

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

impl<'a, const N: usize> Index<[usize; N]> for TensorView<'a>

Source§

type Output = f64

The returned type after indexing.
Source§

fn index(&self, index: [usize; N]) -> &Self::Output

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

impl<'a> Index<(usize,)> for TensorView<'a>

Source§

type Output = f64

The returned type after indexing.
Source§

fn index(&self, index: (usize,)) -> &Self::Output

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

impl<'a> Index<(usize, usize)> for TensorView<'a>

Source§

type Output = f64

The returned type after indexing.
Source§

fn index(&self, index: (usize, usize)) -> &Self::Output

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

impl<'a> Index<(usize, usize, usize)> for TensorView<'a>

Source§

type Output = f64

The returned type after indexing.
Source§

fn index(&self, index: (usize, usize, usize)) -> &Self::Output

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

Auto Trait Implementations§

§

impl<'a> Freeze for TensorView<'a>

§

impl<'a> RefUnwindSafe for TensorView<'a>

§

impl<'a> Send for TensorView<'a>

§

impl<'a> Sync for TensorView<'a>

§

impl<'a> Unpin for TensorView<'a>

§

impl<'a> UnsafeUnpin for TensorView<'a>

§

impl<'a> UnwindSafe for TensorView<'a>

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,