Skip to content

Commit 6dd3654

Browse files
authored
Merge pull request #76 from cassiersg/ndarray-0.15
Ndarray 0.15
2 parents e4c165c + 08fa170 commit 6dd3654

12 files changed

+62
-68
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ addons:
77
- libssl-dev
88
cache: cargo
99
rust:
10-
- 1.42.0
10+
- 1.49.0
1111
- stable
1212
- beta
1313
- nightly

Cargo.toml

+9-9
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ keywords = ["array", "multidimensional", "statistics", "matrix", "ndarray"]
1616
categories = ["data-structures", "science"]
1717

1818
[dependencies]
19-
ndarray = "0.14"
20-
noisy_float = "0.1.8"
19+
ndarray = "0.15.0"
20+
noisy_float = "0.2.0"
2121
num-integer = "0.1"
2222
num-traits = "0.2"
23-
rand = "0.7"
24-
itertools = { version = "0.9.0", default-features = false }
25-
indexmap = "1.0"
23+
rand = "0.8.3"
24+
itertools = { version = "0.10.0", default-features = false }
25+
indexmap = "1.6.2"
2626

2727
[dev-dependencies]
28-
ndarray = { version = "0.14", features = ["approx"] }
28+
ndarray = { version = "0.15.0", features = ["approx"] }
2929
criterion = "0.3"
3030
quickcheck = { version = "0.9.2", default-features = false }
31-
ndarray-rand = "0.12"
31+
ndarray-rand = "0.14.0"
3232
approx = "0.4"
33-
quickcheck_macros = "0.9"
34-
num-bigint = "0.3.1"
33+
quickcheck_macros = "1.0.0"
34+
num-bigint = "0.4.0"
3535

3636
[[bench]]
3737
name = "sort"

benches/deviation.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
use criterion::{
2-
black_box, criterion_group, criterion_main, AxisScale, Criterion, ParameterizedBenchmark,
3-
PlotConfiguration,
2+
black_box, criterion_group, criterion_main, AxisScale, Criterion, PlotConfiguration,
43
};
54
use ndarray::prelude::*;
5+
use ndarray_rand::rand_distr::Uniform;
66
use ndarray_rand::RandomExt;
77
use ndarray_stats::DeviationExt;
8-
use rand::distributions::Uniform;
98

109
fn sq_l2_dist(c: &mut Criterion) {
1110
let lens = vec![10, 100, 1000, 10000];
12-
let benchmark = ParameterizedBenchmark::new(
13-
"sq_l2_dist",
14-
|bencher, &len| {
11+
let mut group = c.benchmark_group("sq_l2_dist");
12+
group.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic));
13+
for len in &lens {
14+
group.bench_with_input(format!("{}", len), len, |b, &len| {
1515
let data = Array::random(len, Uniform::new(0.0, 1.0));
1616
let data2 = Array::random(len, Uniform::new(0.0, 1.0));
1717

18-
bencher.iter(|| black_box(data.sq_l2_dist(&data2).unwrap()))
19-
},
20-
lens,
21-
)
22-
.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic));
23-
c.bench("sq_l2_dist", benchmark);
18+
b.iter(|| black_box(data.sq_l2_dist(&data2).unwrap()))
19+
});
20+
}
21+
group.finish();
2422
}
2523

2624
criterion_group! {

benches/sort.rs

+17-20
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
use criterion::{
2-
black_box, criterion_group, criterion_main, AxisScale, BatchSize, Criterion,
3-
ParameterizedBenchmark, PlotConfiguration,
2+
black_box, criterion_group, criterion_main, AxisScale, BatchSize, Criterion, PlotConfiguration,
43
};
54
use ndarray::prelude::*;
65
use ndarray_stats::Sort1dExt;
76
use rand::prelude::*;
87

98
fn get_from_sorted_mut(c: &mut Criterion) {
109
let lens = vec![10, 100, 1000, 10000];
11-
let benchmark = ParameterizedBenchmark::new(
12-
"get_from_sorted_mut",
13-
|bencher, &len| {
10+
let mut group = c.benchmark_group("get_from_sorted_mut");
11+
group.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic));
12+
for len in &lens {
13+
group.bench_with_input(format!("{}", len), len, |b, &len| {
1414
let mut rng = StdRng::seed_from_u64(42);
1515
let mut data: Vec<_> = (0..len).collect();
1616
data.shuffle(&mut rng);
1717
let indices: Vec<_> = (0..len).step_by(len / 10).collect();
18-
bencher.iter_batched(
18+
b.iter_batched(
1919
|| Array1::from(data.clone()),
2020
|mut arr| {
2121
for &i in &indices {
@@ -24,34 +24,31 @@ fn get_from_sorted_mut(c: &mut Criterion) {
2424
},
2525
BatchSize::SmallInput,
2626
)
27-
},
28-
lens,
29-
)
30-
.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic));
31-
c.bench("get_from_sorted_mut", benchmark);
27+
});
28+
}
29+
group.finish();
3230
}
3331

