GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/core/integ-action-base.hpp
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 0 36 0.0%
Branches: 0 104 0.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2021-2025, LAAS-CNRS, University of Edinburgh,
5 // University of Trento, Heriot-Watt University
6 // Copyright note valid unless otherwise stated in individual files. All
7 // rights reserved.
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #ifndef BINDINGS_PYTHON_CROCODDYL_CORE_INTEGRATED_ACTION_BASE_HPP_
11 #define BINDINGS_PYTHON_CROCODDYL_CORE_INTEGRATED_ACTION_BASE_HPP_
12
13 #include "crocoddyl/core/integ-action-base.hpp"
14 #include "python/crocoddyl/core/core.hpp"
15
16 namespace crocoddyl {
17 namespace python {
18
19 template <typename Scalar>
20 class IntegratedActionModelAbstractTpl_wrap
21 : public IntegratedActionModelAbstractTpl<Scalar>,
22 public bp::wrapper<IntegratedActionModelAbstractTpl<Scalar>> {
23 public:
24 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
25 CROCODDYL_DERIVED_CAST(ActionModelBase, IntegratedActionModelAbstractTpl_wrap)
26
27 typedef typename crocoddyl::IntegratedActionModelAbstractTpl<Scalar>
28 IntegratedActionModel;
29 typedef typename crocoddyl::IntegratedActionDataAbstractTpl<Scalar>
30 IntegratedActionData;
31 typedef typename crocoddyl::DifferentialActionModelAbstractTpl<Scalar>
32 DifferentialActionModel;
33 typedef typename crocoddyl::ActionDataAbstractTpl<Scalar> ActionData;
34 typedef typename crocoddyl::StateAbstractTpl<Scalar> State;
35 typedef typename IntegratedActionModel::ControlParametrizationModelAbstract
36 ControlModel;
37 typedef typename IntegratedActionModel::VectorXs VectorXs;
38 using IntegratedActionModel::control_;
39 using IntegratedActionModel::differential_;
40 using IntegratedActionModel::nu_;
41 using IntegratedActionModel::state_;
42 using IntegratedActionModel::time_step_;
43 using IntegratedActionModel::with_cost_residual_;
44
45 IntegratedActionModelAbstractTpl_wrap(
46 std::shared_ptr<DifferentialActionModel> model,
47 const Scalar timestep = Scalar(1e-3),
48 const bool with_cost_residual = true)
49 : IntegratedActionModel(model, timestep, with_cost_residual),
50 bp::wrapper<IntegratedActionModel>() {}
51
52 IntegratedActionModelAbstractTpl_wrap(
53 std::shared_ptr<DifferentialActionModel> model,
54 std::shared_ptr<ControlModel> control,
55 const Scalar timestep = Scalar(1e-3),
56 const bool with_cost_residual = true)
57 : IntegratedActionModel(model, control, timestep, with_cost_residual),
58 bp::wrapper<IntegratedActionModel>() {}
59
60 void calc(const std::shared_ptr<ActionData>& data,
61 const Eigen::Ref<const VectorXs>& x,
62 const Eigen::Ref<const VectorXs>& u) override {
63 if (static_cast<std::size_t>(x.size()) != state_->get_nx()) {
64 throw_pretty(
65 "Invalid argument: " << "x has wrong dimension (it should be " +
66 std::to_string(state_->get_nx()) + ")");
67 }
68 if (static_cast<std::size_t>(u.size()) != nu_) {
69 throw_pretty(
70 "Invalid argument: " << "u has wrong dimension (it should be " +
71 std::to_string(nu_) + ")");
72 }
73 return bp::call<void>(this->get_override("calc").ptr(), data, (VectorXs)x,
74 (VectorXs)u);
75 }
76
77 void calcDiff(const std::shared_ptr<ActionData>& data,
78 const Eigen::Ref<const VectorXs>& x,
79 const Eigen::Ref<const VectorXs>& u) override {
80 if (static_cast<std::size_t>(x.size()) != state_->get_nx()) {
81 throw_pretty(
82 "Invalid argument: " << "x has wrong dimension (it should be " +
83 std::to_string(state_->get_nx()) + ")");
84 }
85 if (static_cast<std::size_t>(u.size()) != nu_) {
86 throw_pretty(
87 "Invalid argument: " << "u has wrong dimension (it should be " +
88 std::to_string(nu_) + ")");
89 }
90 return bp::call<void>(this->get_override("calcDiff").ptr(), data,
91 (VectorXs)x, (VectorXs)u);
92 }
93
94 std::shared_ptr<ActionData> createData() override {
95 enableMultithreading() = false;
96 if (boost::python::override createData = this->get_override("createData")) {
97 return bp::call<std::shared_ptr<IntegratedActionData>>(createData.ptr());
98 }
99 return IntegratedActionModel::createData();
100 }
101
102 std::shared_ptr<ActionData> default_createData() {
103 return this->IntegratedActionModel::createData();
104 }
105
106 template <typename NewScalar>
107 IntegratedActionModelAbstractTpl_wrap<NewScalar> cast() const {
108 typedef IntegratedActionModelAbstractTpl_wrap<NewScalar> ReturnType;
109 if (control_) {
110 ReturnType ret(differential_->template cast<NewScalar>(),
111 control_->template cast<NewScalar>(),
112 scalar_cast<NewScalar>(time_step_), with_cost_residual_);
113 return ret;
114 } else {
115 ReturnType ret(differential_->template cast<NewScalar>(),
116 scalar_cast<NewScalar>(time_step_), with_cost_residual_);
117 return ret;
118 }
119 }
120 };
121
122 } // namespace python
123 } // namespace crocoddyl
124
125 #endif // BINDINGS_PYTHON_CROCODDYL_CORE_INTEGRATED_ACTION_BASE_HPP_
126