GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/core/numdiff/action-double.cpp
Date: 2025-04-18 16:41:15
Exec Total Coverage
Lines: 0 29 0.0%
Branches: 0 78 0.0%

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