3432
fn get_many_from_sorted_mut(c: &mut Criterion) {
3533
let lens = vec![10, 100, 1000, 10000];
36-
let benchmark = ParameterizedBenchmark::new(
37-
"get_many_from_sorted_mut",
38-
|bencher, &len| {
34+
let mut group = c.benchmark_group("get_many_from_sorted_mut");
35+
group.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic));
36+
for len in &lens {
37+
group.bench_with_input(format!("{}", len), len, |b, &len| {
3938
let mut rng = StdRng::seed_from_u64(42);
4039
let mut data: Vec<_> = (0..len).collect();
4140
data.shuffle(&mut rng);
4241
let indices: Array1<_> = (0..len).step_by(len / 10).collect();
43-
bencher.iter_batched(
42+
b.iter_batched(
4443
|| Array1::from(data.clone()),
4544
|mut arr| {
4645
black_box(arr.get_many_from_sorted_mut(&indices));
4746
},
4847
BatchSize::SmallInput,
4948
)
50-
},
51-
lens,
52-
)
53-
.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic));
54-
c.bench("get_many_from_sorted_mut", benchmark);
49+
});
50+
}
51+
group.finish();
5552
}
5653

5754
criterion_group! {

benches/summary_statistics.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
11
use criterion::{
2-
black_box, criterion_group, criterion_main, AxisScale, BatchSize, Criterion,
3-
ParameterizedBenchmark, PlotConfiguration,
2+
black_box, criterion_group, criterion_main, AxisScale, BatchSize, Criterion, PlotConfiguration,
43
};
54
use ndarray::prelude::*;
5+
use ndarray_rand::rand_distr::Uniform;
66
use ndarray_rand::RandomExt;
77
use ndarray_stats::SummaryStatisticsExt;
8-
use rand::distributions::Uniform;
98

109
fn weighted_std(c: &mut Criterion) {
1110
let lens = vec![10, 100, 1000, 10000];
12-
let benchmark = ParameterizedBenchmark::new(
13-
"weighted_std",
14-
|bencher, &len| {
11+
let mut group = c.benchmark_group("weighted_std");
12+
group.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic));
13+
for len in &lens {
14+
group.bench_with_input(format!("{}", len), len, |b, &len| {
1515
let data = Array::random(len, Uniform::new(0.0, 1.0));
1616
let mut weights = Array::random(len, Uniform::new(0.0, 1.0));
1717
weights /= weights.sum();
18-
bencher.iter_batched(
18+
b.iter_batched(
1919
|| data.clone(),
2020
|arr| {
2121
black_box(arr.weighted_std(&weights, 0.0).unwrap());
2222
},
2323
BatchSize::SmallInput,
2424
)
25-
},
26-
lens,
27-
)
28-
.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic));
29-
c.bench("weighted_std", benchmark);
25+
});
26+
}
27+
group.finish();
3028
}
3129

