From e768f7077333c202fcc4853c6fb0972c663a7f3d Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Thu, 13 Jun 2019 00:35:14 -0400 Subject: [PATCH 01/35] some initial clippy fixes --- src/arrayformat.rs | 6 +++--- src/impl_methods.rs | 11 +++++------ src/macro_utils.rs | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) 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 } } diff --git a/src/impl_methods.rs b/src/impl_methods.rs index 53730d4fb..fe2c05498 100644 --- a/src/impl_methods.rs +++ b/src/impl_methods.rs @@ -1128,7 +1128,7 @@ where fn diag_params(&self) -> (Ix, Ixs) { /* empty shape has len 1 */ let len = self.dim.slice().iter().cloned().min().unwrap_or(1); - let stride = self.strides().iter().fold(0, |sum, s| sum + s); + let stride = self.strides().iter().sum(); (len, stride) } @@ -1195,9 +1195,8 @@ 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 } if dim.slice().iter().any(|&d| d == 0) { return true; @@ -1408,7 +1407,7 @@ where dim: shape, } } else { - let v = self.iter().map(|x| x.clone()).collect::>(); + let v = self.iter().cloned().collect::>(); unsafe { ArrayBase::from_shape_vec_unchecked(shape, v) } } } @@ -1778,7 +1777,7 @@ where } Some(slc) => { let ptr = slc.as_ptr() as *mut A; - let end = unsafe { ptr.offset(slc.len() as isize) }; + let end = unsafe { ptr.add(slc.len()) }; self.ptr >= ptr && self.ptr <= end } } diff --git a/src/macro_utils.rs b/src/macro_utils.rs index 85b5c260e..0480b7c91 100644 --- a/src/macro_utils.rs +++ b/src/macro_utils.rs @@ -61,7 +61,7 @@ macro_rules! expand_if { #[cfg(debug_assertions)] macro_rules! debug_bounds_check { ($self_:ident, $index:expr) => { - if let None = $index.index_checked(&$self_.dim, &$self_.strides) { + if $index.index_checked(&$self_.dim, &$self_.strides).is_none() { panic!( "ndarray: index {:?} is out of bounds for array of shape {:?}", $index, From cea9596de46a3b52ad98afaeaa2e22574ef643c5 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Thu, 13 Jun 2019 10:46:37 -0400 Subject: [PATCH 02/35] some clippy lints cleaned --- benches/iter.rs | 6 ++++++ examples/life.rs | 6 ++++++ src/data_traits.rs | 2 +- src/dimension/axes.rs | 2 +- src/dimension/axis.rs | 2 +- src/dimension/dim.rs | 2 +- src/dimension/dimension_trait.rs | 6 ++---- src/dimension/mod.rs | 8 +++----- src/impl_raw_views.rs | 10 +++++----- src/impl_views.rs | 10 +++++----- src/indexes.rs | 8 ++++---- src/layout/layoutfmt.rs | 2 +- src/layout/mod.rs | 2 +- src/lib.rs | 10 ++++++++-- src/numeric/impl_numeric.rs | 2 +- src/zip/mod.rs | 1 - tests/array-construct.rs | 6 ++++++ tests/array.rs | 6 ++++++ tests/iterator_chunks.rs | 4 ++-- tests/iterators.rs | 12 +++++++++--- tests/ixdyn.rs | 6 ++++++ tests/numeric.rs | 6 ++++++ tests/oper.rs | 7 +++++++ 23 files changed, 88 insertions(+), 38 deletions(-) diff --git a/benches/iter.rs b/benches/iter.rs index 82499f50a..8aa28d288 100644 --- a/benches/iter.rs +++ b/benches/iter.rs @@ -1,4 +1,10 @@ #![feature(test)] +#![allow( + clippy::many_single_char_names, + clippy::deref_addrof, + clippy::unreadable_literal, + clippy::many_single_char_names +)] extern crate rawpointer; extern crate test; diff --git a/examples/life.rs b/examples/life.rs index c410ef98c..14fa1193d 100644 --- a/examples/life.rs +++ b/examples/life.rs @@ -1,3 +1,9 @@ +#![allow( + clippy::many_single_char_names, + clippy::deref_addrof, + clippy::unreadable_literal, + clippy::many_single_char_names +)] extern crate ndarray; use ndarray::prelude::*; diff --git a/src/data_traits.rs b/src/data_traits.rs index b8fe84234..aeb9e9012 100644 --- a/src/data_traits.rs +++ b/src/data_traits.rs @@ -241,7 +241,7 @@ unsafe impl Data for OwnedArcRepr { Self::ensure_unique(&mut self_); let data = OwnedRepr(Arc::try_unwrap(self_.data.0).ok().unwrap()); ArrayBase { - data: data, + data, ptr: self_.ptr, dim: self_.dim, strides: self_.strides, diff --git a/src/dimension/axes.rs b/src/dimension/axes.rs index 4ac61afb2..aae35a9a5 100644 --- a/src/dimension/axes.rs +++ b/src/dimension/axes.rs @@ -7,7 +7,7 @@ where { Axes { dim: d, - strides: strides, + strides, start: 0, end: d.ndim(), } diff --git a/src/dimension/axis.rs b/src/dimension/axis.rs index 6fc389988..9accdd963 100644 --- a/src/dimension/axis.rs +++ b/src/dimension/axis.rs @@ -15,7 +15,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 { diff --git a/src/dimension/dim.rs b/src/dimension/dim.rs index 62a9e0b1f..2d93f0e95 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/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()) { diff --git a/src/dimension/mod.rs b/src/dimension/mod.rs index b2fa8caf6..7faf60245 100644 --- a/src/dimension/mod.rs +++ b/src/dimension/mod.rs @@ -539,12 +539,10 @@ 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 { - 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/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..386c869f4 100644 --- a/src/impl_views.rs +++ b/src/impl_views.rs @@ -476,8 +476,8 @@ where ArrayView { data: ViewRepr::new(), ptr: ptr as *mut A, - dim: dim, - strides: strides, + dim, + strides, } } @@ -522,9 +522,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..1350819b5 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)] @@ -223,7 +223,7 @@ where IndicesIterF { has_remaining: dim.size_checked() != Some(0), index: zero, - dim: dim, + dim, } } 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; diff --git a/src/layout/mod.rs b/src/layout/mod.rs index bb031838b..ea9209088 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -57,5 +57,5 @@ impl Layout { } } -pub const CORDER: u32 = 1 << 0; +pub const CORDER: u32 = 1; pub const FORDER: u32 = 1 << 1; diff --git a/src/lib.rs b/src/lib.rs index 9741989d5..5db1a96c4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,12 @@ // except according to those terms. #![crate_name = "ndarray"] #![doc(html_root_url = "https://docs.rs/ndarray/0.12/")] +#![allow( + clippy::many_single_char_names, + clippy::deref_addrof, + clippy::unreadable_literal, + clippy::many_single_char_names +)] //! The `ndarray` crate provides an *n*-dimensional container for general elements //! and for numerics. @@ -1552,8 +1558,8 @@ where { if let Some(slc) = self.as_slice_memory_order_mut() { // FIXME: Use for loop when slice iterator is perf is restored - for i in 0..slc.len() { - f(&mut slc[i]); + for x in slc.iter_mut() { + f(x); } return; } 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 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) diff --git a/tests/array-construct.rs b/tests/array-construct.rs index 1228fe9ec..09b8a2d04 100644 --- a/tests/array-construct.rs +++ b/tests/array-construct.rs @@ -1,3 +1,9 @@ +#![allow( + clippy::many_single_char_names, + clippy::deref_addrof, + clippy::unreadable_literal, + clippy::many_single_char_names +)] extern crate defmac; extern crate ndarray; diff --git a/tests/array.rs b/tests/array.rs index 000057b07..ca7295408 100644 --- a/tests/array.rs +++ b/tests/array.rs @@ -1,4 +1,10 @@ #![allow(non_snake_case)] +#![allow( + clippy::many_single_char_names, + clippy::deref_addrof, + clippy::unreadable_literal, + clippy::many_single_char_names +)] extern crate defmac; extern crate itertools; diff --git a/tests/iterator_chunks.rs b/tests/iterator_chunks.rs index 9453c0cea..d0c166e8f 100644 --- a/tests/iterator_chunks.rs +++ b/tests/iterator_chunks.rs @@ -10,8 +10,8 @@ fn chunks() { .unwrap(); let (m, n) = a.dim(); - for i in 1..m + 1 { - for j in 1..n + 1 { + for i in 1..=m { + for j in 1..=n { let c = a.exact_chunks((i, j)); let ly = n / j; diff --git a/tests/iterators.rs b/tests/iterators.rs index 6229f790c..2fe8521a8 100644 --- a/tests/iterators.rs +++ b/tests/iterators.rs @@ -1,3 +1,9 @@ +#![allow( + clippy::many_single_char_names, + clippy::deref_addrof, + clippy::unreadable_literal, + clippy::many_single_char_names +)] extern crate itertools; extern crate ndarray; @@ -11,7 +17,7 @@ use itertools::{enumerate, rev}; #[test] fn double_ended() { let a = ArcArray::linspace(0., 7., 8); - let mut it = a.iter().map(|x| *x); + let mut it = a.iter().copied(); assert_eq!(it.next(), Some(0.)); assert_eq!(it.next_back(), Some(7.)); assert_eq!(it.next(), Some(1.)); @@ -555,11 +561,11 @@ fn test_fold() { a += 1; let mut iter = a.iter(); iter.next(); - assert_eq!(iter.fold(0, |acc, &x| acc + x), a.sum() - 1); + assert_eq!(iter.sum::(), a.sum() - 1); let mut a = Array0::::default(()); a += 1; - assert_eq!(a.iter().fold(0, |acc, &x| acc + x), 1); + assert_eq!(a.iter().sum::(), 1); } #[test] diff --git a/tests/ixdyn.rs b/tests/ixdyn.rs index 814eeaefb..d5ebba035 100644 --- a/tests/ixdyn.rs +++ b/tests/ixdyn.rs @@ -1,3 +1,9 @@ +#![allow( + clippy::many_single_char_names, + clippy::deref_addrof, + clippy::unreadable_literal, + clippy::many_single_char_names +)] extern crate ndarray; use ndarray::Array; diff --git a/tests/numeric.rs b/tests/numeric.rs index b9e984d8e..c3fd0fb08 100644 --- a/tests/numeric.rs +++ b/tests/numeric.rs @@ -1,3 +1,9 @@ +#![allow( + clippy::many_single_char_names, + clippy::deref_addrof, + clippy::unreadable_literal, + clippy::many_single_char_names +)] extern crate approx; use approx::assert_abs_diff_eq; use ndarray::{arr0, arr1, arr2, array, aview1, Array, Array1, Array2, Array3, Axis}; diff --git a/tests/oper.rs b/tests/oper.rs index 18a2a4ab8..eae0c910c 100644 --- a/tests/oper.rs +++ b/tests/oper.rs @@ -1,3 +1,10 @@ +#![allow( + clippy::many_single_char_names, + clippy::deref_addrof, + clippy::unreadable_literal, + clippy::many_single_char_names +)] + extern crate approx; extern crate defmac; extern crate ndarray; From 82210d770b4a141f8b576aa8ae04b2bc39554e07 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Thu, 13 Jun 2019 10:54:17 -0400 Subject: [PATCH 03/35] one more --- tests/array.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/array.rs b/tests/array.rs index ca7295408..e128e8e04 100644 --- a/tests/array.rs +++ b/tests/array.rs @@ -579,7 +579,7 @@ fn test_negative_stride_arcarray() { let seq = [ 7f32, 6., 5., 4., 3., 2., 1., 0., 15., 14., 13., 12., 11., 10., 9., 8., ]; - for (a, b) in vi.clone().iter().zip(seq.iter()) { + for (a, b) in vi.iter().zip(seq.iter()) { assert_eq!(*a, *b); } } From 0ed84b5b3ae17e7ecddf41e1ca493da58a389fa8 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Thu, 13 Jun 2019 14:19:43 -0400 Subject: [PATCH 04/35] more lints --- benches/bench1.rs | 15 ++++++++++++--- benches/chunks.rs | 1 + benches/construct.rs | 7 ++++++- benches/gemv.rs | 6 ++++++ benches/higher-order.rs | 11 ++++++++--- benches/iter.rs | 18 +++++++++--------- src/data_traits.rs | 2 +- src/dimension/mod.rs | 2 -- tests/array.rs | 1 + 9 files changed, 44 insertions(+), 19 deletions(-) diff --git a/benches/bench1.rs b/benches/bench1.rs index 6f47b6b59..609a2eb0e 100644 --- a/benches/bench1.rs +++ b/benches/bench1.rs @@ -1,5 +1,11 @@ #![feature(test)] #![allow(unused_imports)] +#![allow( + clippy::many_single_char_names, + clippy::deref_addrof, + clippy::unreadable_literal, + clippy::many_single_char_names +)] extern crate ndarray; extern crate test; @@ -304,6 +310,7 @@ fn add_2d_zip_cutout(bench: &mut test::Bencher) { } #[bench] +#[allow(clippy::identity_op)] fn add_2d_cutouts_by_4(bench: &mut test::Bencher) { let mut a = Array::::zeros((64 * 1, 64 * 1)); let b = Array::::zeros((64 * 1, 64 * 1)); @@ -316,6 +323,7 @@ fn add_2d_cutouts_by_4(bench: &mut test::Bencher) { } #[bench] +#[allow(clippy::identity_op)] fn add_2d_cutouts_by_16(bench: &mut test::Bencher) { let mut a = Array::::zeros((64 * 1, 64 * 1)); let b = Array::::zeros((64 * 1, 64 * 1)); @@ -328,6 +336,7 @@ fn add_2d_cutouts_by_16(bench: &mut test::Bencher) { } #[bench] +#[allow(clippy::identity_op)] fn add_2d_cutouts_by_32(bench: &mut test::Bencher) { let mut a = Array::::zeros((64 * 1, 64 * 1)); let b = Array::::zeros((64 * 1, 64 * 1)); @@ -580,7 +589,7 @@ fn iadd_scalar_2d_strided_dyn(bench: &mut test::Bencher) { fn scaled_add_2d_f32_regular(bench: &mut test::Bencher) { let mut av = Array::::zeros((ADD2DSZ, ADD2DSZ)); let bv = Array::::zeros((ADD2DSZ, ADD2DSZ)); - let scalar = 3.1415926535; + let scalar = std::f32::consts::Pi; bench.iter(|| { av.scaled_add(scalar, &bv); }); @@ -650,7 +659,7 @@ fn bench_row_iter(bench: &mut test::Bencher) { let a = Array::::zeros((1024, 1024)); let it = a.row(17); bench.iter(|| { - for elt in it.clone() { + for elt in it { black_box(elt); } }) @@ -661,7 +670,7 @@ fn bench_col_iter(bench: &mut test::Bencher) { let a = Array::::zeros((1024, 1024)); let it = a.column(17); bench.iter(|| { - for elt in it.clone() { + for elt in it { black_box(elt); } }) diff --git a/benches/chunks.rs b/benches/chunks.rs index 3bdcb1c59..aa67790ac 100644 --- a/benches/chunks.rs +++ b/benches/chunks.rs @@ -64,6 +64,7 @@ fn chunk2x2_sum_uget1(bench: &mut Bencher) { } #[bench] +#[allow(clippy::identity_op)] fn chunk2x2_sum_get2(bench: &mut Bencher) { let a = Array::::zeros((256, 256)); let chunksz = (2, 2); diff --git a/benches/construct.rs b/benches/construct.rs index b9a6a4566..ed09d794b 100644 --- a/benches/construct.rs +++ b/benches/construct.rs @@ -1,5 +1,10 @@ #![feature(test)] - +#![allow( + clippy::many_single_char_names, + clippy::deref_addrof, + clippy::unreadable_literal, + clippy::many_single_char_names +)] extern crate test; use test::Bencher; diff --git a/benches/gemv.rs b/benches/gemv.rs index 2cdb7cb2e..2c5b7dfcb 100644 --- a/benches/gemv.rs +++ b/benches/gemv.rs @@ -1,4 +1,10 @@ #![feature(test)] +#![allow( + clippy::many_single_char_names, + clippy::deref_addrof, + clippy::unreadable_literal, + clippy::many_single_char_names +)] extern crate test; use test::Bencher; diff --git a/benches/higher-order.rs b/benches/higher-order.rs index 95f076700..781c1cda9 100644 --- a/benches/higher-order.rs +++ b/benches/higher-order.rs @@ -1,5 +1,10 @@ #![feature(test)] - +#![allow( + clippy::many_single_char_names, + clippy::deref_addrof, + clippy::unreadable_literal, + clippy::many_single_char_names +)] extern crate test; use test::black_box; use test::Bencher; @@ -67,7 +72,7 @@ fn map_axis_0(bench: &mut Bencher) { let a = Array::from_iter(0..MASZ as i32) .into_shape([MA, MA]) .unwrap(); - bench.iter(|| a.map_axis(Axis(0), |lane| black_box(lane))); + bench.iter(|| a.map_axis(Axis(0), black_box)); } #[bench] @@ -75,5 +80,5 @@ fn map_axis_1(bench: &mut Bencher) { let a = Array::from_iter(0..MASZ as i32) .into_shape([MA, MA]) .unwrap(); - bench.iter(|| a.map_axis(Axis(1), |lane| black_box(lane))); + bench.iter(|| a.map_axis(Axis(1), black_box)); } diff --git a/benches/iter.rs b/benches/iter.rs index 8aa28d288..60879bf9e 100644 --- a/benches/iter.rs +++ b/benches/iter.rs @@ -20,7 +20,7 @@ use ndarray::{FoldWhile, Zip}; #[bench] fn iter_sum_2d_regular(bench: &mut Bencher) { let a = Array::::zeros((64, 64)); - bench.iter(|| a.iter().fold(0, |acc, &x| acc + x)); + bench.iter(|| a.iter().sum::()); } #[bench] @@ -28,7 +28,7 @@ fn iter_sum_2d_cutout(bench: &mut Bencher) { let a = Array::::zeros((66, 66)); let av = a.slice(s![1..-1, 1..-1]); let a = av; - bench.iter(|| a.iter().fold(0, |acc, &x| acc + x)); + bench.iter(|| a.iter().sum::()); } #[bench] @@ -43,21 +43,21 @@ fn iter_all_2d_cutout(bench: &mut Bencher) { fn iter_sum_2d_transpose(bench: &mut Bencher) { let a = Array::::zeros((66, 66)); let a = a.t(); - bench.iter(|| a.iter().fold(0, |acc, &x| acc + x)); + bench.iter(|| a.iter().sum::()); } #[bench] fn iter_filter_sum_2d_u32(bench: &mut Bencher) { let a = Array::linspace(0., 1., 256).into_shape((16, 16)).unwrap(); let b = a.mapv(|x| (x * 100.) as u32); - bench.iter(|| b.iter().filter(|&&x| x < 75).fold(0, |acc, &x| acc + x)); + bench.iter(|| b.iter().filter(|&&x| x < 75).sum::()); } #[bench] fn iter_filter_sum_2d_f32(bench: &mut Bencher) { let a = Array::linspace(0., 1., 256).into_shape((16, 16)).unwrap(); let b = a * 100.; - bench.iter(|| b.iter().filter(|&&x| x < 75.).fold(0., |acc, &x| acc + x)); + bench.iter(|| b.iter().filter(|&&x| x < 75.).sum::()); } #[bench] @@ -65,7 +65,7 @@ fn iter_filter_sum_2d_stride_u32(bench: &mut Bencher) { let a = Array::linspace(0., 1., 256).into_shape((16, 16)).unwrap(); let b = a.mapv(|x| (x * 100.) as u32); let b = b.slice(s![.., ..;2]); - bench.iter(|| b.iter().filter(|&&x| x < 75).fold(0, |acc, &x| acc + x)); + bench.iter(|| b.iter().filter(|&&x| x < 75).sum::()); } #[bench] @@ -73,7 +73,7 @@ fn iter_filter_sum_2d_stride_f32(bench: &mut Bencher) { let a = Array::linspace(0., 1., 256).into_shape((16, 16)).unwrap(); let b = a * 100.; let b = b.slice(s![.., ..;2]); - bench.iter(|| b.iter().filter(|&&x| x < 75.).fold(0., |acc, &x| acc + x)); + bench.iter(|| b.iter().filter(|&&x| x < 75.).sum::()); } const ZIPSZ: usize = 10_000; @@ -196,7 +196,7 @@ fn vector_sum_3_zip_unchecked_manual(bench: &mut Bencher) { let mut ap = a.as_ptr(); let mut bp = b.as_ptr(); let mut cp = c.as_mut_ptr(); - let cend = cp.offset(c.len() as isize); + let cend = cp.add(c.len()); while cp != cend { *cp.post_inc() += *ap.post_inc() + *bp.post_inc(); } @@ -316,7 +316,7 @@ fn indexed_iter_3d_dyn(bench: &mut Bencher) { fn iter_sum_1d_strided_fold(bench: &mut Bencher) { let mut a = Array::::ones(10240); a.slice_axis_inplace(Axis(0), Slice::new(0, None, 2)); - bench.iter(|| a.iter().fold(0, |acc, &x| acc + x)); + bench.iter(|| a.iter().sum::()); } #[bench] diff --git a/src/data_traits.rs b/src/data_traits.rs index aeb9e9012..d7135e67c 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/dimension/mod.rs b/src/dimension/mod.rs index 7faf60245..7db7fc88c 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/tests/array.rs b/tests/array.rs index e128e8e04..f5fcb779c 100644 --- a/tests/array.rs +++ b/tests/array.rs @@ -527,6 +527,7 @@ fn test_index_arrays() { } #[test] +#[allow(clippy::assign_op_pattern)] fn test_add() { let mut A = ArcArray::::zeros((2, 2)); for (i, elt) in A.iter_mut().enumerate() { From 09e4edf48eb79b0345f63edd1c8b99e31c0354b1 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Thu, 13 Jun 2019 14:49:50 -0400 Subject: [PATCH 05/35] even more --- benches/bench1.rs | 2 +- examples/axis_ops.rs | 6 ++++ examples/bounds_check_elim.rs | 6 ++++ examples/convo.rs | 1 + examples/life.rs | 4 +-- examples/zip_many.rs | 6 ++++ src/arrayformat.rs | 7 ++--- src/dimension/dimension_trait.rs | 2 +- src/dimension/dynindeximpl.rs | 2 +- src/geomspace.rs | 2 +- src/impl_clone.rs | 4 +-- src/impl_constructors.rs | 4 +-- src/impl_methods.rs | 9 +++--- src/iterators/chunks.rs | 8 +++--- src/iterators/mod.rs | 48 +++++++++++++++----------------- src/iterators/windows.rs | 2 +- src/linalg/impl_linalg.rs | 4 +-- src/linspace.rs | 4 +-- src/logspace.rs | 2 +- src/slice.rs | 7 ++--- src/stacking.rs | 2 +- tests/azip.rs | 6 ++++ tests/iterator_chunks.rs | 6 ++++ 23 files changed, 83 insertions(+), 61 deletions(-) diff --git a/benches/bench1.rs b/benches/bench1.rs index 609a2eb0e..ae5682c5a 100644 --- a/benches/bench1.rs +++ b/benches/bench1.rs @@ -589,7 +589,7 @@ fn iadd_scalar_2d_strided_dyn(bench: &mut test::Bencher) { fn scaled_add_2d_f32_regular(bench: &mut test::Bencher) { let mut av = Array::::zeros((ADD2DSZ, ADD2DSZ)); let bv = Array::::zeros((ADD2DSZ, ADD2DSZ)); - let scalar = std::f32::consts::Pi; + let scalar = std::f32::consts::PI; bench.iter(|| { av.scaled_add(scalar, &bv); }); diff --git a/examples/axis_ops.rs b/examples/axis_ops.rs index 671b3acb8..37e2c911d 100644 --- a/examples/axis_ops.rs +++ b/examples/axis_ops.rs @@ -1,3 +1,9 @@ +#![allow( + clippy::many_single_char_names, + clippy::deref_addrof, + clippy::unreadable_literal, + clippy::many_single_char_names +)] extern crate ndarray; use ndarray::prelude::*; diff --git a/examples/bounds_check_elim.rs b/examples/bounds_check_elim.rs index fd4eb9fab..45655d829 100644 --- a/examples/bounds_check_elim.rs +++ b/examples/bounds_check_elim.rs @@ -1,4 +1,10 @@ #![crate_type = "lib"] +#![allow( + clippy::many_single_char_names, + clippy::deref_addrof, + clippy::unreadable_literal, + clippy::many_single_char_names +)] // Test cases for bounds check elimination diff --git a/examples/convo.rs b/examples/convo.rs index 97ae82919..b67f43466 100644 --- a/examples/convo.rs +++ b/examples/convo.rs @@ -28,6 +28,7 @@ where for i in 0..n - 2 { for j in 0..m - 2 { let mut conv = F::zero(); + #[allow(clippy::needless_range_loop)] for k in 0..3 { for l in 0..3 { conv = conv + *a.uget((i + k, j + l)) * kernel[k][l]; diff --git a/examples/life.rs b/examples/life.rs index 14fa1193d..54d2e00d5 100644 --- a/examples/life.rs +++ b/examples/life.rs @@ -8,7 +8,7 @@ extern crate ndarray; use ndarray::prelude::*; -const INPUT: &'static [u8] = include_bytes!("life.txt"); +const INPUT: &[u8] = include_bytes!("life.txt"); //const INPUT: &'static [u8] = include_bytes!("lifelite.txt"); const N: usize = 100; @@ -77,7 +77,7 @@ fn render(a: &Board) { print!("."); } } - println!(""); + println!(); } } diff --git a/examples/zip_many.rs b/examples/zip_many.rs index 45992c38a..d5f8b1fe1 100644 --- a/examples/zip_many.rs +++ b/examples/zip_many.rs @@ -1,3 +1,9 @@ +#![allow( + clippy::many_single_char_names, + clippy::deref_addrof, + clippy::unreadable_literal, + clippy::many_single_char_names +)] extern crate ndarray; use ndarray::prelude::*; 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..244b3c2d3 100644 --- a/src/dimension/dimension_trait.rs +++ b/src/dimension/dimension_trait.rs @@ -367,7 +367,7 @@ macro_rules! impl_insert_axis_array( 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) } ); 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 { 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_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..716dda5ed 100644 --- a/src/impl_constructors.rs +++ b/src/impl_constructors.rs @@ -422,8 +422,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 fe2c05498..06722c386 100644 --- a/src/impl_methods.rs +++ b/src/impl_methods.rs @@ -52,6 +52,7 @@ where } /// Return whether the array has any elements + // #[allow(clippy::)] pub fn is_empty(&self) -> bool { self.len() == 0 } @@ -225,7 +226,7 @@ where { let data = self.data.into_shared(); ArrayBase { - data: data, + data, ptr: self.ptr, dim: self.dim, strides: self.strides, @@ -1196,7 +1197,7 @@ where pub fn is_standard_layout(&self) -> bool { fn is_standard_layout(dim: &D, strides: &D) -> bool { if let Some(1) = D::NDIM { - return strides[0] == 1 || dim[0] <= 1 + return strides[0] == 1 || dim[0] <= 1; } if dim.slice().iter().any(|&d| d == 0) { return true; @@ -1452,8 +1453,8 @@ where return Ok(ArrayBase { data: self.data, ptr: self.ptr, - dim: dim, - strides: strides, + dim, + strides, }); } } 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..e95e0377c 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 } @@ -280,7 +276,7 @@ where pub(crate) fn new(self_: ArrayViewMut<'a, A, D>) -> Self { IterMut { inner: match self_.into_slice_() { - Ok(x) => ElementsRepr::Slice(x.into_iter()), + Ok(x) => ElementsRepr::Slice(x.iter_mut()), Err(self_) => ElementsRepr::Counted(self_.into_elements_base()), }, } @@ -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/linalg/impl_linalg.rs b/src/linalg/impl_linalg.rs index a40f38616..368b12f0b 100644 --- a/src/linalg/impl_linalg.rs +++ b/src/linalg/impl_linalg.rs @@ -78,7 +78,7 @@ where let mut sum = A::zero(); for i in 0..self.len() { unsafe { - sum = sum.clone() + self.uget(i).clone() * rhs.uget(i).clone(); + sum = sum + self.uget(i).clone() * rhs.uget(i).clone(); } } sum @@ -512,7 +512,7 @@ fn mat_mul_general( } } else { // It's a no-op if `c` has zero length. - if c.len() == 0 { + if c.is_empty() { return; } diff --git a/src/linspace.rs b/src/linspace.rs index 92d80aaa0..ca0eae470 100644 --- a/src/linspace.rs +++ b/src/linspace.rs @@ -82,7 +82,7 @@ where }; Linspace { start: a, - step: step, + step, index: 0, len: n, } @@ -106,7 +106,7 @@ where let steps = F::ceil(len / step); Linspace { start: a, - step: step, + step, len: steps.to_usize().expect( "Converting the length to `usize` must not fail. The most likely \ cause of this failure is if the sign of `end - start` is \ diff --git a/src/logspace.rs b/src/logspace.rs index ae0911089..55b5397c8 100644 --- a/src/logspace.rs +++ b/src/logspace.rs @@ -90,7 +90,7 @@ where sign: base.signum(), base: base.abs(), start: a, - step: step, + step, index: 0, len: n, } diff --git a/src/slice.rs b/src/slice.rs index d88378b60..aa201caf2 100644 --- a/src/slice.rs +++ b/src/slice.rs @@ -315,10 +315,7 @@ where /// consistent with `indices`. #[doc(hidden)] pub unsafe fn new_unchecked(indices: T, out_dim: PhantomData) -> SliceInfo { - SliceInfo { - out_dim: out_dim, - indices: indices, - } + SliceInfo { out_dim, indices } } } @@ -338,7 +335,7 @@ where } Ok(SliceInfo { out_dim: PhantomData, - indices: indices, + indices, }) } } diff --git a/src/stacking.rs b/src/stacking.rs index c8bdb67d0..e998b6d15 100644 --- a/src/stacking.rs +++ b/src/stacking.rs @@ -37,7 +37,7 @@ where A: Copy, D: RemoveAxis, { - if arrays.len() == 0 { + if arrays.is_empty() { return Err(from_kind(ErrorKind::Unsupported)); } let mut res_dim = arrays[0].raw_dim(); diff --git a/tests/azip.rs b/tests/azip.rs index beb20c49f..2c2999c43 100644 --- a/tests/azip.rs +++ b/tests/azip.rs @@ -1,3 +1,9 @@ +#![allow( + clippy::many_single_char_names, + clippy::deref_addrof, + clippy::unreadable_literal, + clippy::many_single_char_names +)] extern crate itertools; extern crate ndarray; diff --git a/tests/iterator_chunks.rs b/tests/iterator_chunks.rs index d0c166e8f..d0d9c4068 100644 --- a/tests/iterator_chunks.rs +++ b/tests/iterator_chunks.rs @@ -1,3 +1,9 @@ +#![allow( + clippy::many_single_char_names, + clippy::deref_addrof, + clippy::unreadable_literal, + clippy::many_single_char_names +)] extern crate ndarray; use ndarray::prelude::*; From ac4eeb4893c3a783f2ef08f085619b77f16ee6ce Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Thu, 13 Jun 2019 16:23:14 -0400 Subject: [PATCH 06/35] more lints --- src/dimension/axes.rs | 3 +++ src/dimension/axis.rs | 2 +- src/dimension/dynindeximpl.rs | 8 +++----- src/impl_1d.rs | 3 +++ src/impl_methods.rs | 5 +++-- src/impl_views.rs | 3 +++ src/indexes.rs | 1 + src/linalg/impl_linalg.rs | 3 ++- src/numeric/impl_numeric.rs | 2 +- src/numeric_util.rs | 8 ++++---- src/slice.rs | 4 ++-- tests/array.rs | 11 ++++++----- tests/azip.rs | 3 ++- tests/into-ixdyn.rs | 7 +++++++ tests/iterator_chunks.rs | 3 ++- tests/ix0.rs | 8 ++++++++ tests/ixdyn.rs | 3 ++- tests/numeric.rs | 3 ++- tests/s.rs | 6 ++++++ tests/windows.rs | 6 ++++++ 20 files changed, 67 insertions(+), 25 deletions(-) diff --git a/src/dimension/axes.rs b/src/dimension/axes.rs index aae35a9a5..b8107ceb4 100644 --- a/src/dimension/axes.rs +++ b/src/dimension/axes.rs @@ -62,6 +62,9 @@ impl AxisDescription { pub fn stride(self) -> Ixs { self.2 } + pub fn is_empty(self) -> bool { + self.len() == 0 + } } copy_and_clone!(['a, D] Axes<'a, D>); diff --git a/src/dimension/axis.rs b/src/dimension/axis.rs index 9accdd963..ea7f0ed1a 100644 --- a/src/dimension/axis.rs +++ b/src/dimension/axis.rs @@ -21,7 +21,7 @@ pub struct Axis(pub usize); impl Axis { /// Return the index of the axis. #[inline(always)] - pub fn index(&self) -> usize { + pub fn index(self) -> usize { self.0 } } diff --git a/src/dimension/dynindeximpl.rs b/src/dimension/dynindeximpl.rs index e8bcf2b25..e1e4e804f 100644 --- a/src/dimension/dynindeximpl.rs +++ b/src/dimension/dynindeximpl.rs @@ -48,9 +48,7 @@ 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[..]); IxDynRepr::Inline(x.len() as _, arr) } else { Self::from(x) @@ -121,7 +119,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 +204,7 @@ impl<'a> IntoIterator for &'a IxDynImpl { type IntoIter = <&'a [Ix] as IntoIterator>::IntoIter; #[inline] fn into_iter(self) -> Self::IntoIter { - self[..].into_iter() + self[..].iter() } } diff --git a/src/impl_1d.rs b/src/impl_1d.rs index 73d5e837e..ccfc34294 100644 --- a/src/impl_1d.rs +++ b/src/impl_1d.rs @@ -23,6 +23,9 @@ where if let Some(slc) = self.as_slice() { slc.to_vec() } else { + // clippy suggests this but + // the trait `iterators::TrustedIterator` is not implemented for `std::iter::Cloned>>` + // crate::iterators::to_vec(self.iter().cloned()) crate::iterators::to_vec(self.iter().map(|x| x.clone())) } } diff --git a/src/impl_methods.rs b/src/impl_methods.rs index 06722c386..6634fd940 100644 --- a/src/impl_methods.rs +++ b/src/impl_methods.rs @@ -375,8 +375,8 @@ where 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, + 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))| { @@ -413,6 +413,7 @@ where .iter() .enumerate() .for_each(|(axis, slice_or_index)| match slice_or_index { + // Clippy insists we can remove the `&`, but this fails if we try &SliceOrIndex::Slice { start, end, step } => { self.slice_axis_inplace(Axis(axis), Slice { start, end, step }) } diff --git a/src/impl_views.rs b/src/impl_views.rs index 386c869f4..b57354bff 100644 --- a/src/impl_views.rs +++ b/src/impl_views.rs @@ -135,6 +135,9 @@ where } } + // Should this be `to_slice` if taking a reference? + // https://rust-lang.github.io/rust-clippy/master/#wrong_self_convention + /// Return the array’s data as a slice, if it is contiguous and in standard order. /// Return `None` otherwise. pub fn into_slice(&self) -> Option<&'a [A]> { diff --git a/src/indexes.rs b/src/indexes.rs index 1350819b5..26031fbcb 100644 --- a/src/indexes.rs +++ b/src/indexes.rs @@ -140,6 +140,7 @@ impl NdProducer for Indices { private_impl! {} #[doc(hidden)] + #[allow(clippy::clone_on_copy)] fn raw_dim(&self) -> Self::Dim { self.dim.clone() } diff --git a/src/linalg/impl_linalg.rs b/src/linalg/impl_linalg.rs index 368b12f0b..80126f672 100644 --- a/src/linalg/impl_linalg.rs +++ b/src/linalg/impl_linalg.rs @@ -78,7 +78,7 @@ where let mut sum = A::zero(); for i in 0..self.len() { unsafe { - sum = sum + self.uget(i).clone() * rhs.uget(i).clone(); + sum = sum + *self.uget(i) * *rhs.uget(i); } } sum @@ -586,6 +586,7 @@ pub fn general_mat_mul( /// ***Panics*** if array shapes are not compatible
/// *Note:* If enabled, uses blas `gemv` for elements of `f32, f64` when memory /// layout allows. +#[allow(clippy::collapsible_if)] pub fn general_mat_vec_mul( alpha: A, a: &ArrayBase, diff --git a/src/numeric/impl_numeric.rs b/src/numeric/impl_numeric.rs index d2125556b..3f4c9e52d 100644 --- a/src/numeric/impl_numeric.rs +++ b/src/numeric/impl_numeric.rs @@ -184,7 +184,7 @@ where let axis_length = A::from_usize(axis_length).expect("Converting axis length to `A` must not fail."); let sum = self.sum_axis(axis); - Some(sum / &aview0(&axis_length)) + Some(sum / aview0(&axis_length)) } } diff --git a/src/numeric_util.rs b/src/numeric_util.rs index b8259412f..b89196a21 100644 --- a/src/numeric_util.rs +++ b/src/numeric_util.rs @@ -48,11 +48,11 @@ where // make it clear to the optimizer that this loop is short // and can not be autovectorized. - for i in 0..xs.len() { + for (i, x) in xs.iter().enumerate() { if i >= 7 { break; } - acc = f(acc.clone(), xs[i].clone()) + acc = f(acc.clone(), x.clone()) } acc } @@ -99,13 +99,13 @@ where sum = sum + (p2 + p6); sum = sum + (p3 + p7); - for i in 0..xs.len() { + for (i, x) in xs.iter().enumerate() { if i >= 7 { break; } unsafe { // get_unchecked is needed to avoid the bounds check - sum = sum + xs[i] * *ys.get_unchecked(i); + sum = sum + *x * *ys.get_unchecked(i); } } sum diff --git a/src/slice.rs b/src/slice.rs index aa201caf2..50b9e2d13 100644 --- a/src/slice.rs +++ b/src/slice.rs @@ -110,7 +110,7 @@ impl SliceOrIndex { /// Returns `true` if `self` is a `Slice` value. pub fn is_slice(&self) -> bool { match self { - &SliceOrIndex::Slice { .. } => true, + SliceOrIndex::Slice { .. } => true, _ => false, } } @@ -118,7 +118,7 @@ impl SliceOrIndex { /// Returns `true` if `self` is an `Index` value. pub fn is_index(&self) -> bool { match self { - &SliceOrIndex::Index(_) => true, + SliceOrIndex::Index(_) => true, _ => false, } } diff --git a/tests/array.rs b/tests/array.rs index f5fcb779c..2c680b16b 100644 --- a/tests/array.rs +++ b/tests/array.rs @@ -3,7 +3,8 @@ clippy::many_single_char_names, clippy::deref_addrof, clippy::unreadable_literal, - clippy::many_single_char_names + clippy::many_single_char_names, + clippy::float_cmp )] extern crate defmac; @@ -968,11 +969,11 @@ fn iter_size_hint() { fn zero_axes() { let mut a = arr1::(&[]); for _ in a.iter() { - assert!(false); + panic!(); } - a.map(|_| assert!(false)); - a.map_inplace(|_| assert!(false)); - a.visit(|_| assert!(false)); + a.map(|_| panic!()); + a.map_inplace(|_| panic!()); + a.visit(|_| panic!()); println!("{:?}", a); let b = arr2::(&[[], [], [], []]); println!("{:?}\n{:?}", b.shape(), b); diff --git a/tests/azip.rs b/tests/azip.rs index 2c2999c43..e687a1535 100644 --- a/tests/azip.rs +++ b/tests/azip.rs @@ -2,7 +2,8 @@ clippy::many_single_char_names, clippy::deref_addrof, clippy::unreadable_literal, - clippy::many_single_char_names + clippy::many_single_char_names, + clippy::float_cmp )] extern crate itertools; extern crate ndarray; diff --git a/tests/into-ixdyn.rs b/tests/into-ixdyn.rs index a24d9abcb..337791dd6 100644 --- a/tests/into-ixdyn.rs +++ b/tests/into-ixdyn.rs @@ -1,3 +1,10 @@ +#![allow( + clippy::many_single_char_names, + clippy::deref_addrof, + clippy::unreadable_literal, + clippy::many_single_char_names, + clippy::float_cmp +)] extern crate ndarray; use ndarray::prelude::*; diff --git a/tests/iterator_chunks.rs b/tests/iterator_chunks.rs index d0d9c4068..8c5fe6080 100644 --- a/tests/iterator_chunks.rs +++ b/tests/iterator_chunks.rs @@ -2,7 +2,8 @@ clippy::many_single_char_names, clippy::deref_addrof, clippy::unreadable_literal, - clippy::many_single_char_names + clippy::many_single_char_names, + clippy::float_cmp )] extern crate ndarray; diff --git a/tests/ix0.rs b/tests/ix0.rs index edb9f10fc..82d61716f 100644 --- a/tests/ix0.rs +++ b/tests/ix0.rs @@ -1,3 +1,11 @@ +#![allow( + clippy::many_single_char_names, + clippy::deref_addrof, + clippy::unreadable_literal, + clippy::many_single_char_names, + clippy::float_cmp +)] + extern crate ndarray; use ndarray::Array; diff --git a/tests/ixdyn.rs b/tests/ixdyn.rs index d5ebba035..3340d915e 100644 --- a/tests/ixdyn.rs +++ b/tests/ixdyn.rs @@ -2,7 +2,8 @@ clippy::many_single_char_names, clippy::deref_addrof, clippy::unreadable_literal, - clippy::many_single_char_names + clippy::many_single_char_names, + clippy::float_cmp )] extern crate ndarray; diff --git a/tests/numeric.rs b/tests/numeric.rs index c3fd0fb08..0fc9e0bf8 100644 --- a/tests/numeric.rs +++ b/tests/numeric.rs @@ -2,7 +2,8 @@ clippy::many_single_char_names, clippy::deref_addrof, clippy::unreadable_literal, - clippy::many_single_char_names + clippy::many_single_char_names, + clippy::float_cmp )] extern crate approx; use approx::assert_abs_diff_eq; diff --git a/tests/s.rs b/tests/s.rs index 7acdcd8ad..5534734e5 100644 --- a/tests/s.rs +++ b/tests/s.rs @@ -1,3 +1,9 @@ +#![allow( + clippy::many_single_char_names, + clippy::deref_addrof, + clippy::unreadable_literal, + clippy::many_single_char_names +)] extern crate ndarray; use ndarray::{s, Array}; diff --git a/tests/windows.rs b/tests/windows.rs index fc32a70b5..8c1f5480a 100644 --- a/tests/windows.rs +++ b/tests/windows.rs @@ -1,3 +1,9 @@ +#![allow( + clippy::many_single_char_names, + clippy::deref_addrof, + clippy::unreadable_literal, + clippy::many_single_char_names +)] extern crate itertools; extern crate ndarray; From c7089681b01e54316a5ee392fcc5cb3681790a67 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Thu, 13 Jun 2019 17:40:51 -0400 Subject: [PATCH 07/35] all clippy lints solved or ignored --- src/arraytraits.rs | 2 +- src/dimension/dim.rs | 2 ++ src/impl_1d.rs | 2 ++ src/impl_constructors.rs | 7 +++++-- src/impl_methods.rs | 3 ++- src/impl_views.rs | 6 +++--- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/arraytraits.rs b/src/arraytraits.rs index fbdf575f3..fee85786b 100644 --- a/src/arraytraits.rs +++ b/src/arraytraits.rs @@ -127,7 +127,7 @@ where where I: IntoIterator, { - ArrayBase::from_iter(iterable) + ArrayBase::from_iter_(iterable) } } diff --git a/src/dimension/dim.rs b/src/dimension/dim.rs index 2d93f0e95..9c587cbd4 100644 --- a/src/dimension/dim.rs +++ b/src/dimension/dim.rs @@ -74,6 +74,8 @@ where } } +// FIXME: need help understanding why this is complaining +#[allow(clippy::derive_hash_xor_eq)] impl hash::Hash for Dim where Dim: Dimension, diff --git a/src/impl_1d.rs b/src/impl_1d.rs index ccfc34294..ea3fb6512 100644 --- a/src/impl_1d.rs +++ b/src/impl_1d.rs @@ -15,6 +15,8 @@ where S: RawData, { /// Return an vector with the elements of the one-dimensional array. + // TODO: See below re error + #[allow(clippy::map_clone)] pub fn to_vec(&self) -> Vec
where A: Clone, diff --git a/src/impl_constructors.rs b/src/impl_constructors.rs index 716dda5ed..c78538d71 100644 --- a/src/impl_constructors.rs +++ b/src/impl_constructors.rs @@ -10,6 +10,8 @@ //! //! +#![allow(clippy::match_wild_err_arm)] + use num_traits::{Float, One, Zero}; use std::isize; use std::mem; @@ -62,7 +64,7 @@ where /// let array = Array::from_iter((0..5).map(|x| x * x)); /// assert!(array == arr1(&[0, 1, 4, 9, 16])) /// ``` - pub fn from_iter(iterable: I) -> Self + pub fn from_iter_(iterable: I) -> Self where I: IntoIterator, { @@ -196,6 +198,7 @@ where } #[cfg(not(debug_assertions))] +#[allow(clippy::match_wild_err_arm)] macro_rules! size_of_shape_checked_unwrap { ($dim:expr) => { match dimension::size_of_shape_checked($dim) { @@ -327,7 +330,7 @@ where unsafe { Self::from_shape_vec_unchecked(shape, v) } } else { let dim = shape.dim.clone(); - let v = to_vec_mapped(indexes::indices_iter_f(dim).into_iter(), f); + let v = to_vec_mapped(indexes::indices_iter_f(dim), f); unsafe { Self::from_shape_vec_unchecked(shape, v) } } } diff --git a/src/impl_methods.rs b/src/impl_methods.rs index 6634fd940..6d9bc2c01 100644 --- a/src/impl_methods.rs +++ b/src/impl_methods.rs @@ -406,6 +406,8 @@ where /// /// **Panics** if an index is out of bounds or step size is zero.
/// (**Panics** if `D` is `IxDyn` and `indices` does not match the number of array axes.) + // TODO: Clippy insists we can remove the `&` in the below match, but this won't work + #[allow(clippy::match_ref_pats)] pub fn slice_collapse(&mut self, indices: &D::SliceArg) { let indices: &[SliceOrIndex] = indices.as_ref(); assert_eq!(indices.len(), self.ndim()); @@ -413,7 +415,6 @@ where .iter() .enumerate() .for_each(|(axis, slice_or_index)| match slice_or_index { - // Clippy insists we can remove the `&`, but this fails if we try &SliceOrIndex::Slice { start, end, step } => { self.slice_axis_inplace(Axis(axis), Slice { start, end, step }) } diff --git a/src/impl_views.rs b/src/impl_views.rs index b57354bff..8083ed115 100644 --- a/src/impl_views.rs +++ b/src/impl_views.rs @@ -135,11 +135,11 @@ where } } - // Should this be `to_slice` if taking a reference? - // https://rust-lang.github.io/rust-clippy/master/#wrong_self_convention - /// Return the array’s data as a slice, if it is contiguous and in standard order. /// Return `None` otherwise. + // TODO: Should this be `to_slice` if taking a reference? + // https://rust-lang.github.io/rust-clippy/master/#wrong_self_convention + #[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())) } From 3090c36b047aee88dff8bd5e7d0f23782bf0711e Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Thu, 13 Jun 2019 17:45:29 -0400 Subject: [PATCH 08/35] test in travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 97b4d1fa4..2b407a563 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,4 +35,5 @@ before_script: script: - | cargo fmt --all -- --check && + cargo clippy && ./scripts/all-tests.sh "$FEATURES" "$IS_NIGHTLY" From 25d9978e54ac84f06cc0b8b7890a5eccef66eed4 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Thu, 13 Jun 2019 18:00:32 -0400 Subject: [PATCH 09/35] revert from_iter changes --- src/arraytraits.rs | 2 +- src/impl_constructors.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arraytraits.rs b/src/arraytraits.rs index fee85786b..fbdf575f3 100644 --- a/src/arraytraits.rs +++ b/src/arraytraits.rs @@ -127,7 +127,7 @@ where where I: IntoIterator, { - ArrayBase::from_iter_(iterable) + ArrayBase::from_iter(iterable) } } diff --git a/src/impl_constructors.rs b/src/impl_constructors.rs index c78538d71..0c054a8e6 100644 --- a/src/impl_constructors.rs +++ b/src/impl_constructors.rs @@ -64,7 +64,7 @@ where /// let array = Array::from_iter((0..5).map(|x| x * x)); /// assert!(array == arr1(&[0, 1, 4, 9, 16])) /// ``` - pub fn from_iter_(iterable: I) -> Self + pub fn from_iter(iterable: I) -> Self where I: IntoIterator, { From 3abe7b46403d3a126c33e78ab9c3eaeff983a6f8 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Thu, 13 Jun 2019 18:49:43 -0400 Subject: [PATCH 10/35] add temporary allow to from_iter lint --- src/impl_constructors.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/impl_constructors.rs b/src/impl_constructors.rs index 0c054a8e6..ede0d18c1 100644 --- a/src/impl_constructors.rs +++ b/src/impl_constructors.rs @@ -64,6 +64,9 @@ where /// let array = Array::from_iter((0..5).map(|x| x * x)); /// assert!(array == arr1(&[0, 1, 4, 9, 16])) /// ``` + // FIXME: I don't yet understand why we can't rely on FromIterator + // in `arraytraits.rs`, and have that function call call ArrayBase::from_vec + #[allow(clippy::should_implement_trait)] pub fn from_iter(iterable: I) -> Self where I: IntoIterator, From 802e40b9769b199f841080cbee769ca3ca47663c Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Thu, 13 Jun 2019 23:19:40 -0400 Subject: [PATCH 11/35] install clippy in travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2b407a563..8091a825f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,7 +31,7 @@ addons: - libopenblas-dev - gfortran before_script: - - rustup component add rustfmt + - rustup component add rustfmt clippy script: - | cargo fmt --all -- --check && From e7b00697683309c91f5a5d2eae27c59f7eff6239 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Fri, 14 Jun 2019 00:59:20 -0400 Subject: [PATCH 12/35] only run clippy on nightly --- .travis.yml | 1 - scripts/all-tests.sh | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8091a825f..adb4bef1c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,5 +35,4 @@ before_script: script: - | cargo fmt --all -- --check && - cargo clippy && ./scripts/all-tests.sh "$FEATURES" "$IS_NIGHTLY" diff --git a/scripts/all-tests.sh b/scripts/all-tests.sh index 5ad7306ab..dd2f53764 100755 --- a/scripts/all-tests.sh +++ b/scripts/all-tests.sh @@ -14,4 +14,5 @@ cargo test --verbose --features "$FEATURES" cargo test --manifest-path=serialization-tests/Cargo.toml --verbose cargo test --manifest-path=blas-tests/Cargo.toml --verbose CARGO_TARGET_DIR=target/ cargo test --manifest-path=numeric-tests/Cargo.toml --verbose +([ "$IS_NIGHTLY" != 1 ] || cargo clippy) ([ "$IS_NIGHTLY" != 1 ] || cargo bench --no-run --verbose --features "$FEATURES") From dd7933ee7ed8223672043b8c72edd8e98fc54cd2 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Fri, 14 Jun 2019 12:07:12 -0400 Subject: [PATCH 13/35] cloned rather than copied --- tests/iterators.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/iterators.rs b/tests/iterators.rs index 2fe8521a8..6f37e6469 100644 --- a/tests/iterators.rs +++ b/tests/iterators.rs @@ -17,7 +17,7 @@ use itertools::{enumerate, rev}; #[test] fn double_ended() { let a = ArcArray::linspace(0., 7., 8); - let mut it = a.iter().copied(); + let mut it = a.iter().cloned(); assert_eq!(it.next(), Some(0.)); assert_eq!(it.next_back(), Some(7.)); assert_eq!(it.next(), Some(1.)); From 0ed10c6435d69621b2bcb5ad51e610447115aec2 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Fri, 14 Jun 2019 12:44:15 -0400 Subject: [PATCH 14/35] miscreant line --- src/impl_methods.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/impl_methods.rs b/src/impl_methods.rs index 6d9bc2c01..76b79e262 100644 --- a/src/impl_methods.rs +++ b/src/impl_methods.rs @@ -52,7 +52,6 @@ where } /// Return whether the array has any elements - // #[allow(clippy::)] pub fn is_empty(&self) -> bool { self.len() == 0 } From 2d575305623f77f99a33ae972cbe62015c8e2d1c Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Fri, 14 Jun 2019 12:48:34 -0400 Subject: [PATCH 15/35] collapse non-looping loop --- src/dimension/remove_axis.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/dimension/remove_axis.rs b/src/dimension/remove_axis.rs index 1706895f7..edc3d660c 100644 --- a/src/dimension/remove_axis.rs +++ b/src/dimension/remove_axis.rs @@ -49,12 +49,9 @@ macro_rules! impl_remove_axis_array( { let mut it = tup.slice_mut().iter_mut(); for (i, &d) in self.slice().iter().enumerate() { - if i == axis.index() { - continue; - } - for rr in it.by_ref() { - *rr = d; - break + if i != axis.index() { + // FIXME: is this a correct translations from the existing version? + *it.next().unwrap() = d; } } } From 296691e88764eb1f7bd76dcc9f41bd591d56b81b Mon Sep 17 00:00:00 2001 From: Jim Turner Date: Thu, 20 Jun 2019 19:49:51 -0400 Subject: [PATCH 16/35] Derive traits for Axis instead of manual impl The behavior should be identical. --- src/dimension/axis.rs | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/src/dimension/axis.rs b/src/dimension/axis.rs index ea7f0ed1a..42a1ee12c 100644 --- a/src/dimension/axis.rs +++ b/src/dimension/axis.rs @@ -6,8 +6,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::cmp::Ordering; - /// An axis index. /// /// An axis one of an array’s “dimensions”; an *n*-dimensional array has *n* axes. @@ -15,7 +13,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, Debug)] +#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct Axis(pub usize); impl Axis { @@ -25,19 +23,3 @@ impl Axis { self.0 } } - -copy_and_clone! {Axis} - -macro_rules! derive_cmp { - ($traitname:ident for $typename:ident, $method:ident -> $ret:ty) => { - impl $traitname for $typename { - #[inline(always)] - fn $method(&self, rhs: &Self) -> $ret { - (self.0).$method(&rhs.0) - } - } - }; -} - -derive_cmp! {PartialEq for Axis, eq -> bool} -derive_cmp! {PartialOrd for Axis, partial_cmp -> Option} From 1eab0dcce9f4d5cce3b0aa3392e38aedd29b6495 Mon Sep 17 00:00:00 2001 From: Jim Turner Date: Thu, 20 Jun 2019 20:04:42 -0400 Subject: [PATCH 17/35] Remove manual impls of Send and Sync for IxDynImpl `Send` and `Sync` are automatically implemented, so manual implementations aren't necessary. --- src/dimension/dynindeximpl.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/dimension/dynindeximpl.rs b/src/dimension/dynindeximpl.rs index e1e4e804f..9fda75c3d 100644 --- a/src/dimension/dynindeximpl.rs +++ b/src/dimension/dynindeximpl.rs @@ -109,8 +109,6 @@ impl PartialEq for IxDynRepr { /// any dynamic memory allocation. #[derive(Debug, Clone, PartialEq, Eq, Default)] pub struct IxDynImpl(IxDynRepr); -unsafe impl Send for IxDynImpl {} -unsafe impl Sync for IxDynImpl {} impl IxDynImpl { pub(crate) fn insert(&self, i: usize) -> Self { From 6c9b417759a41cc2615eaccc8d484a8d98c3de1e Mon Sep 17 00:00:00 2001 From: Jim Turner Date: Thu, 20 Jun 2019 20:08:01 -0400 Subject: [PATCH 18/35] Implement Hash for IxDynRepr and IxDynImpl --- src/dimension/dynindeximpl.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/dimension/dynindeximpl.rs b/src/dimension/dynindeximpl.rs index 9fda75c3d..26b865a03 100644 --- a/src/dimension/dynindeximpl.rs +++ b/src/dimension/dynindeximpl.rs @@ -1,4 +1,5 @@ use crate::imp_prelude::*; +use std::hash::{Hash, Hasher}; use std::ops::{Deref, DerefMut, Index, IndexMut}; const CAP: usize = 4; @@ -102,12 +103,18 @@ impl PartialEq for IxDynRepr { } } +impl Hash for IxDynRepr { + fn hash(&self, state: &mut H) { + Hash::hash(&self[..], state) + } +} + /// Dynamic dimension or index type. /// /// Use `IxDyn` directly. This type implements a dynamic number of /// dimensions or indices. Short dimensions are stored inline and don't need /// any dynamic memory allocation. -#[derive(Debug, Clone, PartialEq, Eq, Default)] +#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] pub struct IxDynImpl(IxDynRepr); impl IxDynImpl { From ce57d15576211df6c80db38f22d51f1d1caf7a71 Mon Sep 17 00:00:00 2001 From: Jim Turner Date: Thu, 20 Jun 2019 20:25:32 -0400 Subject: [PATCH 19/35] Derive Hash for Dim instead of manual impl This avoids any issues associated with deriving `PartialEq` but manually implementing `Hash`. --- src/dimension/dim.rs | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/dimension/dim.rs b/src/dimension/dim.rs index 9c587cbd4..4d54279a1 100644 --- a/src/dimension/dim.rs +++ b/src/dimension/dim.rs @@ -8,7 +8,6 @@ use itertools::zip; use std::fmt; -use std::hash; use super::Dimension; use super::IntoDimension; @@ -36,7 +35,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, PartialEq, Eq, Hash, Default)] pub struct Dim { index: I, } @@ -74,17 +73,6 @@ where } } -// FIXME: need help understanding why this is complaining -#[allow(clippy::derive_hash_xor_eq)] -impl hash::Hash for Dim -where - Dim: Dimension, -{ - fn hash(&self, state: &mut H) { - self.slice().hash(state); - } -} - impl fmt::Debug for Dim where I: fmt::Debug, From 0330b6d017d8aece91249187195f45571f2021b0 Mon Sep 17 00:00:00 2001 From: Jim Turner Date: Thu, 20 Jun 2019 20:47:23 -0400 Subject: [PATCH 20/35] Simplify remove_axis using copy_from_slice --- src/dimension/remove_axis.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/dimension/remove_axis.rs b/src/dimension/remove_axis.rs index edc3d660c..da366ae17 100644 --- a/src/dimension/remove_axis.rs +++ b/src/dimension/remove_axis.rs @@ -45,17 +45,14 @@ macro_rules! impl_remove_axis_array( #[inline] fn remove_axis(&self, axis: Axis) -> Self::Smaller { debug_assert!(axis.index() < self.ndim()); - let mut tup = Dim([0; $n - 1]); + let mut result = Dim([0; $n - 1]); { - let mut it = tup.slice_mut().iter_mut(); - for (i, &d) in self.slice().iter().enumerate() { - if i != axis.index() { - // FIXME: is this a correct translations from the existing version? - *it.next().unwrap() = d; - } - } + let src = self.slice(); + let dst = result.slice_mut(); + dst[..axis.index()].copy_from_slice(&src[..axis.index()]); + dst[axis.index()..].copy_from_slice(&src[axis.index() + 1..]); } - tup + result } } )* From e6c9b5623da660860c3876cabc7766472d7ea63b Mon Sep 17 00:00:00 2001 From: Jim Turner Date: Thu, 20 Jun 2019 21:18:35 -0400 Subject: [PATCH 21/35] Implement TrustedIterator for Cloned --- src/impl_1d.rs | 7 +------ src/iterators/mod.rs | 1 + 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/impl_1d.rs b/src/impl_1d.rs index ea3fb6512..fa877eff0 100644 --- a/src/impl_1d.rs +++ b/src/impl_1d.rs @@ -15,8 +15,6 @@ where S: RawData, { /// Return an vector with the elements of the one-dimensional array. - // TODO: See below re error - #[allow(clippy::map_clone)] pub fn to_vec(&self) -> Vec
where A: Clone, @@ -25,10 +23,7 @@ where if let Some(slc) = self.as_slice() { slc.to_vec() } else { - // clippy suggests this but - // the trait `iterators::TrustedIterator` is not implemented for `std::iter::Cloned>>` - // crate::iterators::to_vec(self.iter().cloned()) - crate::iterators::to_vec(self.iter().map(|x| x.clone())) + crate::iterators::to_vec(self.iter().cloned()) } } } diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs index e95e0377c..bf7f6f8a0 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -1341,6 +1341,7 @@ unsafe impl TrustedIterator for Linspace {} unsafe impl TrustedIterator for Logspace {} unsafe impl<'a, A, D> TrustedIterator for Iter<'a, A, D> {} unsafe impl<'a, A, D> TrustedIterator for IterMut<'a, A, D> {} +unsafe impl TrustedIterator for std::iter::Cloned where I: TrustedIterator {} unsafe impl TrustedIterator for std::iter::Map where I: TrustedIterator {} unsafe impl<'a, A> TrustedIterator for slice::Iter<'a, A> {} unsafe impl<'a, A> TrustedIterator for slice::IterMut<'a, A> {} From 7dbef15aa2c6e04e0c197bac9bb7ddfec0b5b8eb Mon Sep 17 00:00:00 2001 From: Jim Turner Date: Thu, 20 Jun 2019 21:19:06 -0400 Subject: [PATCH 22/35] Clarify docs for TrustedIterator --- src/iterators/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs index bf7f6f8a0..64cbaca3a 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -1329,6 +1329,9 @@ send_sync_read_write!(ElementsBaseMut); /// (Trait used internally) An iterator that we trust /// to deliver exactly as many items as it said it would. +/// +/// The iterator must produce exactly the number of elements it reported or +/// diverge before reaching the end. pub unsafe trait TrustedIterator {} use crate::indexes::IndicesIterF; From 1e6a406dc8a1723a7c89396b6b1b5405ab7585a2 Mon Sep 17 00:00:00 2001 From: Jim Turner Date: Thu, 20 Jun 2019 21:44:42 -0400 Subject: [PATCH 23/35] Reformat match in slice_collapse --- src/impl_methods.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/impl_methods.rs b/src/impl_methods.rs index 76b79e262..826d24034 100644 --- a/src/impl_methods.rs +++ b/src/impl_methods.rs @@ -405,19 +405,17 @@ where /// /// **Panics** if an index is out of bounds or step size is zero.
/// (**Panics** if `D` is `IxDyn` and `indices` does not match the number of array axes.) - // TODO: Clippy insists we can remove the `&` in the below match, but this won't work - #[allow(clippy::match_ref_pats)] pub fn slice_collapse(&mut self, indices: &D::SliceArg) { let indices: &[SliceOrIndex] = 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 } => { + .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) } From db01f63065db8cf2da3b38aaf7831211a76cc889 Mon Sep 17 00:00:00 2001 From: Jim Turner Date: Thu, 20 Jun 2019 22:08:35 -0400 Subject: [PATCH 24/35] Remove unnecessary .clone() call --- src/indexes.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/indexes.rs b/src/indexes.rs index 26031fbcb..3a34e0bc8 100644 --- a/src/indexes.rs +++ b/src/indexes.rs @@ -140,9 +140,8 @@ impl NdProducer for Indices { private_impl! {} #[doc(hidden)] - #[allow(clippy::clone_on_copy)] fn raw_dim(&self) -> Self::Dim { - self.dim.clone() + self.dim } #[doc(hidden)] From cc66f1748197845943826d60f22ac4abe60ed4a7 Mon Sep 17 00:00:00 2001 From: Jim Turner Date: Thu, 20 Jun 2019 22:08:50 -0400 Subject: [PATCH 25/35] Reformat values of CORDER and FORDER --- src/layout/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/layout/mod.rs b/src/layout/mod.rs index ea9209088..741a0e054 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -57,5 +57,5 @@ impl Layout { } } -pub const CORDER: u32 = 1; -pub const FORDER: u32 = 1 << 1; +pub const CORDER: u32 = 0b01; +pub const FORDER: u32 = 0b10; From 5b6be9917b0753bc5f95b24b4c8b727e082e6661 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Fri, 21 Jun 2019 13:49:33 -0400 Subject: [PATCH 26/35] explicit folds --- tests/iterators.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/iterators.rs b/tests/iterators.rs index 6f37e6469..240204c28 100644 --- a/tests/iterators.rs +++ b/tests/iterators.rs @@ -556,16 +556,17 @@ fn iterators_are_send_sync() { } #[test] +#[allow(clippy::unnecessary_fold)] fn test_fold() { let mut a = Array2::::default((20, 20)); a += 1; let mut iter = a.iter(); iter.next(); - assert_eq!(iter.sum::(), a.sum() - 1); + assert_eq!(iter.fold(0, |acc, &x| acc + x), a.sum() - 1); let mut a = Array0::::default(()); a += 1; - assert_eq!(a.iter().sum::(), 1); + assert_eq!(a.iter().fold(0, |acc, &x| acc + x), 1); } #[test] From d99851c6b58e0652e59d961f278ee6488c19eb42 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Fri, 21 Jun 2019 13:49:43 -0400 Subject: [PATCH 27/35] more minor changes --- tests/array.rs | 12 ++++++------ tests/dimension.rs | 3 +++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/array.rs b/tests/array.rs index 2c680b16b..54d971f8f 100644 --- a/tests/array.rs +++ b/tests/array.rs @@ -418,7 +418,7 @@ fn test_multislice_eval_args_only_once() { { let mut slice = || { eval_count += 1; - s![1..2].clone() + *s![1..2] }; multislice!(arr, mut &slice(), [3..4], [5..6]); } @@ -427,7 +427,7 @@ fn test_multislice_eval_args_only_once() { { let mut slice = || { eval_count += 1; - s![1..2].clone() + *s![1..2] }; multislice!(arr, [3..4], mut &slice(), [5..6]); } @@ -436,7 +436,7 @@ fn test_multislice_eval_args_only_once() { { let mut slice = || { eval_count += 1; - s![1..2].clone() + *s![1..2] }; multislice!(arr, [3..4], [5..6], mut &slice()); } @@ -445,7 +445,7 @@ fn test_multislice_eval_args_only_once() { { let mut slice = || { eval_count += 1; - s![1..2].clone() + *s![1..2] }; multislice!(arr, &slice(), mut [3..4], [5..6]); } @@ -454,7 +454,7 @@ fn test_multislice_eval_args_only_once() { { let mut slice = || { eval_count += 1; - s![1..2].clone() + *s![1..2] }; multislice!(arr, mut [3..4], &slice(), [5..6]); } @@ -463,7 +463,7 @@ fn test_multislice_eval_args_only_once() { { let mut slice = || { eval_count += 1; - s![1..2].clone() + *s![1..2] }; multislice!(arr, mut [3..4], [5..6], &slice()); } diff --git a/tests/dimension.rs b/tests/dimension.rs index 6961a38cd..f45b0a965 100644 --- a/tests/dimension.rs +++ b/tests/dimension.rs @@ -1,3 +1,5 @@ +#![allow(clippy::float_cmp)] + extern crate defmac; extern crate ndarray; @@ -61,6 +63,7 @@ fn remove_axis() { } #[test] +#[allow(clippy::eq_op)] fn dyn_dimension() { let a = arr2(&[[1., 2.], [3., 4.0]]).into_shape(vec![2, 2]).unwrap(); assert_eq!(&a - &a, Array::zeros(vec![2, 2])); From bd1a50d2dd41e8185597241a4cb021d2e17aaf05 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Fri, 21 Jun 2019 14:00:41 -0400 Subject: [PATCH 28/35] replace notes with reference to @jturner314 comment --- src/impl_constructors.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/impl_constructors.rs b/src/impl_constructors.rs index ede0d18c1..4fc0c6900 100644 --- a/src/impl_constructors.rs +++ b/src/impl_constructors.rs @@ -64,8 +64,7 @@ where /// let array = Array::from_iter((0..5).map(|x| x * x)); /// assert!(array == arr1(&[0, 1, 4, 9, 16])) /// ``` - // FIXME: I don't yet understand why we can't rely on FromIterator - // in `arraytraits.rs`, and have that function call call ArrayBase::from_vec + // Potentially remove; see https://github.com/rust-ndarray/ndarray/pull/642#discussion_r296068930 #[allow(clippy::should_implement_trait)] pub fn from_iter(iterable: I) -> Self where From 5b0bba020578aa23a555d2aa40fae15252518a79 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Fri, 21 Jun 2019 14:00:49 -0400 Subject: [PATCH 29/35] more small tweaks --- tests/array.rs | 3 +++ tests/dimension.rs | 2 ++ 2 files changed, 5 insertions(+) diff --git a/tests/array.rs b/tests/array.rs index 54d971f8f..c616cdda6 100644 --- a/tests/array.rs +++ b/tests/array.rs @@ -339,6 +339,7 @@ fn test_slice_collapse_with_indices() { } #[test] +#[allow(clippy::cognitive_complexity)] fn test_multislice() { defmac!(test_multislice mut arr, s1, s2 => { { @@ -732,6 +733,7 @@ fn diag() { /// /// Note that this does not check the strides in the "merged" case! #[test] +#[allow(clippy::cognitive_complexity)] fn merge_axes() { macro_rules! assert_merged { ($arr:expr, $slice:expr, $take:expr, $into:expr) => { @@ -1416,6 +1418,7 @@ fn reshape_f() { } #[test] +#[allow(clippy::cognitive_complexity)] fn insert_axis() { defmac!(test_insert orig, index, new => { let res = orig.insert_axis(Axis(index)); diff --git a/tests/dimension.rs b/tests/dimension.rs index f45b0a965..9479973e5 100644 --- a/tests/dimension.rs +++ b/tests/dimension.rs @@ -226,6 +226,7 @@ fn test_operations() { } #[test] +#[allow(clippy::cognitive_complexity)] fn test_hash() { fn calc_hash(value: &T) -> u64 { let mut hasher = std::collections::hash_map::DefaultHasher::new(); @@ -289,6 +290,7 @@ fn test_array_view() { } #[test] +#[allow(clippy::cognitive_complexity)] fn test_all_ndindex() { macro_rules! ndindex { ($($i:expr),*) => { From 46a9c471821b9885fe75034800d8100ee0b2555b Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Fri, 21 Jun 2019 14:05:46 -0400 Subject: [PATCH 30/35] flup re len & empty --- src/dimension/axes.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dimension/axes.rs b/src/dimension/axes.rs index b8107ceb4..b03f9701b 100644 --- a/src/dimension/axes.rs +++ b/src/dimension/axes.rs @@ -46,6 +46,9 @@ pub struct AxisDescription(pub Axis, pub Ix, pub Ixs); copy_and_clone!(AxisDescription); +// AxisDescription can't really be empty +// https://github.com/rust-ndarray/ndarray/pull/642#discussion_r296051702 +#[allow(clippy::len_without_is_empty)] impl AxisDescription { /// Return axis #[inline(always)] @@ -62,9 +65,6 @@ impl AxisDescription { pub fn stride(self) -> Ixs { self.2 } - pub fn is_empty(self) -> bool { - self.len() == 0 - } } copy_and_clone!(['a, D] Axes<'a, D>); From e2d86aad783779ffa8d3b875d42029115ec65875 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Fri, 21 Jun 2019 14:50:14 -0400 Subject: [PATCH 31/35] clippy on beta only since sometimes not available on nightly (e.g. today) --- .travis.yml | 5 +++-- scripts/all-tests.sh | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index adb4bef1c..4edfe0fef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,10 +13,11 @@ matrix: - rust: beta env: - FEATURES='test docs' + - CHANNEL='beta' - rust: nightly env: - FEATURES='test docs' - - IS_NIGHTLY=1 + - CHANNEL='nightly' env: global: - HOST=x86_64-unknown-linux-gnu @@ -35,4 +36,4 @@ before_script: script: - | cargo fmt --all -- --check && - ./scripts/all-tests.sh "$FEATURES" "$IS_NIGHTLY" + ./scripts/all-tests.sh "$FEATURES" "$CHANNEL" diff --git a/scripts/all-tests.sh b/scripts/all-tests.sh index dd2f53764..bc1b3929b 100755 --- a/scripts/all-tests.sh +++ b/scripts/all-tests.sh @@ -4,7 +4,7 @@ set -x set -e FEATURES=$1 -IS_NIGHTLY=$2 +CHANNEL=$2 cargo build --verbose --no-default-features cargo test --verbose --no-default-features @@ -14,5 +14,5 @@ cargo test --verbose --features "$FEATURES" cargo test --manifest-path=serialization-tests/Cargo.toml --verbose cargo test --manifest-path=blas-tests/Cargo.toml --verbose CARGO_TARGET_DIR=target/ cargo test --manifest-path=numeric-tests/Cargo.toml --verbose -([ "$IS_NIGHTLY" != 1 ] || cargo clippy) -([ "$IS_NIGHTLY" != 1 ] || cargo bench --no-run --verbose --features "$FEATURES") +([ "$CHANNEL" != "beta" ] || cargo clippy) +([ "$CHANNEL" != "nightly" ] || cargo bench --no-run --verbose --features "$FEATURES") From bdf02f15a085d5cf2eec5906c6e807afe1461679 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Fri, 21 Jun 2019 15:10:22 -0400 Subject: [PATCH 32/35] only attempt clippy install on beta --- .travis.yml | 6 +++--- scripts/all-tests.sh | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4edfe0fef..5744e8ed2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,8 +32,8 @@ addons: - libopenblas-dev - gfortran before_script: - - rustup component add rustfmt clippy + - rustup component add rustfmt script: - | - cargo fmt --all -- --check && - ./scripts/all-tests.sh "$FEATURES" "$CHANNEL" + cargo fmt --all -- --check && + ./scripts/all-tests.sh "$FEATURES" "$CHANNEL" diff --git a/scripts/all-tests.sh b/scripts/all-tests.sh index bc1b3929b..7782a10d8 100755 --- a/scripts/all-tests.sh +++ b/scripts/all-tests.sh @@ -14,5 +14,5 @@ cargo test --verbose --features "$FEATURES" cargo test --manifest-path=serialization-tests/Cargo.toml --verbose cargo test --manifest-path=blas-tests/Cargo.toml --verbose CARGO_TARGET_DIR=target/ cargo test --manifest-path=numeric-tests/Cargo.toml --verbose -([ "$CHANNEL" != "beta" ] || cargo clippy) +([ "$CHANNEL" != "beta" ] || rustup componenent add clippy && cargo clippy) ([ "$CHANNEL" != "nightly" ] || cargo bench --no-run --verbose --features "$FEATURES") From 7321592d4a87567ab55de3a62f26a2d4bcc74da5 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Fri, 21 Jun 2019 15:27:07 -0400 Subject: [PATCH 33/35] srlsy? --- scripts/all-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/all-tests.sh b/scripts/all-tests.sh index 7782a10d8..1f92e9b39 100755 --- a/scripts/all-tests.sh +++ b/scripts/all-tests.sh @@ -14,5 +14,5 @@ cargo test --verbose --features "$FEATURES" cargo test --manifest-path=serialization-tests/Cargo.toml --verbose cargo test --manifest-path=blas-tests/Cargo.toml --verbose CARGO_TARGET_DIR=target/ cargo test --manifest-path=numeric-tests/Cargo.toml --verbose -([ "$CHANNEL" != "beta" ] || rustup componenent add clippy && cargo clippy) +([ "$CHANNEL" != "beta" ] || rustup component add clippy && cargo clippy) ([ "$CHANNEL" != "nightly" ] || cargo bench --no-run --verbose --features "$FEATURES") From 9bce28d0f2d8adafb73421331026f8892056c4e5 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Sat, 22 Jun 2019 13:58:02 -0400 Subject: [PATCH 34/35] bash precedence --- scripts/all-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/all-tests.sh b/scripts/all-tests.sh index 1f92e9b39..a54d74223 100755 --- a/scripts/all-tests.sh +++ b/scripts/all-tests.sh @@ -14,5 +14,5 @@ cargo test --verbose --features "$FEATURES" cargo test --manifest-path=serialization-tests/Cargo.toml --verbose cargo test --manifest-path=blas-tests/Cargo.toml --verbose CARGO_TARGET_DIR=target/ cargo test --manifest-path=numeric-tests/Cargo.toml --verbose -([ "$CHANNEL" != "beta" ] || rustup component add clippy && cargo clippy) +([ "$CHANNEL" != "beta" ] || (rustup component add clippy && cargo clippy)) ([ "$CHANNEL" != "nightly" ] || cargo bench --no-run --verbose --features "$FEATURES") From b5205642127592463ae16aca06c659804aab214a Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Wed, 10 Jul 2019 09:29:53 -0400 Subject: [PATCH 35/35] set aside one lint for the moment --- src/array_serde.rs | 2 +- src/numeric_util.rs | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 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/numeric_util.rs b/src/numeric_util.rs index b89196a21..6ad0bb0a5 100644 --- a/src/numeric_util.rs +++ b/src/numeric_util.rs @@ -5,6 +5,9 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. + +// https://github.com/rust-ndarray/ndarray/pull/642#discussion_r296074711 +#![allow(clippy::needless_range_loop)] use std::cmp; use crate::LinalgScalar; @@ -48,11 +51,12 @@ where // make it clear to the optimizer that this loop is short // and can not be autovectorized. - for (i, x) in xs.iter().enumerate() { + // https://github.com/rust-ndarray/ndarray/pull/642#discussion_r296337112 + for i in 0..xs.len() { if i >= 7 { break; } - acc = f(acc.clone(), x.clone()) + acc = f(acc.clone(), xs[i].clone()) } acc } @@ -99,13 +103,13 @@ where sum = sum + (p2 + p6); sum = sum + (p3 + p7); - for (i, x) in xs.iter().enumerate() { + for i in 0..xs.len() { if i >= 7 { break; } unsafe { // get_unchecked is needed to avoid the bounds check - sum = sum + *x * *ys.get_unchecked(i); + sum = sum + xs[i] * *ys.get_unchecked(i); } } sum