pub struct TchTensor {
pub tensor: Tensor,
pub storage: Storage,
}Expand description
A tensor using the tch backend.
Fields§
§tensor: TensorHandle to the tensor. Call methods on this field.
storage: StorageThe tensor’s storage
Implementations§
Source§impl TchTensor
impl TchTensor
Sourcepub fn new(tensor: Tensor) -> Self
pub fn new(tensor: Tensor) -> Self
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.
Sourcepub fn from_existing(tensor: Tensor, storage_parent: Storage) -> Self
pub fn from_existing(tensor: Tensor, storage_parent: Storage) -> Self
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.
Source§impl TchTensor
impl TchTensor
Sourcepub 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.
Sourcepub fn mut_ops<F: Fn(&mut Tensor) -> Tensor>(
&mut self,
func: F,
) -> Option<TchTensor>
pub fn mut_ops<F: Fn(&mut Tensor) -> Tensor>( &mut self, func: F, ) -> Option<TchTensor>
Executes an operation on a tensor if the data can be reused.
Sourcepub fn unary_ops<FOwn, FRef>(self, fown: FOwn, fref: FRef) -> TchTensor
pub fn unary_ops<FOwn, FRef>(self, fown: FOwn, fref: FRef) -> TchTensor
Executes a unary operation, reusing the tensor data if possible.
Sourcepub fn binary_ops_tensor<FLMut, FRMut, FRef>(
lhs: Self,
rhs: Self,
flmut: FLMut,
frmut: FRMut,
fref: FRef,
) -> TchTensor
pub fn binary_ops_tensor<FLMut, FRMut, FRef>( lhs: Self, rhs: Self, flmut: FLMut, frmut: FRMut, fref: FRef, ) -> TchTensor
Executes a binary operation, reusing the tensor data if possible.