@@ -151,20 +151,13 @@ pub trait Dimension : Clone + Eq + Debug + Send + Sync + Default +
151151 strides
152152 }
153153
154- #[ doc( hidden) ]
155- // Return an index of same dimensionality
156- fn zero_index ( & self ) -> Self {
157- Self :: default ( )
158- }
159-
160- #[ doc( hidden) ]
161- /// Return an index of same type and with the specified dimensionality.
154+ /// Creates a dimension of all zeros with the specified ndim.
162155 ///
163156 /// This method is useful for generalizing over fixed-size and
164157 /// variable-size dimension representations.
165158 ///
166159 /// **Panics** if `Self` has a fixed size that is not `ndim`.
167- fn zero_index_with_ndim ( ndim : usize ) -> Self ;
160+ fn zeros ( ndim : usize ) -> Self ;
168161
169162 #[ doc( hidden) ]
170163 #[ inline]
@@ -174,11 +167,7 @@ pub trait Dimension : Clone + Eq + Debug + Send + Sync + Default +
174167 return None ;
175168 }
176169 }
177- let mut index = self . clone ( ) ;
178- for rr in index. slice_mut ( ) . iter_mut ( ) {
179- * rr = 0 ;
180- }
181- Some ( index)
170+ Some ( Self :: zeros ( self . ndim ( ) ) )
182171 }
183172
184173 #[ doc( hidden) ]
@@ -381,7 +370,7 @@ impl Dimension for Dim<[Ix; 0]> {
381370 #[ inline]
382371 fn into_pattern ( self ) -> Self :: Pattern { }
383372 #[ inline]
384- fn zero_index_with_ndim ( ndim : usize ) -> Self {
373+ fn zeros ( ndim : usize ) -> Self {
385374 assert_eq ! ( ndim, 0 ) ;
386375 Self :: default ( )
387376 }
@@ -417,7 +406,7 @@ impl Dimension for Dim<[Ix; 1]> {
417406 get ! ( & self , 0 )
418407 }
419408 #[ inline]
420- fn zero_index_with_ndim ( ndim : usize ) -> Self {
409+ fn zeros ( ndim : usize ) -> Self {
421410 assert_eq ! ( ndim, 1 ) ;
422411 Self :: default ( )
423412 }
@@ -511,7 +500,7 @@ impl Dimension for Dim<[Ix; 2]> {
511500 #[ inline]
512501 fn slice_mut ( & mut self ) -> & mut [ Ix ] { self . ixm ( ) }
513502 #[ inline]
514- fn zero_index_with_ndim ( ndim : usize ) -> Self {
503+ fn zeros ( ndim : usize ) -> Self {
515504 assert_eq ! ( ndim, 2 ) ;
516505 Self :: default ( )
517506 }
@@ -656,7 +645,7 @@ impl Dimension for Dim<[Ix; 3]> {
656645 }
657646
658647 #[ inline]
659- fn zero_index_with_ndim ( ndim : usize ) -> Self {
648+ fn zeros ( ndim : usize ) -> Self {
660649 assert_eq ! ( ndim, 3 ) ;
661650 Self :: default ( )
662651 }
@@ -765,7 +754,7 @@ macro_rules! large_dim {
765754 #[ inline]
766755 fn slice_mut( & mut self ) -> & mut [ Ix ] { self . ixm( ) }
767756 #[ inline]
768- fn zero_index_with_ndim ( ndim: usize ) -> Self {
757+ fn zeros ( ndim: usize ) -> Self {
769758 assert_eq!( ndim, $n) ;
770759 Self :: default ( )
771760 }
@@ -818,12 +807,7 @@ impl Dimension for IxDyn
818807 }
819808
820809 #[ inline]
821- fn zero_index ( & self ) -> Self {
822- IxDyn :: zeros ( self . ndim ( ) )
823- }
824-
825- #[ inline]
826- fn zero_index_with_ndim ( ndim : usize ) -> Self {
810+ fn zeros ( ndim : usize ) -> Self {
827811 IxDyn :: zeros ( ndim)
828812 }
829813
0 commit comments