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 double |
11 |
|
|
#include "crocoddyl/core/activations/smooth-1norm.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 Model> |
20 |
|
|
struct ActivationModelSmooth1NormVisitor |
21 |
|
|
: public bp::def_visitor<ActivationModelSmooth1NormVisitor<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 smooth-abs function.\n\n" |
27 |
|
|
":param data: activation data\n" |
28 |
|
|
":param r: residual vector") |
29 |
|
✗ |
.def("calcDiff", &Model::calcDiff, bp::args("self", "data", "r"), |
30 |
|
|
"Compute the derivatives of a smooth-abs function.\n\n" |
31 |
|
|
"It assumes that calc has been run first.\n" |
32 |
|
|
":param data: activation data\n" |
33 |
|
|
":param r: residual vector \n") |
34 |
|
✗ |
.def("createData", &Model::createData, bp::args("self"), |
35 |
|
|
"Create the smooth-abs activation data.\n\n"); |
36 |
|
|
} |
37 |
|
|
}; |
38 |
|
|
|
39 |
|
|
template <typename Data> |
40 |
|
|
struct ActivationDataSmooth1NormVisitor |
41 |
|
|
: public bp::def_visitor<ActivationDataSmooth1NormVisitor<Data>> { |
42 |
|
|
typedef typename Data::Scalar Scalar; |
43 |
|
|
template <class PyClass> |
44 |
|
✗ |
void visit(PyClass& cl) const { |
45 |
|
✗ |
cl.add_property( |
46 |
|
✗ |
"a", bp::make_getter(&Data::a, bp::return_internal_reference<>()), |
47 |
|
|
"sqrt{eps + ||ri||^2} value"); |
48 |
|
|
} |
49 |
|
|
}; |
50 |
|
|
|
51 |
|
|
#define CROCODDYL_ACTIVATION_MODEL_SMOOTH1NORM_PYTHON_BINDINGS(Scalar) \ |
52 |
|
|
typedef ActivationModelSmooth1NormTpl<Scalar> Model; \ |
53 |
|
|
typedef ActivationModelAbstractTpl<Scalar> ModelBase; \ |
54 |
|
|
bp::register_ptr_to_python<std::shared_ptr<Model>>(); \ |
55 |
|
|
bp::class_<Model, bp::bases<ModelBase>>( \ |
56 |
|
|
"ActivationModelSmooth1Norm", \ |
57 |
|
|
"Smooth-absolute activation model.\n\n" \ |
58 |
|
|
"It describes a smooth representation of an absolute activation " \ |
59 |
|
|
"(1-norm), i.e., sum^nr_{i=0} sqrt{eps + ||ri||^2}, where ri is the " \ |
60 |
|
|
"scalar residual for the i constraints, and nr is the dimension of the " \ |
61 |
|
|
"residual vector.", \ |
62 |
|
|
bp::init<std::size_t, bp::optional<Scalar>>( \ |
63 |
|
|
bp::args("self", "nr", "eps"), \ |
64 |
|
|
"Initialize the activation model.\n\n" \ |
65 |
|
|
":param nr: dimension of the residual vector\n" \ |
66 |
|
|
":param eps: smoothing factor (default: 1.)")) \ |
67 |
|
|
.def(ActivationModelSmooth1NormVisitor<Model>()) \ |
68 |
|
|
.def(CastVisitor<Model>()) \ |
69 |
|
|
.def(PrintableVisitor<Model>()) \ |
70 |
|
|
.def(CopyableVisitor<Model>()); |
71 |
|
|
|
72 |
|
|
#define CROCODDYL_ACTIVATION_DATA_SMOOTH1NORM_PYTHON_BINDINGS(Scalar) \ |
73 |
|
|
typedef ActivationDataSmooth1NormTpl<Scalar> Data; \ |
74 |
|
|
typedef ActivationDataAbstractTpl<Scalar> DataBase; \ |
75 |
|
|
typedef ActivationModelSmooth1NormTpl<Scalar> Model; \ |
76 |
|
|
bp::register_ptr_to_python<std::shared_ptr<Data>>(); \ |
77 |
|
|
bp::class_<Data, bp::bases<DataBase>>( \ |
78 |
|
|
"ActivationDataSmooth1Norm", "Data for smooth-abs activation.\n\n", \ |
79 |
|
|
bp::init<Model*>(bp::args("self", "model"), \ |
80 |
|
|
"Create smooth-abs activation data.\n\n" \ |
81 |
|
|
":param model: smooth-abs activation model")) \ |
82 |
|
|
.def(ActivationDataSmooth1NormVisitor<Data>()) \ |
83 |
|
|
.def(CopyableVisitor<Data>()); |
84 |
|
|
|
85 |
|
✗ |
void exposeActivationSmooth1Norm() { |
86 |
|
✗ |
CROCODDYL_ACTIVATION_MODEL_SMOOTH1NORM_PYTHON_BINDINGS(double) |
87 |
|
✗ |
CROCODDYL_ACTIVATION_DATA_SMOOTH1NORM_PYTHON_BINDINGS(double) |
88 |
|
|
} |
89 |
|
|
|
90 |
|
|
} // namespace python |
91 |
|
|
} // namespace crocoddyl |
92 |
|
|
|