Skip to content

Commit

Permalink
[py] added Python binding of CtcStatic
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonRohou committed Sep 29, 2021
1 parent 0680b21 commit 5c64d19
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
src/core/contractors/dyn/codac_py_CtcEval.cpp
src/core/contractors/dyn/codac_py_CtcLohner.cpp
src/core/contractors/dyn/codac_py_CtcPicard.cpp
src/core/contractors/dyn/codac_py_CtcStatic.cpp

src/core/domains/tube/codac_py_Tube.cpp
src/core/domains/tube/codac_py_TubeVector.cpp
Expand Down
28 changes: 28 additions & 0 deletions python/codac/tests/test_ctcstatic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python

import unittest
from pyibex import Interval, IntervalVector
from codac import *

class TestCtcStatic(unittest.TestCase):

def test_ctcstatic_1(self):

dt = 0.1
tdomain = Interval(0.,10.)

ctc_f = CtcFunction(Function("t", "x[2]", "(x[0]-t;x[1]-t)"))
ctc_static = CtcStatic(ctc_f, True)

x = TubeVector(tdomain, dt, 2)

cn = ContractorNetwork()
cn.add(ctc_static, [x])
cn.contract()

expected = Tube(tdomain, dt, TFunction("t"))
self.assertEqual(x[0], expected)
self.assertEqual(x[1], expected)

if __name__ == '__main__':
unittest.main()
2 changes: 2 additions & 0 deletions python/codac_py.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void export_CtcDeriv(py::module& m, py::class_<DynCtc, pyDynCtc>& dyn_ctc);
void export_CtcEval(py::module& m, py::class_<DynCtc, pyDynCtc>& dyn_ctc);
void export_CtcLohner(py::module& m, py::class_<DynCtc, pyDynCtc>& dyn_ctc);
void export_CtcPicard(py::module& m, py::class_<DynCtc, pyDynCtc>& dyn_ctc);
void export_CtcStatic(py::module& m, py::class_<DynCtc, pyDynCtc>& dyn_ctc);

void export_Tube(py::module&m);
void export_TubeVector(py::module& m);
Expand Down Expand Up @@ -83,6 +84,7 @@ PYBIND11_MODULE(tube, m)
export_CtcEval(m, dyn_ctc);
export_CtcLohner(m, dyn_ctc);
export_CtcPicard(m, dyn_ctc);
export_CtcStatic(m, dyn_ctc);

export_Tube(m);
export_TubeVector(m);
Expand Down
47 changes: 47 additions & 0 deletions python/src/core/contractors/dyn/codac_py_CtcStatic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* \file
* CtcStatic Python binding
* ----------------------------------------------------------------------------
* \date 2021
* \author Simon Rohou
* \copyright Copyright 2021 Codac Team
* \license This program is distributed under the terms of
* the GNU Lesser General Public License (LGPL).
*/

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/operators.h>
#include <pybind11/functional.h>
#include "pyIbex_type_caster.h"

#include "codac_py_DynCtc.h"
#include "codac_CtcStatic.h"
// Generated file from Doxygen XML (doxygen2docstring.py):
#include "codac_py_CtcStatic_docs.h"

using namespace std;
using namespace ibex;
using namespace codac;
namespace py = pybind11;
using namespace pybind11::literals;


void export_CtcStatic(py::module& m, py::class_<DynCtc, pyDynCtc>& dyn_ctc)
{
py::class_<CtcStatic> ctc_picard(m, "CtcStatic", dyn_ctc, CTCSTATIC_MAIN);
ctc_picard

.def(py::init<Ctc&,bool>(),
CTCSTATIC_CTCSTATIC_CTC_BOOL,
"ibex_ctc"_a, "temporal_ctc"_a=false)

.def("contract", (void (CtcStatic::*)(Tube&))&CtcStatic::contract,
CTCSTATIC_VOID_CONTRACT_TUBE,
"x"_a.noconvert())

.def("contract", (void (CtcStatic::*)(TubeVector&) )&CtcStatic::contract,
CTCSTATIC_VOID_CONTRACT_TUBEVECTOR,
"x"_a.noconvert())
;
}

0 comments on commit 5c64d19

Please sign in to comment.