GCC Code Coverage Report


Directory: ./
File: include/crocoddyl/core/controls/poly-zero.hxx
Date: 2025-01-16 08:47:40
Exec Total Coverage
Lines: 49 70 70.0%
Branches: 24 254 9.4%

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