Skip to content

Commit 408e8cd

Browse files
committed
Rename zero_index_with_ndim -> zeros and make it public
1 parent 7df47d2 commit 408e8cd

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

src/dimension/dimension_trait.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -150,20 +150,19 @@ pub trait Dimension : Clone + Eq + Debug + Send + Sync + Default +
150150
strides
151151
}
152152

153-
#[doc(hidden)]
154-
// Return an index of same dimensionality
155-
fn zero_index(&self) -> Self {
156-
Self::default()
157-
}
158-
159-
#[doc(hidden)]
160-
/// Return an index of same type and with the specified dimensionality.
153+
/// Creates a dimension of all zeros with the specified ndim.
161154
///
162155
/// This method is useful for generalizing over fixed-size and
163156
/// variable-size dimension representations.
164157
///
165158
/// **Panics** if `Self` has a fixed size that is not `ndim`.
166-
fn zero_index_with_ndim(ndim: usize) -> Self;
159+
fn zeros(ndim: usize) -> Self;
160+
161+
#[doc(hidden)]
162+
// Return an index of same dimensionality
163+
fn zero_index(&self) -> Self {
164+
Self::default()
165+
}
167166

168167
#[doc(hidden)]
169168
#[inline]
@@ -380,7 +379,7 @@ impl Dimension for Dim<[Ix; 0]> {
380379
#[inline]
381380
fn into_pattern(self) -> Self::Pattern { }
382381
#[inline]
383-
fn zero_index_with_ndim(ndim: usize) -> Self {
382+
fn zeros(ndim: usize) -> Self {
384383
assert_eq!(ndim, 0);
385384
Self::default()
386385
}
@@ -416,7 +415,7 @@ impl Dimension for Dim<[Ix; 1]> {
416415
get!(&self, 0)
417416
}
418417
#[inline]
419-
fn zero_index_with_ndim(ndim: usize) -> Self {
418+
fn zeros(ndim: usize) -> Self {
420419
assert_eq!(ndim, 1);
421420
Self::default()
422421
}
@@ -510,7 +509,7 @@ impl Dimension for Dim<[Ix; 2]> {
510509
#[inline]
511510
fn slice_mut(&mut self) -> &mut [Ix] { self.ixm() }
512511
#[inline]
513-
fn zero_index_with_ndim(ndim: usize) -> Self {
512+
fn zeros(ndim: usize) -> Self {
514513
assert_eq!(ndim, 2);
515514
Self::default()
516515
}
@@ -655,7 +654,7 @@ impl Dimension for Dim<[Ix; 3]> {
655654
}
656655

657656
#[inline]
658-
fn zero_index_with_ndim(ndim: usize) -> Self {
657+
fn zeros(ndim: usize) -> Self {
659658
assert_eq!(ndim, 3);
660659
Self::default()
661660
}
@@ -764,7 +763,7 @@ macro_rules! large_dim {
764763
#[inline]
765764
fn slice_mut(&mut self) -> &mut [Ix] { self.ixm() }
766765
#[inline]
767-
fn zero_index_with_ndim(ndim: usize) -> Self {
766+
fn zeros(ndim: usize) -> Self {
768767
assert_eq!(ndim, $n);
769768
Self::default()
770769
}
@@ -822,7 +821,7 @@ impl Dimension for IxDyn
822821
}
823822

824823
#[inline]
825-
fn zero_index_with_ndim(ndim: usize) -> Self {
824+
fn zeros(ndim: usize) -> Self {
826825
IxDyn::zeros(ndim)
827826
}
828827

src/impl_methods.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
295295

296296
// Copy the dim and strides that remain after removing the subview axes.
297297
let out_ndim = info.out_ndim();
298-
let mut new_dim = Do::zero_index_with_ndim(out_ndim);
299-
let mut new_strides = Do::zero_index_with_ndim(out_ndim);
298+
let mut new_dim = Do::zeros(out_ndim);
299+
let mut new_strides = Do::zeros(out_ndim);
300300
izip!(self.dim.slice(), self.strides.slice(), indices)
301301
.filter_map(|(d, s, slice_or_index)| match slice_or_index {
302302
&SliceOrIndex::Slice {..} => Some((d, s)),
@@ -1378,7 +1378,7 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
13781378
{
13791379
let axes = axes.into_dimension();
13801380
// Ensure that each axis is used exactly once.
1381-
let mut usage_counts = D::zero_index_with_ndim(self.ndim());
1381+
let mut usage_counts = D::zeros(self.ndim());
13821382
for axis in axes.slice() {
13831383
usage_counts[*axis] += 1;
13841384
}
@@ -1387,7 +1387,7 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
13871387
}
13881388
// Determine the new shape and strides.
13891389
let mut new_dim = usage_counts; // reuse to avoid an allocation
1390-
let mut new_strides = D::zero_index_with_ndim(self.ndim());
1390+
let mut new_strides = D::zeros(self.ndim());
13911391
{
13921392
let dim = self.dim.slice();
13931393
let strides = self.strides.slice();

0 commit comments

Comments
 (0)