Skip to main content

ColMajorView

Struct ColMajorView 

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

Source

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

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

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

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§

Source§

impl<T, const N: usize> Debug for ColMajorView<'_, 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> 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> 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.