From 8271464fe67f8b575c1c8e466af45110317244d1 Mon Sep 17 00:00:00 2001 From: Anders Olsson Date: Wed, 2 Jan 2019 21:58:02 +0100 Subject: [PATCH] 2018 edition, and clippy fixes. --- Cargo.toml | 1 + src/factor_graph.rs | 6 ++++-- src/gaussian.rs | 2 ++ src/lib.rs | 19 ++++--------------- src/math.rs | 8 ++++++-- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b7bdec8..427f389 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ name = "trueskill" version = "0.1.0" authors = ["Anders Olsson "] +edition = "2018" [dependencies] log = "0.4" diff --git a/src/factor_graph.rs b/src/factor_graph.rs index 6727ebf..5090f2b 100644 --- a/src/factor_graph.rs +++ b/src/factor_graph.rs @@ -2,8 +2,10 @@ use std::collections::HashMap; use std::f64; use std::ops; -use gaussian::Gaussian; -use math; +use log::*; + +use crate::gaussian::Gaussian; +use crate::math; #[derive(Clone, Copy, Debug, PartialEq)] pub struct VariableId { diff --git a/src/gaussian.rs b/src/gaussian.rs index 762c101..53462b4 100644 --- a/src/gaussian.rs +++ b/src/gaussian.rs @@ -56,6 +56,7 @@ impl ops::Mul for Gaussian { type Output = Gaussian; fn mul(self, rhs: Gaussian) -> Gaussian { + #[allow(clippy::suspicious_arithmetic_impl)] Gaussian::from_pi_tau(self.pi + rhs.pi, self.tau + rhs.tau) } } @@ -64,6 +65,7 @@ impl ops::Div for Gaussian { type Output = Gaussian; fn div(self, rhs: Gaussian) -> Gaussian { + #[allow(clippy::suspicious_arithmetic_impl)] Gaussian::from_pi_tau(self.pi - rhs.pi, self.tau - rhs.tau) } } diff --git a/src/lib.rs b/src/lib.rs index d24365a..31ed10d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,22 +1,11 @@ -#[macro_use] -extern crate log; -extern crate statrs; - -#[cfg(test)] -#[macro_use] -extern crate approx; - -#[cfg(test)] -extern crate env_logger; - mod factor_graph; mod gaussian; mod math; mod matrix; -use factor_graph::*; -use gaussian::Gaussian; -use matrix::Matrix; +use crate::factor_graph::*; +use crate::gaussian::Gaussian; +use crate::matrix::Matrix; /// Default initial mean of ratings. pub const MU: f64 = 25.0; @@ -376,7 +365,7 @@ impl Default for TrueSkill { #[cfg(test)] mod tests { - use approx::{AbsDiffEq, RelativeEq}; + use approx::*; use env_logger; use super::*; diff --git a/src/math.rs b/src/math.rs index c8b836b..469ef60 100644 --- a/src/math.rs +++ b/src/math.rs @@ -1,3 +1,5 @@ +#![allow(clippy::unreadable_literal, clippy::excessive_precision)] + use statrs::distribution::{Continuous, Normal, Univariate}; const S2PI: f64 = 2.50662827463100050242_e0; @@ -99,7 +101,7 @@ fn ndtri(y0: f64) -> f64 { }; if y > 0.13533528323661269189 { - y = y - 0.5; + y -= 0.5; let y2 = y * y; return (y + y * (y2 * polevl(y2, &P0, 4) / p1evl(y2, &Q0, 8))) * S2PI; @@ -136,10 +138,12 @@ pub fn icdf(x: f64) -> f64 { #[cfg(test)] mod tests { + use approx::*; + use super::*; #[test] fn test_cdf() { - assert_eq!(cdf(0.5), 0.6914624612740131); + assert_relative_eq!(cdf(0.5), 0.6914624612740131); } }