Skip to main content

TensorRead

Enum TensorRead 

Source
pub enum TensorRead<'a> {
    Tensor(&'a Tensor),
    View(TensorView<'a>),
}
Expand description

Read-only tensor input accepted by synchronous eager kernels.

TensorRead lets kernels accept either an owned tensor reference or a borrowed TensorView without forcing callers to materialize first. The View variant preserves arbitrary strides and offsets, so kernels that support strided reads can consume transposes, slices, and broadcasts directly.

TensorRead is intentionally borrowed. It is an input-dispatch type, not an owned lazy tensor value. APIs that need to store a lazy layout result should keep an owned base tensor plus layout metadata, then expose a TensorRead only for the duration of kernel dispatch.

§Examples

use tenferro_tensor::{DType, Tensor, TensorRead};

let tensor = Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0]).unwrap();
let read = TensorRead::from_tensor(&tensor);

assert_eq!(read.dtype(), DType::F64);
assert_eq!(read.shape(), &[2]);

Variants§

§

Tensor(&'a Tensor)

§

View(TensorView<'a>)

Implementations§

Source§

impl<'a> TensorRead<'a>

Source

pub fn from_tensor(tensor: &'a Tensor) -> Self

Source

pub fn from_view(view: TensorView<'a>) -> Self

Source

pub fn dtype(&self) -> DType

Source

pub fn shape(&self) -> &[usize]

Source

pub fn as_tensor(&self) -> Option<&'a Tensor>

Source

pub fn to_tensor(&self) -> Result<Tensor>

Convert an owned tensor reference or host view into an owned tensor.

This method clones owned tensor inputs and materializes host views. It has no backend context and does not download backend buffers. Use a backend-specific TensorViewCanonicalization method or an explicit device transfer before materializing backend views on the host.

§Examples
use tenferro_tensor::{TensorRead, TensorView};

let data = [1_i32, 2, 3];
let read = TensorRead::from_view(TensorView::i32(&[3], &data)?);
let tensor = read.to_tensor()?;
assert_eq!(tensor.shape(), &[3]);

Trait Implementations§

Source§

impl<'a> Clone for TensorRead<'a>

Source§

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

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for TensorRead<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for TensorRead<'a>

§

impl<'a> !RefUnwindSafe for TensorRead<'a>

§

impl<'a> Send for TensorRead<'a>

§

impl<'a> Sync for TensorRead<'a>

§

impl<'a> Unpin for TensorRead<'a>

§

impl<'a> UnsafeUnpin for TensorRead<'a>

§

impl<'a> !UnwindSafe for TensorRead<'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.