Directory: | ./ |
---|---|
File: | include/crocoddyl/core/controls/poly-zero.hxx |
Date: | 2025-03-26 19:23:43 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 50 | 73 | 68.5% |
Branches: | 24 | 254 | 9.4% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2021-2025, University of Edinburgh, University of Trento, | ||
5 | // Heriot-Watt University | ||
6 | // Copyright note valid unless otherwise stated in individual files. | ||
7 | // All rights reserved. | ||
8 | /////////////////////////////////////////////////////////////////////////////// | ||
9 | |||
10 | namespace crocoddyl { | ||
11 | |||
12 | template <typename Scalar> | ||
13 | 684 | ControlParametrizationModelPolyZeroTpl< | |
14 | Scalar>::ControlParametrizationModelPolyZeroTpl(const std::size_t nw) | ||
15 | 684 | : Base(nw, nw) {} | |
16 | |||
17 | template <typename Scalar> | ||
18 | 53933 | void ControlParametrizationModelPolyZeroTpl<Scalar>::calc( | |
19 | const std::shared_ptr<ControlParametrizationDataAbstract>& data, | ||
20 | const Scalar, const Eigen::Ref<const VectorXs>& u) const { | ||
21 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 53933 times.
|
53933 | if (static_cast<std::size_t>(u.size()) != nu_) { |
22 | ✗ | throw_pretty( | |
23 | "Invalid argument: " << "u has wrong dimension (it should be " + | ||
24 | std::to_string(nu_) + ")"); | ||
25 | } | ||
26 | 53933 | data->w = u; | |
27 | 53933 | } | |
28 | |||
29 | template <typename Scalar> | ||
30 | #ifndef NDEBUG | ||
31 | 6 | void ControlParametrizationModelPolyZeroTpl<Scalar>::calcDiff( | |
32 | const std::shared_ptr<ControlParametrizationDataAbstract>& data, | ||
33 | const Scalar, const Eigen::Ref<const VectorXs>&) const { | ||
34 | #else | ||
35 | void ControlParametrizationModelPolyZeroTpl<Scalar>::calcDiff( | ||
36 | const std::shared_ptr<ControlParametrizationDataAbstract>&, const Scalar, | ||
37 | const Eigen::Ref<const VectorXs>&) const { | ||
38 | #endif | ||
39 | // The Hessian has constant values which were set in createData. | ||
40 |
3/14✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 6 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 6 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
|
6 | assert_pretty(MatrixXs(data->dw_du).isApprox(MatrixXs::Identity(nu_, nu_)), |
41 | "dw_du has wrong value"); | ||
42 | 6 | } | |
43 | |||
44 | template <typename Scalar> | ||
45 | std::shared_ptr<ControlParametrizationDataAbstractTpl<Scalar> > | ||
46 | 71834 | ControlParametrizationModelPolyZeroTpl<Scalar>::createData() { | |
47 |
1/2✓ Branch 1 taken 71834 times.
✗ Branch 2 not taken.
|
71834 | std::shared_ptr<Data> data = |
48 | 71834 | std::allocate_shared<Data>(Eigen::aligned_allocator<Data>(), this); | |
49 |
1/2✓ Branch 2 taken 71834 times.
✗ Branch 3 not taken.
|
71834 | data->dw_du.setIdentity(); |
50 | 71834 | return data; | |
51 | } | ||
52 | |||
53 | template <typename Scalar> | ||
54 | 7360 | void ControlParametrizationModelPolyZeroTpl<Scalar>::params( | |
55 | const std::shared_ptr<ControlParametrizationDataAbstract>& data, | ||
56 | const Scalar, const Eigen::Ref<const VectorXs>& w) const { | ||
57 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 7360 times.
|
7360 | if (static_cast<std::size_t>(w.size()) != nw_) { |
58 | ✗ | throw_pretty( | |
59 | "Invalid argument: " << "w has wrong dimension (it should be " + | ||
60 | std::to_string(nw_) + ")"); | ||
61 | } | ||
62 | 7360 | data->u = w; | |
63 | 7360 | } | |
64 | |||
65 | template <typename Scalar> | ||
66 | 677 | void ControlParametrizationModelPolyZeroTpl<Scalar>::convertBounds( | |
67 | const Eigen::Ref<const VectorXs>& w_lb, | ||
68 | const Eigen::Ref<const VectorXs>& w_ub, Eigen::Ref<VectorXs> u_lb, | ||
69 | Eigen::Ref<VectorXs> u_ub) const { | ||
70 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 677 times.
|
677 | if (static_cast<std::size_t>(u_lb.size()) != nu_) { |
71 | ✗ | throw_pretty( | |
72 | "Invalid argument: " << "u_lb has wrong dimension (it should be " + | ||
73 | std::to_string(nu_) + ")"); | ||
74 | } | ||
75 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 677 times.
|
677 | if (static_cast<std::size_t>(u_ub.size()) != nu_) { |
76 | ✗ | throw_pretty( | |
77 | "Invalid argument: " << "u_ub has wrong dimension (it should be " + | ||
78 | std::to_string(nu_) + ")"); | ||
79 | } | ||
80 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 677 times.
|
677 | if (static_cast<std::size_t>(w_lb.size()) != nw_) { |
81 | ✗ | throw_pretty( | |
82 | "Invalid argument: " << "w_lb has wrong dimension (it should be " + | ||
83 | std::to_string(nw_) + ")"); | ||
84 | } | ||
85 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 677 times.
|
677 | if (static_cast<std::size_t>(w_ub.size()) != nw_) { |
86 | ✗ | throw_pretty( | |
87 | "Invalid argument: " << "w_ub has wrong dimension (it should be " + | ||
88 | std::to_string(nw_) + ")"); | ||
89 | } | ||
90 | 677 | u_lb = w_lb; | |
91 | 677 | u_ub = w_ub; | |
92 | 677 | } | |
93 | |||
94 | template <typename Scalar> | ||
95 | 65240 | void ControlParametrizationModelPolyZeroTpl<Scalar>::multiplyByJacobian( | |
96 | const std::shared_ptr<ControlParametrizationDataAbstract>&, | ||
97 | const Eigen::Ref<const MatrixXs>& A, Eigen::Ref<MatrixXs> out, | ||
98 | const AssignmentOp op) const { | ||
99 |
1/10✗ Branch 1 not taken.
✓ Branch 2 taken 65240 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
65240 | assert_pretty(is_a_AssignmentOp(op), |
100 | ("op must be one of the AssignmentOp {settop, addto, rmfrom}")); | ||
101 |
3/6✓ Branch 2 taken 65240 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 65240 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 65240 times.
|
130480 | if (A.rows() != out.rows() || static_cast<std::size_t>(A.cols()) != nw_ || |
102 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 65240 times.
|
65240 | static_cast<std::size_t>(out.cols()) != nu_) { |
103 | ✗ | throw_pretty("Invalid argument: " << "A and out have wrong dimensions (" + | |
104 | std::to_string(A.rows()) + "," + | ||
105 | std::to_string(A.cols()) + | ||
106 | " and " + | ||
107 | std::to_string(out.rows()) + "," + | ||
108 | std::to_string(out.cols()) + ")"); | ||
109 | } | ||
110 |
2/4✓ Branch 0 taken 56813 times.
✓ Branch 1 taken 8427 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
65240 | switch (op) { |
111 | 56813 | case setto: | |
112 | 56813 | out = A; | |
113 | 56813 | break; | |
114 | 8427 | case addto: | |
115 | 8427 | out += A; | |
116 | 8427 | break; | |
117 | ✗ | case rmfrom: | |
118 | ✗ | out -= A; | |
119 | ✗ | break; | |
120 | ✗ | default: | |
121 | ✗ | throw_pretty("Invalid argument: allowed operators: setto, addto, rmfrom"); | |
122 | break; | ||
123 | } | ||
124 | 65240 | } | |
125 | |||
126 | template <typename Scalar> | ||
127 | 29468 | void ControlParametrizationModelPolyZeroTpl<Scalar>:: | |
128 | multiplyJacobianTransposeBy( | ||
129 | const std::shared_ptr<ControlParametrizationDataAbstract>&, | ||
130 | const Eigen::Ref<const MatrixXs>& A, Eigen::Ref<MatrixXs> out, | ||
131 | const AssignmentOp op) const { | ||
132 |
1/10✗ Branch 1 not taken.
✓ Branch 2 taken 29468 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
29468 | assert_pretty(is_a_AssignmentOp(op), |
133 | ("op must be one of the AssignmentOp {settop, addto, rmfrom}")); | ||
134 |
3/6✓ Branch 2 taken 29468 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 29468 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 29468 times.
|
58936 | if (A.cols() != out.cols() || static_cast<std::size_t>(A.rows()) != nw_ || |
135 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 29468 times.
|
29468 | static_cast<std::size_t>(out.rows()) != nu_) { |
136 | ✗ | throw_pretty("Invalid argument: " << "A and out have wrong dimensions (" + | |
137 | std::to_string(A.rows()) + "," + | ||
138 | std::to_string(A.cols()) + | ||
139 | " and " + | ||
140 | std::to_string(out.rows()) + "," + | ||
141 | std::to_string(out.cols()) + ")"); | ||
142 | } | ||
143 |
1/4✓ Branch 0 taken 29468 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
29468 | switch (op) { |
144 | 29468 | case setto: | |
145 | 29468 | out = A; | |
146 | 29468 | break; | |
147 | ✗ | case addto: | |
148 | ✗ | out += A; | |
149 | ✗ | break; | |
150 | ✗ | case rmfrom: | |
151 | ✗ | out -= A; | |
152 | ✗ | break; | |
153 | ✗ | default: | |
154 | ✗ | throw_pretty("Invalid argument: allowed operators: setto, addto, rmfrom"); | |
155 | break; | ||
156 | } | ||
157 | 29468 | } | |
158 | |||
159 | template <typename Scalar> | ||
160 | template <typename NewScalar> | ||
161 | ControlParametrizationModelPolyZeroTpl<NewScalar> | ||
162 | 3 | ControlParametrizationModelPolyZeroTpl<Scalar>::cast() const { | |
163 | typedef ControlParametrizationModelPolyZeroTpl<NewScalar> ReturnType; | ||
164 | 3 | ReturnType ret(nw_); | |
165 | 3 | return ret; | |
166 | } | ||
167 | |||
168 | template <typename Scalar> | ||
169 | ✗ | void ControlParametrizationModelPolyZeroTpl<Scalar>::print( | |
170 | std::ostream& os) const { | ||
171 | ✗ | os << "ControlParametrizationModelPolyZero {nw=" << nw_ << "}"; | |
172 | } | ||
173 | |||
174 | } // namespace crocoddyl | ||
175 |