aligator  0.14.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
eigen-member.hpp
Go to the documentation of this file.
1
2#pragma once
3
4#include <Eigen/Core>
5#include <boost/python.hpp>
6#include <boost/python/class.hpp>
7#include <boost/python/return_value_policy.hpp>
8
9#include <fmt/ostream.h>
10
11namespace aligator {
12namespace python {
13
14namespace bp = boost::python;
15
16namespace internal {
17
21template <typename MatrixType, typename Class> struct eigen_member {
22public:
23 typedef Eigen::Ref<const MatrixType> ConstMatRef;
24
25 eigen_member(MatrixType Class::*which)
26 : m_which(which) {}
27
28 Eigen::Ref<MatrixType> operator()(Class &c) const { return c.*m_which; }
29
30 void operator()(Class &c,
31 typename bp::detail::value_arg<ConstMatRef>::type d) const {
32 c.*m_which = d;
33 }
34
35private:
36 MatrixType Class::*m_which;
37};
38
39} // namespace internal
40
45template <class C, class MatrixType>
46bp::object make_getter_eigen_matrix(MatrixType C::*v) {
47 typedef Eigen::Ref<MatrixType> RefType;
48 return bp::make_function(
49 internal::eigen_member<MatrixType, C>(v),
50 bp::return_value_policy<bp::return_by_value,
51 bp::with_custodian_and_ward_postcall<0UL, 1UL>>(),
52 boost::mpl::vector2<RefType, C &>());
53}
54
55template <class C, class MatrixType, class Policies>
56bp::object make_setter_eigen_matrix(MatrixType C::*v,
57 Policies const &policies) {
58 typedef Eigen::Ref<const MatrixType> ConstRefType;
59 return bp::make_function(
60 internal::eigen_member<MatrixType, C>(v), policies,
61 boost::mpl::vector3<void, C &, const ConstRefType>());
62}
63
64template <class C, class MatrixType>
65bp::object make_setter_eigen_matrix(MatrixType C::*v) {
66 return make_setter_eigen_matrix(v, bp::default_call_policies());
67}
68
69} // namespace python
70} // namespace aligator
The Python bindings.
Definition blk-matrix.hpp:5
bp::object make_setter_eigen_matrix(MatrixType C::*v, Policies const &policies)
bp::object make_getter_eigen_matrix(MatrixType C::*v)
Create a getter for Eigen::Matrix type objects which returns an Eigen::Ref.
Main package namespace.