File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed
Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -270,8 +270,8 @@ struct Stats {
270270impl Stats {
271271 fn new ( value : f64 ) -> Self {
272272 Stats {
273- count : 0 , // Will be set during finalization
274- nonzero_count : 1 ,
273+ count : 1 ,
274+ nonzero_count : if value != 0.0 { 1 } else { 0 } ,
275275 sum : value,
276276 sum_of_squares : value * value,
277277 min : value,
@@ -280,7 +280,10 @@ impl Stats {
280280 }
281281
282282 fn update ( & mut self , value : f64 ) {
283- self . nonzero_count += 1 ;
283+ self . count += 1 ;
284+ if value != 0.0 {
285+ self . nonzero_count += 1 ;
286+ }
284287 self . sum += value;
285288 self . sum_of_squares += value * value;
286289
@@ -294,12 +297,13 @@ impl Stats {
294297 }
295298
296299 fn finalize ( & mut self , total_count : usize , nonzero_count : usize ) {
297- // Adjust the count to include zeros
300+ // Adjust the count and nonzero_count
298301 self . count = total_count;
299302 self . nonzero_count = nonzero_count;
300303
301- // Zeros contribute zero to sum and sum_of_squares
302- // No adjustment needed
304+ // No need to adjust sum or sum_of_squares as zeros don't contribute
305+
306+ // min is nonzero minumum
303307 }
304308
305309 fn mean ( & self ) -> f64 {
You can’t perform that action at this time.
0 commit comments