Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions doc/manual/manual/contractors/set/ctcinter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Basic usage
-----------

The most common way to create an intersection contractor is to combine two existing
contractors with ``&``.
contractors using ``&`` or the ``CtcInter`` constructor.

.. tabs::

Expand All @@ -23,7 +23,7 @@ contractors with ``&``.
:language: py
:start-after: [ctcinter-1-beg]
:end-before: [ctcinter-1-end]
:dedent: 2
:dedent: 4

.. group-tab:: C++

Expand All @@ -33,7 +33,8 @@ contractors with ``&``.
:end-before: [ctcinter-1-end]
:dedent: 2

Once built, the contractor can be applied as any other box contractor.
| A ``CtcInter`` can also be built from a Python/C++ list of contractor objects.
| Once built, the contractor can be called as any other box contractor.

.. tabs::

Expand All @@ -43,7 +44,7 @@ Once built, the contractor can be applied as any other box contractor.
:language: py
:start-after: [ctcinter-2-beg]
:end-before: [ctcinter-2-end]
:dedent: 2
:dedent: 4

.. group-tab:: C++

Expand Down
6 changes: 4 additions & 2 deletions doc/manual/manual/contractors/set/src.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ TEST_CASE("CtcInter - manual")
CtcWrapper c1(IntervalVector({{-10,10},{-2,2}}));
CtcWrapper c2(IntervalVector({{-12,2},{0,4}}));

auto c3 = c1 & c2;
// c3 is a CtcInter<IntervalVector> gathering the two contractors.
CtcInter c3(c1,c2);
// or...
auto c3bis = c1 & c2;
// c3 and c3bis are a CtcInter<IntervalVector> gathering the two contractors.
// [ctcinter-1-end]

// [ctcinter-2-beg]
Expand Down
2 changes: 2 additions & 0 deletions doc/manual/manual/contractors/set/src.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def tests_CtcInter_manual(test):
c1 = CtcWrapper([[-10,10],[-2,2]])
c2 = CtcWrapper([[-12,2],[0,4]])

c3 = CtcInter(c1,c2)
# or...
c3 = c1 & c2
# c3 is a CtcInter gathering the two contractors.
# [ctcinter-1-end]
Expand Down
2 changes: 1 addition & 1 deletion examples/13_qinter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ def create_sep(b, d):
q = 2
DefaultFigure.pave(
[[-6,6],[-6,6]],
SepQInter(q, s1, s2, s3),
SepQInter(q, s1,s2,s3),
5e-2
)
2 changes: 1 addition & 1 deletion python/codac/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,4 +456,4 @@ def fixpoint(contract, *x):
"draw_while_paving(..) is deprecated,\n "
" please replace by DefaultFigure.pave(..) (or any Figure2D object)"
)
)
)
38 changes: 24 additions & 14 deletions python/src/core/contractors/codac2_py_CtcInter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,33 @@ void export_CtcInter(py::module& m, py::class_<CtcBase<IntervalVector>,pyCtcInte
"n"_a)

.def(py::init(
[](const CtcBase<IntervalVector>& c)
[](py::args args)
{
return std::make_unique<CtcInter<IntervalVector>>(
std::dynamic_pointer_cast<CtcBase<IntervalVector>>(c.copy()));
}),
CTCINTER_X_CTCINTER_CONST_C_REF,
"c"_a)
Collection<CtcBase<IntervalVector>> ctcs;

.def(py::init(
[](const CtcBase<IntervalVector>& c1, const CtcBase<IntervalVector>& c2)
{
return std::make_unique<CtcInter<IntervalVector>>(
std::dynamic_pointer_cast<CtcBase<IntervalVector>>(c1.copy()),
std::dynamic_pointer_cast<CtcBase<IntervalVector>>(c2.copy()));
auto add = [&ctcs](py::handle c)
{
ctcs.push_back(
c.cast<CtcBase<IntervalVector>&>().copy()
);
};

// Backward compatibility: CtcInter([c1,c2,c3])
if(args.size() == 1 && py::isinstance<py::list>(args[0]))
{
for(const auto& c : args[0].cast<py::list>())
add(c);
}
else
{
// New syntax: CtcInter(c1,c2,c3)
for(const auto& c : args)
add(c);
}

return std::make_unique<CtcInter<IntervalVector>>(ctcs);
}),
CTCINTER_X_CTCINTER_CONST_C_REF_VARIADIC,
"c1"_a, "c2"_a)
CTCINTER_X_CTCINTER_INITIALIZER_LIST_C)

