Skip to main content

ColMajorViewMut

Struct ColMajorViewMut 

Source
pub struct ColMajorViewMut<'a, T, const N: usize> { /* private fields */ }
Expand description

Exclusive view of a validated compact column-major host tensor with rank N.

Mutable traversal yields disjoint references through Rust slice iterators.

§Examples

use tenferro_tensor::{Rank, TypedTensor};
let mut tensor = TypedTensor::<i32, Rank<1>>::from_vec_col_major([2], vec![1, 2])?;
let mut view = tensor.host_col_major_view_mut()?;
if let Some(value) = view.get_mut([1]) { *value = 7; }
assert_eq!(view.as_slice(), &[1, 7]);

Implementations§

Source§

impl<'a, T, const N: usize> ColMajorViewMut<'a, T, N>

Source

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

Return the const-generic logical shape.

§Examples
use tenferro_tensor::{Rank, TypedTensor};
let mut tensor = TypedTensor::<f64, Rank<2>>::zeros([2, 3])?;
assert_eq!(tensor.host_col_major_view_mut()?.shape(), &[2, 3]);
Source

pub fn as_slice(&self) -> &[T]

Return the exact logical slice in column-major order.

§Examples
use tenferro_tensor::{Rank, TypedTensor};
let mut tensor = TypedTensor::<i32, Rank<1>>::from_vec_col_major([2], vec![4, 5])?;
assert_eq!(tensor.host_col_major_view_mut()?.as_slice(), &[4, 5]);
Source

pub fn as_mut_slice(&mut self) -> &mut [T]

Return the exact mutable logical slice in column-major order.

§Examples
use tenferro_tensor::{Rank, TypedTensor};
let mut tensor = TypedTensor::<i32, Rank<1>>::from_vec_col_major([1], vec![4])?;
*tensor.host_col_major_view_mut()?.as_mut_slice().first_mut().unwrap() = 9;
assert_eq!(tensor.as_slice()?, &[9]);
Source

pub fn iter(&self) -> Iter<'_, T>

Iterate immutably in linear column-major order.

§Examples
use tenferro_tensor::{Rank, TypedTensor};
let mut tensor = TypedTensor::<i32, Rank<1>>::from_vec_col_major([2], vec![4, 5])?;
assert_eq!(tensor.host_col_major_view_mut()?.iter().copied().sum::<i32>(), 9);
Source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Iterate mutably in linear column-major order.

§Examples
use tenferro_tensor::{Rank, TypedTensor};
let mut tensor = TypedTensor::<i32, Rank<1>>::from_vec_col_major([2], vec![1, 2])?;
for value in tensor.host_col_major_view_mut()?.iter_mut() { *value += 1; }
assert_eq!(tensor.as_slice()?, &[2, 3]);
Source

pub fn get(&self, index: [usize; N]) -> Option<&T>

Return an element when every index is in bounds.

§Examples
use tenferro_tensor::{Rank, TypedTensor};
let mut tensor = TypedTensor::<i32, Rank<1>>::from_vec_col_major([2], vec![4, 5])?;
assert_eq!(tensor.host_col_major_view_mut()?.get([1]), Some(&5));
Source

pub fn get_mut(&mut self, index: [usize; N]) -> Option<&mut T>

Return a mutable element when every index is in bounds.

§Examples
use tenferro_tensor::{Rank, TypedTensor};
let mut tensor = TypedTensor::<i32, Rank<1>>::from_vec_col_major([2], vec![4, 5])?;
*tensor.host_col_major_view_mut()?.get_mut([1]).unwrap() = 8;
assert_eq!(tensor.as_slice()?, &[4, 8]);
Source

pub unsafe fn get_unchecked(&self, index: [usize; N]) -> &T

Return an element without checking rank, bounds, backend, or layout.

§Safety

The caller must ensure index[axis] < self.shape()[axis] for every axis.

§Examples
use tenferro_tensor::{Rank, TypedTensor};
let mut tensor = TypedTensor::<i32, Rank<1>>::from_vec_col_major([1], vec![4])?;
let view = tensor.host_col_major_view_mut()?;
// SAFETY: index 0 is below the only axis extent, 1.
assert_eq!(unsafe { view.get_unchecked([0]) }, &4);
Source

pub unsafe fn get_unchecked_mut(&mut self, index: [usize; N]) -> &mut T

Return a mutable element without checking rank, bounds, backend, or layout.

§Safety

The caller must ensure index[axis] < self.shape()[axis] for every axis and must not retain overlapping mutable references.

§Examples
use tenferro_tensor::{Rank, TypedTensor};
let mut tensor = TypedTensor::<i32, Rank<1>>::from_vec_col_major([1], vec![4])?;
let mut view = tensor.host_col_major_view_mut()?;
// SAFETY: index 0 is in bounds and this is the only active element borrow.
*unsafe { view.get_unchecked_mut([0]) } = 7;
assert_eq!(view.as_slice(), &[7]);
Source

pub fn axis0_lanes(&self) -> ChunksExact<'_, T>

Iterate immutably over contiguous first-axis lanes.

§Examples
use tenferro_tensor::{Rank, TypedTensor};
let mut tensor = TypedTensor::<i32, Rank<2>>::from_vec_col_major([2, 1], vec![1, 2])?;
assert_eq!(tensor.host_col_major_view_mut()?.axis0_lanes().next(), Some(&[1, 2][..]));
Source

pub fn axis0_lanes_mut(&mut self) -> ChunksExactMut<'_, T>

Iterate mutably over disjoint contiguous first-axis lanes.

§Examples
use tenferro_tensor::{Rank, TypedTensor};
let mut tensor = TypedTensor::<i32, Rank<2>>::from_vec_col_major([2, 2], vec![1, 2, 3, 4])?;
for lane in tensor.host_col_major_view_mut()?.axis0_lanes_mut() { lane[0] *= 10; }
assert_eq!(tensor.as_slice()?, &[10, 2, 30, 4]);

Trait Implementations§

Source§

impl<T, const N: usize> Debug for ColMajorViewMut<'_, T, N>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, T, const N: usize> !UnwindSafe for ColMajorViewMut<'a, T, N>

§

impl<'a, T, const N: usize> Freeze for ColMajorViewMut<'a, T, N>

§

impl<'a, T, const N: usize> RefUnwindSafe for ColMajorViewMut<'a, T, N>
where T: RefUnwindSafe,

§

impl<'a, T, const N: usize> Send for ColMajorViewMut<'a, T, N>
where T: Send,

§

impl<'a, T, const N: usize> Sync for ColMajorViewMut<'a, T, N>
where T: Sync,

§

impl<'a, T, const N: usize> Unpin for ColMajorViewMut<'a, T, N>

§

impl<'a, T, const N: usize> UnsafeUnpin for ColMajorViewMut<'a, T, N>

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