Skip to content

Commit

Permalink
More pymrpt improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Jun 26, 2023
1 parent c2063fd commit a7c7e87
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 4 deletions.
3 changes: 3 additions & 0 deletions doc/source/doxygen-docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
\page changelog Change Log

# Version 2.9.4: UNRELEASED
- Python:
- maps and multimaps are iterable again (Fixes a regression in v2.9.3)
- timestamps now has a `__str__` operator and `to_double()` method.
- BUG FIXES:
- Fix fail to build with libftdi1 v1.4 (Ubuntu Focal).

Expand Down
7 changes: 3 additions & 4 deletions python/generate-python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ $HOME/code/binder/build/source/binder \
-I$HOME/code/mrpt/libs/typemeta/include \
-I$HOME/code/mrpt/libs/vision/include/ \

# applying manual patches:
echo "Applying manual patches..."
find . -name "*.diff" | xargs -I FIL bash -c "git apply FIL"

# Workarounds to binder limitations:
# These are to ensure multiplatform portatbility of generated code
# (e.g. avoid build errors in armhf)
Expand All @@ -96,4 +92,7 @@ sed -i -e 's/unsigned long/size_t/g' $WRAP_OUT_DIR/std/stl_multimap.cpp
find $WRAP_OUT_DIR -name "*.cpp" | xargs -I FIL \
sed -i -e 's/(long)/(int64_t)/g' FIL

# applying manual patches:
echo "Applying manual patches..."
find . -name "*.diff" | xargs -I FIL bash -c "git apply FIL"

