Struct burn_tch::TchTensor

source ·
pub struct TchTensor<E: Element, const D: usize> {
    pub tensor: Tensor,
    pub storage: Storage,
    /* private fields */
}
Expand description

A tensor that uses the tch backend.

Fields§

§tensor: Tensor

Handle to the tensor. Call methods on this field.

§storage: Storage

The tensor’s storage

Implementations§

source§

impl<E: Element, const D: usize> TchTensor<E, D>

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<P: Element, const D: usize> TchTensor<P, D>

source

pub fn mut_ops<F: Fn(&mut Tensor) -> Tensor, EOut: Element, const D_OUT: usize>( &mut self, func: F ) -> Option<TchTensor<EOut, D_OUT>>

Execute an operation on a tensor if the data can be reused.

source

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

Execute a unary ops reusing the tensor data if possible.

source

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

Execute a binary ops reusing the tensor data if possible.

source§

impl<E: Element + Default, const D: usize> TchTensor<E, D>

source

pub fn from_data(data: Data<E, D>, 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<E: Element + Default + Copy + Debug, const D: usize> TchTensor<E, D>

source

pub fn empty(shape: Shape<D>, 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<E: TchElement, const D: usize> Add for TchTensor<E, D>

§

type Output = TchTensor<E, D>

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
source§

impl<P: Element, const D: usize> Clone for TchTensor<P, D>

source§

fn clone(&self) -> Self

Returns a copy 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<E: Debug + Element, const D: usize> Debug for TchTensor<E, D>

source§

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

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

impl<E: PartialEq + Element, const D: usize> PartialEq for TchTensor<E, D>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<E: Element, const D: usize> Send for TchTensor<E, D>

source§

impl<E: Element, const D: usize> StructuralPartialEq for TchTensor<E, D>

source§

impl<E: Element, const D: usize> Sync for TchTensor<E, D>

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> 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> 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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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>,

§

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