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>
impl<'a> TensorRead<'a>
pub fn from_tensor(tensor: &'a Tensor) -> TensorRead<'a>
pub fn from_view(view: TensorView<'a>) -> TensorRead<'a>
pub fn dtype(&self) -> DType
pub fn shape(&self) -> &[usize]
pub fn as_tensor(&self) -> Option<&'a Tensor>
Sourcepub fn to_tensor(&self) -> Result<Tensor, Error>
pub fn to_tensor(&self) -> Result<Tensor, Error>
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>
impl<'a> Clone for TensorRead<'a>
Source§fn clone(&self) -> TensorRead<'a>
fn clone(&self) -> TensorRead<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more