Skip to content

Commit 583f36d

Browse files
committed
Merge branch 'master' into nonzero
2 parents 667285a + 98bf3b6 commit 583f36d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+326
-201
lines changed

.travis.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ matrix:
1313
- rust: beta
1414
env:
1515
- FEATURES='test docs'
16+
- CHANNEL='beta'
1617
- rust: nightly
1718
env:
1819
- FEATURES='test docs'
19-
- IS_NIGHTLY=1
20+
- CHANNEL='nightly'
2021
env:
2122
global:
2223
- HOST=x86_64-unknown-linux-gnu
@@ -30,5 +31,5 @@ before_script:
3031
- rustup component add rustfmt
3132
script:
3233
- |
33-
cargo fmt --all -- --check &&
34-
./scripts/all-tests.sh "$FEATURES" "$IS_NIGHTLY"
34+
cargo fmt --all -- --check &&
35+
./scripts/all-tests.sh "$FEATURES" "$CHANNEL"

benches/bench1.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#![feature(test)]
22
#![allow(unused_imports)]
3+
#![allow(
4+
clippy::many_single_char_names,
5+
clippy::deref_addrof,
6+
clippy::unreadable_literal,
7+
clippy::many_single_char_names
8+
)]
39

410
extern crate ndarray;
511
extern crate test;
@@ -304,6 +310,7 @@ fn add_2d_zip_cutout(bench: &mut test::Bencher) {
304310
}
305311

