GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/core/numdiff/diff-action.cpp
Date: 2025-01-16 08:47:40
Exec Total Coverage
Lines: 53 53 100.0%
Branches: 38 76 50.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2023, 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/numdiff/diff-action.hpp"
11
12 #include "python/crocoddyl/core/core.hpp"
13 #include "python/crocoddyl/core/diff-action-base.hpp"
14 #include "python/crocoddyl/utils/copyable.hpp"
15
16 namespace crocoddyl {
17 namespace python {
18
19 10 void exposeDifferentialActionNumDiff() {
20 bp::register_ptr_to_python<
21 10 boost::shared_ptr<DifferentialActionModelNumDiff> >();
22
23
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<DifferentialActionModelNumDiff,
24 bp::bases<DifferentialActionModelAbstract> >(
25 "DifferentialActionModelNumDiff",
26 "Abstract class for computing calcDiff by using numerical "
27 "differentiation.\n\n",
28
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::init<boost::shared_ptr<DifferentialActionModelAbstract>,
29 bp::optional<bool> >(
30 20 bp::args("self", "model", "gaussApprox"),
31 "Initialize the action model NumDiff.\n\n"
32 ":param model: action model where we compute the derivatives through "
33 "NumDiff,\n"
34 ":param gaussApprox: compute the Hessian using Gauss approximation "
35 "(default False)"))
36 .def<void (DifferentialActionModelNumDiff::*)(
37 const boost::shared_ptr<DifferentialActionDataAbstract>&,
38 const Eigen::Ref<const Eigen::VectorXd>&,
39 20 const Eigen::Ref<const Eigen::VectorXd>&)>(
40 "calc", &DifferentialActionModelNumDiff::calc,
41
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x", "u"),
42 "Compute the next state and cost value.\n\n"
43 "The system evolution is described in model.\n"
44 ":param data: NumDiff action data\n"
45 ":param x: state point (dim. state.nx)\n"
46 ":param u: control input (dim. nu)")
47 .def<void (DifferentialActionModelNumDiff::*)(
48 const boost::shared_ptr<DifferentialActionDataAbstract>&,
49
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const Eigen::Ref<const Eigen::VectorXd>&)>(
50 "calc", &DifferentialActionModelAbstract::calc,
51
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x"))
52 .def<void (DifferentialActionModelNumDiff::*)(
53 const boost::shared_ptr<DifferentialActionDataAbstract>&,
54 const Eigen::Ref<const Eigen::VectorXd>&,
55
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const Eigen::Ref<const Eigen::VectorXd>&)>(
56 "calcDiff", &DifferentialActionModelNumDiff::calcDiff,
57
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x", "u"),
58 "Compute the derivatives of the dynamics and cost functions.\n\n"
59 "It computes the Jacobian and Hessian using numerical "
60 "differentiation.\n"
61 "It assumes that calc has been run first.\n"
62 ":param data: NumDiff action data\n"
63 ":param x: state point (dim. state.nx)\n"
64 ":param u: control input (dim. nu)")
65 .def<void (DifferentialActionModelNumDiff::*)(
66 const boost::shared_ptr<DifferentialActionDataAbstract>&,
67
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 const Eigen::Ref<const Eigen::VectorXd>&)>(
68 "calcDiff", &DifferentialActionModelAbstract::calcDiff,
69
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self", "data", "x"))
70
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
20 .def("createData", &DifferentialActionModelNumDiff::createData,
71
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::args("self"),
72 "Create the action data.\n\n"
73 "Each action model (AM) has its own data that needs to be "
74 "allocated.\n"
75 "This function returns the allocated data for a predefined AM.\n"
76 ":return AM data.")
77
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
78 "model",
79
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_function(&DifferentialActionModelNumDiff::get_model,
80 10 bp::return_value_policy<bp::return_by_value>()),
81 "action model")
82
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
83 "disturbance",
84
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_function(&DifferentialActionModelNumDiff::get_disturbance),
85 &DifferentialActionModelNumDiff::set_disturbance,
86 "disturbance constant used in the numerical differentiation")
87
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("withGaussApprox",
88
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
20 bp::make_function(
89 &DifferentialActionModelNumDiff::get_with_gauss_approx),
90 "Gauss approximation for computing the Hessians")
91
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<DifferentialActionModelNumDiff>());
92
93 bp::register_ptr_to_python<
94 10 boost::shared_ptr<DifferentialActionDataNumDiff> >();
95
96
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::class_<DifferentialActionDataNumDiff,
97 bp::bases<DifferentialActionDataAbstract> >(
98 "DifferentialActionDataNumDiff",
99 "Numerical differentiation diff-action data.",
100
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::init<DifferentialActionModelNumDiff*>(
101 20 bp::args("self", "model"),
102 "Create numerical differentiation diff-action data.\n\n"
103 ":param model: numdiff diff-action model"))
104
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("Rx",
105
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataNumDiff::Rx,
106 10 bp::return_internal_reference<>()),
107 "Jacobian of the cost residual.")
108
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("Ru",
109
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataNumDiff::Ru,
110 10 bp::return_internal_reference<>()),
111 "Jacobian of the cost residual.")
112
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("dx",
113
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataNumDiff::dx,
114 10 bp::return_internal_reference<>()),
115 "state disturbance.")
116
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("du",
117
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataNumDiff::du,
118 10 bp::return_internal_reference<>()),
119 "control disturbance.")
120
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property("xp",
121
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataNumDiff::xp,
122 10 bp::return_internal_reference<>()),
123 "rate state after disturbance.")
124
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
125 "data_0",
126
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataNumDiff::data_0,
127 10 bp::return_value_policy<bp::return_by_value>()),
128 "data that contains the final results")
129
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
130 "data_x",
131
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataNumDiff::data_x,
132 10 bp::return_value_policy<bp::return_by_value>()),
133 "temporary data associated with the state variation")
134
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .add_property(
135 "data_u",
136
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 bp::make_getter(&DifferentialActionDataNumDiff::data_u,
137 10 bp::return_value_policy<bp::return_by_value>()),
138 "temporary data associated with the control variation")
139
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 .def(CopyableVisitor<DifferentialActionDataNumDiff>());
140 10 }
141
142 } // namespace python
143 } // namespace crocoddyl
144