GCC Code Coverage Report


Directory: ./
File: include/crocoddyl/core/activations/quadratic.hpp
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 23 26 88.5%
Branches: 7 54 13.0%

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 #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
18 namespace crocoddyl {
19
20 template <typename _Scalar>
21 class ActivationModelQuadTpl : public ActivationModelAbstractTpl<_Scalar> {
22 public:
23 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
24 16 CROCODDYL_DERIVED_CAST(ActivationModelBase, ActivationModelQuadTpl)
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 4478 explicit ActivationModelQuadTpl(const std::size_t nr) : Base(nr) {};
34 8968 virtual ~ActivationModelQuadTpl() = default;
35
36 296717 virtual void calc(const std::shared_ptr<ActivationDataAbstract>& data,
37 const Eigen::Ref<const VectorXs>& r) override {
38
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 296717 times.
296717 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 296717 data->a_value = Scalar(0.5) * r.dot(r);
44 296717 };
45
46 50852 virtual void calcDiff(const std::shared_ptr<ActivationDataAbstract>& data,
47 const Eigen::Ref<const VectorXs>& r) override {
48
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 50852 times.
50852 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 50852 data->Ar = r;
55 // The Hessian has constant values which were set in createData.
56
3/14
✓ Branch 4 taken 50852 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 50852 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 50852 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.
50852 assert_pretty(MatrixXs(data->Arr).isApprox(MatrixXs::Identity(nr_, nr_)),
57 "Arr has wrong value");
58 50852 };
59
60 340861 virtual std::shared_ptr<ActivationDataAbstract> createData() override {
61
1/2
✓ Branch 1 taken 340861 times.
✗ Branch 2 not taken.
340861 std::shared_ptr<ActivationDataAbstract> data =
62 std::allocate_shared<ActivationDataAbstract>(
63 340861 Eigen::aligned_allocator<ActivationDataAbstract>(), this);
64
1/2
✓ Branch 3 taken 340861 times.
✗ Branch 4 not taken.
340861 data->Arr.diagonal().setOnes();
65 340861 return data;
66 };
67
68 template <typename NewScalar>
69 4 ActivationModelQuadTpl<NewScalar> cast() const {
70 typedef ActivationModelQuadTpl<NewScalar> ReturnType;
71 4 ReturnType res(nr_);
72 4 return res;
73 }
74
75 /**
76 * @brief Print relevant information of the quadratic model
77 *
78 * @param[out] os Output stream object
79 */
80 37 virtual void print(std::ostream& os) const override {
81 37 os << "ActivationModelQuad {nr=" << nr_ << "}";
82 37 }
83
84 protected:
85 using Base::nr_;
86 };
87
88 } // namespace crocoddyl
89
90 extern template class CROCODDYL_EXPLICIT_INSTANTIATION_DECLARATION_DLLAPI
91 crocoddyl::ActivationModelQuadTpl<double>;
92 extern template class CROCODDYL_EXPLICIT_INSTANTIATION_DECLARATION_DLLAPI
93 crocoddyl::ActivationModelQuadTpl<float>;
94
95 #endif // CROCODDYL_CORE_ACTIVATIONS_QUADRATIC_HPP_
96