Skip to content

Commit e8b20ed

Browse files
committed
Add associated type as unstable for Dimension
1 parent 55e0e94 commit e8b20ed

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/dimension/dimension_trait.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ use super::conversion::Convert;
1717
use super::ops::DimAdd;
1818
use super::{stride_offset, stride_offset_checked};
1919
use crate::itertools::{enumerate, zip};
20+
#[cfg(feature = "unstable")]
21+
use crate::layout::dimensionality::*;
2022
use crate::IntoDimension;
2123
use crate::RemoveAxis;
2224
use crate::{ArrayView1, ArrayViewMut1};
@@ -76,6 +78,10 @@ pub trait Dimension:
7678
/// Next larger dimension
7779
type Larger: Dimension + RemoveAxis;
7880

81+
/// The dimensionality of the type, under the new, unstable API.
82+
#[cfg(feature = "unstable")]
83+
type Dimality: Dimensionality;
84+
7985
/// Returns the number of dimensions (number of axes).
8086
fn ndim(&self) -> usize;
8187

@@ -420,6 +426,7 @@ impl Dimension for Dim<[Ix; 0]>
420426
type Pattern = ();
421427
type Smaller = Self;
422428
type Larger = Ix1;
429+
type Dimality = D0;
423430
// empty product is 1 -> size is 1
424431
#[inline]
425432
fn ndim(&self) -> usize
@@ -470,6 +477,8 @@ impl Dimension for Dim<[Ix; 1]>
470477
type Pattern = Ix;
471478
type Smaller = Ix0;
472479
type Larger = Ix2;
480+
#[cfg(feature = "unstable")]
481+
type Dimality = D1;
473482
#[inline]
474483
fn ndim(&self) -> usize
475484
{
@@ -603,6 +612,8 @@ impl Dimension for Dim<[Ix; 2]>
603612
type Pattern = (Ix, Ix);
604613
type Smaller = Ix1;
605614
type Larger = Ix3;
615+
#[cfg(feature = "unstable")]
616+
type Dimality = D2;
606617
#[inline]
607618
fn ndim(&self) -> usize
608619
{
@@ -778,6 +789,8 @@ impl Dimension for Dim<[Ix; 3]>
778789
type Pattern = (Ix, Ix, Ix);
779790
type Smaller = Ix2;
780791
type Larger = Ix4;
792+
#[cfg(feature = "unstable")]
793+
type Dimality = D3;
781794
#[inline]
782795
fn ndim(&self) -> usize
783796
{
@@ -904,12 +917,14 @@ impl Dimension for Dim<[Ix; 3]>
904917
}
905918

906919
macro_rules! large_dim {
907-
($n:expr, $name:ident, $pattern:ty, $larger:ty, { $($insert_axis:tt)* }) => (
920+
($n:expr, $name:ident, $pattern:ty, $larger:ty, $dimality:ty, { $($insert_axis:tt)* }) => (
908921
impl Dimension for Dim<[Ix; $n]> {
909922
const NDIM: Option<usize> = Some($n);
910923
type Pattern = $pattern;
911924
type Smaller = Dim<[Ix; $n - 1]>;
912925
type Larger = $larger;
926+
#[cfg(feature = "unstable")]
927+
type Dimality = $dimality;
913928
#[inline]
914929
fn ndim(&self) -> usize { $n }
915930
#[inline]
@@ -935,13 +950,13 @@ macro_rules! large_dim {
935950
);
936951
}
937952

938-
large_dim!(4, Ix4, (Ix, Ix, Ix, Ix), Ix5, {
953+
large_dim!(4, Ix4, (Ix, Ix, Ix, Ix), Ix5, D4, {
939954
impl_insert_axis_array!(4);
940955
});
941-
large_dim!(5, Ix5, (Ix, Ix, Ix, Ix, Ix), Ix6, {
956+
large_dim!(5, Ix5, (Ix, Ix, Ix, Ix, Ix), Ix6, D5, {
942957
impl_insert_axis_array!(5);
943958
});
944-
large_dim!(6, Ix6, (Ix, Ix, Ix, Ix, Ix, Ix), IxDyn, {
959+
large_dim!(6, Ix6, (Ix, Ix, Ix, Ix, Ix, Ix), IxDyn, D6, {
945960
fn insert_axis(&self, axis: Axis) -> Self::Larger {
946961
debug_assert!(axis.index() <= self.ndim());
947962
let mut out = Vec::with_capacity(self.ndim() + 1);
@@ -960,6 +975,8 @@ impl Dimension for IxDyn
960975
type Pattern = Self;
961976
type Smaller = Self;
962977
type Larger = Self;
978+
#[cfg(feature = "unstable")]
979+
type Dimality = DDyn;
963980
#[inline]
964981
fn ndim(&self) -> usize
965982
{

0 commit comments

Comments
 (0)