pub struct ValueGuard<'a> { /* private fields */ }Expand description
A read-only value view retained by an eager tensor record.
The guard borrows the record’s allocation group. It never owns a tensor and cannot be converted into a mutable view.
§Examples
use tenferro_ad::{EagerRuntime, EagerTensor, Tensor};
use tenferro_cpu::CpuBackend;
let ctx = EagerRuntime::with_cpu_backend(CpuBackend::new())?;
let value = EagerTensor::from_tensor_in(
Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0])?,
ctx,
)?;
let view = value.value()?;
assert_eq!(view.shape(), &[2]);Implementations§
Source§impl<'a> ValueGuard<'a>
impl<'a> ValueGuard<'a>
Sourcepub fn as_tensor_view(&self) -> &TensorView<'_>
pub fn as_tensor_view(&self) -> &TensorView<'_>
Borrow the dtype-erased tensor view.
Sourcepub fn as_slice<T: TensorScalar>(&self) -> Result<&'a [T]>
pub fn as_slice<T: TensorScalar>(&self) -> Result<&'a [T]>
Borrow compact host bytes through the tensor’s explicit scalar type.
Backend-resident values return the backend’s typed host-access error; this method does not download storage implicitly.
§Errors
Returns tenferro_tensor::ValidationError::DTypeMismatch when
T does not match the view dtype, tenferro_tensor::ValidationError::NonContiguousViewAsSlice
for a non-contiguous view, or tenferro_tensor::Error::HostAccess
when backend storage cannot be mapped as a host slice.
Trait Implementations§
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for ValueGuard<'a>
impl<'a> !UnwindSafe for ValueGuard<'a>
impl<'a> Freeze for ValueGuard<'a>
impl<'a> Send for ValueGuard<'a>
impl<'a> Sync for ValueGuard<'a>
impl<'a> Unpin for ValueGuard<'a>
impl<'a> UnsafeUnpin for ValueGuard<'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
Mutably borrows from an owned value. Read more
impl<T, U> Imply<T> for U
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>
Converts
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>
Converts
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