Directory: | ./ |
---|---|
File: | bindings/python/crocoddyl/core/diff-action-base.hpp |
Date: | 2025-01-16 08:47:40 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 27 | 47 | 57.4% |
Branches: | 27 | 150 | 18.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2019-2024, LAAS-CNRS, University of Edinburgh, | ||
5 | // Heriot-Watt University | ||
6 | // Copyright note valid unless otherwise stated in individual files. | ||
7 | // All rights reserved. | ||
8 | /////////////////////////////////////////////////////////////////////////////// | ||
9 | |||
10 | #ifndef BINDINGS_PYTHON_CROCODDYL_CORE_DIFF_ACTION_BASE_HPP_ | ||
11 | #define BINDINGS_PYTHON_CROCODDYL_CORE_DIFF_ACTION_BASE_HPP_ | ||
12 | |||
13 | #include "crocoddyl/core/diff-action-base.hpp" | ||
14 | #include "crocoddyl/core/utils/exception.hpp" | ||
15 | #include "python/crocoddyl/core/core.hpp" | ||
16 | |||
17 | namespace crocoddyl { | ||
18 | namespace python { | ||
19 | |||
20 | class DifferentialActionModelAbstract_wrap | ||
21 | : public DifferentialActionModelAbstract, | ||
22 | public bp::wrapper<DifferentialActionModelAbstract> { | ||
23 | public: | ||
24 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW | ||
25 | using DifferentialActionModelAbstract::unone_; | ||
26 | |||
27 | 6 | DifferentialActionModelAbstract_wrap(boost::shared_ptr<StateAbstract> state, | |
28 | const std::size_t nu, | ||
29 | const std::size_t nr = 1, | ||
30 | const std::size_t ng = 0, | ||
31 | const std::size_t nh = 0, | ||
32 | const std::size_t ng_T = 0, | ||
33 | const std::size_t nh_T = 0) | ||
34 | 6 | : DifferentialActionModelAbstract(state, nu, nr, ng, nh, ng_T, nh_T), | |
35 |
1/2✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
6 | bp::wrapper<DifferentialActionModelAbstract>() { |
36 |
3/6✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 6 times.
✗ Branch 8 not taken.
|
6 | unone_ = NAN * MathBase::VectorXs::Ones(nu); |
37 | 6 | } | |
38 | |||
39 | 242 | void calc(const boost::shared_ptr<DifferentialActionDataAbstract>& data, | |
40 | const Eigen::Ref<const Eigen::VectorXd>& x, | ||
41 | const Eigen::Ref<const Eigen::VectorXd>& u) { | ||
42 |
1/2✗ Branch 3 not taken.
✓ Branch 4 taken 242 times.
|
242 | if (static_cast<std::size_t>(x.size()) != state_->get_nx()) { |
43 | ✗ | throw_pretty( | |
44 | "Invalid argument: " << "x has wrong dimension (it should be " + | ||
45 | std::to_string(state_->get_nx()) + ")"); | ||
46 | } | ||
47 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 242 times.
|
242 | if (static_cast<std::size_t>(u.size()) != nu_) { |
48 | ✗ | throw_pretty( | |
49 | "Invalid argument: " << "u has wrong dimension (it should be " + | ||
50 | std::to_string(nu_) + ")"); | ||
51 | } | ||
52 |
2/2✓ Branch 2 taken 3 times.
✓ Branch 3 taken 239 times.
|
242 | if (std::isnan(u.lpNorm<Eigen::Infinity>())) { |
53 |
2/4✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
|
3 | return bp::call<void>(this->get_override("calc").ptr(), data, |
54 | 6 | (Eigen::VectorXd)x); | |
55 | } else { | ||
56 |
2/4✓ Branch 1 taken 239 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 239 times.
✗ Branch 6 not taken.
|
239 | return bp::call<void>(this->get_override("calc").ptr(), data, |
57 |
1/2✓ Branch 2 taken 239 times.
✗ Branch 3 not taken.
|
478 | (Eigen::VectorXd)x, (Eigen::VectorXd)u); |
58 | } | ||
59 | } | ||
60 | |||
61 | 78 | void calcDiff(const boost::shared_ptr<DifferentialActionDataAbstract>& data, | |
62 | const Eigen::Ref<const Eigen::VectorXd>& x, | ||
63 | const Eigen::Ref<const Eigen::VectorXd>& u) { | ||
64 |
1/2✗ Branch 3 not taken.
✓ Branch 4 taken 78 times.
|
78 | if (static_cast<std::size_t>(x.size()) != state_->get_nx()) { |
65 | ✗ | throw_pretty( | |
66 | "Invalid argument: " << "x has wrong dimension (it should be " + | ||
67 | std::to_string(state_->get_nx()) + ")"); | ||
68 | } | ||
69 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 78 times.
|
78 | if (static_cast<std::size_t>(u.size()) != nu_) { |
70 | ✗ | throw_pretty( | |
71 | "Invalid argument: " << "u has wrong dimension (it should be " + | ||
72 | std::to_string(nu_) + ")"); | ||
73 | } | ||
74 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 77 times.
|
78 | if (std::isnan(u.lpNorm<Eigen::Infinity>())) { |
75 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
1 | return bp::call<void>(this->get_override("calcDiff").ptr(), data, |
76 | 2 | (Eigen::VectorXd)x); | |
77 | } else { | ||
78 |
2/4✓ Branch 1 taken 77 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 77 times.
✗ Branch 6 not taken.
|
77 | return bp::call<void>(this->get_override("calcDiff").ptr(), data, |
79 |
1/2✓ Branch 2 taken 77 times.
✗ Branch 3 not taken.
|
154 | (Eigen::VectorXd)x, (Eigen::VectorXd)u); |
80 | } | ||
81 | } | ||
82 | |||
83 | 265 | boost::shared_ptr<DifferentialActionDataAbstract> createData() { | |
84 | 265 | enableMultithreading() = false; | |
85 |
3/6✓ Branch 1 taken 265 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 265 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 265 times.
✗ Branch 7 not taken.
|
265 | if (boost::python::override createData = this->get_override("createData")) { |
86 | return bp::call<boost::shared_ptr<DifferentialActionDataAbstract> >( | ||
87 |
1/2✓ Branch 2 taken 265 times.
✗ Branch 3 not taken.
|
265 | createData.ptr()); |
88 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 265 times.
|
265 | } |
89 | ✗ | return DifferentialActionModelAbstract::createData(); | |
90 | } | ||
91 | |||
92 | ✗ | boost::shared_ptr<DifferentialActionDataAbstract> default_createData() { | |
93 | ✗ | return this->DifferentialActionModelAbstract::createData(); | |
94 | } | ||
95 | |||
96 | ✗ | void quasiStatic( | |
97 | const boost::shared_ptr<DifferentialActionDataAbstract>& data, | ||
98 | Eigen::Ref<Eigen::VectorXd> u, const Eigen::Ref<const Eigen::VectorXd>& x, | ||
99 | const std::size_t maxiter, const double tol) { | ||
100 | ✗ | if (boost::python::override quasiStatic = | |
101 | ✗ | this->get_override("quasiStatic")) { | |
102 | ✗ | u = bp::call<Eigen::VectorXd>(quasiStatic.ptr(), data, (Eigen::VectorXd)x, | |
103 | ✗ | maxiter, tol); | |
104 | ✗ | if (static_cast<std::size_t>(u.size()) != nu_) { | |
105 | ✗ | throw_pretty( | |
106 | "Invalid argument: " << "u has wrong dimension (it should be " + | ||
107 | std::to_string(nu_) + ")"); | ||
108 | } | ||
109 | ✗ | return; | |
110 | } | ||
111 | ✗ | return DifferentialActionModelAbstract::quasiStatic(data, u, x, maxiter, | |
112 | ✗ | tol); | |
113 | } | ||
114 | |||
115 | ✗ | void default_quasiStatic( | |
116 | const boost::shared_ptr<DifferentialActionDataAbstract>& data, | ||
117 | Eigen::Ref<Eigen::VectorXd> u, const Eigen::Ref<const Eigen::VectorXd>& x, | ||
118 | const std::size_t maxiter, const double tol) { | ||
119 | ✗ | return this->DifferentialActionModelAbstract::quasiStatic(data, u, x, | |
120 | ✗ | maxiter, tol); | |
121 | } | ||
122 | }; | ||
123 | |||
124 | 20 | BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS( | |
125 | DifferentialActionModel_quasiStatic_wraps, | ||
126 | DifferentialActionModelAbstract::quasiStatic_x, 2, 4) | ||
127 | |||
128 | } // namespace python | ||
129 | } // namespace crocoddyl | ||
130 | |||
131 | #endif // BINDINGS_PYTHON_CROCODDYL_CORE_DIFF_ACTION_BASE_HPP_ | ||
132 |