Add test that fails on negative stride
@@ -2516,13 +2516,13 @@ fn test_split_re_im_view() {
#[test]
fn test_split_re_im_view_roundtrip() {
- let a_re = Array3::from_shape_fn((3,4,5), |(i, j, _k)| {
+ let a_re = Array3::from_shape_fn((3,1,5), |(i, j, _k)| {
i * j
});
- let a_im = Array3::from_shape_fn((3,4,5), |(_i, _j, k)| {
+ let a_im = Array3::from_shape_fn((3,1,5), |(_i, _j, k)| {
k
});
- let a = Array3::from_shape_fn((3,4,5), |(i,j,k)| {
+ let a = Array3::from_shape_fn((3,1,5), |(i,j,k)| {
Complex::new(a_re[[i,j,k]], a_im[[i,j,k]])
});
let Complex { re, im } = a.view().split_re_im();
@@ -2540,3 +2540,34 @@ fn test_split_re_im_view_mut() {
assert_eq!(im.sum(), 0);
assert_eq!(a, eye_complex);
}
+
+#[test]
+fn test_split_re_im_zerod() {
+ let mut a = Array0::from_elem((), Complex::new(42, 32));
+ let Complex { re, im } = a.view().split_re_im();
+ assert_eq!(re.get(()), Some(&42));
+ assert_eq!(im.get(()), Some(&32));
+ let cmplx = a.view_mut().split_re_im();
+ cmplx.re.assign_to(cmplx.im);
+ assert_eq!(a.get(()).unwrap().im, 42);
+}
+
+#[test]
+fn test_split_re_im_permuted() {
+ let a = Array3::from_shape_fn((3, 4, 5), |(i, j, k)| {
+ Complex::new(i * k + j, k)
+ });
+ let permuted = a.view().permuted_axes([1,0,2]);
+ let Complex { re, im } = permuted.split_re_im();
+ assert_eq!(re.get((3,2,4)).unwrap(), &11);
+ assert_eq!(im.get((3,2,4)).unwrap(), &4);
+}
+
+#[test]
+fn test_split_re_im_invert_axis() {
+ let mut a = Array::from_shape_fn((2, 3, 2), |(i, j, k)| Complex::new(i as f64 + j as f64, i as f64 + k as f64));
+ a.invert_axis(Axis(1));
+ let cmplx = a.view().split_re_im();
+ assert_eq!(cmplx.re, a.mapv(|z| z.re));
+ assert_eq!(cmplx.im, a.mapv(|z| z.im));
+}
