pub struct TensorView<'a> { /* private fields */ }
Expand description
A view into a tensor’s data
Implementations§
Source§impl<'a> TensorView<'a>
impl<'a> TensorView<'a>
Sourcepub fn new_with_params(
tensor: &'a Tensor,
offset: usize,
shape: Vec<usize>,
strides: Vec<usize>,
) -> Result<Self>
pub fn new_with_params( tensor: &'a Tensor, offset: usize, shape: Vec<usize>, strides: Vec<usize>, ) -> Result<Self>
Create a view with custom offset, shape, and strides
Sourcepub fn is_contiguous(&self) -> bool
pub fn is_contiguous(&self) -> bool
Check if this view is contiguous in memory
Sourcepub fn slice(&self, dim: usize, range: Range<usize>) -> Result<TensorView<'a>>
pub fn slice(&self, dim: usize, range: Range<usize>) -> Result<TensorView<'a>>
Create a slice of this view along a specific dimension
Sourcepub fn select(&self, dim: usize, index: usize) -> Result<TensorView<'a>>
pub fn select(&self, dim: usize, index: usize) -> Result<TensorView<'a>>
Create a view of a specific index along a dimension (reduces dimensionality by 1)
Sourcepub fn transpose(&self) -> Result<TensorView<'a>>
pub fn transpose(&self) -> Result<TensorView<'a>>
Transpose the view (swap last two dimensions)
Sourcepub fn reshape(&self, new_shape: &[usize]) -> Result<TensorView<'a>>
pub fn reshape(&self, new_shape: &[usize]) -> Result<TensorView<'a>>
Reshape the view (only works if contiguous)
Sourcepub fn squeeze(&self) -> TensorView<'a>
pub fn squeeze(&self) -> TensorView<'a>
Create a view with squeezed dimensions (remove dimensions of size 1)
Sourcepub fn unsqueeze(&self, dim: usize) -> Result<TensorView<'a>>
pub fn unsqueeze(&self, dim: usize) -> Result<TensorView<'a>>
Create a view with an added dimension of size 1
Sourcepub fn unravel_index(&self, index: usize) -> Result<Vec<usize>>
pub fn unravel_index(&self, index: usize) -> Result<Vec<usize>>
Convert linear index to multi-dimensional indices
Sourcepub fn ravel_index(&self, indices: &[usize]) -> Result<usize>
pub fn ravel_index(&self, indices: &[usize]) -> Result<usize>
Convert multi-dimensional indices to linear index in the view
Sourcepub fn iter(&'a self) -> TensorViewIterator<'a> ⓘ
pub fn iter(&'a self) -> TensorViewIterator<'a> ⓘ
Iterate over all elements in the view
Sourcepub fn axis_iter(&'a self, axis: usize) -> Result<AxisIterator<'a>>
pub fn axis_iter(&'a self, axis: usize) -> Result<AxisIterator<'a>>
Create a view that iterates along a specific axis
Trait Implementations§
Source§impl<'a> Clone for TensorView<'a>
impl<'a> Clone for TensorView<'a>
Source§fn clone(&self) -> TensorView<'a>
fn clone(&self) -> TensorView<'a>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<'a> Debug for TensorView<'a>
impl<'a> Debug for TensorView<'a>
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> !UnwindSafe for TensorView<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more