Skip to content

Commit

Permalink
Rename SliceOrIndex to AxisSliceInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
jturner314 committed Dec 9, 2018
1 parent 5d2f7f6 commit d45eeb9
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 109 deletions.
8 changes: 4 additions & 4 deletions blas-tests/tests/oper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ndarray::prelude::*;
use ndarray::{LinalgScalar, Data};
use ndarray::linalg::general_mat_mul;
use ndarray::linalg::general_mat_vec_mul;
use ndarray::{Ix, Ixs, SliceInfo, SliceOrIndex};
use ndarray::{Ix, Ixs, SliceInfo, AxisSliceInfo};

use std::fmt;
use defmac::defmac;
Expand Down Expand Up @@ -433,11 +433,11 @@ fn scaled_add_3() {
vec![n, q]
};
let cslice = if n == 1 {
vec![SliceOrIndex::from(..).step_by(s2)]
vec![AxisSliceInfo::from(..).step_by(s2)]
} else {
vec![
SliceOrIndex::from(..).step_by(s1),
SliceOrIndex::from(..).step_by(s2),
AxisSliceInfo::from(..).step_by(s1),
AxisSliceInfo::from(..).step_by(s2),
]
};

Expand Down
22 changes: 11 additions & 11 deletions src/dimension/dimension_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::ops::{Add, Sub, Mul, AddAssign, SubAssign, MulAssign};

use itertools::{enumerate, izip, zip};

