Tensor

Struct Tensor 

Source
pub struct Tensor<D: Device, T: Scalar> { /* private fields */ }
Expand description

A tensor on either CPU or GPU.

Implementations§

Source§

impl<F: Float> Tensor<Cpu<F>, F>

Source§

impl<D: Device, T: Scalar> Tensor<D, T>

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn size(&self) -> usize

Size of the tensor in bytes.

Source

pub fn offset(index: usize) -> usize

The offset in bytes for a linear index.

Source

pub fn data(&self) -> &D::Data

Source

pub fn id(&self) -> Id<TensorId>

Source§

impl<D: Device, F: Float> Tensor<D, F>

Source

pub const fn def(&self) -> &'static str

Source§

impl<T: Scalar, K: Kind> Tensor<Gpu<K>, T>

Source

pub fn from_data_u8( context: &Context, shape: impl Into<Shape>, contents: &[u8], ) -> Result<Self, TensorError>

Source

pub fn back_in_place(&self) -> TensorCpu<T>

Source

pub async fn back(&self) -> TensorCpu<T>

Source§

impl<T: Scalar, K: Kind> Tensor<Gpu<K>, T>

Source

pub fn context(&self) -> &Context

Source

pub fn load(&self, host: &TensorCpu<T>) -> Result<(), TensorError>

Source

pub fn load_batch( &self, host: &TensorCpu<T>, batch: usize, ) -> Result<(), TensorError>

Source

pub fn destroy(self)

Source§

impl<T: Scalar> Tensor<Gpu<Uniform>, T>

Source

pub fn layout(&self, binding: u32) -> BindGroupLayoutEntry

Source§

impl<T: Scalar> Tensor<Gpu<ReadWrite>, T>

Source

pub fn meta_layout(&self, binding: u32) -> BindGroupLayoutEntry

Source

pub fn layout(&self, binding: u32, read_only: bool) -> BindGroupLayoutEntry

Source§

impl<T: Scalar> Tensor<Cpu<T>, T>

Source

pub fn map<U: Scalar>(self, f: impl FnMut(&T) -> U) -> TensorCpu<U>

Apply a map f to every element in the tensor.

Source

pub fn pad(self, multiples: impl Into<Shape>) -> Self

Pad each dimension to multiples with zeros.

Source

pub fn repeat(self, axis: usize, repeat: usize) -> Self

Repeat the tensor along a given axis.

Source

pub fn stack(batches: Vec<Self>, axis: usize) -> Result<Self, TensorError>

Concat a batch of tensors.

Source

pub fn split(self, axis: usize) -> Result<Vec<Self>, TensorError>

Split the tensor along the batch axis.

Source

pub fn slice( &self, x: impl TensorAxis, y: impl TensorAxis, z: impl TensorAxis, w: impl TensorAxis, ) -> Result<Self, TensorError>

Source

pub fn into_slice( self, x: impl TensorAxis, y: impl TensorAxis, z: impl TensorAxis, w: impl TensorAxis, ) -> Result<Self, TensorError>

Source§

impl<T: Scalar> Tensor<Gpu<ReadWrite>, T>

Source

pub fn view( &self, x: impl TensorAxis, y: impl TensorAxis, z: impl TensorAxis, w: impl TensorAxis, ) -> Result<TensorGpuView<'_, T>, TensorError>

Create a view for the tensor.

Trait Implementations§

Source§

impl<D: Device, T: Scalar> Clone for Tensor<D, T>

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<D: Debug + Device, T: Debug + Scalar> Debug for Tensor<D, T>
where D::Data: Debug,

Source§

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

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

impl<D: Device, T: Scalar> Deref for Tensor<D, T>

Source§

type Target = <D as Device>::Data

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'a, T: Scalar> From<&'a Tensor<Gpu<ReadWrite>, T>> for TensorGpuView<'a, T>

Source§

fn from(value: &'a TensorGpu<T, ReadWrite>) -> Self

Converts to this type from the input type.
Source§

impl<T: Scalar> From<Tensor<Cpu<T>, T>> for Vec<T>

Source§

fn from(value: TensorCpu<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Scalar> TensorInto<Tensor<Cpu<T>, T>> for TensorCpu<T>

Source§

fn to(self, _: &Context) -> Self

Source§

impl<T: Scalar, K: Kind> TensorInto<Tensor<Gpu<K>, T>> for TensorCpu<T>

Source§

fn to(self, context: &Context) -> TensorGpu<T, K>

Source§

impl<T: Scalar> TensorInto<Tensor<Gpu<ReadWrite>, T>> for TensorGpu<T, ReadWrite>

Available on non-WebAssembly only.
Source§

fn to(self, context: &Context) -> Self

Source§

impl<D: Device, T: Scalar> TensorScalar for Tensor<D, T>

Source§

type T = T

Auto Trait Implementations§

§

impl<D, T> Freeze for Tensor<D, T>
where <D as Device>::Data: Freeze,

§

impl<D, T> RefUnwindSafe for Tensor<D, T>

§

impl<D, T> Send for Tensor<D, T>
where <D as Device>::Data: Send,

§

impl<D, T> Sync for Tensor<D, T>
where <D as Device>::Data: Sync,

§

impl<D, T> Unpin for Tensor<D, T>
where <D as Device>::Data: Unpin, T: Unpin,

§

impl<D, T> UnwindSafe for Tensor<D, T>
where <D as Device>::Data: UnwindSafe, T: 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§

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<From, Into> CoHom<From> for Into
where From: Hom<Into>,

Source§

fn co_hom(value: From) -> Into

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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<T> Upcast<T> for T

Source§

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

Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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