Skip to content

Commit ff541c1

Browse files
authored
Merge pull request #1362 from Sergim96/topic/virtual_binding_constraint_dimension
2 parents 2a3d59e + 422095a commit ff541c1

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77
## [Unreleased]
88

9+
* Created Python bindings for (diff)-action getters in https://github.com/loco-3d/crocoddyl/pull/1362
910
* Enabled casting and multi-scalar Python bindings in https://github.com/loco-3d/crocoddyl/pull/1346
1011
* Add install version in https://github.com/loco-3d/crocoddyl/pull/1355
1112
* Removed absolute path for boost library in https://github.com/loco-3d/crocoddyl/pull/1353

bindings/python/crocoddyl/core/action-base.cpp

+25-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "python/crocoddyl/core/action-base.hpp"
1111

12+
#include "python/crocoddyl/utils/deprecate.hpp"
1213
#include "python/crocoddyl/utils/vector-converter.hpp"
1314

1415
namespace crocoddyl {
@@ -95,20 +96,40 @@ struct ActionModelAbstractVisitor
9596
"dimension of cost-residual vector")
9697
.add_property(
9798
"ng", bp::make_function(&Model::get_ng),
98-
bp::make_setter(&Model::ng_, bp::return_internal_reference<>()),
99+
bp::make_setter(
100+
&Model::ng_,
101+
deprecated<bp::return_internal_reference<>>(
102+
"Deprecated. Contraint dimension should not be modified.")),
99103
"number of inequality constraints")
104+
.def("get_ng", &Model::get_ng, &Model::default_get_ng,
105+
"Return the number of inequality constraints.")
100106
.add_property(
101107
"nh", bp::make_function(&Model::get_nh),
102-
bp::make_setter(&Model::nh_, bp::return_internal_reference<>()),
108+
bp::make_setter(
109+
&Model::nh_,
110+
deprecated<bp::return_internal_reference<>>(
111+
"Deprecated. Contraint dimension should not be modified.")),
103112
"number of equality constraints")
113+
.def("get_nh", &Model::get_nh, &Model::default_get_nh,
114+
"Return the number of equality constraints.")
104115
.add_property(
105116
"ng_T", bp::make_function(&Model::get_ng_T),
106-
bp::make_setter(&Model::ng_T_, bp::return_internal_reference<>()),
117+
bp::make_setter(
118+
&Model::ng_T_,
119+
deprecated<bp::return_internal_reference<>>(
120+
"Deprecated. Contraint dimension should not be modified.")),
107121
"number of inequality terminal constraints")
122+
.def("get_ng_T", &Model::get_ng_T, &Model::default_get_ng_T,
123+
"Return the number of inequality terminal constraints.")
108124
.add_property(
109125
"nh_T", bp::make_function(&Model::get_nh_T),
110-
bp::make_setter(&Model::nh_T_, bp::return_internal_reference<>()),
126+
bp::make_setter(
127+
&Model::nh_T_,
128+
deprecated<bp::return_internal_reference<>>(
129+
"Deprecated. Contraint dimension should not be modified.")),
111130
"number of equality terminal constraints")
131+
.def("get_nh_T", &Model::get_nh_T, &Model::default_get_nh_T,
132+
"Return the number of equality terminal constraints.")
112133
.add_property(
113134
"state",
114135
bp::make_function(&Model::get_state,

bindings/python/crocoddyl/core/action-base.hpp

+36
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,42 @@ class ActionModelAbstractTpl_wrap
132132
return this->ActionModel::quasiStatic(data, u, x, maxiter, tol);
133133
}
134134

135+
std::size_t get_ng() const override {
136+
if (boost::python::override get_ng = this->get_override("get_ng")) {
137+
return bp::call<std::size_t>(get_ng.ptr());
138+
}
139+
return this->ActionModel::get_ng();
140+
}
141+
142+
std::size_t default_get_ng() const { return this->ActionModel::get_ng(); }
143+
144+
std::size_t get_nh() const override {
145+
if (boost::python::override get_nh = this->get_override("get_nh")) {
146+
return bp::call<std::size_t>(get_nh.ptr());
147+
}
148+
return this->ActionModel::get_nh();
149+
}
150+
151+
std::size_t default_get_nh() const { return this->ActionModel::get_nh(); }
152+
153+
std::size_t get_ng_T() const override {
154+
if (boost::python::override get_ng_T = this->get_override("get_ng_T")) {
155+
return bp::call<std::size_t>(get_ng_T.ptr());
156+
}
157+
return this->ActionModel::get_ng_T();
158+
}
159+
160+
std::size_t default_get_ng_T() const { return this->ActionModel::get_ng_T(); }
161+
162+
std::size_t get_nh_T() const override {
163+
if (boost::python::override get_nh_T = this->get_override("get_nh_T")) {
164+
return bp::call<std::size_t>(get_nh_T.ptr());
165+
}
166+
return this->ActionModel::get_nh_T();
167+
}
168+
169+
std::size_t default_get_nh_T() const { return this->ActionModel::get_nh_T(); }
170+
135171
template <typename NewScalar>
136172
ActionModelAbstractTpl_wrap<NewScalar> cast() const {
137173
typedef ActionModelAbstractTpl_wrap<NewScalar> ReturnType;

0 commit comments

Comments
 (0)