306312
#[bench]
313+
#[allow(clippy::identity_op)]
307314
fn add_2d_cutouts_by_4(bench: &mut test::Bencher) {
308315
let mut a = Array::<i32, _>::zeros((64 * 1, 64 * 1));
309316
let b = Array::<i32, _>::zeros((64 * 1, 64 * 1));
@@ -316,6 +323,7 @@ fn add_2d_cutouts_by_4(bench: &mut test::Bencher) {
316323
}
317324

318325
#[bench]
326+
#[allow(clippy::identity_op)]
319327
fn add_2d_cutouts_by_16(bench: &mut test::Bencher) {
320328
let mut a = Array::<i32, _>::zeros((64 * 1, 64 * 1));
321329
let b = Array::<i32, _>::zeros((64 * 1, 64 * 1));
@@ -328,6 +336,7 @@ fn add_2d_cutouts_by_16(bench: &mut test::Bencher) {
328336
}
329337

330338
#[bench]
339+
#[allow(clippy::identity_op)]
331340
fn add_2d_cutouts_by_32(bench: &mut test::Bencher) {
332341
let mut a = Array::<i32, _>::zeros((64 * 1, 64 * 1));
333342
let b = Array::<i32, _>::zeros((64 * 1, 64 * 1));
@@ -580,7 +589,7 @@ fn iadd_scalar_2d_strided_dyn(bench: &mut test::Bencher) {
580589
fn scaled_add_2d_f32_regular(bench: &mut test::Bencher) {
581590
let mut av = Array::<f32, _>::zeros((ADD2DSZ, ADD2DSZ));
582591
let bv = Array::<f32, _>::zeros((ADD2DSZ, ADD2DSZ));
583-
let scalar = 3.1415926535;
592+
let scalar = std::f32::consts::PI;
584593
bench.iter(|| {
585594
av.scaled_add(scalar, &bv);
586595
});
@@ -650,7 +659,7 @@ fn bench_row_iter(bench: &mut test::Bencher) {
650659
let a = Array::<f32, _>::zeros((1024, 1024));
651660
let it = a.row(17);
652661
bench.iter(|| {
653-
for elt in it.clone() {
662+
for elt in it {
654663
black_box(elt);
655664
}
656665
})
@@ -661,7 +670,7 @@ fn bench_col_iter(bench: &mut test::Bencher) {
661670
let a = Array::<f32, _>::zeros((1024, 1024));
662671
let it = a.column(17);
663672
bench.iter(|| {
664-
for elt in it.clone() {
673+
for elt in it {
665674
black_box(elt);
666675
}
667676
})

benches/chunks.rs

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ fn chunk2x2_sum_uget1(bench: &mut Bencher) {
6464
}
6565

6666
#[bench]
67+
#[allow(clippy::identity_op)]
6768
fn chunk2x2_sum_get2(bench: &mut Bencher) {
6869
let a = Array::<f32, _>::zeros((256, 256));
6970
let chunksz = (2, 2);

benches/construct.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#![feature(test)]
2-
2+
#![allow(
3+
clippy::many_single_char_names,
4+
clippy::deref_addrof,
5+
clippy::unreadable_literal,
6+
clippy::many_single_char_names
7+
)]
38
extern crate test;
49
use test::Bencher;
510

benches/gemv.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#![feature(test)]
2+
#![allow(
3+
clippy::many_single_char_names,
4+
clippy::deref_addrof,
5+
clippy::unreadable_literal,
6+
clippy::many_single_char_names
7+
)]
28

39
extern crate test;
410
use test::Bencher;

benches/higher-order.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#![feature(test)]
2-
2+
#![allow(
3+
clippy::many_single_char_names,
4+
clippy::deref_addrof,
5+
clippy::unreadable_literal,
6+
clippy::many_single_char_names
7+
)]
38
extern crate test;
49
use test::black_box;
510
use test::Bencher;
@@ -67,13 +72,13 @@ fn map_axis_0(bench: &mut Bencher) {
6772
let a = Array::from_iter(0..MASZ as i32)
6873
.into_shape([MA, MA])
6974
.unwrap();
70-
bench.iter(|| a.map_axis(Axis(0), |lane| black_box(lane)));
75+
bench.iter(|| a.map_axis(Axis(0), black_box));
7176
}
7277

7378
#[bench]
7479
fn map_axis_1(bench: &mut Bencher) {
7580
let a = Array::from_iter(0..MASZ as i32)
7681
.into_shape([MA, MA])
7782
.unwrap();
78-
bench.iter(|| a.map_axis(Axis(1), |lane| black_box(lane)));
83+
bench.iter(|| a.map_axis(Axis(1), black_box));
7984
}

benches/iter.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#![feature(test)]
2+
#![allow(
3+
clippy::many_single_char_names,
4+
clippy::deref_addrof,
5+
clippy::unreadable_literal,
6+
clippy::many_single_char_names
7+
)]
28

39
extern crate rawpointer;
410
extern crate test;
@@ -14,15 +20,15 @@ use ndarray::{FoldWhile, Zip};
1420
#[bench]
1521
fn iter_sum_2d_regular(bench: &mut Bencher) {
1622
let a = Array::<i32, _>::zeros((64, 64));
17-
bench.iter(|| a.iter().fold(0, |acc, &x| acc + x));
23+
bench.iter(|| a.iter().sum::<i32>());
1824
}
1925

2026
#[bench]
2127
fn iter_sum_2d_cutout(bench: &mut Bencher) {
2228
let a = Array::<i32, _>::zeros((66, 66));
2329
let av = a.slice(s![1..-1, 1..-1]);
2430
let a = av;
25-
bench.iter(|| a.iter().fold(0, |acc, &x| acc + x));
31+
bench.iter(|| a.iter().sum::<i32>());
2632
}
2733

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

4349
#[bench]
4450
fn iter_filter_sum_2d_u32(bench: &mut Bencher) {
4551
let a = Array::linspace(0., 1., 256).into_shape((16, 16)).unwrap();
4652
let b = a.mapv(|x| (x * 100.) as u32);
47-
bench.iter(|| b.iter().filter(|&&x| x < 75).fold(0, |acc, &x| acc + x));
53+
bench.iter(|| b.iter().filter(|&&x| x < 75).sum::<u32>());
4854
}
4955

5056
#[bench]
5157
fn iter_filter_sum_2d_f32(bench: &mut Bencher) {
5258
let a = Array::linspace(0., 1., 256).into_shape((16, 16)).unwrap();
5359
let b = a * 100.;
54-
bench.iter(|| b.iter().filter(|&&x| x < 75.).fold(0., |acc, &x| acc + x));
60+
bench.iter(|| b.iter().filter(|&&x| x < 75.).sum::<f32>());
5561
}
5662

5763
#[bench]
5864
fn iter_filter_sum_2d_stride_u32(bench: &mut Bencher) {
5965
let a = Array::linspace(0., 1., 256).into_shape((16, 16)).unwrap();
6066
let b = a.mapv(|x| (x * 100.) as u32);
6167
let b = b.slice(s![.., ..;2]);
62-
bench.iter(|| b.iter().filter(|&&x| x < 75).fold(0, |acc, &x| acc + x));
68+
bench.iter(|| b.iter().filter(|&&x| x < 75).sum::<u32>());
6369
}
6470

6571
#[bench]
6672
fn iter_filter_sum_2d_stride_f32(bench: &mut Bencher) {
6773
let a = Array::linspace(0., 1., 256).into_shape((16, 16)).unwrap();
6874
let b = a * 100.;
6975
let b = b.slice(s![.., ..;2]);
70-
bench.iter(|| b.iter().filter(|&&x| x < 75.).fold(0., |acc, &x| acc + x));
76+
bench.iter(|| b.iter().filter(|&&x| x < 75.).sum::<f32>());
7177
}
7278

7379
const ZIPSZ: usize = 10_000;
@@ -190,7 +196,7 @@ fn vector_sum_3_zip_unchecked_manual(bench: &mut Bencher) {
190196
let mut ap = a.as_ptr();
191197
let mut bp = b.as_ptr();
192198
let mut cp = c.as_mut_ptr();
193-
let cend = cp.offset(c.len() as isize);
199+
let cend = cp.add(c.len());
194200
while cp != cend {
195201
*cp.post_inc() += *ap.post_inc() + *bp.post_inc();
196202
}
@@ -310,7 +316,7 @@ fn indexed_iter_3d_dyn(bench: &mut Bencher) {
310316
fn iter_sum_1d_strided_fold(bench: &mut Bencher) {
311317
let mut a = Array::<u64, _>::ones(10240);
312318
a.slice_axis_inplace(Axis(0), Slice::new(0, None, 2));
313-
bench.iter(|| a.iter().fold(0, |acc, &x| acc + x));
319+
bench.iter(|| a.iter().sum::<u64>());
314320
}
315321

316322
#[bench]

examples/axis_ops.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#![allow(
2+
clippy::many_single_char_names,
3+
clippy::deref_addrof,
4+
clippy::unreadable_literal,
5+
clippy::many_single_char_names
6+
)]
17
extern crate ndarray;
28

39
use ndarray::prelude::*;

examples/bounds_check_elim.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#![crate_type = "lib"]
2+
#![allow(
3+
clippy::many_single_char_names,
4+
clippy::deref_addrof,
5+
clippy::unreadable_literal,
6+
clippy::many_single_char_names
7+
)]
28

