pub struct TensorView<T> {
pub storage: ViewStorage<T>,
pub view: StridedView,
/* private fields */
}Expand description
Enhanced tensor that supports zero-copy views and strided operations
Fields§
§storage: ViewStorage<T>Reference to the underlying tensor data
view: StridedViewStrided view information
Implementations§
Source§impl<T> TensorView<T>
impl<T> TensorView<T>
Sourcepub fn size_bytes(&self) -> usize
pub fn size_bytes(&self) -> usize
Get the size in bytes
Sourcepub fn is_contiguous(&self) -> bool
pub fn is_contiguous(&self) -> bool
Check if the tensor is contiguous in memory
Source§impl<T: Clone + Default> TensorView<T>
impl<T: Clone + Default> TensorView<T>
Sourcepub fn from_tensor(tensor: &Tensor<T>) -> Result<Self>
pub fn from_tensor(tensor: &Tensor<T>) -> Result<Self>
Create a new tensor view from an existing tensor
Sourcepub fn transpose(&self, axes: &[usize]) -> Result<TensorView<T>>
pub fn transpose(&self, axes: &[usize]) -> Result<TensorView<T>>
Create a zero-copy transpose view
Sourcepub fn reshape(&self, new_shape: &[usize]) -> Result<TensorView<T>>
pub fn reshape(&self, new_shape: &[usize]) -> Result<TensorView<T>>
Create a zero-copy reshape view (when possible)
Sourcepub fn slice(&self, ranges: &[(usize, usize)]) -> Result<TensorView<T>>
pub fn slice(&self, ranges: &[(usize, usize)]) -> Result<TensorView<T>>
Create a zero-copy slice view
Sourcepub fn to_tensor(&self) -> Result<Tensor<T>>
pub fn to_tensor(&self) -> Result<Tensor<T>>
Convert back to a regular tensor (may require data copy)
Sourcepub fn requires_grad(&self) -> bool
pub fn requires_grad(&self) -> bool
Check if the tensor requires gradient computation
Sourcepub fn set_requires_grad(&mut self, requires_grad: bool)
pub fn set_requires_grad(&mut self, requires_grad: bool)
Set whether the tensor requires gradient computation
Trait Implementations§
Source§impl<T> Clone for TensorView<T>
impl<T> Clone for TensorView<T>
Source§impl<T: Debug> Debug for TensorView<T>
impl<T: Debug> Debug for TensorView<T>
Auto Trait Implementations§
impl<T> Freeze for TensorView<T>
impl<T> RefUnwindSafe for TensorView<T>where
T: RefUnwindSafe,
impl<T> Send for TensorView<T>
impl<T> Sync for TensorView<T>
impl<T> Unpin for TensorView<T>
impl<T> UnsafeUnpin for TensorView<T>
impl<T> UnwindSafe for TensorView<T>where
T: RefUnwindSafe,
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