More clippy fixes.

This commit is contained in:
2019-01-02 22:24:42 +01:00
parent 8271464fe6
commit 7ad47d330f
3 changed files with 36 additions and 33 deletions

View File

@@ -232,8 +232,8 @@ impl SumFactor {
&self, &self,
variable_arena: &mut VariableArena, variable_arena: &mut VariableArena,
variable: VariableId, variable: VariableId,
y: Vec<Gaussian>, y: &[Gaussian],
fy: Vec<Gaussian>, fy: &[Gaussian],
a: &[f64], a: &[f64],
) { ) {
let (sum_pi, sum_tau) = let (sum_pi, sum_tau) =
@@ -263,7 +263,7 @@ impl SumFactor {
} }
pub fn update_sum(&self, variable_arena: &mut VariableArena) { pub fn update_sum(&self, variable_arena: &mut VariableArena) {
let (y, fy) = self let (y, fy): (Vec<_>, Vec<_>) = self
.terms .terms
.iter() .iter()
.map(|term| { .map(|term| {
@@ -273,7 +273,7 @@ impl SumFactor {
}) })
.unzip(); .unzip();
self.internal_update(variable_arena, self.sum, y, fy, &self.coeffs); self.internal_update(variable_arena, self.sum, &y, &fy, &self.coeffs);
} }
pub fn update_term(&self, variable_arena: &mut VariableArena, index: usize) { pub fn update_term(&self, variable_arena: &mut VariableArena, index: usize) {
@@ -293,7 +293,7 @@ impl SumFactor {
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let (y, fy) = self let (y, fy): (Vec<_>, Vec<_>) = self
.terms .terms
.iter() .iter()
.enumerate() .enumerate()
@@ -305,7 +305,7 @@ impl SumFactor {
}) })
.unzip(); .unzip();
self.internal_update(variable_arena, idx_term, y, fy, &a); self.internal_update(variable_arena, idx_term, &y, &fy, &a);
} }
pub fn update_all_terms(&self, variable_arena: &mut VariableArena) { pub fn update_all_terms(&self, variable_arena: &mut VariableArena) {

View File

@@ -1,3 +1,5 @@
#![allow(clippy::unreadable_literal, clippy::excessive_precision)]
mod factor_graph; mod factor_graph;
mod gaussian; mod gaussian;
mod math; mod math;
@@ -421,7 +423,7 @@ mod tests {
assert_relative_eq!( assert_relative_eq!(
ts.quality(&[&[alice], &[bob]]), ts.quality(&[&[alice], &[bob]]),
0.4472135954999579, 0.447_213_595_499_957_9,
epsilon = EPSILON epsilon = EPSILON
); );
} }

View File

@@ -1,5 +1,3 @@
#![allow(clippy::unreadable_literal, clippy::excessive_precision)]
use statrs::distribution::{Continuous, Normal, Univariate}; use statrs::distribution::{Continuous, Normal, Univariate};
const S2PI: f64 = 2.50662827463100050242_e0; const S2PI: f64 = 2.50662827463100050242_e0;
@@ -70,44 +68,33 @@ const Q2: [f64; 8] = [
]; ];
fn polevl(x: f64, coef: &[f64], n: usize) -> f64 { fn polevl(x: f64, coef: &[f64], n: usize) -> f64 {
let mut ans = coef[0]; coef.iter()
.skip(1)
for i in 1..n + 1 { .take(n)
ans = ans * x + coef[i]; .fold(coef[0], |ans, coef| ans * x + coef)
}
ans
} }
fn p1evl(x: f64, coef: &[f64], n: usize) -> f64 { fn p1evl(x: f64, coef: &[f64], n: usize) -> f64 {
let mut ans = x + coef[0]; coef.iter().take(n).fold(1.0, |ans, coef| ans * x + coef)
for i in 1..n {
ans = ans * x + coef[i];
} }
ans fn ndtri(mut y0: f64) -> f64 {
} let code = if y0 > (1.0 - 0.13533528323661269189) {
y0 = 1.0 - y0;
fn ndtri(y0: f64) -> f64 {
let mut y = y0;
let code = if y > (1.0 - 0.13533528323661269189) {
y = 1.0 - y;
false false
} else { } else {
true true
}; };
if y > 0.13533528323661269189 { if y0 > 0.13533528323661269189 {
y -= 0.5; y0 -= 0.5;
let y2 = y * y; let y1 = y0 * y0;
return (y + y * (y2 * polevl(y2, &P0, 4) / p1evl(y2, &Q0, 8))) * S2PI; return (y0 + y0 * (y1 * polevl(y1, &P0, 4) / p1evl(y1, &Q0, 8))) * S2PI;
} }
let x = (-2.0 * y.ln()).sqrt(); let x = (-2.0 * y0.ln()).sqrt();
let z = 1.0 / x; let z = 1.0 / x;
let x0 = x - x.ln() / x; let x0 = x - x.ln() / x;
@@ -146,4 +133,18 @@ mod tests {
fn test_cdf() { fn test_cdf() {
assert_relative_eq!(cdf(0.5), 0.6914624612740131); assert_relative_eq!(cdf(0.5), 0.6914624612740131);
} }
#[test]
fn test_polevl() {
assert_relative_eq!(polevl(1.0, &P0, 4), -5.946465329663694);
assert_relative_eq!(polevl(1.0, &P1, 8), 153.51931825976564);
assert_relative_eq!(polevl(1.0, &P2, 8), 15.63898396843608);
}
#[test]
fn test_p1evl() {
assert_relative_eq!(p1evl(1.0, &Q0, 8), 1.4736150619750965);
assert_relative_eq!(p1evl(1.0, &Q1, 8), 120.85394687227081);
assert_relative_eq!(p1evl(1.0, &Q2, 8), 12.311115335036716);
}
} }