Skip to main content

TensorDataView

Struct TensorDataView 

Source
pub struct TensorDataView<'a, E: Element> { /* private fields */ }
Expand description

Typed Index view over a TensorData.

Creating a view materializes lazy storage into host-accessible memory when necessary. It does not perform dtype conversion.

§Example

use burn_std::*;

let data = TensorData::from([[1.0, 2.0], [3.0, 4.0]]);
let view: TensorDataView<f64> = data.view();

assert_eq!(view.shape(), &data.shape);
assert_eq!(&view.dtype(), &data.dtype);

assert_eq!(view[&[0, 0]], 1.0);
assert_eq!(view[&[0, 1]], 2.0);
assert_eq!(view[&[1, 0]], 3.0);
assert_eq!(view[&[1, 1]], 4.0);

Implementations§

Source§

impl<'a, E: Element> TensorDataView<'a, E>

Source

pub fn try_view( data: &'a TensorData, ) -> Result<TensorDataView<'a, E>, DataError>

Creates a typed indexed view over data.

§Example
use burn_std::*;

let data = TensorData::from([[1.0, 2.0], [3.0, 4.0]]);
let view: TensorDataView<f64> = data.try_view().unwrap();

assert_eq!(view.shape(), &data.shape);
assert_eq!(&view.dtype(), &data.dtype);

assert_eq!(view[&[0, 0]], 1.0);
assert_eq!(view[&[0, 1]], 2.0);
assert_eq!(view[&[1, 0]], 3.0);
assert_eq!(view[&[1, 1]], 4.0);
§Errors

Returns an error if storage access fails or the dtype, byte representation, or element count is incompatible with E.

Source

pub fn shape(&self) -> &Shape

Returns the shape of the view.

Source

pub fn dtype(&self) -> DType

Returns the dtype of the view.

Source

pub fn ravel_index<I: AsIndex>(&self, index: &[I]) -> usize

Ravels the index via ravel_index and the view’s shape.

Trait Implementations§

Source§

impl<'a, E: Debug + Element> Debug for TensorDataView<'a, E>

Source§

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

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

impl<'a, I: AsIndex, E: Element> Index<&[I]> for TensorDataView<'a, E>

Source§

type Output = E

The returned type after indexing.
Source§

fn index(&self, index: &[I]) -> &Self::Output

Performs the indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<'a, E> Freeze for TensorDataView<'a, E>
where &'a [E]: Freeze,

§

impl<'a, E> RefUnwindSafe for TensorDataView<'a, E>
where &'a [E]: RefUnwindSafe,

§

impl<'a, E> Send for TensorDataView<'a, E>
where &'a [E]: Send,

§

impl<'a, E> Sync for TensorDataView<'a, E>
where &'a [E]: Sync,

§

impl<'a, E> Unpin for TensorDataView<'a, E>
where &'a [E]: Unpin,

§

impl<'a, E> UnsafeUnpin for TensorDataView<'a, E>
where &'a [E]: UnsafeUnpin,

§

impl<'a, E> UnwindSafe for TensorDataView<'a, E>
where &'a [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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = !

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

Source§

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.