Skip to content

Commit

Permalink
removed non-const interpolation functions
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-urban committed Oct 30, 2024
1 parent 02d1354 commit 54d5f3e
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 238 deletions.
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ project(
'cpp',
license: 'MPL-2.0',

version: '0.27.0',
version: '0.28.0',
default_options: ['warning_level=2', 'buildtype=release', 'cpp_std=c++20'],
meson_version: '>=1.3.2' #first version with clang-cl openmp support,
)
Expand Down
11 changes: 6 additions & 5 deletions src/pymodule/vectorinterpolators/c_akimainterpolator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ void init_akimainterpolator(pybind11::module& m, const std::string& name)
py::arg("Y") = std::vector<XYType>({}),
py::arg("extrapolation_mode") = t_extr_mode::extrapolate)
.def("__call__",
py::overload_cast<XYType>(&t_AkimaInterpolator::operator()),
py::overload_cast<XYType>(&t_AkimaInterpolator::operator(), py::const_),
DOC(themachinethatgoesping, tools, vectorinterpolators, I_Interpolator, operator_call),
py::arg("target_x"))
.def("get_y_const",
py::overload_cast<XYType>(&t_AkimaInterpolator::get_y_const, py::const_),
DOC(themachinethatgoesping, tools, vectorinterpolators, AkimaInterpolator, get_y_const),
.def("get_y",
py::overload_cast<XYType>(&t_AkimaInterpolator::get_y, py::const_),
DOC(themachinethatgoesping, tools, vectorinterpolators, AkimaInterpolator, get_y),
py::arg("target_x"))
.def("__call__",
py::overload_cast<const std::vector<XYType>&>(&t_AkimaInterpolator::operator()),
py::overload_cast<const std::vector<XYType>&>(&t_AkimaInterpolator::operator(),
py::const_),
DOC(themachinethatgoesping,
tools,
vectorinterpolators,
Expand Down
10 changes: 5 additions & 5 deletions src/pymodule/vectorinterpolators/c_linearinterpolator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ void init_linearinterpolator(pybind11::module& m, const std::string& name)
py::arg("Y") = std::vector<YType>({}),
py::arg("extrapolation_mode") = t_extr_mode::extrapolate)
.def("__call__",
py::overload_cast<XType>(&t_LinearInterpolator::operator()),
py::overload_cast<XType>(&t_LinearInterpolator::operator(), py::const_),
DOC(themachinethatgoesping, tools, vectorinterpolators, I_Interpolator, operator_call),
py::arg("target_x"))
.def("get_y_const",
py::overload_cast<XType>(&t_LinearInterpolator::get_y_const, py::const_),
DOC(themachinethatgoesping, tools, vectorinterpolators, I_PairInterpolator, get_y_const),
.def("get_y",
py::overload_cast<XType>(&t_LinearInterpolator::get_y, py::const_),
DOC(themachinethatgoesping, tools, vectorinterpolators, I_PairInterpolator, get_y),
py::arg("target_x"))
.def("__call__",
py::overload_cast<const std::vector<XType>&>(&t_LinearInterpolator::operator()),
py::overload_cast<const std::vector<XType>&>(&t_LinearInterpolator::operator(), py::const_),
DOC(themachinethatgoesping,
tools,
vectorinterpolators,
Expand Down
11 changes: 6 additions & 5 deletions src/pymodule/vectorinterpolators/c_nearestinterpolator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@ void init_nearestinterpolator(pybind11::module& m, const std::string& name)
py::arg("Y") = std::vector<YType>({}),
py::arg("extrapolation_mode") = t_extr_mode::extrapolate)
.def("__call__",
py::overload_cast<XType>(&t_NearestInterpolator::operator()),
py::overload_cast<XType>(&t_NearestInterpolator::operator(), py::const_),
DOC(themachinethatgoesping, tools, vectorinterpolators, I_Interpolator, operator_call),
py::arg("target_x"))
.def("get_y_const",
py::overload_cast<XType>(&t_NearestInterpolator::get_y_const, py::const_),
DOC(themachinethatgoesping, tools, vectorinterpolators, I_PairInterpolator, get_y_const),
.def("get_y",
py::overload_cast<XType>(&t_NearestInterpolator::get_y, py::const_),
DOC(themachinethatgoesping, tools, vectorinterpolators, I_PairInterpolator, get_y),
py::arg("target_x"))
.def("__call__",
py::overload_cast<const std::vector<XType>&>(&t_NearestInterpolator::operator()),
py::overload_cast<const std::vector<XType>&>(&t_NearestInterpolator::operator(),
py::const_),
DOC(themachinethatgoesping,
tools,
vectorinterpolators,
Expand Down
21 changes: 6 additions & 15 deletions src/pymodule/vectorinterpolators/c_slerpinterpolator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,36 +46,27 @@ void init_slerpinterpolator(pybind11::module& m, const std::string& name)
&t_SlerpInterpolator::empty,
DOC(themachinethatgoesping, tools, vectorinterpolators, I_PairInterpolator, empty))
.def("__call__",
py::overload_cast<XType, bool>(&t_SlerpInterpolator::ypr),
py::overload_cast<XType, bool>(&t_SlerpInterpolator::ypr, py::const_),
DOC(themachinethatgoesping, tools, vectorinterpolators, SlerpInterpolator, ypr),
py::arg("target_x"),
py::arg("output_in_degrees") = true)
.def("__call__",
py::overload_cast<const std::vector<XType>&, bool>(&t_SlerpInterpolator::ypr),
py::overload_cast<const std::vector<XType>&, bool>(&t_SlerpInterpolator::ypr,
py::const_),
DOC(themachinethatgoesping, tools, vectorinterpolators, SlerpInterpolator, ypr_2),
py::arg("targets_x"),
py::arg("output_in_degrees") = true)
.def("ypr",
py::overload_cast<XType, bool>(&t_SlerpInterpolator::ypr),
py::overload_cast<XType, bool>(&t_SlerpInterpolator::ypr, py::const_),
DOC(themachinethatgoesping, tools, vectorinterpolators, SlerpInterpolator, ypr),
py::arg("target_x"),
py::arg("output_in_degrees") = true)
.def("ypr",
py::overload_cast<const std::vector<XType>&, bool>(&t_SlerpInterpolator::ypr),
py::overload_cast<const std::vector<XType>&, bool>(&t_SlerpInterpolator::ypr,
py::const_),
DOC(themachinethatgoesping, tools, vectorinterpolators, SlerpInterpolator, ypr_2),
py::arg("targets_x"),
py::arg("output_in_degrees") = true)
.def("ypr_const",
py::overload_cast<XType, bool>(&t_SlerpInterpolator::ypr_const, py::const_),
DOC(themachinethatgoesping, tools, vectorinterpolators, SlerpInterpolator, ypr_const),
py::arg("target_x"),
py::arg("output_in_degrees") = true)
// .def(
// "ypr_const",
// py::overload_cast<const std::vector<XType>&, bool>(&t_SlerpInterpolator::ypr_const, py::const_),
// DOC(themachinethatgoesping, tools, vectorinterpolators, SlerpInterpolator, ypr_const_2),
// py::arg("targets_x"),
// py::arg("output_in_degrees") = true)
.def("set_extrapolation_mode",
&t_SlerpInterpolator::set_extrapolation_mode,
DOC(themachinethatgoesping,
Expand Down
14 changes: 7 additions & 7 deletions src/tests/vectorinterpolators/linear.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ TEST_CASE("LinearInterpolator: should perform basic interpolations correctly", T
SECTION("const interpolation should produce the same results as classic interpolation")
{
for (double x_val = -10; x_val <= 12; x_val += 0.1)
REQUIRE(interpolator(x_val) == Catch::Approx(interpolator.get_y_const(x_val)));
REQUIRE(interpolator(x_val) == Catch::Approx(interpolator.get_y(x_val)));
}

SECTION("preset values should be interpolated correctly")
Expand Down Expand Up @@ -82,8 +82,8 @@ TEST_CASE("LinearInterpolator: should perform basic interpolations correctly", T
{
REQUIRE_THROWS_AS(interpolator(-11), std::out_of_range);
REQUIRE_THROWS_AS(interpolator(13), std::out_of_range);
REQUIRE_THROWS_AS(interpolator.get_y_const(-11), std::out_of_range);
REQUIRE_THROWS_AS(interpolator.get_y_const(13), std::out_of_range);
REQUIRE_THROWS_AS(interpolator.get_y(-11), std::out_of_range);
REQUIRE_THROWS_AS(interpolator.get_y(13), std::out_of_range);
}
break;

Expand All @@ -92,17 +92,17 @@ TEST_CASE("LinearInterpolator: should perform basic interpolations correctly", T
{
REQUIRE(interpolator(-11) == Catch::Approx(1));
REQUIRE(interpolator(13) == Catch::Approx(y_append));
REQUIRE(interpolator.get_y_const(-11) == Catch::Approx(1));
REQUIRE(interpolator.get_y_const(13) == Catch::Approx(y_append));
REQUIRE(interpolator.get_y(-11) == Catch::Approx(1));
REQUIRE(interpolator.get_y(13) == Catch::Approx(y_append));
}
break;

default:
SECTION(" - extrapolation in all other cases")
REQUIRE(interpolator(-11) == Catch::Approx(1.2));
REQUIRE(interpolator(14) == Catch::Approx(-4 / 3.));
REQUIRE(interpolator.get_y_const(-11) == Catch::Approx(1.2));
REQUIRE(interpolator.get_y_const(14) == Catch::Approx(-4 / 3.));
REQUIRE(interpolator.get_y(-11) == Catch::Approx(1.2));
REQUIRE(interpolator.get_y(14) == Catch::Approx(-4 / 3.));

break;
}
Expand Down
10 changes: 5 additions & 5 deletions src/tests/vectorinterpolators/nearest.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ TEST_CASE("NearestInterpolator: should perform basic interpolations correctly",
SECTION("const interpolation should produce the same results as classic interpolation")
{
for (double x_val = -10; x_val <= 12; x_val += 0.1)
REQUIRE(interpolator(x_val) == Catch::Approx(interpolator.get_y_const(x_val)));
REQUIRE(interpolator(x_val) == Catch::Approx(interpolator.get_y(x_val)));
}
REQUIRE(interpolator.binary_hash() ==
10074301266414863605ULL); // lookup should not change the hash
Expand Down Expand Up @@ -95,17 +95,17 @@ TEST_CASE("NearestInterpolator: should perform basic interpolations correctly",
{
REQUIRE_THROWS_AS(interpolator(-11), std::out_of_range);
REQUIRE_THROWS_AS(interpolator(13), std::out_of_range);
REQUIRE_THROWS_AS(interpolator.get_y_const(-11), std::out_of_range);
REQUIRE_THROWS_AS(interpolator.get_y_const(13), std::out_of_range);
REQUIRE_THROWS_AS(interpolator.get_y(-11), std::out_of_range);
REQUIRE_THROWS_AS(interpolator.get_y(13), std::out_of_range);
}
break;

default:
SECTION(" - nearest extrapolation in all other cases")
REQUIRE(interpolator(-11) == Catch::Approx(1));
REQUIRE(interpolator(13) == Catch::Approx(y_append));
REQUIRE(interpolator.get_y_const(-11) == Catch::Approx(1));
REQUIRE(interpolator.get_y_const(13) == Catch::Approx(y_append));
REQUIRE(interpolator.get_y(-11) == Catch::Approx(1));
REQUIRE(interpolator.get_y(13) == Catch::Approx(y_append));
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//sourcehash: ed064a674b2936cc83bd14ff3ef722ec0d7671d201bb532268476ded39e7ef9d
//sourcehash: f2c90401a43df0683bdb25e8be6b64044cb280f9e2d9239f80cf43b92538bf3d

/*
This file contains docstrings for use in the Python bindings.
Expand Down Expand Up @@ -109,7 +109,7 @@ R"doc(return the y component of the internal data vector
Returns:
std::vector<XYType>)doc";

static const char *__doc_themachinethatgoesping_tools_vectorinterpolators_AkimaInterpolator_get_y_const = R"doc()doc";
static const char *__doc_themachinethatgoesping_tools_vectorinterpolators_AkimaInterpolator_get_y = R"doc()doc";

static const char *__doc_themachinethatgoesping_tools_vectorinterpolators_AkimaInterpolator_info_string =
R"doc(\ return an info string using the class __printer__ object \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//sourcehash: 5ddaae068f5b36105f921597593f0f8bc2e9ce00931d815570cf341fe2594edc
//sourcehash: f64d021ec0ed3dd9c872f966453efc20b45dd917ee1e2e6c5776bf11f1bc68d1

/*
This file contains docstrings for use in the Python bindings.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//sourcehash: fa4fc2190912b87676f5155f663b329167d6494b5e38cf6990e6ba62caee7ba5
//sourcehash: 2ea9486c0b7d77753818c25eb8f9084cb585df0bdaf3189a62ff0a0514e56ee8

/*
This file contains docstrings for use in the Python bindings.
Expand Down Expand Up @@ -97,7 +97,7 @@ R"doc(return the y component of the internal data vector
Returns:
std::vector<YType>)doc";

static const char *__doc_themachinethatgoesping_tools_vectorinterpolators_I_PairInterpolator_get_y_const = R"doc()doc";
static const char *__doc_themachinethatgoesping_tools_vectorinterpolators_I_PairInterpolator_get_y = R"doc()doc";

static const char *__doc_themachinethatgoesping_tools_vectorinterpolators_I_PairInterpolator_insert = R"doc()doc";

Expand All @@ -118,8 +118,6 @@ Parameter ``y1``:
Returns:
interpolated y value)doc";

static const char *__doc_themachinethatgoesping_tools_vectorinterpolators_I_PairInterpolator_last_x_pair = R"doc(< last pair (for faster consecutive searches))doc";

static const char *__doc_themachinethatgoesping_tools_vectorinterpolators_I_PairInterpolator_operator_call =
R"doc(get the interpolated y value for given x target
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//sourcehash: 16fdb3d053d0dae3ec48396a5d10edefb693b0fa9a0400a99a93b74e86e63cdc
//sourcehash: d8b630d9b4aab99aa6397befd5baa274e95d3d0e0244a255c4e1f77f9c7e5df6

/*
This file contains docstrings for use in the Python bindings.
Expand Down Expand Up @@ -353,18 +353,6 @@ Parameter ``output_in_degrees``:
Returns:
corresponding y value)doc";

static const char *__doc_themachinethatgoesping_tools_vectorinterpolators_SlerpInterpolator_ypr_const =
R"doc(get the interpolated yaw, pitch and roll values for given x target
Parameter ``target_x``:
find the corresponding y value for this x value
Parameter ``output_in_degrees``:
if true, yaw pitch and roll input values are in ° otherwise rad
Returns:
corresponding y value)doc";

#if defined(__GNUG__)
#pragma GCC diagnostic pop
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ class AkimaInterpolator : public I_Interpolator<XYType, XYType>
return true;
}

XYType get_y_const(XYType target_x) const
XYType get_y(XYType target_x) const
{
// if less than 4 values are present, act as linear interpolator
if (_X.size() < 4)
return _min_linearextrapolator.get_y_const(target_x);
return _min_linearextrapolator.get_y(target_x);

// check if _X (and _Y) are initialized (_X and _Y should always be the same size)
if (_X.size() != _Y.size())
Expand All @@ -136,7 +136,7 @@ class AkimaInterpolator : public I_Interpolator<XYType, XYType>
return _Y[0];

case t_extr_mode::extrapolate:
return _min_linearextrapolator.get_y_const(target_x);
return _min_linearextrapolator.get_y(target_x);

default: // fail
// throw std::out_of_range("ERROR[INTERPOLATE]: x value out of range (too small), "
Expand All @@ -157,7 +157,7 @@ class AkimaInterpolator : public I_Interpolator<XYType, XYType>
return _Y.back();

case t_extr_mode::extrapolate:
return _max_linearextrapolator.get_y_const(target_x);
return _max_linearextrapolator.get_y(target_x);

default: // fail
// throw std::out_of_range("ERROR[INTERPOLATE]: x value out of range (too large), "
Expand All @@ -180,7 +180,7 @@ class AkimaInterpolator : public I_Interpolator<XYType, XYType>
* @param target_x find the corresponding y value for this x value
* @return corresponding y value
*/
XYType operator()(XYType target_x) final { return get_y_const(target_x); }
XYType operator()(XYType target_x) const final { return get_y(target_x); }

/**
* @brief get nearest y values for given x targets (vectorized call)
Expand All @@ -189,7 +189,7 @@ class AkimaInterpolator : public I_Interpolator<XYType, XYType>
* corrsponding y value
* @return corresponding y value
*/
std::vector<XYType> operator()(const std::vector<XYType>& targetsX)
std::vector<XYType> operator()(const std::vector<XYType>& targetsX) const
{
return I_Interpolator<XYType, XYType>::operator()(targetsX);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ class I_Interpolator
* @param target_x find the corresponding y value for this x value
* @return corresponding y value
*/
virtual YType operator()(XType target_x) = 0;
virtual YType operator()(XType target_x) const = 0;

/**
* @brief get nearest y values for given x targets (vectorized call)
*
* @param targets_x vector of x values. For each of these values find the corrsponding y value
* @return corresponding y value
*/
std::vector<YType> operator()(const std::vector<XType>& targetsX)
std::vector<YType> operator()(const std::vector<XType>& targetsX) const
{
std::vector<YType> y_values;
y_values.reserve(targetsX.size());
Expand Down
Loading

0 comments on commit 54d5f3e

Please sign in to comment.