GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/core/activations/weighted-quadratic.cpp
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 10 10 100.0%
Branches: 24 48 50.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 #include "crocoddyl/core/activations/weighted-quadratic.hpp"
11
12 #include "python/crocoddyl/core/activation-base.hpp"
13 #include "python/crocoddyl/core/core.hpp"
14
15 namespace crocoddyl {
16 namespace python {
17
18 template <typename Model>
19 struct ActivationModelWeightedQuadVisitor
20 : public bp::def_visitor<ActivationModelWeightedQuadVisitor<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 0.5 * ||r||_w^2.\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 a quadratic function.\n\n"
30 ":param data: activation data\n"
31 "Note that the Hessian is constant, so we don't write again this "
32 "value.\n"
33 "It assumes that calc has been run first.\n"
34 ":param r: residual vector \n")
35
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"),
36 "Create the weighted quadratic action data.")
37
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.
40 .add_property("weights",
38 bp::make_function(&Model::get_weights,
39 40 bp::return_internal_reference<>()),
40 &Model::set_weights, "weights of the quadratic term");
41 40 }
42 };
43
44 #define CROCODDYL_ACTIVATION_MODEL_WEIGHTEDQUAD_PYTHON_BINDINGS(Scalar) \
45 typedef ActivationModelWeightedQuadTpl<Scalar> Model; \
46 typedef ActivationModelAbstractTpl<Scalar> ModelBase; \
47 typedef typename Model::VectorXs VectorXs; \
48 bp::register_ptr_to_python<std::shared_ptr<Model>>(); \
49 bp::class_<Model, bp::bases<ModelBase>>( \
50 "ActivationModelWeightedQuad", \
51 "Weighted quadratic activation model.\n\n" \
52 "A weighted quadratic action describes a quadratic function that " \
53 "depends on the residual, i.e., 0.5 *||r||_w^2.", \
54 bp::init<VectorXs>( \
55 bp::args("self", "weights"), \
56 "Initialize the activation model.\n\n" \
57 ":param weights: weights vector, note that nr=weights.size()")) \
58 .def(ActivationModelWeightedQuadVisitor<Model>()) \
59 .def(CastVisitor<Model>()) \
60 .def(PrintableVisitor<Model>()) \
61 .def(CopyableVisitor<Model>());
62
63 10 void exposeActivationWeightedQuad() {
64
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(
65 CROCODDYL_ACTIVATION_MODEL_WEIGHTEDQUAD_PYTHON_BINDINGS)
66 10 }
67
68 } // namespace python
69 } // namespace crocoddyl
70