pub enum TensorWrite<'a> {
Tensor(&'a mut Tensor),
View(TensorViewMut<'a>),
}Expand description
Mutable tensor output accepted by synchronous eager kernels.
TensorWrite mirrors TensorRead for output dispatch: it can target an
owned compact Tensor or a borrowed mutable TensorViewMut. The target
is never resized.
§Examples
use tenferro_tensor::{Tensor, TensorWrite};
let mut tensor = Tensor::from_vec_col_major(vec![1], vec![0.0_f64])?;
let write = TensorWrite::from_tensor(&mut tensor);
assert_eq!(write.shape(), &[1]);Variants§
Tensor(&'a mut Tensor)
View(TensorViewMut<'a>)
Implementations§
Source§impl<'a> TensorWrite<'a>
impl<'a> TensorWrite<'a>
pub fn from_tensor(tensor: &'a mut Tensor) -> Self
pub fn from_view(view: TensorViewMut<'a>) -> Self
Sourcepub fn as_read(&self) -> TensorRead<'_>
pub fn as_read(&self) -> TensorRead<'_>
Borrow this writable target as a read-only tensor input.
This is useful for explicit read-modify-write kernels such as
accumulation updates. The returned view borrows through &self, so it
cannot outlive the current read-only borrow of the writable target.
§Examples
use tenferro_tensor::{DType, Tensor, TensorWrite};
let mut tensor = Tensor::from_vec_col_major(vec![1], vec![2.0_f64])?;
let write = TensorWrite::from_tensor(&mut tensor);
let read = write.as_read();
assert_eq!(read.dtype(), DType::F64);pub fn dtype(&self) -> DType
pub fn shape(&self) -> &[usize]
pub fn strides(&self) -> Result<Vec<isize>>
pub fn offset(&self) -> isize
pub fn layout_linear_offset(&self, indices: &[usize]) -> Result<usize>
pub fn is_col_major_contiguous(&self) -> Result<bool>
pub fn layout_summary(&self) -> String
pub fn assert_col_major_contiguous(&self) -> Result<()>
pub fn copy_from_tensor(&mut self, src: &Tensor) -> Result<()>
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for TensorWrite<'a>
impl<'a> !RefUnwindSafe for TensorWrite<'a>
impl<'a> Send for TensorWrite<'a>
impl<'a> Sync for TensorWrite<'a>
impl<'a> Unpin for TensorWrite<'a>
impl<'a> UnsafeUnpin for TensorWrite<'a>
impl<'a> !UnwindSafe for TensorWrite<'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