| 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 | // Auto-generated file for float | ||
| 10 | #include "crocoddyl/core/numdiff/activation.hpp" | ||
| 11 | |||
| 12 | #include "python/crocoddyl/core/activation-base.hpp" | ||
| 13 | #include "python/crocoddyl/core/core.hpp" | ||
| 14 | #include "python/crocoddyl/utils/copyable.hpp" | ||
| 15 | |||
| 16 | namespace crocoddyl { | ||
| 17 | namespace python { | ||
| 18 | |||
| 19 | template <typename Model> | ||
| 20 | struct ActivationModelNumDiffVisitor | ||
| 21 | : public bp::def_visitor<ActivationModelNumDiffVisitor<Model>> { | ||
| 22 | typedef typename Model::Scalar Scalar; | ||
| 23 | template <class PyClass> | ||
| 24 | ✗ | void visit(PyClass& cl) const { | |
| 25 | ✗ | cl.def("calc", &Model::calc, bp::args("self", "data", "r"), | |
| 26 | "Compute the activation value.\n\n" | ||
| 27 | "The activation evolution is described in model.\n" | ||
| 28 | ":param data: NumDiff action data\n" | ||
| 29 | ":param r: residual vector") | ||
| 30 | ✗ | .def("calcDiff", &Model::calcDiff, bp::args("self", "data", "r"), | |
| 31 | "Compute the derivatives of the residual.\n\n" | ||
| 32 | "It computes the Jacobian and Hessian using numerical " | ||
| 33 | "differentiation.\n" | ||
| 34 | "It assumes that calc has been run first.\n" | ||
| 35 | ":param data: NumDiff action data\n" | ||
| 36 | ":param r: residual vector\n") | ||
| 37 | ✗ | .def("createData", &Model::createData, bp::args("self"), | |
| 38 | "Create the activation data.\n\n" | ||
| 39 | "Each activation model (AM) has its own data that needs to be " | ||
| 40 | "allocated.\n" | ||
| 41 | "This function returns the allocated data for a predefined AM.\n" | ||
| 42 | ":return AM data.") | ||
| 43 | ✗ | .add_property( | |
| 44 | "model", | ||
| 45 | bp::make_function(&Model::get_model, | ||
| 46 | ✗ | bp::return_value_policy<bp::return_by_value>()), | |
| 47 | "action model") | ||
| 48 | ✗ | .add_property( | |
| 49 | "disturbance", bp::make_function(&Model::get_disturbance), | ||
| 50 | "disturbance constant used in the numerical differentiation"); | ||
| 51 | ✗ | } | |
| 52 | }; | ||
| 53 | |||
| 54 | template <typename Data> | ||
| 55 | struct ActivationDataNumDiffVisitor | ||
| 56 | : public bp::def_visitor<ActivationDataNumDiffVisitor<Data>> { | ||
| 57 | template <class PyClass> | ||
| 58 | ✗ | void visit(PyClass& cl) const { | |
| 59 | ✗ | cl.add_property( | |
| 60 | ✗ | "dr", bp::make_getter(&Data::dr, bp::return_internal_reference<>()), | |
| 61 | "disturbance.") | ||
| 62 | ✗ | .add_property( | |
| 63 | ✗ | "rp", bp::make_getter(&Data::rp, bp::return_internal_reference<>()), | |
| 64 | "input plus the disturbance.") | ||
| 65 | ✗ | .add_property( | |
| 66 | "data_0", | ||
| 67 | ✗ | bp::make_getter(&Data::data_0, | |
| 68 | ✗ | bp::return_value_policy<bp::return_by_value>()), | |
| 69 | "data that contains the final results") | ||
| 70 | ✗ | .add_property( | |
| 71 | "data_rp", | ||
| 72 | ✗ | bp::make_getter(&Data::data_rp, | |
| 73 | ✗ | bp::return_value_policy<bp::return_by_value>()), | |
| 74 | "temporary data associated with the input variation") | ||
| 75 | ✗ | .add_property( | |
| 76 | "data_r2p", | ||
| 77 | ✗ | bp::make_getter(&Data::data_r2p, | |
| 78 | ✗ | bp::return_value_policy<bp::return_by_value>()), | |
| 79 | "temporary data associated with the input variation"); | ||
| 80 | ✗ | } | |
| 81 | }; | ||
| 82 | |||
| 83 | #define CROCODDYL_ACTIVATION_MODEL_NUMDIFF_PYTHON_BINDINGS(Scalar) \ | ||
| 84 | typedef ActivationModelNumDiffTpl<Scalar> Model; \ | ||
| 85 | typedef ActivationModelAbstractTpl<Scalar> ModelBase; \ | ||
| 86 | bp::register_ptr_to_python<std::shared_ptr<Model>>(); \ | ||
| 87 | bp::class_<Model, bp::bases<ModelBase>>( \ | ||
| 88 | "ActivationModelNumDiff", \ | ||
| 89 | "Abstract class for computing calcDiff by using numerical " \ | ||
| 90 | "differentiation.\n\n", \ | ||
| 91 | bp::init<std::shared_ptr<ModelBase>>( \ | ||
| 92 | bp::args("self", "model"), \ | ||
| 93 | "Initialize the activation model NumDiff.\n\n" \ | ||
| 94 | ":param model: activation model where we compute the derivatives " \ | ||
| 95 | "through NumDiff")) \ | ||
| 96 | .def(ActivationModelNumDiffVisitor<Model>()) \ | ||
| 97 | .def(CastVisitor<Model>()) \ | ||
| 98 | .def(PrintableVisitor<Model>()) \ | ||
| 99 | .def(CopyableVisitor<Model>()); | ||
| 100 | |||
| 101 | #define CROCODDYL_ACTIVATION_DATA_NUMDIFF_PYTHON_BINDINGS(Scalar) \ | ||
| 102 | typedef ActivationDataNumDiffTpl<Scalar> Data; \ | ||
| 103 | typedef ActivationDataAbstractTpl<Scalar> DataBase; \ | ||
| 104 | typedef ActivationModelNumDiffTpl<Scalar> Model; \ | ||
| 105 | bp::register_ptr_to_python<std::shared_ptr<Data>>(); \ | ||
| 106 | bp::class_<Data, bp::bases<DataBase>>( \ | ||
| 107 | "ActivationDataNumDiff", "Numerical differentiation activation data.", \ | ||
| 108 | bp::init<Model*>(bp::args("self", "model"), \ | ||
| 109 | "Create numerical differentiation activation data.\n\n" \ | ||
| 110 | ":param model: numdiff activation model")) \ | ||
| 111 | .def(ActivationDataNumDiffVisitor<Data>()) \ | ||
| 112 | .def(CopyableVisitor<Data>()); | ||
| 113 | |||
| 114 | ✗ | void exposeActivationNumDiff() { | |
| 115 | ✗ | CROCODDYL_ACTIVATION_MODEL_NUMDIFF_PYTHON_BINDINGS(float) | |
| 116 | ✗ | CROCODDYL_ACTIVATION_DATA_NUMDIFF_PYTHON_BINDINGS(float) | |
| 117 | ✗ | } | |
| 118 | |||
| 119 | } // namespace python | ||
| 120 | } // namespace crocoddyl | ||
| 121 |