pub struct ColMajorView<'a, T, const N: usize> { /* private fields */ }Expand description
Shared view of a validated compact column-major host tensor with rank N.
The first index varies fastest in memory. Construction is available through
TypedTensor::host_col_major_view and
TypedTensorView::host_col_major_view.
§Examples
use tenferro_tensor::{Rank, TypedTensor};
let tensor = TypedTensor::<i32, Rank<2>>::from_vec_col_major(
[2, 2],
vec![1, 2, 3, 4],
)?;
let view = tensor.host_col_major_view()?;
assert_eq!(view.get([1, 0]), Some(&2));Implementations§
Source§impl<'a, T, const N: usize> ColMajorView<'a, T, N>
impl<'a, T, const N: usize> ColMajorView<'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 tensor = TypedTensor::<f64, Rank<2>>::zeros([2, 3])?;
assert_eq!(tensor.host_col_major_view()?.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 tensor = TypedTensor::<i32, Rank<1>>::from_vec_col_major([2], vec![4, 5])?;
assert_eq!(tensor.host_col_major_view()?.as_slice(), &[4, 5]);Sourcepub fn iter(&self) -> Iter<'_, T>
pub fn iter(&self) -> Iter<'_, T>
Iterate in linear column-major order.
§Examples
use tenferro_tensor::{Rank, TypedTensor};
let tensor = TypedTensor::<i32, Rank<1>>::from_vec_col_major([2], vec![4, 5])?;
assert_eq!(tensor.host_col_major_view()?.iter().copied().sum::<i32>(), 9);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 tensor = TypedTensor::<i32, Rank<2>>::from_vec_col_major([2, 2], vec![1, 2, 3, 4])?;
let view = tensor.host_col_major_view()?;
assert_eq!(view.get([0, 1]), Some(&3));
assert_eq!(view.get([2, 0]), None);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 tensor = TypedTensor::<i32, Rank<1>>::from_vec_col_major([2], vec![4, 5])?;
let view = tensor.host_col_major_view()?;
// SAFETY: index 1 is below the only axis extent, 2.
assert_eq!(unsafe { view.get_unchecked([1]) }, &5);Sourcepub fn axis0_lanes(&self) -> ChunksExact<'_, T>
pub fn axis0_lanes(&self) -> ChunksExact<'_, T>
Iterate over contiguous first-axis lanes in column-major order.
Rank-zero tensors yield one scalar lane. Tensors with an empty axis yield no lanes.
§Examples
use tenferro_tensor::{Rank, TypedTensor};
let tensor = TypedTensor::<i32, Rank<2>>::from_vec_col_major([2, 2], vec![1, 2, 3, 4])?;
let view = tensor.host_col_major_view()?;
let lanes = view.axis0_lanes().collect::<Vec<_>>();
assert_eq!(lanes, vec![&[1, 2][..], &[3, 4][..]]);Trait Implementations§
Auto Trait Implementations§
impl<'a, T, const N: usize> Freeze for ColMajorView<'a, T, N>
impl<'a, T, const N: usize> RefUnwindSafe for ColMajorView<'a, T, N>where
T: RefUnwindSafe,
impl<'a, T, const N: usize> Send for ColMajorView<'a, T, N>where
T: Sync,
impl<'a, T, const N: usize> Sync for ColMajorView<'a, T, N>where
T: Sync,
impl<'a, T, const N: usize> Unpin for ColMajorView<'a, T, N>
impl<'a, T, const N: usize> UnsafeUnpin for ColMajorView<'a, T, N>
impl<'a, T, const N: usize> UnwindSafe for ColMajorView<'a, T, N>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more