aligator  0.6.1
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) : m_which(which) {}
26
27 Eigen::Ref<MatrixType> operator()(Class &c) const { return c.*m_which; }
28
29 void operator()(Class &c,
30 typename bp::detail::value_arg<ConstMatRef>::type d) const {
31 c.*m_which = d;
32 }
33
34private:
35 MatrixType Class::*m_which;
36};
37
38} // namespace internal
39
44template <class C, class MatrixType>
45bp::object make_getter_eigen_matrix(MatrixType C::*v) {
46 typedef Eigen::Ref<MatrixType> RefType;
47 return bp::make_function(
48 internal::eigen_member<MatrixType, C>(v),
49 bp::return_value_policy<bp::return_by_value,
50 bp::with_custodian_and_ward_postcall<0UL, 1UL>>(),
51 boost::mpl::vector2<RefType, C &>());
52}
53
54template <class C, class MatrixType, class Policies>
55bp::object make_setter_eigen_matrix(MatrixType C::*v,
56 Policies const &policies) {
57 typedef Eigen::Ref<const MatrixType> ConstRefType;
58 return bp::make_function(
59 internal::eigen_member<MatrixType, C>(v), policies,
60 boost::mpl::vector3<void, C &, const ConstRefType>());
61}
62
63template <class C, class MatrixType>
64bp::object make_setter_eigen_matrix(MatrixType C::*v) {
65 return make_setter_eigen_matrix(v, bp::default_call_policies());
66}
67
68} // namespace python
69} // namespace aligator
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.