pinocchio 4.1.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
Loading...
Searching...
No Matches
std-vector.hpp
1//
2// Copyright (c) 2016-2024 CNRS INRIA
3//
4
5#pragma once
6
7#include "pinocchio/bindings/python/fwd.hpp"
8
9#include <eigenpy/std-vector.hpp>
10#include <eigenpy/pickle-vector.hpp>
11
12#include <boost/python/def_visitor.hpp>
13
14#include <type_traits>
15
16namespace eigenpy
17{
18
19 template<typename Derived>
20 struct has_operator_equal<
21 Derived,
22 std::enable_if_t<std::is_base_of_v<::pinocchio::NumericalBase<Derived>, Derived>, Derived>>
23 : has_operator_equal<typename ::pinocchio::NumericalBase<Derived>::Scalar>
24 {
25 };
26
27 template<typename _Scalar, int _Rows, int _Cols, int _Options>
28 struct has_operator_equal<Eigen::Matrix<_Scalar, _Rows, _Cols, _Options>>
29 : has_operator_equal<typename Eigen::Matrix<_Scalar, _Rows, _Cols, _Options>::Scalar>
30 {
31 };
32
33} // namespace eigenpy
34
35namespace pinocchio
36{
37 namespace python
38 {
39 template<
40 class vector_type,
41 bool NoProxy = false,
42 bool EnableFromPythonListConverter = true,
43#ifdef PINOCCHIO_PYTHON_NO_SERIALIZATION
44 bool pickable = false>
45#else
46 bool pickable = true>
47#endif
48 using StdVectorPythonVisitor = eigenpy::
49 StdVectorPythonVisitor<vector_type, NoProxy, EnableFromPythonListConverter, pickable>;
50
51 template<typename MatType>
52 void exposeStdVectorEigenSpecificType(const char * name)
53 {
54 typedef std::vector<MatType> VecMatType;
55 std::string full_name = "StdVec_";
56 full_name += name;
57 StdVectorPythonVisitor<VecMatType>::expose(
58 full_name.c_str(), eigenpy::details::overload_base_get_item_for_std_vector<VecMatType>());
59 }
60
61 // Visitor to add default pickling method to an already registerd StdVector.
62 // Since eigenpy::registration_class doesn't support adding attribute, we must set
63 // __safe_for_unpickling__ and __getstate_manages_dict__ to true in the __init__.py.
64 // This visitor is intended to be use as eigenpy::register_symbolic_link_to_registered_type
65 // argument.
66 template<typename vector_type>
68 : public boost::python::def_visitor<DefPickleStdVectorVisitor<vector_type>>
69 {
70 template<class PyClass>
71 void visit(PyClass & cl) const
72 {
73#ifndef PINOCCHIO_PYTHON_NO_SERIALIZATION
74 typedef eigenpy::PickleVector<vector_type> PickleSuiteType;
75 cl.def("__getinitargs__", &PickleSuiteType::getinitargs);
76 cl.def("__getstate__", &PickleSuiteType::getstate);
77 cl.def("__setstate__", &PickleSuiteType::setstate);
78#else
79 PINOCCHIO_UNUSED_VARIABLE(cl);
80#endif
81 }
82 };
83 } // namespace python
84} // namespace pinocchio
Main pinocchio namespace.
Definition treeview.dox:11