@@ -140,50 +140,6 @@ macro_rules! ndindex_with_array {
140140 0
141141 }
142142 }
143-
144- // implement NdIndex<IxDyn> for Dim<[Ix; 2]> and so on
145- unsafe impl NdIndex <IxDyn > for Dim <[ Ix ; $n] > {
146- #[ inline]
147- fn index_checked( & self , dim: & IxDyn , strides: & IxDyn ) -> Option <isize > {
148- debug_assert_eq!( strides. ndim( ) , $n,
149- "Attempted to index with {:?} in array with {} axes" ,
150- self , strides. ndim( ) ) ;
151- stride_offset_checked( dim. ix( ) , strides. ix( ) , self . ix( ) )
152- }
153-
154- #[ inline]
155- fn index_unchecked( & self , strides: & IxDyn ) -> isize {
156- debug_assert_eq!( strides. ndim( ) , $n,
157- "Attempted to index with {:?} in array with {} axes" ,
158- self , strides. ndim( ) ) ;
159- $(
160- stride_offset( get!( self , $index) , get!( strides, $index) ) +
161- ) *
162- 0
163- }
164- }
165-
166- // implement NdIndex<IxDyn> for [Ix; 2] and so on
167- unsafe impl NdIndex <IxDyn > for [ Ix ; $n] {
168- #[ inline]
169- fn index_checked( & self , dim: & IxDyn , strides: & IxDyn ) -> Option <isize > {
170- debug_assert_eq!( strides. ndim( ) , $n,
171- "Attempted to index with {:?} in array with {} axes" ,
172- self , strides. ndim( ) ) ;
173- stride_offset_checked( dim. ix( ) , strides. ix( ) , self )
174- }
175-
176- #[ inline]
177- fn index_unchecked( & self , strides: & IxDyn ) -> isize {
178- debug_assert_eq!( strides. ndim( ) , $n,
179- "Attempted to index with {:?} in array with {} axes" ,
180- self , strides. ndim( ) ) ;
181- $(
182- stride_offset( self [ $index] , get!( strides, $index) ) +
183- ) *
184- 0
185- }
186- }
187143 ) +
188144 } ;
189145}
@@ -198,6 +154,64 @@ ndindex_with_array! {
198154 [ 6 , Ix6 0 1 2 3 4 5 ]
199155}
200156
157+ // implement NdIndex<IxDyn> for Dim<[Ix; 2]> and so on
158+ unsafe impl < const N : usize > NdIndex < IxDyn > for Dim < [ Ix ; N ] > {
159+ #[ inline]
160+ fn index_checked ( & self , dim : & IxDyn , strides : & IxDyn ) -> Option < isize > {
161+ debug_assert_eq ! (
162+ strides. ndim( ) ,
163+ N ,
164+ "Attempted to index with {:?} in array with {} axes" ,
165+ self ,
166+ strides. ndim( )
167+ ) ;
168+ stride_offset_checked ( dim. ix ( ) , strides. ix ( ) , self . ix ( ) )
169+ }
170+
171+ #[ inline]
172+ fn index_unchecked ( & self , strides : & IxDyn ) -> isize {
173+ debug_assert_eq ! (
174+ strides. ndim( ) ,
175+ N ,
176+ "Attempted to index with {:?} in array with {} axes" ,
177+ self ,
178+ strides. ndim( )
179+ ) ;
180+ ( 0 ..N )
181+ . map ( |i| stride_offset ( get ! ( self , i) , get ! ( strides, i) ) )
182+ . sum ( )
183+ }
184+ }
185+
186+ // implement NdIndex<IxDyn> for [Ix; 2] and so on
187+ unsafe impl < const N : usize > NdIndex < IxDyn > for [ Ix ; N ] {
188+ #[ inline]
189+ fn index_checked ( & self , dim : & IxDyn , strides : & IxDyn ) -> Option < isize > {
190+ debug_assert_eq ! (
191+ strides. ndim( ) ,
192+ N ,
193+ "Attempted to index with {:?} in array with {} axes" ,
194+ self ,
195+ strides. ndim( )
196+ ) ;
197+ stride_offset_checked ( dim. ix ( ) , strides. ix ( ) , self )
198+ }
199+
200+ #[ inline]
201+ fn index_unchecked ( & self , strides : & IxDyn ) -> isize {
202+ debug_assert_eq ! (
203+ strides. ndim( ) ,
204+ N ,
205+ "Attempted to index with {:?} in array with {} axes" ,
206+ self ,
207+ strides. ndim( )
208+ ) ;
209+ ( 0 ..N )
210+ . map ( |i| stride_offset ( self [ i] , get ! ( strides, i) ) )
211+ . sum ( )
212+ }
213+ }
214+
201215impl < ' a > IntoDimension for & ' a [ Ix ] {
202216 type Dim = IxDyn ;
203217 fn into_dimension ( self ) -> Self :: Dim {
0 commit comments