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>
impl<'a, C: Memorable, const D: usize> TensorRef<'a, C, D>
Sourcepub unsafe fn from_raw_parts(
data: *const C,
dims: [usize; D],
strides: [usize; D],
) -> Self
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
MatVecRefis alive.
Sourcepub fn num_elements(&self) -> usize
pub fn num_elements(&self) -> usize
Returns the total number of elements in the tensor.
Sourcepub fn get(&self, indices: &[usize; D]) -> &C
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.
Sourcepub unsafe fn get_unchecked(&self, indices: &[usize; D]) -> &C
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§impl<'a, C: Memorable> TensorRef<'a, C, 4>
impl<'a, C: Memorable> TensorRef<'a, C, 4>
Sourcepub fn subtensor_ref(&self, m: usize) -> TensorRef<'a, C, 3>
pub fn subtensor_ref(&self, m: usize) -> TensorRef<'a, C, 3>
Returns an immutable view of a 3D subtensor at the given index.
Sourcepub unsafe fn subtensor_ref_unchecked(&self, m: usize) -> TensorRef<'a, C, 3>
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>
impl<'a, C: Memorable> TensorRef<'a, C, 3>
Sourcepub fn subtensor_ref(&self, m: usize) -> MatRef<'a, C>
pub fn subtensor_ref(&self, m: usize) -> MatRef<'a, C>
Returns an immutable matrix view of a 2D subtensor at the given index.
Sourcepub unsafe fn subtensor_ref_unchecked(&self, m: usize) -> MatRef<'a, C>
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>
impl<'a, C: Memorable> TensorRef<'a, C, 2>
Sourcepub fn subtensor_ref(&self, m: usize) -> RowRef<'a, C>
pub fn subtensor_ref(&self, m: usize) -> RowRef<'a, C>
Returns an immutable row view of a 1D subtensor at the given index.
Sourcepub unsafe fn subtensor_ref_unchecked(&self, m: usize) -> RowRef<'a, C>
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>
impl<'a, C: Memorable> TensorRef<'a, C, 1>
Sourcepub fn subtensor_ref(&self, m: usize) -> &C
pub fn subtensor_ref(&self, m: usize) -> &C
Returns an immutable reference to an element at the given index.
Sourcepub unsafe fn subtensor_ref_unchecked(&self, m: usize) -> &C
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.