| 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 | // Auto-generated file for float | ||
| 11 | #include "crocoddyl/core/activations/quadratic-barrier.hpp" | ||
| 12 | |||
| 13 | #include "python/crocoddyl/core/activation-base.hpp" | ||
| 14 | #include "python/crocoddyl/core/core.hpp" | ||
| 15 | |||
| 16 | namespace crocoddyl { | ||
| 17 | namespace python { | ||
| 18 | |||
| 19 | template <typename Bounds> | ||
| 20 | struct ActivationBoundsVisitor | ||
| 21 | : public bp::def_visitor<ActivationBoundsVisitor<Bounds>> { | ||
| 22 | typedef typename Bounds::Scalar Scalar; | ||
| 23 | template <class PyClass> | ||
| 24 | ✗ | void visit(PyClass& cl) const { | |
| 25 | ✗ | cl.add_property( | |
| 26 | ✗ | "lb", bp::make_getter(&Bounds::lb), | |
| 27 | ✗ | bp::make_setter(&Bounds::lb, bp::return_internal_reference<>()), | |
| 28 | "lower bounds") | ||
| 29 | ✗ | .add_property( | |
| 30 | ✗ | "ub", bp::make_getter(&Bounds::ub), | |
| 31 | ✗ | bp::make_setter(&Bounds::lb, bp::return_internal_reference<>()), | |
| 32 | "upper bounds") | ||
| 33 | ✗ | .add_property("beta", &Bounds::beta, "beta"); | |
| 34 | ✗ | } | |
| 35 | }; | ||
| 36 | |||
| 37 | template <typename Model> | ||
| 38 | struct ActivationModelQuadraticVisitor | ||
| 39 | : public bp::def_visitor<ActivationModelQuadraticVisitor<Model>> { | ||
| 40 | typedef typename Model::Scalar Scalar; | ||
| 41 | template <class PyClass> | ||
| 42 | ✗ | void visit(PyClass& cl) const { | |
| 43 | ✗ | cl.def("calc", &Model::calc, bp::args("self", "data", "r"), | |
| 44 | "Compute the inequality activation.\n\n" | ||
| 45 | ":param data: activation data\n" | ||
| 46 | ":param r: residual vector") | ||
| 47 | ✗ | .def("calcDiff", &Model::calcDiff, bp::args("self", "data", "r"), | |
| 48 | "Compute the derivatives of inequality activation.\n\n" | ||
| 49 | ":param data: activation data\n" | ||
| 50 | "Note that the Hessian is constant, so we don't write again this " | ||
| 51 | "value. It assumes that calc has been run first.\n" | ||
| 52 | ":param r: residual vector \n") | ||
| 53 | ✗ | .def("createData", &Model::createData, bp::args("self"), | |
| 54 | "Create the weighted quadratic action data.") | ||
| 55 | ✗ | .add_property("bounds", | |
| 56 | bp::make_function(&Model::get_bounds, | ||
| 57 | ✗ | bp::return_internal_reference<>()), | |
| 58 | bp::make_function(&Model::set_bounds), | ||
| 59 | "bounds (beta, lower and upper bounds)"); | ||
| 60 | ✗ | } | |
| 61 | }; | ||
| 62 | |||
| 63 | #define CROCODDYL_ACTIVATION_BOUNDS_PYTHON_BINDINGS(Scalar) \ | ||
| 64 | typedef ActivationBoundsTpl<Scalar> Bounds; \ | ||
| 65 | typedef typename Bounds::VectorXs VectorXs; \ | ||
| 66 | bp::register_ptr_to_python<std::shared_ptr<Bounds>>(); \ | ||
| 67 | bp::class_<Bounds>( \ | ||
| 68 | "ActivationBounds", \ | ||
| 69 | "Activation bounds.\n\n" \ | ||
| 70 | "The activation bounds describe the lower and upper vector plus it " \ | ||
| 71 | "activation range (between 0 and 1), its default value is 1. Note that " \ | ||
| 72 | "a full activation is defined by 1 and the activation range is equally " \ | ||
| 73 | "distributed between the lower and upper bounds.", \ | ||
| 74 | bp::init<VectorXs, VectorXs, bp::optional<Scalar>>( \ | ||
| 75 | bp::args("self", "lb", "ub", "beta"), \ | ||
| 76 | "Initialize the activation bounds.\n\n" \ | ||
| 77 | ":param lb: lower bounds\n" \ | ||
| 78 | ":param ub: upper bounds\n" \ | ||
| 79 | ":param beta: range of activation (between 0 to 1, default 1)")) \ | ||
| 80 | .def(ActivationBoundsVisitor<Bounds>()) \ | ||
| 81 | .def(CastVisitor<Bounds>()) \ | ||
| 82 | .def(PrintableVisitor<Bounds>()) \ | ||
| 83 | .def(CopyableVisitor<Bounds>()); | ||
| 84 | |||
| 85 | #define CROCODDYL_ACTIVATION_MODEL_QUADRATIC_BARRIER_PYTHON_BINDINGS(Scalar) \ | ||
| 86 | typedef ActivationModelQuadraticBarrierTpl<Scalar> Model; \ | ||
| 87 | typedef ActivationModelAbstractTpl<Scalar> ModelBase; \ | ||
| 88 | typedef ActivationBoundsTpl<Scalar> Bounds; \ | ||
| 89 | bp::register_ptr_to_python<std::shared_ptr<Model>>(); \ | ||
| 90 | bp::class_<Model, bp::bases<ModelBase>>( \ | ||
| 91 | "ActivationModelQuadraticBarrier", \ | ||
| 92 | "Inequality activation model.\n\n" \ | ||
| 93 | "The activation is zero when r is between the lower (lb) and upper " \ | ||
| 94 | "(ub) bounds, beta determines how much of the total range is not " \ | ||
| 95 | "activated. This is the activation equations:\n" \ | ||
| 96 | "a(r) = 0.5 * ||r||^2 for lb > r > ub\n" \ | ||
| 97 | "a(r) = 0. for lb <= r <= ub.", \ | ||
| 98 | bp::init<Bounds>(bp::args("self", "bounds"), \ | ||
| 99 | "Initialize the activation model.\n\n" \ | ||
| 100 | ":param bounds: activation bounds")) \ | ||
| 101 | .def(ActivationModelQuadraticVisitor<Model>()) \ | ||
| 102 | .def(CastVisitor<Model>()) \ | ||
| 103 | .def(PrintableVisitor<Model>()) \ | ||
| 104 | .def(CopyableVisitor<Model>()); | ||
| 105 | |||
| 106 | ✗ | void exposeActivationQuadraticBarrier() { | |
| 107 | ✗ | CROCODDYL_ACTIVATION_BOUNDS_PYTHON_BINDINGS(float) | |
| 108 | ✗ | CROCODDYL_ACTIVATION_MODEL_QUADRATIC_BARRIER_PYTHON_BINDINGS(float) | |
| 109 | ✗ | } | |
| 110 | |||
| 111 | } // namespace python | ||
| 112 | } // namespace crocoddyl | ||
| 113 |