Struct burn_tensor::TensorData
source · 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§
source§impl TensorData
impl TensorData
sourcepub fn new<E: Element, S: Into<Vec<usize>>>(value: Vec<E>, shape: S) -> Self
pub fn new<E: Element, S: Into<Vec<usize>>>(value: Vec<E>, shape: S) -> Self
Creates a new tensor data structure.
sourcepub fn quantized<E: Element, S: Into<Vec<usize>>>(
value: Vec<E>,
shape: S,
strategy: QuantizationStrategy,
) -> Self
pub fn quantized<E: Element, S: Into<Vec<usize>>>( value: Vec<E>, shape: S, strategy: QuantizationStrategy, ) -> Self
Creates a new quantized tensor data structure.
sourcepub fn as_slice<E: Element>(&self) -> Result<&[E], DataError>
pub fn as_slice<E: Element>(&self) -> Result<&[E], DataError>
Returns the immutable slice view of the tensor data.
sourcepub fn as_mut_slice<E: Element>(&mut self) -> Result<&mut [E], DataError>
pub fn as_mut_slice<E: Element>(&mut self) -> Result<&mut [E], DataError>
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: Element>(&self) -> Result<Vec<E>, DataError>
pub fn to_vec<E: Element>(&self) -> Result<Vec<E>, DataError>
Returns the tensor data as a vector of scalar values.
sourcepub fn iter<E: Element>(&self) -> Box<dyn Iterator<Item = E> + '_>
pub fn iter<E: Element>(&self) -> Box<dyn Iterator<Item = E> + '_>
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: Element, R: RngCore, S: Into<Vec<usize>>>(
shape: S,
distribution: Distribution,
rng: &mut R,
) -> Self
pub fn random<E: Element, R: RngCore, S: Into<Vec<usize>>>( shape: S, distribution: Distribution, rng: &mut R, ) -> Self
Populates the data with random values.
sourcepub fn zeros<E: Element, S: Into<Vec<usize>>>(shape: S) -> TensorData
pub fn zeros<E: Element, S: Into<Vec<usize>>>(shape: S) -> TensorData
Populates the data with zeros.
sourcepub fn ones<E: Element, S: Into<Vec<usize>>>(shape: S) -> TensorData
pub fn ones<E: Element, S: Into<Vec<usize>>>(shape: S) -> TensorData
Populates the data with ones.
sourcepub fn full<E: Element, S: Into<Vec<usize>>>(
shape: S,
fill_value: E,
) -> TensorData
pub fn full<E: Element, S: Into<Vec<usize>>>( shape: S, fill_value: E, ) -> TensorData
Populates the data with the given value
sourcepub fn with_quantization(self, quantization: QuantizationStrategy) -> Self
pub fn with_quantization(self, quantization: QuantizationStrategy) -> Self
Applies the data quantization strategy.
§Panics
Panics if the data type is not supported for quantization.
sourcepub fn assert_approx_eq(&self, other: &Self, precision: usize)
pub fn assert_approx_eq(&self, other: &Self, precision: usize)
sourcepub fn assert_approx_eq_diff(&self, other: &Self, tolerance: f64)
pub fn assert_approx_eq_diff(&self, other: &Self, tolerance: f64)
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<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Display for TensorData
impl Display for TensorData
source§impl From<&[usize]> for TensorData
impl From<&[usize]> for TensorData
source§impl<Elem: Element, const A: usize, const B: usize, const C: usize, const D: usize, const E: usize> From<[[[[[Elem; E]; D]; C]; B]; A]> for TensorData
impl<Elem: Element, const A: usize, const B: usize, const C: usize, const D: usize, const E: usize> From<[[[[[Elem; E]; D]; C]; B]; A]> for TensorData
source§impl<E: Element, const A: usize, const B: usize, const C: usize, const D: usize> From<[[[[E; D]; C]; B]; A]> for TensorData
impl<E: Element, const A: usize, const B: usize, const C: usize, const D: usize> From<[[[[E; D]; C]; B]; A]> for TensorData
source§impl<E: Element, const A: usize, const B: usize, const C: usize> From<[[[E; C]; B]; A]> for TensorData
impl<E: Element, const A: usize, const B: usize, const C: usize> From<[[[E; C]; B]; A]> for TensorData
source§impl PartialEq for TensorData
impl PartialEq for TensorData
source§impl Serialize for TensorData
impl Serialize for TensorData
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
)