Merge another partial into this one using parallel Welford.
(&mut self, other: &ArrayAggPartial)
| 54 | |
| 55 | /// Merge another partial into this one using parallel Welford. |
| 56 | pub fn merge(&mut self, other: &ArrayAggPartial) { |
| 57 | if other.count == 0 { |
| 58 | return; |
| 59 | } |
| 60 | if self.count == 0 { |
| 61 | *self = other.clone(); |
| 62 | return; |
| 63 | } |
| 64 | self.sum += other.sum; |
| 65 | if other.min < self.min { |
| 66 | self.min = other.min; |
| 67 | } |
| 68 | if other.max > self.max { |
| 69 | self.max = other.max; |
| 70 | } |
| 71 | let new_count = self.count + other.count; |
| 72 | let delta = other.welford_mean - self.welford_mean; |
| 73 | let combined_mean = (self.welford_mean * self.count as f64 |
| 74 | + other.welford_mean * other.count as f64) |
| 75 | / new_count as f64; |
| 76 | let combined_m2 = self.welford_m2 |
| 77 | + other.welford_m2 |
| 78 | + delta * delta * (self.count as f64 * other.count as f64) / new_count as f64; |
| 79 | self.welford_mean = combined_mean; |
| 80 | self.welford_m2 = combined_m2; |
| 81 | self.count = new_count; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | /// Returns `true` if any shard reported that `system_as_of` fell below its |