Skip to content

Commit 62a450c

Browse files
committed
shape: Add tests for .coerce_shape()
1 parent 1dfda50 commit 62a450c

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

tests/reshape.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ use ndarray::Order;
88
fn reshape() {
99
let data = [1, 2, 3, 4, 5, 6, 7, 8];
1010
let v = aview1(&data);
11-
let u = v.into_shape((3, 3));
11+
let u = v.coerce_shape((3, 3));
1212
assert!(u.is_err());
13-
let u = v.into_shape((2, 2, 2));
13+
let u = v.coerce_shape((2, 2, 2));
1414
assert!(u.is_ok());
1515
let u = u.unwrap();
1616
assert_eq!(u.shape(), &[2, 2, 2]);
17-
let s = u.into_shape((4, 2)).unwrap();
17+
let s = u.coerce_shape((4, 2)).unwrap();
1818
assert_eq!(s.shape(), &[4, 2]);
1919
assert_eq!(s, aview2(&[[1, 2], [3, 4], [5, 6], [7, 8]]));
2020
}
@@ -24,17 +24,17 @@ fn reshape() {
2424
fn reshape_error1() {
2525
let data = [1, 2, 3, 4, 5, 6, 7, 8];
2626
let v = aview1(&data);
27-
let _u = v.into_shape((2, 5)).unwrap();
27+
let _u = v.coerce_shape((2, 5)).unwrap();
2828
}
2929

3030
#[test]
3131
#[should_panic(expected = "IncompatibleLayout")]
3232
fn reshape_error2() {
3333
let data = [1, 2, 3, 4, 5, 6, 7, 8];
3434
let v = aview1(&data);
35-
let mut u = v.into_shape((2, 2, 2)).unwrap();
35+
let mut u = v.coerce_shape((2, 2, 2)).unwrap();
3636
u.swap_axes(0, 1);
37-
let _s = u.into_shape((2, 4)).unwrap();
37+
let _s = u.coerce_shape((2, 4)).unwrap();
3838
}
3939

4040
#[test]
@@ -47,16 +47,16 @@ fn reshape_f() {
4747
println!("{:?}", v);
4848

4949
// noop ok
50-
let v2 = v.into_shape((3, 4));
50+
let v2 = v.coerce_shape(((3, 4), Order::F));
5151
assert!(v2.is_ok());
5252
assert_eq!(v, v2.unwrap());
5353

54-
let u = v.into_shape((3, 2, 2));
54+
let u = v.coerce_shape(((3, 2, 2), Order::F));
5555
assert!(u.is_ok());
5656
let u = u.unwrap();
5757
println!("{:?}", u);
5858
assert_eq!(u.shape(), &[3, 2, 2]);
59-
let s = u.into_shape((4, 3)).unwrap();
59+
let s = u.coerce_shape(((4, 3), Order::F)).unwrap();
6060
println!("{:?}", s);
6161
assert_eq!(s.shape(), &[4, 3]);
6262
assert_eq!(s, aview2(&[[0, 4, 8], [1, 5, 9], [2, 6, 10], [3, 7, 11]]));

0 commit comments

Comments
 (0)