From 9eb04a07344962b983339f2e570b29950760bd1e Mon Sep 17 00:00:00 2001 From: Alessandro Cresto Miseroglio Date: Thu, 4 Jul 2019 18:53:14 +0200 Subject: [PATCH 01/11] Implement Hash to be clippy compliant Fix #642 --- src/dimension/axis.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/dimension/axis.rs b/src/dimension/axis.rs index 6fc389988..e9137cb01 100644 --- a/src/dimension/axis.rs +++ b/src/dimension/axis.rs @@ -7,6 +7,7 @@ // except according to those terms. use std::cmp::Ordering; +use std::hash::{Hash, Hasher}; /// An axis index. /// @@ -15,7 +16,7 @@ use std::cmp::Ordering; /// /// All array axis arguments use this type to make the code easier to write /// correctly and easier to understand. -#[derive(Eq, Ord, Hash, Debug)] +#[derive(Eq, Ord, Debug)] pub struct Axis(pub usize); impl Axis { @@ -28,6 +29,12 @@ impl Axis { copy_and_clone! {Axis} +impl Hash for Axis { + fn hash(&self, state: &mut H) { + self.0.hash(state); + } +} + macro_rules! derive_cmp { ($traitname:ident for $typename:ident, $method:ident -> $ret:ty) => { impl $traitname for $typename { From 80f79b2c04c711586e843a97214b82a5aaff6b40 Mon Sep 17 00:00:00 2001 From: Alessandro Cresto Miseroglio Date: Thu, 4 Jul 2019 19:32:40 +0200 Subject: [PATCH 02/11] Implement PartialEq fixes #642 --- src/dimension/dim.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/dimension/dim.rs b/src/dimension/dim.rs index 62a9e0b1f..48bed9560 100644 --- a/src/dimension/dim.rs +++ b/src/dimension/dim.rs @@ -36,7 +36,7 @@ use crate::Ix; /// array[[0, 0]] = 1.; /// assert_eq!(array.raw_dim(), Dim([3, 2])); /// ``` -#[derive(Copy, Clone, PartialEq, Eq, Default)] +#[derive(Copy, Clone, Eq, Default)] pub struct Dim { index: I, } @@ -65,6 +65,13 @@ where index.into_dimension() } +impl PartialEq for Dim +{ + fn eq(&self, rhs: &Self) -> bool { + self == rhs + } +} + impl PartialEq for Dim where I: PartialEq, From a2951a9024a0f8299a30ad3701ef101da0c5d75a Mon Sep 17 00:00:00 2001 From: Alessandro Cresto Miseroglio Date: Thu, 4 Jul 2019 19:41:08 +0200 Subject: [PATCH 03/11] Run cargo fmt fixes #642 --- src/dimension/dim.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/dimension/dim.rs b/src/dimension/dim.rs index 48bed9560..c66369d3d 100644 --- a/src/dimension/dim.rs +++ b/src/dimension/dim.rs @@ -65,8 +65,7 @@ where index.into_dimension() } -impl PartialEq for Dim -{ +impl PartialEq for Dim { fn eq(&self, rhs: &Self) -> bool { self == rhs } From b1dc6849458e42a13397c1560e206402596020b7 Mon Sep 17 00:00:00 2001 From: Alessandro Cresto Miseroglio Date: Thu, 4 Jul 2019 20:31:57 +0200 Subject: [PATCH 04/11] Implement PartialEq fixes #642 --- src/dimension/dim.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/dimension/dim.rs b/src/dimension/dim.rs index c66369d3d..e42510000 100644 --- a/src/dimension/dim.rs +++ b/src/dimension/dim.rs @@ -65,9 +65,12 @@ where index.into_dimension() } -impl PartialEq for Dim { - fn eq(&self, rhs: &Self) -> bool { - self == rhs +impl PartialEq for Dim +where + I: PartialEq, +{ + fn eq(&self, rhs: &Dim) -> bool { + self.index == rhs.index } } From fdf984b6b7b4cd8e575b66ae730f89ca193afa27 Mon Sep 17 00:00:00 2001 From: Alessandro Cresto Miseroglio Date: Thu, 4 Jul 2019 20:41:48 +0200 Subject: [PATCH 05/11] Remove loops witch never loops fixes #642 --- src/dimension/dimension_trait.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/dimension/dimension_trait.rs b/src/dimension/dimension_trait.rs index e9c99ede6..8f964716a 100644 --- a/src/dimension/dimension_trait.rs +++ b/src/dimension/dimension_trait.rs @@ -130,9 +130,8 @@ pub trait Dimension: if self.slice().iter().all(|&d| d != 0) { let mut it = strides.slice_mut().iter_mut().rev(); // Set first element to 1 - while let Some(rs) = it.next() { + if let Some(rs) = it.next() { *rs = 1; - break; } let mut cum_prod = 1; for (rs, dim) in it.zip(self.slice().iter().rev()) { @@ -156,9 +155,8 @@ pub trait Dimension: if self.slice().iter().all(|&d| d != 0) { let mut it = strides.slice_mut().iter_mut(); // Set first element to 1 - while let Some(rs) = it.next() { + if let Some(rs) = it.next() { *rs = 1; - break; } let mut cum_prod = 1; for (rs, dim) in it.zip(self.slice()) { From 8db15b1a71d38358aabad2965d7736e26d5f0895 Mon Sep 17 00:00:00 2001 From: Alessandro Cresto Miseroglio Date: Thu, 4 Jul 2019 22:00:52 +0200 Subject: [PATCH 06/11] Remove useless inline attributes #642 --- src/dimension/mod.rs | 2 -- src/zip/mod.rs | 1 - 2 files changed, 3 deletions(-) diff --git a/src/dimension/mod.rs b/src/dimension/mod.rs index b2fa8caf6..b7cb9fed0 100644 --- a/src/dimension/mod.rs +++ b/src/dimension/mod.rs @@ -266,13 +266,11 @@ pub trait DimensionExt { /// Get the dimension at `axis`. /// /// *Panics* if `axis` is out of bounds. - #[inline] fn axis(&self, axis: Axis) -> Ix; /// Set the dimension at `axis`. /// /// *Panics* if `axis` is out of bounds. - #[inline] fn set_axis(&mut self, axis: Axis, value: Ix); } diff --git a/src/zip/mod.rs b/src/zip/mod.rs index 670585b4d..6472d1af2 100644 --- a/src/zip/mod.rs +++ b/src/zip/mod.rs @@ -178,7 +178,6 @@ pub trait NdProducer { #[doc(hidden)] fn stride_of(&self, axis: Axis) -> ::Stride; #[doc(hidden)] - #[inline(always)] fn contiguous_stride(&self) -> Self::Stride; #[doc(hidden)] fn split_at(self, axis: Axis, index: usize) -> (Self, Self) From db8ec89b957133135d6c89be1b5395a83505e94f Mon Sep 17 00:00:00 2001 From: Alessandro Cresto Miseroglio Date: Fri, 5 Jul 2019 11:44:03 +0200 Subject: [PATCH 07/11] Fix Clippy errors #642 --- src/dimension/dim.rs | 2 +- src/dimension/dynindeximpl.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dimension/dim.rs b/src/dimension/dim.rs index e42510000..5cedfe76d 100644 --- a/src/dimension/dim.rs +++ b/src/dimension/dim.rs @@ -44,7 +44,7 @@ pub struct Dim { impl Dim { /// Private constructor and accessors for Dim pub(crate) fn new(index: I) -> Dim { - Dim { index: index } + Dim { index } } #[inline(always)] pub(crate) fn ix(&self) -> &I { diff --git a/src/dimension/dynindeximpl.rs b/src/dimension/dynindeximpl.rs index 17e8d3f89..e8bcf2b25 100644 --- a/src/dimension/dynindeximpl.rs +++ b/src/dimension/dynindeximpl.rs @@ -221,7 +221,7 @@ impl IxDyn { /// Create a new dimension value with `n` axes, all zeros #[inline] pub fn zeros(n: usize) -> IxDyn { - const ZEROS: &'static [usize] = &[0; 4]; + const ZEROS: &[usize] = &[0; 4]; if n <= ZEROS.len() { Dim(&ZEROS[..n]) } else { From 4c05652ad0393753f67df843ff04b3bfcd018001 Mon Sep 17 00:00:00 2001 From: Alessandro Cresto Miseroglio Date: Fri, 5 Jul 2019 11:52:34 +0200 Subject: [PATCH 08/11] Fix Clippy errors #642 Add comment on axis as remainder. --- src/dimension/axis.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/dimension/axis.rs b/src/dimension/axis.rs index e9137cb01..ec4e0e30e 100644 --- a/src/dimension/axis.rs +++ b/src/dimension/axis.rs @@ -29,6 +29,8 @@ impl Axis { copy_and_clone! {Axis} +// Hash and PartialEq must be explicitly implemented or both default-generated. +// ref: https://rust-lang.github.io/rust-clippy/master/index.html#derive_hash_xor_eq impl Hash for Axis { fn hash(&self, state: &mut H) { self.0.hash(state); From 71c0980f446e540f254bb472f237e56d4cb2c747 Mon Sep 17 00:00:00 2001 From: Alessandro Cresto Miseroglio Date: Fri, 5 Jul 2019 17:29:17 +0200 Subject: [PATCH 09/11] Fix since semver clippy error #642 --- src/data_traits.rs | 2 +- src/numeric/impl_numeric.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/data_traits.rs b/src/data_traits.rs index b8fe84234..482677b4f 100644 --- a/src/data_traits.rs +++ b/src/data_traits.rs @@ -133,7 +133,7 @@ pub unsafe trait DataMut: Data + RawDataMut { /// accessed with safe code. /// /// ***Internal trait, see `Data`.*** -#[deprecated(note = "use `Data + RawDataClone` instead", since = "0.13")] +#[deprecated(note = "use `Data + RawDataClone` instead", since = "0.13.0")] pub trait DataClone: Data + RawDataClone {} #[allow(deprecated)] diff --git a/src/numeric/impl_numeric.rs b/src/numeric/impl_numeric.rs index 08454c5c6..d2125556b 100644 --- a/src/numeric/impl_numeric.rs +++ b/src/numeric/impl_numeric.rs @@ -314,7 +314,7 @@ where /// **Panics** if broadcasting to the same shape isn’t possible. #[deprecated( note = "Use `abs_diff_eq` - it requires the `approx` crate feature", - since = "0.13" + since = "0.13.0" )] pub fn all_close(&self, rhs: &ArrayBase, tol: A) -> bool where From 6551df0a188fe249b07ae4052d99f94bea24873c Mon Sep 17 00:00:00 2001 From: Alessandro Cresto Miseroglio Date: Fri, 5 Jul 2019 17:37:04 +0200 Subject: [PATCH 10/11] Fix some clippy warnings #642 --- src/array_serde.rs | 2 +- src/arrayformat.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/array_serde.rs b/src/array_serde.rs index 468be50ff..3bf8a084a 100644 --- a/src/array_serde.rs +++ b/src/array_serde.rs @@ -139,7 +139,7 @@ impl ArrayVisitor { } } -static ARRAY_FIELDS: &'static [&'static str] = &["v", "dim", "data"]; +static ARRAY_FIELDS: &[&str] = &["v", "dim", "data"]; /// **Requires crate feature `"serde-1"`** impl<'de, A, Di, S> Deserialize<'de> for ArrayBase diff --git a/src/arrayformat.rs b/src/arrayformat.rs index fa6225882..f96e9008e 100644 --- a/src/arrayformat.rs +++ b/src/arrayformat.rs @@ -52,13 +52,13 @@ enum PrintableCell { fn to_be_printed(length: usize, limit: usize) -> Vec { if length <= 2 * limit { (0..length) - .map(|x| PrintableCell::ElementIndex(x)) + .map(PrintableCell::ElementIndex) .collect() } else { let mut v: Vec = - (0..limit).map(|x| PrintableCell::ElementIndex(x)).collect(); + (0..limit).map(PrintableCell::ElementIndex).collect(); v.push(PrintableCell::Ellipses); - v.extend((length - limit..length).map(|x| PrintableCell::ElementIndex(x))); + v.extend((length - limit..length).map(PrintableCell::ElementIndex)); v } } From a2b81881c38ccdc7f2a06a6c496c247035f0012a Mon Sep 17 00:00:00 2001 From: Alessandro Cresto Miseroglio Date: Sat, 6 Jul 2019 15:12:43 +0200 Subject: [PATCH 11/11] Fix clippy warnings #642 --- src/arrayformat.rs | 7 ++--- src/dimension/dimension_trait.rs | 7 +++-- src/dimension/dynindeximpl.rs | 12 +++++---- src/dimension/mod.rs | 19 +++++++++---- src/geomspace.rs | 2 +- src/impl_1d.rs | 1 + src/impl_clone.rs | 4 +-- src/impl_constructors.rs | 8 +++--- src/impl_methods.rs | 30 ++++++++++++--------- src/impl_raw_views.rs | 10 +++---- src/impl_views.rs | 12 +++++---- src/indexes.rs | 12 ++++----- src/iterators/chunks.rs | 8 +++--- src/iterators/mod.rs | 46 +++++++++++++++----------------- src/iterators/windows.rs | 2 +- src/layout/layoutfmt.rs | 2 +- 16 files changed, 99 insertions(+), 83 deletions(-) diff --git a/src/arrayformat.rs b/src/arrayformat.rs index f96e9008e..d753fe473 100644 --- a/src/arrayformat.rs +++ b/src/arrayformat.rs @@ -51,12 +51,9 @@ enum PrintableCell { // where indexes are being omitted. fn to_be_printed(length: usize, limit: usize) -> Vec { if length <= 2 * limit { - (0..length) - .map(PrintableCell::ElementIndex) - .collect() + (0..length).map(PrintableCell::ElementIndex).collect() } else { - let mut v: Vec = - (0..limit).map(PrintableCell::ElementIndex).collect(); + let mut v: Vec = (0..limit).map(PrintableCell::ElementIndex).collect(); v.push(PrintableCell::Ellipses); v.extend((length - limit..length).map(PrintableCell::ElementIndex)); v diff --git a/src/dimension/dimension_trait.rs b/src/dimension/dimension_trait.rs index 8f964716a..eb7b55e6b 100644 --- a/src/dimension/dimension_trait.rs +++ b/src/dimension/dimension_trait.rs @@ -360,14 +360,14 @@ pub trait Dimension: } // Dimension impls - +#[allow(clippy::range_plus_one)] macro_rules! impl_insert_axis_array( ($n:expr) => ( fn insert_axis(&self, axis: Axis) -> Self::Larger { debug_assert!(axis.index() <= $n); let mut out = [1; $n + 1]; out[0..axis.index()].copy_from_slice(&self.slice()[0..axis.index()]); - out[axis.index()+1..$n+1].copy_from_slice(&self.slice()[axis.index()..$n]); + out[axis.index()+1..=$n].copy_from_slice(&self.slice()[axis.index()..$n]); Dim(out) } ); @@ -659,6 +659,7 @@ impl Dimension for Dim<[Ix; 2]> { } /// Return stride offset for this dimension and index. + #[allow(clippy::many_single_char_names)] #[inline] fn stride_offset_checked(&self, strides: &Self, index: &Self) -> Option { let m = get!(self, 0); @@ -743,6 +744,7 @@ impl Dimension for Dim<[Ix; 3]> { } /// Self is an index, return the stride offset + #[allow(clippy::many_single_char_names)] #[inline] fn stride_offset(index: &Self, strides: &Self) -> isize { let i = get!(index, 0); @@ -755,6 +757,7 @@ impl Dimension for Dim<[Ix; 3]> { } /// Return stride offset for this dimension and index. + #[allow(clippy::many_single_char_names)] #[inline] fn stride_offset_checked(&self, strides: &Self, index: &Self) -> Option { let m = get!(self, 0); diff --git a/src/dimension/dynindeximpl.rs b/src/dimension/dynindeximpl.rs index e8bcf2b25..28d84411e 100644 --- a/src/dimension/dynindeximpl.rs +++ b/src/dimension/dynindeximpl.rs @@ -48,9 +48,10 @@ impl IxDynRepr { pub fn copy_from(x: &[T]) -> Self { if x.len() <= CAP { let mut arr = [T::zero(); CAP]; - for i in 0..x.len() { - arr[i] = x[i]; - } + arr[..x.len()].clone_from_slice(&x[..]); + //for i in 0..x.len() { + // arr[i] = x[i]; + //} IxDynRepr::Inline(x.len() as _, arr) } else { Self::from(x) @@ -121,7 +122,7 @@ impl IxDynImpl { IxDynImpl(if len < CAP { let mut out = [1; CAP]; out[0..i].copy_from_slice(&self[0..i]); - out[i + 1..len + 1].copy_from_slice(&self[i..len]); + out[i + 1..=len].copy_from_slice(&self[i..len]); IxDynRepr::Inline((len + 1) as u32, out) } else { let mut out = Vec::with_capacity(len + 1); @@ -206,7 +207,8 @@ impl<'a> IntoIterator for &'a IxDynImpl { type IntoIter = <&'a [Ix] as IntoIterator>::IntoIter; #[inline] fn into_iter(self) -> Self::IntoIter { - self[..].into_iter() + //self[..].into_iter() + self[..].iter() } } diff --git a/src/dimension/mod.rs b/src/dimension/mod.rs index b7cb9fed0..b921b09c4 100644 --- a/src/dimension/mod.rs +++ b/src/dimension/mod.rs @@ -420,6 +420,7 @@ pub fn do_slice(dim: &mut usize, stride: &mut usize, slice: Slice) -> isize { /// nonnegative. /// /// See https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm +#[allow(clippy::many_single_char_names)] fn extended_gcd(a: isize, b: isize) -> (isize, (isize, isize)) { if a == 0 { (b.abs(), (0, b.signum())) @@ -456,6 +457,7 @@ fn extended_gcd(a: isize, b: isize) -> (isize, (isize, isize)) { /// /// See https://en.wikipedia.org/wiki/Diophantine_equation#One_equation /// and https://math.stackexchange.com/questions/1656120#1656138 +#[allow(clippy::many_single_char_names)] fn solve_linear_diophantine_eq(a: isize, b: isize, c: isize) -> Option<(isize, isize)> { debug_assert_ne!(a, 0); debug_assert_ne!(b, 0); @@ -535,14 +537,21 @@ fn arith_seq_intersect( /// If the slice is empty, then returns `None`, otherwise returns `Some((min, max))`. fn slice_min_max(axis_len: usize, slice: Slice) -> Option<(usize, usize)> { let (start, end, step) = to_abs_slice(axis_len, slice); + //if start == end { + // None + //} else { + // if step > 0 { + // Some((start, end - 1 - (end - start - 1) % (step as usize))) + // } else { + // Some((start + (end - start - 1) % (-step as usize), end - 1)) + // } + //} if start == end { None + } else if step > 0 { + Some((start, end - 1 - (end - start - 1) % (step as usize))) } else { - if step > 0 { - Some((start, end - 1 - (end - start - 1) % (step as usize))) - } else { - Some((start + (end - start - 1) % (-step as usize), end - 1)) - } + Some((start + (end - start - 1) % (-step as usize), end - 1)) } } diff --git a/src/geomspace.rs b/src/geomspace.rs index c595025b6..06242f68e 100644 --- a/src/geomspace.rs +++ b/src/geomspace.rs @@ -96,7 +96,7 @@ where Some(Geomspace { sign: a.signum(), start: log_a, - step: step, + step, index: 0, len: n, }) diff --git a/src/impl_1d.rs b/src/impl_1d.rs index 73d5e837e..52af58f20 100644 --- a/src/impl_1d.rs +++ b/src/impl_1d.rs @@ -15,6 +15,7 @@ where S: RawData, { /// Return an vector with the elements of the one-dimensional array. + #[allow(clippy::map_clone)] pub fn to_vec(&self) -> Vec where A: Clone, diff --git a/src/impl_clone.rs b/src/impl_clone.rs index af009feb4..013f070ca 100644 --- a/src/impl_clone.rs +++ b/src/impl_clone.rs @@ -13,8 +13,8 @@ impl Clone for ArrayBase { unsafe { let (data, ptr) = self.data.clone_with_ptr(self.ptr); ArrayBase { - data: data, - ptr: ptr, + data, + ptr, dim: self.dim.clone(), strides: self.strides.clone(), } diff --git a/src/impl_constructors.rs b/src/impl_constructors.rs index 638a633fc..53e12f11f 100644 --- a/src/impl_constructors.rs +++ b/src/impl_constructors.rs @@ -62,6 +62,7 @@ where /// let array = Array::from_iter((0..5).map(|x| x * x)); /// assert!(array == arr1(&[0, 1, 4, 9, 16])) /// ``` + #[allow(clippy::should_implement_trait)] pub fn from_iter(iterable: I) -> Self where I: IntoIterator, @@ -212,7 +213,7 @@ macro_rules! size_of_shape_checked_unwrap { ($dim:expr) => { match dimension::size_of_shape_checked($dim) { Ok(sz) => sz, - Err(_) => panic!( + Err(_e) => panic!( "ndarray: Shape too large, product of non-zero axis lengths \ overflows isize in shape {:?}", $dim @@ -315,6 +316,7 @@ where /// visited in arbitrary order. /// /// **Panics** if the product of non-zero axis lengths overflows `isize`. + #[allow(clippy::identity_conversion)] pub fn from_shape_fn(shape: Sh, f: F) -> Self where Sh: ShapeBuilder, @@ -422,8 +424,8 @@ where ArrayBase { ptr: v.as_mut_ptr(), data: DataOwned::new(v), - strides: strides, - dim: dim, + strides, + dim, } } diff --git a/src/impl_methods.rs b/src/impl_methods.rs index 19775809b..018afce33 100644 --- a/src/impl_methods.rs +++ b/src/impl_methods.rs @@ -225,7 +225,7 @@ where { let data = self.data.into_shared(); ArrayBase { - data: data, + data, ptr: self.ptr, dim: self.dim, strides: self.strides, @@ -373,9 +373,9 @@ where 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, + .filter_map(|(d, s, slice_or_index)| match *slice_or_index { + SliceOrIndex::Slice { .. } => Some((d, s)), + SliceOrIndex::Index(_) => None, }) .zip(izip!(new_dim.slice_mut(), new_strides.slice_mut())) .for_each(|((d, s), (new_d, new_s))| { @@ -411,11 +411,11 @@ where indices .iter() .enumerate() - .for_each(|(axis, slice_or_index)| match slice_or_index { - &SliceOrIndex::Slice { start, end, step } => { + .for_each(|(axis, slice_or_index)| match *slice_or_index { + SliceOrIndex::Slice { start, end, step } => { self.slice_axis_inplace(Axis(axis), Slice { start, end, step }) } - &SliceOrIndex::Index(index) => { + SliceOrIndex::Index(index) => { let i_usize = abs_index(self.len_of(Axis(axis)), index); self.collapse_axis(Axis(axis), i_usize) } @@ -1195,10 +1195,13 @@ where /// contiguous in memory, it has custom strides, etc. pub fn is_standard_layout(&self) -> bool { fn is_standard_layout(dim: &D, strides: &D) -> bool { - match D::NDIM { - Some(1) => return strides[0] == 1 || dim[0] <= 1, - _ => {} - } + if let Some(1) = D::NDIM { + return strides[0] == 1 || dim[0] <= 1; + }; + //match D::NDIM { + // Some(1) => return strides[0] == 1 || dim[0] <= 1, + // _ => {} + //} if dim.slice().iter().any(|&d| d == 0) { return true; } @@ -1426,6 +1429,7 @@ where /// [3., 4.]]) /// ); /// ``` + #[allow(clippy::map_clone)] pub fn reshape(&self, shape: E) -> ArrayBase where S: DataShared + DataOwned, @@ -1495,8 +1499,8 @@ where return Ok(ArrayBase { data: self.data, ptr: self.ptr, - dim: dim, - strides: strides, + dim, + strides, }); } } diff --git a/src/impl_raw_views.rs b/src/impl_raw_views.rs index 5cb8b13b6..e5cf8438a 100644 --- a/src/impl_raw_views.rs +++ b/src/impl_raw_views.rs @@ -15,8 +15,8 @@ where RawArrayView { data: RawViewRepr::new(), ptr: ptr as *mut A, - dim: dim, - strides: strides, + dim, + strides, } } @@ -118,9 +118,9 @@ where pub(crate) unsafe fn new_(ptr: *mut A, dim: D, strides: D) -> Self { RawArrayViewMut { data: RawViewRepr::new(), - ptr: ptr, - dim: dim, - strides: strides, + ptr, + dim, + strides, } } diff --git a/src/impl_views.rs b/src/impl_views.rs index 98e324418..4198679d1 100644 --- a/src/impl_views.rs +++ b/src/impl_views.rs @@ -137,6 +137,8 @@ where /// Return the array’s data as a slice, if it is contiguous and in standard order. /// Return `None` otherwise. + // FIXME: maybe a different name should be considered + #[allow(clippy::wrong_self_convention)] pub fn into_slice(&self) -> Option<&'a [A]> { if self.is_standard_layout() { unsafe { Some(slice::from_raw_parts(self.ptr, self.len())) } @@ -476,8 +478,8 @@ where ArrayView { data: ViewRepr::new(), ptr: ptr as *mut A, - dim: dim, - strides: strides, + dim, + strides, } } @@ -522,9 +524,9 @@ where } ArrayViewMut { data: ViewRepr::new(), - ptr: ptr, - dim: dim, - strides: strides, + ptr, + dim, + strides, } } diff --git a/src/indexes.rs b/src/indexes.rs index ee5e5e9e5..2a9ac488e 100644 --- a/src/indexes.rs +++ b/src/indexes.rs @@ -33,7 +33,7 @@ where let dim = shape.into_dimension(); Indices { start: E::Dim::zeros(dim.ndim()), - dim: dim, + dim, } } @@ -94,7 +94,7 @@ where let sz = self.dim.size(); let index = if sz != 0 { Some(self.start) } else { None }; IndicesIter { - index: index, + index, dim: self.dim, } } @@ -172,7 +172,7 @@ impl NdProducer for Indices { unsafe fn uget_ptr(&self, i: &Self::Dim) -> Self::Ptr { let mut index = *i; index += &self.start; - IndexPtr { index: index } + IndexPtr { index } } #[doc(hidden)] @@ -219,11 +219,11 @@ where E: IntoDimension, { let dim = shape.into_dimension(); - let zero = E::Dim::zeros(dim.ndim()); + let index = E::Dim::zeros(dim.ndim()); IndicesIterF { has_remaining: dim.size_checked() != Some(0), - index: zero, - dim: dim, + index, + dim, } } diff --git a/src/iterators/chunks.rs b/src/iterators/chunks.rs index 19c7529be..a3e781d5a 100644 --- a/src/iterators/chunks.rs +++ b/src/iterators/chunks.rs @@ -64,8 +64,8 @@ impl<'a, A, D: Dimension> ExactChunks<'a, A, D> { ExactChunks { base: a, - chunk: chunk, - inner_strides: inner_strides, + chunk, + inner_strides, } } } @@ -154,8 +154,8 @@ impl<'a, A, D: Dimension> ExactChunksMut<'a, A, D> { ExactChunksMut { base: a, - chunk: chunk, - inner_strides: inner_strides, + chunk, + inner_strides, } } } diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs index 22bc989c2..a7d6e364a 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -45,7 +45,7 @@ impl Baseiter { #[inline] pub unsafe fn new(ptr: *mut A, len: D, stride: D) -> Baseiter { Baseiter { - ptr: ptr, + ptr, index: len.first_index(), dim: len, strides: stride, @@ -79,23 +79,19 @@ impl Iterator for Baseiter { let ndim = self.dim.ndim(); debug_assert_ne!(ndim, 0); let mut accum = init; - loop { - if let Some(mut index) = self.index.clone() { - let stride = self.strides.last_elem() as isize; - let elem_index = index.last_elem(); - let len = self.dim.last_elem(); - let offset = D::stride_offset(&index, &self.strides); - unsafe { - let row_ptr = self.ptr.offset(offset); - for i in 0..(len - elem_index) { - accum = g(accum, row_ptr.offset(i as isize * stride)); - } + while let Some(mut index) = self.index.clone() { + let stride = self.strides.last_elem() as isize; + let elem_index = index.last_elem(); + let len = self.dim.last_elem(); + let offset = D::stride_offset(&index, &self.strides); + unsafe { + let row_ptr = self.ptr.offset(offset); + for i in 0..(len - elem_index) { + accum = g(accum, row_ptr.offset(i as isize * stride)); } - index.set_last_elem(len - 1); - self.index = self.dim.next_for(index); - } else { - break; - }; + } + index.set_last_elem(len - 1); + self.index = self.dim.next_for(index); } accum } @@ -776,7 +772,7 @@ impl AxisIterCore { AxisIterCore { index: 0, len: shape, - stride: stride, + stride, inner_dim: v.dim.remove_axis(axis), inner_strides: v.strides.remove_axis(axis), ptr: v.ptr, @@ -1198,8 +1194,8 @@ fn chunk_iter_parts( let iter = AxisIterCore { index: 0, len: iter_len, - stride: stride, - inner_dim: inner_dim, + stride, + inner_dim, inner_strides: v.strides, ptr: v.ptr, }; @@ -1211,9 +1207,9 @@ impl<'a, A, D: Dimension> AxisChunksIter<'a, A, D> { pub(crate) fn new(v: ArrayView<'a, A, D>, axis: Axis, size: usize) -> Self { let (iter, n_whole_chunks, last_dim) = chunk_iter_parts(v, axis, size); AxisChunksIter { - iter: iter, - n_whole_chunks: n_whole_chunks, - last_dim: last_dim, + iter, + n_whole_chunks, + last_dim, life: PhantomData, } } @@ -1306,9 +1302,9 @@ impl<'a, A, D: Dimension> AxisChunksIterMut<'a, A, D> { pub(crate) fn new(v: ArrayViewMut<'a, A, D>, axis: Axis, size: usize) -> Self { let (iter, len, last_dim) = chunk_iter_parts(v.into_view(), axis, size); AxisChunksIterMut { - iter: iter, + iter, n_whole_chunks: len, - last_dim: last_dim, + last_dim, life: PhantomData, } } diff --git a/src/iterators/windows.rs b/src/iterators/windows.rs index 964e05c4d..654be7a01 100644 --- a/src/iterators/windows.rs +++ b/src/iterators/windows.rs @@ -42,7 +42,7 @@ impl<'a, A, D: Dimension> Windows<'a, A, D> { unsafe { Windows { base: ArrayView::from_shape_ptr(size.clone().strides(a.strides), a.ptr), - window: window, + window, strides: window_strides, } } diff --git a/src/layout/layoutfmt.rs b/src/layout/layoutfmt.rs index 3ad8aa3c7..d785a17a0 100644 --- a/src/layout/layoutfmt.rs +++ b/src/layout/layoutfmt.rs @@ -10,7 +10,7 @@ use super::Layout; use super::LayoutPriv; use itertools::Itertools; -const LAYOUT_NAMES: &'static [&'static str] = &["C", "F"]; +const LAYOUT_NAMES: &[&str] = &["C", "F"]; use std::fmt;