pub struct TchTensor<E, const D: usize>where
E: Element,{
pub tensor: Tensor,
pub storage: Storage,
/* private fields */
}
Expand description
A tensor using the tch backend.
Fields§
§tensor: Tensor
Handle to the tensor. Call methods on this field.
storage: Storage
The tensor’s storage
Implementations§
§impl<E, const D: usize> TchTensor<E, D>where
E: Element,
impl<E, const D: usize> TchTensor<E, D>where
E: Element,
pub fn new(tensor: Tensor) -> TchTensor<E, D>
pub fn new(tensor: Tensor) -> TchTensor<E, D>
Create a new tensor.
Note that if the tensor was created from an operation that may reuse the same tensor storage as the parent, you should use from_existing instead.
pub fn from_existing(tensor: Tensor, storage_parent: Storage) -> TchTensor<E, D>
pub fn from_existing(tensor: Tensor, storage_parent: Storage) -> TchTensor<E, D>
Create a tensor that was created from an operation executed on a parent tensor.
If the child tensor shared the same storage as its parent, it will be cloned, effectively tracking how much tensors point to the same memory space.
§impl<P, const D: usize> TchTensor<P, D>where
P: Element,
impl<P, const D: usize> TchTensor<P, D>where
P: Element,
pub fn can_mut(&self) -> bool
pub fn can_mut(&self) -> bool
Checks if the tensor can be mutated in-place.
Returns true
if the tensor’s stride does not contain zero (no broadcasting)
and the storage can be mutated.
pub fn mut_ops<F, EOut, const D_OUT: usize>(
&mut self,
func: F,
) -> Option<TchTensor<EOut, D_OUT>>where
F: Fn(&mut Tensor) -> Tensor,
EOut: Element,
pub fn mut_ops<F, EOut, const D_OUT: usize>(
&mut self,
func: F,
) -> Option<TchTensor<EOut, D_OUT>>where
F: Fn(&mut Tensor) -> Tensor,
EOut: Element,
Executes an operation on a tensor if the data can be reused.
pub fn unary_ops<FOwn, FRef, EOut, const D_OUT: usize>(
self,
fown: FOwn,
fref: FRef,
) -> TchTensor<EOut, D_OUT>
pub fn unary_ops<FOwn, FRef, EOut, const D_OUT: usize>( self, fown: FOwn, fref: FRef, ) -> TchTensor<EOut, D_OUT>
Executes a unary operation, reusing the tensor data if possible.
pub fn binary_ops_tensor<FLMut, FRMut, FRef, EOut, const D_OUT: usize>(
lhs: TchTensor<P, D>,
rhs: TchTensor<P, D>,
flmut: FLMut,
frmut: FRMut,
fref: FRef,
) -> TchTensor<EOut, D_OUT>
pub fn binary_ops_tensor<FLMut, FRMut, FRef, EOut, const D_OUT: usize>( lhs: TchTensor<P, D>, rhs: TchTensor<P, D>, flmut: FLMut, frmut: FRMut, fref: FRef, ) -> TchTensor<EOut, D_OUT>
Executes a binary operation, reusing the tensor data if possible.
§impl<E, const D: usize> TchTensor<E, D>
impl<E, const D: usize> TchTensor<E, D>
pub fn from_data(data: TensorData, device: Device) -> TchTensor<E, D>
pub fn from_data(data: TensorData, device: Device) -> TchTensor<E, D>
Trait Implementations§
§impl<E, const D: usize> PartialEq for TchTensor<E, D>where
E: PartialEq + Element,
impl<E, const D: usize> PartialEq for TchTensor<E, D>where
E: PartialEq + Element,
impl<E, const D: usize> Send for TchTensor<E, D>where
E: Element,
impl<E, const D: usize> StructuralPartialEq for TchTensor<E, D>where
E: Element,
impl<E, const D: usize> Sync for TchTensor<E, D>where
E: Element,
Auto Trait Implementations§
impl<E, const D: usize> Freeze for TchTensor<E, D>
impl<E, const D: usize> RefUnwindSafe for TchTensor<E, D>where
E: RefUnwindSafe,
impl<E, const D: usize> Unpin for TchTensor<E, D>where
E: Unpin,
impl<E, const D: usize> UnwindSafe for TchTensor<E, D>where
E: UnwindSafe,
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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