Skip to content

Commit

Permalink
fix: clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
troublescooter committed May 16, 2021
1 parent 9d6ca0e commit 0b59c4e
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/distribution/beta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl Continuous<f64, f64> for Beta {
///
/// where `α` is shapeA, `β` is shapeB, and `Γ` is the gamma function
fn pdf(&self, x: f64) -> f64 {
if x < 0.0 || x > 1.0 {
if !(0.0..=1.0).contains(&x) {
0.0
} else if self.shape_a.is_infinite() {
if ulps_eq!(x, 1.0) {
Expand Down Expand Up @@ -329,7 +329,7 @@ impl Continuous<f64, f64> for Beta {
///
/// where `α` is shapeA, `β` is shapeB, and `Γ` is the gamma function
fn ln_pdf(&self, x: f64) -> f64 {
if x < 0.0 || x > 1.0 {
if !(0.0..=1.0).contains(&x) {
-INF
} else if self.shape_a.is_infinite() {
if ulps_eq!(x, 1.0) {
Expand Down
2 changes: 1 addition & 1 deletion src/distribution/categorical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ pub fn prob_mass_to_cdf(prob_mass: &[f64]) -> Vec<f64> {
fn binary_index(search: &[f64], val: f64) -> usize {
use std::cmp;

let mut low = 0 as isize;
let mut low = 0_isize;
let mut high = search.len() as isize - 1;
while low <= high {
let mid = low + ((high - low) / 2);
Expand Down
2 changes: 1 addition & 1 deletion src/distribution/chi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl Distribution<f64> for Chi {
/// where `k` is degrees of freedom and `Γ` is the gamma function
fn mean(&self) -> Option<f64> {
if self.freedom.is_infinite() {
return None;
None
} else if self.freedom > 300.0 {
// Large n approximation based on the Stirling series approximation to the Gamma function
// This avoids call the Gamma function with large arguments and returning NaN
Expand Down
2 changes: 1 addition & 1 deletion src/distribution/negative_binomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl NegativeBinomial {
if p.is_nan() || p < 0.0 || p > 1.0 || r.is_nan() || r < 0.0 {
Err(StatsError::BadParams)
} else {
Ok(NegativeBinomial { p, r })
Ok(NegativeBinomial { r, p })
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/distribution/normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl ContinuousCDF<f64, f64> for Normal {
/// where `μ` is the mean, `σ` is the standard deviation and `erfc_inv` is
/// the inverse of the complementary error function
fn inverse_cdf(&self, x: f64) -> f64 {
if x < 0.0 || x > 1.0 {
if !(0.0..=1.0).contains(&x) {
panic!("x must be in [0, 1]");
} else {
self.mean - (self.std_dev * f64::consts::SQRT_2 * erf::erfc_inv(2.0 * x))
Expand Down
2 changes: 1 addition & 1 deletion src/distribution/students_t.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl ContinuousCDF<f64, f64> for StudentsT {
/// Student's T-distribution at `x`
fn inverse_cdf(&self, x: f64) -> f64 {
// first calculate inverse_cdf for normal Student's T
assert!(x >= 0.0 && x <= 1.0);
assert!((0.0..=1.0).contains(&x));
let x = 2. * x.min(1. - x);
let a = 0.5 * self.freedom;
let b = 0.5;
Expand Down
4 changes: 2 additions & 2 deletions src/function/beta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub fn checked_beta_reg(a: f64, b: f64, x: f64) -> Result<f64> {
Err(StatsError::ArgMustBePositive("a"))
} else if b <= 0.0 {
Err(StatsError::ArgMustBePositive("b"))
} else if x < 0.0 || x > 1.0 {
} else if !(0.0..=1.0).contains(&x) {
Err(StatsError::ArgIntervalIncl("x", 0.0, 1.0))
} else {
let bt = if is_zero(x) || ulps_eq!(x, 1.0) {
Expand Down Expand Up @@ -275,7 +275,7 @@ pub fn inv_beta_reg(mut a: f64, mut b: f64, mut x: f64) -> f64 {
const SAE: i32 = -30;
const FPU: f64 = 1e-30; // 10^SAE

debug_assert!(x >= 0.0 && x <= 1.0 && a > 0.0 && b > 0.0);
debug_assert!((0.0..=1.0).contains(&x) && a > 0.0 && b > 0.0);

if x == 0.0 {
return 0.0;
Expand Down
2 changes: 1 addition & 1 deletion src/function/logistic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn logit(p: f64) -> f64 {
///
/// If `p < 0.0` or `p > 1.0`
pub fn checked_logit(p: f64) -> Result<f64> {
if p < 0.0 || p > 1.0 {
if !(0.0..=1.0).contains(&p) {
Err(StatsError::ArgIntervalIncl("p", 0.0, 1.0))
} else {
Ok((p / (1.0 - p)).ln())
Expand Down
2 changes: 1 addition & 1 deletion src/statistics/slice_statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl<D: AsMut<[f64]> + AsRef<[f64]>> OrderStatistics<f64> for Data<D> {
}

fn quantile(&mut self, tau: f64) -> f64 {
if tau < 0.0 || tau > 1.0 || self.is_empty() {
if !(0.0..=1.0).contains(&tau) || self.is_empty() {
return f64::NAN;
}

Expand Down

0 comments on commit 0b59c4e

Please sign in to comment.