diff --git a/examples/axis_ops.rs b/examples/axis_ops.rs index 3dbf0eee9..624af32c3 100644 --- a/examples/axis_ops.rs +++ b/examples/axis_ops.rs @@ -14,21 +14,21 @@ where { println!("Regularize:\n{:?}", a); // reverse all neg axes - while let Some(ax) = a.axes().find(|ax| ax.stride() <= 0) { - if ax.stride() == 0 { + while let Some(ax) = a.axes().find(|ax| ax.stride <= 0) { + if ax.stride == 0 { return Err(()); } // reverse ax - println!("Reverse {:?}", ax.axis()); - a.invert_axis(ax.axis()); + println!("Reverse {:?}", ax.axis); + a.invert_axis(ax.axis); } // sort by least stride let mut i = 0; let n = a.ndim(); - while let Some(ax) = a.axes().rev().skip(i).min_by_key(|ax| ax.stride().abs()) { - a.swap_axes(n - 1 - i, ax.axis().index()); - println!("Swap {:?} <=> {}", ax.axis(), n - 1 - i); + while let Some(ax) = a.axes().rev().skip(i).min_by_key(|ax| ax.stride.abs()) { + a.swap_axes(n - 1 - i, ax.axis.index()); + println!("Swap {:?} <=> {}", ax.axis, n - 1 - i); i += 1; } diff --git a/src/dimension/axes.rs b/src/dimension/axes.rs index 50830f3c6..a678e78ca 100644 --- a/src/dimension/axes.rs +++ b/src/dimension/axes.rs @@ -42,7 +42,11 @@ pub struct Axes<'a, D> { /// Description of the axis, its length and its stride. #[derive(Debug)] -pub struct AxisDescription(pub Axis, pub Ix, pub Ixs); +pub struct AxisDescription { + pub axis: Axis, + pub len: usize, + pub stride: isize, +} copy_and_clone!(AxisDescription); @@ -51,19 +55,22 @@ copy_and_clone!(AxisDescription); #[allow(clippy::len_without_is_empty)] impl AxisDescription { /// Return axis + #[deprecated(note = "Use .axis field instead", since = "0.15.0")] #[inline(always)] pub fn axis(self) -> Axis { - self.0 + self.axis } /// Return length + #[deprecated(note = "Use .len field instead", since = "0.15.0")] #[inline(always)] pub fn len(self) -> Ix { - self.1 + self.len } /// Return stride + #[deprecated(note = "Use .stride field instead", since = "0.15.0")] #[inline(always)] pub fn stride(self) -> Ixs { - self.2 + self.stride } } @@ -79,11 +86,11 @@ where fn next(&mut self) -> Option { if self.start < self.end { let i = self.start.post_inc(); - Some(AxisDescription( - Axis(i), - self.dim[i], - self.strides[i] as Ixs, - )) + Some(AxisDescription { + axis: Axis(i), + len: self.dim[i], + stride: self.strides[i] as Ixs, + }) } else { None } @@ -94,7 +101,11 @@ where F: FnMut(B, AxisDescription) -> B, { (self.start..self.end) - .map(move |i| AxisDescription(Axis(i), self.dim[i], self.strides[i] as isize)) + .map(move |i| AxisDescription { + axis: Axis(i), + len: self.dim[i], + stride: self.strides[i] as isize, + }) .fold(init, f) } @@ -111,11 +122,11 @@ where fn next_back(&mut self) -> Option { if self.start < self.end { let i = self.end.pre_dec(); - Some(AxisDescription( - Axis(i), - self.dim[i], - self.strides[i] as Ixs, - )) + Some(AxisDescription { + axis: Axis(i), + len: self.dim[i], + stride: self.strides[i] as Ixs, + }) } else { None } diff --git a/src/dimension/dimension_trait.rs b/src/dimension/dimension_trait.rs index 18a10c3f0..92f241189 100644 --- a/src/dimension/dimension_trait.rs +++ b/src/dimension/dimension_trait.rs @@ -332,8 +332,8 @@ pub trait Dimension: }; axes_of(self, strides) .rev() - .min_by_key(|ax| ax.stride().abs()) - .map_or(Axis(n - 1), |ax| ax.axis()) + .min_by_key(|ax| ax.stride.abs()) + .map_or(Axis(n - 1), |ax| ax.axis) } /// Compute the maximum stride axis (absolute value), under the constraint @@ -346,9 +346,9 @@ pub trait Dimension: _ => {} } axes_of(self, strides) - .filter(|ax| ax.len() > 1) - .max_by_key(|ax| ax.stride().abs()) - .map_or(Axis(0), |ax| ax.axis()) + .filter(|ax| ax.len > 1) + .max_by_key(|ax| ax.stride.abs()) + .map_or(Axis(0), |ax| ax.axis) } /// Convert the dimensional into a dynamic dimensional (IxDyn). diff --git a/src/impl_methods.rs b/src/impl_methods.rs index 19733fc6d..9943e7c8e 100644 --- a/src/impl_methods.rs +++ b/src/impl_methods.rs @@ -557,16 +557,16 @@ where where F: FnMut(AxisDescription) -> Slice, { - (0..self.ndim()).for_each(|ax| { + for ax in 0..self.ndim() { self.slice_axis_inplace( Axis(ax), - f(AxisDescription( - Axis(ax), - self.dim[ax], - self.strides[ax] as isize, - )), + f(AxisDescription { + axis: Axis(ax), + len: self.dim[ax], + stride: self.strides[ax] as isize, + }), ) - }) + } } /// Return a reference to the element at `index`, or return `None`