93 changes: 93 additions & 0 deletions python/patch-007.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
diff --git a/python/src/std/stl_deque.cpp b/python/src/std/stl_deque.cpp
index 1638b4d29..4c5984034 100644
--- a/python/src/std/stl_deque.cpp
+++ b/python/src/std/stl_deque.cpp
@@ -56,6 +56,11 @@ void bind_std_stl_deque(std::function< pybind11::module &(std::string const &nam
cl.def("pop_back", (void (std::deque<mrpt::bayes::CProbabilityParticle<mrpt::math::TPose3D, mrpt::bayes::particle_storage_mode::VALUE>>::*)()) &std::deque<mrpt::bayes::CProbabilityParticle<mrpt::math::TPose3D, mrpt::bayes::particle_storage_mode::VALUE>>::pop_back, "C++: std::deque<mrpt::bayes::CProbabilityParticle<mrpt::math::TPose3D, mrpt::bayes::particle_storage_mode::VALUE>>::pop_back() --> void");
cl.def("swap", (void (std::deque<mrpt::bayes::CProbabilityParticle<mrpt::math::TPose3D, mrpt::bayes::particle_storage_mode::VALUE>>::*)(class std::deque<struct mrpt::bayes::CProbabilityParticle<struct mrpt::math::TPose3D, mrpt::bayes::particle_storage_mode::VALUE> > &)) &std::deque<mrpt::bayes::CProbabilityParticle<mrpt::math::TPose3D, mrpt::bayes::particle_storage_mode::VALUE>>::swap, "C++: std::deque<mrpt::bayes::CProbabilityParticle<mrpt::math::TPose3D, mrpt::bayes::particle_storage_mode::VALUE>>::swap(class std::deque<struct mrpt::bayes::CProbabilityParticle<struct mrpt::math::TPose3D, mrpt::bayes::particle_storage_mode::VALUE> > &) --> void", pybind11::arg("__x"));
cl.def("clear", (void (std::deque<mrpt::bayes::CProbabilityParticle<mrpt::math::TPose3D, mrpt::bayes::particle_storage_mode::VALUE>>::*)()) &std::deque<mrpt::bayes::CProbabilityParticle<mrpt::math::TPose3D, mrpt::bayes::particle_storage_mode::VALUE>>::clear, "C++: std::deque<mrpt::bayes::CProbabilityParticle<mrpt::math::TPose3D, mrpt::bayes::particle_storage_mode::VALUE>>::clear() --> void");
+
+ cl.def("__iter__", [](const std::deque<mrpt::bayes::CProbabilityParticle<mrpt::math::TPose3D, mrpt::bayes::particle_storage_mode::VALUE>> &o) {
+ return pybind11::make_iterator(o.begin(), o.end());
+ }, pybind11::keep_alive<0, 1>());
+
}
{ // std::deque file:bits/stl_deque.h line:766
pybind11::class_<std::deque<mrpt::bayes::CProbabilityParticle<mrpt::math::TPose2D, mrpt::bayes::particle_storage_mode::VALUE>>, std::shared_ptr<std::deque<mrpt::bayes::CProbabilityParticle<mrpt::math::TPose2D, mrpt::bayes::particle_storage_mode::VALUE>>>> cl(M("std"), "deque_mrpt_bayes_CProbabilityParticle_mrpt_math_TPose2D_mrpt_bayes_particle_storage_mode_VALUE_t", "");
@@ -90,5 +95,10 @@ void bind_std_stl_deque(std::function< pybind11::module &(std::string const &nam
cl.def("pop_back", (void (std::deque<mrpt::bayes::CProbabilityParticle<mrpt::math::TPose2D, mrpt::bayes::particle_storage_mode::VALUE>>::*)()) &std::deque<mrpt::bayes::CProbabilityParticle<mrpt::math::TPose2D, mrpt::bayes::particle_storage_mode::VALUE>>::pop_back, "C++: std::deque<mrpt::bayes::CProbabilityParticle<mrpt::math::TPose2D, mrpt::bayes::particle_storage_mode::VALUE>>::pop_back() --> void");
cl.def("swap", (void (std::deque<mrpt::bayes::CProbabilityParticle<mrpt::math::TPose2D, mrpt::bayes::particle_storage_mode::VALUE>>::*)(class std::deque<struct mrpt::bayes::CProbabilityParticle<struct mrpt::math::TPose2D, mrpt::bayes::particle_storage_mode::VALUE> > &)) &std::deque<mrpt::bayes::CProbabilityParticle<mrpt::math::TPose2D, mrpt::bayes::particle_storage_mode::VALUE>>::swap, "C++: std::deque<mrpt::bayes::CProbabilityParticle<mrpt::math::TPose2D, mrpt::bayes::particle_storage_mode::VALUE>>::swap(class std::deque<struct mrpt::bayes::CProbabilityParticle<struct mrpt::math::TPose2D, mrpt::bayes::particle_storage_mode::VALUE> > &) --> void", pybind11::arg("__x"));
cl.def("clear", (void (std::deque<mrpt::bayes::CProbabilityParticle<mrpt::math::TPose2D, mrpt::bayes::particle_storage_mode::VALUE>>::*)()) &std::deque<mrpt::bayes::CProbabilityParticle<mrpt::math::TPose2D, mrpt::bayes::particle_storage_mode::VALUE>>::clear, "C++: std::deque<mrpt::bayes::CProbabilityParticle<mrpt::math::TPose2D, mrpt::bayes::particle_storage_mode::VALUE>>::clear() --> void");
+
+ cl.def("__iter__", [](const std::deque<mrpt::bayes::CProbabilityParticle<mrpt::math::TPose2D, mrpt::bayes::particle_storage_mode::VALUE>> &o) {
+ return pybind11::make_iterator(o.begin(), o.end());
+ }, pybind11::keep_alive<0, 1>());
+
}
}
diff --git a/python/src/std/stl_deque_1.cpp b/python/src/std/stl_deque_1.cpp
index b16449336..69668158e 100644
--- a/python/src/std/stl_deque_1.cpp
+++ b/python/src/std/stl_deque_1.cpp
@@ -64,6 +64,11 @@ void bind_std_stl_deque_1(std::function< pybind11::module &(std::string const &n
cl.def("pop_back", (void (std::deque<mrpt::math::TPose3D>::*)()) &std::deque<mrpt::math::TPose3D>::pop_back, "C++: std::deque<mrpt::math::TPose3D>::pop_back() --> void");
cl.def("swap", (void (std::deque<mrpt::math::TPose3D>::*)(class std::deque<struct mrpt::math::TPose3D> &)) &std::deque<mrpt::math::TPose3D>::swap, "C++: std::deque<mrpt::math::TPose3D>::swap(class std::deque<struct mrpt::math::TPose3D> &) --> void", pybind11::arg("__x"));
cl.def("clear", (void (std::deque<mrpt::math::TPose3D>::*)()) &std::deque<mrpt::math::TPose3D>::clear, "C++: std::deque<mrpt::math::TPose3D>::clear() --> void");
+
+ cl.def("__iter__", [](const std::deque<mrpt::math::TPose3D> &o) {
+ return pybind11::make_iterator(o.begin(), o.end());
+ }, pybind11::keep_alive<0, 1>());
+
}
{ // std::deque file:bits/stl_deque.h line:766
pybind11::class_<std::deque<mrpt::bayes::CProbabilityParticle<mrpt::maps::CRBPFParticleData, mrpt::bayes::particle_storage_mode::POINTER>>, std::shared_ptr<std::deque<mrpt::bayes::CProbabilityParticle<mrpt::maps::CRBPFParticleData, mrpt::bayes::particle_storage_mode::POINTER>>>> cl(M("std"), "deque_mrpt_bayes_CProbabilityParticle_mrpt_maps_CRBPFParticleData_mrpt_bayes_particle_storage_mode_POINTER_t", "");
@@ -91,5 +96,10 @@ void bind_std_stl_deque_1(std::function< pybind11::module &(std::string const &n
cl.def("pop_back", (void (std::deque<mrpt::bayes::CProbabilityParticle<mrpt::maps::CRBPFParticleData, mrpt::bayes::particle_storage_mode::POINTER>>::*)()) &std::deque<mrpt::bayes::CProbabilityParticle<mrpt::maps::CRBPFParticleData, mrpt::bayes::particle_storage_mode::POINTER>>::pop_back, "C++: std::deque<mrpt::bayes::CProbabilityParticle<mrpt::maps::CRBPFParticleData, mrpt::bayes::particle_storage_mode::POINTER>>::pop_back() --> void");
cl.def("swap", (void (std::deque<mrpt::bayes::CProbabilityParticle<mrpt::maps::CRBPFParticleData, mrpt::bayes::particle_storage_mode::POINTER>>::*)(class std::deque<struct mrpt::bayes::CProbabilityParticle<class mrpt::maps::CRBPFParticleData, mrpt::bayes::particle_storage_mode::POINTER> > &)) &std::deque<mrpt::bayes::CProbabilityParticle<mrpt::maps::CRBPFParticleData, mrpt::bayes::particle_storage_mode::POINTER>>::swap, "C++: std::deque<mrpt::bayes::CProbabilityParticle<mrpt::maps::CRBPFParticleData, mrpt::bayes::particle_storage_mode::POINTER>>::swap(class std::deque<struct mrpt::bayes::CProbabilityParticle<class mrpt::maps::CRBPFParticleData, mrpt::bayes::particle_storage_mode::POINTER> > &) --> void", pybind11::arg("__x"));
cl.def("clear", (void (std::deque<mrpt::bayes::CProbabilityParticle<mrpt::maps::CRBPFParticleData, mrpt::bayes::particle_storage_mode::POINTER>>::*)()) &std::deque<mrpt::bayes::CProbabilityParticle<mrpt::maps::CRBPFParticleData, mrpt::bayes::particle_storage_mode::POINTER>>::clear, "C++: std::deque<mrpt::bayes::CProbabilityParticle<mrpt::maps::CRBPFParticleData, mrpt::bayes::particle_storage_mode::POINTER>>::clear() --> void");
+
+ cl.def("__iter__", [](const std::deque<mrpt::bayes::CProbabilityParticle<mrpt::maps::CRBPFParticleData, mrpt::bayes::particle_storage_mode::POINTER>> &o) {
+ return pybind11::make_iterator(o.begin(), o.end());
+ }, pybind11::keep_alive<0, 1>());
+
}
}
diff --git a/python/src/std/stl_multimap.cpp b/python/src/std/stl_multimap.cpp
index ccfa54684..2b4e8b2ab 100644
--- a/python/src/std/stl_multimap.cpp
+++ b/python/src/std/stl_multimap.cpp
@@ -56,6 +56,10 @@ void bind_std_stl_multimap(std::function< pybind11::module &(std::string const &
cl.def("key_comp", (struct std::less<mrpt::Clock::time_point > (std::multimap<std::chrono::time_point<mrpt::Clock, std::chrono::duration<int64_t, std::ratio<1, 10000000> > >,std::shared_ptr<mrpt::serialization::CSerializable>>::*)() const) &std::multimap<std::chrono::time_point<mrpt::Clock, std::chrono::duration<int64_t, std::ratio<1, 10000000>>>, std::shared_ptr<mrpt::serialization::CSerializable>>::key_comp, "C++: std::multimap<std::chrono::time_point<mrpt::Clock, std::chrono::duration<int64_t, std::ratio<1, 10000000>>>, std::shared_ptr<mrpt::serialization::CSerializable>>::key_comp() const --> struct std::less<mrpt::Clock::time_point >");
cl.def("count", (size_t (std::multimap<std::chrono::time_point<mrpt::Clock, std::chrono::duration<int64_t, std::ratio<1, 10000000> > >,std::shared_ptr<mrpt::serialization::CSerializable>>::*)(const mrpt::Clock::time_point &) const) &std::multimap<std::chrono::time_point<mrpt::Clock, std::chrono::duration<int64_t, std::ratio<1, 10000000>>>, std::shared_ptr<mrpt::serialization::CSerializable>>::count, "C++: std::multimap<std::chrono::time_point<mrpt::Clock, std::chrono::duration<int64_t, std::ratio<1, 10000000>>>, std::shared_ptr<mrpt::serialization::CSerializable>>::count(const mrpt::Clock::time_point &) const --> size_t", pybind11::arg("__x"));
cl.def("equal_range", (struct std::pair<struct std::_Rb_tree_iterator<struct std::pair<const mrpt::Clock::time_point, class std::shared_ptr<class mrpt::serialization::CSerializable> > >, struct std::_Rb_tree_iterator<struct std::pair<const mrpt::Clock::time_point, class std::shared_ptr<class mrpt::serialization::CSerializable> > > > (std::multimap<std::chrono::time_point<mrpt::Clock, std::chrono::duration<int64_t, std::ratio<1, 10000000> > >,std::shared_ptr<mrpt::serialization::CSerializable>>::*)(const mrpt::Clock::time_point &)) &std::multimap<std::chrono::time_point<mrpt::Clock, std::chrono::duration<int64_t, std::ratio<1, 10000000>>>, std::shared_ptr<mrpt::serialization::CSerializable>>::equal_range, "C++: std::multimap<std::chrono::time_point<mrpt::Clock, std::chrono::duration<int64_t, std::ratio<1, 10000000>>>, std::shared_ptr<mrpt::serialization::CSerializable>>::equal_range(const mrpt::Clock::time_point &) --> struct std::pair<struct std::_Rb_tree_iterator<struct std::pair<const mrpt::Clock::time_point, class std::shared_ptr<class mrpt::serialization::CSerializable> > >, struct std::_Rb_tree_iterator<struct std::pair<const mrpt::Clock::time_point, class std::shared_ptr<class mrpt::serialization::CSerializable> > > >", pybind11::arg("__x"));
+
+ cl.def("__iter__", [](const std::multimap<std::chrono::time_point<mrpt::Clock, std::chrono::duration<int64_t, std::ratio<1, 10000000> > >,std::shared_ptr<mrpt::serialization::CSerializable>> &o) {
+ return pybind11::make_iterator(o.begin(), o.end());
+ }, pybind11::keep_alive<0, 1>());
}
{ // std::map file:bits/stl_map.h line:100
pybind11::class_<std::map<mrpt::containers::yaml::node_t,mrpt::containers::yaml::node_t>, std::shared_ptr<std::map<mrpt::containers::yaml::node_t,mrpt::containers::yaml::node_t>>> cl(M("std"), "map_mrpt_containers_yaml_node_t_mrpt_containers_yaml_node_t_t", "");
@@ -82,5 +86,9 @@ void bind_std_stl_multimap(std::function< pybind11::module &(std::string const &
cl.def("key_comp", (struct std::less<struct mrpt::containers::yaml::node_t> (std::map<mrpt::containers::yaml::node_t,mrpt::containers::yaml::node_t>::*)() const) &std::map<mrpt::containers::yaml::node_t, mrpt::containers::yaml::node_t>::key_comp, "C++: std::map<mrpt::containers::yaml::node_t, mrpt::containers::yaml::node_t>::key_comp() const --> struct std::less<struct mrpt::containers::yaml::node_t>");
cl.def("count", (size_t (std::map<mrpt::containers::yaml::node_t,mrpt::containers::yaml::node_t>::*)(const struct mrpt::containers::yaml::node_t &) const) &std::map<mrpt::containers::yaml::node_t, mrpt::containers::yaml::node_t>::count, "C++: std::map<mrpt::containers::yaml::node_t, mrpt::containers::yaml::node_t>::count(const struct mrpt::containers::yaml::node_t &) const --> size_t", pybind11::arg("__x"));
cl.def("equal_range", (struct std::pair<struct std::_Rb_tree_iterator<struct std::pair<const struct mrpt::containers::yaml::node_t, struct mrpt::containers::yaml::node_t> >, struct std::_Rb_tree_iterator<struct std::pair<const struct mrpt::containers::yaml::node_t, struct mrpt::containers::yaml::node_t> > > (std::map<mrpt::containers::yaml::node_t,mrpt::containers::yaml::node_t>::*)(const struct mrpt::containers::yaml::node_t &)) &std::map<mrpt::containers::yaml::node_t, mrpt::containers::yaml::node_t>::equal_range, "C++: std::map<mrpt::containers::yaml::node_t, mrpt::containers::yaml::node_t>::equal_range(const struct mrpt::containers::yaml::node_t &) --> struct std::pair<struct std::_Rb_tree_iterator<struct std::pair<const struct mrpt::containers::yaml::node_t, struct mrpt::containers::yaml::node_t> >, struct std::_Rb_tree_iterator<struct std::pair<const struct mrpt::containers::yaml::node_t, struct mrpt::containers::yaml::node_t> > >", pybind11::arg("__x"));
+
+ cl.def("__iter__", [](const std::map<mrpt::containers::yaml::node_t,mrpt::containers::yaml::node_t> &o) {
+ return pybind11::make_iterator(o.begin(), o.end());
+ }, pybind11::keep_alive<0, 1>());
}
}
diff --git a/python/src/std/stl_vector.cpp b/python/src/std/stl_vector.cpp
index f4c9f4013..6d067dc27 100644
--- a/python/src/std/stl_vector.cpp
+++ b/python/src/std/stl_vector.cpp
@@ -62,5 +62,9 @@ void bind_std_stl_vector(std::function< pybind11::module &(std::string const &na
cl.def("erase", (class __gnu_cxx::__normal_iterator<std::string *, class std::vector<std::string > > (std::vector<std::string>::*)(class __gnu_cxx::__normal_iterator<const std::string *, class std::vector<std::string > >, class __gnu_cxx::__normal_iterator<const std::string *, class std::vector<std::string > >)) &std::vector<std::string>::erase, "C++: std::vector<std::string>::erase(class __gnu_cxx::__normal_iterator<const std::string *, class std::vector<std::string > >, class __gnu_cxx::__normal_iterator<const std::string *, class std::vector<std::string > >) --> class __gnu_cxx::__normal_iterator<std::string *, class std::vector<std::string > >", pybind11::arg("__first"), pybind11::arg("__last"));
cl.def("swap", (void (std::vector<std::string>::*)(class std::vector<std::string > &)) &std::vector<std::string>::swap, "C++: std::vector<std::string>::swap(class std::vector<std::string > &) --> void", pybind11::arg("__x"));
cl.def("clear", (void (std::vector<std::string>::*)()) &std::vector<std::string>::clear, "C++: std::vector<std::string>::clear() --> void");
+
+ cl.def("__iter__", [](const std::vector<std::string> &o) {
+ return pybind11::make_iterator(o.begin(), o.end());
+ }, pybind11::keep_alive<0, 1>());
}
}
21 changes: 21 additions & 0 deletions python/patch-008.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff --git a/python/src/std/chrono.cpp b/python/src/std/chrono.cpp
index 17eaa6e50..4c07e8ce6 100644
--- a/python/src/std/chrono.cpp
+++ b/python/src/std/chrono.cpp
@@ -7,6 +7,7 @@
#include <pybind11/pybind11.h>
#include <string>
#include <pybind11/stl.h>
+#include <mrpt/system/datetime.h>


#ifndef BINDER_PYBIND11_TYPE_CASTER
@@ -50,5 +51,8 @@ void bind_std_chrono(std::function< pybind11::module &(std::string const &namesp
cl.def_static("min", (mrpt::Clock::time_point (*)()) &std::chrono::time_point<mrpt::Clock, std::chrono::duration<int64_t, std::ratio<1, 10000000>>>::min, "C++: std::chrono::time_point<mrpt::Clock, std::chrono::duration<int64_t, std::ratio<1, 10000000>>>::min() --> mrpt::Clock::time_point");
cl.def_static("max", (mrpt::Clock::time_point (*)()) &std::chrono::time_point<mrpt::Clock, std::chrono::duration<int64_t, std::ratio<1, 10000000>>>::max, "C++: std::chrono::time_point<mrpt::Clock, std::chrono::duration<int64_t, std::ratio<1, 10000000>>>::max() --> mrpt::Clock::time_point");
cl.def("assign", (mrpt::Clock::time_point & (mrpt::Clock::time_point::*)(const mrpt::Clock::time_point &)) &std::chrono::time_point<mrpt::Clock, std::chrono::duration<int64_t, std::ratio<1, 10000000>>>::operator=, "C++: std::chrono::time_point<mrpt::Clock, std::chrono::duration<int64_t, std::ratio<1, 10000000>>>::operator=(const mrpt::Clock::time_point &) --> mrpt::Clock::time_point &", pybind11::return_value_policy::automatic, pybind11::arg(""));
+
+ cl.def("to_double", [](const mrpt::Clock::time_point &t) { return mrpt::Clock::toDouble(t); });
+ cl.def("__str__", [](const mrpt::Clock::time_point &t) { return mrpt::system::dateTimeLocalToString(t); }, "Gets the date and time of the given timestamp in local time.");
}
}
4 changes: 4 additions & 0 deletions python/src/std/chrono.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <pybind11/pybind11.h>
#include <string>
#include <pybind11/stl.h>
#include <mrpt/system/datetime.h>


#ifndef BINDER_PYBIND11_TYPE_CASTER
Expand Down Expand Up @@ -50,5 +51,8 @@ void bind_std_chrono(std::function< pybind11::module &(std::string const &namesp
cl.def_static("min", (mrpt::Clock::time_point (*)()) &std::chrono::time_point<mrpt::Clock, std::chrono::duration<int64_t, std::ratio<1, 10000000>>>::min, "C++: std::chrono::time_point<mrpt::Clock, std::chrono::duration<int64_t, std::ratio<1, 10000000>>>::min() --> mrpt::Clock::time_point");
cl.def_static("max", (mrpt::Clock::time_point (*)()) &std::chrono::time_point<mrpt::Clock, std::chrono::duration<int64_t, std::ratio<1, 10000000>>>::max, "C++: std::chrono::time_point<mrpt::Clock, std::chrono::duration<int64_t, std::ratio<1, 10000000>>>::max() --> mrpt::Clock::time_point");
cl.def("assign", (mrpt::Clock::time_point & (mrpt::Clock::time_point::*)(const mrpt::Clock::time_point &)) &std::chrono::time_point<mrpt::Clock, std::chrono::duration<int64_t, std::ratio<1, 10000000>>>::operator=, "C++: std::chrono::time_point<mrpt::Clock, std::chrono::duration<int64_t, std::ratio<1, 10000000>>>::operator=(const mrpt::Clock::time_point &) --> mrpt::Clock::time_point &", pybind11::return_value_policy::automatic, pybind11::arg(""));

cl.def("to_double", [](const mrpt::Clock::time_point &t) { return mrpt::Clock::toDouble(t); });
cl.def("__str__", [](const mrpt::Clock::time_point &t) { return mrpt::system::dateTimeLocalToString(t); }, "Gets the date and time of the given timestamp in local time.");
}
}
Loading

0 comments on commit a7c7e87

Please sign in to comment.