Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some Clippy lints #642

Merged
merged 38 commits into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e768f70
some initial clippy fixes
max-sixty Jun 13, 2019
cea9596
some clippy lints cleaned
max-sixty Jun 13, 2019
82210d7
one more
max-sixty Jun 13, 2019
0ed84b5
more lints
max-sixty Jun 13, 2019
09e4edf
even more
max-sixty Jun 13, 2019
ac4eeb4
more lints
max-sixty Jun 13, 2019
c708968
all clippy lints solved or ignored
max-sixty Jun 13, 2019
3090c36
test in travis
max-sixty Jun 13, 2019
25d9978
revert from_iter changes
max-sixty Jun 13, 2019
3abe7b4
add temporary allow to from_iter lint
max-sixty Jun 13, 2019
802e40b
install clippy in travis
max-sixty Jun 14, 2019
e7b0069
only run clippy on nightly
max-sixty Jun 14, 2019
dd7933e
cloned rather than copied
max-sixty Jun 14, 2019
0ed10c6
miscreant line
max-sixty Jun 14, 2019
2d57530
collapse non-looping loop
max-sixty Jun 14, 2019
296691e
Derive traits for Axis instead of manual impl
jturner314 Jun 20, 2019
1eab0dc
Remove manual impls of Send and Sync for IxDynImpl
jturner314 Jun 21, 2019
6c9b417
Implement Hash for IxDynRepr and IxDynImpl
jturner314 Jun 21, 2019
ce57d15
Derive Hash for Dim instead of manual impl
jturner314 Jun 21, 2019
0330b6d
Simplify remove_axis using copy_from_slice
jturner314 Jun 21, 2019
e6c9b56
Implement TrustedIterator for Cloned
jturner314 Jun 21, 2019
7dbef15
Clarify docs for TrustedIterator
jturner314 Jun 21, 2019
1e6a406
Reformat match in slice_collapse
jturner314 Jun 21, 2019
db01f63
Remove unnecessary .clone() call
jturner314 Jun 21, 2019
cc66f17
Reformat values of CORDER and FORDER
jturner314 Jun 21, 2019
27d6717
Merge pull request #1 from jturner314/clippy
max-sixty Jun 21, 2019
5b6be99
explicit folds
max-sixty Jun 21, 2019
d99851c
more minor changes
max-sixty Jun 21, 2019
bd1a50d
replace notes with reference to @jturner314 comment
max-sixty Jun 21, 2019
5b0bba0
more small tweaks
max-sixty Jun 21, 2019
46a9c47
flup re len & empty
max-sixty Jun 21, 2019
e2d86aa
clippy on beta only since sometimes not available on nightly (e.g. to…
max-sixty Jun 21, 2019
bdf02f1
only attempt clippy install on beta
max-sixty Jun 21, 2019
7321592
srlsy?
max-sixty Jun 21, 2019
9bce28d
bash precedence
max-sixty Jun 22, 2019
c434ba5
Merge branch 'master' into clippy
max-sixty Jul 5, 2019
11e0102
Merge branch 'master' into clippy
max-sixty Jul 10, 2019
b520564
set aside one lint for the moment
max-sixty Jul 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ addons:
- libopenblas-dev
- gfortran
before_script:
- rustup component add rustfmt
- rustup component add rustfmt clippy
script:
- |
cargo fmt --all -- --check &&
Expand Down
15 changes: 12 additions & 3 deletions benches/bench1.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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::<i32, _>::zeros((64 * 1, 64 * 1));
let b = Array::<i32, _>::zeros((64 * 1, 64 * 1));
Expand All @@ -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::<i32, _>::zeros((64 * 1, 64 * 1));
let b = Array::<i32, _>::zeros((64 * 1, 64 * 1));
Expand All @@ -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::<i32, _>::zeros((64 * 1, 64 * 1));
let b = Array::<i32, _>::zeros((64 * 1, 64 * 1));
Expand Down Expand Up @@ -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::<f32, _>::zeros((ADD2DSZ, ADD2DSZ));
let bv = Array::<f32, _>::zeros((ADD2DSZ, ADD2DSZ));
let scalar = 3.1415926535;
let scalar = std::f32::consts::PI;
bench.iter(|| {
av.scaled_add(scalar, &bv);
});
Expand Down Expand Up @@ -650,7 +659,7 @@ fn bench_row_iter(bench: &mut test::Bencher) {
let a = Array::<f32, _>::zeros((1024, 1024));
let it = a.row(17);
bench.iter(|| {
for elt in it.clone() {
for elt in it {
black_box(elt);
}
})
Expand All @@ -661,7 +670,7 @@ fn bench_col_iter(bench: &mut test::Bencher) {
let a = Array::<f32, _>::zeros((1024, 1024));
let it = a.column(17);
bench.iter(|| {
for elt in it.clone() {
for elt in it {
black_box(elt);
}
})
Expand Down
1 change: 1 addition & 0 deletions benches/chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<f32, _>::zeros((256, 256));
let chunksz = (2, 2);
Expand Down
7 changes: 6 additions & 1 deletion benches/construct.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
6 changes: 6 additions & 0 deletions benches/gemv.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
11 changes: 8 additions & 3 deletions benches/higher-order.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -67,13 +72,13 @@ 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]
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));
}
24 changes: 15 additions & 9 deletions benches/iter.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,15 +20,15 @@ use ndarray::{FoldWhile, Zip};
#[bench]
fn iter_sum_2d_regular(bench: &mut Bencher) {
let a = Array::<i32, _>::zeros((64, 64));
bench.iter(|| a.iter().fold(0, |acc, &x| acc + x));
bench.iter(|| a.iter().sum::<i32>());
}

#[bench]
fn iter_sum_2d_cutout(bench: &mut Bencher) {
let a = Array::<i32, _>::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::<i32>());
}

