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