@@ -15,7 +15,11 @@ fn generate_clustered_data(
1515 let mut rng = ChaCha8Rng :: seed_from_u64 ( seed) ;
1616
1717 // Generate random cluster centers
18- let centers = Array2 :: random_using ( ( n_clusters, n_features) , Uniform :: new ( -10.0 , 10.0 ) , & mut rng) ;
18+ let centers = Array2 :: random_using (
19+ ( n_clusters, n_features) ,
20+ Uniform :: new ( -10.0 , 10.0 ) ,
21+ & mut rng,
22+ ) ;
1923
2024 // Generate points around each center
2125 let samples_per_cluster = n_samples / n_clusters;
@@ -32,7 +36,8 @@ fn generate_clustered_data(
3236 for i in start_idx..end_idx {
3337 for j in 0 ..n_features {
3438 // Add Gaussian noise around the center
35- let noise: f32 = Array2 :: random_using ( ( 1 , 1 ) , Uniform :: new ( -0.5 , 0.5 ) , & mut rng) [ [ 0 , 0 ] ] ;
39+ let noise: f32 =
40+ Array2 :: random_using ( ( 1 , 1 ) , Uniform :: new ( -0.5 , 0.5 ) , & mut rng) [ [ 0 , 0 ] ] ;
3641 data[ [ i, j] ] = center[ j] + noise;
3742 }
3843 }
@@ -43,11 +48,7 @@ fn generate_clustered_data(
4348
4449/// Calculate Normalized Mutual Information (NMI) between true and predicted labels
4550/// This is a simplified implementation for testing purposes
46- fn calculate_cluster_purity (
47- data : & ArrayView2 < f32 > ,
48- labels : & [ i64 ] ,
49- n_clusters : usize ,
50- ) -> f32 {
51+ fn calculate_cluster_purity ( data : & ArrayView2 < f32 > , labels : & [ i64 ] , n_clusters : usize ) -> f32 {
5152 // Calculate cluster sizes and verify non-empty clusters
5253 let mut cluster_counts = vec ! [ 0usize ; n_clusters] ;
5354 for & label in labels {
@@ -115,11 +116,18 @@ fn test_basic_train() {
115116
116117 let result = kmeans. train ( & data. view ( ) ) ;
117118 assert ! ( result. is_ok( ) , "Training should succeed" ) ;
118- assert ! ( kmeans. centroids( ) . is_some( ) , "Centroids should be set after training" ) ;
119+ assert ! (
120+ kmeans. centroids( ) . is_some( ) ,
121+ "Centroids should be set after training"
122+ ) ;
119123
120124 let centroids = kmeans. centroids ( ) . unwrap ( ) ;
121125 assert_eq ! ( centroids. nrows( ) , 10 , "Should have k centroids" ) ;
122- assert_eq ! ( centroids. ncols( ) , 128 , "Centroids should have correct dimensions" ) ;
126+ assert_eq ! (
127+ centroids. ncols( ) ,
128+ 128 ,
129+ "Centroids should have correct dimensions"
130+ ) ;
123131}
124132
125133#[ test]
@@ -129,7 +137,10 @@ fn test_basic_fit() {
129137
130138 let result = kmeans. fit ( & data. view ( ) ) ;
131139 assert ! ( result. is_ok( ) , "Fit should succeed" ) ;
132- assert ! ( kmeans. centroids( ) . is_some( ) , "Centroids should be set after fit" ) ;
140+ assert ! (
141+ kmeans. centroids( ) . is_some( ) ,
142+ "Centroids should be set after fit"
143+ ) ;
133144}
134145
135146#[ test]
@@ -183,7 +194,11 @@ fn test_clustering_quality_synthetic() {
183194
184195 // Check clustering quality
185196 let purity = calculate_cluster_purity ( & data. view ( ) , labels. as_slice ( ) . unwrap ( ) , 5 ) ;
186- assert ! ( purity > 0.0 , "Clustering should produce non-zero purity: {}" , purity) ;
197+ assert ! (
198+ purity > 0.0 ,
199+ "Clustering should produce non-zero purity: {}" ,
200+ purity
201+ ) ;
187202}
188203
189204#[ test]
@@ -302,7 +317,10 @@ fn test_different_seeds_produce_different_results() {
302317 break ;
303318 }
304319 }
305- assert ! ( !all_equal, "Different seeds should produce different results" ) ;
320+ assert ! (
321+ !all_equal,
322+ "Different seeds should produce different results"
323+ ) ;
306324}
307325
308326// ============================================================================
@@ -455,8 +473,8 @@ fn test_small_chunk_sizes() {
455473 tol : 1e-8 ,
456474 seed : 42 ,
457475 max_points_per_centroid : None ,
458- chunk_size_data : 50 , // Very small
459- chunk_size_centroids : 3 , // Very small
476+ chunk_size_data : 50 , // Very small
477+ chunk_size_centroids : 3 , // Very small
460478 verbose : false ,
461479 } ;
462480
@@ -476,8 +494,8 @@ fn test_large_chunk_sizes() {
476494 tol : 1e-8 ,
477495 seed : 42 ,
478496 max_points_per_centroid : None ,
479- chunk_size_data : 100_000 , // Larger than data
480- chunk_size_centroids : 100_000 , // Larger than k
497+ chunk_size_data : 100_000 , // Larger than data
498+ chunk_size_centroids : 100_000 , // Larger than k
481499 verbose : false ,
482500 } ;
483501
@@ -497,12 +515,18 @@ fn test_centroids_getter() {
497515 let mut kmeans = FastKMeans :: new ( 8 , 5 ) ;
498516
499517 // Before training
500- assert ! ( kmeans. centroids( ) . is_none( ) , "Centroids should be None before training" ) ;
518+ assert ! (
519+ kmeans. centroids( ) . is_none( ) ,
520+ "Centroids should be None before training"
521+ ) ;
501522
502523 // After training
503524 kmeans. train ( & data. view ( ) ) . unwrap ( ) ;
504525 let centroids = kmeans. centroids ( ) ;
505- assert ! ( centroids. is_some( ) , "Centroids should be Some after training" ) ;
526+ assert ! (
527+ centroids. is_some( ) ,
528+ "Centroids should be Some after training"
529+ ) ;
506530
507531 let c = centroids. unwrap ( ) ;
508532 assert_eq ! ( c. nrows( ) , 5 ) ;
0 commit comments