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>
impl<'a, E: Element> TensorDataView<'a, E>
Sourcepub fn try_view(
data: &'a TensorData,
) -> Result<TensorDataView<'a, E>, DataError>
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.
Sourcepub fn ravel_index<I: AsIndex>(&self, index: &[I]) -> usize
pub fn ravel_index<I: AsIndex>(&self, index: &[I]) -> usize
Ravels the index via ravel_index and the view’s shape.
Trait Implementations§
Auto Trait Implementations§
impl<'a, E> Freeze for TensorDataView<'a, E>
impl<'a, E> RefUnwindSafe for TensorDataView<'a, E>where
&'a [E]: RefUnwindSafe,
impl<'a, E> Send for TensorDataView<'a, E>
impl<'a, E> Sync for TensorDataView<'a, E>
impl<'a, E> Unpin for TensorDataView<'a, E>
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> 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
Mutably borrows from an owned value. Read more