aligator  0.16.0
A versatile and efficient C++ library for real-time constrained trajectory optimization.
Loading...
Searching...
No Matches
blk-matrix.hpp
Go to the documentation of this file.
1
3#include "fwd.hpp"
5
6namespace aligator {
7namespace python {
8namespace bp = boost::python;
9
10template <typename T> struct PrintableVisitor;
11
12template <typename BlockMatrixType> struct BlkMatrixPythonVisitor;
13
14template <typename MatrixType, int N, int M>
15struct BlkMatrixPythonVisitor<BlkMatrix<MatrixType, N, M>>
16 : bp::def_visitor<BlkMatrixPythonVisitor<BlkMatrix<MatrixType, N, M>>> {
18 using RefType = Eigen::Ref<MatrixType>;
20
22
23 static RefType get_block(BlockMatrixType &bmt, size_t i, size_t j) {
24 return bmt(i, j);
25 }
26
27 static RefType get_block2(BlockMatrixType &bmt, size_t i) { return bmt[i]; }
28
29 static RefType blockRow(BlockMatrixType &mat, size_t i) {
30 if (i >= mat.rowDims().size()) {
31 PyErr_SetString(PyExc_IndexError, "Index out of range.");
32 bp::throw_error_already_set();
33 }
34 return mat.blockRow(i);
35 }
36
37 static RefType blockCol(BlockMatrixType &mat, size_t i) {
38 if (i >= mat.rowDims().size()) {
39 PyErr_SetString(PyExc_IndexError, "Index out of range.");
40 bp::throw_error_already_set();
41 }
42 return mat.blockCol(i);
43 }
44
45 template <class... Args> void visit(bp::class_<Args...> &obj) const {
46 obj.add_property(
47 "matrix", +[](BlockMatrixType &m) -> RefType { return m.matrix(); })
48 .add_property("rows", &BlockMatrixType::rows)
49 .add_property("cols", &BlockMatrixType::cols)
50 .add_property("rowDims",
51 bp::make_function(&BlockMatrixType::rowDims,
52 bp::return_internal_reference<>()))
53 .add_property("colDims",
54 bp::make_function(&BlockMatrixType::colDims,
55 bp::return_internal_reference<>()))
56 .def("blockRow", blockRow, "Get a block row by index.")
57 .def("blockCol", blockCol, "Get a block row by index.")
58 .def("setZero", &BlockMatrixType::setZero, ("self"_a),
59 "Set all coefficients to zero.")
60 .def("__call__", get_block, ("self"_a, "i", "j"))
63 obj.def("__call__", get_block2, ("self"_a, "i"));
64 }
65 }
66
67 static void expose(const char *name) {
68 bp::class_<BlockMatrixType>(name, "", bp::no_init).def(Self());
69 }
70};
71
72} // namespace python
73} // namespace aligator
Block matrix class, with a fixed or dynamic-size number of row and column blocks.
const ColDimsType & colDims() const
static constexpr bool IsVectorAtCompileTime
auto blockRow(size_t i)
MatrixType & matrix()
const RowDimsType & rowDims() const
auto blockCol(size_t j) const
The Python bindings.
Definition blk-matrix.hpp:7
Main package namespace.
static RefType get_block2(BlockMatrixType &bmt, size_t i)
static RefType get_block(BlockMatrixType &bmt, size_t i, size_t j)