Skip to main content

TensorRef

Struct TensorRef 

Source
pub struct TensorRef<'a, T, const N: usize>
where T: DeviceRepr + Copy + 'static,
{ pub data: DeviceSlice<'a, T>, pub shape: [i32; N], pub stride: [i64; N], }
Expand description

Read-only view of a device-resident rank-N tensor.

shape[i] is the extent along axis i. stride[i] is the element stride along axis i (memory offset to advance one step along that axis). A stride of 0 along an axis signals a broadcast operand — the kernel reads the same memory cell for every step along that axis. The default row-major contiguous stride for shape [d0, d1, …, dN-1] is [d1·d2·…·dN-1, …, dN-1, 1].

T is bounded by DeviceRepr only (not by crate::Element / crate::IntElement) so the same view struct can carry any scalar payload — input, output, mask, or auxiliary buffer. The per-op element-class enforcement happens at the Plan layer.

Fields§

§data: DeviceSlice<'a, T>

Device-resident element storage.

§shape: [i32; N]

Extent along each axis (in elements).

§stride: [i64; N]

Element stride along each axis. Stride 0 marks a broadcast axis.

Implementations§

Source§

impl<'a, T, const N: usize> TensorRef<'a, T, N>
where T: DeviceRepr + Copy + 'static,

Source

pub fn numel(&self) -> i64

Total number of logical elements (product of shape).

Returns 1 for the rank-0 (scalar) case. Saturates on overflow rather than wrapping — a tensor with overflowing element count cannot fit in CUDA’s int64_t element-count surface anyway, so reporting i64::MAX is a fine sentinel.

Source

pub fn is_contiguous(&self) -> bool

true iff stride matches the standard row-major contiguous layout (rightmost axis has stride 1; each prior axis multiplies by the extent to its right).

The rank-0 case is always contiguous. A broadcast tensor (any stride[i] == 0) is not contiguous.

Trait Implementations§

Source§

impl<'a, T, const N: usize> Clone for TensorRef<'a, T, N>
where T: Clone + DeviceRepr + Copy + 'static,

Source§

fn clone(&self) -> TensorRef<'a, T, N>

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, T, const N: usize> Copy for TensorRef<'a, T, N>
where T: Copy + DeviceRepr + 'static,

Source§

impl<'a, T, const N: usize> Debug for TensorRef<'a, T, N>
where T: Debug + DeviceRepr + Copy + 'static,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, T, const N: usize> Freeze for TensorRef<'a, T, N>

§

impl<'a, T, const N: usize> RefUnwindSafe for TensorRef<'a, T, N>
where T: RefUnwindSafe,

§

impl<'a, T, const N: usize> Send for TensorRef<'a, T, N>
where T: Sync,

§

impl<'a, T, const N: usize> Sync for TensorRef<'a, T, N>
where T: Sync,

§

impl<'a, T, const N: usize> Unpin for TensorRef<'a, T, N>

§

impl<'a, T, const N: usize> UnsafeUnpin for TensorRef<'a, T, N>

§

impl<'a, T, const N: usize> UnwindSafe for TensorRef<'a, T, N>
where T: RefUnwindSafe,

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.