64 template<
typename dtype>
68 const std::string& inInterpMethod =
"linear")
72 if (inPercentile < 0. || inPercentile > 100.)
87 if (inInterpMethod !=
"linear" && inInterpMethod !=
"lower" && inInterpMethod !=
"higher" &&
88 inInterpMethod !=
"nearest" && inInterpMethod !=
"midpoint")
90 std::string errStr =
"input interpolation method is not a vaid option.\n";
91 errStr +=
"\tValid options are 'linear', 'lower', 'higher', 'nearest', 'midpoint'.";
115 const auto indexLower = clip<uint32>(i, 0, inArray.
size() - 2);
117 if (inInterpMethod ==
"linear")
119 const double percentI =
static_cast<double>(indexLower) /
static_cast<double>(inArray.
size() - 1);
120 const double fraction =
121 (inPercentile / 100. - percentI) /
122 (
static_cast<double>(indexLower + 1) /
static_cast<double>(inArray.
size() - 1) - percentI);
125 (arrayCopy[indexLower + 1] - arrayCopy[indexLower]) * fraction };
129 if (inInterpMethod ==
"lower")
135 if (inInterpMethod ==
"higher")
141 if (inInterpMethod ==
"nearest")
143 const double percent = inPercentile / 100.;
144 const double percent1 =
static_cast<double>(indexLower) /
static_cast<double>(inArray.
size() - 1);
145 const double percent2 =
146 static_cast<double>(indexLower + 1) /
static_cast<double>(inArray.
size() - 1);
147 const double diff1 = percent - percent1;
148 const double diff2 = percent2 - percent;
150 switch (argmin<double>({ diff1, diff2 }).item())
165 if (inInterpMethod ==
"midpoint")
167 NdArray<double> returnArray = { (arrayCopy[indexLower] + arrayCopy[indexLower + 1]) / 2. };
179 for (
uint32 row = 0; row < inShape.
rows; ++row)
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:39
size_type size() const noexcept
Definition: NdArrayCore.hpp:4477
iterator end() noexcept
Definition: NdArrayCore.hpp:1576
self_type transpose() const
Definition: NdArrayCore.hpp:4837
bool isempty() const noexcept
Definition: NdArrayCore.hpp:2885
const_reference back() const noexcept
Definition: NdArrayCore.hpp:2240
const_reference front() const noexcept
Definition: NdArrayCore.hpp:2813
iterator begin() noexcept
Definition: NdArrayCore.hpp:1268
bool isscalar() const noexcept
Definition: NdArrayCore.hpp:2909
value_type item() const
Definition: NdArrayCore.hpp:2975
const Shape & shape() const noexcept
Definition: NdArrayCore.hpp:4464
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
uint32 rows
Definition: Core/Shape.hpp:44
uint32 cols
Definition: Core/Shape.hpp:45
void sort(RandomIt first, RandomIt last) noexcept
Definition: StlAlgorithms.hpp:696
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:48
Definition: Cartesian.hpp:40
Axis
Enum To describe an axis.
Definition: Types.hpp:47
dtype floor(dtype inValue) noexcept
Definition: floor.hpp:48
NdArray< double > percentile(const NdArray< dtype > &inArray, double inPercentile, Axis inAxis=Axis::NONE, const std::string &inInterpMethod="linear")
Definition: percentile.hpp:65
std::uint32_t uint32
Definition: Types.hpp:40