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]
Sourcepub fn strides(&self) -> Result<Vec<isize>>
pub fn strides(&self) -> Result<Vec<isize>>
§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>
pub fn layout_linear_offset(&self, indices: &[usize]) -> Result<usize>
§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>
pub fn is_col_major_contiguous(&self) -> Result<bool>
§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<()>
pub fn assert_col_major_contiguous(&self) -> Result<()>
§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.