64 template<
typename dtype>
66 Axis inAxis =
Axis::NONE,
const std::string& inInterpMethod =
"linear")
70 if (inPercentile < 0.0 || inPercentile > 100.0)
79 else if (inArray.
size() == 1)
85 if (inInterpMethod !=
"linear" &&
86 inInterpMethod !=
"lower" &&
87 inInterpMethod !=
"higher" &&
88 inInterpMethod !=
"nearest" &&
89 inInterpMethod !=
"midpoint")
91 std::string errStr =
"input interpolation method is not a vaid option.\n";
92 errStr +=
"\tValid options are 'linear', 'lower', 'higher', 'nearest', 'midpoint'.";
114 const auto i =
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 = (inPercentile / 100.0 - percentI) /
121 (
static_cast<double>(indexLower + 1) /
static_cast<double>(inArray.
size() - 1) - percentI);
123 NdArray<double> returnArray = { arrayCopy[indexLower] + (arrayCopy[indexLower + 1] - arrayCopy[indexLower]) * fraction };
127 if (inInterpMethod ==
"lower")
133 if (inInterpMethod ==
"higher")
139 if (inInterpMethod ==
"nearest")
141 const double percent = inPercentile / 100.0;
142 const double percent1 =
static_cast<double>(indexLower) /
static_cast<double>(inArray.
size() - 1);
143 const double percent2 =
static_cast<double>(indexLower + 1) /
static_cast<double>(inArray.
size() - 1);
144 const double diff1 = percent - percent1;
145 const double diff2 = percent2 - percent;
147 switch (argmin<double>({ diff1, diff2 }).item())
162 if (inInterpMethod ==
"midpoint")
164 NdArray<double> returnArray = { (arrayCopy[indexLower] + arrayCopy[indexLower + 1]) / 2.0 };
176 for (
uint32 row = 0; row < inShape.
rows; ++row)
190 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:4296
iterator end() noexcept
Definition: NdArrayCore.hpp:1474
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4283
bool isempty() const noexcept
Definition: NdArrayCore.hpp:2843
const_reference back() const noexcept
Definition: NdArrayCore.hpp:2204
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4629
const_reference front() const noexcept
Definition: NdArrayCore.hpp:2772
iterator begin() noexcept
Definition: NdArrayCore.hpp:1166
value_type item() const
Definition: NdArrayCore.hpp:2931
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:65
std::uint32_t uint32
Definition: Types.hpp:40