pub struct TensorData {
pub bytes: Bytes,
pub shape: Shape,
pub dtype: DType,
}Expand description
Data structure for tensors.
Fields§
§bytes: BytesThe values of the tensor (as bytes).
shape: ShapeThe shape of the tensor.
dtype: DTypeThe data type of the tensor.
Implementations§
Source§impl TensorData
impl TensorData
Source§impl TensorData
impl TensorData
Sourcepub fn assert_eq(&self, other: &TensorData, strict: bool)
Available on crate feature api only.
pub fn assert_eq(&self, other: &TensorData, strict: bool)
api only.Sourcepub fn assert_approx_eq<F>(&self, other: &TensorData, tolerance: Tolerance<F>)
Available on crate feature api only.
pub fn assert_approx_eq<F>(&self, other: &TensorData, tolerance: Tolerance<F>)
api only.Sourcepub fn assert_within_range<E>(&self, range: Range<E>)where
E: ElementOrdered,
Available on crate feature api only.
pub fn assert_within_range<E>(&self, range: Range<E>)where
E: ElementOrdered,
api only.Sourcepub fn assert_within_range_inclusive<E>(&self, range: RangeInclusive<E>)where
E: ElementOrdered,
Available on crate feature api only.
pub fn assert_within_range_inclusive<E>(&self, range: RangeInclusive<E>)where
E: ElementOrdered,
api only.Source§impl TensorData
impl TensorData
Sourcepub fn new<E, S>(value: Vec<E>, shape: S) -> TensorData
Available on crate feature api only.
pub fn new<E, S>(value: Vec<E>, shape: S) -> TensorData
api only.Creates a new tensor data structure.
Sourcepub fn quantized<E, S>(
value: Vec<E>,
shape: S,
scheme: QuantScheme,
qparams: &[f32],
) -> TensorData
Available on crate feature api only.
pub fn quantized<E, S>( value: Vec<E>, shape: S, scheme: QuantScheme, qparams: &[f32], ) -> TensorData
api only.Creates a new quantized tensor data structure.
Sourcepub fn from_bytes<S>(bytes: Bytes, shape: S, dtype: DType) -> TensorData
Available on crate feature api only.
pub fn from_bytes<S>(bytes: Bytes, shape: S, dtype: DType) -> TensorData
api only.Creates a new tensor data structure from raw bytes.
Sourcepub fn from_bytes_vec<S>(bytes: Vec<u8>, shape: S, dtype: DType) -> TensorData
Available on crate feature api only.
pub fn from_bytes_vec<S>(bytes: Vec<u8>, shape: S, dtype: DType) -> TensorData
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
impl TensorData
Sourcepub fn convert<E>(self) -> TensorDatawhere
E: Element,
Available on crate feature api only.
pub fn convert<E>(self) -> TensorDatawhere
E: Element,
api only.Converts the data to a different element type.
Sourcepub fn convert_dtype(self, dtype: DType) -> TensorData
Available on crate feature api only.
pub fn convert_dtype(self, dtype: DType) -> TensorData
api only.Converts the data to a different element type.
Source§impl TensorData
impl TensorData
Sourcepub fn random<E, R, S>(
shape: S,
distribution: Distribution,
rng: &mut R,
) -> TensorData
Available on crate feature api only.
pub fn random<E, R, S>( shape: S, distribution: Distribution, rng: &mut R, ) -> TensorData
api only.Populates the data with random values.
Sourcepub fn zeros<E, S>(shape: S) -> TensorData
Available on crate feature api only.
pub fn zeros<E, S>(shape: S) -> TensorData
api only.Populates the data with zeros.
Sourcepub fn ones<E, S>(shape: S) -> TensorData
Available on crate feature api only.
pub fn ones<E, S>(shape: S) -> TensorData
api only.Populates the data with ones.
Sourcepub fn full<E, S>(shape: S, fill_value: E) -> TensorData
Available on crate feature api only.
pub fn full<E, S>(shape: S, fill_value: E) -> TensorData
api only.Populates the data with the given value
Sourcepub fn full_dtype<E, S>(shape: S, fill_value: E, dtype: DType) -> TensorData
Available on crate feature api only.
pub fn full_dtype<E, S>(shape: S, fill_value: E, dtype: DType) -> TensorData
api only.Populates the data with the given value
Source§impl TensorData
impl TensorData
Source§impl TensorData
impl TensorData
Sourcepub fn as_slice<E>(&self) -> Result<&[E], DataError>where
E: Element,
Available on crate feature api only.
pub fn as_slice<E>(&self) -> Result<&[E], DataError>where
E: Element,
api only.Returns the immutable slice view of the tensor data.
Sourcepub fn as_mut_slice<E>(&mut self) -> Result<&mut [E], DataError>where
E: Element,
Available on crate feature api only.
pub fn as_mut_slice<E>(&mut self) -> Result<&mut [E], DataError>where
E: Element,
api only.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,
Available on crate feature api only.
pub fn to_vec<E>(&self) -> Result<Vec<E>, DataError>where
E: Element,
api only.Returns the tensor data as a vector of scalar values.
Sourcepub fn into_vec<E>(self) -> Result<Vec<E>, DataError>where
E: Element,
Available on crate feature api only.
pub fn into_vec<E>(self) -> Result<Vec<E>, DataError>where
E: Element,
api only.Returns the tensor data as a vector of scalar values.
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
Available on crate feature api only.
pub fn as_bytes(&self) -> &[u8] ⓘ
api only.Returns the data as a slice of bytes.
Sourcepub fn into_bytes(self) -> Bytes
Available on crate feature api only.
pub fn into_bytes(self) -> Bytes
api only.Returns the bytes representation of the data.
Trait Implementations§
Source§impl Clone for TensorData
impl Clone for TensorData
Source§fn clone(&self) -> TensorData
fn clone(&self) -> TensorData
1.0.0 (const: unstable) · 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
impl Eq 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<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<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, 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<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 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 StructuralPartialEq for TensorData
Auto Trait Implementations§
impl !RefUnwindSafe for TensorData
impl !UnwindSafe for TensorData
impl Freeze for TensorData
impl Send for TensorData
impl Sync for TensorData
impl Unpin for TensorData
impl UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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.