Add Dimension::NDIM associated constant
@@ -41,6 +41,10 @@ pub trait Dimension : Clone + Eq + Debug + Send + Sync + Default +
MulAssign + for<'x> MulAssign<&'x Self> + MulAssign<usize>
{
+ /// For fixed-size dimension representations (e.g. `Ix2`), this should be
+ /// `Some(ndim)`, and for variable-size dimension representations (e.g.
+ /// `IxDyn`), this should be `None`.
+ const NDIM: Option<usize>;
/// `SliceArg` is the type which is used to specify slicing for this
/// dimension.
///
@@ -350,6 +354,7 @@ macro_rules! impl_insert_axis_array(
);
impl Dimension for Dim<[Ix; 0]> {
+ const NDIM: Option<usize> = Some(0);
type SliceArg = [Si; 0];
type Pattern = ();
type Smaller = Self;
@@ -381,6 +386,7 @@ impl Dimension for Dim<[Ix; 0]> {
impl Dimension for Dim<[Ix; 1]> {
+ const NDIM: Option<usize> = Some(1);
type SliceArg = [Si; 1];
type Pattern = Ix;
type Smaller = Ix0;
@@ -469,6 +475,7 @@ impl Dimension for Dim<[Ix; 1]> {
}
impl Dimension for Dim<[Ix; 2]> {
+ const NDIM: Option<usize> = Some(2);
type SliceArg = [Si; 2];
type Pattern = (Ix, Ix);
type Smaller = Ix1;
@@ -599,6 +606,7 @@ impl Dimension for Dim<[Ix; 2]> {
}
impl Dimension for Dim<[Ix; 3]> {
+ const NDIM: Option<usize> = Some(3);
type SliceArg = [Si; 3];
type Pattern = (Ix, Ix, Ix);
type Smaller = Ix2;
@@ -710,6 +718,7 @@ impl Dimension for Dim<[Ix; 3]> {
macro_rules! large_dim {
($n:expr, $name:ident, $pattern:ty, $larger:ty, { $($insert_axis:tt)* }) => (
impl Dimension for Dim<[Ix; $n]> {
+ const NDIM: Option<usize> = Some($n);
type SliceArg = [Si; $n];
type Pattern = $pattern;
type Smaller = Dim<[Ix; $n - 1]>;
@@ -756,6 +765,7 @@ large_dim!(6, Ix6, (Ix, Ix, Ix, Ix, Ix, Ix), IxDyn, {
/// and memory wasteful, but it allows an arbitrary and dynamic number of axes.
impl Dimension for IxDyn
{
+ const NDIM: Option<usize> = None;
type SliceArg = [Si];
type Pattern = Self;
type Smaller = Self;
