LindaSummer commented on code in PR #3312:
URL: https://github.com/apache/kvrocks/pull/3312#discussion_r2918724851
##########
src/types/tdigest.h:
##########
@@ -309,3 +309,45 @@ inline Status TDigestRank(TD&& td, const
std::vector<double>& inputs, std::vecto
}
return Status::OK();
}
+
+template <typename TD>
+inline StatusOr<double> TDigestTrimmedMean(TD&& td, double low_cut_quantile,
double high_cut_quantile) {
+ if (td.Size() == 0) {
+ return std::numeric_limits<double>::quiet_NaN();
+ }
+
+ const double total_weight = td.TotalWeight();
+ const double leftmost_weight = std::floor(total_weight * low_cut_quantile);
+ const double rightmost_weight = std::ceil(total_weight * high_cut_quantile);
+
+ double count_done = 0.0;
+ double trimmed_sum = 0.0;
+ double trimmed_count = 0.0;
+
+ auto iter = td.Begin();
+ while (iter->Valid()) {
+ auto centroid = GET_OR_RET(iter->GetCentroid());
+ const double n_weight = centroid.weight;
+ double count_add = n_weight;
+
+ count_add -= std::min(std::max(0.0, leftmost_weight - count_done),
count_add);
+ count_add = std::min(std::max(0.0, rightmost_weight - count_done),
count_add);
Review Comment:
Could we have a comment on this? It may be hard to understand at first
glance.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]