Skip to main content

TensorView

Struct TensorView 

Source
pub struct TensorView<'a> {
    pub data: DevicePtr,
    pub dtype: DataType,
    pub shape: &'a [usize],
    pub strides: &'a [i64],
    pub byte_offset: usize,
    pub device: DeviceId,
    pub backing: TensorBacking,
    /* private fields */
}
Expand description

Immutable, non-owning view of a tensor on any device.

Fields§

§data: DevicePtr§dtype: DataType§shape: &'a [usize]§strides: &'a [i64]

Strides in elements (may be negative, matching DLPack).

§byte_offset: usize

Offset in bytes of the element origin from data (DLPack semantics).

§device: DeviceId§backing: TensorBacking

Implementations§

Source§

impl<'a> TensorView<'a>

Source

pub fn new( data: DevicePtr, dtype: DataType, shape: &'a [usize], strides: &'a [i64], device: DeviceId, ) -> Self

Construct a zero-offset view. data must remain valid for 'a.

Source

pub fn absent(dtype: DataType) -> Self

Construct an absent view: the positional placeholder an executor passes for an omitted optional input (an ONNX empty-string input name). It carries a null pointer and an empty shape so it can never be read as a real tensor — kernels test TensorView::is_absent before touching an optional slot. This preserves positional arity so a later present input (e.g. Slice’s steps when axes is omitted) is not misread as the omitted one.

Source

pub fn is_absent(&self) -> bool

Whether this view is the TensorView::absent placeholder for an omitted optional input (null backing pointer). Kernels with optional inputs check this to distinguish “input not supplied” from a real, possibly-empty, tensor.

Source

pub fn with_byte_offset(self, byte_offset: usize) -> Self

Set the DLPack-style byte offset of the element origin.

Source

pub fn with_backing(self, backing: TensorBacking) -> Self

Source

pub fn validate(&self) -> Result<()>

Check the view’s invariants (rank, dtype, offset alignment). See [validate_view]; call this on any view imported from DLPack before use.

Source

pub fn is_contiguous(&self) -> bool

Whether the view is contiguous row-major.

Source

pub fn numel(&self) -> usize

Number of elements.

Source

pub fn byte_size(&self) -> usize

Logical element byte size (dense; ignores stride gaps). Uses storage_bytes so sub-byte (int4/uint4) types are counted correctly.

Source

pub fn data_ptr<T>(&self) -> *const T

Typed const pointer to the element origin, applying byte_offset. Computed with wrapping arithmetic (no deref) — safe to call.

Trait Implementations§

Source§

impl<'a> Clone for TensorView<'a>

Source§

fn clone(&self) -> TensorView<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for TensorView<'a>

Auto Trait Implementations§

§

impl<'a> !Send for TensorView<'a>

§

impl<'a> !Sync for TensorView<'a>

§

impl<'a> Freeze for TensorView<'a>

§

impl<'a> RefUnwindSafe 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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

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.