3230
criterion_group! {

src/correlation.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ where
185185
mod cov_tests {
186186
use super::*;
187187
use ndarray::array;
188+
use ndarray_rand::rand;
189+
use ndarray_rand::rand_distr::Uniform;
188190
use ndarray_rand::RandomExt;
189191
use quickcheck_macros::quickcheck;
190-
use rand;
191-
use rand::distributions::Uniform;
192192

193193
#[quickcheck]
194194
fn constant_random_variables_have_zero_covariance_matrix(value: f64) -> bool {
@@ -288,9 +288,10 @@ mod cov_tests {
288288
mod pearson_correlation_tests {
289289
use super::*;
290290
use ndarray::array;
291+
use ndarray::Array;
292+
use ndarray_rand::rand_distr::Uniform;
291293
use ndarray_rand::RandomExt;
292294
use quickcheck_macros::quickcheck;
293-
use rand::distributions::Uniform;
294295

295296
#[quickcheck]
296297
fn output_matrix_is_symmetric(bound: f64) -> bool {

src/deviation.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ where
232232

233233
let mut count = 0;
234234

235-
Zip::from(self).and(other).apply(|a, b| {
235+
Zip::from(self).and(other).for_each(|a, b| {
236236
if a == b {
237237
count += 1;
238238
}
@@ -259,7 +259,7 @@ where
259259

260260
let mut result = A::zero();
261261

262-
Zip::from(self).and(other).apply(|self_i, other_i| {
262+
Zip::from(self).and(other).for_each(|self_i, other_i| {
263263
let (a, b) = (self_i.clone(), other_i.clone());
264264
let diff = a - b;
265265
result += diff.clone() * diff;
@@ -291,7 +291,7 @@ where
291291

292292
let mut result = A::zero();
293293

294-
Zip::from(self).and(other).apply(|self_i, other_i| {
294+
Zip::from(self).and(other).for_each(|self_i, other_i| {
295295
let (a, b) = (self_i.clone(), other_i.clone());
296296
result += (a - b).abs();
297297
});
@@ -309,7 +309,7 @@ where
309309

310310
let mut max = A::zero();
311311

312-
Zip::from(self).and(other).apply(|self_i, other_i| {
312+
Zip::from(self).and(other).for_each(|self_i, other_i| {
313313
let (a, b) = (self_i.clone(), other_i.clone());
314314
let diff = (a - b).abs();
315315
if diff > max {

src/entropy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ where
169169
Zip::from(&mut temp)
170170
.and(self)
171171
.and(q)
172-
.apply(|result, &p, &q| {
172+
.for_each(|result, &p, &q| {
173173
*result = {
174174
if p == A::zero() {
175175
A::zero()
@@ -202,7 +202,7 @@ where
202202
Zip::from(&mut temp)
203203
.and(self)
204204
.and(q)
205-
.apply(|result, &p, &q| {
205+
.for_each(|result, &p, &q| {
206206
*result = {
207207
if p == A::zero() {
208208
A::zero()

src/maybe_nan/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ where
332332
A: 'a,
333333
F: FnMut(&'a A::NotNan),
334334
{
335-
self.visit(|elem| {
335+
self.for_each(|elem| {
336336
if let Some(not_nan) = elem.try_as_not_nan() {
337337
f(not_nan)
338338
}

src/quantile/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ where
477477
let mut results = Array::from_elem(results_shape, data.first().unwrap().clone());
478478
Zip::from(results.lanes_mut(axis))
479479
.and(data.lanes_mut(axis))
480-
.apply(|mut results, mut data| {
480+
.for_each(|mut results, mut data| {
481481
let index_map =
482482
get_many_from_sorted_mut_unchecked(&mut data, &searched_indexes);
483483
for (result, &q) in results.iter_mut().zip(qs) {

src/sort.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ where
116116
self[0].clone()
117117
} else {
118118
let mut rng = thread_rng();
119-
let pivot_index = rng.gen_range(0, n);
119+
let pivot_index = rng.gen_range(0..n);
120120
let partition_index = self.partition_mut(pivot_index);
121121
if i < partition_index {
122122
self.slice_axis_mut(Axis(0), Slice::from(..partition_index))
@@ -251,7 +251,7 @@ fn _get_many_from_sorted_mut_unchecked<A>(
251251

252252
// We pick a random pivot index: the corresponding element is the pivot value
253253
let mut rng = thread_rng();
254-
let pivot_index = rng.gen_range(0, n);
254+
let pivot_index = rng.gen_range(0..n);
255255

256256
// We partition the array with respect to the pivot value.
257257
// The pivot value moves to `array_partition_index`.

tests/summary_statistics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use approx::{abs_diff_eq, assert_abs_diff_eq};
22
use ndarray::{arr0, array, Array, Array1, Array2, Axis};
3+
use ndarray_rand::rand_distr::Uniform;
34
use ndarray_rand::RandomExt;
45
use ndarray_stats::{
56
errors::{EmptyInput, MultiInputError, ShapeMismatch},
67
SummaryStatisticsExt,
78
};
89
use noisy_float::types::N64;
910
use quickcheck::{quickcheck, TestResult};
10-
use rand::distributions::Uniform;
1111
use std::f64;
1212

1313
#[test]

0 commit comments

Comments
 (0)