GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/core/diff-action-base.hpp
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 25 46 54.3%
Branches: 26 154 16.9%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2025, 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 "python/crocoddyl/core/core.hpp"
15
16 namespace crocoddyl {
17 namespace python {
18
19 template <typename _Scalar>
20 class DifferentialActionModelAbstractTpl_wrap
21 : public DifferentialActionModelAbstractTpl<_Scalar>,
22 public bp::wrapper<DifferentialActionModelAbstractTpl<_Scalar>> {
23 public:
24 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
25 CROCODDYL_DERIVED_CAST(DifferentialActionModelBase,
26 DifferentialActionModelAbstractTpl_wrap)
27
28 typedef _Scalar Scalar;
29 typedef typename ScalarSelector<Scalar>::type ScalarType;
30 typedef typename crocoddyl::DifferentialActionModelAbstractTpl<Scalar>
31 DifferentialActionModel;
32 typedef typename crocoddyl::DifferentialActionDataAbstractTpl<Scalar>
33 DifferentialActionData;
34 typedef typename crocoddyl::StateAbstractTpl<Scalar> State;
35 typedef typename DifferentialActionModel::VectorXs VectorXs;
36 using DifferentialActionModel::ng_;
37 using DifferentialActionModel::ng_T_;
38 using DifferentialActionModel::nh_;
39 using DifferentialActionModel::nh_T_;
40 using DifferentialActionModel::nr_;
41 using DifferentialActionModel::nu_;
42 using DifferentialActionModel::state_;
43 using DifferentialActionModel::unone_;
44
45 12 DifferentialActionModelAbstractTpl_wrap(std::shared_ptr<State> state,
46 const std::size_t nu,
47 const std::size_t nr = 1,
48 const std::size_t ng = 0,
49 const std::size_t nh = 0,
50 const std::size_t ng_T = 0,
51 const std::size_t nh_T = 0)
52 : DifferentialActionModel(state, nu, nr, ng, nh, ng_T, nh_T),
53
1/2
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
12 bp::wrapper<DifferentialActionModel>() {
54
2/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
12 unone_ = VectorXs::Constant(nu_, Scalar(NAN));
55 }
56
57 70 void calc(const std::shared_ptr<DifferentialActionData>& data,
58 const Eigen::Ref<const VectorXs>& x,
59 const Eigen::Ref<const VectorXs>& u) override {
60
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 35 times.
70 if (static_cast<std::size_t>(x.size()) != state_->get_nx()) {
61 throw_pretty(
62 "Invalid argument: " << "x has wrong dimension (it should be " +
63 std::to_string(state_->get_nx()) + ")");
64 }
65
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 35 times.
70 if (static_cast<std::size_t>(u.size()) != nu_) {
66 throw_pretty(
67 "Invalid argument: " << "u has wrong dimension (it should be " +
68 std::to_string(nu_) + ")");
69 }
70 70 if (std::isnan(
71
2/2
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 32 times.
140 scalar_cast<ScalarType>(u.template lpNorm<Eigen::Infinity>()))) {
72
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
6 return bp::call<void>(this->get_override("calc").ptr(), data,
73 12 (VectorXs)x);
74 } else {
75
3/6
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 32 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 32 times.
✗ Branch 9 not taken.
64 return bp::call<void>(this->get_override("calc").ptr(), data, (VectorXs)x,
76 128 (VectorXs)u);
77 }
78 }
79
80 4 void calcDiff(const std::shared_ptr<DifferentialActionData>& data,
81 const Eigen::Ref<const VectorXs>& x,
82 const Eigen::Ref<const VectorXs>& u) override {
83
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
4 if (static_cast<std::size_t>(x.size()) != state_->get_nx()) {
84 throw_pretty(
85 "Invalid argument: " << "x has wrong dimension (it should be " +
86 std::to_string(state_->get_nx()) + ")");
87 }
88
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
4 if (static_cast<std::size_t>(u.size()) != nu_) {
89 throw_pretty(
90 "Invalid argument: " << "u has wrong dimension (it should be " +
91 std::to_string(nu_) + ")");
92 }
93 4 if (std::isnan(
94
2/2
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
8 scalar_cast<ScalarType>(u.template lpNorm<Eigen::Infinity>()))) {
95
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
2 return bp::call<void>(this->get_override("calcDiff").ptr(), data,
96 4 (VectorXs)x);
97 } else {
98
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
2 return bp::call<void>(this->get_override("calcDiff").ptr(), data,
99
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
4 (VectorXs)x, (VectorXs)u);
100 }
101 }
102
103 270 std::shared_ptr<DifferentialActionData> createData() override {
104 270 enableMultithreading() = false;
105
4/8
✓ Branch 1 taken 135 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 135 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 135 times.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 135 times.
540 if (boost::python::override createData = this->get_override("createData")) {
106 return bp::call<std::shared_ptr<DifferentialActionData>>(
107
1/2
✓ Branch 2 taken 135 times.
✗ Branch 3 not taken.
270 createData.ptr());
108 }
109 return DifferentialActionModel::createData();
110 }
111
112 std::shared_ptr<DifferentialActionData> default_createData() {
113 return this->DifferentialActionModel::createData();
114 }
115
116 void quasiStatic(const std::shared_ptr<DifferentialActionData>& data,
117 Eigen::Ref<VectorXs> u, const Eigen::Ref<const VectorXs>& x,
118 const std::size_t maxiter, const Scalar tol) override {
119 if (boost::python::override quasiStatic =
120 this->get_override("quasiStatic")) {
121 u = bp::call<VectorXs>(quasiStatic.ptr(), data, (VectorXs)x, maxiter,
122 tol);
123 if (static_cast<std::size_t>(u.size()) != nu_) {
124 throw_pretty(
125 "Invalid argument: " << "u has wrong dimension (it should be " +
126 std::to_string(nu_) + ")");
127 }
128 return;
129 }
130 return DifferentialActionModel::quasiStatic(data, u, x, maxiter, tol);
131 }
132
133 void default_quasiStatic(const std::shared_ptr<DifferentialActionData>& data,
134 Eigen::Ref<VectorXs> u,
135 const Eigen::Ref<const VectorXs>& x,
136 const std::size_t maxiter, const Scalar tol) {
137 return this->DifferentialActionModel::quasiStatic(data, u, x, maxiter, tol);
138 }
139
140 template <typename NewScalar>
141 DifferentialActionModelAbstractTpl_wrap<NewScalar> cast() const {
142 typedef DifferentialActionModelAbstractTpl_wrap<NewScalar> ReturnType;
143 ReturnType ret(state_->template cast<NewScalar>(), nr_, nu_, ng_, nh_,
144 ng_T_, nh_T_);
145 return ret;
146 }
147 };
148
149 } // namespace python
150 } // namespace crocoddyl
151
152 #endif // BINDINGS_PYTHON_CROCODDYL_CORE_DIFF_ACTION_BASE_HPP_
153