Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ quickcheck = "0.7"
ndarray-rand = "0.8"

[patch.crates-io]
ndarray = { git = "https://github.com/jturner314/ndarray.git", branch = "master" }
noisy_float = { git = "https://github.com/SergiusIW/noisy_float-rs.git", rev = "c33a94803987475bbd205c9ff5a697af533f9a17" }
33 changes: 25 additions & 8 deletions src/correlation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ where
/// ```
/// and similarly for ̅y.
///
/// **Panics** if `ddof` is greater than or equal to the number of
/// observations, if `M` is emtpy or if the type cast of `n_observations`
/// from `usize` to `A` fails.
/// **Panics** if `ddof` is greater than or equal to the number of
/// observations, if the number of observations is zero and division by
/// zero panics for type `A`, or if the type cast of `n_observations` from
/// `usize` to `A` fails.
///
/// # Example
///
Expand Down Expand Up @@ -133,11 +134,27 @@ mod tests {
}

#[test]
#[should_panic]
fn test_empty_matrix() {
let a: Array2<f32> = array![[], []];
// Negative ddof (-1 < 0) to avoid invalid-ddof panic
a.cov(-1.);
fn test_covariance_zero_variables() {
let a = Array2::<f32>::zeros((0, 2));
let cov = a.cov(1.);
assert_eq!(cov.shape(), &[0, 0]);
}

#[test]
fn test_covariance_zero_observations() {
let a = Array2::<f32>::zeros((2, 0));
// Negative ddof (-1 < 0) to avoid invalid-ddof panic
let cov = a.cov(-1.);
assert_eq!(cov.shape(), &[2, 2]);
cov.mapv(|x| x.is_nan());
}

#[test]
fn test_covariance_zero_variables_zero_observations() {
let a = Array2::<f32>::zeros((0, 0));
// Negative ddof (-1 < 0) to avoid invalid-ddof panic
let cov = a.cov(-1.);
assert_eq!(cov.shape(), &[0, 0]);
}

#[test]
Expand Down