Skip to content

Commit 857f549

Browse files
committed
[py] all contractors now return the contracted objects
1 parent 5e6992b commit 857f549

23 files changed

Lines changed: 238 additions & 156 deletions

doc/manual/manual/contractors/analytic/ctcinverse.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,17 @@ Note that since Codac's design is based on C++ template programming, the most ge
297297
| +-------------------------+---------------------------+-------------------------------------+
298298
| | :math:`\mathbb{R}` |ms| | :math:`\mathbb{R}^n` |ms| | :math:`\mathbb{R}^{r\times c}` |ms| |
299299
+--------------------+--------------------------------+-------------------------+---------------------------+-------------------------------------+
300-
| Input(s) :math:`X` | :math:`\mathbb{R}` | |noa| | |noa| | |noa| |
300+
| Input(s) :math:`X` | :math:`\mathbb{R}` | |okk| | |okk| | |noa| |
301301
| +--------------------------------+-------------------------+---------------------------+-------------------------------------+
302302
| | :math:`\mathbb{R}^n` | |okk| | |okk| | |noa| |
303303
| +--------------------------------+-------------------------+---------------------------+-------------------------------------+
304-
| | :math:`\mathbb{R}^{r\times c}` | |noa| | |noa| | |noa| |
304+
| | :math:`\mathbb{R}^{r\times c}` | |okk| | |okk| | |noa| |
305305
| +--------------------------------+-------------------------+---------------------------+-------------------------------------+
306-
| | any mixed types | |noa| | |noa| | |noa| |
306+
| | any mixed types | |okk| | |okk| | |noa| |
307307
+--------------------+--------------------------------+-------------------------+---------------------------+-------------------------------------+
308308

309+
NB: *any mixed types* does not include matrix types yet.
310+
309311
.. group-tab:: C++
310312

311313
.. table:: Possible usages of ``CtcInverse``
@@ -335,15 +337,17 @@ Note that since Codac's design is based on C++ template programming, the most ge
335337
| +-------------------------+---------------------------+-------------------------------------+
336338
| | :math:`\mathbb{R}` |ms| | :math:`\mathbb{R}^n` |ms| | :math:`\mathbb{R}^{r\times c}` |ms| |
337339
+--------------------+--------------------------------+-------------------------+---------------------------+-------------------------------------+
338-
| Input(s) :math:`X` | :math:`\mathbb{R}` | |noa| | |noa| | |noa| |
340+
| Input(s) :math:`X` | :math:`\mathbb{R}` | |okk| | |okk| | |noa| |
339341
| +--------------------------------+-------------------------+---------------------------+-------------------------------------+
340342
| | :math:`\mathbb{R}^n` | |okk| | |okk| | |noa| |
341343
| +--------------------------------+-------------------------+---------------------------+-------------------------------------+
342-
| | :math:`\mathbb{R}^{r\times c}` | |noa| | |noa| | |noa| |
344+
| | :math:`\mathbb{R}^{r\times c}` | |okk| | |okk| | |noa| |
343345
| +--------------------------------+-------------------------+---------------------------+-------------------------------------+
344-
| | any mixed types | |noa| | |noa| | |noa| |
346+
| | any mixed types | |okk| | |okk| | |noa| |
345347
+--------------------+--------------------------------+-------------------------+---------------------------+-------------------------------------+
346348

349+
NB: *any mixed types* does not include matrix types yet.
350+
347351

348352
Not-in constraints: ``CtcInverseNotIn``
349353
---------------------------------------

doc/manual/manual/contractors/analytic/src.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
c = CtcInverseNotIn(f, Interval(0,1));
5353

5454
y = IntervalVector({{0.5,3},{-1,1}});
55-
c.contract(y); % [[1,3],[-1,1]]
55+
y = c.contract(y); % [[1,3],[-1,1]]
5656
% Only the first component is constrained by the not-in condition
5757
% [ctcinv-6-end]
5858

doc/manual/manual/contractors/analytic/src.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def tests_CtcInverse_manual(test):
9292
c = CtcInverseNotIn(f, [0,1])
9393

9494
y = IntervalVector([[0.5,3],[-1,1]])
95-
c.contract(y) # [[1,3],[-1,1]]
95+
y = c.contract(y) # [[1,3],[-1,1]]
9696
# Only the first component is constrained by the not-in condition
9797
# [ctcinv-6-end]
9898

