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§
Required Associated Types§
Required Methods§
Sourcefn shape_from_vec(shape: ShapeVec) -> Result<Self::Shape>
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]);Sourcefn shape_into_vec(shape: Self::Shape) -> ShapeVec
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]);Sourcefn strides_from_vec(strides: StrideVec) -> Result<Self::Strides>
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]);Sourcefn strides_into_vec(strides: Self::Strides) -> StrideVec
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.