pub enum TypedTensorWrite<'a, T> {
Tensor(&'a mut TypedTensor<T>),
View(TypedTensorViewMut<'a, T>),
}Expand description
Mutable typed tensor output accepted by synchronous eager kernels.
TypedTensorWrite is the typed counterpart to TensorWrite. It accepts
either an owned compact TypedTensor or an arbitrary-strided mutable
TypedTensorViewMut without erasing the scalar type at the public API
boundary.
§Examples
use tenferro_tensor::{TypedTensorViewMut, TypedTensorWrite};
let mut data = [0.0_f64, 1.0, 0.0, 2.0];
let view = TypedTensorViewMut::from_slice([2], [2], 1, &mut data)?;
let write = TypedTensorWrite::from_view(view).into_tensor_write();
assert_eq!(write.shape(), &[2]);
assert_eq!(write.strides()?, [2]);Variants§
Tensor(&'a mut TypedTensor<T>)
An owned compact typed tensor borrowed mutably for the write.
View(TypedTensorViewMut<'a, T>)
An arbitrary-strided mutable typed tensor view.
Implementations§
Source§impl<'a, T> TypedTensorWrite<'a, T>
impl<'a, T> TypedTensorWrite<'a, T>
Sourcepub fn from_tensor(tensor: &'a mut TypedTensor<T>) -> Self
pub fn from_tensor(tensor: &'a mut TypedTensor<T>) -> Self
Create a writable target from an owned typed tensor.
§Examples
use tenferro_tensor::{TypedTensor, TypedTensorWrite};
let mut tensor = TypedTensor::<f64>::from_vec_col_major(vec![1], vec![0.0])?;
let write = TypedTensorWrite::from_tensor(&mut tensor);
assert!(matches!(write, TypedTensorWrite::Tensor(_)));Sourcepub fn from_view(view: TypedTensorViewMut<'a, T>) -> Self
pub fn from_view(view: TypedTensorViewMut<'a, T>) -> Self
Create a writable target from a mutable typed tensor view.
§Examples
use tenferro_tensor::{TypedTensorViewMut, TypedTensorWrite};
let mut data = [0.0_f64, 1.0];
let view = TypedTensorViewMut::from_col_major(&[2], &mut data)?;
let write = TypedTensorWrite::from_view(view);
assert!(matches!(write, TypedTensorWrite::View(_)));Source§impl<'a, T: TensorScalar> TypedTensorWrite<'a, T>
impl<'a, T: TensorScalar> TypedTensorWrite<'a, T>
Sourcepub fn into_tensor_write(self) -> TensorWrite<'a>
pub fn into_tensor_write(self) -> TensorWrite<'a>
Erase the scalar type while preserving the output layout.
§Examples
use tenferro_tensor::{DType, TypedTensor, TypedTensorWrite};
let mut tensor = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![0.0; 2])?;
let write = TypedTensorWrite::from_tensor(&mut tensor).into_tensor_write();
assert_eq!(write.dtype(), DType::F64);
assert_eq!(write.shape(), &[2]);Trait Implementations§
Source§impl<'a, T: Debug> Debug for TypedTensorWrite<'a, T>
impl<'a, T: Debug> Debug for TypedTensorWrite<'a, T>
Source§impl<'a, T> From<&'a mut TypedTensor<T>> for TypedTensorWrite<'a, T>
impl<'a, T> From<&'a mut TypedTensor<T>> for TypedTensorWrite<'a, T>
Source§fn from(tensor: &'a mut TypedTensor<T>) -> Self
fn from(tensor: &'a mut TypedTensor<T>) -> Self
Converts to this type from the input type.
Source§impl<'a, T> From<TypedTensorViewMut<'a, T>> for TypedTensorWrite<'a, T>
impl<'a, T> From<TypedTensorViewMut<'a, T>> for TypedTensorWrite<'a, T>
Source§fn from(view: TypedTensorViewMut<'a, T>) -> Self
fn from(view: TypedTensorViewMut<'a, T>) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl<'a, T> Freeze for TypedTensorWrite<'a, T>
impl<'a, T> !RefUnwindSafe for TypedTensorWrite<'a, T>
impl<'a, T> Send for TypedTensorWrite<'a, T>where
T: Send,
impl<'a, T> Sync for TypedTensorWrite<'a, T>where
T: Sync,
impl<'a, T> Unpin for TypedTensorWrite<'a, T>
impl<'a, T> UnsafeUnpin for TypedTensorWrite<'a, T>
impl<'a, T> !UnwindSafe for TypedTensorWrite<'a, T>
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
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