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

Function QuantileToDataPoint

cpp/src/arrow/compute/kernels/aggregate_quantile.cc:46–75  ·  view source on GitHub ↗

quantile to exact datapoint index (IsDataPoint == true)

Source from the content-addressed store, hash-verified

44
45// quantile to exact datapoint index (IsDataPoint == true)
46uint64_t QuantileToDataPoint(size_t length, double q,
47 enum QuantileOptions::Interpolation interpolation) {
48 const double index = (length - 1) * q;
49 uint64_t datapoint_index = static_cast<uint64_t>(index);
50 const double fraction = index - datapoint_index;
51
52 if (interpolation == QuantileOptions::LINEAR ||
53 interpolation == QuantileOptions::MIDPOINT) {
54 DCHECK_EQ(fraction, 0);
55 }
56
57 // convert NEAREST interpolation method to LOWER or HIGHER
58 if (interpolation == QuantileOptions::NEAREST) {
59 if (fraction < 0.5) {
60 interpolation = QuantileOptions::LOWER;
61 } else if (fraction > 0.5) {
62 interpolation = QuantileOptions::HIGHER;
63 } else {
64 // round 0.5 to nearest even number, similar to numpy.around
65 interpolation =
66 (datapoint_index & 1) ? QuantileOptions::HIGHER : QuantileOptions::LOWER;
67 }
68 }
69
70 if (interpolation == QuantileOptions::HIGHER && fraction != 0) {
71 ++datapoint_index;
72 }
73
74 return datapoint_index;
75}
76
77template <typename T>
78double DataPointToDouble(T value, const DataType&) {

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected