Skip to content

Commit 13f8d85

Browse files
committed
Rename zero_index_with_ndim -> zeros and make it public
1 parent 408f42b commit 13f8d85

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
@@ -303,8 +303,8 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
303303

304304
// Copy the dim and strides that remain after removing the subview axes.
305305
let out_ndim = info.out_ndim();
306-
let mut new_dim = Do::zero_index_with_ndim(out_ndim);
307-
let mut new_strides = Do::zero_index_with_ndim(out_ndim);
306+
let mut new_dim = Do::zeros(out_ndim);
307+
let mut new_strides = Do::zeros(out_ndim);
308308
izip!(self.dim.slice(), self.strides.slice(), indices)
309309
.filter_map(|(d, s, slice_or_index)| match slice_or_index {
310310
&SliceOrIndex::Slice {..} => Some((d, s)),
@@ -1386,7 +1386,7 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
13861386
{
13871387
let axes = axes.into_dimension();
13881388
// Ensure that each axis is used exactly once.
1389-
let mut usage_counts = D::zero_index_with_ndim(self.ndim());
1389+
let mut usage_counts = D::zeros(self.ndim());
13901390
for axis in axes.slice() {
13911391
usage_counts[*axis] += 1;
13921392
}
@@ -1395,7 +1395,7 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
13951395
}
13961396
// Determine the new shape and strides.
13971397
let mut new_dim = usage_counts; // reuse to avoid an allocation
1398-
let mut new_strides = D::zero_index_with_ndim(self.ndim());
1398+
let mut new_strides = D::zeros(self.ndim());
13991399
{
14001400
let dim = self.dim.slice();
14011401
let strides = self.strides.slice();

0 commit comments

Comments
 (0)