39
// Test cases for bounds check elimination
410

examples/convo.rs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ where
2828
for i in 0..n - 2 {
2929
for j in 0..m - 2 {
3030
let mut conv = F::zero();
31+
#[allow(clippy::needless_range_loop)]
3132
for k in 0..3 {
3233
for l in 0..3 {
3334
conv = conv + *a.uget((i + k, j + l)) * kernel[k][l];

examples/life.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
#![allow(
2+
clippy::many_single_char_names,
3+
clippy::deref_addrof,
4+
clippy::unreadable_literal,
5+
clippy::many_single_char_names
6+
)]
17
extern crate ndarray;
28

39
use ndarray::prelude::*;
410

5-
const INPUT: &'static [u8] = include_bytes!("life.txt");
11+
const INPUT: &[u8] = include_bytes!("life.txt");
612
//const INPUT: &'static [u8] = include_bytes!("lifelite.txt");
713

814
const N: usize = 100;
@@ -71,7 +77,7 @@ fn render(a: &Board) {
7177
print!(".");
7278
}
7379
}
74-
println!("");
80+
println!();
7581
}
7682
}
7783

examples/zip_many.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#![allow(
2+
clippy::many_single_char_names,
3+
clippy::deref_addrof,
4+
clippy::unreadable_literal,
5+
clippy::many_single_char_names
6+
)]
17
extern crate ndarray;
28

