Trait TensorRank
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: SmallVec<[usize; 8]>) -> Result<Self::Shape, Error>;
fn shape_into_vec(shape: Self::Shape) -> SmallVec<[usize; 8]>;
fn strides_from_vec(
strides: SmallVec<[isize; 8]>,
) -> Result<Self::Strides, Error>;
fn strides_into_vec(strides: Self::Strides) -> SmallVec<[isize; 8]>;
}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§
Required Associated Types§
Required Methods§
fn shape_from_vec(shape: SmallVec<[usize; 8]>) -> Result<Self::Shape, Error>
fn shape_from_vec(shape: SmallVec<[usize; 8]>) -> Result<Self::Shape, Error>
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]);fn shape_into_vec(shape: Self::Shape) -> SmallVec<[usize; 8]>
fn shape_into_vec(shape: Self::Shape) -> SmallVec<[usize; 8]>
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]);fn strides_from_vec(
strides: SmallVec<[isize; 8]>,
) -> Result<Self::Strides, Error>
fn strides_from_vec( strides: SmallVec<[isize; 8]>, ) -> Result<Self::Strides, Error>
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]);fn strides_into_vec(strides: Self::Strides) -> SmallVec<[isize; 8]>
fn strides_into_vec(strides: Self::Strides) -> SmallVec<[isize; 8]>
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.