diff --git a/tests/array.rs b/tests/array.rs index e3922ea8d..23c863789 100644 --- a/tests/array.rs +++ b/tests/array.rs @@ -9,10 +9,10 @@ use approx::assert_relative_eq; use defmac::defmac; -use itertools::{zip, Itertools}; +use itertools::Itertools; +use ndarray::indices; use ndarray::prelude::*; use ndarray::{arr3, rcarr2}; -use ndarray::indices; use ndarray::{Slice, SliceInfo, SliceInfoElem}; use num_complex::Complex; use std::convert::TryFrom; @@ -499,13 +499,13 @@ fn test_index() { *elt = i; } - for ((i, j), a) in zip(indices((2, 3)), &A) { + for ((i, j), a) in indices((2, 3)).into_iter().zip(&A) { assert_eq!(*a, A[[i, j]]); } let vi = A.slice(s![1.., ..;2]); let mut it = vi.iter(); - for ((i, j), x) in zip(indices((1, 2)), &mut it) { + for ((i, j), x) in indices((1, 2)).into_iter().zip(&mut it) { assert_eq!(*x, vi[[i, j]]); } assert!(it.next().is_none()); @@ -2071,9 +2071,8 @@ fn test_view_from_shape_ptr() { #[test] fn test_view_from_shape_ptr_deny_neg_strides() { let data = [0, 1, 2, 3, 4, 5]; - let _view = unsafe { - ArrayView::from_shape_ptr((2, 3).strides((-3isize as usize, 1)), data.as_ptr()) - }; + let _view = + unsafe { ArrayView::from_shape_ptr((2, 3).strides((-3isize as usize, 1)), data.as_ptr()) }; } #[should_panic(expected = "Unsupported")] @@ -2466,74 +2465,48 @@ mod array_cow_tests { #[test] fn test_remove_index() { - let mut a = arr2(&[[1, 2, 3], - [4, 5, 6], - [7, 8, 9], - [10,11,12]]); + let mut a = arr2(&[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]); a.remove_index(Axis(0), 1); a.remove_index(Axis(1), 2); assert_eq!(a.shape(), &[3, 2]); - assert_eq!(a, - array![[1, 2], - [7, 8], - [10,11]]); - - let mut a = arr2(&[[1, 2, 3], - [4, 5, 6], - [7, 8, 9], - [10,11,12]]); + assert_eq!(a, array![[1, 2], [7, 8], [10, 11]]); + + let mut a = arr2(&[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]); a.invert_axis(Axis(0)); a.remove_index(Axis(0), 1); a.remove_index(Axis(1), 2); assert_eq!(a.shape(), &[3, 2]); - assert_eq!(a, - array![[10,11], - [4, 5], - [1, 2]]); + assert_eq!(a, array![[10, 11], [4, 5], [1, 2]]); a.remove_index(Axis(1), 1); assert_eq!(a.shape(), &[3, 1]); - assert_eq!(a, - array![[10], - [4], - [1]]); + assert_eq!(a, array![[10], [4], [1]]); a.remove_index(Axis(1), 0); assert_eq!(a.shape(), &[3, 0]); - assert_eq!(a, - array![[], - [], - []]); + assert_eq!(a, array![[], [], []]); } -#[should_panic(expected="must be less")] +#[should_panic(expected = "must be less")] #[test] fn test_remove_index_oob1() { - let mut a = arr2(&[[1, 2, 3], - [4, 5, 6], - [7, 8, 9], - [10,11,12]]); + let mut a = arr2(&[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]); a.remove_index(Axis(0), 4); } -#[should_panic(expected="must be less")] +#[should_panic(expected = "must be less")] #[test] fn test_remove_index_oob2() { let mut a = array![[10], [4], [1]]; a.remove_index(Axis(1), 0); assert_eq!(a.shape(), &[3, 0]); - assert_eq!(a, - array![[], - [], - []]); + assert_eq!(a, array![[], [], []]); a.remove_index(Axis(0), 1); // ok - assert_eq!(a, - array![[], - []]); + assert_eq!(a, array![[], []]); a.remove_index(Axis(1), 0); // oob } -#[should_panic(expected="index out of bounds")] +#[should_panic(expected = "index out of bounds")] #[test] fn test_remove_index_oob3() { let mut a = array![[10], [4], [1]]; @@ -2552,14 +2525,10 @@ fn test_split_complex_view() { #[test] fn test_split_complex_view_roundtrip() { - let a_re = Array3::from_shape_fn((3,1,5), |(i, j, _k)| { - i * j - }); - let a_im = Array3::from_shape_fn((3,1,5), |(_i, _j, k)| { - 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 a_re = Array3::from_shape_fn((3, 1, 5), |(i, j, _k)| i * j); + let a_im = Array3::from_shape_fn((3, 1, 5), |(_i, _j, k)| 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_complex(); assert_eq!(a_re, re); @@ -2590,18 +2559,18 @@ fn test_split_complex_zerod() { #[test] fn test_split_complex_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 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_complex(); - assert_eq!(re.get((3,2,4)).unwrap(), &11); - assert_eq!(im.get((3,2,4)).unwrap(), &4); + assert_eq!(re.get((3, 2, 4)).unwrap(), &11); + assert_eq!(im.get((3, 2, 4)).unwrap(), &4); } #[test] fn test_split_complex_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)); + 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_complex(); assert_eq!(cmplx.re, a.mapv(|z| z.re));