.def("nb", &CtcInter<IntervalVector>::nb,
SIZET_CTCINTER_X_NB_CONST)
Expand Down
49 changes: 25 additions & 24 deletions python/src/core/contractors/codac2_py_CtcQInter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,35 @@ void export_CtcQInter(py::module& m, py::class_<CtcBase<IntervalVector>,pyCtcInt
exported

.def(py::init(
[](unsigned int q, const CtcBase<IntervalVector>& c)
[](Index q, py::args args)
{
return std::make_unique<CtcQInter>(q,
std::dynamic_pointer_cast<CtcBase<IntervalVector>>(c.copy()));
}),
CTCQINTER_CTCQINTER_UNSIGNED_INT_CONST_C_REF,
"q"_a, "c"_a)
matlab::test_integer(q);
Collection<CtcBase<IntervalVector>> ctcs;

.def(py::init(
[](unsigned int q, const CtcBase<IntervalVector>& c1, const CtcBase<IntervalVector>& c2)
{
return std::make_unique<CtcQInter>(q,
std::dynamic_pointer_cast<CtcBase<IntervalVector>>(c1.copy()),
std::dynamic_pointer_cast<CtcBase<IntervalVector>>(c2.copy()));
}),
CTCQINTER_CTCQINTER_UNSIGNED_INT_CONST_C_REF_VARIADIC,
"q"_a, "c1"_a, "c2"_a)
auto add = [&ctcs](py::handle c)
{
ctcs.push_back(
c.cast<CtcBase<IntervalVector>&>().copy()
);
};

.def(py::init(
[](unsigned int q, const CtcBase<IntervalVector>& c1, const CtcBase<IntervalVector>& c2, const CtcBase<IntervalVector>& c3)
{
return std::make_unique<CtcQInter>(q,
std::dynamic_pointer_cast<CtcBase<IntervalVector>>(c1.copy()),
std::dynamic_pointer_cast<CtcBase<IntervalVector>>(c2.copy()),
std::dynamic_pointer_cast<CtcBase<IntervalVector>>(c3.copy()));
// Backward compatibility: CtcQInter(q, [c1,c2,c3])
if(args.size() == 1 && py::isinstance<py::list>(args[0]))
{
for(const auto& c : args[0].cast<py::list>())
add(c);
}
else
{
// New syntax: CtcQInter(q, c1,c2,c3)
for(const auto& c : args)
add(c);
}

return std::make_unique<CtcQInter>(q, ctcs);
}),
CTCQINTER_CTCQINTER_UNSIGNED_INT_CONST_C_REF_VARIADIC,
"q"_a, "c1"_a, "c2"_a, "c3"_a)
CTCQINTER_CTCQINTER_UNSIGNED_INT_CONST_C_REF,
"q"_a)

.def("nb", &CtcQInter::nb,
SIZET_CTCQINTER_NB_CONST)
Expand Down
38 changes: 24 additions & 14 deletions python/src/core/contractors/codac2_py_CtcUnion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,33 @@ void export_CtcUnion(py::module& m, py::class_<CtcBase<IntervalVector>,pyCtcInte
"n"_a)

.def(py::init(
[](const CtcBase<IntervalVector>& c)
[](py::args args)
{
return std::make_unique<CtcUnion<IntervalVector>>(
std::dynamic_pointer_cast<CtcBase<IntervalVector>>(c.copy()));
}),
CTCUNION_X_CTCUNION_CONST_C_REF,
"c"_a)
Collection<CtcBase<IntervalVector>> ctcs;

.def(py::init(
[](const CtcBase<IntervalVector>& c1, const CtcBase<IntervalVector>& c2)
{
return std::make_unique<CtcUnion<IntervalVector>>(
std::dynamic_pointer_cast<CtcBase<IntervalVector>>(c1.copy()),
std::dynamic_pointer_cast<CtcBase<IntervalVector>>(c2.copy()));
auto add = [&ctcs](py::handle c)
{
ctcs.push_back(
c.cast<CtcBase<IntervalVector>&>().copy()
);
};

// Backward compatibility: CtcUnion([c1,c2,c3])
if(args.size() == 1 && py::isinstance<py::list>(args[0]))
{
for(const auto& c : args[0].cast<py::list>())
add(c);
}
else
{
// New syntax: CtcUnion(c1,c2,c3)
for(const auto& c : args)
add(c);
}

return std::make_unique<CtcUnion<IntervalVector>>(ctcs);
}),
CTCUNION_X_CTCUNION_CONST_C_REF_VARIADIC,
"c1"_a, "c2"_a)
CTCUNION_X_CTCUNION_INITIALIZER_LIST_C)

.def("nb", &CtcUnion<IntervalVector>::nb,
SIZET_CTCUNION_X_NB_CONST)
Expand Down
44 changes: 23 additions & 21 deletions python/src/core/separators/codac2_py_SepInter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,33 @@ void export_SepInter(py::module& m, py::class_<SepBase,pySep>& pysep)
exported

.def(py::init(
[](const py::list& l)
[](py::args args)
{
Collection<SepBase> l_copy;
for(const auto& li : l)
l_copy.push_back(li.cast<SepBase&>().copy());
return std::make_unique<SepInter>(l_copy);
}),
SEPINTER_SEPINTER_CONST_COLLECTION_T_REF,
"s"_a)
Collection<SepBase> seps;