use {Ix, Ixs, Ix0, Ix1, Ix2, Ix3, Ix4, Ix5, Ix6, IxDyn, Dim, SliceOrIndex, IxDynImpl};
use {Ix, Ixs, Ix0, Ix1, Ix2, Ix3, Ix4, Ix5, Ix6, IxDyn, Dim, AxisSliceInfo, IxDynImpl};
use IntoDimension;
use RemoveAxis;
use {ArrayView1, ArrayViewMut1};
Expand Down Expand Up @@ -52,14 +52,14 @@ pub trait Dimension : Clone + Eq + Debug + Send + Sync + Default +
/// size, which you pass by reference. For the dynamic dimension it is
/// a slice.
///
/// - For `Ix1`: `[SliceOrIndex; 1]`
/// - For `Ix2`: `[SliceOrIndex; 2]`
/// - For `Ix1`: `[AxisSliceInfo; 1]`
/// - For `Ix2`: `[AxisSliceInfo; 2]`
/// - and so on..
/// - For `IxDyn`: `[SliceOrIndex]`
/// - For `IxDyn`: `[AxisSliceInfo]`
///
/// The easiest way to create a `&SliceInfo<SliceArg, Do>` is using the
/// [`s![]`](macro.s!.html) macro.
type SliceArg: ?Sized + AsRef<[SliceOrIndex]>;
type SliceArg: ?Sized + AsRef<[AxisSliceInfo]>;
/// Pattern matching friendly form of the dimension value.
///
/// - For `Ix1`: `usize`,
Expand Down Expand Up @@ -364,7 +364,7 @@ macro_rules! impl_insert_axis_array(

impl Dimension for Dim<[Ix; 0]> {
const NDIM: Option<usize> = Some(0);
type SliceArg = [SliceOrIndex; 0];
type SliceArg = [AxisSliceInfo; 0];
type Pattern = ();
type Smaller = Self;
type Larger = Ix1;
Expand Down Expand Up @@ -401,7 +401,7 @@ impl Dimension for Dim<[Ix; 0]> {

impl Dimension for Dim<[Ix; 1]> {
const NDIM: Option<usize> = Some(1);
type SliceArg = [SliceOrIndex; 1];
type SliceArg = [AxisSliceInfo; 1];
type Pattern = Ix;
type Smaller = Ix0;
type Larger = Ix2;
Expand Down Expand Up @@ -499,7 +499,7 @@ impl Dimension for Dim<[Ix; 1]> {

impl Dimension for Dim<[Ix; 2]> {
const NDIM: Option<usize> = Some(2);
type SliceArg = [SliceOrIndex; 2];
type SliceArg = [AxisSliceInfo; 2];
type Pattern = (Ix, Ix);
type Smaller = Ix1;
type Larger = Ix3;
Expand Down Expand Up @@ -645,7 +645,7 @@ impl Dimension for Dim<[Ix; 2]> {

impl Dimension for Dim<[Ix; 3]> {
const NDIM: Option<usize> = Some(3);
type SliceArg = [SliceOrIndex; 3];
type SliceArg = [AxisSliceInfo; 3];
type Pattern = (Ix, Ix, Ix);
type Smaller = Ix2;
type Larger = Ix4;
Expand Down Expand Up @@ -763,7 +763,7 @@ macro_rules! large_dim {
($n:expr, $name:ident, $pattern:ty, $larger:ty, { $($insert_axis:tt)* }) => (
impl Dimension for Dim<[Ix; $n]> {
const NDIM: Option<usize> = Some($n);
type SliceArg = [SliceOrIndex; $n];
type SliceArg = [AxisSliceInfo; $n];
type Pattern = $pattern;
type Smaller = Dim<[Ix; $n - 1]>;
type Larger = $larger;
Expand Down Expand Up @@ -815,7 +815,7 @@ large_dim!(6, Ix6, (Ix, Ix, Ix, Ix, Ix, Ix), IxDyn, {
impl Dimension for IxDyn
{
const NDIM: Option<usize> = None;
type SliceArg = [SliceOrIndex];
type SliceArg = [AxisSliceInfo];
type Pattern = Self;
type Smaller = Self;
type Larger = Self;
Expand Down
16 changes: 8 additions & 8 deletions src/dimension/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use {Ix, Ixs, Slice, SliceOrIndex};
use {AxisSliceInfo, Ix, Ixs, Slice};
use error::{from_kind, ErrorKind, ShapeError};
use itertools::izip;
use num_integer::div_floor;
Expand Down Expand Up @@ -534,15 +534,15 @@ pub fn slices_intersect<D: Dimension>(
) -> bool {
debug_assert_eq!(indices1.as_ref().len(), indices2.as_ref().len());
for (&axis_len, &si1, &si2) in izip!(dim.slice(), indices1.as_ref(), indices2.as_ref()) {
// The slices do not intersect iff any pair of `SliceOrIndex` does not intersect.
// The slices do not intersect iff any pair of `AxisSliceInfo` does not intersect.
match (si1, si2) {
(
SliceOrIndex::Slice {
AxisSliceInfo::Slice {
start: start1,
end: end1,
step: step1,
},
SliceOrIndex::Slice {
AxisSliceInfo::Slice {
start: start2,
end: end2,
step: step2,
Expand All @@ -563,8 +563,8 @@ pub fn slices_intersect<D: Dimension>(
return false;
}
}
(SliceOrIndex::Slice { start, end, step }, SliceOrIndex::Index(ind)) |
(SliceOrIndex::Index(ind), SliceOrIndex::Slice { start, end, step }) => {
(AxisSliceInfo::Slice { start, end, step }, AxisSliceInfo::Index(ind)) |
(AxisSliceInfo::Index(ind), AxisSliceInfo::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 @@ -574,7 +574,7 @@ pub fn slices_intersect<D: Dimension>(
return false;
}
}
(SliceOrIndex::Index(ind1), SliceOrIndex::Index(ind2)) => {
(AxisSliceInfo::Index(ind1), AxisSliceInfo::Index(ind2)) => {
let ind1 = abs_index(axis_len, ind1);
let ind2 = abs_index(axis_len, ind2);
if ind1 != ind2 {
Expand Down Expand Up @@ -624,7 +624,7 @@ mod test {
use error::{from_kind, ErrorKind};
use num_integer::gcd;
use quickcheck::{quickcheck, TestResult};
use slice::{Slice, SliceOrIndex};
use slice::Slice;
use {Dim, Dimension, Ix0, Ix1, Ix2, Ix3, IxDyn};

#[test]
Expand Down
14 changes: 7 additions & 7 deletions src/impl_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ use dimension::{abs_index, axes_of, Axes, do_slice, merge_axes, size_of_shape_ch
use zip::Zip;

use {
AxisSliceInfo,
NdIndex,
Slice,
SliceInfo,
SliceOrIndex
};
use iter::{
AxisChunksIter,
Expand Down Expand Up @@ -346,16 +346,16 @@ where
// Slice and collapse in-place without changing the number of dimensions.
self.slice_collapse(&*info);

let indices: &[SliceOrIndex] = (**info).as_ref();
let indices: &[AxisSliceInfo] = (**info).as_ref();

// Copy the dim and strides that remain after removing the subview axes.
let out_ndim = info.out_ndim();
let mut new_dim = Do::zeros(out_ndim);
let mut new_strides = Do::zeros(out_ndim);
izip!(self.dim.slice(), self.strides.slice(), indices)
.filter_map(|(d, s, slice_or_index)| match slice_or_index {
&SliceOrIndex::Slice {..} => Some((d, s)),
&SliceOrIndex::Index(_) => None,
&AxisSliceInfo::Slice {..} => Some((d, s)),
&AxisSliceInfo::Index(_) => None,
})
.zip(izip!(new_dim.slice_mut(), new_strides.slice_mut()))
.for_each(|((d, s), (new_d, new_s))| {
Expand Down Expand Up @@ -386,16 +386,16 @@ where
/// **Panics** if an index is out of bounds or step size is zero.<br>
/// (**Panics** if `D` is `IxDyn` and `indices` does not match the number of array axes.)
pub fn slice_collapse(&mut self, indices: &D::SliceArg) {
let indices: &[SliceOrIndex] = indices.as_ref();
let indices: &[AxisSliceInfo] = indices.as_ref();
assert_eq!(indices.len(), self.ndim());
indices
.iter()
.enumerate()
.for_each(|(axis, slice_or_index)| match slice_or_index {
&SliceOrIndex::Slice { start, end, step } => {
&AxisSliceInfo::Slice { start, end, step } => {
self.slice_axis_inplace(Axis(axis), Slice { start, end, step })
}
&SliceOrIndex::Index(index) => {
&AxisSliceInfo::Index(index) => {
let i_usize = abs_index(self.len_of(Axis(axis)), index);
self.collapse_axis(Axis(axis), i_usize)
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub use indexes::{indices, indices_of};
pub use error::{ShapeError, ErrorKind};
pub use slice::{
deref_raw_view_mut_into_view_with_life, deref_raw_view_mut_into_view_mut_with_life,
life_of_view_mut, Slice, SliceInfo, SliceNextDim, SliceOrIndex
life_of_view_mut, AxisSliceInfo, Slice, SliceInfo, SliceNextDim,
};

use iterators::Baseiter;
Expand Down

0 comments on commit d45eeb9

Please sign in to comment.