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>
Sourcepub fn tensor_view(self) -> TensorView<'a>
pub fn tensor_view(self) -> TensorView<'a>
Convert this read target into a dtype-erased tensor view.
Owned tensors are borrowed without copying their storage. Existing views preserve their layout and placement metadata.
pub fn dtype(&self) -> DType
pub fn shape(&self) -> &[usize]
Sourcepub fn placement(&self) -> &Placement
pub fn placement(&self) -> &Placement
Return the placement metadata carried by this read target.
§Examples
use tenferro_tensor::{MemoryKind, Tensor, TensorRead};
let tensor = Tensor::from_vec_col_major(vec![1], vec![1.0_f64])?;
let read = TensorRead::from_tensor(&tensor);
assert_eq!(read.placement().memory_kind, MemoryKind::UnpinnedHost);Sourcepub fn backend_family(&self) -> Option<&'static str>
pub fn backend_family(&self) -> Option<&'static str>
Return the physical backend family of this read target, when backend-owned.
§Examples
use tenferro_tensor::{Tensor, TensorRead};
let tensor = Tensor::from_vec_col_major(vec![1], vec![1.0_f64])?;
assert_eq!(TensorRead::from_tensor(&tensor).backend_family(), None);Sourcepub fn allocation_domain(&self) -> Option<AllocationDomainId>
pub fn allocation_domain(&self) -> Option<AllocationDomainId>
Return the shared allocation domain of this read target, when present.
§Examples
use tenferro_tensor::{Tensor, TensorRead};
let tensor = Tensor::from_vec_col_major(vec![1], vec![1.0_f64])?;
assert_eq!(TensorRead::from_tensor(&tensor).allocation_domain(), None);Sourcepub fn strides(&self) -> Result<Vec<isize>, Error>
pub fn strides(&self) -> Result<Vec<isize>, Error>
§Errors
Returns crate::Error::Validation with
tenferro_tensor_core::ValidationError::IntegerOverflow when
column-major stride arithmetic overflows.
pub fn offset(&self) -> isize
Sourcepub fn layout_linear_offset(&self, indices: &[usize]) -> Result<usize, Error>
pub fn layout_linear_offset(&self, indices: &[usize]) -> Result<usize, Error>
§Errors
Returns crate::Error::Validation with
tenferro_tensor_core::ValidationError::RankMismatch when indices
has the wrong rank, tenferro_tensor_core::ValidationError::InvalidArgument
when an index is outside its axis extent, or
tenferro_tensor_core::ValidationError::IntegerOverflow when offset
arithmetic overflows.
Sourcepub fn is_col_major_contiguous(&self) -> Result<bool, Error>
pub fn is_col_major_contiguous(&self) -> Result<bool, Error>
§Errors
Returns crate::Error::Validation with
tenferro_tensor_core::ValidationError::IntegerOverflow when
compactness arithmetic overflows.
pub fn layout_summary(&self) -> String
Sourcepub fn assert_col_major_contiguous(&self) -> Result<(), Error>
pub fn assert_col_major_contiguous(&self) -> Result<(), Error>
§Errors
Returns crate::Error::Validation with
tenferro_tensor_core::ValidationError::IntegerOverflow when
compactness arithmetic overflows, or
tenferro_tensor_core::ValidationError::InvalidArgument when the
view is not compact column-major.
pub fn as_tensor(&self) -> Option<&'a Tensor>
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 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto 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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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