From fd85c0f75e03f170b97fcedba26317e0832d087e Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 30 Sep 2022 09:17:51 +0300 Subject: Handle "divide-by-zero" Sort NAN as less than everything else --- src/correlations.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/correlations.rs') diff --git a/src/correlations.rs b/src/correlations.rs index 6b38ffe..7c79c7e 100644 --- a/src/correlations.rs +++ b/src/correlations.rs @@ -1,3 +1,5 @@ +use std::cmp::Ordering; + use crate::parser::parse_rows_with_names; use crate::reader::BufferReader; use crate::sorter::sort_write_to_file; @@ -171,7 +173,9 @@ impl<'a> Compute<'a> { //naive implementation try extern sorting could save 3 seconds - corr_results.sort_by(|a, b| b.1.abs().partial_cmp(&a.1.abs()).unwrap()); + corr_results.sort_by(|a, b| { + b.1.abs().partial_cmp(&a.1.abs()).unwrap_or_else(|| { + Ordering::Less})}); sort_write_to_file(String::from(self.output_file), corr_results) } -- cgit 1.4.1