-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #325 from ManifoldFR/wj/move-std-vector
Copy std-vector and std-map from Pinocchio
- Loading branch information
Showing
17 changed files
with
877 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule cmake
updated
4 files
+3 −3 | .pre-commit-config.yaml | |
+14 −5 | find-external/Simde/FindSimde.cmake | |
+1 −1 | find-external/qpOASES/FindqpOASES.cmake | |
+3 −1 | test.cmake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// Copyright (c) 2016-2021 CNRS INRIA | ||
// | ||
|
||
#ifndef __eigenpy_utils_copyable_hpp__ | ||
#define __eigenpy_utils_copyable_hpp__ | ||
|
||
#include <boost/python.hpp> | ||
|
||
namespace eigenpy { | ||
|
||
namespace bp = boost::python; | ||
|
||
/// | ||
/// \brief Add the Python method copy to allow a copy of this by calling the | ||
/// copy constructor. | ||
/// | ||
template <class C> | ||
struct CopyableVisitor : public bp::def_visitor<CopyableVisitor<C> > { | ||
template <class PyClass> | ||
void visit(PyClass& cl) const { | ||
cl.def("copy", ©, bp::arg("self"), "Returns a copy of *this."); | ||
} | ||
|
||
private: | ||
static C copy(const C& self) { return C(self); } | ||
}; | ||
} // namespace eigenpy | ||
|
||
#endif // ifndef __eigenpy_utils_copyable_hpp__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// Copyright (c) 2019-2020 CNRS INRIA | ||
// | ||
|
||
#ifndef __eigenpy_utils_pickle_vector_hpp__ | ||
#define __eigenpy_utils_pickle_vector_hpp__ | ||
|
||
#include <boost/python.hpp> | ||
#include <boost/python/stl_iterator.hpp> | ||
#include <boost/python/tuple.hpp> | ||
|
||
namespace eigenpy { | ||
/// | ||
/// \brief Create a pickle interface for the std::vector | ||
/// | ||
/// \tparam VecType Vector Type to pickle | ||
/// | ||
template <typename VecType> | ||
struct PickleVector : boost::python::pickle_suite { | ||
static boost::python::tuple getinitargs(const VecType&) { | ||
return boost::python::make_tuple(); | ||
} | ||
|
||
static boost::python::tuple getstate(boost::python::object op) { | ||
return boost::python::make_tuple( | ||
boost::python::list(boost::python::extract<const VecType&>(op)())); | ||
} | ||
|
||
static void setstate(boost::python::object op, boost::python::tuple tup) { | ||
if (boost::python::len(tup) > 0) { | ||
VecType& o = boost::python::extract<VecType&>(op)(); | ||
boost::python::stl_input_iterator<typename VecType::value_type> begin( | ||
tup[0]), | ||
end; | ||
while (begin != end) { | ||
o.push_back(*begin); | ||
++begin; | ||
} | ||
} | ||
} | ||
|
||
static bool getstate_manages_dict() { return true; } | ||
}; | ||
} // namespace eigenpy | ||
|
||
#endif // ifndef __eigenpy_utils_pickle_vector_hpp__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/// Copyright (c) 2016-2022 CNRS INRIA | ||
/// This file was taken from Pinocchio (header | ||
/// <pinocchio/bindings/python/utils/std-vector.hpp>) | ||
/// | ||
|
||
#ifndef __eigenpy_utils_map_hpp__ | ||
#define __eigenpy_utils_map_hpp__ | ||
|
||
#include <boost/python/suite/indexing/map_indexing_suite.hpp> | ||
|
||
namespace eigenpy { | ||
namespace details { | ||
template <typename Container> | ||
struct overload_base_get_item_for_std_map | ||
: public boost::python::def_visitor< | ||
overload_base_get_item_for_std_map<Container> > { | ||
typedef typename Container::value_type value_type; | ||
typedef typename Container::value_type::second_type data_type; | ||
typedef typename Container::key_type key_type; | ||
typedef typename Container::key_type index_type; | ||
|
||
template <class Class> | ||
void visit(Class& cl) const { | ||
cl.def("__getitem__", &base_get_item); | ||
} | ||
|
||
private: | ||
static boost::python::object base_get_item( | ||
boost::python::back_reference<Container&> container, PyObject* i_) { | ||
namespace bp = ::boost::python; | ||
|
||
index_type idx = convert_index(container.get(), i_); | ||
typename Container::iterator i = container.get().find(idx); | ||
if (i == container.get().end()) { | ||
PyErr_SetString(PyExc_KeyError, "Invalid key"); | ||
bp::throw_error_already_set(); | ||
} | ||
|
||
typename bp::to_python_indirect<data_type&, | ||
bp::detail::make_reference_holder> | ||
convert; | ||
return bp::object(bp::handle<>(convert(i->second))); | ||
} | ||
|
||
static index_type convert_index(Container& /*container*/, PyObject* i_) { | ||
namespace bp = ::boost::python; | ||
bp::extract<key_type const&> i(i_); | ||
if (i.check()) { | ||
return i(); | ||
} else { | ||
bp::extract<key_type> i(i_); | ||
if (i.check()) return i(); | ||
} | ||
|
||
PyErr_SetString(PyExc_TypeError, "Invalid index type"); | ||
bp::throw_error_already_set(); | ||
return index_type(); | ||
} | ||
}; | ||
|
||
} // namespace details | ||
} // namespace eigenpy | ||
|
||
#endif // ifndef __eigenpy_utils_map_hpp__ |
Oops, something went wrong.