From de18d8e010505f23c0e8eedb316e2f6b60fb482f Mon Sep 17 00:00:00 2001 From: Palash Tyagi <23239946+Magnus167@users.noreply.github.com> Date: Sat, 12 Jul 2025 00:56:09 +0100 Subject: [PATCH] applied formatting --- src/compute/mod.rs | 3 +-- src/compute/models/dense_nn.rs | 40 ++++++++++++++++++++++---------- src/compute/models/mod.rs | 8 +++---- src/compute/models/pca.rs | 9 +++---- src/compute/stats/correlation.rs | 2 +- src/compute/stats/mod.rs | 4 ++-- src/frame/mod.rs | 2 +- src/matrix/boolops.rs | 6 ++--- src/matrix/mod.rs | 4 ++-- 9 files changed, 45 insertions(+), 33 deletions(-) diff --git a/src/compute/mod.rs b/src/compute/mod.rs index 8986bdc..6aa9b32 100644 --- a/src/compute/mod.rs +++ b/src/compute/mod.rs @@ -1,4 +1,3 @@ - pub mod models; -pub mod stats; \ No newline at end of file +pub mod stats; diff --git a/src/compute/models/dense_nn.rs b/src/compute/models/dense_nn.rs index 31314b5..930dcc3 100644 --- a/src/compute/models/dense_nn.rs +++ b/src/compute/models/dense_nn.rs @@ -349,7 +349,8 @@ mod tests { assert!( (output[(i, j)] - expected[(i, j)]).abs() < 1e-9, "Tanh forward output mismatch at ({}, {})", - i, j + i, + j ); } } @@ -366,7 +367,8 @@ mod tests { assert!( (output[(i, j)] - expected[(i, j)]).abs() < 1e-9, "ReLU derivative output mismatch at ({}, {})", - i, j + i, + j ); } } @@ -383,7 +385,8 @@ mod tests { assert!( (output[(i, j)] - expected[(i, j)]).abs() < 1e-9, "Tanh derivative output mismatch at ({}, {})", - i, j + i, + j ); } } @@ -401,7 +404,10 @@ mod tests { assert_eq!(matrix.cols(), cols); for val in matrix.data() { - assert!(*val >= -limit && *val <= limit, "Xavier initialized value out of range"); + assert!( + *val >= -limit && *val <= limit, + "Xavier initialized value out of range" + ); } } @@ -417,7 +423,10 @@ mod tests { assert_eq!(matrix.cols(), cols); for val in matrix.data() { - assert!(*val >= -limit && *val <= limit, "He initialized value out of range"); + assert!( + *val >= -limit && *val <= limit, + "He initialized value out of range" + ); } } @@ -436,7 +445,8 @@ mod tests { assert!( (output_gradient[(i, j)] - expected_gradient[(i, j)]).abs() < 1e-9, "BCE gradient output mismatch at ({}, {})", - i, j + i, + j ); } } @@ -462,16 +472,22 @@ mod tests { let before_preds = model.predict(&x); // BCE loss calculation for testing - let before_loss = -1.0 / (y.rows() as f64) * before_preds.zip(&y, |yh, yv| { - yv * yh.ln() + (1.0 - yv) * (1.0 - yh).ln() - }).data().iter().sum::(); + let before_loss = -1.0 / (y.rows() as f64) + * before_preds + .zip(&y, |yh, yv| yv * yh.ln() + (1.0 - yv) * (1.0 - yh).ln()) + .data() + .iter() + .sum::(); model.train(&x, &y); let after_preds = model.predict(&x); - let after_loss = -1.0 / (y.rows() as f64) * after_preds.zip(&y, |yh, yv| { - yv * yh.ln() + (1.0 - yv) * (1.0 - yh).ln() - }).data().iter().sum::(); + let after_loss = -1.0 / (y.rows() as f64) + * after_preds + .zip(&y, |yh, yv| yv * yh.ln() + (1.0 - yv) * (1.0 - yh).ln()) + .data() + .iter() + .sum::(); assert!( after_loss < before_loss, diff --git a/src/compute/models/mod.rs b/src/compute/models/mod.rs index 051d523..560b9f2 100644 --- a/src/compute/models/mod.rs +++ b/src/compute/models/mod.rs @@ -1,7 +1,7 @@ +pub mod activations; +pub mod dense_nn; +pub mod gaussian_nb; +pub mod k_means; pub mod linreg; pub mod logreg; -pub mod dense_nn; -pub mod k_means; pub mod pca; -pub mod gaussian_nb; -pub mod activations; diff --git a/src/compute/models/pca.rs b/src/compute/models/pca.rs index db77d2d..5c03293 100644 --- a/src/compute/models/pca.rs +++ b/src/compute/models/pca.rs @@ -1,6 +1,6 @@ -use crate::matrix::{Axis, Matrix, SeriesOps}; -use crate::compute::stats::descriptive::mean_vertical; use crate::compute::stats::correlation::covariance_matrix; +use crate::compute::stats::descriptive::mean_vertical; +use crate::matrix::{Axis, Matrix, SeriesOps}; /// Returns the `n_components` principal axes (rows) and the centred data's mean. pub struct PCA { @@ -24,10 +24,7 @@ impl PCA { } } - PCA { - components, - mean, - } + PCA { components, mean } } /// Project new data on the learned axes. diff --git a/src/compute/stats/correlation.rs b/src/compute/stats/correlation.rs index 0e29764..feb4908 100644 --- a/src/compute/stats/correlation.rs +++ b/src/compute/stats/correlation.rs @@ -94,7 +94,7 @@ pub fn covariance_matrix(x: &Matrix, axis: Axis) -> Matrix { } Axis::Row => { let mean_matrix = mean_horizontal(x); // n_samples x 1 - // Manually create a matrix by broadcasting the column vector across columns + // Manually create a matrix by broadcasting the column vector across columns let mut broadcasted_mean = Matrix::zeros(n_samples, n_features); for r in 0..n_samples { let mean_val = mean_matrix.get(r, 0); diff --git a/src/compute/stats/mod.rs b/src/compute/stats/mod.rs index dda89bb..38cc2ec 100644 --- a/src/compute/stats/mod.rs +++ b/src/compute/stats/mod.rs @@ -1,7 +1,7 @@ +pub mod correlation; pub mod descriptive; pub mod distributions; -pub mod correlation; +pub use correlation::*; pub use descriptive::*; pub use distributions::*; -pub use correlation::*; \ No newline at end of file diff --git a/src/frame/mod.rs b/src/frame/mod.rs index e7840d4..ced467c 100644 --- a/src/frame/mod.rs +++ b/src/frame/mod.rs @@ -4,4 +4,4 @@ pub mod ops; pub use base::*; #[allow(unused_imports)] -pub use ops::*; \ No newline at end of file +pub use ops::*; diff --git a/src/matrix/boolops.rs b/src/matrix/boolops.rs index ddfa451..c830139 100644 --- a/src/matrix/boolops.rs +++ b/src/matrix/boolops.rs @@ -171,7 +171,7 @@ mod tests { #[test] fn test_bool_ops_count_overall() { let matrix = create_bool_test_matrix(); // Data: [T, F, T, F, T, F, T, F, F] - // Count of true values: 4 + // Count of true values: 4 assert_eq!(matrix.count(), 4); let matrix_all_false = BoolMatrix::from_vec(vec![false; 5], 5, 1); // 5x1 @@ -211,7 +211,7 @@ mod tests { #[test] fn test_bool_ops_1xn_matrix() { let matrix = BoolMatrix::from_vec(vec![true, false, false, true], 1, 4); // 1 row, 4 cols - // Data: [T, F, F, T] + // Data: [T, F, F, T] assert_eq!(matrix.any_vertical(), vec![true, false, false, true]); assert_eq!(matrix.all_vertical(), vec![true, false, false, true]); @@ -229,7 +229,7 @@ mod tests { #[test] fn test_bool_ops_nx1_matrix() { let matrix = BoolMatrix::from_vec(vec![true, false, false, true], 4, 1); // 4 rows, 1 col - // Data: [T, F, F, T] + // Data: [T, F, F, T] assert_eq!(matrix.any_vertical(), vec![true]); // T|F|F|T = T assert_eq!(matrix.all_vertical(), vec![false]); // T&F&F&T = F diff --git a/src/matrix/mod.rs b/src/matrix/mod.rs index 43977ab..509d449 100644 --- a/src/matrix/mod.rs +++ b/src/matrix/mod.rs @@ -1,7 +1,7 @@ +pub mod boolops; pub mod mat; pub mod seriesops; -pub mod boolops; +pub use boolops::*; pub use mat::*; pub use seriesops::*; -pub use boolops::*; \ No newline at end of file