quantile to exact datapoint index (IsDataPoint == true)
| 44 | |
| 45 | // quantile to exact datapoint index (IsDataPoint == true) |
| 46 | uint64_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 | |
| 77 | template <typename T> |
| 78 | double DataPointToDouble(T value, const DataType&) { |
no outgoing calls
no test coverage detected