Skip to content

Commit a63257e

Browse files
authored
Merge pull request #6 from sile/remove-ordered-float
Remove `ordered-float` dependency and replace it with `total_cmp` method for float comparisons
2 parents b55f278 + cab4a6d commit a63257e

3 files changed

Lines changed: 4 additions & 7 deletions

File tree

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ categories = ["science"]
1111
license = "MIT"
1212

1313
[dependencies]
14-
ordered-float = "2"
1514
rand = "0.8"
1615
rand_distr = "0.4"
1716
statrs = "0.15"

src/density_estimation/parzen.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::density_estimation::{BuildDensityEstimator, DensityEstimator};
22
use crate::Range;
3-
use ordered_float::OrderedFloat;
43
use rand::distributions::Distribution;
54
use rand::seq::SliceRandom;
65
use rand::Rng;
@@ -62,7 +61,7 @@ impl BuildDensityEstimator for ParzenEstimatorBuilder {
6261
stddev: f64::NAN,
6362
})
6463
.collect::<Vec<_>>();
65-
xs.sort_by_key(|x| OrderedFloat(x.mean));
64+
xs.sort_by(|x, y| x.mean.total_cmp(&y.mean));
6665

6766
self.setup_stddev(&mut xs, range);
6867

@@ -126,7 +125,7 @@ impl DensityEstimator for ParzenEstimator {
126125
fn logsumexp(xs: &[f64]) -> f64 {
127126
let max_x = xs
128127
.iter()
129-
.max_by_key(|&&x| OrderedFloat(x))
128+
.max_by(|x, y| x.total_cmp(y))
130129
.expect("unreachable");
131130
xs.iter().map(|&x| (x - max_x).exp()).sum::<f64>().ln() + max_x
132131
}

src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ use crate::density_estimation::{BuildDensityEstimator, DefaultEstimatorBuilder,
4545
#[cfg(doc)]
4646
use crate::density_estimation::{HistogramEstimator, ParzenEstimator};
4747
use crate::range::{Range, RangeError};
48-
use ordered_float::OrderedFloat;
4948
use rand::distributions::Distribution;
5049
use rand::Rng;
5150
use std::num::NonZeroUsize;
@@ -171,7 +170,7 @@ impl<T: BuildDensityEstimator> TpeOptimizer<T> {
171170
/// to reduce bias due to too few samples.
172171
pub fn ask<R: Rng + ?Sized>(&mut self, rng: &mut R) -> Result<f64, T::Error> {
173172
if !self.is_sorted {
174-
self.trials.sort_by_key(|t| OrderedFloat(t.value));
173+
self.trials.sort_by(|x, y| x.value.total_cmp(&y.value));
175174
self.is_sorted = true;
176175
}
177176

@@ -196,7 +195,7 @@ impl<T: BuildDensityEstimator> TpeOptimizer<T> {
196195
let ei = superior_log_likelihood - inferior_log_likelihood;
197196
(ei, candidate)
198197
})
199-
.max_by_key(|(ei, _)| OrderedFloat(*ei))
198+
.max_by(|(ei0, _), (ei1, _)| ei0.total_cmp(ei1))
200199
.map(|(_, param)| param)
201200
.expect("unreachable");
202201
Ok(param)

0 commit comments

Comments
 (0)