GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: bindings/python/crocoddyl/core/numdiff/activation.cpp Lines: 38 38 100.0 %
Date: 2024-02-13 11:12:33 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
10
  bp::class_<ActivationModelNumDiff, bp::bases<ActivationModelAbstract> >(
22
      "ActivationModelNumDiff",
23
      "Abstract class for computing calcDiff by using numerical "
24
      "differentiation.\n\n",
25
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
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
10
           ":param r: residual vector")
35
      .def("calcDiff", &ActivationModelNumDiff::calcDiff,
36
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
10
           ":param r: residual vector\n")
43
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
10
           ":return AM data.")
49
      .add_property(
50
          "model",
51
10
          bp::make_function(&ActivationModelNumDiff::get_model,
52
10
                            bp::return_value_policy<bp::return_by_value>()),
53
10
          "action model")
54
      .add_property(
55
          "disturbance",
56
20
          bp::make_function(&ActivationModelNumDiff::get_disturbance),
57
10
          "disturbance constant used in the numerical differentiation")
58
10
      .def(CopyableVisitor<ActivationModelNumDiff>());
59
60
10
  bp::register_ptr_to_python<boost::shared_ptr<ActivationDataNumDiff> >();
61
62
10
  bp::class_<ActivationDataNumDiff, bp::bases<ActivationDataAbstract> >(
63
      "ActivationDataNumDiff", "Numerical differentiation activation data.",
64
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
      .add_property("dr",
69
10
                    bp::make_getter(&ActivationDataNumDiff::dr,
70
10
                                    bp::return_internal_reference<>()),
71
10
                    "disturbance.")
72
      .add_property("rp",
73
10
                    bp::make_getter(&ActivationDataNumDiff::rp,
74
10
                                    bp::return_internal_reference<>()),
75
10
                    "input plus the disturbance.")
76
      .add_property(
77
          "data_0",
78
10
          bp::make_getter(&ActivationDataNumDiff::data_0,
79
10
                          bp::return_value_policy<bp::return_by_value>()),
80
10
          "data that contains the final results")
81
      .add_property(
82
          "data_rp",
83
10
          bp::make_getter(&ActivationDataNumDiff::data_rp,
84
10
                          bp::return_value_policy<bp::return_by_value>()),
85
10
          "temporary data associated with the input variation")
86
      .add_property(
87
          "data_r2p",
88
10
          bp::make_getter(&ActivationDataNumDiff::data_r2p,
89
10
                          bp::return_value_policy<bp::return_by_value>()),
90
10
          "temporary data associated with the input variation")
91
10
      .def(CopyableVisitor<ActivationDataNumDiff>());
92
10
}
93
94
}  // namespace python
95
}  // namespace crocoddyl