1
+ #[ macro_use( array) ]
1
2
extern crate ndarray;
2
3
extern crate ndarray_stats;
3
4
4
5
use ndarray:: prelude:: * ;
5
6
use ndarray_stats:: {
6
- interpolate:: { Linear , Lower } ,
7
+ interpolate:: { Higher , Linear , Lower , Midpoint , Nearest } ,
7
8
PercentileExt ,
8
9
} ;
9
10
11
+ #[ test]
12
+ fn test_min ( ) {
13
+ let a = array ! [ [ 1 , 5 , 3 ] , [ 2 , 0 , 6 ] ] ;
14
+ assert_eq ! ( a. min( ) , & 0 ) ;
15
+ }
16
+
17
+ #[ test]
18
+ fn test_min_partialord ( ) {
19
+ let a = array ! [ [ 1. , 5. , 3. ] , [ 2. , 0. , 6. ] ] ;
20
+ assert_eq ! ( a. min_partialord( ) , Some ( & 0. ) ) ;
21
+
22
+ let a = array ! [ [ 1. , 5. , 3. ] , [ 2. , :: std:: f64 :: NAN , 6. ] ] ;
23
+ assert_eq ! ( a. min_partialord( ) , None ) ;
24
+ }
25
+
26
+ #[ test]
27
+ fn test_min_skipnan ( ) {
28
+ let a = array ! [ [ 1. , 5. , 3. ] , [ 2. , 0. , 6. ] ] ;
29
+ assert_eq ! ( a. min_skipnan( ) , & 0. ) ;
30
+
31
+ let a = array ! [ [ 1. , 5. , 3. ] , [ 2. , :: std:: f64 :: NAN , 6. ] ] ;
32
+ assert_eq ! ( a. min_skipnan( ) , & 1. ) ;
33
+ }
34
+
35
+ #[ test]
36
+ fn test_min_skipnan_all_nan ( ) {
37
+ let a = arr2 ( & [ [ :: std:: f64:: NAN ; 3 ] ; 2 ] ) ;
38
+ assert ! ( a. min_skipnan( ) . is_nan( ) ) ;
39
+ }
40
+
41
+ #[ test]
42
+ fn test_max ( ) {
43
+ let a = array ! [ [ 1 , 5 , 7 ] , [ 2 , 0 , 6 ] ] ;
44
+ assert_eq ! ( a. max( ) , & 7 ) ;
45
+ }
46
+
47
+ #[ test]
48
+ fn test_max_partialord ( ) {
49
+ let a = array ! [ [ 1. , 5. , 7. ] , [ 2. , 0. , 6. ] ] ;
50
+ assert_eq ! ( a. max_partialord( ) , Some ( & 7. ) ) ;
51
+
52
+ let a = array ! [ [ 1. , 5. , 7. ] , [ 2. , :: std:: f64 :: NAN , 6. ] ] ;
53
+ assert_eq ! ( a. max_partialord( ) , None ) ;
54
+ }
55
+
56
+ #[ test]
57
+ fn test_max_skipnan ( ) {
58
+ let a = array ! [ [ 1. , 5. , 7. ] , [ 2. , 0. , 6. ] ] ;
59
+ assert_eq ! ( a. max_skipnan( ) , & 7. ) ;
60
+
61
+ let a = array ! [ [ 1. , 5. , 7. ] , [ 2. , :: std:: f64 :: NAN , 6. ] ] ;
62
+ assert_eq ! ( a. max_skipnan( ) , & 7. ) ;
63
+ }
64
+
65
+ #[ test]
66
+ fn test_max_skipnan_all_nan ( ) {
67
+ let a = arr2 ( & [ [ :: std:: f64:: NAN ; 3 ] ; 2 ] ) ;
68
+ assert ! ( a. max_skipnan( ) . is_nan( ) ) ;
69
+ }
70
+
10
71
#[ test]
11
72
fn test_percentile_axis_mut_with_odd_axis_length ( ) {
12
73
let mut a = arr2 ( & [ [ 1 , 3 , 2 , 10 ] , [ 2 , 4 , 3 , 11 ] , [ 3 , 5 , 6 , 12 ] ] ) ;
@@ -35,9 +96,36 @@ fn test_percentile_axis_mut_to_get_maximum() {
35
96
assert ! ( q == arr0( 22 ) ) ;
36
97
}
37
98
99
+ #[ test]
100
+ fn test_percentile_axis_skipnan_mut_higher_opt_i32 ( ) {
101
+ let mut a = arr2 ( & [ [ Some ( 4 ) , Some ( 2 ) , None , Some ( 1 ) , Some ( 5 ) ] , [ None ; 5 ] ] ) ;
102
+ let q = a. percentile_axis_skipnan_mut :: < Higher > ( Axis ( 1 ) , 0.6 ) ;
103
+ assert_eq ! ( q. shape( ) , & [ 2 ] ) ;
104
+ assert_eq ! ( q[ 0 ] , Some ( 4 ) ) ;
105
+ assert ! ( q[ 1 ] . is_none( ) ) ;
106
+ }
107
+
108
+ #[ test]
109
+ fn test_percentile_axis_skipnan_mut_nearest_opt_i32 ( ) {
110
+ let mut a = arr2 ( & [ [ Some ( 4 ) , Some ( 2 ) , None , Some ( 1 ) , Some ( 5 ) ] , [ None ; 5 ] ] ) ;
111
+ let q = a. percentile_axis_skipnan_mut :: < Nearest > ( Axis ( 1 ) , 0.6 ) ;
112
+ assert_eq ! ( q. shape( ) , & [ 2 ] ) ;
113
+ assert_eq ! ( q[ 0 ] , Some ( 4 ) ) ;
114
+ assert ! ( q[ 1 ] . is_none( ) ) ;
115
+ }
116
+
117
+ #[ test]
118
+ fn test_percentile_axis_skipnan_mut_midpoint_opt_i32 ( ) {
119
+ let mut a = arr2 ( & [ [ Some ( 4 ) , Some ( 2 ) , None , Some ( 1 ) , Some ( 5 ) ] , [ None ; 5 ] ] ) ;
120
+ let q = a. percentile_axis_skipnan_mut :: < Midpoint > ( Axis ( 1 ) , 0.6 ) ;
121
+ assert_eq ! ( q. shape( ) , & [ 2 ] ) ;
122
+ assert_eq ! ( q[ 0 ] , Some ( 3 ) ) ;
123
+ assert ! ( q[ 1 ] . is_none( ) ) ;
124
+ }
125
+
38
126
// TODO: See https://github.com/SergiusIW/noisy_float-rs/pull/19
39
127
// #[test]
40
- // fn test_percentile_axis_skipnan_mut_f64 () {
128
+ // fn test_percentile_axis_skipnan_mut_linear_f64 () {
41
129
// let mut a = arr2(&[[1., 2., ::std::f64::NAN, 3.], [::std::f64::NAN; 4]]);
42
130
// let q = a.percentile_axis_skipnan_mut::<Linear>(Axis(1), 0.75);
43
131
// assert_eq!(q.shape(), &[2]);
@@ -46,8 +134,8 @@ fn test_percentile_axis_mut_to_get_maximum() {
46
134
// }
47
135
48
136
#[ test]
49
- fn test_percentile_axis_skipnan_mut_opt_i32 ( ) {
50
- let mut a = arr2 ( & [ [ Some ( 1 ) , Some ( 2 ) , None , Some ( 4 ) ] , [ None ; 4 ] ] ) ;
137
+ fn test_percentile_axis_skipnan_mut_linear_opt_i32 ( ) {
138
+ let mut a = arr2 ( & [ [ Some ( 2 ) , Some ( 4 ) , None , Some ( 1 ) ] , [ None ; 4 ] ] ) ;
51
139
let q = a. percentile_axis_skipnan_mut :: < Linear > ( Axis ( 1 ) , 0.75 ) ;
52
140
assert_eq ! ( q. shape( ) , & [ 2 ] ) ;
53
141
assert_eq ! ( q[ 0 ] , Some ( 3 ) ) ;
0 commit comments