.def(py::init(
[](const SepBase& s)
{
return std::make_unique<SepInter>(s.copy());
}),
SEPINTER_SEPINTER_CONST_S_REF,
"s"_a)
auto add = [&seps](py::handle s)
{
seps.push_back(
s.cast<SepBase&>().copy()
);
};

.def(py::init(
[](const SepBase& s1, const SepBase& s2)
{
return std::make_unique<SepInter>(s1.copy(),s2.copy());
// Backward compatibility: SepInter([s1,s2,s3])
if(args.size() == 1 && py::isinstance<py::list>(args[0]))
{
for(const auto& s : args[0].cast<py::list>())
add(s);
}
else
{
// New syntax: SepInter(s1,s2,s3)
for(const auto& s : args)
add(s);
}

return std::make_unique<SepInter>(seps);
}),
SEPINTER_SEPINTER_CONST_S_REF_VARIADIC,
"s1"_a, "s2"_a)
SEPINTER_SEPINTER_CONST_COLLECTION_SEPBASE_REF)

.def("nb", &SepInter::nb,
SIZET_SEPINTER_NB_CONST)
Expand Down
43 changes: 25 additions & 18 deletions python/src/core/separators/codac2_py_SepQInter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,35 @@ void export_SepQInter(py::module& m, py::class_<SepBase,pySep>& pysep)
exported

.def(py::init(
[](unsigned int q, const SepBase& s)
[](Index q, py::args args)
{
return std::make_unique<SepQInter>(q,s.copy());
}),
SEPQINTER_SEPQINTER_UNSIGNED_INT_CONST_S_REF,
"q"_a, "s"_a)
matlab::test_integer(q);
Collection<SepBase> seps;

.def(py::init(
[](unsigned int q, const SepBase& s1, const SepBase& s2)
{
return std::make_unique<SepQInter>(q,s1.copy(),s2.copy());
}),
SEPQINTER_SEPQINTER_UNSIGNED_INT_CONST_S_REF_VARIADIC,
"q"_a, "s1"_a, "s2"_a)
auto add = [&seps](py::handle s)
{
seps.push_back(
s.cast<SepBase&>().copy()
);
};

.def(py::init(
[](unsigned int q, const SepBase& s1, const SepBase& s2, const SepBase& s3)
{
return std::make_unique<SepQInter>(q,s1.copy(),s2.copy(),s3.copy());
// Backward compatibility: SepQInter(q, [s1,s2,s3])
if(args.size() == 1 && py::isinstance<py::list>(args[0]))
{
for(const auto& s : args[0].cast<py::list>())
add(s);
}
else
{
// New syntax: SepQInter(q, s1,s2,s3)
for(const auto& s : args)
add(s);
}

return std::make_unique<SepQInter>(q, seps);
}),
SEPQINTER_SEPQINTER_UNSIGNED_INT_CONST_S_REF_VARIADIC,
"q"_a, "s1"_a, "s2"_a, "s3"_a)
SEPQINTER_SEPQINTER_UNSIGNED_INT_CONST_COLLECTION_SEPBASE_REF,
"q"_a)

.def("nb", &SepQInter::nb,
SIZET_SEPQINTER_NB_CONST)
Expand Down
44 changes: 23 additions & 21 deletions python/src/core/separators/codac2_py_SepUnion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,33 @@ void export_SepUnion(py::module& m, py::class_<SepBase,pySep>& pysep)
exported

.def(py::init(
[](const py::list& l)
[](py::args args)
{
Collection<SepBase> l_copy;
for(const auto& li : l)
l_copy.push_back(li.cast<SepBase&>().copy());
return std::make_unique<SepUnion>(l_copy);
}),
SEPUNION_SEPUNION_CONST_COLLECTION_T_REF,
"s"_a)
Collection<SepBase> seps;

.def(py::init(
[](const SepBase& s)
{
return std::make_unique<SepUnion>(s.copy());
}),
SEPUNION_SEPUNION_CONST_S_REF,
"s"_a)
auto add = [&seps](py::handle s)
{
seps.push_back(
s.cast<SepBase&>().copy()
);
};

.def(py::init(
[](const SepBase& s1, const SepBase& s2)
{
return std::make_unique<SepUnion>(s1.copy(),s2.copy());
// Backward compatibility: SepUnion([s1,s2,s3])
if(args.size() == 1 && py::isinstance<py::list>(args[0]))
{
for(const auto& s : args[0].cast<py::list>())
add(s);
}
else
{
// New syntax: SepUnion(s1,s2,s3)
for(const auto& s : args)
add(s);
}

return std::make_unique<SepUnion>(seps);
}),
SEPUNION_SEPUNION_CONST_S_REF_VARIADIC,
"s1"_a, "s2"_a)
SEPUNION_SEPUNION_CONST_COLLECTION_SEPBASE_REF)

.def("nb", &SepUnion::nb,
SIZET_SEPUNION_NB_CONST)
Expand Down
Loading
Loading