Skip to main content

IntoRankShape

Trait IntoRankShape 

Source
pub trait IntoRankShape<R: TensorRank> {
    // Required method
    fn into_rank_shape(self) -> Result<R::Shape>;
}
Expand description

Convert a shape container into the representation required by a tensor rank.

Dynamic rank accepts any IntoShapeVec input. For a static Rank<N>, arrays and array references of exactly N elements convert without a runtime rank check; vectors, slices, and ShapeVec values are checked by TensorRank::shape_from_vec.

§Examples

use tenferro_tensor_core::{IntoRankShape, Rank};

let shape = <[usize; 2] as IntoRankShape<Rank<2>>>::into_rank_shape([2, 3])?;
assert_eq!(shape, [2, 3]);
use tenferro_tensor_core::{IntoRankShape, Rank};

let _ = <[usize; 2] as IntoRankShape<Rank<3>>>::into_rank_shape([2, 3]);

Required Methods§

Source

fn into_rank_shape(self) -> Result<R::Shape>

Convert this shape container into R’s shape representation.

§Examples
use tenferro_tensor_core::{IntoRankShape, Rank};
let shape = <Vec<usize> as IntoRankShape<Rank<2>>>::into_rank_shape(vec![2, 3])?;
assert_eq!(shape, [2, 3]);
§Errors

Returns ValidationError::RankMismatch when a vector or slice has a length different from the static rank.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<const N: usize> IntoRankShape<Rank<N>> for &[usize; N]

Source§

impl<const N: usize> IntoRankShape<Rank<N>> for &[usize]

Source§

impl<const N: usize> IntoRankShape<Rank<N>> for Vec<usize>

Source§

impl<const N: usize> IntoRankShape<Rank<N>> for [usize; N]

Implementors§

Source§

impl<S> IntoRankShape<DynRank> for S
where S: IntoShapeVec,

Source§

impl<const N: usize> IntoRankShape<Rank<N>> for ShapeVec