From e7a995ebea5a8c45947aa60317930771335e33ca Mon Sep 17 00:00:00 2001 From: Orion Yeung <11580988+orionyeung001@users.noreply.github.com> Date: Mon, 2 Dec 2024 13:28:41 -0600 Subject: [PATCH] chore: simple lints also derives Eq for DiscreteUniform distribution --- src/distribution/discrete_uniform.rs | 2 +- src/distribution/internal.rs | 10 +++------- src/distribution/multivariate_normal.rs | 1 - 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/distribution/discrete_uniform.rs b/src/distribution/discrete_uniform.rs index a9760808..b610b735 100644 --- a/src/distribution/discrete_uniform.rs +++ b/src/distribution/discrete_uniform.rs @@ -15,7 +15,7 @@ use crate::statistics::*; /// assert_eq!(n.mean().unwrap(), 2.5); /// assert_eq!(n.pmf(3), 1.0 / 6.0); /// ``` -#[derive(Copy, Clone, PartialEq, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Debug)] pub struct DiscreteUniform { min: i64, max: i64, diff --git a/src/distribution/internal.rs b/src/distribution/internal.rs index 9075669e..13435d44 100644 --- a/src/distribution/internal.rs +++ b/src/distribution/internal.rs @@ -24,15 +24,11 @@ pub fn integral_bisection_search( loop { let mid = (lb.clone() + ub.clone()) / two.clone(); if !(f(&lb)..=f(&ub)).contains(&f(&mid)) { - // if f found not monotone on the interval - return None; + return None; // f found not monotone on interval } else if f(&lb) == z { return Some(lb); - } else if f(&ub) == z { - return Some(ub); - } else if (lb.clone() + K::one()) == ub { - // no more elements to search - return Some(ub); + } else if f(&ub) == z || (lb.clone() + K::one()) == ub { + return Some(ub); // found or no more integers between } else if f(&mid) >= z { ub = mid; } else { diff --git a/src/distribution/multivariate_normal.rs b/src/distribution/multivariate_normal.rs index f1b7be70..29767385 100644 --- a/src/distribution/multivariate_normal.rs +++ b/src/distribution/multivariate_normal.rs @@ -255,7 +255,6 @@ where /// where `L` is the Cholesky decomposition of the covariance matrix, /// `Z` is a vector of normally distributed random variables, and /// `μ` is the mean vector - fn sample(&self, rng: &mut R) -> OVector { let d = crate::distribution::Normal::new(0., 1.).unwrap(); let z = OVector::from_distribution_generic(self.mu.shape_generic().0, Const::<1>, &d, rng);