GCC Code Coverage Report


Directory: ./
File: include/crocoddyl/core/controls/poly-zero.hxx
Date: 2025-05-13 10:30:51
Exec Total Coverage
Lines: 0 67 0.0%
Branches: 0 254 0.0%

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 ControlParametrizationModelPolyZeroTpl<
14 Scalar>::ControlParametrizationModelPolyZeroTpl(const std::size_t nw)
15 : Base(nw, nw) {}
16
17 template <typename Scalar>
18 void ControlParametrizationModelPolyZeroTpl<Scalar>::calc(
19 const std::shared_ptr<ControlParametrizationDataAbstract>& data,
20 const Scalar, const Eigen::Ref<const VectorXs>& u) const {
21 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 data->w = u;
27 }
28
29 template <typename Scalar>
30 #ifndef NDEBUG
31 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 assert_pretty(MatrixXs(data->dw_du).isApprox(MatrixXs::Identity(nu_, nu_)),
41 "dw_du has wrong value");
42 }
43
44 template <typename Scalar>
45 std::shared_ptr<ControlParametrizationDataAbstractTpl<Scalar> >
46 ControlParametrizationModelPolyZeroTpl<Scalar>::createData() {
47 std::shared_ptr<Data> data =
48 std::allocate_shared<Data>(Eigen::aligned_allocator<Data>(), this);
49 data->dw_du.setIdentity();
50 return data;
51 }
52
53 template <typename Scalar>
54 void ControlParametrizationModelPolyZeroTpl<Scalar>::params(
55 const std::shared_ptr<ControlParametrizationDataAbstract>& data,
56 const Scalar, const Eigen::Ref<const VectorXs>& w) const {
57 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 data->u = w;
63 }
64
65 template <typename Scalar>
66 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 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 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 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 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 u_lb = w_lb;
91 u_ub = w_ub;
92 }
93
94 template <typename Scalar>
95 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 assert_pretty(is_a_AssignmentOp(op),
100 ("op must be one of the AssignmentOp {settop, addto, rmfrom}"));
101 if (A.rows() != out.rows() || static_cast<std::size_t>(A.cols()) != nw_ ||
102 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 switch (op) {
111 case setto:
112 out = A;
113 break;
114 case addto:
115 out += A;
116 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 }
125
126 template <typename Scalar>
127 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 assert_pretty(is_a_AssignmentOp(op),
133 ("op must be one of the AssignmentOp {settop, addto, rmfrom}"));
134 if (A.cols() != out.cols() || static_cast<std::size_t>(A.rows()) != nw_ ||
135 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 switch (op) {
144 case setto:
145 out = A;
146 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 }
158
159 template <typename Scalar>
160 template <typename NewScalar>
161 ControlParametrizationModelPolyZeroTpl<NewScalar>
162 ControlParametrizationModelPolyZeroTpl<Scalar>::cast() const {
163 typedef ControlParametrizationModelPolyZeroTpl<NewScalar> ReturnType;
164 ReturnType ret(nw_);
165 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