64 template<
typename dtype>
68 const std::string& inInterpMethod =
"linear")
72 if (inPercentile < 0.0 || inPercentile > 100.0)
81 else if (inArray.
size() == 1)
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'.";
114 static_cast<uint32>(
std::floor(
static_cast<double>(inArray.
size() - 1) * inPercentile / 100.0));
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.0 - 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.0;
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.0 };
179 for (
uint32 row = 0; row < inShape.
rows; ++row)
196 for (
uint32 row = 0; row < inShape.
rows; ++row)
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:36
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:37
size_type size() const noexcept
Definition: NdArrayCore.hpp:4289
iterator end() noexcept
Definition: NdArrayCore.hpp:1479
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4276
bool isempty() const noexcept
Definition: NdArrayCore.hpp:2835
const_reference back() const noexcept
Definition: NdArrayCore.hpp:2194
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4650
const_reference front() const noexcept
Definition: NdArrayCore.hpp:2764
iterator begin() noexcept
Definition: NdArrayCore.hpp:1171
value_type item() const
Definition: NdArrayCore.hpp:2921
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:705
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:51
Definition: Coordinate.hpp:45
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