Skip to content

Commit a31b3ea

Browse files
appehelsingjonasBoss
authored andcommitted
Upgraded ndarray to 0.16
1 parent 87d3484 commit a31b3ea

File tree

8 files changed

+53
-44
lines changed

8 files changed

+53
-44
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ categories = ["science", "algorithms", "mathematics"]
1212
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1313

1414
[dependencies]
15-
ndarray = "0.15"
15+
ndarray = "0.16"
1616
num-traits = "0.2"
1717
thiserror = "1.0"
1818

1919
[dev-dependencies]
2020
cargo-tarpaulin = "0.27"
21-
ndarray = {version = "0.15", features = ["approx-0_5", "rayon"] }
21+
ndarray = {version = "0.16", features = ["approx", "rayon"] }
2222
approx = "0.5"
2323
criterion = "0.5"
2424
rand = "0.8"

benches/bench_interp1d.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn bench_interp1d_scalar_multithread(c: &mut Criterion) {
6767
})
6868
});
6969

70-
let query = query.into_shape((2500, 4)).unwrap();
70+
let query = query.into_shape_with_order((2500, 4)).unwrap();
7171
let query_arr: Vec<_> = query.axis_iter(Axis(0)).collect();
7272
c.bench_function("1D scalar MT `interp_array`", |b| {
7373
b.iter(|| {
@@ -80,7 +80,7 @@ fn bench_interp1d_scalar_multithread(c: &mut Criterion) {
8080

8181
fn bench_interp1d_array(c: &mut Criterion) {
8282
let data = Array::from_rand(500, (0.0, 1.0), 69)
83-
.into_shape((100, 5))
83+
.into_shape_with_order((100, 5))
8484
.unwrap();
8585
let interp = Interp1D::builder(data).build().unwrap();
8686
let query = Array::from_rand(10_000, (0.0, 99.0), 123);
@@ -102,7 +102,7 @@ fn bench_interp1d_array(c: &mut Criterion) {
102102
})
103103
});
104104

105-
let query = query.into_shape((2500, 4)).unwrap();
105+
let query = query.into_shape_with_order((2500, 4)).unwrap();
106106
let query_arr: Vec<_> = query.axis_iter(Axis(0)).collect();
107107
c.bench_function("1D array `interp_array`", |b| {
108108
b.iter(|| {

benches/bench_interp1d_query_dim.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn bench_scalar_data_1d_query(c: &mut Criterion) {
1313
let interp = Interp1D::builder(data).build().unwrap();
1414
let query = Array::from_rand(10_000, (0.0, 99.0), 123);
1515

16-
let query = query.into_shape((2500, 4)).unwrap();
16+
let query = query.into_shape_with_order((2500, 4)).unwrap();
1717
let query_arr: Vec<_> = query.axis_iter(Axis(0)).collect();
1818
c.bench_function("1D scalar `interp_array`", |b| {
1919
b.iter(|| {
@@ -38,7 +38,7 @@ fn bench_scalar_data_2d_query(c: &mut Criterion) {
3838
let interp = Interp1D::builder(data).build().unwrap();
3939
let query = Array::from_rand(10_000, (0.0, 99.0), 123);
4040

41-
let query = query.into_shape((625, 4, 4)).unwrap();
41+
let query = query.into_shape_with_order((625, 4, 4)).unwrap();
4242
let query_arr: Vec<_> = query.axis_iter(Axis(0)).collect();
4343
c.bench_function("1D scalar `interp_array` 2D-query", |b| {
4444
b.iter(|| {
@@ -63,7 +63,7 @@ fn bench_scalar_data_3d_query(c: &mut Criterion) {
6363
let interp = Interp1D::builder(data).build().unwrap();
6464
let query = Array::from_rand(10_000, (0.0, 99.0), 123);
6565

66-
let query = query.into_shape((125, 5, 4, 4)).unwrap();
66+
let query = query.into_shape_with_order((125, 5, 4, 4)).unwrap();
6767
let query_arr: Vec<_> = query.axis_iter(Axis(0)).collect();
6868
c.bench_function("1D scalar `interp_array` 3D-query", |b| {
6969
b.iter(|| {

benches/bench_interp2d.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mod rand_extensions;
1111

1212
fn bench_interp2d_scalar(c: &mut Criterion) {
1313
let data = Array::from_rand(10_000, (0.0, 1.0), 42)
14-
.into_shape((100, 100))
14+
.into_shape_with_order((100, 100))
1515
.unwrap();
1616
let interp = Interp2D::builder(data).build().unwrap();
1717
let query_x = Array::from_rand(10_000, (0.0, 99.0), 123);
@@ -45,7 +45,7 @@ fn bench_interp2d_scalar(c: &mut Criterion) {
4545

4646
fn bench_interp2d_scalar_multithread(c: &mut Criterion) {
4747
let data = Array::from_rand(10_000, (0.0, 1.0), 42)
48-
.into_shape((100, 100))
48+
.into_shape_with_order((100, 100))
4949
.unwrap();
5050
let interp = Interp2D::builder(data).build().unwrap();
5151
let query_x = Array::from_rand(10_000, (0.0, 99.0), 123);
@@ -67,8 +67,8 @@ fn bench_interp2d_scalar_multithread(c: &mut Criterion) {
6767
})
6868
});
6969

70-
let query_x = query_x.into_shape((2500, 4)).unwrap();
71-
let query_y = query_y.into_shape((2500, 4)).unwrap();
70+
let query_x = query_x.into_shape_with_order((2500, 4)).unwrap();
71+
let query_y = query_y.into_shape_with_order((2500, 4)).unwrap();
7272
let query_arrx: Vec<_> = query_x.axis_iter(Axis(0)).collect();
7373
let query_arry: Vec<_> = query_y.axis_iter(Axis(0)).collect();
7474
c.bench_function("2D scalar MT `interp_array`", |b| {
@@ -85,7 +85,7 @@ fn bench_interp2d_scalar_multithread(c: &mut Criterion) {
8585

8686
fn bench_interp2d_array(c: &mut Criterion) {
8787
let data = Array::from_rand(50_000, (0.0, 1.0), 69)
88-
.into_shape((100, 100, 5))
88+
.into_shape_with_order((100, 100, 5))
8989
.unwrap();
9090
let interp = Interp2D::builder(data).build().unwrap();
9191
let query_x = Array::from_rand(10_000, (0.0, 99.0), 123);
@@ -108,8 +108,8 @@ fn bench_interp2d_array(c: &mut Criterion) {
108108
})
109109
});
110110

111-
let query_x = query_x.into_shape((2500, 4)).unwrap();
112-
let query_y = query_y.into_shape((2500, 4)).unwrap();
111+
let query_x = query_x.into_shape_with_order((2500, 4)).unwrap();
112+
let query_y = query_y.into_shape_with_order((2500, 4)).unwrap();
113113
let query_arrx: Vec<_> = query_x.axis_iter(Axis(0)).collect();
114114
let query_arry: Vec<_> = query_y.axis_iter(Axis(0)).collect();
115115
c.bench_function("2D array `interp_array`", |b| {

benches/bench_interp2d_query_dim.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mod rand_extensions;
88

99
fn setup() -> (Interp2DScalar<f64, Bilinear>, Array1<f64>, Array1<f64>) {
1010
let data = Array::from_rand(10_000, (0.0, 1.0), 42)
11-
.into_shape((100, 100))
11+
.into_shape_with_order((100, 100))
1212
.unwrap();
1313
let interp = Interp2D::builder(data).build().unwrap();
1414
let query_x = Array::from_rand(10_000, (0.0, 99.0), 123);
@@ -18,8 +18,8 @@ fn setup() -> (Interp2DScalar<f64, Bilinear>, Array1<f64>, Array1<f64>) {
1818

1919
fn bench_scalar_data_1d_query(c: &mut Criterion) {
2020
let (interp, query_x, query_y) = black_box(setup());
21-
let query_x = query_x.into_shape((2500, 4)).unwrap();
22-
let query_y = query_y.into_shape((2500, 4)).unwrap();
21+
let query_x = query_x.into_shape_with_order((2500, 4)).unwrap();
22+
let query_y = query_y.into_shape_with_order((2500, 4)).unwrap();
2323
let query_arrx: Vec<_> = query_x.axis_iter(Axis(0)).collect();
2424
let query_arry: Vec<_> = query_y.axis_iter(Axis(0)).collect();
2525

@@ -43,8 +43,8 @@ fn bench_scalar_data_1d_query(c: &mut Criterion) {
4343

4444
fn bench_scalar_data_2d_query(c: &mut Criterion) {
4545
let (interp, query_x, query_y) = black_box(setup());
46-
let query_x = query_x.into_shape((625, 4, 4)).unwrap();
47-
let query_y = query_y.into_shape((625, 4, 4)).unwrap();
46+
let query_x = query_x.into_shape_with_order((625, 4, 4)).unwrap();
47+
let query_y = query_y.into_shape_with_order((625, 4, 4)).unwrap();
4848
let query_arrx: Vec<_> = query_x.axis_iter(Axis(0)).collect();
4949
let query_arry: Vec<_> = query_y.axis_iter(Axis(0)).collect();
5050

@@ -68,8 +68,8 @@ fn bench_scalar_data_2d_query(c: &mut Criterion) {
6868

6969
fn bench_scalar_data_3d_query(c: &mut Criterion) {
7070
let (interp, query_x, query_y) = black_box(setup());
71-
let query_x = query_x.into_shape((125, 5, 4, 4)).unwrap();
72-
let query_y = query_y.into_shape((125, 5, 4, 4)).unwrap();
71+
let query_x = query_x.into_shape_with_order((125, 5, 4, 4)).unwrap();
72+
let query_y = query_y.into_shape_with_order((125, 5, 4, 4)).unwrap();
7373
let query_arrx: Vec<_> = query_x.axis_iter(Axis(0)).collect();
7474
let query_arry: Vec<_> = query_y.axis_iter(Axis(0)).collect();
7575

src/interp1d/mod.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,15 @@ where
308308
}
309309
});
310310

311-
let subview = match subview.into_shape(self.data.raw_dim().remove_axis(Axis(0))) {
312-
Ok(view) => view,
313-
Err(err) => {
314-
let expect = self.get_buffer_shape(xs.raw_dim()).into_pattern();
315-
let got = buffer.dim();
316-
panic!("{err} expected: {expect:?}, got: {got:?}")
317-
}
318-
};
311+
let subview =
312+
match subview.into_shape_with_order(self.data.raw_dim().remove_axis(Axis(0))) {
313+
Ok(view) => view,
314+
Err(err) => {
315+
let expect = self.get_buffer_shape(xs.raw_dim()).into_pattern();
316+
let got = buffer.dim();
317+
panic!("{err} expected: {expect:?}, got: {got:?}")
318+
}
319+
};
319320

320321
self.strategy.interp_into(self, subview, x)?;
321322
}
@@ -359,7 +360,11 @@ where
359360
/// - `x` is stricktly monotonic rising
360361
/// - `data.shape()[0] == x.len()`
361362
/// - the `strategy` is porperly initialized with the data
362-
pub unsafe fn new_unchecked(x: ArrayBase<Sx, Ix1>, data: ArrayBase<Sd, D>, strategy: Strat) -> Self {
363+
pub unsafe fn new_unchecked(
364+
x: ArrayBase<Sx, Ix1>,
365+
data: ArrayBase<Sd, D>,
366+
strategy: Strat,
367+
) -> Self {
363368
Interp1D { x, data, strategy }
364369
}
365370

@@ -498,7 +503,7 @@ mod tests {
498503
macro_rules! get_interp {
499504
($dim:expr, $shape:expr) => {{
500505
let arr = rand_arr(4usize.pow($dim), (0.0, 1.0), 64)
501-
.into_shape($shape)
506+
.into_shape_with_order($shape)
502507
.unwrap();
503508
Interp1D::builder(arr).build().unwrap()
504509
}};
@@ -565,7 +570,7 @@ mod tests {
565570
#[should_panic(expected = "expected: [2], got: [1]")] // this is not really a good message
566571
fn interp1d_2d_array_into_too_small1() {
567572
let arr = rand_arr((4usize).pow(2), (0.0, 1.0), 64)
568-
.into_shape((4, 4))
573+
.into_shape_with_order((4, 4))
569574
.unwrap();
570575
let interp = Interp1D::builder(arr).build().unwrap();
571576
let mut buf = Array::zeros((1, 4));
@@ -576,7 +581,7 @@ mod tests {
576581
#[should_panic]
577582
fn interp1d_2d_array_into_too_small2() {
578583
let arr = rand_arr((4usize).pow(2), (0.0, 1.0), 64)
579-
.into_shape((4, 4))
584+
.into_shape_with_order((4, 4))
580585
.unwrap();
581586
let interp = Interp1D::builder(arr).build().unwrap();
582587
let mut buf = Array::zeros((2, 3));
@@ -587,7 +592,7 @@ mod tests {
587592
#[should_panic]
588593
fn interp1d_2d_array_into_too_big1() {
589594
let arr = rand_arr((4usize).pow(2), (0.0, 1.0), 64)
590-
.into_shape((4, 4))
595+
.into_shape_with_order((4, 4))
591596
.unwrap();
592597
let interp = Interp1D::builder(arr).build().unwrap();
593598
let mut buf = Array::zeros((3, 4));
@@ -598,7 +603,7 @@ mod tests {
598603
#[should_panic]
599604
fn interp1d_2d_array_into_too_big2() {
600605
let arr = rand_arr((4usize).pow(2), (0.0, 1.0), 64)
601-
.into_shape((4, 4))
606+
.into_shape_with_order((4, 4))
602607
.unwrap();
603608
let interp = Interp1D::builder(arr).build().unwrap();
604609
let mut buf = Array::zeros((2, 5));

src/interp2d/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ where
265265
}
266266
});
267267

268-
let subview = match subview.into_shape(
268+
let subview = match subview.into_shape_with_order(
269269
self.data
270270
.raw_dim()
271271
.remove_axis(Axis(0))
@@ -543,7 +543,7 @@ mod tests {
543543
#[test]
544544
fn $name() {
545545
let arr = rand_arr(4usize.pow($dim), (0.0, 1.0), 64)
546-
.into_shape($shape)
546+
.into_shape_with_order($shape)
547547
.unwrap();
548548
let interp = Interp2D::builder(arr).build().unwrap();
549549
let res = interp.interp(2.2, 2.2).unwrap();
@@ -578,7 +578,7 @@ mod tests {
578578
#[test]
579579
fn interp2d_2d_scalar() {
580580
let arr = rand_arr(4usize.pow(2), (0.0, 1.0), 64)
581-
.into_shape((4, 4))
581+
.into_shape_with_order((4, 4))
582582
.unwrap();
583583
let _res: f64 = Interp2D::builder(arr) // typecheck f64 as return type
584584
.build()

tests/interp2d.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,19 @@ fn extrapolate() {
8383

8484
#[test]
8585
fn interpolate_array() {
86-
let data = Array::linspace(0.0, 8.0, 9).into_shape((3, 3)).unwrap();
86+
let data = Array::linspace(0.0, 8.0, 9)
87+
.into_shape_with_order((3, 3))
88+
.unwrap();
8789
let x = array![1.0, 2.0, 3.0];
8890
let y = array![4.0, 5.0, 6.0];
8991
let resolution = 11usize;
9092
let qx = Array::linspace(1.0, 3.0, resolution);
9193
let qy = Array::linspace(4.0, 6.0, resolution);
9294
let qx = Array::from_iter(qx.into_iter().flat_map(|x| repeat(x).take(resolution)))
93-
.into_shape((resolution, resolution))
95+
.into_shape_with_order((resolution, resolution))
9496
.unwrap();
9597
let qy = Array::from_iter(repeat(qy).take(resolution).flatten())
96-
.into_shape((resolution, resolution))
98+
.into_shape_with_order((resolution, resolution))
9799
.unwrap();
98100

99101
let interp = Interp2D::builder(data).x(x).y(y).build().unwrap();
@@ -247,7 +249,7 @@ fn interp_nd_data() {
247249
.flatten()
248250
.flatten(),
249251
)
250-
.into_shape((2, 2, 2, 2))
252+
.into_shape_with_order((2, 2, 2, 2))
251253
.unwrap();
252254

253255
let interp = Interp2DBuilder::new(data).build().unwrap();
@@ -265,7 +267,9 @@ fn interp_nd_data() {
265267
#[test]
266268
#[should_panic(expected = "`xs.shape()` and `ys.shape()` do not match")]
267269
fn interp_array_with_unmatched_axis() {
268-
let data = Array::linspace(0.0, 8.0, 9).into_shape((3, 3)).unwrap();
270+
let data = Array::linspace(0.0, 8.0, 9)
271+
.into_shape_with_order((3, 3))
272+
.unwrap();
269273
let qx = array![0.0, 1.0];
270274
let qy = array![0.0, 1.0, 2.0];
271275
let interp = Interp2D::builder(data).build().unwrap();

0 commit comments

Comments
 (0)