39
use ndarray::prelude::*;

scripts/all-tests.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -x
44
set -e
55

66
FEATURES=$1
7-
IS_NIGHTLY=$2
7+
CHANNEL=$2
88

99
cargo build --verbose --no-default-features
1010
cargo test --verbose --no-default-features
@@ -14,4 +14,5 @@ cargo test --verbose --features "$FEATURES"
1414
cargo test --manifest-path=serialization-tests/Cargo.toml --verbose
1515
cargo test --manifest-path=blas-tests/Cargo.toml --verbose
1616
CARGO_TARGET_DIR=target/ cargo test --manifest-path=numeric-tests/Cargo.toml --verbose
17-
([ "$IS_NIGHTLY" != 1 ] || cargo bench --no-run --verbose --features "$FEATURES")
17+
([ "$CHANNEL" != "beta" ] || (rustup component add clippy && cargo clippy))
18+
([ "$CHANNEL" != "nightly" ] || cargo bench --no-run --verbose --features "$FEATURES")

src/array_serde.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl<S, Di> ArrayVisitor<S, Di> {
139139
}
140140
}
141141

142-
static ARRAY_FIELDS: &'static [&'static str] = &["v", "dim", "data"];
142+
static ARRAY_FIELDS: &[&str] = &["v", "dim", "data"];
143143

144144
/// **Requires crate feature `"serde-1"`**
145145
impl<'de, A, Di, S> Deserialize<'de> for ArrayBase<S, Di>

src/arrayformat.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,11 @@ enum PrintableCell {
5151
// where indexes are being omitted.
5252
fn to_be_printed(length: usize, limit: usize) -> Vec<PrintableCell> {
5353
if length <= 2 * limit {
54-
(0..length)
55-
.map(|x| PrintableCell::ElementIndex(x))
56-
.collect()
54+
(0..length).map(PrintableCell::ElementIndex).collect()
5755
} else {
58-
let mut v: Vec<PrintableCell> =
59-
(0..limit).map(|x| PrintableCell::ElementIndex(x)).collect();
56+
let mut v: Vec<PrintableCell> = (0..limit).map(PrintableCell::ElementIndex).collect();
6057
v.push(PrintableCell::Ellipses);
61-
v.extend((length - limit..length).map(|x| PrintableCell::ElementIndex(x)));
58+
v.extend((length - limit..length).map(PrintableCell::ElementIndex));
6259
v
6360
}
6461
}

src/data_traits.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub unsafe trait DataMut: Data + RawDataMut {
133133
/// accessed with safe code.
134134
///
135135
/// ***Internal trait, see `Data`.***
136-
#[deprecated(note = "use `Data + RawDataClone` instead", since = "0.13")]
136+
#[deprecated(note = "use `Data + RawDataClone` instead", since = "0.13.0")]
137137
pub trait DataClone: Data + RawDataClone {}
138138

139139
#[allow(deprecated)]
@@ -241,7 +241,7 @@ unsafe impl<A> Data for OwnedArcRepr<A> {
241241
Self::ensure_unique(&mut self_);
242242
let data = OwnedRepr(Arc::try_unwrap(self_.data.0).ok().unwrap());
243243
ArrayBase {
244-
data: data,
244+
data,
245245
ptr: self_.ptr,
246246
dim: self_.dim,
247247
strides: self_.strides,

src/dimension/axes.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ where
77
{
88
Axes {
99
dim: d,
10-
strides: strides,
10+
strides,
1111
start: 0,
1212
end: d.ndim(),
1313
}
@@ -46,6 +46,9 @@ pub struct AxisDescription(pub Axis, pub Ix, pub Ixs);
4646

4747
copy_and_clone!(AxisDescription);
4848

49+
// AxisDescription can't really be empty
50+
// https://github.com/rust-ndarray/ndarray/pull/642#discussion_r296051702
51+
#[allow(clippy::len_without_is_empty)]
4952
impl AxisDescription {
5053
/// Return axis
5154
#[inline(always)]

0 commit comments

Comments
 (0)