pub struct TensorView<'a> { /* private fields */ }Expand description
A read-only, type-erased window into a tensor’s plain storage: the bytes from the
view’s origin to the end of the storage, read through shape and strides (in
items, never negative).
Typed access checks the datum type, the alignment and the extent against those
bytes. as_slice reads len() contiguous items from the origin, which only
matches the view’s logical content when its strides are natural.
Implementations§
Source§impl<'a> TensorView<'a>
impl<'a> TensorView<'a>
Sourcepub fn from_bytes(
tensor: &'a Tensor,
offset_bytes: usize,
shape: &'a [usize],
strides: &'a [isize],
) -> TractResult<TensorView<'a>>
pub fn from_bytes( tensor: &'a Tensor, offset_bytes: usize, shape: &'a [usize], strides: &'a [isize], ) -> TractResult<TensorView<'a>>
A view of tensor’s storage starting offset_bytes in, read with shape and
strides. Errors if the offset is past the end of the storage.
Sourcepub fn from_pod_bytes(
dt: DatumType,
bytes: &'a [u8],
shape: &'a [usize],
strides: &'a [isize],
) -> TractResult<TensorView<'a>>
pub fn from_pod_bytes( dt: DatumType, bytes: &'a [u8], shape: &'a [usize], strides: &'a [isize], ) -> TractResult<TensorView<'a>>
A view over raw bytes holding dt items. Only for datum types where every bit
pattern is a valid value.
pub fn datum_type(&self) -> DatumType
pub fn shape(&self) -> &'a [usize]
pub fn strides(&self) -> &'a [isize]
pub fn rank(&self) -> usize
Sourcepub fn offset_axis(&mut self, axis: usize, pos: usize) -> TractResult<()>
pub fn offset_axis(&mut self, axis: usize, pos: usize) -> TractResult<()>
Moves the view’s origin pos steps along axis, keeping its shape and strides.
Sourcepub fn as_ptr<D: Datum>(&self) -> TractResult<*const D>
pub fn as_ptr<D: Datum>(&self) -> TractResult<*const D>
The view’s origin, typed. Errors on a datum type mismatch.
Sourcepub unsafe fn as_ptr_unchecked<D: Datum>(&self) -> *const D
pub unsafe fn as_ptr_unchecked<D: Datum>(&self) -> *const D
The view’s origin, cast to D without checking the datum type.
Sourcepub fn as_slice<D: Datum>(&self) -> TractResult<&'a [D]>
pub fn as_slice<D: Datum>(&self) -> TractResult<&'a [D]>
len() contiguous items from the view’s origin.
Sourcepub unsafe fn as_slice_unchecked<D: Datum>(&self) -> &'a [D]
pub unsafe fn as_slice_unchecked<D: Datum>(&self) -> &'a [D]
Like Self::as_slice, without checking the datum type, alignment or extent.
Trait Implementations§
Source§impl<'a> Clone for TensorView<'a>
impl<'a> Clone for TensorView<'a>
impl<'a> Copy for TensorView<'a>
Auto Trait Implementations§
impl<'a> Forget for TensorView<'a>
impl<'a> Freeze for TensorView<'a>
impl<'a> Move for TensorView<'a>
impl<'a> RefUnwindSafe for TensorView<'a>
impl<'a> Send for TensorView<'a>
impl<'a> Sync for TensorView<'a>
impl<'a> Unpin for TensorView<'a>
impl<'a> UnsafeUnpin for TensorView<'a>
impl<'a> UnwindSafe for TensorView<'a>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more