Skip to content

Commit 4ebbb71

Browse files
committed
shape: Add tests for .to_shape()
1 parent f46496f commit 4ebbb71

File tree

1 file changed

+0
-58
lines changed

1 file changed

+0
-58
lines changed

tests/array.rs

-58
Original file line numberDiff line numberDiff line change
@@ -1370,64 +1370,6 @@ fn transpose_view_mut() {
13701370
assert_eq!(at, arr2(&[[1, 4], [2, 5], [3, 7]]));
13711371
}
13721372

1373-
#[test]
1374-
fn reshape() {
1375-
let data = [1, 2, 3, 4, 5, 6, 7, 8];
1376-
let v = aview1(&data);
1377-
let u = v.into_shape((3, 3));
1378-
assert!(u.is_err());
1379-
let u = v.into_shape((2, 2, 2));
1380-
assert!(u.is_ok());
1381-
let u = u.unwrap();
1382-
assert_eq!(u.shape(), &[2, 2, 2]);
1383-
let s = u.into_shape((4, 2)).unwrap();
1384-
assert_eq!(s.shape(), &[4, 2]);
1385-
assert_eq!(s, aview2(&[[1, 2], [3, 4], [5, 6], [7, 8]]));
1386-
}
1387-
1388-
#[test]
1389-
#[should_panic(expected = "IncompatibleShape")]
1390-
fn reshape_error1() {
1391-
let data = [1, 2, 3, 4, 5, 6, 7, 8];
1392-
let v = aview1(&data);
1393-
let _u = v.into_shape((2, 5)).unwrap();
1394-
}
1395-
1396-
#[test]
1397-
#[should_panic(expected = "IncompatibleLayout")]
1398-
fn reshape_error2() {
1399-
let data = [1, 2, 3, 4, 5, 6, 7, 8];
1400-
let v = aview1(&data);
1401-
let mut u = v.into_shape((2, 2, 2)).unwrap();
1402-
u.swap_axes(0, 1);
1403-
let _s = u.into_shape((2, 4)).unwrap();
1404-
}
1405-
1406-
#[test]
1407-
fn reshape_f() {
1408-
let mut u = Array::zeros((3, 4).f());
1409-
for (i, elt) in enumerate(u.as_slice_memory_order_mut().unwrap()) {
1410-
*elt = i as i32;
1411-
}
1412-
let v = u.view();
1413-
println!("{:?}", v);
1414-
1415-
// noop ok
1416-
let v2 = v.into_shape((3, 4));
1417-
assert!(v2.is_ok());
1418-
assert_eq!(v, v2.unwrap());
1419-
1420-
let u = v.into_shape((3, 2, 2));
1421-
assert!(u.is_ok());
1422-
let u = u.unwrap();
1423-
println!("{:?}", u);
1424-
assert_eq!(u.shape(), &[3, 2, 2]);
1425-
let s = u.into_shape((4, 3)).unwrap();
1426-
println!("{:?}", s);
1427-
assert_eq!(s.shape(), &[4, 3]);
1428-
assert_eq!(s, aview2(&[[0, 4, 8], [1, 5, 9], [2, 6, 10], [3, 7, 11]]));
1429-
}
1430-
14311373
#[test]
14321374
#[allow(clippy::cognitive_complexity)]
14331375
fn insert_axis() {

0 commit comments

Comments
 (0)