Directory: | ./ |
---|---|
File: | include/crocoddyl/core/activations/quadratic.hpp |
Date: | 2025-01-16 08:47:40 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 19 | 22 | 86.4% |
Branches: | 7 | 54 | 13.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2019-2023, 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 | #ifndef CROCODDYL_CORE_ACTIVATIONS_QUADRATIC_HPP_ | ||
11 | #define CROCODDYL_CORE_ACTIVATIONS_QUADRATIC_HPP_ | ||
12 | |||
13 | #include <stdexcept> | ||
14 | |||
15 | #include "crocoddyl/core/activation-base.hpp" | ||
16 | #include "crocoddyl/core/fwd.hpp" | ||
17 | #include "crocoddyl/core/utils/exception.hpp" | ||
18 | |||
19 | namespace crocoddyl { | ||
20 | |||
21 | template <typename _Scalar> | ||
22 | class ActivationModelQuadTpl : public ActivationModelAbstractTpl<_Scalar> { | ||
23 | public: | ||
24 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW | ||
25 | |||
26 | typedef _Scalar Scalar; | ||
27 | typedef MathBaseTpl<Scalar> MathBase; | ||
28 | typedef ActivationModelAbstractTpl<Scalar> Base; | ||
29 | typedef ActivationDataAbstractTpl<Scalar> ActivationDataAbstract; | ||
30 | typedef typename MathBase::VectorXs VectorXs; | ||
31 | typedef typename MathBase::MatrixXs MatrixXs; | ||
32 | |||
33 | 4484 | explicit ActivationModelQuadTpl(const std::size_t nr) : Base(nr) {}; | |
34 | 8972 | virtual ~ActivationModelQuadTpl() {}; | |
35 | |||
36 | 298291 | virtual void calc(const boost::shared_ptr<ActivationDataAbstract>& data, | |
37 | const Eigen::Ref<const VectorXs>& r) { | ||
38 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 298291 times.
|
298291 | if (static_cast<std::size_t>(r.size()) != nr_) { |
39 | ✗ | throw_pretty( | |
40 | "Invalid argument: " << "r has wrong dimension (it should be " + | ||
41 | std::to_string(nr_) + ")"); | ||
42 | } | ||
43 | 298291 | data->a_value = Scalar(0.5) * r.dot(r); | |
44 | 298291 | }; | |
45 | |||
46 | 51641 | virtual void calcDiff(const boost::shared_ptr<ActivationDataAbstract>& data, | |
47 | const Eigen::Ref<const VectorXs>& r) { | ||
48 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 51641 times.
|
51641 | if (static_cast<std::size_t>(r.size()) != nr_) { |
49 | ✗ | throw_pretty( | |
50 | "Invalid argument: " << "r has wrong dimension (it should be " + | ||
51 | std::to_string(nr_) + ")"); | ||
52 | } | ||
53 | |||
54 | 51641 | data->Ar = r; | |
55 | // The Hessian has constant values which were set in createData. | ||
56 |
3/14✓ Branch 4 taken 51641 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 51641 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 51641 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.
|
51641 | assert_pretty(MatrixXs(data->Arr).isApprox(MatrixXs::Identity(nr_, nr_)), |
57 | "Arr has wrong value"); | ||
58 | 51641 | }; | |
59 | |||
60 | 342172 | virtual boost::shared_ptr<ActivationDataAbstract> createData() { | |
61 |
1/2✓ Branch 1 taken 342172 times.
✗ Branch 2 not taken.
|
342172 | boost::shared_ptr<ActivationDataAbstract> data = |
62 | boost::allocate_shared<ActivationDataAbstract>( | ||
63 | 342172 | Eigen::aligned_allocator<ActivationDataAbstract>(), this); | |
64 |
1/2✓ Branch 3 taken 342172 times.
✗ Branch 4 not taken.
|
342172 | data->Arr.diagonal().setOnes(); |
65 | 342172 | return data; | |
66 | ✗ | }; | |
67 | |||
68 | /** | ||
69 | * @brief Print relevant information of the quadratic model | ||
70 | * | ||
71 | * @param[out] os Output stream object | ||
72 | */ | ||
73 | 39 | virtual void print(std::ostream& os) const { | |
74 | 39 | os << "ActivationModelQuad {nr=" << nr_ << "}"; | |
75 | 39 | } | |
76 | |||
77 | protected: | ||
78 | using Base::nr_; | ||
79 | }; | ||
80 | |||
81 | } // namespace crocoddyl | ||
82 | |||
83 | #endif // CROCODDYL_CORE_ACTIVATIONS_QUADRATIC_HPP_ | ||
84 |