Skip to main content

TensorWrite

Enum TensorWrite 

Source
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>

Source

pub fn from_tensor(tensor: &'a mut Tensor) -> Self

Source

pub fn from_view(view: TensorViewMut<'a>) -> Self

Source

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);
Source

pub fn dtype(&self) -> DType

Source

pub fn shape(&self) -> &[usize]

Source

pub fn strides(&self) -> Result<Vec<isize>>

§Errors

Returns crate::Error::Validation with tenferro_tensor_core::ValidationError::IntegerOverflow when column-major stride arithmetic overflows.

Source

pub fn offset(&self) -> isize

Source

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.

Source

pub fn is_col_major_contiguous(&self) -> Result<bool>

§Errors

Returns crate::Error::Validation with tenferro_tensor_core::ValidationError::IntegerOverflow when compactness arithmetic overflows.

Source

pub fn layout_summary(&self) -> String

Source

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.

Trait Implementations§

Source§

impl<'a> Debug for TensorWrite<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSendSync for T
where T: Send + Sync,

§

impl<T> MaybeSync for T
where T: Sync,