GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: bindings/python/crocoddyl/core/actuation/squashing-base.cpp Lines: 31 35 88.6 %
Date: 2024-02-13 11:12:33 Branches: 28 56 50.0 %

Line Branch Exec Source
1
///////////////////////////////////////////////////////////////////////////////
2
// BSD 3-Clause License
3
//
4
// Copyright (C) 2019-2023, 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
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
20
      bp::init<int>(bp::args("self", "ns"),
31
                    "Initialize the squashing model. \n\n"
32
                    ":param ns: dimension of the input vector"))
33
      .def("calc", pure_virtual(&SquashingModelAbstract_wrap::calc),
34
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

10
           ":param s: squashing input")
39
      .def("calcDiff", pure_virtual(&SquashingModelAbstract_wrap::calcDiff),
40
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

10
           ":param u: squashing input")
45
      .def("createData", &SquashingModelAbstract_wrap::createData,
46

20
           bp::args("self"), "Create the squashing data.\n\n")
47
      .add_property(
48
          "ns",
49
10
          bp::make_function(&SquashingModelAbstract_wrap::get_ns,
50
10
                            bp::return_value_policy<bp::return_by_value>()),
51
10
          "dimension of the squashing vector")
52
      .add_property(
53
          "s_lb",
54
10
          bp::make_function(&SquashingModelAbstract_wrap::get_s_lb,
55
                            bp::return_value_policy<bp::return_by_value>()),
56
20
          bp::make_function(&SquashingModelAbstract_wrap::set_s_lb),
57
10
          "lower bound for the active zone of the squashing function")
58
      .add_property(
59
          "s_ub",
60
10
          bp::make_function(&SquashingModelAbstract_wrap::get_s_ub,
61
                            bp::return_value_policy<bp::return_by_value>()),
62
20
          bp::make_function(&SquashingModelAbstract_wrap::set_s_ub),
63
10
          "upper bound for the active zone of the squashing function")
64
10
      .def(CopyableVisitor<SquashingModelAbstract_wrap>());
65
66
10
  bp::register_ptr_to_python<boost::shared_ptr<SquashingDataAbstract> >();
67
68
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
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
      .add_property("u",
82
10
                    bp::make_getter(&SquashingDataAbstract::u,
83
                                    bp::return_internal_reference<>()),
84
20
                    bp::make_setter(&SquashingDataAbstract::u),
85
10
                    "squashing-output")
86
      .add_property("du_ds",
87
10
                    bp::make_getter(&SquashingDataAbstract::du_ds,
88
                                    bp::return_internal_reference<>()),
89
20
                    bp::make_setter(&SquashingDataAbstract::du_ds),
90
10
                    "Jacobian of the squashing function")
91
10
      .def(CopyableVisitor<SquashingDataAbstract>());
92
10
}
93
94
}  // namespace python
95
}  // namespace crocoddyl