aligator  0.6.1
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
blk-matrix.hpp
Go to the documentation of this file.
1#include "fwd.hpp"
3
4namespace aligator {
5namespace python {
6namespace bp = boost::python;
7
8template <typename BlockMatrixType>
10 : bp::def_visitor<BlkMatrixPythonVisitor<BlockMatrixType>> {
11
12 enum { N = BlockMatrixType::N, M = BlockMatrixType::M };
13 using MatrixType = typename BlockMatrixType::MatrixType;
14 using RefType = Eigen::Ref<MatrixType>;
15
16 using Self = BlkMatrixPythonVisitor<BlockMatrixType>;
17
18 static RefType get_block(BlockMatrixType &bmt, size_t i, size_t j) {
19 return bmt(i, j);
20 }
21
22 static RefType blockRow(BlockMatrixType &mat, size_t i) {
23 if (i >= mat.rowDims().size()) {
24 PyErr_SetString(PyExc_IndexError, "Index out of range.");
25 bp::throw_error_already_set();
26 }
27 return mat.blockRow(i);
28 }
29
30 template <class... Args> void visit(bp::class_<Args...> &obj) const {
31 obj.add_property(
32 "matrix", +[](BlockMatrixType &m) -> RefType { return m.matrix(); })
33 .def_readonly("rows", &BlockMatrixType::rows)
34 .def_readonly("cols", &BlockMatrixType::cols)
35 .add_property("rowDims",
36 bp::make_function(&BlockMatrixType::rowDims,
37 bp::return_internal_reference<>()))
38 .add_property("colDims",
39 bp::make_function(&BlockMatrixType::colDims,
40 bp::return_internal_reference<>()))
41 .def("blockRow", blockRow, "Get a block row by index.")
42 .def("__call__", get_block, ("self"_a, "i", "j"));
43 }
44
45 static void expose(const char *name) {
46 bp::class_<BlockMatrixType>(name, "", bp::no_init).def(Self());
47 }
48};
49
50} // namespace python
51} // namespace aligator
Main package namespace.
static void expose(const char *name)
typename BlockMatrixType::MatrixType MatrixType
BlkMatrixPythonVisitor< BlockMatrixType > Self
static RefType blockRow(BlockMatrixType &mat, size_t i)
void visit(bp::class_< Args... > &obj) const
static RefType get_block(BlockMatrixType &bmt, size_t i, size_t j)