GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/core/activations/weighted-quadratic-barrier.cpp
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 12 12 100.0%
Branches: 28 56 50.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2025, University of Edinburgh, Heriot-Watt University
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #include "crocoddyl/core/activations/weighted-quadratic-barrier.hpp"
10
11 #include "python/crocoddyl/core/activation-base.hpp"
12 #include "python/crocoddyl/core/core.hpp"
13
14 namespace crocoddyl {
15 namespace python {
16
17 template <typename Model>
18 struct ActivationModelWeightedQuadraticBarrierVisitor
19 : public bp::def_visitor<
20 ActivationModelWeightedQuadraticBarrierVisitor<Model>> {
21 typedef typename Model::Scalar Scalar;
22 template <class PyClass>
23 40 void visit(PyClass& cl) const {
24 40 cl.def("calc", &Model::calc, bp::args("self", "data", "r"),
25 "Compute the inequality activation.\n\n"
26 ":param data: activation data\n"
27 ":param r: residual vector")
28
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
80 .def("calcDiff", &Model::calcDiff, bp::args("self", "data", "r"),
29 "Compute the derivatives of inequality activation.\n\n"
30 "Note that the Hessian is constant, so we don't write again this "
31 "value. It assumes that calc has been run first.\n"
32 ":param data: activation data\n"
33 ":param r: residual vector \n")
34
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
80 .def("createData", &Model::createData, bp::args("self"),
35 "Create the weighted quadratic activation data.")
36
4/8
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 20 times.
✗ Branch 11 not taken.
80 .add_property(
37 "bounds",
38 bp::make_function(&Model::get_bounds,
39 40 bp::return_value_policy<bp::return_by_value>()),
40 bp::make_function(&Model::set_bounds),
41 "bounds (beta, lower and upper bounds)")
42
3/6
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
80 .add_property("weights",
43 bp::make_function(&Model::get_weights,
44 40 bp::return_internal_reference<>()),
45 bp::make_function(&Model::set_weights),
46 "vector of weights");
47 40 }
48 };
49
50 #define CROCODDYL_ACTIVATION_MODEL_WEIGHTEDQUADRATICBARRIER_PYTHON_BINDINGS( \
51 Scalar) \
52 typedef ActivationModelWeightedQuadraticBarrierTpl<Scalar> Model; \
53 typedef ActivationModelAbstractTpl<Scalar> ModelBase; \
54 typedef ActivationBoundsTpl<Scalar> Bounds; \
55 typedef typename Model::VectorXs VectorXs; \
56 bp::register_ptr_to_python<std::shared_ptr<Model>>(); \
57 bp::class_<Model, bp::bases<ModelBase>>( \
58 "ActivationModelWeightedQuadraticBarrier", \
59 "Inequality activation model.\n\n" \
60 "The activation is zero when r is between the lower (lb) and upper " \
61 "(ub) bounds, beta determines how much of the total range is not " \
62 "activated. This is the activation equations:\n" \
63 "a(r) = 0.5 * ||r||_w^2 for lb < r < ub\n" \
64 "a(r) = 0. for lb >= r >= ub,\n" \
65 "where w is the vector of weights", \
66 bp::init<Bounds, VectorXs>(bp::args("self", "bounds", "weights"), \
67 "Initialize the activation model.\n\n" \
68 ":param bounds: activation bounds\n" \
69 ":param weights: weights")) \
70 .def(ActivationModelWeightedQuadraticBarrierVisitor<Model>()) \
71 .def(CastVisitor<Model>()) \
72 .def(PrintableVisitor<Model>()) \
73 .def(CopyableVisitor<Model>());
74
75 10 void exposeActivationWeightedQuadraticBarrier() {
76
17/34
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 10 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 10 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 10 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 10 times.
✗ Branch 19 not taken.
✓ Branch 24 taken 10 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 10 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 10 times.
✗ Branch 31 not taken.
✓ Branch 35 taken 10 times.
✗ Branch 36 not taken.
✓ Branch 38 taken 10 times.
✗ Branch 39 not taken.
✓ Branch 41 taken 10 times.
✗ Branch 42 not taken.
✓ Branch 44 taken 10 times.
✗ Branch 45 not taken.
✓ Branch 47 taken 10 times.
✗ Branch 48 not taken.
✓ Branch 50 taken 10 times.
✗ Branch 51 not taken.
✓ Branch 53 taken 10 times.
✗ Branch 54 not taken.
✓ Branch 56 taken 10 times.
✗ Branch 57 not taken.
20 CROCODDYL_PYTHON_SCALARS(
77 CROCODDYL_ACTIVATION_MODEL_WEIGHTEDQUADRATICBARRIER_PYTHON_BINDINGS)
78 10 }
79
80 } // namespace python
81 } // namespace crocoddyl
82