| Directory: | ./ |
|---|---|
| File: | bindings/python/crocoddyl/core/activation-base.cpp |
| Date: | 2025-03-26 19:23:43 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 17 | 17 | 100.0% |
| Branches: | 44 | 88 | 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 "python/crocoddyl/core/activation-base.hpp" | ||
| 11 | |||
| 12 | namespace crocoddyl { | ||
| 13 | namespace python { | ||
| 14 | |||
| 15 | template <typename Model> | ||
| 16 | struct ActivationModelAbstractVisitor | ||
| 17 | : public bp::def_visitor<ActivationModelAbstractVisitor<Model>> { | ||
| 18 | template <class PyClass> | ||
| 19 | 40 | void visit(PyClass& cl) const { | |
| 20 |
2/4✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 20 times.
✗ Branch 6 not taken.
|
40 | cl.def("calc", pure_virtual(&Model::calc), bp::args("self", "data", "r"), |
| 21 | "Compute the activation value.\n\n" | ||
| 22 | ":param data: activation data\n" | ||
| 23 | ":param r: residual vector") | ||
| 24 |
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 | .def("calcDiff", pure_virtual(&Model::calcDiff), |
| 25 | bp::args("self", "data", "r"), | ||
| 26 | "Compute the derivatives of the residual.\n\n" | ||
| 27 | "It computes the partial derivatives of the residual vector " | ||
| 28 | "function.\n" | ||
| 29 | ":param data: activation data\n" | ||
| 30 | ":param r: residual vector \n") | ||
| 31 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
80 | .def("createData", &Model::createData, &Model::default_createData, |
| 32 | bp::args("self"), "Create the activation data.\n\n") | ||
| 33 |
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("nr", bp::make_function(&Model::get_nr), |
| 34 | "dimension of cost-residual vector"); | ||
| 35 | 40 | } | |
| 36 | }; | ||
| 37 | |||
| 38 | template <typename Data> | ||
| 39 | struct ActivationDataAbstractVisitor | ||
| 40 | : public bp::def_visitor<ActivationDataAbstractVisitor<Data>> { | ||
| 41 | template <class PyClass> | ||
| 42 | 40 | void visit(PyClass& cl) const { | |
| 43 |
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 | cl.add_property( |
| 44 | "a_value", | ||
| 45 | bp::make_getter(&Data::a_value, | ||
| 46 | 40 | bp::return_value_policy<bp::return_by_value>()), | |
| 47 | bp::make_setter(&Data::a_value), "cost value") | ||
| 48 |
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.
|
120 | .add_property( |
| 49 | 40 | "Ar", bp::make_getter(&Data::Ar, bp::return_internal_reference<>()), | |
| 50 | bp::make_setter(&Data::Ar), "Jacobian of the residual") | ||
| 51 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
40 | .add_property("Arr", &Data::getHessianMatrix, &Data::setHessianMatrix, |
| 52 | "Hessian of the residual"); | ||
| 53 | 40 | } | |
| 54 | }; | ||
| 55 | |||
| 56 | #define CROCODDYL_ACTIVATION_MODEL_ABSTRACT_PYTHON_BINDINGS(Scalar) \ | ||
| 57 | typedef ActivationModelAbstractTpl<Scalar> Model; \ | ||
| 58 | typedef ActivationModelAbstractTpl_wrap<Scalar> Model_wrap; \ | ||
| 59 | bp::register_ptr_to_python<std::shared_ptr<Model>>(); \ | ||
| 60 | bp::class_<Model_wrap, boost::noncopyable>( \ | ||
| 61 | "ActivationModelAbstract", \ | ||
| 62 | "Abstract class for activation models.\n\n" \ | ||
| 63 | "In crocoddyl, an activation model takes the residual vector and " \ | ||
| 64 | "computes the activation value and its derivatives from it. Activation " \ | ||
| 65 | "value and its derivatives are computed by calc() and calcDiff(), " \ | ||
| 66 | "respectively.", \ | ||
| 67 | bp::init<std::size_t>( \ | ||
| 68 | bp::args("self", "nr"), \ | ||
| 69 | "Initialize the activation model.\n\n" \ | ||
| 70 | ":param nr: dimension of the cost-residual vector")) \ | ||
| 71 | .def(ActivationModelAbstractVisitor<Model_wrap>()) \ | ||
| 72 | .def(PrintableVisitor<Model_wrap>()) \ | ||
| 73 | .def(CopyableVisitor<Model_wrap>()); | ||
| 74 | |||
| 75 | #define CROCODDYL_ACTIVATION_DATA_ABSTRACT_PYTHON_BINDINGS(Scalar) \ | ||
| 76 | typedef ActivationDataAbstractTpl<Scalar> Data; \ | ||
| 77 | typedef ActivationModelAbstractTpl<Scalar> Model; \ | ||
| 78 | bp::register_ptr_to_python<std::shared_ptr<Data>>(); \ | ||
| 79 | bp::class_<Data>( \ | ||
| 80 | "ActivationDataAbstract", "Abstract class for activation data.\n\n", \ | ||
| 81 | bp::init<Model*>( \ | ||
| 82 | bp::args("self", "model"), \ | ||
| 83 | "Create common data shared between AMs.\n\n" \ | ||
| 84 | "The action data uses the model in order to first process it.\n" \ | ||
| 85 | ":param model: action model")) \ | ||
| 86 | .def(ActivationDataAbstractVisitor<Data>()) \ | ||
| 87 | .def(CopyableVisitor<Data>()); | ||
| 88 | |||
| 89 | 10 | void exposeActivationAbstract() { | |
| 90 |
15/30✓ 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 21 taken 10 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 10 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 10 times.
✗ Branch 28 not taken.
✓ Branch 32 taken 10 times.
✗ Branch 33 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.
|
20 | CROCODDYL_PYTHON_SCALARS(CROCODDYL_ACTIVATION_MODEL_ABSTRACT_PYTHON_BINDINGS) |
| 91 |
13/26✓ 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 18 taken 10 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 10 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 10 times.
✗ Branch 25 not taken.
✓ Branch 29 taken 10 times.
✗ Branch 30 not taken.
✓ Branch 32 taken 10 times.
✗ Branch 33 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.
|
20 | CROCODDYL_PYTHON_SCALARS(CROCODDYL_ACTIVATION_DATA_ABSTRACT_PYTHON_BINDINGS) |
| 92 | 10 | } | |
| 93 | |||
| 94 | } // namespace python | ||
| 95 | } // namespace crocoddyl | ||
| 96 |