Struct burn::tensor::Data

source ·
pub struct Data<E, const D: usize> {
    pub value: Vec<E>,
    pub shape: Shape<D>,
}
Expand description

Data structure for tensors.

Fields§

§value: Vec<E>

The values of the tensor.

§shape: Shape<D>

The shape of the tensor.

Implementations§

source§

impl<E, const D: usize> Data<E, D>

source

pub fn new(value: Vec<E>, shape: Shape<D>) -> Data<E, D>

Constructs a new Data.

source§

impl<const D: usize, E> Data<E, D>
where E: Element,

source

pub fn convert<EOther>(self) -> Data<EOther, D>
where EOther: Element,

Converts the data to a different element type.

source

pub fn assert_within_range<EOther>(&self, range: Range<EOther>)
where EOther: Element,

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§

impl<const D: usize> Data<bool, D>

source

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

Converts the data to a different element type.

source§

impl<E, const D: usize> Data<E, D>
where E: Element,

source

pub fn random<R>( shape: Shape<D>, distribution: Distribution, rng: &mut R ) -> Data<E, D>
where R: RngCore,

Populates the data with random values.

source§

impl<E, const D: usize> Data<E, D>
where E: Debug + Element,

source

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

Populates the data with zeros.

source§

impl<E, const D: usize> Data<E, D>
where E: Debug + Element,

source

pub fn ones(shape: Shape<D>) -> Data<E, D>

Populates the data with ones.

source§

impl<E, const D: usize> Data<E, D>
where E: Debug + Element,

source

pub fn full(shape: Shape<D>, fill_value: E) -> Data<E, D>

Populates the data with the given value

source§

impl<E, const D: usize> Data<E, D>
where E: Debug + Copy,

source

pub fn serialize(&self) -> DataSerialize<E>

Serializes the data.

§Returns

The serialized data.

source§

impl<E, const D: usize> Data<E, D>
where E: Into<f64> + Clone + Debug + PartialEq,

source

pub fn assert_approx_eq(&self, other: &Data<E, D>, precision: usize)

Asserts the data is approximately equal to another data.

§Arguments
  • other - The other data.
  • precision - The precision of the comparison.
§Panics

Panics if the data is not approximately equal.

source

pub fn assert_approx_eq_diff(&self, other: &Data<E, D>, tolerance: f64)

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§

impl<const D: usize> Data<usize, D>

source

pub fn from_usize<O>(self) -> Data<O, D>
where O: FromPrimitive,

Converts the usize data to a different element type.

Trait Implementations§

source§

impl<E, const D: usize> Clone for Data<E, D>
where E: Clone,

source§

fn clone(&self) -> Data<E, D>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<E, const D: usize> Debug for Data<E, D>
where E: Debug,

source§

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

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

impl<E, const D: usize> Display for Data<E, D>
where E: Debug,

source§

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

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

impl<E> From<&[E]> for Data<E, 1>
where E: Debug + Copy,

source§

fn from(elems: &[E]) -> Data<E, 1>

Converts to this type from the input type.
source§

impl<E, const D: usize> From<&DataSerialize<E>> for Data<E, D>
where E: Clone,

source§

fn from(data: &DataSerialize<E>) -> Data<E, D>

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 Data<E, 4>
where E: Debug + Copy,

source§

fn from(elems: [[[[E; D]; C]; B]; A]) -> Data<E, 4>

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 Data<E, 3>
where E: Debug + Copy,

source§

fn from(elems: [[[E; C]; B]; A]) -> Data<E, 3>

Converts to this type from the input type.
source§

impl<E, const A: usize, const B: usize> From<[[E; B]; A]> for Data<E, 2>
where E: Debug + Copy,

source§

fn from(elems: [[E; B]; A]) -> Data<E, 2>

Converts to this type from the input type.
source§

impl<E, const A: usize> From<[E; A]> for Data<E, 1>
where E: Debug + Copy,

source§

fn from(elems: [E; A]) -> Data<E, 1>

Converts to this type from the input type.
source§

impl<E, const D: usize> From<DataSerialize<E>> for Data<E, D>

source§

fn from(data: DataSerialize<E>) -> Data<E, D>

Converts to this type from the input type.
source§

impl<E, const D: usize> PartialEq for Data<E, D>
where E: PartialEq,

source§

fn eq(&self, other: &Data<E, D>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<E, const D: usize> Eq for Data<E, D>
where E: Eq,

source§

impl<E, const D: usize> StructuralPartialEq for Data<E, D>

Auto Trait Implementations§

§

impl<E, const D: usize> Freeze for Data<E, D>

§

impl<E, const D: usize> RefUnwindSafe for Data<E, D>
where E: RefUnwindSafe,

§

impl<E, const D: usize> Send for Data<E, D>
where E: Send,

§

impl<E, const D: usize> Sync for Data<E, D>
where E: Sync,

§

impl<E, const D: usize> Unpin for Data<E, D>
where E: Unpin,

§

impl<E, const D: usize> UnwindSafe for Data<E, D>
where E: UnwindSafe,

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<T> Downcast<T> for T

source§

fn downcast(&self) -> &T

source§

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

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

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§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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.
source§

impl<T> Upcast<T> for T

source§

fn upcast(&self) -> Option<&T>

source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> WasmNotSend for T
where T: Send,

source§

impl<T> WasmNotSync for T
where T: Sync,