TchTensor

Struct TchTensor 

Source
pub struct TchTensor {
    pub tensor: Tensor,
    pub storage: Storage,
}
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§

Source§

impl TchTensor

Source

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.

Source

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

pub fn partial(tensor: Tensor, storage_parent: Storage) -> Self

Create a tensor that uses a part of its parent tensor such as slice and narrow.

Source§

impl TchTensor

Source

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.

Source

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.

Source

pub fn unary_ops<FOwn, FRef>(self, fown: FOwn, fref: FRef) -> TchTensor
where FOwn: Fn(Tensor) -> Tensor, FRef: Fn(&Tensor) -> Tensor,

Executes a unary operation, reusing the tensor data if possible.

Source

pub fn binary_ops_tensor<FLMut, FRMut, FRef>( lhs: Self, rhs: Self, flmut: FLMut, frmut: FRMut, fref: FRef, ) -> TchTensor
where FLMut: Fn(&mut Tensor, &Tensor) -> Tensor, FRMut: Fn(&Tensor, &mut Tensor) -> Tensor, FRef: Fn(&Tensor, &Tensor) -> Tensor,

Executes a binary operation, reusing the tensor data if possible.

Source§

impl TchTensor

Source

pub fn from_data<E: TchElement>(data: TensorData, device: Device) -> Self

Creates a new tensor from a shape and a device.

§Arguments
  • data - The tensor’s data.
  • device - The device on which the tensor will be allocated.
§Returns

A new tensor.

Source§

impl TchTensor

Source

pub fn empty<E: Element>(shape: Shape, device: LibTorchDevice) -> Self

Creates an empty tensor from a shape and a device.

§Arguments
  • shape - The shape of the tensor.
  • device - The device to create the tensor on.
§Returns

A new empty tensor.

Trait Implementations§

Source§

impl Clone for TchTensor

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TchTensor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for TchTensor

Source§

fn eq(&self, other: &TchTensor) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl QTensorPrimitive for TchTensor

Source§

fn scheme(&self) -> &QuantScheme

Returns the quantization settings for the given tensor.
Source§

fn acc_precision(&self) -> QuantAcc

The precision used for the accumulation in various kernels.
Source§

fn propagation(&self) -> QuantPropagation

How quantization is propagated during computation.
Source§

fn default_scheme() -> QuantScheme

Returns the default tensor quantization scheme.
Source§

impl TensorMetadata for TchTensor

Source§

fn dtype(&self) -> DType

The dtype of the tensor.
Source§

fn shape(&self) -> Shape

The shape of the tensor.
Source§

fn rank(&self) -> usize

The number of dimensions of the tensor.
Source§

impl Send for TchTensor

Source§

impl StructuralPartialEq for TchTensor

Source§

impl Sync for TchTensor

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V