Directory: | ./ |
---|---|
File: | bindings/python/crocoddyl/core/activations/smooth-1norm.cpp |
Date: | 2025-01-16 08:47:40 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 21 | 21 | 100.0% |
Branches: | 14 | 28 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2019-2024, 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/smooth-1norm.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 | 10 | void exposeActivationSmooth1Norm() { | |
20 | boost::python::register_ptr_to_python< | ||
21 | 10 | boost::shared_ptr<ActivationModelSmooth1Norm> >(); | |
22 | |||
23 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ActivationModelSmooth1Norm, bp::bases<ActivationModelAbstract> >( |
24 | "ActivationModelSmooth1Norm", | ||
25 | "Smooth-absolute activation model.\n\n" | ||
26 | "It describes a smooth representation of an absolute activation " | ||
27 | "(1-norm), i.e.\n" | ||
28 | "sum^nr_{i=0} sqrt{eps + ||ri||^2}, where ri is the scalar residual for " | ||
29 | "the i constraints,\n." | ||
30 | "and nr is the dimension of the residual vector.", | ||
31 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<std::size_t, bp::optional<double> >( |
32 | 20 | bp::args("self", "nr", "eps"), | |
33 | "Initialize the activation model.\n\n" | ||
34 | ":param nr: dimension of the residual vector\n" | ||
35 | ":param eps: smoothing factor (default: 1.)")) | ||
36 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("calc", &ActivationModelSmooth1Norm::calc, |
37 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "r"), |
38 | "Compute the smooth-abs function.\n\n" | ||
39 | ":param data: activation data\n" | ||
40 | ":param r: residual vector") | ||
41 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("calcDiff", &ActivationModelSmooth1Norm::calcDiff, |
42 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "r"), |
43 | "Compute the derivatives of a smooth-abs function.\n\n" | ||
44 | "It assumes that calc has been run first.\n" | ||
45 | ":param data: activation data\n" | ||
46 | ":param r: residual vector \n") | ||
47 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("createData", &ActivationModelSmooth1Norm::createData, |
48 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self"), "Create the smooth-abs activation data.\n\n") |
49 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ActivationModelSmooth1Norm>()); |
50 | |||
51 | 10 | bp::register_ptr_to_python<boost::shared_ptr<ActivationDataSmooth1Norm> >(); | |
52 | |||
53 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ActivationDataSmooth1Norm, bp::bases<ActivationDataAbstract> >( |
54 | "ActivationDataSmooth1Norm", "Data for smooth-abs activation.\n\n", | ||
55 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<ActivationModelSmooth1Norm*>( |
56 | 20 | bp::args("self", "model"), | |
57 | "Create smooth-abs activation data.\n\n" | ||
58 | ":param model: smooth-abs activation model")) | ||
59 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("a", |
60 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ActivationDataSmooth1Norm::a, |
61 | 10 | bp::return_internal_reference<>()), | |
62 | "sqrt{eps + ||ri||^2} value") | ||
63 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ActivationDataSmooth1Norm>()); |
64 | 10 | } | |
65 | |||
66 | } // namespace python | ||
67 | } // namespace crocoddyl | ||
68 |