Directory: | ./ |
---|---|
File: | include/crocoddyl/core/state-base.hxx |
Date: | 2025-01-16 08:47:40 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 62 | 91 | 68.1% |
Branches: | 36 | 132 | 27.3% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2019-2020, LAAS-CNRS, University of Edinburgh | ||
5 | // Copyright note valid unless otherwise stated in individual files. | ||
6 | // All rights reserved. | ||
7 | /////////////////////////////////////////////////////////////////////////////// | ||
8 | #include "crocoddyl/core/mathbase.hpp" | ||
9 | |||
10 | namespace crocoddyl { | ||
11 | template <typename Scalar> | ||
12 | 11621 | StateAbstractTpl<Scalar>::StateAbstractTpl(const std::size_t nx, | |
13 | const std::size_t ndx) | ||
14 | 11621 | : nx_(nx), | |
15 | 11621 | ndx_(ndx), | |
16 |
2/4✓ Branch 1 taken 11621 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11621 times.
✗ Branch 5 not taken.
|
11621 | lb_(VectorXs::Constant(nx_, -std::numeric_limits<Scalar>::infinity())), |
17 |
2/4✓ Branch 2 taken 11621 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 11621 times.
✗ Branch 6 not taken.
|
11621 | ub_(VectorXs::Constant(nx_, std::numeric_limits<Scalar>::infinity())), |
18 | 11621 | has_limits_(false) { | |
19 | 11621 | nv_ = ndx / 2; | |
20 | 11621 | nq_ = nx_ - nv_; | |
21 | 11621 | } | |
22 | |||
23 | template <typename Scalar> | ||
24 | StateAbstractTpl<Scalar>::StateAbstractTpl() | ||
25 | : nx_(0), | ||
26 | ndx_(0), | ||
27 | lb_(MathBase::VectorXs::Constant( | ||
28 | nx_, -std::numeric_limits<Scalar>::infinity())), | ||
29 | ub_(MathBase::VectorXs::Constant( | ||
30 | nx_, std::numeric_limits<Scalar>::infinity())), | ||
31 | has_limits_(false) {} | ||
32 | |||
33 | template <typename Scalar> | ||
34 | 23254 | StateAbstractTpl<Scalar>::~StateAbstractTpl() {} | |
35 | |||
36 | template <typename Scalar> | ||
37 | 1292 | typename MathBaseTpl<Scalar>::VectorXs StateAbstractTpl<Scalar>::diff_dx( | |
38 | const Eigen::Ref<const VectorXs>& x0, | ||
39 | const Eigen::Ref<const VectorXs>& x1) { | ||
40 |
1/2✓ Branch 2 taken 1292 times.
✗ Branch 3 not taken.
|
1292 | VectorXs dxout = VectorXs::Zero(ndx_); |
41 |
2/4✓ Branch 1 taken 1292 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1292 times.
✗ Branch 5 not taken.
|
1292 | diff(x0, x1, dxout); |
42 | 1292 | return dxout; | |
43 | } | ||
44 | |||
45 | template <typename Scalar> | ||
46 | 47 | typename MathBaseTpl<Scalar>::VectorXs StateAbstractTpl<Scalar>::integrate_x( | |
47 | const Eigen::Ref<const VectorXs>& x, const Eigen::Ref<const VectorXs>& dx) { | ||
48 |
1/2✓ Branch 2 taken 47 times.
✗ Branch 3 not taken.
|
47 | VectorXs xout = VectorXs::Zero(nx_); |
49 |
2/4✓ Branch 1 taken 47 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 47 times.
✗ Branch 5 not taken.
|
47 | integrate(x, dx, xout); |
50 | 47 | return xout; | |
51 | } | ||
52 | |||
53 | template <typename Scalar> | ||
54 | std::vector<typename MathBaseTpl<Scalar>::MatrixXs> | ||
55 | 6 | StateAbstractTpl<Scalar>::Jdiff_Js(const Eigen::Ref<const VectorXs>& x0, | |
56 | const Eigen::Ref<const VectorXs>& x1, | ||
57 | Jcomponent firstsecond) { | ||
58 |
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_); |
59 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | Jfirst.setZero(); |
60 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | Jsecond.setZero(); |
61 | 6 | std::vector<MatrixXs> Jacs; | |
62 |
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); |
63 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
6 | switch (firstsecond) { |
64 | 4 | case both: | |
65 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | Jacs.push_back(Jfirst); |
66 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | Jacs.push_back(Jsecond); |
67 | 4 | break; | |
68 | ✗ | case first: | |
69 | ✗ | Jacs.push_back(Jfirst); | |
70 | ✗ | break; | |
71 | 2 | case second: | |
72 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | Jacs.push_back(Jsecond); |
73 | 2 | break; | |
74 | ✗ | default: | |
75 | ✗ | Jacs.push_back(Jfirst); | |
76 | ✗ | Jacs.push_back(Jsecond); | |
77 | ✗ | break; | |
78 | } | ||
79 | 12 | return Jacs; | |
80 | 6 | } | |
81 | |||
82 | template <typename Scalar> | ||
83 | std::vector<typename MathBaseTpl<Scalar>::MatrixXs> | ||
84 | 18 | StateAbstractTpl<Scalar>::Jintegrate_Js(const Eigen::Ref<const VectorXs>& x, | |
85 | const Eigen::Ref<const VectorXs>& dx, | ||
86 | const Jcomponent firstsecond) { | ||
87 |
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_); |
88 |
1/2✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
|
18 | Jfirst.setZero(); |
89 |
1/2✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
|
18 | Jsecond.setZero(); |
90 | 18 | std::vector<MatrixXs> Jacs; | |
91 |
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); |
92 |
1/4✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
18 | switch (firstsecond) { |
93 | 18 | case both: | |
94 |
1/2✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
|
18 | Jacs.push_back(Jfirst); |
95 |
1/2✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
|
18 | Jacs.push_back(Jsecond); |
96 | 18 | break; | |
97 | ✗ | case first: | |
98 | ✗ | Jacs.push_back(Jfirst); | |
99 | ✗ | break; | |
100 | ✗ | case second: | |
101 | ✗ | Jacs.push_back(Jsecond); | |
102 | ✗ | break; | |
103 | ✗ | default: | |
104 | ✗ | Jacs.push_back(Jfirst); | |
105 | ✗ | Jacs.push_back(Jsecond); | |
106 | ✗ | break; | |
107 | } | ||
108 | 36 | return Jacs; | |
109 | 18 | } | |
110 | |||
111 | template <typename Scalar> | ||
112 | 669609 | std::size_t StateAbstractTpl<Scalar>::get_nx() const { | |
113 | 669609 | return nx_; | |
114 | } | ||
115 | |||
116 | template <typename Scalar> | ||
117 | 7942823 | std::size_t StateAbstractTpl<Scalar>::get_ndx() const { | |
118 | 7942823 | return ndx_; | |
119 | } | ||
120 | |||
121 | template <typename Scalar> | ||
122 | 197938 | std::size_t StateAbstractTpl<Scalar>::get_nq() const { | |
123 | 197938 | return nq_; | |
124 | } | ||
125 | |||
126 | template <typename Scalar> | ||
127 | 4097070 | std::size_t StateAbstractTpl<Scalar>::get_nv() const { | |
128 | 4097070 | return nv_; | |
129 | } | ||
130 | |||
131 | template <typename Scalar> | ||
132 | 7 | const typename MathBaseTpl<Scalar>::VectorXs& StateAbstractTpl<Scalar>::get_lb() | |
133 | const { | ||
134 | 7 | return lb_; | |
135 | } | ||
136 | |||
137 | template <typename Scalar> | ||
138 | 7 | const typename MathBaseTpl<Scalar>::VectorXs& StateAbstractTpl<Scalar>::get_ub() | |
139 | const { | ||
140 | 7 | return ub_; | |
141 | } | ||
142 | |||
143 | template <typename Scalar> | ||
144 | ✗ | bool StateAbstractTpl<Scalar>::get_has_limits() const { | |
145 | ✗ | return has_limits_; | |
146 | } | ||
147 | |||
148 | template <typename Scalar> | ||
149 | ✗ | void StateAbstractTpl<Scalar>::set_lb(const VectorXs& lb) { | |
150 | ✗ | if (static_cast<std::size_t>(lb.size()) != nx_) { | |
151 | ✗ | throw_pretty("Invalid argument: " | |
152 | << "lower bound has wrong dimension (it should be " + | ||
153 | std::to_string(nx_) + ")"); | ||
154 | } | ||
155 | ✗ | lb_ = lb; | |
156 | ✗ | update_has_limits(); | |
157 | } | ||
158 | |||
159 | template <typename Scalar> | ||
160 | ✗ | void StateAbstractTpl<Scalar>::set_ub(const VectorXs& ub) { | |
161 | ✗ | if (static_cast<std::size_t>(ub.size()) != nx_) { | |
162 | ✗ | throw_pretty("Invalid argument: " | |
163 | << "upper bound has wrong dimension (it should be " + | ||
164 | std::to_string(nx_) + ")"); | ||
165 | } | ||
166 | ✗ | ub_ = ub; | |
167 | ✗ | update_has_limits(); | |
168 | } | ||
169 | |||
170 | template <typename Scalar> | ||
171 | 11104 | void StateAbstractTpl<Scalar>::update_has_limits() { | |
172 |
4/16✓ Branch 1 taken 11104 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11104 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 11104 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 11104 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.
|
11104 | has_limits_ = isfinite(lb_.array()).any() || isfinite(ub_.array()).any(); |
173 | 11104 | } | |
174 | |||
175 | } // namespace crocoddyl | ||
176 |