Skip to content

Commit 6e99ef8

Browse files
authored
Merge pull request #375 from mgeisler/refactor-len-of
MAINT: use len_of(...) instead of shape().axis(...)
2 parents ffac3f6 + b424332 commit 6e99ef8

File tree

5 files changed

+11
-12
lines changed

5 files changed

+11
-12
lines changed

src/impl_2d.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl<A, S> ArrayBase<S, Ix2>
3232

3333
/// Return the number of rows (length of `Axis(0)`) in the two-dimensional array.
3434
pub fn rows(&self) -> usize {
35-
self.shape().axis(Axis(0))
35+
self.len_of(Axis(0))
3636
}
3737

3838
/// Return an array view of column `index`.
@@ -54,7 +54,7 @@ impl<A, S> ArrayBase<S, Ix2>
5454

5555
/// Return the number of columns (length of `Axis(1)`) in the two-dimensional array.
5656
pub fn cols(&self) -> usize {
57-
self.shape().axis(Axis(1))
57+
self.len_of(Axis(1))
5858
}
5959

6060
/// Return true if the array is square, false otherwise.

src/impl_methods.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
16111611
F: FnMut(ArrayView1<'a, A>) -> B,
16121612
A: 'a,
16131613
{
1614-
let view_len = self.shape().axis(axis);
1614+
let view_len = self.len_of(axis);
16151615
let view_stride = self.strides.axis(axis);
16161616
// use the 0th subview as a map to each 1d array view extended from
16171617
// the 0th element.

src/impl_views.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ impl<'a, A, D> ArrayView<'a, A, D>
9494
-> (Self, Self)
9595
{
9696
// NOTE: Keep this in sync with the ArrayViewMut version
97-
assert!(index <= self.shape().axis(axis));
97+
assert!(index <= self.len_of(axis));
9898
let left_ptr = self.ptr;
99-
let right_ptr = if index == self.shape().axis(axis) {
99+
let right_ptr = if index == self.len_of(axis) {
100100
self.ptr
101101
} else {
102102
let offset = stride_offset(index, self.strides.axis(axis));
@@ -200,9 +200,9 @@ impl<'a, A, D> ArrayViewMut<'a, A, D>
200200
-> (Self, Self)
201201
{
202202
// NOTE: Keep this in sync with the ArrayView version
203-
assert!(index <= self.shape().axis(axis));
203+
assert!(index <= self.len_of(axis));
204204
let left_ptr = self.ptr;
205-
let right_ptr = if index == self.shape().axis(axis) {
205+
let right_ptr = if index == self.len_of(axis) {
206206
self.ptr
207207
} else {
208208
let offset = stride_offset(index, self.strides.axis(axis));

src/numeric/impl_numeric.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl<A, S, D> ArrayBase<S, D>
7070
where A: Clone + Zero + Add<Output=A>,
7171
D: RemoveAxis,
7272
{
73-
let n = self.shape().axis(axis);
73+
let n = self.len_of(axis);
7474
let mut res = self.subview(axis, 0).to_owned();
7575
let stride = self.strides()[axis.index()];
7676
if self.ndim() == 2 && stride == 1 {
@@ -115,7 +115,7 @@ impl<A, S, D> ArrayBase<S, D>
115115
where A: LinalgScalar,
116116
D: RemoveAxis,
117117
{
118-
let n = self.shape().axis(axis);
118+
let n = self.len_of(axis);
119119
let sum = self.sum_axis(axis);
120120
let mut cnt = A::one();
121121
for _ in 1..n {

src/stacking.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ pub fn stack<'a, A, D>(axis: Axis, arrays: &[ArrayView<'a, A, D>])
4646
return Err(from_kind(ErrorKind::IncompatibleShape));
4747
}
4848

49-
let stacked_dim = arrays.iter()
50-
.fold(0, |acc, a| acc + a.shape().axis(axis));
49+
let stacked_dim = arrays.iter().fold(0, |acc, a| acc + a.len_of(axis));
5150
res_dim.set_axis(axis, stacked_dim);
5251

5352
// we can safely use uninitialized values here because they are Copy
@@ -62,7 +61,7 @@ pub fn stack<'a, A, D>(axis: Axis, arrays: &[ArrayView<'a, A, D>])
6261
{
6362
let mut assign_view = res.view_mut();
6463
for array in arrays {
65-
let len = array.shape().axis(axis);
64+
let len = array.len_of(axis);
6665
let (mut front, rest) = assign_view.split_at(axis, len);
6766
front.assign(array);
6867
assign_view = rest;

0 commit comments

Comments
 (0)