Skip to content

Commit d2837d1

Browse files
committed
Add Dimension::NDIM associated constant
1 parent 5de94ef commit d2837d1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/dimension/dimension_trait.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ pub trait Dimension : Clone + Eq + Debug + Send + Sync + Default +
4141
MulAssign + for<'x> MulAssign<&'x Self> + MulAssign<usize>
4242

4343
{
44+
/// For fixed-size dimension representations (e.g. `Ix2`), this should be
45+
/// `Some(ndim)`, and for variable-size dimension representations (e.g.
46+
/// `IxDyn`), this should be `None`.
47+
const NDIM: Option<usize>;
4448
/// `SliceArg` is the type which is used to specify slicing for this
4549
/// dimension.
4650
///
@@ -350,6 +354,7 @@ macro_rules! impl_insert_axis_array(
350354
);
351355

352356
impl Dimension for Dim<[Ix; 0]> {
357+
const NDIM: Option<usize> = Some(0);
353358
type SliceArg = [Si; 0];
354359
type Pattern = ();
355360
type Smaller = Self;
@@ -381,6 +386,7 @@ impl Dimension for Dim<[Ix; 0]> {
381386

382387

383388
impl Dimension for Dim<[Ix; 1]> {
389+
const NDIM: Option<usize> = Some(1);
384390
type SliceArg = [Si; 1];
385391
type Pattern = Ix;
386392
type Smaller = Ix0;
@@ -469,6 +475,7 @@ impl Dimension for Dim<[Ix; 1]> {
469475
}
470476

471477
impl Dimension for Dim<[Ix; 2]> {
478+
const NDIM: Option<usize> = Some(2);
472479
type SliceArg = [Si; 2];
473480
type Pattern = (Ix, Ix);
474481
type Smaller = Ix1;
@@ -599,6 +606,7 @@ impl Dimension for Dim<[Ix; 2]> {
599606
}
600607

601608
impl Dimension for Dim<[Ix; 3]> {
609+
const NDIM: Option<usize> = Some(3);
602610
type SliceArg = [Si; 3];
603611
type Pattern = (Ix, Ix, Ix);
604612
type Smaller = Ix2;
@@ -710,6 +718,7 @@ impl Dimension for Dim<[Ix; 3]> {
710718
macro_rules! large_dim {
711719
($n:expr, $name:ident, $pattern:ty, $larger:ty, { $($insert_axis:tt)* }) => (
712720
impl Dimension for Dim<[Ix; $n]> {
721+
const NDIM: Option<usize> = Some($n);
713722
type SliceArg = [Si; $n];
714723
type Pattern = $pattern;
715724
type Smaller = Dim<[Ix; $n - 1]>;
@@ -756,6 +765,7 @@ large_dim!(6, Ix6, (Ix, Ix, Ix, Ix, Ix, Ix), IxDyn, {
756765
/// and memory wasteful, but it allows an arbitrary and dynamic number of axes.
757766
impl Dimension for IxDyn
758767
{
768+
const NDIM: Option<usize> = None;
759769
type SliceArg = [Si];
760770
type Pattern = Self;
761771
type Smaller = Self;

0 commit comments

Comments
 (0)