NumCpp  2.14.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions/interp.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <string>
31
33#include "NumCpp/NdArray.hpp"
35
36namespace nc
37{
38 //============================================================================
47 template<typename dtype>
48 constexpr double interp(dtype inValue1, dtype inValue2, double inPercent) noexcept
49 {
51 }
52
53 //============================================================================
54 // Method Description:
70 template<typename dtype>
72 {
73 // do some error checking first
74 if (inXp.size() != inFp.size())
75 {
76 THROW_INVALID_ARGUMENT_ERROR("inXp and inFp need to be the same size().");
77 }
78
79 if (inX.min().item() < inXp.min().item() || inX.max().item() > inXp.max().item())
80 {
81 THROW_INVALID_ARGUMENT_ERROR("endpoints of inX should be contained within inXp.");
82 }
83
84 // sort the input inXp and inFp data
86 NdArray<dtype> sortedXp(1, inFp.size());
87 NdArray<dtype> sortedFp(1, inFp.size());
88 uint32 counter = 0;
89 for (auto sortedXpIdx : sortedXpIdxs)
90 {
93 }
94
95 // get the sorted input inX array indices
97
99
100 uint32 currXpIdx = 0;
101 uint32 currXidx = 0;
102 while (currXidx < inX.size())
103 {
104 const auto sortedXIdx = sortedXIdxs[currXidx];
105 const auto x = inX[sortedXIdx];
106 const auto xPLow = sortedXp[currXpIdx];
107 const auto xPHigh = sortedXp[currXpIdx + 1];
108 const auto fPLow = sortedFp[currXpIdx];
109 const auto fPHigh = sortedFp[currXpIdx + 1];
110
111 if (xPLow <= x && x <= xPHigh)
112 {
113 const double percent = static_cast<double>(x - xPLow) / static_cast<double>(xPHigh - xPLow);
115 ++currXidx;
116 }
117 else
118 {
119 ++currXpIdx;
120 }
121 }
122
123 return returnArray;
124 }
125} // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition Error.hpp:37
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:139
constexpr double interp(double inValue1, double inValue2, double inPercent) noexcept
Definition Utils/interp.hpp:41
Definition Cartesian.hpp:40
NdArray< uint32 > argsort(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition argsort.hpp:46
constexpr double interp(dtype inValue1, dtype inValue2, double inPercent) noexcept
Definition Functions/interp.hpp:48
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59
std::uint32_t uint32
Definition Types.hpp:40