Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix clippy #283

Merged
merged 9 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/algorithm/neighbour/cover_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl<T: Debug + PartialEq, D: Distance<T>> CoverTree<T, D> {
current_cover_set.push((d, &self.root));

let mut heap = HeapSelection::with_capacity(k);
heap.add(std::f64::MAX);
heap.add(f64::MAX);

let mut empty_heap = true;
if !self.identical_excluded || self.get_data_value(self.root.idx) != p {
Expand All @@ -145,7 +145,7 @@ impl<T: Debug + PartialEq, D: Distance<T>> CoverTree<T, D> {
}

let upper_bound = if empty_heap {
std::f64::INFINITY
f64::INFINITY
} else {
*heap.peek()
};
Expand Down Expand Up @@ -291,7 +291,7 @@ impl<T: Debug + PartialEq, D: Distance<T>> CoverTree<T, D> {
} else {
let max_dist = self.max(point_set);
let next_scale = (max_scale - 1).min(self.get_scale(max_dist));
if next_scale == std::i64::MIN {
if next_scale == i64::MIN {
let mut children: Vec<Node> = Vec::new();
let mut leaf = self.new_leaf(p);
children.push(leaf);
Expand Down Expand Up @@ -435,7 +435,7 @@ impl<T: Debug + PartialEq, D: Distance<T>> CoverTree<T, D> {

fn get_scale(&self, d: f64) -> i64 {
if d == 0f64 {
std::i64::MIN
i64::MIN
} else {
(self.inv_log_base * d.ln()).ceil() as i64
}
Expand Down
4 changes: 2 additions & 2 deletions src/algorithm/neighbour/linear_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<T, D: Distance<T>> LinearKNNSearch<T, D> {

for _ in 0..k {
heap.add(KNNPoint {
distance: std::f64::INFINITY,
distance: f64::INFINITY,
index: None,
});
}
Expand Down Expand Up @@ -215,7 +215,7 @@ mod tests {
};

let point_inf = KNNPoint {
distance: std::f64::INFINITY,
distance: f64::INFINITY,
index: Some(3),
};

Expand Down
4 changes: 2 additions & 2 deletions src/algorithm/sort/heap_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ mod tests {
#[test]
fn test_add1() {
let mut heap = HeapSelection::with_capacity(3);
heap.add(std::f64::INFINITY);
heap.add(f64::INFINITY);
heap.add(-5f64);
heap.add(4f64);
heap.add(-1f64);
Expand All @@ -151,7 +151,7 @@ mod tests {
#[test]
fn test_add2() {
let mut heap = HeapSelection::with_capacity(3);
heap.add(std::f64::INFINITY);
heap.add(f64::INFINITY);
heap.add(0.0);
heap.add(8.4852);
heap.add(5.6568);
Expand Down
1 change: 1 addition & 0 deletions src/algorithm/sort/quick_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use num_traits::Num;
pub trait QuickArgSort {
fn quick_argsort_mut(&mut self) -> Vec<usize>;

#[allow(dead_code)]
fn quick_argsort(&self) -> Vec<usize>;
}

Expand Down
8 changes: 4 additions & 4 deletions src/cluster/kmeans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<TX: Number, TY: Number, X: Array2<TX>, Y: Array1<TY>> PartialEq for KMeans<
return false;
}
for j in 0..self.centroids[i].len() {
if (self.centroids[i][j] - other.centroids[i][j]).abs() > std::f64::EPSILON {
if (self.centroids[i][j] - other.centroids[i][j]).abs() > f64::EPSILON {
return false;
}
}
Expand Down Expand Up @@ -270,7 +270,7 @@ impl<TX: Number, TY: Number, X: Array2<TX>, Y: Array1<TY>> KMeans<TX, TY, X, Y>

let (n, d) = data.shape();

let mut distortion = std::f64::MAX;
let mut distortion = f64::MAX;
let mut y = KMeans::<TX, TY, X, Y>::kmeans_plus_plus(data, parameters.k, parameters.seed);
let mut size = vec![0; parameters.k];
let mut centroids = vec![vec![0f64; d]; parameters.k];
Expand Down Expand Up @@ -331,7 +331,7 @@ impl<TX: Number, TY: Number, X: Array2<TX>, Y: Array1<TY>> KMeans<TX, TY, X, Y>
let mut row = vec![0f64; x.shape().1];

for i in 0..n {
let mut min_dist = std::f64::MAX;
let mut min_dist = f64::MAX;
let mut best_cluster = 0;

for j in 0..self.k {
Expand Down Expand Up @@ -361,7 +361,7 @@ impl<TX: Number, TY: Number, X: Array2<TX>, Y: Array1<TY>> KMeans<TX, TY, X, Y>
.cloned()
.collect();

let mut d = vec![std::f64::MAX; n];
let mut d = vec![f64::MAX; n];
let mut row = vec![TX::zero(); data.shape().1];

for j in 1..k {
Expand Down
22 changes: 11 additions & 11 deletions src/linalg/basic/arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@
if p.is_infinite() && p.is_sign_positive() {
self.iterator(0)
.map(|x| x.to_f64().unwrap().abs())
.fold(std::f64::NEG_INFINITY, |a, b| a.max(b))
.fold(f64::NEG_INFINITY, |a, b| a.max(b))
} else if p.is_infinite() && p.is_sign_negative() {
self.iterator(0)
.map(|x| x.to_f64().unwrap().abs())
.fold(std::f64::INFINITY, |a, b| a.min(b))
.fold(f64::INFINITY, |a, b| a.min(b))
} else {
let mut norm = 0f64;

Expand Down Expand Up @@ -558,11 +558,11 @@
if p.is_infinite() && p.is_sign_positive() {
self.iterator(0)
.map(|x| x.to_f64().unwrap().abs())
.fold(std::f64::NEG_INFINITY, |a, b| a.max(b))
.fold(f64::NEG_INFINITY, |a, b| a.max(b))
} else if p.is_infinite() && p.is_sign_negative() {
self.iterator(0)
.map(|x| x.to_f64().unwrap().abs())
.fold(std::f64::INFINITY, |a, b| a.min(b))
.fold(f64::INFINITY, |a, b| a.min(b))
} else {
let mut norm = 0f64;

Expand Down Expand Up @@ -731,34 +731,34 @@
pub trait MutArrayView2<T: Debug + Display + Copy + Sized>:
MutArray<T, (usize, usize)> + ArrayView2<T>
{
///
/// copy values from another array
fn copy_from(&mut self, other: &dyn Array<T, (usize, usize)>) {
self.iterator_mut(0)
.zip(other.iterator(0))
.for_each(|(s, o)| *s = *o);
}
///
/// update view with absolute values
fn abs_mut(&mut self)
where
T: Number + Signed,
{
self.iterator_mut(0).for_each(|v| *v = v.abs());
}
///
/// update view values with opposite sign
fn neg_mut(&mut self)
where
T: Number + Neg<Output = T>,
{
self.iterator_mut(0).for_each(|v| *v = -*v);
}
///
/// update view values at power `p`
fn pow_mut(&mut self, p: T)
where
T: RealNumber,
{
self.iterator_mut(0).for_each(|v| *v = v.powf(p));
}
///
/// scale view values
fn scale_mut(&mut self, mean: &[T], std: &[T], axis: u8)
where
T: Number,
Expand All @@ -784,27 +784,27 @@

/// Trait for mutable 1D-array view
pub trait Array1<T: Debug + Display + Copy + Sized>: MutArrayView1<T> + Sized + Clone {
///

Check failure on line 787 in src/linalg/basic/arrays.rs

View workflow job for this annotation

GitHub Actions / lint

empty doc comment
fn slice<'a>(&'a self, range: Range<usize>) -> Box<dyn ArrayView1<T> + 'a>;
///

Check failure on line 789 in src/linalg/basic/arrays.rs

View workflow job for this annotation

GitHub Actions / lint

empty doc comment
fn slice_mut<'a>(&'a mut self, range: Range<usize>) -> Box<dyn MutArrayView1<T> + 'a>;
///

Check failure on line 791 in src/linalg/basic/arrays.rs

View workflow job for this annotation

GitHub Actions / lint

empty doc comment
fn fill(len: usize, value: T) -> Self
where
Self: Sized;
///

Check failure on line 795 in src/linalg/basic/arrays.rs

View workflow job for this annotation

GitHub Actions / lint

empty doc comment
fn from_iterator<I: Iterator<Item = T>>(iter: I, len: usize) -> Self
where
Self: Sized;
///

Check failure on line 799 in src/linalg/basic/arrays.rs

View workflow job for this annotation

GitHub Actions / lint

empty doc comment
fn from_vec_slice(slice: &[T]) -> Self
where
Self: Sized;
///

Check failure on line 803 in src/linalg/basic/arrays.rs

View workflow job for this annotation

GitHub Actions / lint

empty doc comment
fn from_slice(slice: &'_ dyn ArrayView1<T>) -> Self
where
Self: Sized;
///

Check failure on line 807 in src/linalg/basic/arrays.rs

View workflow job for this annotation

GitHub Actions / lint

empty doc comment
fn zeros(len: usize) -> Self
where
T: Number,
Expand All @@ -812,7 +812,7 @@
{
Self::fill(len, T::zero())
}
///

Check failure on line 815 in src/linalg/basic/arrays.rs

View workflow job for this annotation

GitHub Actions / lint

empty doc comment
fn ones(len: usize) -> Self
where
T: Number,
Expand All @@ -820,7 +820,7 @@
{
Self::fill(len, T::one())
}
///

Check failure on line 823 in src/linalg/basic/arrays.rs

View workflow job for this annotation

GitHub Actions / lint

empty doc comment
fn rand(len: usize) -> Self
where
T: RealNumber,
Expand All @@ -828,7 +828,7 @@
{
Self::from_iterator((0..len).map(|_| T::rand()), len)
}
///

Check failure on line 831 in src/linalg/basic/arrays.rs

View workflow job for this annotation

GitHub Actions / lint

empty doc comment
fn add_scalar(&self, x: T) -> Self
where
T: Number,
Expand Down Expand Up @@ -1631,8 +1631,8 @@
let v = vec![3., -2., 6.];
assert_eq!(v.norm(1.), 11.);
assert_eq!(v.norm(2.), 7.);
assert_eq!(v.norm(std::f64::INFINITY), 6.);
assert_eq!(v.norm(std::f64::NEG_INFINITY), 2.);
assert_eq!(v.norm(f64::INFINITY), 6.);
assert_eq!(v.norm(f64::NEG_INFINITY), 2.);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/linalg/traits/evd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ mod tests {
));
for (i, eigen_values_i) in eigen_values.iter().enumerate() {
assert!((eigen_values_i - evd.d[i]).abs() < 1e-4);
assert!((0f64 - evd.e[i]).abs() < std::f64::EPSILON);
assert!((0f64 - evd.e[i]).abs() < f64::EPSILON);
}
}
#[cfg_attr(
Expand Down Expand Up @@ -875,7 +875,7 @@ mod tests {
));
for (i, eigen_values_i) in eigen_values.iter().enumerate() {
assert!((eigen_values_i - evd.d[i]).abs() < 1e-4);
assert!((0f64 - evd.e[i]).abs() < std::f64::EPSILON);
assert!((0f64 - evd.e[i]).abs() < f64::EPSILON);
}
}
#[cfg_attr(
Expand Down
4 changes: 2 additions & 2 deletions src/linalg/traits/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ mod tests {
let expected_0 = vec![0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
let expected_1 = vec![1.25, 1.25];

assert!(m.var(0).approximate_eq(&expected_0, std::f64::EPSILON));
assert!(m.var(1).approximate_eq(&expected_1, std::f64::EPSILON));
assert!(m.var(0).approximate_eq(&expected_0, f64::EPSILON));
assert!(m.var(1).approximate_eq(&expected_1, f64::EPSILON));
assert_eq!(
m.mean(0),
vec![0.0, 0.25, 0.25, 1.25, 1.5, 1.75, 2.75, 3.25]
Expand Down
2 changes: 1 addition & 1 deletion src/linear/lasso_optimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<T: FloatNumber, X: Array2<T>> InteriorPointOptimizer<T, X> {

// CALCULATE DUALITY GAP
let xnu = nu.xa(false, x);
let max_xnu = xnu.norm(std::f64::INFINITY);
let max_xnu = xnu.norm(f64::INFINITY);
if max_xnu > lambda_f64 {
let lnu = T::from_f64(lambda_f64 / max_xnu).unwrap();
nu.mul_scalar_mut(lnu);
Expand Down
18 changes: 9 additions & 9 deletions src/linear/logistic_regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,11 +629,11 @@ mod tests {
objective.df(&mut g, &vec![1., 2., 3., 4., 5., 6., 7., 8., 9.]);
objective.df(&mut g, &vec![1., 2., 3., 4., 5., 6., 7., 8., 9.]);

assert!((g[0] + 33.000068218163484).abs() < std::f64::EPSILON);
assert!((g[0] + 33.000068218163484).abs() < f64::EPSILON);

let f = objective.f(&[1., 2., 3., 4., 5., 6., 7., 8., 9.]);

assert!((f - 408.0052230582765).abs() < std::f64::EPSILON);
assert!((f - 408.0052230582765).abs() < f64::EPSILON);

let objective_reg = MultiClassObjectiveFunction {
x: &x,
Expand Down Expand Up @@ -689,13 +689,13 @@ mod tests {
objective.df(&mut g, &vec![1., 2., 3.]);
objective.df(&mut g, &vec![1., 2., 3.]);

assert!((g[0] - 26.051064349381285).abs() < std::f64::EPSILON);
assert!((g[1] - 10.239000702928523).abs() < std::f64::EPSILON);
assert!((g[2] - 3.869294270156324).abs() < std::f64::EPSILON);
assert!((g[0] - 26.051064349381285).abs() < f64::EPSILON);
assert!((g[1] - 10.239000702928523).abs() < f64::EPSILON);
assert!((g[2] - 3.869294270156324).abs() < f64::EPSILON);

let f = objective.f(&[1., 2., 3.]);

assert!((f - 59.76994756647412).abs() < std::f64::EPSILON);
assert!((f - 59.76994756647412).abs() < f64::EPSILON);

let objective_reg = BinaryObjectiveFunction {
x: &x,
Expand Down Expand Up @@ -916,7 +916,7 @@ mod tests {
let x: DenseMatrix<f32> = DenseMatrix::rand(52181, 94);
let y1: Vec<i32> = vec![1; 2181];
let y2: Vec<i32> = vec![0; 50000];
let y: Vec<i32> = y1.into_iter().chain(y2.into_iter()).collect();
let y: Vec<i32> = y1.into_iter().chain(y2).collect();

let lr = LogisticRegression::fit(&x, &y, Default::default()).unwrap();
let lr_reg = LogisticRegression::fit(
Expand All @@ -938,12 +938,12 @@ mod tests {
let x: &DenseMatrix<f64> = &DenseMatrix::rand(52181, 94);
let y1: Vec<u32> = vec![1; 2181];
let y2: Vec<u32> = vec![0; 50000];
let y: &Vec<u32> = &(y1.into_iter().chain(y2.into_iter()).collect());
let y: &Vec<u32> = &(y1.into_iter().chain(y2).collect());
println!("y vec height: {:?}", y.len());
println!("x matrix shape: {:?}", x.shape());

let lr = LogisticRegression::fit(x, y, Default::default()).unwrap();
let y_hat = lr.predict(&x).unwrap();
let y_hat = lr.predict(x).unwrap();

println!("y_hat shape: {:?}", y_hat.shape());

Expand Down
2 changes: 1 addition & 1 deletion src/naive_bayes/categorical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl<T: Number + Unsigned> PartialEq for CategoricalNBDistribution<T> {
return false;
}
for (a_i_j, b_i_j) in a_i.iter().zip(b_i.iter()) {
if (*a_i_j - *b_i_j).abs() > std::f64::EPSILON {
if (*a_i_j - *b_i_j).abs() > f64::EPSILON {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/naive_bayes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ mod tests {
}

fn classes(&self) -> &Vec<i32> {
&self.0
self.0
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/neighbors/knn_regressor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ mod tests {
let y_hat = knn.predict(&x).unwrap();
assert_eq!(5, Vec::len(&y_hat));
for i in 0..y_hat.len() {
assert!((y_hat[i] - y_exp[i]).abs() < std::f64::EPSILON);
assert!((y_hat[i] - y_exp[i]).abs() < f64::EPSILON);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/optimization/first_order/gradient_descent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ impl Default for GradientDescent {
fn default() -> Self {
GradientDescent {
max_iter: 10000,
g_rtol: std::f64::EPSILON.sqrt(),
g_atol: std::f64::EPSILON,
g_rtol: f64::EPSILON.sqrt(),
g_atol: f64::EPSILON,
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/optimization/first_order/lbfgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl LBFGS {
}

if state.x.max_diff(&state.x_prev)
<= T::from_f64(self.x_rtol * state.x.norm(std::f64::INFINITY)).unwrap()
<= T::from_f64(self.x_rtol * state.x.norm(f64::INFINITY)).unwrap()
{
x_converged = true;
}
Expand All @@ -188,7 +188,7 @@ impl LBFGS {
state.counter_f_tol += 1;
}

if state.x_df.norm(std::f64::INFINITY) <= self.g_atol {
if state.x_df.norm(f64::INFINITY) <= self.g_atol {
g_converged = true;
}

Expand Down Expand Up @@ -248,7 +248,7 @@ impl<T: FloatNumber + RealNumber> FirstOrderOptimizer<T> for LBFGS {

df(&mut state.x_df, x0);

let g_converged = state.x_df.norm(std::f64::INFINITY) < self.g_atol;
let g_converged = state.x_df.norm(f64::INFINITY) < self.g_atol;
let mut converged = g_converged;
let stopped = false;

Expand Down Expand Up @@ -299,7 +299,7 @@ mod tests {

let result = optimizer.optimize(&f, &df, &x0, &ls);

assert!((result.f_x - 0.0).abs() < std::f64::EPSILON);
assert!((result.f_x - 0.0).abs() < f64::EPSILON);
assert!((result.x[0] - 1.0).abs() < 1e-8);
assert!((result.x[1] - 1.0).abs() < 1e-8);
assert!(result.iterations <= 24);
Expand Down
2 changes: 1 addition & 1 deletion src/svm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ mod tests {
.unwrap()
.abs();

assert!((4913f64 - result) < std::f64::EPSILON);
assert!((4913f64 - result).abs() < f64::EPSILON);
}

#[cfg_attr(
Expand Down
Loading
Loading