Skip to main content

DynTensor

Enum DynTensor 

Source
pub enum DynTensor<D: Device> {
    Float(Tensor<D, Float>),
    Int(Tensor<D, Int>),
    Bool(Tensor<D, Bool>),
}
Expand description

A tensor whose kind (Float/Int/Bool) is determined at runtime.

This is the type-erased counterpart to Tensor<D, K>. Use it when you need to store or pass tensors of different kinds together — most importantly for disk I/O (from_bytes / to_bytes).

Variants§

§

Float(Tensor<D, Float>)

§

Int(Tensor<D, Int>)

§

Bool(Tensor<D, Bool>)

Implementations§

Source§

impl<D: Device> DynTensor<D>

Source

pub fn dtype(&self) -> DType

Runtime element type.

Source

pub fn shape(&self) -> &Shape

Logical shape.

Source

pub fn dims(&self) -> &[usize]

Dimensions as a slice.

Source

pub fn device(&self) -> &D

Device that owns the storage.

Source§

impl<D: Device> DynTensor<D>

Source

pub fn as_float(&self) -> Option<&Tensor<D, Float>>

Borrow as a Float tensor, or None.

Source

pub fn as_int(&self) -> Option<&Tensor<D, Int>>

Borrow as an Int tensor, or None.

Source

pub fn as_bool(&self) -> Option<&Tensor<D, Bool>>

Borrow as a Bool tensor, or None.

Source

pub fn into_float(self) -> Result<Tensor<D, Float>>

Unwrap into a Float tensor, or error.

Source

pub fn into_int(self) -> Result<Tensor<D, Int>>

Unwrap into an Int tensor, or error.

Source

pub fn into_bool(self) -> Result<Tensor<D, Bool>>

Unwrap into a Bool tensor, or error.

Source§

impl<D: Device> DynTensor<D>

Source

pub fn from_bytes( bytes: &[u8], dtype: DType, shape: impl Into<Shape>, device: &D, ) -> Result<Self>

Create a DynTensor from raw little-endian bytes and a runtime DType.

This is the primary entry point for deserialization (safetensors, NPY, …). The byte slice length must equal shape.element_count() * dtype.size_in_bytes().

Source

pub fn to_bytes(&self) -> Result<Vec<u8>>

Serialize to raw little-endian bytes in logical order.

Trait Implementations§

Source§

impl<D: Device> Clone for DynTensor<D>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<D: Device> Display for DynTensor<D>

Source§

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

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

impl<D: Device> From<Tensor<D, Bool>> for DynTensor<D>

Source§

fn from(t: Tensor<D, Bool>) -> Self

Converts to this type from the input type.
Source§

impl<D: Device> From<Tensor<D, Int>> for DynTensor<D>

Source§

fn from(t: Tensor<D, Int>) -> Self

Converts to this type from the input type.
Source§

impl<D: Device> From<Tensor<D>> for DynTensor<D>

Source§

fn from(t: Tensor<D, Float>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<D> Freeze for DynTensor<D>
where Tensor<D>: Freeze, Tensor<D, Int>: Freeze, Tensor<D, Bool>: Freeze,

§

impl<D> RefUnwindSafe for DynTensor<D>

§

impl<D> Send for DynTensor<D>
where Tensor<D>: Send, Tensor<D, Int>: Send, Tensor<D, Bool>: Send,

§

impl<D> Sync for DynTensor<D>
where Tensor<D>: Sync, Tensor<D, Int>: Sync, Tensor<D, Bool>: Sync,

§

impl<D> Unpin for DynTensor<D>
where Tensor<D>: Unpin, Tensor<D, Int>: Unpin, Tensor<D, Bool>: Unpin,

§

impl<D> UnsafeUnpin for DynTensor<D>

§

impl<D> UnwindSafe for DynTensor<D>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> 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<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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