TensorRef

Struct TensorRef 

Source
pub struct TensorRef<'a, C: Memorable, const D: usize> { /* private fields */ }
Expand description

An immutable view into tensor data.

This struct provides read-only access to tensor data without owning the underlying memory. It holds a reference to the data along with dimension and stride information.

Implementations§

Source§

impl<'a, C: Memorable, const D: usize> TensorRef<'a, C, D>

Source

pub unsafe fn from_raw_parts( data: *const C, dims: [usize; D], strides: [usize; D], ) -> Self

Creates a TensorRef from pointers to tensor data, dimensions, and strides.

§Safety

The caller must ensure:

  • The pointers are valid and non-null.
  • For each unit, the entire memory region addressed by the tensor is within a single allocation.
  • The memory is accessible by the pointer.
  • No mutable aliasing occurs. No mutable references to the tensor data exist when the MatVecRef is alive.
Source

pub fn dims(&self) -> &[usize; D]

Returns a reference to the dimensions of the tensor.

Source

pub fn strides(&self) -> &[usize; D]

Returns a reference to the strides of the tensor.

Source

pub fn rank(&self) -> usize

Returns the rank (number of dimensions) of the tensor.

Source

pub fn num_elements(&self) -> usize

Returns the total number of elements in the tensor.

Source

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

Returns a raw pointer to the tensor’s data.

Source

pub fn get(&self, indices: &[usize; D]) -> &C

Returns a reference to an element at the given indices.

§Panics

Panics if the indices are out of bounds.

Source

pub unsafe fn get_unchecked(&self, indices: &[usize; D]) -> &C

Returns an immutable reference to an element at the given indices, without performing bounds checks.

§Safety

Calling this method with out-of-bounds indices is undefined behavior.

Source

pub unsafe fn ptr_at(&self, indices: &[usize; D]) -> *const C

Returns a raw pointer to an element at the given indices, without performing bounds checks.

§Safety

Calling this method with out-of-bounds indices is undefined behavior.

Source

pub fn to_owned(self) -> Tensor<C, D>

Creates an owned Tensor by copying the data from this TensorRef.

Source§

impl<'a, C: Memorable> TensorRef<'a, C, 4>

Source

pub fn subtensor_ref(&self, m: usize) -> TensorRef<'a, C, 3>

Returns an immutable view of a 3D subtensor at the given index.

Source

pub unsafe fn subtensor_ref_unchecked(&self, m: usize) -> TensorRef<'a, C, 3>

Returns an immutable view of a 3D subtensor at the given index without bounds checking.

§Safety

Caller must ensure that m is within bounds.

Source§

impl<'a, C: Memorable> TensorRef<'a, C, 3>

Source

pub fn subtensor_ref(&self, m: usize) -> MatRef<'a, C>

Returns an immutable matrix view of a 2D subtensor at the given index.

Source

pub unsafe fn subtensor_ref_unchecked(&self, m: usize) -> MatRef<'a, C>

Returns an immutable matrix view of a 2D subtensor at the given index without bounds checking.

§Safety

Caller must ensure that m is within bounds.

Source§

impl<'a, C: Memorable> TensorRef<'a, C, 2>

Source

pub fn subtensor_ref(&self, m: usize) -> RowRef<'a, C>

Returns an immutable row view of a 1D subtensor at the given index.

Source

pub unsafe fn subtensor_ref_unchecked(&self, m: usize) -> RowRef<'a, C>

Returns an immutable row view of a 1D subtensor at the given index without bounds checking.

§Safety

Caller must ensure that m is within bounds.

Source§

impl<'a, C: Memorable> TensorRef<'a, C, 1>

Source

pub fn subtensor_ref(&self, m: usize) -> &C

Returns an immutable reference to an element at the given index.

Source

pub unsafe fn subtensor_ref_unchecked(&self, m: usize) -> &C

Returns an immutable reference to an element at the given index without bounds checking.

§Safety

Caller must ensure that m is within bounds.

Trait Implementations§

Source§

impl<'a, C: Clone + Memorable, const D: usize> Clone for TensorRef<'a, C, D>

Source§

fn clone(&self) -> TensorRef<'a, C, D>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, C: Display + Debug + Memorable, const D: usize> Debug for TensorRef<'a, C, D>

Source§

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

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

impl<'a, C: Memorable, const D: usize> Index<[usize; D]> for TensorRef<'a, C, D>

Source§

type Output = C

The returned type after indexing.
Source§

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

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

impl<'a, C: Copy + Memorable, const D: usize> Copy for TensorRef<'a, C, D>

Auto Trait Implementations§

§

impl<'a, C, const D: usize> Freeze for TensorRef<'a, C, D>

§

impl<'a, C, const D: usize> RefUnwindSafe for TensorRef<'a, C, D>
where C: RefUnwindSafe,

§

impl<'a, C, const D: usize> !Send for TensorRef<'a, C, D>

§

impl<'a, C, const D: usize> !Sync for TensorRef<'a, C, D>

§

impl<'a, C, const D: usize> Unpin for TensorRef<'a, C, D>

§

impl<'a, C, const D: usize> UnwindSafe for TensorRef<'a, C, D>
where C: RefUnwindSafe,

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

Source§

fn by_ref(&self) -> &T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

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

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V