diff --git a/.travis.yml b/.travis.yml index de92a9d78..e32f2c62e 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 @@ -30,5 +31,5 @@ before_script: - rustup component add rustfmt script: - | - cargo fmt --all -- --check && - ./scripts/all-tests.sh "$FEATURES" "$IS_NIGHTLY" + cargo fmt --all -- --check && + ./scripts/all-tests.sh "$FEATURES" "$CHANNEL" diff --git a/benches/bench1.rs b/benches/bench1.rs index 6f47b6b59..ae5682c5a 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 82499f50a..60879bf9e 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; @@ -14,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] @@ -22,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] @@ -37,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] @@ -59,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] @@ -67,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; @@ -190,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(); } @@ -310,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/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 c410ef98c..54d2e00d5 100644 --- a/examples/life.rs +++ b/examples/life.rs @@ -1,8 +1,14 @@ +#![allow( + clippy::many_single_char_names, + clippy::deref_addrof, + clippy::unreadable_literal, + clippy::many_single_char_names +)] 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; @@ -71,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/scripts/all-tests.sh b/scripts/all-tests.sh index 5ad7306ab..a54d74223 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,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 bench --no-run --verbose --features "$FEATURES") +([ "$CHANNEL" != "beta" ] || (rustup component add clippy && cargo clippy)) +([ "$CHANNEL" != "nightly" ] || cargo bench --no-run --verbose --features "$FEATURES") 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..d753fe473 100644 --- a/src/arrayformat.rs +++ b/src/arrayformat.rs @@ -51,14 +51,11 @@ enum PrintableCell { // where indexes are being omitted. fn to_be_printed(length: usize, limit: usize) -> Vec { if length <= 2 * limit { - (0..length) - .map(|x| PrintableCell::ElementIndex(x)) - .collect() + (0..length).map(PrintableCell::ElementIndex).collect() } else { - let mut v: Vec = - (0..limit).map(|x| PrintableCell::ElementIndex(x)).collect(); + let mut v: Vec = (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/data_traits.rs b/src/data_traits.rs index b8fe84234..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)] @@ -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..b03f9701b 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(), } @@ -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)] diff --git a/src/dimension/axis.rs b/src/dimension/axis.rs index 6fc389988..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,29 +13,13 @@ 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(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] 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 } } - -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} diff --git a/src/dimension/dim.rs b/src/dimension/dim.rs index 62a9e0b1f..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, } @@ -44,7 +43,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 { @@ -74,15 +73,6 @@ where } } -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, diff --git a/src/dimension/dimension_trait.rs b/src/dimension/dimension_trait.rs index e9c99ede6..244b3c2d3 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()) { @@ -369,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..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; @@ -48,9 +49,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) @@ -104,15 +103,19 @@ 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); -unsafe impl Send for IxDynImpl {} -unsafe impl Sync for IxDynImpl {} impl IxDynImpl { pub(crate) fn insert(&self, i: usize) -> Self { @@ -121,7 +124,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 +209,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() } } @@ -221,7 +224,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/dimension/mod.rs b/src/dimension/mod.rs index b2fa8caf6..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); } @@ -539,12 +537,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/dimension/remove_axis.rs b/src/dimension/remove_axis.rs index 1706895f7..da366ae17 100644 --- a/src/dimension/remove_axis.rs +++ b/src/dimension/remove_axis.rs @@ -45,20 +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() { - continue; - } - for rr in it.by_ref() { - *rr = d; - break - } - } + 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 } } )* 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..fa877eff0 100644 --- a/src/impl_1d.rs +++ b/src/impl_1d.rs @@ -23,7 +23,7 @@ where if let Some(slc) = self.as_slice() { slc.to_vec() } else { - crate::iterators::to_vec(self.iter().map(|x| x.clone())) + crate::iterators::to_vec(self.iter().cloned()) } } } 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..4fc0c6900 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,6 +64,8 @@ where /// let array = Array::from_iter((0..5).map(|x| x * x)); /// assert!(array == arr1(&[0, 1, 4, 9, 16])) /// ``` + // 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 I: IntoIterator, @@ -196,6 +200,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 +332,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) } } } @@ -422,8 +427,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..ddd141f5f 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, @@ -374,8 +374,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))| { @@ -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) } @@ -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; @@ -1450,7 +1449,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) } } } @@ -1495,8 +1494,8 @@ where return Ok(ArrayBase { data: self.data, ptr: self.ptr, - dim: dim, - strides: strides, + dim, + strides, }); } } @@ -1820,7 +1819,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/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 cfd65437f..63b4ea526 100644 --- a/src/impl_views.rs +++ b/src/impl_views.rs @@ -138,6 +138,7 @@ where /// Return the array’s data as a slice, if it is contiguous and in standard order. /// Return `None` otherwise. #[deprecated(note = "`into_slice` has been renamed to `to_slice`", since = "0.13.0")] + #[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())) } @@ -487,8 +488,8 @@ where ArrayView { data: ViewRepr::new(), ptr: ptr as *mut A, - dim: dim, - strides: strides, + dim, + strides, } } @@ -533,9 +534,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..3a34e0bc8 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, } } @@ -141,7 +141,7 @@ impl NdProducer for Indices { #[doc(hidden)] fn raw_dim(&self) -> Self::Dim { - self.dim.clone() + self.dim } #[doc(hidden)] @@ -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/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 0f3f3de4d..9feb429e6 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, } } @@ -1333,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; @@ -1345,6 +1344,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> {} 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; diff --git a/src/layout/mod.rs b/src/layout/mod.rs index bb031838b..741a0e054 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 FORDER: u32 = 1 << 1; +pub const CORDER: u32 = 0b01; +pub const FORDER: u32 = 0b10; diff --git a/src/lib.rs b/src/lib.rs index 4c7c5ad7d..53ffa3480 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/linalg/impl_linalg.rs b/src/linalg/impl_linalg.rs index a40f38616..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.clone() + self.uget(i).clone() * rhs.uget(i).clone(); + sum = sum + *self.uget(i) * *rhs.uget(i); } } 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; } @@ -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/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/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, diff --git a/src/numeric/impl_numeric.rs b/src/numeric/impl_numeric.rs index 08454c5c6..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)) } } @@ -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/numeric_util.rs b/src/numeric_util.rs index b8259412f..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,6 +51,7 @@ where // make it clear to the optimizer that this loop is short // and can not be autovectorized. + // https://github.com/rust-ndarray/ndarray/pull/642#discussion_r296337112 for i in 0..xs.len() { if i >= 7 { break; diff --git a/src/slice.rs b/src/slice.rs index d88378b60..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, } } @@ -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/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 178381a66..0719a3860 100644 --- a/tests/array.rs +++ b/tests/array.rs @@ -1,4 +1,11 @@ #![allow(non_snake_case)] +#![allow( + clippy::many_single_char_names, + clippy::deref_addrof, + clippy::unreadable_literal, + clippy::many_single_char_names, + clippy::float_cmp +)] extern crate defmac; extern crate itertools; @@ -332,6 +339,7 @@ fn test_slice_collapse_with_indices() { } #[test] +#[allow(clippy::cognitive_complexity)] fn test_multislice() { defmac!(test_multislice mut arr, s1, s2 => { { @@ -411,7 +419,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]); } @@ -420,7 +428,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]); } @@ -429,7 +437,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()); } @@ -438,7 +446,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]); } @@ -447,7 +455,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]); } @@ -456,7 +464,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()); } @@ -521,6 +529,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() { @@ -573,7 +582,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); } } @@ -724,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) => { @@ -961,11 +971,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); @@ -1408,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/azip.rs b/tests/azip.rs index beb20c49f..e687a1535 100644 --- a/tests/azip.rs +++ b/tests/azip.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 itertools; extern crate ndarray; diff --git a/tests/dimension.rs b/tests/dimension.rs index 6961a38cd..9479973e5 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])); @@ -223,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(); @@ -286,6 +290,7 @@ fn test_array_view() { } #[test] +#[allow(clippy::cognitive_complexity)] fn test_all_ndindex() { macro_rules! ndindex { ($($i:expr),*) => { 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 9453c0cea..8c5fe6080 100644 --- a/tests/iterator_chunks.rs +++ b/tests/iterator_chunks.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::*; @@ -10,8 +17,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..240204c28 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().cloned(); assert_eq!(it.next(), Some(0.)); assert_eq!(it.next_back(), Some(7.)); assert_eq!(it.next(), Some(1.)); @@ -550,6 +556,7 @@ fn iterators_are_send_sync() { } #[test] +#[allow(clippy::unnecessary_fold)] fn test_fold() { let mut a = Array2::::default((20, 20)); a += 1; 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 814eeaefb..3340d915e 100644 --- a/tests/ixdyn.rs +++ b/tests/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::Array; diff --git a/tests/numeric.rs b/tests/numeric.rs index b9e984d8e..0fc9e0bf8 100644 --- a/tests/numeric.rs +++ b/tests/numeric.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 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; 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;