-
Notifications
You must be signed in to change notification settings - Fork 0
/
UtilityAdapter.cpp
49 lines (42 loc) · 1.46 KB
/
UtilityAdapter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "UtilityAdapter.hpp"
#include "util.hpp"
#include "ActivityPredictor/Utility.cpp"
#include <vector>
using namespace std;
UtilityAdapter::UtilityAdapter() {
}
UtilityAdapter::~UtilityAdapter() {
}
py::object UtilityAdapter::interpolateSplineRegular(
py::list& inputX, py::list& inputY,
float newSpacing, int outputLength, float initialOffset)
{
if (py::len(inputX) != py::len(inputY)) {
throw length_error("Cannot interpolate X and Y different lengths");
}
auto inputXVec = vectorFromList<float>(inputX);
auto inputYVec = vectorFromList<float>(inputY);
auto outputVec = vector<float>(outputLength, 0.0);
bool successful = ::interpolateSplineRegular(
inputXVec.data(),
inputYVec.data(),
inputXVec.size(),
outputVec.data(),
outputLength,
newSpacing,
initialOffset);
if (!successful) {
throw range_error("Insufficient data to interpolate up to desired length");
}
return listFromVector(outputVec);
}
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(UtilityAdapter_interpolateSplineRegular_overloads, UtilityAdapter::interpolateSplineRegular, 4, 5);
BOOST_PYTHON_MODULE(utilityadapter)
{
py::class_<UtilityAdapter>("UtilityAdapter", py::init<>())
.def("interpolateSplineRegular", &UtilityAdapter::interpolateSplineRegular,
UtilityAdapter_interpolateSplineRegular_overloads(
py::args("initialOffset"), ""
))
;
}