@@ -151,20 +151,13 @@ pub trait Dimension : Clone + Eq + Debug + Send + Sync + Default +
151
151
strides
152
152
}
153
153
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.
162
155
///
163
156
/// This method is useful for generalizing over fixed-size and
164
157
/// variable-size dimension representations.
165
158
///
166
159
/// **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 ;
168
161
169
162
#[ doc( hidden) ]
170
163
#[ inline]
@@ -174,11 +167,7 @@ pub trait Dimension : Clone + Eq + Debug + Send + Sync + Default +
174
167
return None ;
175
168
}
176
169
}
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 ( ) ) )
182
171
}
183
172
184
173
#[ doc( hidden) ]
@@ -381,7 +370,7 @@ impl Dimension for Dim<[Ix; 0]> {
381
370
#[ inline]
382
371
fn into_pattern ( self ) -> Self :: Pattern { }
383
372
#[ inline]
384
- fn zero_index_with_ndim ( ndim : usize ) -> Self {
373
+ fn zeros ( ndim : usize ) -> Self {
385
374
assert_eq ! ( ndim, 0 ) ;
386
375
Self :: default ( )
387
376
}
@@ -417,7 +406,7 @@ impl Dimension for Dim<[Ix; 1]> {
417
406
get ! ( & self , 0 )
418
407
}
419
408
#[ inline]
420
- fn zero_index_with_ndim ( ndim : usize ) -> Self {
409
+ fn zeros ( ndim : usize ) -> Self {
421
410
assert_eq ! ( ndim, 1 ) ;
422
411
Self :: default ( )
423
412
}
@@ -511,7 +500,7 @@ impl Dimension for Dim<[Ix; 2]> {
511
500
#[ inline]
512
501
fn slice_mut ( & mut self ) -> & mut [ Ix ] { self . ixm ( ) }
513
502
#[ inline]
514
- fn zero_index_with_ndim ( ndim : usize ) -> Self {
503
+ fn zeros ( ndim : usize ) -> Self {
515
504
assert_eq ! ( ndim, 2 ) ;
516
505
Self :: default ( )
517
506
}
@@ -656,7 +645,7 @@ impl Dimension for Dim<[Ix; 3]> {
656
645
}
657
646
658
647
#[ inline]
659
- fn zero_index_with_ndim ( ndim : usize ) -> Self {
648
+ fn zeros ( ndim : usize ) -> Self {
660
649
assert_eq ! ( ndim, 3 ) ;
661
650
Self :: default ( )
662
651
}
@@ -765,7 +754,7 @@ macro_rules! large_dim {
765
754
#[ inline]
766
755
fn slice_mut( & mut self ) -> & mut [ Ix ] { self . ixm( ) }
767
756
#[ inline]
768
- fn zero_index_with_ndim ( ndim: usize ) -> Self {
757
+ fn zeros ( ndim: usize ) -> Self {
769
758
assert_eq!( ndim, $n) ;
770
759
Self :: default ( )
771
760
}
@@ -818,12 +807,7 @@ impl Dimension for IxDyn
818
807
}
819
808
820
809
#[ 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 {
827
811
IxDyn :: zeros ( ndim)
828
812
}
829
813
0 commit comments