doc/manual/manual/contractors/dynamic/ctclohner.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ This contractor is supposed to yield better results than the Picard contractor,
3131

3232
var = VectorVar(n) # n is the dimension of the system
3333
ctc_lohner = CtcLohner(AnalyticFunction([var], [expr1, expr2, ..., exprn]))
34-
ctc_lohner.contract(x)
34+
x = ctc_lohner.contract(x)
3535

3636
.. code-tab:: c++
3737

@@ -80,8 +80,8 @@ The Lohner contractor is used for obtaining a two-dimensional tube, considering
8080
ctc_lohner = CtcLohner(f)
8181

8282
# Contracting the tubes
83-
ctc_lohner.contract(a)
84-
ctc_lohner.contract(b)
83+
a = ctc_lohner.contract(a)
84+
b = ctc_lohner.contract(b)
8585

8686
# Graphics
8787
fig1 = Figure2D("Lohner_1",GraphicOutput.VIBES|GraphicOutput.IPE)

doc/manual/manual/contractors/set/src.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def tests_CtcInter_manual(test):
2626

2727
# [ctcinter-2-beg]
2828
x = IntervalVector([[-oo,oo],[-oo,oo]])
29-
c3.contract(x)
29+
x = c3.contract(x)
3030
# x = [ [-10, 2] ; [0, 2] ]
3131
# [ctcinter-2-end]
3232

doc/manual/tuto/cp_robotics/src/lesson_C.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@
182182
x = res_ctc_f{1};
183183
v = res_ctc_f{2};
184184

185-
ctc_deriv.contract(x,v);
185+
res_ctc_deriv = ctc_deriv.contract(x,v);
186+
x = res_ctc_deriv{1};
187+
v = res_ctc_deriv{2};
186188

187189
end
188190

doc/manual/tuto/cp_robotics/src/lesson_C.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def ctc_all_obs(x):
171171
x.set(xi,yi[0]) # restriction on the tube x at time ti=yi[0]
172172

173173
x,v = ctc_f.contract(x,v)
174-
ctc_deriv.contract(x,v)
174+
x,v = ctc_deriv.contract(x,v)
175175

176176
return x
177177

doc/manual/tuto/cp_robotics/src/lesson_D.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@
7474

7575

7676
# [D-q7-beg]
77-
ctc_f.contract(x,v)
78-
ctc_deriv.contract(x,v)
77+
x,v = ctc_f.contract(x,v)
78+
x,v = ctc_deriv.contract(x,v)
7979
# [D-q7-end]
8080

8181

@@ -119,8 +119,8 @@
119119

120120
# [D-q13-beg]
121121
def contractors_list(x,v):
122-
ctc_deriv.contract(x,v)
123-
ctc_f.contract(x,v)
122+
x,v = ctc_deriv.contract(x,v)
123+
x,v = ctc_f.contract(x,v)
124124
for yi in Y: # for each range-only measurement
125125
ti = yi[1]
126126
pi = x(ti)

doc/manual/tuto/cp_robotics/src/lesson_E.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def contractors_list(tube_x12):
170170

171171
tube_x12.set(pi, tj)
172172

173-
ctc_deriv.contract(tube_x12, tube_v12)
173+
tube_x12,tube_v12 = ctc_deriv.contract(tube_x12,tube_v12)
174174
return tube_x12
175175

176176
tube_x12 = fixpoint(contractors_list, tube_x12)

python/src/core/contractors/codac2_py_CtcDeriv.cpp

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,48 @@ using namespace codac2;
2121
namespace py = pybind11;
2222
using namespace pybind11::literals;
2323

