GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/core/activations/2norm-barrier.cpp
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 10 10 100.0%
Branches: 25 50 50.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2021-2025, LAAS-CNRS, Heriot-Watt University
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #include "crocoddyl/core/activations/2norm-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 ActivationModel2NormBarrierVisitor
19 : public bp::def_visitor<ActivationModel2NormBarrierVisitor<Model>> {
20 typedef typename Model::Scalar Scalar;
21 template <class PyClass>
22 40 void visit(PyClass& cl) const {
23 40 cl.def("calc", &Model::calc, bp::args("self", "data", "r"),
24 "Compute the activation value.\n\n"
25 ":param data: activation data\n"
26 ":param r: residual vector")
27
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"),
28 "Compute the derivatives of the collision function.\n\n"
29 ":param data: activation data\n"
30 ":param r: residual vector \n")
31
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"),
32 "Create the collision activation data.\n\n")
33
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(
34 "alpha",
35 bp::make_function(&Model::get_alpha,
36 40 bp::return_value_policy<bp::return_by_value>()),
37 bp::make_function(&Model::set_alpha), "alpha");
38 40 }
39 };
40
41 #define CROCODDYL_ACTIVATION_MODEL_2NORM_BARRIER_PYTHON_BINDINGS(Scalar) \
42 typedef ActivationModel2NormBarrierTpl<Scalar> Model; \
43 typedef ActivationModelAbstractTpl<Scalar> ModelBase; \
44 bp::register_ptr_to_python<std::shared_ptr<Model>>(); \
45 bp::class_<Model, bp::bases<ModelBase>>( \
46 "ActivationModel2NormBarrier", \
47 "An 2-norm activation model for a defined barrier alpha\n\n" \
48 "If the residual is lower than an alpha threshold, this function " \
49 "imposes a quadratic term. In short, the activation value is 0 if the " \
50 "residual is major or equals alpha, otherwise, it is equals to 0.5 " \
51 "*(||r|| - alpha)^2", \
52 bp::init<std::size_t, bp::optional<Scalar, bool>>( \
53 bp::args("self", "nr", "alpha", "true_hessian"), \
54 "Initialize the activation model.\n\n" \
55 ":param nr: dimension of the cost-residual vector\n" \
56 ":param alpha: activation threshold (default 0.1)\n" \
57 ":param true_hessian: use true Hessian in calcDiff if true, " \
58 "else Gauss-Newton approximation (default false)")) \
59 .def(ActivationModel2NormBarrierVisitor<Model>()) \
60 .def(CastVisitor<Model>()) \
61 .def(PrintableVisitor<Model>()) \
62 .def(CopyableVisitor<Model>());
63
64 10 void exposeActivation2NormBarrier() {
65
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(
66 CROCODDYL_ACTIVATION_MODEL_2NORM_BARRIER_PYTHON_BINDINGS)
67 10 }
68
69 } // namespace python
70 } // namespace crocoddyl
71