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
impl TensorData
pub 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.
pub 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.
pub 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.
pub 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.
pub 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.
pub 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.
pub fn num_elements(&self) -> usize
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
pub fn random<E, R, S>( shape: S, distribution: Distribution, rng: &mut R, ) -> TensorData
Populates the data with random values.
pub fn zeros<E, S>(shape: S) -> TensorData
pub fn zeros<E, S>(shape: S) -> TensorData
Populates the data with zeros.
pub fn ones<E, S>(shape: S) -> TensorData
pub fn ones<E, S>(shape: S) -> TensorData
Populates the data with ones.
pub 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
pub fn convert<E>(self) -> TensorDatawhere
E: Element,
pub fn convert<E>(self) -> TensorDatawhere
E: Element,
Converts the data to a different element type.
pub 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.
pub fn assert_approx_eq(&self, other: &TensorData, precision: usize)
pub fn assert_approx_eq(&self, other: &TensorData, precision: usize)
pub fn assert_eq(&self, other: &TensorData, strict: bool)
pub fn assert_eq(&self, other: &TensorData, strict: bool)
pub fn assert_approx_eq_diff(&self, other: &TensorData, tolerance: f64)
pub fn assert_approx_eq_diff(&self, other: &TensorData, tolerance: f64)
pub 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,
Trait Implementations§
§impl Clone for TensorData
impl Clone for TensorData
§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 more§impl Debug for TensorData
impl Debug for TensorData
§impl<'de> Deserialize<'de> for TensorData
impl<'de> Deserialize<'de> for TensorData
§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>,
§impl Display for TensorData
impl Display for TensorData
§impl<E> From<&[E]> for TensorDatawhere
E: Element,
impl<E> From<&[E]> for TensorDatawhere
E: Element,
§fn from(elems: &[E]) -> TensorData
fn from(elems: &[E]) -> TensorData
§impl From<&[usize]> for TensorData
impl From<&[usize]> for TensorData
§fn from(elems: &[usize]) -> TensorData
fn from(elems: &[usize]) -> TensorData
§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,
§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,
§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,
§impl<E, const A: usize, const B: usize> From<[[E; B]; A]> for TensorDatawhere
E: Element,
impl<E, const A: usize, const B: usize> From<[[E; B]; A]> for TensorDatawhere
E: Element,
§fn from(elems: [[E; B]; A]) -> TensorData
fn from(elems: [[E; B]; A]) -> TensorData
§impl<E, const A: usize> From<[E; A]> for TensorDatawhere
E: Element,
impl<E, const A: usize> From<[E; A]> for TensorDatawhere
E: Element,
§fn from(elems: [E; A]) -> TensorData
fn from(elems: [E; A]) -> TensorData
§impl<const A: usize> From<[usize; A]> for TensorData
impl<const A: usize> From<[usize; A]> for TensorData
§fn from(elems: [usize; A]) -> TensorData
fn from(elems: [usize; A]) -> TensorData
§impl PartialEq for TensorData
impl PartialEq for TensorData
§impl Serialize for TensorData
impl Serialize for TensorData
§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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string()
] Read more§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString
]. Read more