-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ctc] CtcDelay now available in Python
- Loading branch information
1 parent
4536e21
commit 3ab0551
Showing
8 changed files
with
114 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* \file | ||
* CtcDelay Python binding | ||
* ---------------------------------------------------------------------------- | ||
* \date 2020 | ||
* \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 "tubex_py_DynCtc.h" | ||
#include "tubex_CtcDelay.h" | ||
// Generated file from Doxygen XML (doxygen2docstring.py): | ||
#include "tubex_py_CtcDelay_docs.h" | ||
|
||
using namespace std; | ||
using namespace ibex; | ||
using namespace tubex; | ||
namespace py = pybind11; | ||
using namespace pybind11::literals; | ||
|
||
|
||
void export_CtcDelay(py::module& m, py::class_<DynCtc, pyDynCtc>& dyn_ctc) | ||
{ | ||
py::class_<CtcDelay> ctc_eval(m, "CtcDelay", dyn_ctc, CTCDELAY_MAIN); | ||
ctc_eval | ||
|
||
.def(py::init<>(), | ||
CTCDELAY_CTCDELAY) | ||
|
||
.def("contract", (void (CtcDelay::*)(Interval&,Tube&,Tube&))&CtcDelay::contract, | ||
CTCDELAY_VOID_CONTRACT_INTERVAL_TUBE_TUBE, | ||
"a"_a.noconvert(), "x"_a.noconvert(), "y"_a.noconvert()) | ||
|
||
.def("contract", (void (CtcDelay::*)(Interval&,TubeVector&,TubeVector&))&CtcDelay::contract, | ||
CTCDELAY_VOID_CONTRACT_INTERVAL_TUBEVECTOR_TUBEVECTOR, | ||
"a"_a.noconvert(), "x"_a.noconvert(), "y"_a.noconvert()) | ||
; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
class ctc: | ||
|
||
delay = CtcDelay() | ||
deriv = CtcDeriv() | ||
eval = CtcEval() | ||
dist = CtcDist() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python | ||
|
||
import unittest | ||
import math | ||
from pyibex import Interval, IntervalVector | ||
from tubex_lib import * | ||
|
||
class TestCtcDelay(unittest.TestCase): | ||
|
||
def assertApproxIntv(self, first, second): | ||
if first.is_empty() is False: | ||
# if isinstance(second, Interval): | ||
self.assertAlmostEqual(first.lb(), second.lb()) | ||
self.assertAlmostEqual(first.ub(), second.ub()) | ||
else: | ||
self.assertEqual(first, second) | ||
|
||
def test_ctcdelay_1(self): | ||
tdomain = Interval(0.,10.) | ||
x = Tube(tdomain, 0.01, TFunction("cos(t)")) | ||
y = Tube(tdomain, 0.01) | ||
|
||
pi = Interval.PI | ||
ctc_delay = CtcDelay() | ||
ctc_delay.contract(pi, x, y) | ||
|
||
beginDrawing() | ||
fig_x = VIBesFigTube("delay x", x) | ||
fig_x.show() | ||
fig_y = VIBesFigTube("delay y", y) | ||
fig_y.show() | ||
endDrawing() | ||
|
||
self.assertEqual(y(Interval(0.,math.pi)), Interval.ALL_REALS) | ||
self.assertApproxIntv(y(Interval(math.pi+0.01,10.)), Interval(-1.,1.)) | ||
self.assertTrue(y(5.).is_superset(x(5. - math.pi))) | ||
|
||
def test_ctcdelay_2(self): | ||
tdomain = Interval(0.,10.) | ||
dt = 0.01 | ||
x = Tube(tdomain, dt, TFunction("cos(t)")) | ||
y = Tube(tdomain, dt, TFunction("sin(t)")) | ||
|
||
delay = Interval(0.,2.*math.pi) | ||
ctc_delay = CtcDelay() | ||
ctc_delay.contract(delay, x, y) | ||
|
||
beginDrawing() | ||
fig_x = VIBesFigTube("delay x", x) | ||
fig_x.show() | ||
fig_y = VIBesFigTube("delay y", y) | ||
fig_y.show() | ||
endDrawing() | ||
|
||
self.assertTrue(delay.contains(math.pi/2.)) | ||
self.assertTrue(delay.diam() < 3.*dt) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters