 |
NumCpp
1.0
A C++ implementation of the Python Numpy library
|
Go to the documentation of this file.
66 template<
typename dtype>
68 Axis inAxis =
Axis::NONE,
const std::string& inInterpMethod =
"linear")
72 if (inPercentile < 0.0 || inPercentile > 100.0)
77 if (inInterpMethod.compare(
"linear") != 0 &&
78 inInterpMethod.compare(
"lower") != 0 &&
79 inInterpMethod.compare(
"higher") != 0 &&
80 inInterpMethod.compare(
"nearest") != 0 &&
81 inInterpMethod.compare(
"midpoint") != 0)
83 std::string errStr =
"input interpolation method is not a vaid option.\n";
84 errStr +=
"\tValid options are 'linear', 'lower', 'higher', 'nearest', 'midpoint'.";
104 const uint32 indexLower =
static_cast<uint32>(clip<uint32>(i, 0, inArray.
size() - 2));
109 if (inInterpMethod.compare(
"linear") == 0)
111 const double percentI =
static_cast<double>(indexLower) /
static_cast<double>(inArray.
size() - 1);
112 const double fraction = (inPercentile / 100.0 - percentI) /
113 (
static_cast<double>(indexLower + 1) /
static_cast<double>(inArray.
size() - 1) - percentI);
115 const double returnValue = arrayCopy[indexLower] + (arrayCopy[indexLower + 1] - arrayCopy[indexLower]) * fraction;
119 else if (inInterpMethod.compare(
"lower") == 0)
124 else if (inInterpMethod.compare(
"higher") == 0)
129 else if (inInterpMethod.compare(
"nearest") == 0)
131 const double percent = inPercentile / 100.0;
132 const double percent1 =
static_cast<double>(indexLower) /
static_cast<double>(inArray.
size() - 1);
133 const double percent2 =
static_cast<double>(indexLower + 1) /
static_cast<double>(inArray.
size() - 1);
134 const double diff1 = percent - percent1;
135 const double diff2 = percent2 - percent;
137 switch (argmin<double>({ diff1, diff2 }).item())
151 else if (inInterpMethod.compare(
"midpoint") == 0)
153 NdArray<dtype> returnArray = {
static_cast<dtype
>((arrayCopy[indexLower] + arrayCopy[indexLower + 1]) / 2.0) };
170 for (
uint32 row = 0; row < inShape.
rows; ++row)
184 for (
uint32 row = 0; row < inShape.
rows; ++row)
value_type item() const
Definition: NdArrayCore.hpp:2950
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4296
std::int32_t int32
Definition: Types.hpp:37
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:38
NdArray< dtype > percentile(const NdArray< dtype > &inArray, double inPercentile, Axis inAxis=Axis::NONE, const std::string &inInterpMethod="linear")
Definition: percentile.hpp:67
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:53
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4591
std::uint32_t uint32
Definition: Types.hpp:41
dtype floor(dtype inValue) noexcept
Definition: floor.hpp:49
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
iterator end() noexcept
Definition: NdArrayCore.hpp:1435
size_type size() const noexcept
Definition: NdArrayCore.hpp:4310
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1491
Axis
Enum To describe an axis.
Definition: Types.hpp:47
Definition: Coordinate.hpp:45
uint32 rows
Definition: Core/Shape.hpp:45
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1147
void sort(RandomIt first, RandomIt last) noexcept
Definition: StlAlgorithms.hpp:630
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091