MCPcopy Create free account
hub / github.com/apache/datafusion / variance

Method variance

datafusion/functions-aggregate/src/variance.rs:469–491  ·  view source on GitHub ↗
(
        &mut self,
        emit_to: datafusion_expr::EmitTo,
    )

Source from the content-addressed store, hash-verified

467 }
468
469 pub fn variance(
470 &mut self,
471 emit_to: datafusion_expr::EmitTo,
472 ) -> (Vec<f64>, NullBuffer) {
473 let mut counts = emit_to.take_needed(&mut self.counts);
474 // means are only needed for updating m2s and are not needed for the final result.
475 // But we still need to take them to ensure the internal state is consistent.
476 let _ = emit_to.take_needed(&mut self.means);
477 let m2s = emit_to.take_needed(&mut self.m2s);
478
479 if let StatsType::Sample = self.stats_type {
480 counts.iter_mut().for_each(|count| {
481 *count = count.saturating_sub(1);
482 });
483 }
484 let nulls = NullBuffer::from_iter(counts.iter().map(|&count| count != 0));
485 let variance = m2s
486 .iter()
487 .zip(counts)
488 .map(|(m2, count)| m2 / count as f64)
489 .collect();
490 (variance, nulls)
491 }
492}
493
494impl GroupsAccumulator for VarianceGroupsAccumulator {

Callers 3

try_fromMethod · 0.45
evaluateMethod · 0.45
evaluateMethod · 0.45

Calls 4

take_neededMethod · 0.80
collectMethod · 0.80
mapMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected