Skip to content

Commit 763e293

Browse files
Merge pull request #139 from vks/fix-doctests
Fix doctests
2 parents 8e51645 + 0b59c4e commit 763e293

File tree

11 files changed

+84
-71
lines changed

11 files changed

+84
-71
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
v0.14.0
2+
- upgrade `rand` dependency to `0.8`
3+
- fix inaccurate sampling of `Gamma`
4+
- Implemented Empirical distribution
5+
- Implemented Laplace distribution
6+
- Removed Checked* traits
7+
- Almost clippy-clean
8+
- Almost fully enabled rustfmt
9+
- Begin applying consistent numeric relative-accuracy targets with the approx crate
10+
- Introduce macro to generate testing boilerplate, yet not all tests use this yet
11+
- Moved to dynamic vectors in the MultivariateNormal distribution
12+
- Reduced a number of distribution-specific traits into the Distribution and DiscreteDistribution traits
13+
114
v0.13.0
215
- Implemented `MultivariateNormal` distribution (depends on `nalgebra 0.19`)
316
- Implemented `Dirac` distribution

src/distribution/beta.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl Continuous<f64, f64> for Beta {
291291
///
292292
/// where `α` is shapeA, `β` is shapeB, and `Γ` is the gamma function
293293
fn pdf(&self, x: f64) -> f64 {
294-
if x < 0.0 || x > 1.0 {
294+
if !(0.0..=1.0).contains(&x) {
295295
0.0
296296
} else if self.shape_a.is_infinite() {
297297
if ulps_eq!(x, 1.0) {
@@ -329,7 +329,7 @@ impl Continuous<f64, f64> for Beta {
329329
///
330330
/// where `α` is shapeA, `β` is shapeB, and `Γ` is the gamma function
331331
fn ln_pdf(&self, x: f64) -> f64 {
332-
if x < 0.0 || x > 1.0 {
332+
if !(0.0..=1.0).contains(&x) {
333333
-INF
334334
} else if self.shape_a.is_infinite() {
335335
if ulps_eq!(x, 1.0) {

src/distribution/categorical.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ pub fn prob_mass_to_cdf(prob_mass: &[f64]) -> Vec<f64> {
282282
fn binary_index(search: &[f64], val: f64) -> usize {
283283
use std::cmp;
284284

285-
let mut low = 0 as isize;
285+
let mut low = 0_isize;
286286
let mut high = search.len() as isize - 1;
287287
while low <= high {
288288
let mid = low + ((high - low) / 2);

src/distribution/chi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl Distribution<f64> for Chi {
145145
/// where `k` is degrees of freedom and `Γ` is the gamma function
146146
fn mean(&self) -> Option<f64> {
147147
if self.freedom.is_infinite() {
148-
return None;
148+
None
149149
} else if self.freedom > 300.0 {
150150
// Large n approximation based on the Stirling series approximation to the Gamma function
151151
// This avoids call the Gamma function with large arguments and returning NaN

src/distribution/negative_binomial.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl NegativeBinomial {
5151
if p.is_nan() || p < 0.0 || p > 1.0 || r.is_nan() || r < 0.0 {
5252
Err(StatsError::BadParams)
5353
} else {
54-
Ok(NegativeBinomial { p, r })
54+
Ok(NegativeBinomial { r, p })
5555
}
5656
}
5757

src/distribution/normal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl ContinuousCDF<f64, f64> for Normal {
9090
/// where `μ` is the mean, `σ` is the standard deviation and `erfc_inv` is
9191
/// the inverse of the complementary error function
9292
fn inverse_cdf(&self, x: f64) -> f64 {
93-
if x < 0.0 || x > 1.0 {
93+
if !(0.0..=1.0).contains(&x) {
9494
panic!("x must be in [0, 1]");
9595
} else {
9696
self.mean - (self.std_dev * f64::consts::SQRT_2 * erf::erfc_inv(2.0 * x))

src/distribution/students_t.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl ContinuousCDF<f64, f64> for StudentsT {
155155
/// Student's T-distribution at `x`
156156
fn inverse_cdf(&self, x: f64) -> f64 {
157157
// first calculate inverse_cdf for normal Student's T
158-
assert!(x >= 0.0 && x <= 1.0);
158+
assert!((0.0..=1.0).contains(&x));
159159
let x = 2. * x.min(1. - x);
160160
let a = 0.5 * self.freedom;
161161
let b = 0.5;

src/function/beta.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub fn checked_beta_reg(a: f64, b: f64, x: f64) -> Result<f64> {
115115
Err(StatsError::ArgMustBePositive("a"))
116116
} else if b <= 0.0 {
117117
Err(StatsError::ArgMustBePositive("b"))
118-
} else if x < 0.0 || x > 1.0 {
118+
} else if !(0.0..=1.0).contains(&x) {
119119
Err(StatsError::ArgIntervalIncl("x", 0.0, 1.0))
120120
} else {
121121
let bt = if is_zero(x) || ulps_eq!(x, 1.0) {
@@ -275,7 +275,7 @@ pub fn inv_beta_reg(mut a: f64, mut b: f64, mut x: f64) -> f64 {
275275
const SAE: i32 = -30;
276276
const FPU: f64 = 1e-30; // 10^SAE
277277

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

280280
if x == 0.0 {
281281
return 0.0;

src/function/logistic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn logit(p: f64) -> f64 {
2424
///
2525
/// If `p < 0.0` or `p > 1.0`
2626
pub fn checked_logit(p: f64) -> Result<f64> {
27-
if p < 0.0 || p > 1.0 {
27+
if !(0.0..=1.0).contains(&p) {
2828
Err(StatsError::ArgIntervalIncl("p", 0.0, 1.0))
2929
} else {
3030
Ok((p / (1.0 - p)).ln())

src/statistics/slice_statistics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl<D: AsMut<[f64]> + AsRef<[f64]>> OrderStatistics<f64> for Data<D> {
129129
}
130130

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

0 commit comments

Comments
 (0)