Skip to content

Commit a426210

Browse files
committed
shape: Replace reshape with into_shape_with_order in tests
1 parent 3f3ba15 commit a426210

File tree

3 files changed

+35
-35
lines changed

3 files changed

+35
-35
lines changed

tests/array.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fn arrayviewmut_shrink_lifetime<'a, 'b: 'a>(
7474
fn test_mat_mul() {
7575
// smoke test, a big matrix multiplication of uneven size
7676
let (n, m) = (45, 33);
77-
let a = ArcArray::linspace(0., ((n * m) - 1) as f32, n as usize * m as usize).reshape((n, m));
77+
let a = ArcArray::linspace(0., ((n * m) - 1) as f32, n as usize * m as usize).into_shape_with_order((n, m)).unwrap();
7878
let b = ArcArray::eye(m);
7979
assert_eq!(a.dot(&b), a);
8080
let c = ArcArray::eye(n);
@@ -542,7 +542,7 @@ fn test_add() {
542542

543543
#[test]
544544
fn test_multidim() {
545-
let mut mat = ArcArray::zeros(2 * 3 * 4 * 5 * 6).reshape((2, 3, 4, 5, 6));
545+
let mut mat = ArcArray::zeros(2 * 3 * 4 * 5 * 6).into_shape_with_order((2, 3, 4, 5, 6)).unwrap();
546546
mat[(0, 0, 0, 0, 0)] = 22u8;
547547
{
548548
for (i, elt) in mat.iter_mut().enumerate() {
@@ -604,7 +604,7 @@ fn test_cow() {
604604
assert_eq!(n[[0, 0]], 1);
605605
assert_eq!(n[[0, 1]], 0);
606606
assert_eq!(n.get((0, 1)), Some(&0));
607-
let mut rev = mat.reshape(4);
607+
let mut rev = mat.into_shape_with_order(4).unwrap();
608608
rev.slice_collapse(s![..;-1]);
609609
assert_eq!(rev[0], 4);
610610
assert_eq!(rev[1], 3);
@@ -643,7 +643,7 @@ fn test_cow_shrink() {
643643
assert_eq!(n[[0, 1]], 0);
644644
assert_eq!(n.get((0, 1)), Some(&0));
645645
// small has non-C strides this way
646-
let mut small = mat.reshape(6);
646+
let mut small = mat.into_shape_with_order(6).unwrap();
647647
small.slice_collapse(s![4..;-1]);
648648
assert_eq!(small[0], 6);
649649
assert_eq!(small[1], 5);
@@ -660,22 +660,22 @@ fn test_cow_shrink() {
660660
#[test]
661661
#[cfg(feature = "std")]
662662
fn test_sub() {
663-
let mat = ArcArray::linspace(0., 15., 16).reshape((2, 4, 2));
663+
let mat = ArcArray::linspace(0., 15., 16).into_shape_with_order((2, 4, 2)).unwrap();
664664
let s1 = mat.index_axis(Axis(0), 0);
665665
let s2 = mat.index_axis(Axis(0), 1);
666666
assert_eq!(s1.shape(), &[4, 2]);
667667
assert_eq!(s2.shape(), &[4, 2]);
668-
let n = ArcArray::linspace(8., 15., 8).reshape((4, 2));
668+
let n = ArcArray::linspace(8., 15., 8).into_shape_with_order((4, 2)).unwrap();
669669
assert_eq!(n, s2);
670-
let m = ArcArray::from(vec![2., 3., 10., 11.]).reshape((2, 2));
670+
let m = ArcArray::from(vec![2., 3., 10., 11.]).into_shape_with_order((2, 2)).unwrap();
671671
assert_eq!(m, mat.index_axis(Axis(1), 1));
672672
}
673673

674674
#[should_panic]
675675
#[test]
676676
#[cfg(feature = "std")]
677677
fn test_sub_oob_1() {
678-
let mat = ArcArray::linspace(0., 15., 16).reshape((2, 4, 2));
678+
let mat = ArcArray::linspace(0., 15., 16).into_shape_with_order((2, 4, 2)).unwrap();
679679
mat.index_axis(Axis(0), 2);
680680
}
681681

@@ -1337,7 +1337,7 @@ fn from_vec_dim_stride_2d_rejects() {
13371337

13381338
#[test]
13391339
fn views() {
1340-
let a = ArcArray::from(vec![1, 2, 3, 4]).reshape((2, 2));
1340+
let a = ArcArray::from(vec![1, 2, 3, 4]).into_shape_with_order((2, 2)).unwrap();
13411341
let b = a.view();
13421342
assert_eq!(a, b);
13431343
assert_eq!(a.shape(), b.shape());
@@ -1354,7 +1354,7 @@ fn views() {
13541354

13551355
#[test]
13561356
fn view_mut() {
1357-
let mut a = ArcArray::from(vec![1, 2, 3, 4]).reshape((2, 2));
1357+
let mut a = ArcArray::from(vec![1, 2, 3, 4]).into_shape_with_order((2, 2)).unwrap();
13581358
for elt in &mut a.view_mut() {
13591359
*elt = 0;
13601360
}
@@ -1373,7 +1373,7 @@ fn view_mut() {
13731373

13741374
#[test]
13751375
fn slice_mut() {
1376-
let mut a = ArcArray::from(vec![1, 2, 3, 4]).reshape((2, 2));
1376+
let mut a = ArcArray::from(vec![1, 2, 3, 4]).into_shape_with_order((2, 2)).unwrap();
13771377
for elt in a.slice_mut(s![.., ..]) {
13781378
*elt = 0;
13791379
}
@@ -1680,7 +1680,7 @@ fn arithmetic_broadcast() {
16801680
#[test]
16811681
fn char_array() {
16821682
// test compilation & basics of non-numerical array
1683-
let cc = ArcArray::from_iter("alphabet".chars()).reshape((4, 2));
1683+
let cc = ArcArray::from_iter("alphabet".chars()).into_shape_with_order((4, 2)).unwrap();
16841684
assert!(cc.index_axis(Axis(1), 0) == ArcArray::from_iter("apae".chars()));
16851685
}
16861686

@@ -1740,7 +1740,7 @@ fn split_at() {
17401740
}
17411741
assert_eq!(a, arr2(&[[1., 5.], [8., 4.]]));
17421742

1743-
let b = ArcArray::linspace(0., 59., 60).reshape((3, 4, 5));
1743+
let b = ArcArray::linspace(0., 59., 60).into_shape_with_order((3, 4, 5)).unwrap();
17441744

17451745
let (left, right) = b.view().split_at(Axis(2), 2);
17461746
assert_eq!(left.shape(), [3, 4, 2]);

tests/iterators.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn double_ended() {
4242
#[test]
4343
fn iter_size_hint() {
4444
// Check that the size hint is correctly computed
45-
let a = ArcArray::from_iter(0..24).reshape((2, 3, 4));
45+
let a = ArcArray::from_iter(0..24).into_shape_with_order((2, 3, 4)).unwrap();
4646
let mut data = [0; 24];
4747
for (i, elt) in enumerate(&mut data) {
4848
*elt = i as i32;
@@ -64,7 +64,7 @@ fn indexed() {
6464
for (i, elt) in a.indexed_iter() {
6565
assert_eq!(i, *elt as usize);
6666
}
67-
let a = a.reshape((2, 4, 1));
67+
let a = a.into_shape_with_order((2, 4, 1)).unwrap();
6868
let (mut i, mut j, k) = (0, 0, 0);
6969
for (idx, elt) in a.indexed_iter() {
7070
assert_eq!(idx, (i, j, k));
@@ -96,11 +96,11 @@ fn as_slice() {
9696
}
9797

9898
let a = ArcArray::linspace(0., 7., 8);
99-
let a = a.reshape((2, 4, 1));
99+
let a = a.into_shape_with_order((2, 4, 1)).unwrap();
100100

101101
assert_slice_correct(&a);
102102

103-
let a = a.reshape((2, 4));
103+
let a = a.into_shape_with_order((2, 4)).unwrap();
104104
assert_slice_correct(&a);
105105

106106
assert!(a.view().index_axis(Axis(1), 0).as_slice().is_none());
@@ -123,7 +123,7 @@ fn as_slice() {
123123
assert!(u.as_slice().is_some());
124124
assert_slice_correct(&u);
125125

126-
let a = a.reshape((8, 1));
126+
let a = a.into_shape_with_order((8, 1)).unwrap();
127127
assert_slice_correct(&a);
128128
let u = a.slice(s![..;2, ..]);
129129
println!(
@@ -138,7 +138,7 @@ fn as_slice() {
138138
#[test]
139139
fn inner_iter() {
140140
let a = ArcArray::from_iter(0..12);
141-
let a = a.reshape((2, 3, 2));
141+
let a = a.into_shape_with_order((2, 3, 2)).unwrap();
142142
// [[[0, 1],
143143
// [2, 3],
144144
// [4, 5]],
@@ -187,7 +187,7 @@ fn inner_iter_corner_cases() {
187187
#[test]
188188
fn inner_iter_size_hint() {
189189
// Check that the size hint is correctly computed
190-
let a = ArcArray::from_iter(0..24).reshape((2, 3, 4));
190+
let a = ArcArray::from_iter(0..24).into_shape_with_order((2, 3, 4)).unwrap();
191191
let mut len = 6;
192192
let mut it = a.rows().into_iter();
193193
assert_eq!(it.len(), len);
@@ -202,7 +202,7 @@ fn inner_iter_size_hint() {
202202
#[test]
203203
fn outer_iter() {
204204
let a = ArcArray::from_iter(0..12);
205-
let a = a.reshape((2, 3, 2));
205+
let a = a.into_shape_with_order((2, 3, 2)).unwrap();
206206
// [[[0, 1],
207207
// [2, 3],
208208
// [4, 5]],
@@ -261,7 +261,7 @@ fn outer_iter() {
261261
#[test]
262262
fn axis_iter() {
263263
let a = ArcArray::from_iter(0..12);
264-
let a = a.reshape((2, 3, 2));
264+
let a = a.into_shape_with_order((2, 3, 2)).unwrap();
265265
// [[[0, 1],
266266
// [2, 3],
267267
// [4, 5]],
@@ -353,7 +353,7 @@ fn outer_iter_corner_cases() {
353353
#[test]
354354
fn outer_iter_mut() {
355355
let a = ArcArray::from_iter(0..12);
356-
let a = a.reshape((2, 3, 2));
356+
let a = a.into_shape_with_order((2, 3, 2)).unwrap();
357357
// [[[0, 1],
358358
// [2, 3],
359359
// [4, 5]],
@@ -380,7 +380,7 @@ fn outer_iter_mut() {
380380
#[test]
381381
fn axis_iter_mut() {
382382
let a = ArcArray::from_iter(0..12);
383-
let a = a.reshape((2, 3, 2));
383+
let a = a.into_shape_with_order((2, 3, 2)).unwrap();
384384
// [[[0, 1],
385385
// [2, 3],
386386
// [4, 5]],
@@ -400,7 +400,7 @@ fn axis_iter_mut() {
400400
#[test]
401401
fn axis_chunks_iter() {
402402
let a = ArcArray::from_iter(0..24);
403-
let a = a.reshape((2, 6, 2));
403+
let a = a.into_shape_with_order((2, 6, 2)).unwrap();
404404

405405
let it = a.axis_chunks_iter(Axis(1), 2);
406406
assert_equal(
@@ -413,7 +413,7 @@ fn axis_chunks_iter() {
413413
);
414414

415415
let a = ArcArray::from_iter(0..28);
416-
let a = a.reshape((2, 7, 2));
416+
let a = a.into_shape_with_order((2, 7, 2)).unwrap();
417417

418418
let it = a.axis_chunks_iter(Axis(1), 2);
419419
assert_equal(
@@ -535,7 +535,7 @@ fn axis_chunks_iter_corner_cases() {
535535
// and enable checking if no pointer offsetting is out of bounds. However
536536
// checking the absence of of out of bounds offsetting cannot (?) be
537537
// done automatically, so one has to launch this test in a debugger.
538-
let a = ArcArray::<f32, _>::linspace(0., 7., 8).reshape((8, 1));
538+
let a = ArcArray::<f32, _>::linspace(0., 7., 8).into_shape_with_order((8, 1)).unwrap();
539539
let it = a.axis_chunks_iter(Axis(0), 4);
540540
assert_equal(it, vec![a.slice(s![..4, ..]), a.slice(s![4.., ..])]);
541541
let a = a.slice(s![..;-1,..]);
@@ -634,7 +634,7 @@ fn axis_chunks_iter_split_at() {
634634
#[test]
635635
fn axis_chunks_iter_mut() {
636636
let a = ArcArray::from_iter(0..24);
637-
let mut a = a.reshape((2, 6, 2));
637+
let mut a = a.into_shape_with_order((2, 6, 2)).unwrap();
638638

639639
let mut it = a.axis_chunks_iter_mut(Axis(1), 2);
640640
let mut col0 = it.next().unwrap();
@@ -658,7 +658,7 @@ fn axis_chunks_iter_mut_zero_axis_len() {
658658
#[test]
659659
fn outer_iter_size_hint() {
660660
// Check that the size hint is correctly computed
661-
let a = ArcArray::from_iter(0..24).reshape((4, 3, 2));
661+
let a = ArcArray::from_iter(0..24).into_shape_with_order((4, 3, 2)).unwrap();
662662
let mut len = 4;
663663
let mut it = a.outer_iter();
664664
assert_eq!(it.len(), len);
@@ -690,7 +690,7 @@ fn outer_iter_size_hint() {
690690

691691
#[test]
692692
fn outer_iter_split_at() {
693-
let a = ArcArray::from_iter(0..30).reshape((5, 3, 2));
693+
let a = ArcArray::from_iter(0..30).into_shape_with_order((5, 3, 2)).unwrap();
694694

695695
let it = a.outer_iter();
696696
let (mut itl, mut itr) = it.clone().split_at(2);
@@ -712,15 +712,15 @@ fn outer_iter_split_at() {
712712
#[test]
713713
#[should_panic]
714714
fn outer_iter_split_at_panics() {
715-
let a = ArcArray::from_iter(0..30).reshape((5, 3, 2));
715+
let a = ArcArray::from_iter(0..30).into_shape_with_order((5, 3, 2)).unwrap();
716716

717717
let it = a.outer_iter();
718718
it.split_at(6);
719719
}
720720

721721
#[test]
722722
fn outer_iter_mut_split_at() {
723-
let mut a = ArcArray::from_iter(0..30).reshape((5, 3, 2));
723+
let mut a = ArcArray::from_iter(0..30).into_shape_with_order((5, 3, 2)).unwrap();
724724

725725
{
726726
let it = a.outer_iter_mut();

xtest-serialization/tests/serialize.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn serial_many_dim_serde() {
4545

4646
{
4747
// Test a sliced array.
48-
let mut a = ArcArray::linspace(0., 31., 32).reshape((2, 2, 2, 4));
48+
let mut a = ArcArray::linspace(0., 31., 32).into_shape_with_order((2, 2, 2, 4)).unwrap();
4949
a.slice_collapse(s![..;-1, .., .., ..2]);
5050
let serial = serde_json::to_string(&a).unwrap();
5151
println!("Encode {:?} => {:?}", a, serial);
@@ -155,7 +155,7 @@ fn serial_many_dim_serde_msgpack() {
155155

156156
{
157157
// Test a sliced array.
158-
let mut a = ArcArray::linspace(0., 31., 32).reshape((2, 2, 2, 4));
158+
let mut a = ArcArray::linspace(0., 31., 32).into_shape_with_order((2, 2, 2, 4)).unwrap();
159159
a.slice_collapse(s![..;-1, .., .., ..2]);
160160

161161
let mut buf = Vec::new();
@@ -208,7 +208,7 @@ fn serial_many_dim_ron() {
208208

209209
{
210210
// Test a sliced array.
211-
let mut a = ArcArray::linspace(0., 31., 32).reshape((2, 2, 2, 4));
211+
let mut a = ArcArray::linspace(0., 31., 32).into_shape_with_order((2, 2, 2, 4)).unwrap();
212212
a.slice_collapse(s![..;-1, .., .., ..2]);
213213

214214
let a_s = ron_serialize(&a).unwrap();

0 commit comments

Comments
 (0)