GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/core/action-base.hpp
Date: 2025-01-16 08:47:40
Exec Total Coverage
Lines: 27 45 60.0%
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_ACTION_BASE_HPP_
11 #define BINDINGS_PYTHON_CROCODDYL_CORE_ACTION_BASE_HPP_
12
13 #include "crocoddyl/core/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 ActionModelAbstract_wrap : public ActionModelAbstract,
21 public bp::wrapper<ActionModelAbstract> {
22 public:
23 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
24 using ActionModelAbstract::ng_;
25 using ActionModelAbstract::ng_T_;
26 using ActionModelAbstract::nh_;
27 using ActionModelAbstract::nh_T_;
28 using ActionModelAbstract::nu_;
29 using ActionModelAbstract::unone_;
30
31 8 ActionModelAbstract_wrap(boost::shared_ptr<StateAbstract> state,
32 const std::size_t nu, const std::size_t nr = 1,
33 const std::size_t ng = 0, const std::size_t nh = 0,
34 const std::size_t ng_T = 0,
35 const std::size_t nh_T = 0)
36 8 : ActionModelAbstract(state, nu, nr, ng, nh, ng_T, nh_T),
37
1/2
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 bp::wrapper<ActionModelAbstract>() {
38
3/6
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 8 times.
✗ Branch 8 not taken.
8 unone_ = NAN * MathBase::VectorXs::Ones(nu);
39 8 }
40
41 108 void calc(const boost::shared_ptr<ActionDataAbstract>& data,
42 const Eigen::Ref<const Eigen::VectorXd>& x,
43 const Eigen::Ref<const Eigen::VectorXd>& u) {
44
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 108 times.
108 if (static_cast<std::size_t>(x.size()) != state_->get_nx()) {
45 throw_pretty(
46 "Invalid argument: " << "x has wrong dimension (it should be " +
47 std::to_string(state_->get_nx()) + ")");
48 }
49
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 108 times.
108 if (static_cast<std::size_t>(u.size()) != nu_) {
50 throw_pretty(
51 "Invalid argument: " << "u has wrong dimension (it should be " +
52 std::to_string(nu_) + ")");
53 }
54
2/2
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 105 times.
108 if (std::isnan(u.lpNorm<Eigen::Infinity>())) {
55
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,
56 6 (Eigen::VectorXd)x);
57 } else {
58
2/4
✓ Branch 1 taken 105 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 105 times.
✗ Branch 6 not taken.
105 return bp::call<void>(this->get_override("calc").ptr(), data,
59
1/2
✓ Branch 2 taken 105 times.
✗ Branch 3 not taken.
210 (Eigen::VectorXd)x, (Eigen::VectorXd)u);
60 }
61 }
62
63 10 void calcDiff(const boost::shared_ptr<ActionDataAbstract>& data,
64 const Eigen::Ref<const Eigen::VectorXd>& x,
65 const Eigen::Ref<const Eigen::VectorXd>& u) {
66
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
10 if (static_cast<std::size_t>(x.size()) != state_->get_nx()) {
67 throw_pretty(
68 "Invalid argument: " << "x has wrong dimension (it should be " +
69 std::to_string(state_->get_nx()) + ")");
70 }
71
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
10 if (static_cast<std::size_t>(u.size()) != nu_) {
72 throw_pretty(
73 "Invalid argument: " << "u has wrong dimension (it should be " +
74 std::to_string(nu_) + ")");
75 }
76
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 9 times.
10 if (std::isnan(u.lpNorm<Eigen::Infinity>())) {
77
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,
78 2 (Eigen::VectorXd)x);
79 } else {
80
2/4
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 9 times.
✗ Branch 6 not taken.
9 return bp::call<void>(this->get_override("calcDiff").ptr(), data,
81
1/2
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
18 (Eigen::VectorXd)x, (Eigen::VectorXd)u);
82 }
83 }
84
85 153 boost::shared_ptr<ActionDataAbstract> createData() {
86 153 enableMultithreading() = false;
87
3/6
✓ Branch 1 taken 153 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 153 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 153 times.
✗ Branch 7 not taken.
153 if (boost::python::override createData = this->get_override("createData")) {
88
1/2
✓ Branch 2 taken 153 times.
✗ Branch 3 not taken.
153 return bp::call<boost::shared_ptr<ActionDataAbstract> >(createData.ptr());
89
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 153 times.
153 }
90 return ActionModelAbstract::createData();
91 }
92
93 boost::shared_ptr<ActionDataAbstract> default_createData() {
94 return this->ActionModelAbstract::createData();
95 }
96
97 void quasiStatic(const boost::shared_ptr<ActionDataAbstract>& data,
98 Eigen::Ref<Eigen::VectorXd> u,
99 const Eigen::Ref<const Eigen::VectorXd>& x,
100 const std::size_t maxiter, const double tol) {
101 if (boost::python::override quasiStatic =
102 this->get_override("quasiStatic")) {
103 u = bp::call<Eigen::VectorXd>(quasiStatic.ptr(), data, (Eigen::VectorXd)x,
104 maxiter, tol);
105 if (static_cast<std::size_t>(u.size()) != nu_) {
106 throw_pretty(
107 "Invalid argument: " << "u has wrong dimension (it should be " +
108 std::to_string(nu_) + ")");
109 }
110 return;
111 }
112 return ActionModelAbstract::quasiStatic(data, u, x, maxiter, tol);
113 }
114
115 void default_quasiStatic(const boost::shared_ptr<ActionDataAbstract>& data,
116 Eigen::Ref<Eigen::VectorXd> u,
117 const Eigen::Ref<const Eigen::VectorXd>& x,
118 const std::size_t maxiter, const double tol) {
119 return this->ActionModelAbstract::quasiStatic(data, u, x, maxiter, tol);
120 }
121 };
122
123 20 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(ActionModel_quasiStatic_wraps,
124 ActionModelAbstract::quasiStatic_x, 2, 4)
125
126 } // namespace python
127 } // namespace crocoddyl
128
129 #endif // BINDINGS_PYTHON_CROCODDYL_CORE_ACTION_BASE_HPP_
130