Skip to main content

TensorRank

Trait TensorRank 

Source
pub trait TensorRank:
    Sealed
    + Clone
    + Copy
    + Debug
    + Eq
    + Send
    + Sync
    + 'static {
    type Shape: Clone + Debug + PartialEq + Eq + AsRef<[usize]>;
    type Strides: Clone + Debug + PartialEq + Eq + AsRef<[isize]>;

    const RANK: Option<usize>;

    // Required methods
    fn shape_from_vec(shape: ShapeVec) -> Result<Self::Shape>;
    fn shape_into_vec(shape: Self::Shape) -> ShapeVec;
    fn strides_from_vec(strides: StrideVec) -> Result<Self::Strides>;
    fn strides_into_vec(strides: Self::Strides) -> StrideVec;
}
Expand description

Rank contract for tensor metadata shapes and strides.

§Examples

use tenferro_tensor_core::{Rank, TensorRank};

let shape = <Rank<2> as TensorRank>::shape_from_vec(vec![2, 3].into())?;
assert_eq!(shape.as_ref(), &[2, 3]);

Required Associated Constants§

Source

const RANK: Option<usize>

Static rank when known at compile time.

§Examples
use tenferro_tensor_core::{DynRank, Rank, TensorRank};

assert_eq!(DynRank::RANK, None);
assert_eq!(Rank::<2>::RANK, Some(2));

Required Associated Types§

Source

type Shape: Clone + Debug + PartialEq + Eq + AsRef<[usize]>

Shape representation for this rank.

§Examples
use tenferro_tensor_core::{DynRank, TensorRank};

let shape: <DynRank as TensorRank>::Shape = vec![2, 3].into();
assert_eq!(shape.as_ref(), &[2, 3]);
Source

type Strides: Clone + Debug + PartialEq + Eq + AsRef<[isize]>

Stride representation for this rank.

§Examples
use tenferro_tensor_core::{DynRank, TensorRank};

let strides: <DynRank as TensorRank>::Strides = vec![1, 2].into();
assert_eq!(strides.as_ref(), &[1, 2]);

Required Methods§

Source

fn shape_from_vec(shape: ShapeVec) -> Result<Self::Shape>

Convert a dynamic shape vector into this rank’s shape representation.

§Examples
use tenferro_tensor_core::{Rank, TensorRank};

let shape = <Rank<1> as TensorRank>::shape_from_vec(vec![4].into())?;
assert_eq!(shape.as_ref(), &[4]);
Source

fn shape_into_vec(shape: Self::Shape) -> ShapeVec

Convert this rank’s shape representation into a dynamic shape vector.

§Examples
use tenferro_tensor_core::{Rank, TensorRank};

let shape = <Rank<2> as TensorRank>::shape_from_vec(vec![2, 3].into())?;
assert_eq!(<Rank<2> as TensorRank>::shape_into_vec(shape).as_slice(), &[2, 3]);
Source

fn strides_from_vec(strides: StrideVec) -> Result<Self::Strides>

Convert a dynamic stride vector into this rank’s stride representation.

§Examples
use tenferro_tensor_core::{Rank, TensorRank};

let strides = <Rank<2> as TensorRank>::strides_from_vec(vec![1, 2].into())?;
assert_eq!(strides.as_ref(), &[1, 2]);
Source

fn strides_into_vec(strides: Self::Strides) -> StrideVec

Convert this rank’s stride representation into a dynamic stride vector.

§Examples
use tenferro_tensor_core::{Rank, TensorRank};

let strides = <Rank<2> as TensorRank>::strides_from_vec(vec![1, 2].into())?;
assert_eq!(<Rank<2> as TensorRank>::strides_into_vec(strides).as_slice(), &[1, 2]);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl TensorRank for DynRank

Source§

const RANK: Option<usize> = None

Source§

type Shape = SmallVec<[usize; 8]>

Source§

type Strides = SmallVec<[isize; 8]>

Source§

impl<const N: usize> TensorRank for Rank<N>