pub struct TensorData {
pub bytes: Bytes,
pub shape: Vec<usize>,
pub dtype: DType,
}
Expand description
Data structure for tensors.
Fields§
§bytes: Bytes
The values of the tensor (as bytes).
shape: Vec<usize>
The shape of the tensor.
dtype: DType
The data type of the tensor.
Implementations§
Source§impl TensorData
impl TensorData
Sourcepub fn new<E, S>(value: Vec<E>, shape: S) -> TensorData
pub fn new<E, S>(value: Vec<E>, shape: S) -> TensorData
Creates a new tensor data structure.
Sourcepub fn quantized<E, S>(
value: Vec<E>,
shape: S,
strategy: QuantizationStrategy,
) -> TensorData
pub fn quantized<E, S>( value: Vec<E>, shape: S, strategy: QuantizationStrategy, ) -> TensorData
Creates a new quantized tensor data structure.
Sourcepub fn from_bytes<S>(bytes: Vec<u8>, shape: S, dtype: DType) -> TensorData
pub fn from_bytes<S>(bytes: Vec<u8>, shape: S, dtype: DType) -> TensorData
Creates a new tensor data structure from raw bytes.
Prefer TensorData::new
or TensorData::quantized
over this method unless you are
certain that the bytes representation is valid.
Sourcepub fn as_slice<E>(&self) -> Result<&[E], DataError>where
E: Element,
pub fn as_slice<E>(&self) -> Result<&[E], DataError>where
E: Element,
Returns the immutable slice view of the tensor data.
Sourcepub fn as_mut_slice<E>(&mut self) -> Result<&mut [E], DataError>where
E: Element,
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.
Sourcepub fn to_vec<E>(&self) -> Result<Vec<E>, DataError>where
E: Element,
pub fn to_vec<E>(&self) -> Result<Vec<E>, DataError>where
E: Element,
Returns the tensor data as a vector of scalar values.
Sourcepub fn into_vec<E>(self) -> Result<Vec<E>, DataError>where
E: Element,
pub fn into_vec<E>(self) -> Result<Vec<E>, DataError>where
E: Element,
Returns the tensor data as a vector of scalar values.
Sourcepub fn iter<E>(&self) -> Box<dyn Iterator<Item = E> + '_>where
E: Element,
pub fn iter<E>(&self) -> Box<dyn Iterator<Item = E> + '_>where
E: Element,
Returns an iterator over the values of the tensor data.
Sourcepub fn num_elements(&self) -> usize
pub fn num_elements(&self) -> usize
Returns the total number of elements of the tensor data.
Sourcepub fn random<E, R, S>(
shape: S,
distribution: Distribution,
rng: &mut R,
) -> TensorData
pub fn random<E, R, S>( shape: S, distribution: Distribution, rng: &mut R, ) -> TensorData
Populates the data with random values.
Sourcepub fn zeros<E, S>(shape: S) -> TensorData
pub fn zeros<E, S>(shape: S) -> TensorData
Populates the data with zeros.
Sourcepub fn ones<E, S>(shape: S) -> TensorData
pub fn ones<E, S>(shape: S) -> TensorData
Populates the data with ones.
Sourcepub fn full<E, S>(shape: S, fill_value: E) -> TensorData
pub fn full<E, S>(shape: S, fill_value: E) -> TensorData
Populates the data with the given value
Sourcepub fn convert<E>(self) -> TensorDatawhere
E: Element,
pub fn convert<E>(self) -> TensorDatawhere
E: Element,
Converts the data to a different element type.
Sourcepub fn convert_dtype(self, dtype: DType) -> TensorData
pub fn convert_dtype(self, dtype: DType) -> TensorData
Converts the data to a different element type.
Sourcepub fn into_bytes(self) -> Bytes
pub fn into_bytes(self) -> Bytes
Returns the bytes representation of the data.
Sourcepub fn with_quantization(self, quantization: QuantizationStrategy) -> TensorData
pub fn with_quantization(self, quantization: QuantizationStrategy) -> TensorData
Applies the data quantization strategy.
§Panics
Panics if the data type is not supported for quantization.
Sourcepub fn dequantize(self) -> Result<TensorData, DataError>
pub fn dequantize(self) -> Result<TensorData, DataError>
Dequantizes the data according to its quantization scheme.
Sourcepub fn assert_eq(&self, other: &TensorData, strict: bool)
pub fn assert_eq(&self, other: &TensorData, strict: bool)
Sourcepub fn assert_approx_eq<F>(&self, other: &TensorData, tolerance: Tolerance<F>)
pub fn assert_approx_eq<F>(&self, other: &TensorData, tolerance: Tolerance<F>)
Sourcepub fn assert_within_range<E>(&self, range: Range<E>)where
E: Element,
pub fn assert_within_range<E>(&self, range: Range<E>)where
E: Element,
Sourcepub fn assert_within_range_inclusive<E>(&self, range: RangeInclusive<E>)where
E: Element,
pub fn assert_within_range_inclusive<E>(&self, range: RangeInclusive<E>)where
E: Element,
Trait Implementations§
Source§impl Clone for TensorData
impl Clone for TensorData
Source§fn clone(&self) -> TensorData
fn clone(&self) -> TensorData
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for TensorData
impl Debug for TensorData
Source§impl<'de> Deserialize<'de> for TensorData
impl<'de> Deserialize<'de> for TensorData
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<TensorData, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<TensorData, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for TensorData
impl Display for TensorData
Source§impl<E> From<&[E]> for TensorDatawhere
E: Element,
impl<E> From<&[E]> for TensorDatawhere
E: Element,
Source§fn from(elems: &[E]) -> TensorData
fn from(elems: &[E]) -> TensorData
Source§impl From<&[usize]> for TensorData
impl From<&[usize]> for TensorData
Source§fn from(elems: &[usize]) -> TensorData
fn from(elems: &[usize]) -> TensorData
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 TensorDatawhere
Elem: Element,
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 TensorDatawhere
Elem: Element,
Source§impl<E, const A: usize, const B: usize, const C: usize, const D: usize> From<[[[[E; D]; C]; B]; A]> for TensorDatawhere
E: Element,
impl<E, const A: usize, const B: usize, const C: usize, const D: usize> From<[[[[E; D]; C]; B]; A]> for TensorDatawhere
E: Element,
Source§impl<E, const A: usize, const B: usize, const C: usize> From<[[[E; C]; B]; A]> for TensorDatawhere
E: Element,
impl<E, const A: usize, const B: usize, const C: usize> From<[[[E; C]; B]; A]> for TensorDatawhere
E: Element,
Source§impl<E, const A: usize> From<[E; A]> for TensorDatawhere
E: Element,
impl<E, const A: usize> From<[E; A]> for TensorDatawhere
E: Element,
Source§fn from(elems: [E; A]) -> TensorData
fn from(elems: [E; A]) -> TensorData
Source§impl PartialEq for TensorData
impl PartialEq for TensorData
Source§impl Serialize for TensorData
impl Serialize for TensorData
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Eq for TensorData
impl StructuralPartialEq for TensorData
Auto Trait Implementations§
impl Freeze for TensorData
impl RefUnwindSafe for TensorData
impl Send for TensorData
impl Sync for TensorData
impl Unpin for TensorData
impl UnwindSafe for TensorData
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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