fix: cargo fmt

This commit is contained in:
Volodymyr Orlov
2020-06-05 17:52:03 -07:00
parent 685be04488
commit a2784d6345
52 changed files with 3342 additions and 2829 deletions
+11 -19
View File
@@ -1,9 +1,8 @@
use std::fmt::{Debug, Display};
use num_traits::{Float, FromPrimitive};
use rand::prelude::*;
use std::fmt::{Debug, Display};
pub trait FloatExt: Float + FromPrimitive + Debug + Display + Copy {
fn copysign(self, sign: Self) -> Self;
fn ln_1pe(self) -> Self;
@@ -15,33 +14,29 @@ pub trait FloatExt: Float + FromPrimitive + Debug + Display + Copy {
fn two() -> Self;
fn half() -> Self;
}
impl FloatExt for f64 {
fn copysign(self, sign: Self) -> Self{
fn copysign(self, sign: Self) -> Self {
self.copysign(sign)
}
fn ln_1pe(self) -> f64{
fn ln_1pe(self) -> f64 {
if self > 15. {
return self;
} else {
return self.exp().ln_1p();
}
}
fn sigmoid(self) -> f64 {
if self < -40. {
return 0.;
} else if self > 40. {
return 1.;
} else {
return 1. / (1. + f64::exp(-self))
return 1. / (1. + f64::exp(-self));
}
}
fn rand() -> f64 {
@@ -59,29 +54,26 @@ impl FloatExt for f64 {
}
impl FloatExt for f32 {
fn copysign(self, sign: Self) -> Self{
fn copysign(self, sign: Self) -> Self {
self.copysign(sign)
}
fn ln_1pe(self) -> f32{
fn ln_1pe(self) -> f32 {
if self > 15. {
return self;
} else {
return self.exp().ln_1p();
}
}
fn sigmoid(self) -> f32 {
if self < -40. {
return 0.;
} else if self > 40. {
return 1.;
} else {
return 1. / (1. + f32::exp(-self))
return 1. / (1. + f32::exp(-self));
}
}
fn rand() -> f32 {
@@ -99,13 +91,13 @@ impl FloatExt for f32 {
}
#[cfg(test)]
mod tests {
use super::*;
mod tests {
use super::*;
#[test]
fn sigmoid() {
fn sigmoid() {
assert_eq!(1.0.sigmoid(), 0.7310585786300049);
assert_eq!(41.0.sigmoid(), 1.);
assert_eq!((-41.0).sigmoid(), 0.);
}
}
}