Skip to content

Rename AxisSliceInfo to SliceInfoElem #945

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 2 commits into from
Mar 17, 2021
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
5 changes: 2 additions & 3 deletions blas-tests/tests/oper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ extern crate num_traits;
use ndarray::linalg::general_mat_mul;
use ndarray::linalg::general_mat_vec_mul;
use ndarray::prelude::*;
use ndarray::{AxisSliceInfo, Ix, Ixs, Slice};
use ndarray::{Data, LinalgScalar};
use ndarray::{Data, Ix, Ixs, LinalgScalar, Slice, SliceInfoElem};

use approx::{assert_abs_diff_eq, assert_relative_eq};
use defmac::defmac;
Expand Down Expand Up @@ -419,7 +418,7 @@ fn scaled_add_3() {
let mut a = range_mat64(m, k);
let mut answer = a.clone();
let cdim = if n == 1 { vec![q] } else { vec![n, q] };
let cslice: Vec<AxisSliceInfo> = if n == 1 {
let cslice: Vec<SliceInfoElem> = if n == 1 {
vec![Slice::from(..).step_by(s2).into()]
} else {
vec![
Expand Down
16 changes: 8 additions & 8 deletions src/dimension/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use crate::error::{from_kind, ErrorKind, ShapeError};
use crate::slice::SliceArg;
use crate::{AxisSliceInfo, Ix, Ixs, Slice};
use crate::{Ix, Ixs, Slice, SliceInfoElem};
use num_integer::div_floor;

pub use self::axes::{axes_of, Axes, AxisDescription};
Expand Down Expand Up @@ -608,15 +608,15 @@ pub fn slices_intersect<D: Dimension>(
indices1.as_ref().iter().filter(|si| !si.is_new_axis()),
indices2.as_ref().iter().filter(|si| !si.is_new_axis()),
) {
// The slices do not intersect iff any pair of `AxisSliceInfo` does not intersect.
// The slices do not intersect iff any pair of `SliceInfoElem` does not intersect.
match (si1, si2) {
(
AxisSliceInfo::Slice {
SliceInfoElem::Slice {
start: start1,
end: end1,
step: step1,
},
AxisSliceInfo::Slice {
SliceInfoElem::Slice {
start: start2,
end: end2,
step: step2,
Expand All @@ -637,8 +637,8 @@ pub fn slices_intersect<D: Dimension>(
return false;
}
}
(AxisSliceInfo::Slice { start, end, step }, AxisSliceInfo::Index(ind))
| (AxisSliceInfo::Index(ind), AxisSliceInfo::Slice { start, end, step }) => {
(SliceInfoElem::Slice { start, end, step }, SliceInfoElem::Index(ind))
| (SliceInfoElem::Index(ind), SliceInfoElem::Slice { start, end, step }) => {
let ind = abs_index(axis_len, ind);
let (min, max) = match slice_min_max(axis_len, Slice::new(start, end, step)) {
Some(m) => m,
Expand All @@ -648,14 +648,14 @@ pub fn slices_intersect<D: Dimension>(
return false;
}
}
(AxisSliceInfo::Index(ind1), AxisSliceInfo::Index(ind2)) => {
(SliceInfoElem::Index(ind1), SliceInfoElem::Index(ind2)) => {
let ind1 = abs_index(axis_len, ind1);
let ind2 = abs_index(axis_len, ind2);
if ind1 != ind2 {
return false;
}
}
(AxisSliceInfo::NewAxis, _) | (_, AxisSliceInfo::NewAxis) => unreachable!(),
(SliceInfoElem::NewAxis, _) | (_, SliceInfoElem::NewAxis) => unreachable!(),
}
}
true
Expand Down
16 changes: 8 additions & 8 deletions src/impl_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::iter::{
};
use crate::slice::{MultiSliceArg, SliceArg};
use crate::stacking::concatenate;
use crate::{AxisSliceInfo, NdIndex, Slice};
use crate::{NdIndex, Slice, SliceInfoElem};

/// # Methods For All Array Types
impl<A, S, D> ArrayBase<S, D>
Expand Down Expand Up @@ -415,7 +415,7 @@ where
let mut old_axis = 0;
let mut new_axis = 0;
info.as_ref().iter().for_each(|&ax_info| match ax_info {
AxisSliceInfo::Slice { start, end, step } => {
SliceInfoElem::Slice { start, end, step } => {
// Slice the axis in-place to update the `dim`, `strides`, and `ptr`.
self.slice_axis_inplace(Axis(old_axis), Slice { start, end, step });
// Copy the sliced dim and stride to corresponding axis.
Expand All @@ -424,7 +424,7 @@ where
old_axis += 1;
new_axis += 1;
}
AxisSliceInfo::Index(index) => {
SliceInfoElem::Index(index) => {
// Collapse the axis in-place to update the `ptr`.
let i_usize = abs_index(self.len_of(Axis(old_axis)), index);
self.collapse_axis(Axis(old_axis), i_usize);
Expand All @@ -434,7 +434,7 @@ where
// is zero length.
old_axis += 1;
}
AxisSliceInfo::NewAxis => {
SliceInfoElem::NewAxis => {
// Set the dim and stride of the new axis.
new_dim[new_axis] = 1;
new_strides[new_axis] = 0;
Expand Down Expand Up @@ -465,7 +465,7 @@ where
///
/// - if an index is out of bounds
/// - if a step size is zero
/// - if [`AxisSliceInfo::NewAxis`] is in `info`, e.g. if [`NewAxis`] was
/// - if [`SliceInfoElem::NewAxis`] is in `info`, e.g. if [`NewAxis`] was
/// used in the [`s!`] macro
/// - if `D` is `IxDyn` and `info` does not match the number of array axes
pub fn slice_collapse<I>(&mut self, info: I)
Expand All @@ -479,16 +479,16 @@ where
);
let mut axis = 0;
info.as_ref().iter().for_each(|&ax_info| match ax_info {
AxisSliceInfo::Slice { start, end, step } => {
SliceInfoElem::Slice { start, end, step } => {
self.slice_axis_inplace(Axis(axis), Slice { start, end, step });
axis += 1;
}
AxisSliceInfo::Index(index) => {
SliceInfoElem::Index(index) => {
let i_usize = abs_index(self.len_of(Axis(axis)), index);
self.collapse_axis(Axis(axis), i_usize);
axis += 1;
}
AxisSliceInfo::NewAxis => panic!("`slice_collapse` does not support `NewAxis`."),
SliceInfoElem::NewAxis => panic!("`slice_collapse` does not support `NewAxis`."),
});
debug_assert_eq!(axis, self.ndim());
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub use crate::dimension::NdIndex;
pub use crate::error::{ErrorKind, ShapeError};
pub use crate::indexes::{indices, indices_of};
pub use crate::slice::{
AxisSliceInfo, MultiSliceArg, NewAxis, Slice, SliceArg, SliceInfo, SliceNextDim,
MultiSliceArg, NewAxis, Slice, SliceArg, SliceInfo, SliceInfoElem, SliceNextDim,
};

use crate::iterators::Baseiter;
Expand Down
Loading