Directory: | ./ |
---|---|
File: | bindings/python/crocoddyl/core/actuation/squashing-base.cpp |
Date: | 2025-01-16 08:47:40 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 32 | 36 | 88.9% |
Branches: | 28 | 56 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2019-2024, University of Edinburgh, IRI: CSIC-UPC, | ||
5 | // Heriot-Watt University | ||
6 | // Copyright note valid unless otherwise stated in individual files. | ||
7 | // All rights reserved. | ||
8 | /////////////////////////////////////////////////////////////////////////////// | ||
9 | |||
10 | #include "python/crocoddyl/core/actuation/squashing-base.hpp" | ||
11 | |||
12 | #include "python/crocoddyl/utils/copyable.hpp" | ||
13 | |||
14 | namespace crocoddyl { | ||
15 | namespace python { | ||
16 | |||
17 | 10 | void exposeSquashingAbstract() { | |
18 | 10 | bp::register_ptr_to_python<boost::shared_ptr<SquashingModelAbstract> >(); | |
19 | |||
20 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<SquashingModelAbstract_wrap, boost::noncopyable>( |
21 | "SquashingModelAbstract", | ||
22 | "Abstract class for squashing functions. \n\n" | ||
23 | "A squashing function is any sigmoid function that maps from R to a " | ||
24 | "bounded domain\n" | ||
25 | "Its input can be any value and its output will be a value between a " | ||
26 | "lower bound and an upper bound.\n" | ||
27 | "The computation of the output value is done using calc() while its " | ||
28 | "derivative is computed using calcDiff(), " | ||
29 | "respectively.", | ||
30 |
1/2✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
|
20 | bp::init<std::size_t>(bp::args("self", "ns"), |
31 | "Initialize the squashing model. \n\n" | ||
32 | ":param ns: dimension of the input vector")) | ||
33 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | .def("calc", pure_virtual(&SquashingModelAbstract_wrap::calc), |
34 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "s"), |
35 | "Compute the squashing value for a given value of u, " | ||
36 | "component-wise. \n\n" | ||
37 | ":param data: squashing data\n" | ||
38 | ":param s: squashing input") | ||
39 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | .def("calcDiff", pure_virtual(&SquashingModelAbstract_wrap::calcDiff), |
40 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "s"), |
41 | "Compute the derivative of the squashing function.\n\n" | ||
42 | "It assumes that calc has been run first.\n" | ||
43 | ":param data: squashing data\n" | ||
44 | ":param u: squashing input") | ||
45 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def("createData", &SquashingModelAbstract_wrap::createData, |
46 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self"), "Create the squashing data.\n\n") |
47 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
48 | "ns", | ||
49 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_function(&SquashingModelAbstract_wrap::get_ns, |
50 | 10 | bp::return_value_policy<bp::return_by_value>()), | |
51 | "dimension of the squashing vector") | ||
52 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
53 | "s_lb", | ||
54 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_function(&SquashingModelAbstract_wrap::get_s_lb, |
55 | ✗ | bp::return_value_policy<bp::return_by_value>()), | |
56 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_function(&SquashingModelAbstract_wrap::set_s_lb), |
57 | "lower bound for the active zone of the squashing function") | ||
58 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property( |
59 | "s_ub", | ||
60 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_function(&SquashingModelAbstract_wrap::get_s_ub, |
61 | ✗ | bp::return_value_policy<bp::return_by_value>()), | |
62 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_function(&SquashingModelAbstract_wrap::set_s_ub), |
63 | "upper bound for the active zone of the squashing function") | ||
64 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<SquashingModelAbstract_wrap>()); |
65 | |||
66 | 10 | bp::register_ptr_to_python<boost::shared_ptr<SquashingDataAbstract> >(); | |
67 | |||
68 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<SquashingDataAbstract>( |
69 | "SquashingDataAbstract", | ||
70 | "Abstract class for squashing datas. \n\n" | ||
71 | "In crocoddyl, an squashing data contains all the required information " | ||
72 | "for processing a \n" | ||
73 | "user-defined squashing model. The squashing data is typically allocated " | ||
74 | "once per running.\n" | ||
75 | "model.createData().", | ||
76 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<SquashingModelAbstract*>( |
77 | 20 | bp::args("self", "model"), | |
78 | "Create common data shared between squashing models. \n\n" | ||
79 | "The squashing data uses the model in order to first process it. \n" | ||
80 | ":param model: squashing model")) | ||
81 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("u", |
82 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&SquashingDataAbstract::u, |
83 | ✗ | bp::return_internal_reference<>()), | |
84 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_setter(&SquashingDataAbstract::u), |
85 | "squashing-output") | ||
86 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("du_ds", |
87 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&SquashingDataAbstract::du_ds, |
88 | ✗ | bp::return_internal_reference<>()), | |
89 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::make_setter(&SquashingDataAbstract::du_ds), |
90 | "Jacobian of the squashing function") | ||
91 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<SquashingDataAbstract>()); |
92 | 10 | } | |
93 | |||
94 | } // namespace python | ||
95 | } // namespace crocoddyl | ||
96 |