File tree Expand file tree Collapse file tree 2 files changed +18
-8
lines changed Expand file tree Collapse file tree 2 files changed +18
-8
lines changed Original file line number Diff line number Diff line change @@ -14,4 +14,5 @@ quickcheck = "0.7"
14
14
ndarray-rand = " 0.8"
15
15
16
16
[patch .crates-io ]
17
+ ndarray = { git = " https://github.com/jturner314/ndarray.git" , rev = " 9c361c4e331ccc402dad0bbf115de00a1d561d3c" }
17
18
noisy_float = { git = " https://github.com/SergiusIW/noisy_float-rs.git" , rev = " c33a94803987475bbd205c9ff5a697af533f9a17" }
Original file line number Diff line number Diff line change 39
39
/// ```
40
40
/// and similarly for ̅y.
41
41
///
42
- /// **Panics** if `ddof` is greater than or equal to the number of
43
- /// observations, if `M` is emtpy or if the type cast of `n_observations`
44
- /// from `usize` to `A` fails.
42
+ /// **Panics** if `ddof` is greater than or equal to the number of
43
+ /// observations, if the number of observations is zero and division by
44
+ /// zero panics for type `A`, or if the type cast of `n_observations` from
45
+ /// `usize` to `A` fails.
45
46
///
46
47
/// # Example
47
48
///
@@ -133,11 +134,19 @@ mod tests {
133
134
}
134
135
135
136
#[ test]
136
- #[ should_panic]
137
- fn test_empty_matrix ( ) {
138
- let a: Array2 < f32 > = array ! [ [ ] , [ ] ] ;
139
- // Negative ddof (-1 < 0) to avoid invalid-ddof panic
140
- a. cov ( -1. ) ;
137
+ fn test_covariance_zero_variables ( ) {
138
+ let a = Array2 :: < f32 > :: zeros ( ( 0 , 2 ) ) ;
139
+ let cov = a. cov ( 1. ) ;
140
+ assert_eq ! ( cov. shape( ) , & [ 0 , 0 ] ) ;
141
+ }
142
+
143
+ #[ test]
144
+ fn test_covariance_zero_observations ( ) {
145
+ let a = Array2 :: < f32 > :: zeros ( ( 2 , 0 ) ) ;
146
+ // Negative ddof (-1 < 0) to avoid invalid-ddof panic
147
+ let cov = a. cov ( -1. ) ;
148
+ assert_eq ! ( cov. shape( ) , & [ 2 , 2 ] ) ;
149
+ cov. mapv ( |x| x. is_nan ( ) ) ;
141
150
}
142
151
143
152
#[ test]
You can’t perform that action at this time.
0 commit comments