#[bench]
Expand All @@ -37,37 +43,37 @@ fn iter_all_2d_cutout(bench: &mut Bencher) {
fn iter_sum_2d_transpose(bench: &mut Bencher) {
let a = Array::<i32, _>::zeros((66, 66));
let a = a.t();
bench.iter(|| a.iter().fold(0, |acc, &x| acc + x));
bench.iter(|| a.iter().sum::<i32>());
}

#[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::<u32>());
}

#[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::<f32>());
}

#[bench]
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::<u32>());
}

#[bench]
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::<f32>());
}

const ZIPSZ: usize = 10_000;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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::<u64, _>::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::<u64>());
}

#[bench]
Expand Down
6 changes: 6 additions & 0 deletions examples/axis_ops.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down
6 changes: 6 additions & 0 deletions examples/bounds_check_elim.rs
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 1 addition & 0 deletions examples/convo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
10 changes: 8 additions & 2 deletions examples/life.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -71,7 +77,7 @@ fn render(a: &Board) {
print!(".");
}
}
println!("");
println!();
}
}

Expand Down
6 changes: 6 additions & 0 deletions examples/zip_many.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down
1 change: 1 addition & 0 deletions scripts/all-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")
9 changes: 3 additions & 6 deletions src/arrayformat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,11 @@ enum PrintableCell {
// where indexes are being omitted.
fn to_be_printed(length: usize, limit: usize) -> Vec<PrintableCell> {
if length <= 2 * limit {
(0..length)
.map(|x| PrintableCell::ElementIndex(x))
.collect()
(0..length).map(PrintableCell::ElementIndex).collect()
} else {
let mut v: Vec<PrintableCell> =
(0..limit).map(|x| PrintableCell::ElementIndex(x)).collect();
let mut v: Vec<PrintableCell> = (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
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/data_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -241,7 +241,7 @@ unsafe impl<A> Data for OwnedArcRepr<A> {
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,
Expand Down
5 changes: 4 additions & 1 deletion src/dimension/axes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ where
{
Axes {
dim: d,
strides: strides,
strides,
start: 0,
end: d.ndim(),
}
Expand Down Expand Up @@ -62,6 +62,9 @@ impl AxisDescription {
pub fn stride(self) -> Ixs {
self.2
}
pub fn is_empty(self) -> bool {
max-sixty marked this conversation as resolved.
Show resolved Hide resolved
self.len() == 0
}
}

copy_and_clone!(['a, D] Axes<'a, D>);
Expand Down
4 changes: 2 additions & 2 deletions src/dimension/axis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,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(Eq, Ord, Debug)]
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
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/dimension/dim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct Dim<I: ?Sized> {
impl<I> Dim<I> {
/// Private constructor and accessors for Dim
pub(crate) fn new(index: I) -> Dim<I> {
Dim { index: index }
Dim { index }
}
#[inline(always)]
pub(crate) fn ix(&self) -> &I {
Expand Down Expand Up @@ -74,6 +74,8 @@ where
}
}

// FIXME: need help understanding why this is complaining
max-sixty marked this conversation as resolved.
Show resolved Hide resolved
#[allow(clippy::derive_hash_xor_eq)]
impl<I: ?Sized> hash::Hash for Dim<I>
where
Dim<I>: Dimension,
Expand Down
Loading