Directory: | ./ |
---|---|
File: | bindings/python/crocoddyl/core/numdiff/activation.cpp |
Date: | 2025-01-16 08:47:40 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 36 | 36 | 100.0% |
Branches: | 26 | 52 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2019-2023, University of Edinburgh, Heriot-Watt University | ||
5 | // Copyright note valid unless otherwise stated in individual files. | ||
6 | // All rights reserved. | ||
7 | /////////////////////////////////////////////////////////////////////////////// | ||
8 | |||
9 | #include "crocoddyl/core/numdiff/activation.hpp" | ||
10 | |||
11 | #include "python/crocoddyl/core/activation-base.hpp" | ||
12 | #include "python/crocoddyl/core/core.hpp" | ||
13 | #include "python/crocoddyl/utils/copyable.hpp" | ||
14 | |||
15 | namespace crocoddyl { | ||
16 | namespace python { | ||
17 | |||
18 | 10 | void exposeActivationNumDiff() { | |
19 | 10 | bp::register_ptr_to_python<boost::shared_ptr<ActivationModelNumDiff> >(); | |
20 | |||
21 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ActivationModelNumDiff, bp::bases<ActivationModelAbstract> >( |
22 | "ActivationModelNumDiff", | ||
23 | "Abstract class for computing calcDiff by using numerical " | ||
24 | "differentiation.\n\n", | ||
25 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<boost::shared_ptr<ActivationModelAbstract> >( |
26 | 20 | bp::args("self", "model"), | |
27 | "Initialize the activation model NumDiff.\n\n" | ||
28 | ":param model: activation model where we compute the derivatives " | ||
29 | "through NumDiff")) | ||
30 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
20 | .def("calc", &ActivationModelNumDiff::calc, bp::args("self", "data", "r"), |
31 | "Compute the activation value.\n\n" | ||
32 | "The activation evolution is described in model.\n" | ||
33 | ":param data: NumDiff action data\n" | ||
34 | ":param r: residual vector") | ||
35 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("calcDiff", &ActivationModelNumDiff::calcDiff, |
36 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "r"), |
37 | "Compute the derivatives of the residual.\n\n" | ||
38 | "It computes the Jacobian and Hessian using numerical " | ||
39 | "differentiation.\n" | ||
40 | "It assumes that calc has been run first.\n" | ||
41 | ":param data: NumDiff action data\n" | ||
42 | ":param r: residual vector\n") | ||
43 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
20 | .def("createData", &ActivationModelNumDiff::createData, bp::args("self"), |
44 | "Create the activation data.\n\n" | ||
45 | "Each activation model (AM) has its own data that needs to be " | ||
46 | "allocated.\n" | ||
47 | "This function returns the allocated data for a predefined AM.\n" | ||
48 | ":return AM data.") | ||
49 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
50 | "model", | ||
51 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_function(&ActivationModelNumDiff::get_model, |
52 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
53 | "action model") | ||
54 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
55 | "disturbance", | ||
56 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_function(&ActivationModelNumDiff::get_disturbance), |
57 | "disturbance constant used in the numerical differentiation") | ||
58 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ActivationModelNumDiff>()); |
59 | |||
60 | 10 | bp::register_ptr_to_python<boost::shared_ptr<ActivationDataNumDiff> >(); | |
61 | |||
62 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ActivationDataNumDiff, bp::bases<ActivationDataAbstract> >( |
63 | "ActivationDataNumDiff", "Numerical differentiation activation data.", | ||
64 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<ActivationModelNumDiff*>( |
65 | 20 | bp::args("self", "model"), | |
66 | "Create numerical differentiation activation data.\n\n" | ||
67 | ":param model: numdiff activation model")) | ||
68 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("dr", |
69 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ActivationDataNumDiff::dr, |
70 | 10 | bp::return_internal_reference<>()), | |
71 | "disturbance.") | ||
72 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("rp", |
73 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ActivationDataNumDiff::rp, |
74 | 10 | bp::return_internal_reference<>()), | |
75 | "input plus the disturbance.") | ||
76 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
77 | "data_0", | ||
78 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ActivationDataNumDiff::data_0, |
79 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
80 | "data that contains the final results") | ||
81 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
82 | "data_rp", | ||
83 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ActivationDataNumDiff::data_rp, |
84 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
85 | "temporary data associated with the input variation") | ||
86 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
87 | "data_r2p", | ||
88 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ActivationDataNumDiff::data_r2p, |
89 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
90 | "temporary data associated with the input variation") | ||
91 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ActivationDataNumDiff>()); |
92 | 10 | } | |
93 | |||
94 | } // namespace python | ||
95 | } // namespace crocoddyl | ||
96 |