Skip to content

MAINT: use len_of(...) instead of shape().axis(...) #375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/impl_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl<A, S> ArrayBase<S, Ix2>

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

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

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

/// Return true if the array is square, false otherwise.
Expand Down
2 changes: 1 addition & 1 deletion src/impl_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,7 @@ impl<A, S, D> ArrayBase<S, D> where S: Data<Elem=A>, D: Dimension
F: FnMut(ArrayView1<'a, A>) -> B,
A: 'a,
{
let view_len = self.shape().axis(axis);
let view_len = self.len_of(axis);
let view_stride = self.strides.axis(axis);
// use the 0th subview as a map to each 1d array view extended from
// the 0th element.
Expand Down
8 changes: 4 additions & 4 deletions src/impl_views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ impl<'a, A, D> ArrayView<'a, A, D>
-> (Self, Self)
{
// NOTE: Keep this in sync with the ArrayViewMut version
assert!(index <= self.shape().axis(axis));
assert!(index <= self.len_of(axis));
let left_ptr = self.ptr;
let right_ptr = if index == self.shape().axis(axis) {
let right_ptr = if index == self.len_of(axis) {
self.ptr
} else {
let offset = stride_offset(index, self.strides.axis(axis));
Expand Down Expand Up @@ -200,9 +200,9 @@ impl<'a, A, D> ArrayViewMut<'a, A, D>
-> (Self, Self)
{
// NOTE: Keep this in sync with the ArrayView version
assert!(index <= self.shape().axis(axis));
assert!(index <= self.len_of(axis));
let left_ptr = self.ptr;
let right_ptr = if index == self.shape().axis(axis) {
let right_ptr = if index == self.len_of(axis) {
self.ptr
} else {
let offset = stride_offset(index, self.strides.axis(axis));
Expand Down
4 changes: 2 additions & 2 deletions src/numeric/impl_numeric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<A, S, D> ArrayBase<S, D>
where A: Clone + Zero + Add<Output=A>,
D: RemoveAxis,
{
let n = self.shape().axis(axis);
let n = self.len_of(axis);
let mut res = self.subview(axis, 0).to_owned();
let stride = self.strides()[axis.index()];
if self.ndim() == 2 && stride == 1 {
Expand Down Expand Up @@ -115,7 +115,7 @@ impl<A, S, D> ArrayBase<S, D>
where A: LinalgScalar,
D: RemoveAxis,
{
let n = self.shape().axis(axis);
let n = self.len_of(axis);
let sum = self.sum_axis(axis);
let mut cnt = A::one();
for _ in 1..n {
Expand Down
5 changes: 2 additions & 3 deletions src/stacking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ pub fn stack<'a, A, D>(axis: Axis, arrays: &[ArrayView<'a, A, D>])
return Err(from_kind(ErrorKind::IncompatibleShape));
}

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

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