Skip to content

Commit 11d3de1

Browse files
committed
[python/gar] Separate out how utils are exposed
1 parent ab1d956 commit 11d3de1

File tree

2 files changed

+40
-25
lines changed

2 files changed

+40
-25
lines changed

bindings/python/src/gar/expose-gar.cpp

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "aligator/python/blk-matrix.hpp"
44
#include "aligator/gar/lqr-problem.hpp"
55
#include "aligator/gar/riccati-base.hpp"
6-
#include "aligator/gar/utils.hpp"
76

87
#include "aligator/python/utils.hpp"
98
#include "aligator/python/visitors.hpp"
@@ -24,17 +23,6 @@ using context::VectorXs;
2423

2524
using knot_vec_t = lqr_t::KnotVector;
2625

27-
bp::dict lqr_sol_initialize_wrap(const lqr_t &problem) {
28-
bp::dict out;
29-
auto ss = lqrInitializeSolution(problem);
30-
auto &[xs, us, vs, lbdas] = ss;
31-
out["xs"] = xs;
32-
out["us"] = us;
33-
out["vs"] = vs;
34-
out["lbdas"] = lbdas;
35-
return out;
36-
}
37-
3826
static void exposeBlockMatrices() {
3927
BlkMatrixPythonVisitor<BlkMatrix<MatrixXs, 2, 2>>::expose("BlockMatrix22");
4028
BlkMatrixPythonVisitor<BlkMatrix<VectorXs, 4, 1>>::expose("BlockVector4");
@@ -61,6 +49,8 @@ void exposeParallelSolver();
6149
void exposeDenseSolver();
6250
// fwd-declare exposeProxRiccati()
6351
void exposeProxRiccati();
52+
// fwd-declare exposeGarUtils()
53+
void exposeGarUtils();
6454

6555
void exposeGAR() {
6656

@@ -129,19 +119,7 @@ void exposeGAR() {
129119
.def("forward", &riccati_base_t::forward,
130120
("self"_a, "xs", "us", "vs", "lbdas", "theta"_a = std::nullopt));
131121

132-
bp::def(
133-
"lqrDenseMatrix",
134-
+[](const lqr_t &problem, Scalar mudyn, Scalar mueq) {
135-
auto mat_rhs = lqrDenseMatrix(problem, mudyn, mueq);
136-
return bp::make_tuple(std::get<0>(mat_rhs), std::get<1>(mat_rhs));
137-
},
138-
("problem"_a, "mudyn", "mueq"));
139-
140-
bp::def("lqrCreateSparseMatrix", lqrCreateSparseMatrix<Scalar>,
141-
("problem"_a, "mudyn", "mueq", "mat", "rhs", "update"),
142-
"Create or update a sparse matrix from an LQRProblem.");
143-
144-
bp::def("lqrInitializeSolution", lqr_sol_initialize_wrap, ("problem"_a));
122+
exposeGarUtils();
145123

146124
#ifdef ALIGATOR_WITH_CHOLMOD
147125
exposeCholmodSolver();
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include "aligator/python/fwd.hpp"
2+
#include "aligator/gar/utils.hpp"
3+
4+
namespace aligator::python {
5+
using namespace gar;
6+
7+
using context::Scalar;
8+
using lqr_t = LQRProblemTpl<context::Scalar>;
9+
10+
bp::dict lqr_sol_initialize_wrap(const lqr_t &problem) {
11+
bp::dict out;
12+
auto ss = lqrInitializeSolution(problem);
13+
auto &[xs, us, vs, lbdas] = ss;
14+
out["xs"] = xs;
15+
out["us"] = us;
16+
out["vs"] = vs;
17+
out["lbdas"] = lbdas;
18+
return out;
19+
}
20+
21+
void exposeGarUtils() {
22+
23+
bp::def(
24+
"lqrDenseMatrix",
25+
+[](const lqr_t &problem, Scalar mudyn, Scalar mueq) {
26+
auto mat_rhs = lqrDenseMatrix(problem, mudyn, mueq);
27+
return bp::make_tuple(std::get<0>(mat_rhs), std::get<1>(mat_rhs));
28+
},
29+
("problem"_a, "mudyn", "mueq"));
30+
31+
bp::def("lqrCreateSparseMatrix", lqrCreateSparseMatrix<Scalar>,
32+
("problem"_a, "mudyn", "mueq", "mat", "rhs", "update"),
33+
"Create or update a sparse matrix from an LQRProblem.");
34+
35+
bp::def("lqrInitializeSolution", lqr_sol_initialize_wrap, ("problem"_a));
36+
}
37+
} // namespace aligator::python

0 commit comments

Comments
 (0)