GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/core/numdiff/diff-action-double.cpp
Date: 2025-04-18 16:41:15
Exec Total Coverage
Lines: 0 30 0.0%
Branches: 0 82 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/diff-action.hpp"
12
13 #include "python/crocoddyl/core/core.hpp"
14 #include "python/crocoddyl/core/diff-action-base.hpp"
15 #include "python/crocoddyl/utils/copyable.hpp"
16
17 namespace crocoddyl {
18 namespace python {
19
20 template <typename Model>
21 struct DifferentialActionModelNumDiffVisitor
22 : public bp::def_visitor<DifferentialActionModelNumDiffVisitor<Model>> {
23 typedef typename Model::DifferentialActionDataAbstract 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.\n"
57 "It assumes that calc has been run first.\n"
58 ":param data: NumDiff action data\n"
59 ":param x: state point (dim. state.nx)\n"
60 ":param u: control input (dim. nu)")
61 .def("createData", &Model::createData, bp::args("self"),
62 "Create the action data.\n\n"
63 "Each action model (AM) has its own data that needs to be "
64 "allocated.\n"
65 "This function returns the allocated data for a predefined AM.\n"
66 ":return AM data.")
67 .add_property(
68 "model",
69 bp::make_function(&Model::get_model,
70 bp::return_value_policy<bp::return_by_value>()),
71 "action model")
72 .add_property(
73 "disturbance", bp::make_function(&Model::get_disturbance),
74 &Model::set_disturbance,
75 "disturbance constant used in the numerical differentiation")
76 .add_property("withGaussApprox",
77 bp::make_function(&Model::get_with_gauss_approx),
78 "Gauss approximation for computing the Hessians");
79 }
80 };
81
82 template <typename Data>
83 struct DifferentialActionDataNumDiffVisitor
84 : public bp::def_visitor<DifferentialActionDataNumDiffVisitor<Data>> {
85 template <class PyClass>
86 void visit(PyClass& cl) const {
87 cl.add_property(
88 "Rx", bp::make_getter(&Data::Rx, bp::return_internal_reference<>()),
89 "Jacobian of the cost residual.")
90 .add_property(
91 "Ru", bp::make_getter(&Data::Ru, bp::return_internal_reference<>()),
92 "Jacobian of the cost residual.")
93 .add_property(
94 "dx", bp::make_getter(&Data::dx, bp::return_internal_reference<>()),
95 "state disturbance.")
96 .add_property(
97 "du", bp::make_getter(&Data::du, bp::return_internal_reference<>()),
98 "control disturbance.")
99 .add_property(
100 "xp", bp::make_getter(&Data::xp, bp::return_internal_reference<>()),
101 "rate state after disturbance.")
102 .add_property(
103 "data_0",
104 bp::make_getter(&Data::data_0,
105 bp::return_value_policy<bp::return_by_value>()),
106 "data that contains the final results")
107 .add_property(
108 "data_x",
109 bp::make_getter(&Data::data_x,
110 bp::return_value_policy<bp::return_by_value>()),
111 "temporary data associated with the state variation")
112 .add_property(
113 "data_u",
114 bp::make_getter(&Data::data_u,
115 bp::return_value_policy<bp::return_by_value>()),
116 "temporary data associated with the control variation");
117 }
118 };
119
120 #define CROCODDYL_DIFFACTION_MODEL_NUMDIFF_PYTHON_BINDINGS(Scalar) \
121 typedef DifferentialActionModelNumDiffTpl<Scalar> Model; \
122 typedef DifferentialActionModelAbstractTpl<Scalar> ModelBase; \
123 bp::register_ptr_to_python<std::shared_ptr<Model>>(); \
124 bp::class_<Model, bp::bases<ModelBase>>( \
125 "DifferentialActionModelNumDiff", \
126 "Abstract class for computing calcDiff by using numerical " \
127 "differentiation.\n\n", \
128 bp::init<std::shared_ptr<ModelBase>, bp::optional<bool>>( \
129 bp::args("self", "model", "gaussApprox"), \
130 "Initialize the action model NumDiff.\n\n" \
131 ":param model: action model where we compute the derivatives " \
132 "through NumDiff.\n" \
133 ":param gaussApprox: compute the Hessian using Gauss approximation " \
134 "(default False)")) \
135 .def(DifferentialActionModelNumDiffVisitor<Model>()) \
136 .def(CastVisitor<Model>()) \
137 .def(PrintableVisitor<Model>()) \
138 .def(CopyableVisitor<Model>());
139
140 #define CROCODDYL_DIFFACTION_DATA_NUMDIFF_PYTHON_BINDINGS(Scalar) \
141 typedef DifferentialActionDataNumDiffTpl<Scalar> Data; \
142 typedef DifferentialActionDataAbstractTpl<Scalar> DataBase; \
143 typedef DifferentialActionModelNumDiffTpl<Scalar> Model; \
144 bp::register_ptr_to_python<std::shared_ptr<Data>>(); \
145 bp::class_<Data, bp::bases<DataBase>>( \
146 "DifferentialActionDataNumDiff", \
147 "Numerical differentiation diff-action data.", \
148 bp::init<Model*>( \
149 bp::args("self", "model"), \
150 "Create numerical differentiation diff-action data.\n\n" \
151 ":param model: numdiff diff-action model")) \
152 .def(DifferentialActionDataNumDiffVisitor<Data>()) \
153 .def(CopyableVisitor<Data>());
154
155 void exposeDifferentialActionNumDiff() {
156 CROCODDYL_DIFFACTION_MODEL_NUMDIFF_PYTHON_BINDINGS(double)
157 CROCODDYL_DIFFACTION_DATA_NUMDIFF_PYTHON_BINDINGS(double)
158 }
159
160 } // namespace python
161 } // namespace crocoddyl
162