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>
impl<'a, T, const N: usize> ColMajorViewMut<'a, T, N>
Sourcepub fn shape(&self) -> &[usize; N]
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]);Sourcepub fn as_slice(&self) -> &[T]
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]);Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
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]);Sourcepub fn iter(&self) -> Iter<'_, T>
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);Sourcepub fn iter_mut(&mut self) -> IterMut<'_, T>
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]);Sourcepub fn get(&self, index: [usize; N]) -> Option<&T>
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));Sourcepub fn get_mut(&mut self, index: [usize; N]) -> Option<&mut T>
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]);Sourcepub unsafe fn get_unchecked(&self, index: [usize; N]) -> &T
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);Sourcepub unsafe fn get_unchecked_mut(&mut self, index: [usize; N]) -> &mut T
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]);Sourcepub fn axis0_lanes(&self) -> ChunksExact<'_, T>
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][..]));Sourcepub fn axis0_lanes_mut(&mut self) -> ChunksExactMut<'_, T>
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]);