24+
template<typename T>
25+
void export_contract(py::class_<CtcDeriv>& exported)
26+
{
27+
exported
28+
29+
.def("contract",
30+
[](const CtcDeriv& ctc, Slice<T>& x, const Slice<T>& v, const std::vector<Index_type>& ctc_indices)
31+
-> py::tuple
32+
{
33+
if constexpr(std::is_same_v<T,IntervalVector>)
34+
ctc.contract(x, v, matlab::convert_indices(ctc_indices));
35+
else
36+
ctc.contract(x, v);
37+
38+
return py::make_tuple(
39+
py::cast(x, py::return_value_policy::reference),
40+
py::cast(v, py::return_value_policy::reference)
41+
);
42+
},
43+
VOID_CTCDERIV_CONTRACT_SLICE_T_REF_CONST_SLICE_T_REF_CONST_VECTOR_INDEX_REF_CONST,
44+
"x"_a, "v"_a, "ctc_indices"_a = std::vector<Index>())
45+
46+
.def("contract",
47+
[](const CtcDeriv& ctc, SlicedTube<T>& x, const SlicedTube<T>& v, const std::vector<Index_type>& ctc_indices)
48+
-> py::tuple
49+
{
50+
if constexpr(std::is_same_v<T,IntervalVector>)
51+
ctc.contract(x, v, matlab::convert_indices(ctc_indices));
52+
else
53+
ctc.contract(x, v);
54+
55+
return py::make_tuple(
56+
py::cast(x, py::return_value_policy::reference),
57+
py::cast(v, py::return_value_policy::reference)
58+
);
59+
},
60+
VOID_CTCDERIV_CONTRACT_SLICEDTUBE_T_REF_CONST_SLICEDTUBE_T_REF_CONST_VECTOR_INDEX_REF_CONST,
61+
"x"_a, "v"_a, "ctc_indices"_a = std::vector<Index>())
62+
63+
;
64+
}
65+
2466
void export_CtcDeriv(py::module& m)
2567
{
2668
py::class_<CtcDeriv> exported(m, "CtcDeriv", CTCDERIV_MAIN);
@@ -33,32 +75,8 @@ void export_CtcDeriv(py::module& m)
3375
.def("restrict_tdomain", &CtcDeriv::restrict_tdomain,
3476
VOID_CTCDERIV_RESTRICT_TDOMAIN_CONST_INTERVAL_REF,
3577
"tdomain"_a)
36-
37-
// Contractions on Slice objects
38-
39-
.def("contract", (void (CtcDeriv::*)(Slice<Interval>&,const Slice<Interval>&,const std::vector<Index>&) const)&CtcDeriv::contract,
40-
VOID_CTCDERIV_CONTRACT_SLICE_T_REF_CONST_SLICE_T_REF_CONST_VECTOR_INDEX_REF_CONST,
41-
"x"_a, "v"_a, "ctc_indices"_a=std::vector<Index>())
42-
43-
.def("contract", [](const CtcDeriv& ctc, Slice<IntervalVector>& x, const Slice<IntervalVector>& v, const std::vector<Index_type>& ctc_indices)
44-
{
45-
ctc.contract(x, v, matlab::convert_indices(ctc_indices));
46-
},
47-
VOID_CTCDERIV_CONTRACT_SLICE_T_REF_CONST_SLICE_T_REF_CONST_VECTOR_INDEX_REF_CONST,
48-
"x"_a, "v"_a, "ctc_indices"_a=std::vector<Index>())
49-
50-
// Contractions on SlicedTube objects
51-
52-
.def("contract", (void (CtcDeriv::*)(SlicedTube<Interval>&,const SlicedTube<Interval>&,const std::vector<Index>&) const)&CtcDeriv::contract,
53-
VOID_CTCDERIV_CONTRACT_SLICEDTUBE_T_REF_CONST_SLICEDTUBE_T_REF_CONST_VECTOR_INDEX_REF_CONST,
54-
"x"_a, "v"_a, "ctc_indices"_a=std::vector<Index>())
55-
56-
.def("contract", [](const CtcDeriv& ctc, SlicedTube<IntervalVector>& x, SlicedTube<IntervalVector>& v, const std::vector<Index_type>& ctc_indices)
57-
{
58-
return ctc.contract(x, v, matlab::convert_indices(ctc_indices));
59-
},
60-
VOID_CTCDERIV_CONTRACT_SLICEDTUBE_T_REF_CONST_SLICEDTUBE_T_REF_CONST_VECTOR_INDEX_REF_CONST,
61-
"x"_a, "v"_a, "ctc_indices"_a=std::vector<Index>())
62-
6378
;
79+
80+
export_contract<Interval>(exported);
81+
export_contract<IntervalVector>(exported);
6482
}

0 commit comments

Comments
 (0)