Skip to main content

TensorViewMut

Enum TensorViewMut 

Source
pub enum TensorViewMut<'a> {
    F32(TypedTensorViewMut<'a, f32>),
    F64(TypedTensorViewMut<'a, f64>),
    I32(TypedTensorViewMut<'a, i32>),
    I64(TypedTensorViewMut<'a, i64>),
    Bool(TypedTensorViewMut<'a, bool>),
    C32(TypedTensorViewMut<'a, Complex<f32>>),
    C64(TypedTensorViewMut<'a, Complex<f64>>),
}
Expand description

Dynamic mutable borrowed tensor view.

TensorViewMut is the mutable counterpart to TensorView. It keeps the dtype erased while preserving the typed mutable view’s shape, strides, and offset metadata.

§Examples

use tenferro_tensor::{DType, TensorViewMut, TypedTensorViewMut};

let mut data = [1.0_f64, 2.0];
let view = TensorViewMut::F64(TypedTensorViewMut::from_slice([2], [1], 0, &mut data)?);
assert_eq!(view.dtype(), DType::F64);

Variants§

Implementations§

Source§

impl<'a> TensorViewMut<'a>

Source

pub fn f32(shape: &'a [usize], data: &'a mut [f32]) -> Result<Self>

Create a dynamic mutable view over compact column-major host data.

§Errors

Returns crate::Error::Validation with tenferro_tensor_core::ValidationError::IntegerOverflow when compact layout arithmetic overflows, or tenferro_tensor_core::ValidationError::InvalidArgument when the requested shape exceeds data.

Source

pub fn f64(shape: &'a [usize], data: &'a mut [f64]) -> Result<Self>

Create a dynamic mutable view over compact column-major host data.

§Errors

Returns crate::Error::Validation with tenferro_tensor_core::ValidationError::IntegerOverflow when compact layout arithmetic overflows, or tenferro_tensor_core::ValidationError::InvalidArgument when the requested shape exceeds data.

Source

pub fn i32(shape: &'a [usize], data: &'a mut [i32]) -> Result<Self>

Create a dynamic mutable view over compact column-major host data.

§Errors

Returns crate::Error::Validation with tenferro_tensor_core::ValidationError::IntegerOverflow when compact layout arithmetic overflows, or tenferro_tensor_core::ValidationError::InvalidArgument when the requested shape exceeds data.

Source

pub fn i64(shape: &'a [usize], data: &'a mut [i64]) -> Result<Self>

Create a dynamic mutable view over compact column-major host data.

§Errors

Returns crate::Error::Validation with tenferro_tensor_core::ValidationError::IntegerOverflow when compact layout arithmetic overflows, or tenferro_tensor_core::ValidationError::InvalidArgument when the requested shape exceeds data.

Source

pub fn bool(shape: &'a [usize], data: &'a mut [bool]) -> Result<Self>

Create a dynamic mutable view over compact column-major host data.

§Errors

Returns crate::Error::Validation with tenferro_tensor_core::ValidationError::IntegerOverflow when compact layout arithmetic overflows, or tenferro_tensor_core::ValidationError::InvalidArgument when the requested shape exceeds data.

Source

pub fn c32(shape: &'a [usize], data: &'a mut [Complex32]) -> Result<Self>

Create a dynamic mutable view over compact column-major host data.

§Errors

Returns crate::Error::Validation with tenferro_tensor_core::ValidationError::IntegerOverflow when compact layout arithmetic overflows, or tenferro_tensor_core::ValidationError::InvalidArgument when the requested shape exceeds data.

Source

pub fn c64(shape: &'a [usize], data: &'a mut [Complex64]) -> Result<Self>

Create a dynamic mutable view over compact column-major host data.

§Errors

Returns crate::Error::Validation with tenferro_tensor_core::ValidationError::IntegerOverflow when compact layout arithmetic overflows, or tenferro_tensor_core::ValidationError::InvalidArgument when the requested shape exceeds data.

Source

pub fn dtype(&self) -> DType

Source

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

Source

pub fn strides(&self) -> &[isize]

Source

pub fn offset(&self) -> isize

Source

pub fn layout_linear_offset(&self, indices: &[usize]) -> Result<usize>

Compute the physical element offset for a logical index.

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

Return whether this view is compact column-major.

§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<()>

Assert this view is compact column-major.

§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.

Source

pub fn as_read_only(&self) -> TensorView<'_>

Trait Implementations§

Source§

impl<'a> Debug for TensorViewMut<'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 TensorViewMut<'a>

§

impl<'a> !RefUnwindSafe for TensorViewMut<'a>

§

impl<'a> Send for TensorViewMut<'a>

§

impl<'a> Sync for TensorViewMut<'a>

§

impl<'a> Unpin for TensorViewMut<'a>

§

impl<'a> UnsafeUnpin for TensorViewMut<'a>

§

impl<'a> !UnwindSafe for TensorViewMut<'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,