MCPcopy Create free account
hub / github.com/apache/arrow / ExactQuantile

Function ExactQuantile

cpp/src/arrow/util/tdigest_test.cc:77–95  ·  view source on GitHub ↗

Calculate exact quantile as truth

Source from the content-addressed store, hash-verified

75
76// Calculate exact quantile as truth
77std::vector<double> ExactQuantile(std::vector<double> values,
78 const std::vector<double>& quantiles) {
79 std::sort(values.begin(), values.end());
80
81 std::vector<double> output;
82 for (double q : quantiles) {
83 const double index = (values.size() - 1) * q;
84 const int64_t lower_index = static_cast<int64_t>(index);
85 const double fraction = index - lower_index;
86 if (fraction == 0) {
87 output.push_back(values[lower_index]);
88 } else {
89 const double lerp =
90 fraction * values[lower_index + 1] + (1 - fraction) * values[lower_index];
91 output.push_back(lerp);
92 }
93 }
94 return output;
95}
96
97void TestRandom(size_t size) {
98 const std::vector<double> fixed_quantiles = {0, 0.01, 0.1, 0.2, 0.5, 0.8, 0.9, 0.99, 1};

Callers 3

TestRandomFunction · 0.85
TestMergeFunction · 0.85
TESTFunction · 0.85

Calls 4

push_backMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected