GCC Code Coverage Report


Directory: ./
File: include/crocoddyl/core/state-base.hxx
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 62 104 59.6%
Branches: 36 142 25.4%

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 #include <boost/core/demangle.hpp>
11
12 #include "crocoddyl/core/mathbase.hpp"
13
14 namespace crocoddyl {
15 template <typename Scalar>
16 11609 StateAbstractTpl<Scalar>::StateAbstractTpl(const std::size_t nx,
17 const std::size_t ndx)
18 11609 : nx_(nx),
19 11609 ndx_(ndx),
20
2/4
✓ Branch 1 taken 11609 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11609 times.
✗ Branch 5 not taken.
11609 lb_(VectorXs::Constant(nx_, -std::numeric_limits<Scalar>::infinity())),
21
2/4
✓ Branch 2 taken 11609 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 11609 times.
✗ Branch 6 not taken.
11609 ub_(VectorXs::Constant(nx_, std::numeric_limits<Scalar>::infinity())),
22 11609 has_limits_(false) {
23 11609 nv_ = ndx / 2;
24 11609 nq_ = nx_ - nv_;
25 11609 }
26
27 template <typename Scalar>
28 StateAbstractTpl<Scalar>::StateAbstractTpl()
29 : nx_(0),
30 ndx_(0),
31 lb_(MathBase::VectorXs::Constant(
32 nx_, -std::numeric_limits<Scalar>::infinity())),
33 ub_(MathBase::VectorXs::Constant(
34 nx_, std::numeric_limits<Scalar>::infinity())),
35 has_limits_(false) {}
36
37 template <typename Scalar>
38 23442 StateAbstractTpl<Scalar>::~StateAbstractTpl() {}
39
40 template <typename Scalar>
41 1362 typename MathBaseTpl<Scalar>::VectorXs StateAbstractTpl<Scalar>::diff_dx(
42 const Eigen::Ref<const VectorXs>& x0,
43 const Eigen::Ref<const VectorXs>& x1) {
44
1/2
✓ Branch 2 taken 1362 times.
✗ Branch 3 not taken.
1362 VectorXs dxout = VectorXs::Zero(ndx_);
45
2/4
✓ Branch 1 taken 1362 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1362 times.
✗ Branch 5 not taken.
1362 diff(x0, x1, dxout);
46 1362 return dxout;
47 }
48
49 template <typename Scalar>
50 92 typename MathBaseTpl<Scalar>::VectorXs StateAbstractTpl<Scalar>::integrate_x(
51 const Eigen::Ref<const VectorXs>& x, const Eigen::Ref<const VectorXs>& dx) {
52
1/2
✓ Branch 2 taken 92 times.
✗ Branch 3 not taken.
92 VectorXs xout = VectorXs::Zero(nx_);
53
2/4
✓ Branch 1 taken 92 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 92 times.
✗ Branch 5 not taken.
92 integrate(x, dx, xout);
54 92 return xout;
55 }
56
57 template <typename Scalar>
58 std::vector<typename MathBaseTpl<Scalar>::MatrixXs>
59 6 StateAbstractTpl<Scalar>::Jdiff_Js(const Eigen::Ref<const VectorXs>& x0,
60 const Eigen::Ref<const VectorXs>& x1,
61 Jcomponent firstsecond) {
62
2/4
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 MatrixXs Jfirst(ndx_, ndx_), Jsecond(ndx_, ndx_);
63
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 Jfirst.setZero();
64
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 Jsecond.setZero();
65 6 std::vector<MatrixXs> Jacs;
66
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 Jdiff(x0, x1, Jfirst, Jsecond, firstsecond);
67
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
6 switch (firstsecond) {
68 4 case both:
69
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 Jacs.push_back(Jfirst);
70
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 Jacs.push_back(Jsecond);
71 4 break;
72 case first:
73 Jacs.push_back(Jfirst);
74 break;
75 2 case second:
76
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 Jacs.push_back(Jsecond);
77 2 break;
78 default:
79 Jacs.push_back(Jfirst);
80 Jacs.push_back(Jsecond);
81 break;
82 }
83 12 return Jacs;
84 6 }
85
86 template <typename Scalar>
87 std::vector<typename MathBaseTpl<Scalar>::MatrixXs>
88 18 StateAbstractTpl<Scalar>::Jintegrate_Js(const Eigen::Ref<const VectorXs>& x,
89 const Eigen::Ref<const VectorXs>& dx,
90 const Jcomponent firstsecond) {
91
2/4
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
18 MatrixXs Jfirst(ndx_, ndx_), Jsecond(ndx_, ndx_);
92
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 Jfirst.setZero();
93
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 Jsecond.setZero();
94 18 std::vector<MatrixXs> Jacs;
95
3/6
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 18 times.
✗ Branch 8 not taken.
18 Jintegrate(x, dx, Jfirst, Jsecond, firstsecond, setto);
96
1/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18 switch (firstsecond) {
97 18 case both:
98
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 Jacs.push_back(Jfirst);
99
1/2
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
18 Jacs.push_back(Jsecond);
100 18 break;
101 case first:
102 Jacs.push_back(Jfirst);
103 break;
104 case second:
105 Jacs.push_back(Jsecond);
106 break;
107 default:
108 Jacs.push_back(Jfirst);
109 Jacs.push_back(Jsecond);
110 break;
111 }
112 36 return Jacs;
113 18 }
114
115 template <typename Scalar>
116 void StateAbstractTpl<Scalar>::print(std::ostream& os) const {
117 os << boost::core::demangle(typeid(*this).name());
118 }
119
120 template <typename Scalar>
121 666589 std::size_t StateAbstractTpl<Scalar>::get_nx() const {
122 666589 return nx_;
123 }
124
125 template <typename Scalar>
126 7919932 std::size_t StateAbstractTpl<Scalar>::get_ndx() const {
127 7919932 return ndx_;
128 }
129
130 template <typename Scalar>
131 194968 std::size_t StateAbstractTpl<Scalar>::get_nq() const {
132 194968 return nq_;
133 }
134
135 template <typename Scalar>
136 4087276 std::size_t StateAbstractTpl<Scalar>::get_nv() const {
137 4087276 return nv_;
138 }
139
140 template <typename Scalar>
141 7 const typename MathBaseTpl<Scalar>::VectorXs& StateAbstractTpl<Scalar>::get_lb()
142 const {
143 7 return lb_;
144 }
145
146 template <typename Scalar>
147 7 const typename MathBaseTpl<Scalar>::VectorXs& StateAbstractTpl<Scalar>::get_ub()
148 const {
149 7 return ub_;
150 }
151
152 template <typename Scalar>
153 bool StateAbstractTpl<Scalar>::get_has_limits() const {
154 return has_limits_;
155 }
156
157 template <typename Scalar>
158 void StateAbstractTpl<Scalar>::set_lb(const VectorXs& lb) {
159 if (static_cast<std::size_t>(lb.size()) != nx_) {
160 throw_pretty("Invalid argument: "
161 << "lower bound has wrong dimension (it should be " +
162 std::to_string(nx_) + ")");
163 }
164 lb_ = lb;
165 update_has_limits();
166 }
167
168 template <typename Scalar>
169 void StateAbstractTpl<Scalar>::set_ub(const VectorXs& ub) {
170 if (static_cast<std::size_t>(ub.size()) != nx_) {
171 throw_pretty("Invalid argument: "
172 << "upper bound has wrong dimension (it should be " +
173 std::to_string(nx_) + ")");
174 }
175 ub_ = ub;
176 update_has_limits();
177 }
178
179 template <typename Scalar>
180 11087 void StateAbstractTpl<Scalar>::update_has_limits() {
181
4/16
✓ Branch 1 taken 11087 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11087 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 11087 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 11087 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
11087 has_limits_ = isfinite(lb_.array()).any() || isfinite(ub_.array()).any();
182 11087 }
183
184 template <typename Scalar>
185 std::ostream& operator<<(std::ostream& os,
186 const StateAbstractTpl<Scalar>& model) {
187 model.print(os);
188 return os;
189 }
190
191 } // namespace crocoddyl
192