GCC Code Coverage Report


Directory: ./
File: include/crocoddyl/core/cost-base.hxx
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 42 65 64.6%
Branches: 24 106 22.6%

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 namespace crocoddyl {
13
14 template <typename Scalar>
15 5362 CostModelAbstractTpl<Scalar>::CostModelAbstractTpl(
16 std::shared_ptr<StateAbstract> state,
17 std::shared_ptr<ActivationModelAbstract> activation,
18 std::shared_ptr<ResidualModelAbstract> residual)
19 5362 : state_(state),
20 5362 activation_(activation),
21 5362 residual_(residual),
22
1/2
✓ Branch 2 taken 5362 times.
✗ Branch 3 not taken.
5362 nu_(residual->get_nu()),
23
3/6
✓ Branch 4 taken 5362 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 5362 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 5362 times.
✗ Branch 11 not taken.
10724 unone_(VectorXs::Zero(residual->get_nu())) {
24
3/6
✓ Branch 2 taken 5362 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 5362 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 5362 times.
5362 if (activation_->get_nr() != residual_->get_nr()) {
25 throw_pretty("Invalid argument: "
26 << "nr is equals to " + std::to_string(residual_->get_nr()));
27 }
28 5362 }
29
30 template <typename Scalar>
31 649 CostModelAbstractTpl<Scalar>::CostModelAbstractTpl(
32 std::shared_ptr<StateAbstract> state,
33 std::shared_ptr<ActivationModelAbstract> activation, const std::size_t nu)
34 649 : state_(state),
35 649 activation_(activation),
36 649 residual_(std::make_shared<ResidualModelAbstractTpl<Scalar>>(
37
2/4
✓ Branch 2 taken 649 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 649 times.
✗ Branch 6 not taken.
649 state, activation->get_nr(), nu)),
38 649 nu_(nu),
39
2/4
✓ Branch 3 taken 649 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 649 times.
✗ Branch 7 not taken.
1298 unone_(VectorXs::Zero(nu)) {}
40
41 template <typename Scalar>
42 6 CostModelAbstractTpl<Scalar>::CostModelAbstractTpl(
43 std::shared_ptr<StateAbstract> state,
44 std::shared_ptr<ActivationModelAbstract> activation)
45 6 : state_(state),
46 6 activation_(activation),
47 6 residual_(std::make_shared<ResidualModelAbstractTpl<Scalar>>(
48
2/4
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
6 state, activation->get_nr())),
49
1/2
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 nu_(state->get_nv()),
50
3/6
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 6 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
12 unone_(VectorXs::Zero(state->get_nv())) {}
51
52 template <typename Scalar>
53 1673 CostModelAbstractTpl<Scalar>::CostModelAbstractTpl(
54 std::shared_ptr<StateAbstract> state,
55 std::shared_ptr<ResidualModelAbstract> residual)
56 1673 : state_(state),
57 1673 activation_(
58
2/4
✓ Branch 2 taken 1673 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1673 times.
✗ Branch 6 not taken.
1673 std::make_shared<ActivationModelQuadTpl<Scalar>>(residual->get_nr())),
59 1673 residual_(residual),
60
1/2
✓ Branch 2 taken 1673 times.
✗ Branch 3 not taken.
1673 nu_(residual->get_nu()),
61
3/6
✓ Branch 4 taken 1673 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1673 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1673 times.
✗ Branch 11 not taken.
3346 unone_(VectorXs::Zero(residual->get_nu())) {}
62
63 template <typename Scalar>
64 CostModelAbstractTpl<Scalar>::CostModelAbstractTpl(
65 std::shared_ptr<StateAbstract> state, const std::size_t nr,
66 const std::size_t nu)
67 : state_(state),
68 activation_(std::make_shared<ActivationModelQuadTpl<Scalar>>(nr)),
69 residual_(std::make_shared<ResidualModelAbstract>(state, nr, nu)),
70 nu_(nu),
71 unone_(VectorXs::Zero(nu)) {}
72
73 template <typename Scalar>
74 CostModelAbstractTpl<Scalar>::CostModelAbstractTpl(
75 std::shared_ptr<StateAbstract> state, const std::size_t nr)
76 : state_(state),
77 activation_(std::make_shared<ActivationModelQuadTpl<Scalar>>(nr)),
78 residual_(std::make_shared<ResidualModelAbstract>(state, nr)),
79 nu_(state->get_nv()),
80 unone_(VectorXs::Zero(state->get_nv())) {}
81
82 template <typename Scalar>
83 void CostModelAbstractTpl<Scalar>::calc(
84 const std::shared_ptr<CostDataAbstract>& data,
85 const Eigen::Ref<const VectorXs>& x) {
86 calc(data, x, unone_);
87 }
88
89 template <typename Scalar>
90 void CostModelAbstractTpl<Scalar>::calcDiff(
91 const std::shared_ptr<CostDataAbstract>& data,
92 const Eigen::Ref<const VectorXs>& x) {
93 calcDiff(data, x, unone_);
94 }
95
96 template <typename Scalar>
97 std::shared_ptr<CostDataAbstractTpl<Scalar>>
98 15 CostModelAbstractTpl<Scalar>::createData(DataCollectorAbstract* const data) {
99 return std::allocate_shared<CostDataAbstract>(
100
1/2
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
30 Eigen::aligned_allocator<CostDataAbstract>(), this, data);
101 }
102
103 template <typename Scalar>
104 void CostModelAbstractTpl<Scalar>::print(std::ostream& os) const {
105 os << boost::core::demangle(typeid(*this).name());
106 }
107
108 template <typename Scalar>
109 const std::shared_ptr<StateAbstractTpl<Scalar>>&
110 1938931 CostModelAbstractTpl<Scalar>::get_state() const {
111 1938931 return state_;
112 }
113
114 template <typename Scalar>
115 const std::shared_ptr<ActivationModelAbstractTpl<Scalar>>&
116 491270 CostModelAbstractTpl<Scalar>::get_activation() const {
117 491270 return activation_;
118 }
119
120 template <typename Scalar>
121 const std::shared_ptr<ResidualModelAbstractTpl<Scalar>>&
122 476333 CostModelAbstractTpl<Scalar>::get_residual() const {
123 476333 return residual_;
124 }
125
126 template <typename Scalar>
127 1923147 std::size_t CostModelAbstractTpl<Scalar>::get_nu() const {
128 1923147 return nu_;
129 }
130
131 template <typename Scalar>
132 template <class ReferenceType>
133 void CostModelAbstractTpl<Scalar>::set_reference(ReferenceType ref) {
134 set_referenceImpl(typeid(ref), &ref);
135 }
136
137 template <typename Scalar>
138 void CostModelAbstractTpl<Scalar>::set_referenceImpl(const std::type_info&,
139 const void*) {
140 throw_pretty("It has not been implemented the set_referenceImpl() function");
141 }
142
143 template <typename Scalar>
144 template <class ReferenceType>
145 ReferenceType CostModelAbstractTpl<Scalar>::get_reference() {
146 #pragma GCC diagnostic push // TODO: Remove once the deprecated FrameXX has
147 // been removed in a future release
148 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
149 ReferenceType ref;
150 get_referenceImpl(typeid(ref), &ref);
151 return ref;
152 #pragma GCC diagnostic pop
153 }
154
155 template <typename Scalar>
156 void CostModelAbstractTpl<Scalar>::get_referenceImpl(const std::type_info&,
157 void*) {
158 throw_pretty("It has not been implemented the set_referenceImpl() function");
159 }
160
161 template <class Scalar>
162 324 std::ostream& operator<<(std::ostream& os,
163 const CostModelAbstractTpl<Scalar>& model) {
164 324 model.print(os);
165 324 return os;
166 }
167
168 } // namespace crocoddyl
169