65 template<
typename dtype>
67 Axis inAxis =
Axis::NONE,
const std::string& inInterpMethod =
"linear")
71 if (inPercentile < 0.0 || inPercentile > 100.0)
80 else if (inArray.
size() == 1)
86 if (inInterpMethod !=
"linear" &&
87 inInterpMethod !=
"lower" &&
88 inInterpMethod !=
"higher" &&
89 inInterpMethod !=
"nearest" &&
90 inInterpMethod !=
"midpoint")
92 std::string errStr =
"input interpolation method is not a vaid option.\n";
93 errStr +=
"\tValid options are 'linear', 'lower', 'higher', 'nearest', 'midpoint'.";
115 const auto i =
static_cast<uint32>(
std::floor(
static_cast<double>(inArray.
size() - 1) * inPercentile / 100.0));
116 const auto indexLower = clip<uint32>(i, 0, inArray.
size() - 2);
118 if (inInterpMethod ==
"linear")
120 const double percentI =
static_cast<double>(indexLower) /
static_cast<double>(inArray.
size() - 1);
121 const double fraction = (inPercentile / 100.0 - percentI) /
122 (
static_cast<double>(indexLower + 1) /
static_cast<double>(inArray.
size() - 1) - percentI);
124 NdArray<double> returnArray = { arrayCopy[indexLower] + (arrayCopy[indexLower + 1] - arrayCopy[indexLower]) * fraction };
128 if (inInterpMethod ==
"lower")
134 if (inInterpMethod ==
"higher")
140 if (inInterpMethod ==
"nearest")
142 const double percent = inPercentile / 100.0;
143 const double percent1 =
static_cast<double>(indexLower) /
static_cast<double>(inArray.
size() - 1);
144 const double percent2 =
static_cast<double>(indexLower + 1) /
static_cast<double>(inArray.
size() - 1);
145 const double diff1 = percent - percent1;
146 const double diff2 = percent2 - percent;
148 switch (argmin<double>({ diff1, diff2 }).item())
163 if (inInterpMethod ==
"midpoint")
165 NdArray<double> returnArray = { (arrayCopy[indexLower] + arrayCopy[indexLower + 1]) / 2.0 };
177 for (
uint32 row = 0; row < inShape.
rows; ++row)
180 inPercentile,
Axis::NONE, inInterpMethod).item();
191 for (
uint32 row = 0; row < inShape.
rows; ++row)
194 inPercentile,
Axis::NONE, inInterpMethod).item();
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:72
size_type size() const noexcept
Definition: NdArrayCore.hpp:4497
iterator end() noexcept
Definition: NdArrayCore.hpp:1558
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4483
bool isempty() const noexcept
Definition: NdArrayCore.hpp:3012
const_reference back() const noexcept
Definition: NdArrayCore.hpp:2344
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4841
const_reference front() const noexcept
Definition: NdArrayCore.hpp:2933
iterator begin() noexcept
Definition: NdArrayCore.hpp:1214
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:629
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:52
Definition: Coordinate.hpp:45
Axis
Enum To describe an axis.
Definition: Types.hpp:46
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:66
std::uint32_t uint32
Definition: Types.hpp:40