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>
impl<'a> TensorView<'a>
Sourcepub fn new(data: &'a [f64], shape: Shape, storage_offset: usize) -> Self
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.
Sourcepub fn new_default(data: &'a [f64], shape: Shape) -> Self
pub fn new_default(data: &'a [f64], shape: Shape) -> Self
Constructs a new TensorView with default storage_offset of 0.
Sourcepub fn with_strides(
data: &'a [f64],
shape: Shape,
strides: Strides,
storage_offset: usize,
) -> Self
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.
Sourcepub fn with_strides_default(
data: &'a [f64],
shape: Shape,
strides: Strides,
) -> Self
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.
Sourcepub fn get(&self, idx: &[usize]) -> Option<f64>
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.
Sourcepub unsafe fn get_unchecked(&self, idx: &[usize]) -> f64
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.
Sourcepub fn is_contiguous(&self) -> bool
pub fn is_contiguous(&self) -> bool
Returns true if this view has a contiguous layout.
Sourcepub const fn as_raw_slice(&self) -> &[f64]
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.
Sourcepub fn iter_elements(&self) -> ElementIter<'_> ⓘ
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.