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.
Source§impl TchTensor
impl TchTensor
Sourcepub fn from_data<E: TchElement>(data: TensorData, device: Device) -> Self
pub fn from_data<E: TchElement>(data: TensorData, device: Device) -> Self
Trait Implementations§
Source§impl TensorMetadata for TchTensor
impl TensorMetadata for TchTensor
impl Send for TchTensor
impl StructuralPartialEq for TchTensor
impl Sync for TchTensor
Auto Trait Implementations§
impl Freeze for TchTensor
impl RefUnwindSafe for TchTensor
impl Unpin for TchTensor
impl UnwindSafe for TchTensor
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§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