Skip to main content

TensorDataViewMut

Struct TensorDataViewMut 

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

Typed mutable IndexMut view over a TensorData.

Creating a mutable view materializes lazy storage and performs copy-on-write when necessary. It does not perform dtype conversion.

§Example

use burn_std::*;

let mut data = TensorData::from([[1.0, 2.0], [3.0, 4.0]]);
let shape = data.shape.clone();
let dtype = data.dtype;
let mut view: TensorDataViewMut<f64> = data.mut_view();

assert_eq!(view.shape(), &shape);
assert_eq!(&view.dtype(), &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);

view[&[0, 0]] = 10.0;
assert_eq!(view[&[0, 0]], 10.0);

Implementations§

Source§

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

Source

pub fn try_mut_view( data: &'a mut TensorData, ) -> Result<TensorDataViewMut<'a, E>, DataError>

Creates a typed mutable indexed view over data.

§Example
use burn_std::*;

let mut data = TensorData::from([[1.0, 2.0], [3.0, 4.0]]);
let shape = data.shape.clone();
let dtype = data.dtype;

let mut view: TensorDataViewMut<f64> =
    TensorDataViewMut::try_mut_view(&mut data).unwrap();

assert_eq!(view.shape(), &shape);
assert_eq!(&view.dtype(), &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);

view[&[0, 0]] = 10.0;
assert_eq!(view[&[0, 0]], 10.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 dims via ravel_index and the view’s shape.

Trait Implementations§

Source§

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

Source§

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

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

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

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
Source§

impl<'a, I, E> IndexMut<&[I]> for TensorDataViewMut<'a, E>
where I: AsIndex, E: Element,

Source§

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

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

Auto Trait Implementations§

§

impl<'a, E> !UnwindSafe for TensorDataViewMut<'a, E>

§

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

§

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

§

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

§

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

§

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

§

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

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.