Skip to main content

TensorData

Struct TensorData 

Source
pub struct TensorData {
    pub bytes: Bytes,
    pub shape: Shape,
    pub dtype: DType,
}
Expand description

Data structure for tensors.

Fields§

§bytes: Bytes

The values of the tensor (as bytes).

§shape: Shape

The shape of the tensor.

§dtype: DType

The data type of the tensor.

Implementations§

Source§

impl TensorData

Source

pub fn rank(&self) -> usize

Available on crate feature api only.

Returns the rank (the number of dimensions).

Source

pub fn num_elements(&self) -> usize

Available on crate feature api only.

Returns the total number of elements of the tensor data.

Source§

impl TensorData

Source

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

Available on crate feature api only.

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.

Source

pub fn assert_approx_eq<F>(&self, other: &TensorData, tolerance: Tolerance<F>)
where F: Float + Element,

Available on crate feature api only.

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.

Source

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

Available on crate feature api only.

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

Source

pub fn assert_within_range_inclusive<E>(&self, range: RangeInclusive<E>)
where E: ElementOrdered,

Available on crate feature api only.

Asserts each value is within a given inclusive range.

§Arguments
  • range - The range.
§Panics

If any value is not within the half-open range bounded inclusively (start..=end).

Source§

impl TensorData

Source

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

Available on crate feature api only.

Creates a new tensor data structure.

Source

pub fn quantized<E, S>( value: Vec<E>, shape: S, scheme: QuantScheme, qparams: &[f32], ) -> TensorData
where E: Element, S: Into<Shape>,

Available on crate feature api only.

Creates a new quantized tensor data structure.

Source

pub fn from_bytes<S>(bytes: Bytes, shape: S, dtype: DType) -> TensorData
where S: Into<Shape>,

Available on crate feature api only.

Creates a new tensor data structure from raw bytes.

Source

pub fn from_bytes_vec<S>(bytes: Vec<u8>, shape: S, dtype: DType) -> TensorData
where S: Into<Shape>,

Available on crate feature api only.

Creates a new tensor data structure from raw bytes stored in a vector.

Prefer TensorData::new or TensorData::quantized over this method unless you are certain that the bytes representation is valid.

Source§

impl TensorData

Source

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

Available on crate feature api only.

Converts the data to a different element type.

Source

pub fn convert_dtype(self, dtype: DType) -> TensorData

Available on crate feature api only.

Converts the data to a different element type.

Source§

impl TensorData

Source

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

Available on crate feature api only.

Populates the data with random values.

Source

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

Available on crate feature api only.

Populates the data with zeros.

Source

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

Available on crate feature api only.

Populates the data with ones.

Source

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

Available on crate feature api only.

Populates the data with the given value

Source

pub fn full_dtype<E, S>(shape: S, fill_value: E, dtype: DType) -> TensorData
where E: Into<Scalar>, S: Into<Shape>,

Available on crate feature api only.

Populates the data with the given value

Source§

impl TensorData

Source

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

Available on crate feature api only.

Returns an iterator over the values of the tensor data.

Source§

impl TensorData

Source

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

Available on crate feature api only.

Returns the immutable slice view of the tensor data.

Source

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

Available on crate feature api only.

Returns the mutable slice view of the tensor data.

§Panics

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

Source

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

Available on crate feature api only.

Returns the tensor data as a vector of scalar values.

Source

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

Available on crate feature api only.

Returns the tensor data as a vector of scalar values.

Source

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

Available on crate feature api only.

Returns the data as a slice of bytes.

Source

pub fn into_bytes(self) -> Bytes

Available on crate feature api only.

Returns the bytes representation of the data.

Trait Implementations§

Source§

impl Clone for TensorData

Source§

fn clone(&self) -> TensorData

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

Source§

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

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

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

Source§

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

impl Display for TensorData

Source§

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

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

impl Eq for TensorData

Source§

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

Source§

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

Converts to this type from the input type.
Source§

impl From<&[usize]> for TensorData

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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,

Source§

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

Converts to this type from the input type.
Source§

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,

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

impl PartialEq for TensorData

Source§

fn eq(&self, other: &TensorData) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for TensorData

Source§

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

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<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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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

Source§

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.

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

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.