Struct burn::backend::libtorch::TchTensor

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,

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>

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.

pub fn partial(tensor: Tensor, storage_parent: Storage) -> TchTensor<E, D>

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

§

impl<P, const D: usize> TchTensor<P, D>
where P: Element,

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,

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>
where EOut: Element, FOwn: Fn(Tensor) -> Tensor, FRef: Fn(&Tensor) -> Tensor,

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>
where EOut: Element, 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.

§

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

pub fn from_data(data: TensorData, device: Device) -> TchTensor<E, D>

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.

§

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

pub fn empty(shape: Shape<D>, device: LibTorchDevice) -> TchTensor<E, D>

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§

§

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

§

fn clone(&self) -> TchTensor<P, D>

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
§

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

§

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

Formats the value using the given formatter. Read more
§

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

§

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

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

default unsafe fn clone_to_uninit(&self, dst: *mut T)

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

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,