You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by ti...@apache.org on 2026/02/10 13:17:10 UTC
(datasketches-rust) branch floating-cal created (now d77af8a)
This is an automated email from the ASF dual-hosted git repository.
tison pushed a change to branch floating-cal
in repository https://gitbox.apache.org/repos/asf/datasketches-rust.git
at d77af8a chore(tdigest): better handle Centroid adds
This branch includes the following new commits:
new d77af8a chore(tdigest): better handle Centroid adds
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org
(datasketches-rust) 01/01: chore(tdigest): better handle Centroid adds
Posted by ti...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tison pushed a commit to branch floating-cal
in repository https://gitbox.apache.org/repos/asf/datasketches-rust.git
commit d77af8aca98e639965daa24dd54f3220b0f0d599
Author: tison <wa...@gmail.com>
AuthorDate: Tue Feb 10 21:17:00 2026 +0800
chore(tdigest): better handle Centroid adds
Signed-off-by: tison <wa...@gmail.com>
---
datasketches/src/tdigest/sketch.rs | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/datasketches/src/tdigest/sketch.rs b/datasketches/src/tdigest/sketch.rs
index a790892..a9ef093 100644
--- a/datasketches/src/tdigest/sketch.rs
+++ b/datasketches/src/tdigest/sketch.rs
@@ -1251,15 +1251,24 @@ impl Centroid {
fn add(&mut self, other: Centroid) {
let (self_weight, other_weight) = (self.weight(), other.weight());
let total_weight = self_weight + other_weight;
- self.weight = self.weight.saturating_add(other.weight.get());
+ self.weight = self
+ .weight
+ .checked_add(other.weight.get())
+ .expect("weight overflow");
let (self_mean, other_mean) = (self.mean, other.mean);
- let ratio_self = self_weight / total_weight;
let ratio_other = other_weight / total_weight;
- self.mean = self_mean.mul_add(ratio_self, other_mean * ratio_other);
+ let delta = other_mean - self_mean;
+ self.mean = if delta.is_finite() {
+ delta.mul_add(ratio_other, self_mean)
+ } else {
+ let ratio_self = self_weight / total_weight;
+ self_mean.mul_add(ratio_self, other_mean * ratio_other)
+ };
+
debug_assert!(
- !self.mean.is_nan(),
- "NaN values should never be present in centroids; self: {}, other: {}",
+ self.mean.is_finite(),
+ "Centroid's mean must be finite; self: {}, other: {}",
self_mean,
other_mean
);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org