Struct burn::prelude::TensorData

pub struct TensorData {
    pub bytes: Vec<u8>,
    pub shape: Vec<usize>,
    pub dtype: DType,
}
Expand description

Data structure for tensors.

Fields§

§bytes: Vec<u8>

The values of the tensor (as bytes).

§shape: Vec<usize>

The shape of the tensor.

§dtype: DType

The data type of the tensor.

Implementations§

§

impl TensorData

pub fn new<E, S>(value: Vec<E>, shape: S) -> TensorData
where E: Element, S: Into<Vec<usize>>,

Creates a new tensor data structure.

pub fn quantized<E, S>( value: Vec<E>, shape: S, strategy: QuantizationStrategy, ) -> TensorData
where E: Element, S: Into<Vec<usize>>,

Creates a new quantized tensor data structure.

pub fn as_slice<E>(&self) -> Result<&[E], DataError>
where E: Element,

Returns the immutable slice view of the tensor data.

pub fn as_mut_slice<E>(&mut self) -> Result<&mut [E], DataError>
where E: Element,

Returns the mutable slice view of the tensor data.

§Panics

If the target element type is different from the stored element type.

pub fn to_vec<E>(&self) -> Result<Vec<E>, DataError>
where E: Element,

Returns the tensor data as a vector of scalar values.

pub fn iter<E>(&self) -> Box<dyn Iterator<Item = E> + '_>
where E: Element,

Returns an iterator over the values of the tensor data.

pub fn num_elements(&self) -> usize

Returns the total number of elements of the tensor data.

pub fn random<E, R, S>( shape: S, distribution: Distribution, rng: &mut R, ) -> TensorData
where E: Element, R: RngCore, S: Into<Vec<usize>>,

Populates the data with random values.

pub fn zeros<E, S>(shape: S) -> TensorData
where E: Element, S: Into<Vec<usize>>,

Populates the data with zeros.

pub fn ones<E, S>(shape: S) -> TensorData
where E: Element, S: Into<Vec<usize>>,

Populates the data with ones.

pub fn full<E, S>(shape: S, fill_value: E) -> TensorData
where E: Element, S: Into<Vec<usize>>,

Populates the data with the given value

pub fn convert<E>(self) -> TensorData
where E: Element,

Converts the data to a different element type.

pub fn as_bytes(&self) -> &[u8]

Returns the data as a slice of bytes.

pub fn with_quantization(self, quantization: QuantizationStrategy) -> TensorData

Applies the data quantization strategy.

§Panics

Panics if the data type is not supported for quantization.

pub fn assert_approx_eq(&self, other: &TensorData, precision: usize)

Asserts the data is approximately equal to another data.

§Arguments
  • other - The other data.
  • precision - The precision of the comparison.
§Panics

Panics if the data is not approximately equal.

pub fn assert_eq(&self, other: &TensorData, strict: bool)

Asserts the data is equal to another data.

§Arguments
  • other - The other data.
  • strict - If true, the data types must the be same. Otherwise, the comparison is done in the current data type.
§Panics

Panics if the data is not equal.

pub fn assert_approx_eq_diff(&self, other: &TensorData, tolerance: f64)

Asserts the data is approximately equal to another data.

§Arguments
  • other - The other data.
  • tolerance - The tolerance of the comparison.
§Panics

Panics if the data is not approximately equal.

pub fn assert_within_range<E>(&self, range: Range<E>)
where E: Element,

Asserts each value is within a given range.

§Arguments
  • range - The range.
§Panics

If any value is not within the half-open range bounded inclusively below and exclusively above (start..end).

Trait Implementations§

§

impl Clone for TensorData

§

fn clone(&self) -> TensorData

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 Debug for TensorData

§

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

Formats the value using the given formatter. Read more
§

impl<'de> Deserialize<'de> for TensorData

§

fn deserialize<__D>( __deserializer: __D, ) -> Result<TensorData, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl Display for TensorData

§

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

Formats the value using the given formatter. Read more
§

impl<E> From<&[E]> for TensorData
where E: Element,

§

fn from(elems: &[E]) -> TensorData

Converts to this type from the input type.
§

impl From<&[usize]> for TensorData

§

fn from(elems: &[usize]) -> TensorData

Converts to this type from the input type.
§

impl<Elem, const A: usize, const B: usize, const C: usize, const D: usize, const E: usize> From<[[[[[Elem; E]; D]; C]; B]; A]> for TensorData
where Elem: Element,

§

fn from(elems: [[[[[Elem; E]; D]; C]; B]; A]) -> TensorData

Converts to this type from the input type.
§

impl<E, const A: usize, const B: usize, const C: usize, const D: usize> From<[[[[E; D]; C]; B]; A]> for TensorData
where E: Element,

§

fn from(elems: [[[[E; D]; C]; B]; A]) -> TensorData

Converts to this type from the input type.
§

impl<E, const A: usize, const B: usize, const C: usize> From<[[[E; C]; B]; A]> for TensorData
where E: Element,

§

fn from(elems: [[[E; C]; B]; A]) -> TensorData

Converts to this type from the input type.
§

impl<E, const A: usize, const B: usize> From<[[E; B]; A]> for TensorData
where E: Element,

§

fn from(elems: [[E; B]; A]) -> TensorData

Converts to this type from the input type.
§

impl<E, const A: usize> From<[E; A]> for TensorData
where E: Element,

§

fn from(elems: [E; A]) -> TensorData

Converts to this type from the input type.
§

impl<const A: usize> From<[usize; A]> for TensorData

§

fn from(elems: [usize; A]) -> TensorData

Converts to this type from the input type.
§

impl PartialEq for TensorData

§

fn eq(&self, other: &TensorData) -> 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 Serialize for TensorData

§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl Eq for TensorData

§

impl StructuralPartialEq for TensorData

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§

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

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToString for T
where T: Display + ?Sized,

source§

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

§

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

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

§

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,