codac4matlab 2.0.0.dev14__cp313-cp313-win32.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codac4matlab/__init__.py +4 -0
- codac4matlab/_core.cp313-win32.pyd +0 -0
- codac4matlab/_graphics.cp313-win32.pyd +0 -0
- codac4matlab/_unsupported.cp313-win32.pyd +0 -0
- codac4matlab/core/__init__.py +340 -0
- codac4matlab/graphics/__init__.py +1 -0
- codac4matlab/tests/__init__.py +1 -0
- codac4matlab/tests/test_AnalyticFunction.py +419 -0
- codac4matlab/tests/test_AnalyticTraj.py +63 -0
- codac4matlab/tests/test_Approx.py +27 -0
- codac4matlab/tests/test_BoolInterval.py +40 -0
- codac4matlab/tests/test_Color.py +79 -0
- codac4matlab/tests/test_ConvexPolygon.py +207 -0
- codac4matlab/tests/test_CtcAction.py +30 -0
- codac4matlab/tests/test_CtcCartProd.py +39 -0
- codac4matlab/tests/test_CtcCtcBoundary.py +48 -0
- codac4matlab/tests/test_CtcFixpoint.py +65 -0
- codac4matlab/tests/test_CtcInter.py +39 -0
- codac4matlab/tests/test_CtcInverse.py +157 -0
- codac4matlab/tests/test_CtcInverseNotIn.py +129 -0
- codac4matlab/tests/test_CtcLazy.py +50 -0
- codac4matlab/tests/test_CtcPolygon.py +91 -0
- codac4matlab/tests/test_CtcSegment.py +104 -0
- codac4matlab/tests/test_Ellipsoid.py +20 -0
- codac4matlab/tests/test_IntFullPivLU.py +57 -0
- codac4matlab/tests/test_Interval.py +230 -0
- codac4matlab/tests/test_IntervalMatrix.py +664 -0
- codac4matlab/tests/test_IntervalVector.py +657 -0
- codac4matlab/tests/test_Interval_operations.py +293 -0
- codac4matlab/tests/test_Matrix.py +68 -0
- codac4matlab/tests/test_OctaSym.py +32 -0
- codac4matlab/tests/test_Polygon.py +108 -0
- codac4matlab/tests/test_SampledTraj.py +113 -0
- codac4matlab/tests/test_Segment.py +123 -0
- codac4matlab/tests/test_SepCartProd.py +34 -0
- codac4matlab/tests/test_SepCtcBoundary.py +52 -0
- codac4matlab/tests/test_SepInverse.py +104 -0
- codac4matlab/tests/test_SepPolygon.py +102 -0
- codac4matlab/tests/test_SepProj.py +39 -0
- codac4matlab/tests/test_SepTransform.py +41 -0
- codac4matlab/tests/test_Vector.py +41 -0
- codac4matlab/tests/test_arithmetic_add.py +54 -0
- codac4matlab/tests/test_arithmetic_div.py +46 -0
- codac4matlab/tests/test_arithmetic_mul.py +114 -0
- codac4matlab/tests/test_arithmetic_sub.py +54 -0
- codac4matlab/tests/test_capd.py +19 -0
- codac4matlab/tests/test_cart_prod.py +37 -0
- codac4matlab/tests/test_eigen.py +19 -0
- codac4matlab/tests/test_geometry.py +136 -0
- codac4matlab/tests/test_hull.py +35 -0
- codac4matlab/tests/test_ibex.py +19 -0
- codac4matlab/tests/test_inversion.py +57 -0
- codac4matlab/tests/test_linear_ctc.py +77 -0
- codac4matlab/tests/test_operators.py +348 -0
- codac4matlab/tests/test_transformations.py +61 -0
- codac4matlab/unsupported/__init__.py +1 -0
- codac4matlab/version.py +1 -0
- codac4matlab-2.0.0.dev14.dist-info/METADATA +23 -0
- codac4matlab-2.0.0.dev14.dist-info/RECORD +61 -0
- codac4matlab-2.0.0.dev14.dist-info/WHEEL +5 -0
- codac4matlab-2.0.0.dev14.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Codac tests
|
|
4
|
+
# ----------------------------------------------------------------------------
|
|
5
|
+
# \date 2024
|
|
6
|
+
# \author Simon Rohou
|
|
7
|
+
# \copyright Copyright 2024 Codac Team
|
|
8
|
+
# \license GNU Lesser General Public License (LGPL)
|
|
9
|
+
|
|
10
|
+
import unittest
|
|
11
|
+
from codac import *
|
|
12
|
+
|
|
13
|
+
class TestCtcInverseNotIn(unittest.TestCase):
|
|
14
|
+
|
|
15
|
+
# Multivariable functions not supported (yet) for CtcInverseNotInNotIn: ScalarVar x,y
|
|
16
|
+
# Multivariable functions not supported (yet) for CtcInverseNotInNotIn: AnalyticFunction f { {x,y}, x-y }
|
|
17
|
+
# Multivariable functions not supported (yet) for CtcInverseNotInNotIn: CtcInverseNotInNotIn<Interval> c(f, Interval(0.))
|
|
18
|
+
|
|
19
|
+
def tests_CtcInverseNotIn_2(self):
|
|
20
|
+
|
|
21
|
+
# Test not really relevant, but copied from CtcInverse:
|
|
22
|
+
|
|
23
|
+
x = VectorVar(2)
|
|
24
|
+
f = AnalyticFunction([x], vec(x[0]-x[1]))
|
|
25
|
+
c = CtcInverseNotIn(f, [[0]])
|
|
26
|
+
|
|
27
|
+
#pave(IntervalVector([[-10,10],[-10,10]]), c, 0.1)
|
|
28
|
+
|
|
29
|
+
b = IntervalVector(2)
|
|
30
|
+
|
|
31
|
+
c.contract(b)
|
|
32
|
+
self.assertTrue(b == IntervalVector(2))
|
|
33
|
+
|
|
34
|
+
b = IntervalVector([[1,2],[1,2]])
|
|
35
|
+
c.contract(b)
|
|
36
|
+
self.assertTrue(b == IntervalVector([[1,2],[1,2]]))
|
|
37
|
+
|
|
38
|
+
b = IntervalVector([[1,oo],[1,oo]])
|
|
39
|
+
c.contract(b)
|
|
40
|
+
self.assertTrue(b == IntervalVector([[1,oo],[1,oo]]))
|
|
41
|
+
|
|
42
|
+
b = IntervalVector([[10],[10]])
|
|
43
|
+
c.contract(b)
|
|
44
|
+
self.assertTrue(b == IntervalVector([[10],[10]]))
|
|
45
|
+
|
|
46
|
+
b = IntervalVector([[1,5],[8,9]])
|
|
47
|
+
c.contract(b)
|
|
48
|
+
self.assertTrue(b == IntervalVector([[1,5],[8,9]]))
|
|
49
|
+
|
|
50
|
+
def tests_CtcInverseNotIn_3(self):
|
|
51
|
+
|
|
52
|
+
x = VectorVar(2)
|
|
53
|
+
f = AnalyticFunction([x], vec(x[0],sqr(x[0]/7.)+sqr(x[1]/3.)))
|
|
54
|
+
c = CtcInverseNotIn(f, [[0,oo],[1]])
|
|
55
|
+
|
|
56
|
+
b = IntervalVector([[0,0.8],[-2.28,-1.56]])
|
|
57
|
+
c.contract(b)
|
|
58
|
+
self.assertTrue(b == IntervalVector([[0,0.8],[-2.28,-1.56]]))
|
|
59
|
+
|
|
60
|
+
b = IntervalVector([[4,5.4],[-0.05,2.45]])
|
|
61
|
+
c.contract(b)
|
|
62
|
+
self.assertTrue(Approx(b,1e-2) == IntervalVector([[4,5.4],[-0.05,2.45]]))
|
|
63
|
+
|
|
64
|
+
b = IntervalVector([[6.25,6.7],[0.9,1.85]])
|
|
65
|
+
c.contract(b)
|
|
66
|
+
self.assertTrue(Approx(b,1e-2) == IntervalVector([[6.25,6.70],[0.9,1.85]]))
|
|
67
|
+
|
|
68
|
+
b = IntervalVector([[-6,-5],[0,2]])
|
|
69
|
+
c.contract(b)
|
|
70
|
+
self.assertTrue(b == IntervalVector([[-6,-5],[0,2]]))
|
|
71
|
+
|
|
72
|
+
b = IntervalVector([[2,3],[-1,1]])
|
|
73
|
+
c.contract(b)
|
|
74
|
+
self.assertTrue(b == IntervalVector([[2,3],[-1,1]]))
|
|
75
|
+
|
|
76
|
+
# disabled: def tests_CtcInverseNotIn_3_CtcWrapper(self):
|
|
77
|
+
# disabled:
|
|
78
|
+
# disabled: x = VectorVar(2)
|
|
79
|
+
# disabled: f = AnalyticFunction([x], vec(x[0],sqr(x[0]/7.)+sqr(x[1]/3.)))
|
|
80
|
+
# disabled: c = CtcInverseNotIn(f, CtcWrapper([[0,oo],[1]]))
|
|
81
|
+
# disabled:
|
|
82
|
+
# disabled: b = IntervalVector([[0,0.8],[-2.28,-1.56]])
|
|
83
|
+
# disabled: c.contract(b)
|
|
84
|
+
# disabled: self.assertTrue(b == IntervalVector([[0,0.8],[-2.28,-1.56]]))
|
|
85
|
+
# disabled:
|
|
86
|
+
# disabled: b = IntervalVector([[4,5.4],[-0.05,2.45]])
|
|
87
|
+
# disabled: c.contract(b)
|
|
88
|
+
# disabled: self.assertTrue(Approx(b,1e-2) == IntervalVector([[4,5.4],[-0.05,2.45]]))
|
|
89
|
+
# disabled:
|
|
90
|
+
# disabled: b = IntervalVector([[6.25,6.7],[0.9,1.85]])
|
|
91
|
+
# disabled: c.contract(b)
|
|
92
|
+
# disabled: self.assertTrue(Approx(b,1e-2) == IntervalVector([[6.25,6.70],[0.9,1.85]]))
|
|
93
|
+
# disabled:
|
|
94
|
+
# disabled: b = IntervalVector([[-6,-5],[0,2]])
|
|
95
|
+
# disabled: c.contract(b)
|
|
96
|
+
# disabled: self.assertTrue(b == IntervalVector([[-6,-5],[0,2]]))
|
|
97
|
+
# disabled:
|
|
98
|
+
# disabled: b = IntervalVector([[2,3],[-1,1]])
|
|
99
|
+
# disabled: c.contract(b)
|
|
100
|
+
# disabled: self.assertTrue(b == IntervalVector([[2,3],[-1,1]]))
|
|
101
|
+
|
|
102
|
+
def tests_CtcInverseNotIn_4(self):
|
|
103
|
+
|
|
104
|
+
v = VectorVar(1)
|
|
105
|
+
c = CtcInverseNotIn(AnalyticFunction([v], v), [[-1,1]])
|
|
106
|
+
x = IntervalVector(1)
|
|
107
|
+
|
|
108
|
+
c.contract(x)
|
|
109
|
+
self.assertTrue(x == IntervalVector(1))
|
|
110
|
+
|
|
111
|
+
x = IntervalVector([[0,8]])
|
|
112
|
+
c.contract(x)
|
|
113
|
+
self.assertTrue(x == IntervalVector([[1,8]]))
|
|
114
|
+
|
|
115
|
+
def tests_CtcInverseNotIn_5(self):
|
|
116
|
+
|
|
117
|
+
v = VectorVar(2)
|
|
118
|
+
c = CtcInverseNotIn(AnalyticFunction([v], v), IntervalVector([[-1,1],[5,6]]))
|
|
119
|
+
x = IntervalVector(2)
|
|
120
|
+
|
|
121
|
+
c.contract(x)
|
|
122
|
+
self.assertTrue(x == IntervalVector(2))
|
|
123
|
+
|
|
124
|
+
x = IntervalVector([[0,8],[5.5,oo]])
|
|
125
|
+
c.contract(x)
|
|
126
|
+
self.assertTrue(x == IntervalVector([[0,8],[5.5,oo]])) # unchanged
|
|
127
|
+
|
|
128
|
+
if __name__ == '__main__':
|
|
129
|
+
unittest.main()
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Codac tests
|
|
4
|
+
# ----------------------------------------------------------------------------
|
|
5
|
+
# \date 2024
|
|
6
|
+
# \author Simon Rohou
|
|
7
|
+
# \copyright Copyright 2024 Codac Team
|
|
8
|
+
# \license GNU Lesser General Public License (LGPL)
|
|
9
|
+
|
|
10
|
+
import unittest
|
|
11
|
+
from codac import *
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class CtcCustom(Ctc):
|
|
15
|
+
|
|
16
|
+
def __init__(self):
|
|
17
|
+
Ctc.__init__(self, 2)
|
|
18
|
+
|
|
19
|
+
def contract(self, x):
|
|
20
|
+
if x[0].rad() > 1.:
|
|
21
|
+
return IntervalVector(x.mid()).inflate(0.5*x.rad())
|
|
22
|
+
return x
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class TestCtcLazy(unittest.TestCase):
|
|
26
|
+
|
|
27
|
+
def tests_CtcLazy(self):
|
|
28
|
+
|
|
29
|
+
ctc_custom = CtcCustom()
|
|
30
|
+
x = IntervalVector([[-1000,1000],[-1000,1000]])
|
|
31
|
+
x = ctc_custom.contract(x)
|
|
32
|
+
self.assertTrue(Approx(x) == IntervalVector([[-500,500],[-500,500]]))
|
|
33
|
+
x = ctc_custom.contract(x)
|
|
34
|
+
self.assertTrue(Approx(x) == IntervalVector([[-250,250],[-250,250]]))
|
|
35
|
+
x = ctc_custom.contract(x)
|
|
36
|
+
self.assertTrue(Approx(x) == IntervalVector([[-125,125],[-125,125]]))
|
|
37
|
+
|
|
38
|
+
ctc_lazy = CtcLazy(ctc_custom)
|
|
39
|
+
|
|
40
|
+
x = IntervalVector([[-1000,1000],[-1000,1000]])
|
|
41
|
+
x = ctc_lazy.contract(x)
|
|
42
|
+
self.assertTrue(x == IntervalVector([[-250,250],[-250,250]]))
|
|
43
|
+
|
|
44
|
+
x = IntervalVector([[-500,500],[-500,500]])
|
|
45
|
+
x = ctc_lazy.contract(x)
|
|
46
|
+
self.assertTrue(x == IntervalVector([[-125,125],[-125,125]]))
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
if __name__ == '__main__':
|
|
50
|
+
unittest.main()
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Codac tests
|
|
4
|
+
# ----------------------------------------------------------------------------
|
|
5
|
+
# \date 2024
|
|
6
|
+
# \author Simon Rohou
|
|
7
|
+
# \copyright Copyright 2024 Codac Team
|
|
8
|
+
# \license GNU Lesser General Public License (LGPL)
|
|
9
|
+
|
|
10
|
+
import unittest
|
|
11
|
+
from codac import *
|
|
12
|
+
|
|
13
|
+
class TestCtcPolygon(unittest.TestCase):
|
|
14
|
+
|
|
15
|
+
def tests_CtcPolygon(self):
|
|
16
|
+
|
|
17
|
+
# Polygon, defined as a list of vertices
|
|
18
|
+
c = CtcPolygon([[3,-1],[3,4],[5,6],[-1,1]])
|
|
19
|
+
|
|
20
|
+
x = IntervalVector(2)
|
|
21
|
+
c.contract(x)
|
|
22
|
+
self.assertTrue(x == IntervalVector([[-1,5],[-1,6]]))
|
|
23
|
+
|
|
24
|
+
x = IntervalVector([[3.02,3.16],[2.5,3.2]]) # possible bug
|
|
25
|
+
c.contract(x)
|
|
26
|
+
self.assertTrue(x.is_empty())
|
|
27
|
+
|
|
28
|
+
def tests_CtcPolygon_fromCodac1(self):
|
|
29
|
+
|
|
30
|
+
# Polygone with hole, defined as a list of edges
|
|
31
|
+
|
|
32
|
+
c = CtcPolygon([
|
|
33
|
+
# external border
|
|
34
|
+
[[6,-6], [7,9]],
|
|
35
|
+
[[7,9], [0,5]],
|
|
36
|
+
[[0,5], [-9,8]],
|
|
37
|
+
[[-9,8], [-8,-9]],
|
|
38
|
+
[[-8,-9], [6,-6]],
|
|
39
|
+
# hole
|
|
40
|
+
[[-2,3], [3.5,2]],
|
|
41
|
+
[[3.5,2], [1.5,0.5]],
|
|
42
|
+
[[1.5,0.5], [3,-4]],
|
|
43
|
+
[[3,-4], [-3,-3]],
|
|
44
|
+
[[-3,-3], [-2,3]]
|
|
45
|
+
])
|
|
46
|
+
|
|
47
|
+
#draw_while_paving(IntervalVector([[-10,10],[-10,10]]), c, 0.1)
|
|
48
|
+
|
|
49
|
+
# Check a box inside the hole
|
|
50
|
+
|
|
51
|
+
x = IntervalVector([[0],[0]]).inflate(0.5)
|
|
52
|
+
#DefaultFigure.draw_box(x,Color::purple())
|
|
53
|
+
c.contract(x)
|
|
54
|
+
self.assertTrue(x.is_empty())
|
|
55
|
+
|
|
56
|
+
# Check a box inside the polygon
|
|
57
|
+
|
|
58
|
+
x = IntervalVector([[5],[-5]]).inflate(0.5)
|
|
59
|
+
_x = IntervalVector(x)
|
|
60
|
+
#DefaultFigure.draw_box(x,Color::purple())
|
|
61
|
+
c.contract(x)
|
|
62
|
+
self.assertTrue(x == _x)
|
|
63
|
+
|
|
64
|
+
# Check a box outside the polygon
|
|
65
|
+
|
|
66
|
+
x = IntervalVector([[-1],[8]]).inflate(0.5)
|
|
67
|
+
#DefaultFigure.draw_box(x,Color::purple())
|
|
68
|
+
c.contract(x)
|
|
69
|
+
self.assertTrue(x.is_empty())
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# Other polygon, defined as a list of vertices
|
|
73
|
+
|
|
74
|
+
c = CtcPolygon([[6,-6],[7,9],[0,5],[-9,8],[-8,-9]])
|
|
75
|
+
|
|
76
|
+
# Check a box inside the polygon
|
|
77
|
+
|
|
78
|
+
x = IntervalVector([[5],[-5]]).inflate(0.5)
|
|
79
|
+
_x = IntervalVector(x)
|
|
80
|
+
c.contract(x)
|
|
81
|
+
self.assertTrue(x == _x)
|
|
82
|
+
|
|
83
|
+
# Check a box outside the polygon
|
|
84
|
+
|
|
85
|
+
x = IntervalVector([[-1],[8]]).inflate(0.5)
|
|
86
|
+
c.contract(x)
|
|
87
|
+
self.assertTrue(x.is_empty())
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
if __name__ == '__main__':
|
|
91
|
+
unittest.main()
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Codac tests
|
|
4
|
+
# ----------------------------------------------------------------------------
|
|
5
|
+
# \date 2024
|
|
6
|
+
# \author Simon Rohou
|
|
7
|
+
# \copyright Copyright 2024 Codac Team
|
|
8
|
+
# \license GNU Lesser General Public License (LGPL)
|
|
9
|
+
|
|
10
|
+
import unittest
|
|
11
|
+
from codac import *
|
|
12
|
+
|
|
13
|
+
class TestCtcSegment(unittest.TestCase):
|
|
14
|
+
|
|
15
|
+
def tests_CtcSegment(self):
|
|
16
|
+
|
|
17
|
+
x = IntervalVector(2)
|
|
18
|
+
c = CtcSegment([[3],[-1]],[[3],[4]])
|
|
19
|
+
|
|
20
|
+
x = IntervalVector(2)
|
|
21
|
+
c.contract(x)
|
|
22
|
+
self.assertTrue(x == IntervalVector([[3,3],[-1,4]]))
|
|
23
|
+
|
|
24
|
+
x = IntervalVector([[3.0,3.16],[2.5,3.2]])
|
|
25
|
+
c.contract(x)
|
|
26
|
+
self.assertTrue(x == IntervalVector([[3,3],[2.5,3.2]]))
|
|
27
|
+
|
|
28
|
+
x = IntervalVector([[3.02,3.16],[2.5,3.2]])
|
|
29
|
+
c.contract(x)
|
|
30
|
+
self.assertTrue(x.is_empty())
|
|
31
|
+
|
|
32
|
+
x = IntervalVector(2)
|
|
33
|
+
c = CtcSegment([[-1],[-1]],[[1],[1]])
|
|
34
|
+
|
|
35
|
+
x = IntervalVector(2)
|
|
36
|
+
c.contract(x)
|
|
37
|
+
self.assertTrue(x == IntervalVector([[-1,1],[-1,1]]))
|
|
38
|
+
|
|
39
|
+
x = IntervalVector([[-oo,oo],[0]])
|
|
40
|
+
c.contract(x)
|
|
41
|
+
self.assertTrue(x == IntervalVector([[0],[0]]))
|
|
42
|
+
|
|
43
|
+
x = IntervalVector([[0,oo],[0,oo]])
|
|
44
|
+
c.contract(x)
|
|
45
|
+
self.assertTrue(x == IntervalVector([[0,1],[0,1]]))
|
|
46
|
+
|
|
47
|
+
x = IntervalVector([[2,oo],[2,oo]])
|
|
48
|
+
c.contract(x)
|
|
49
|
+
self.assertTrue(x.is_empty())
|
|
50
|
+
|
|
51
|
+
def tests_CtcSegment_fromCodac1(self):
|
|
52
|
+
|
|
53
|
+
# Test_CtcSegment01
|
|
54
|
+
|
|
55
|
+
c = CtcSegment([[0],[0]], [[10],[20]])
|
|
56
|
+
x = IntervalVector([[-5,50],[-5, 50]])
|
|
57
|
+
c.contract(x)
|
|
58
|
+
self.assertTrue(x == IntervalVector([[0,10],[0,20]]))
|
|
59
|
+
|
|
60
|
+
# Test_CtcSegment02
|
|
61
|
+
|
|
62
|
+
c = CtcSegment([[0],[0]], [[10],[20]])
|
|
63
|
+
x = IntervalVector([[10,50],[20,50]])
|
|
64
|
+
c.contract(x)
|
|
65
|
+
self.assertTrue(x == IntervalVector([[10,10],[20,20]]))
|
|
66
|
+
|
|
67
|
+
# Test_contract_degenerate
|
|
68
|
+
|
|
69
|
+
c = CtcSegment([[5],[5]], [[5],[5]])
|
|
70
|
+
x = IntervalVector([[-5,50],[-5,50]])
|
|
71
|
+
c.contract(x)
|
|
72
|
+
self.assertTrue(x == IntervalVector([[5,5],[5,5]]))
|
|
73
|
+
|
|
74
|
+
# Test_contract_degenerate_x
|
|
75
|
+
|
|
76
|
+
c = CtcSegment([[5],[5]], [[10],[5]])
|
|
77
|
+
x = IntervalVector([[-50,50],[-50,50]])
|
|
78
|
+
c.contract(x)
|
|
79
|
+
self.assertTrue(x == IntervalVector([[5,10],[5,5]]))
|
|
80
|
+
|
|
81
|
+
# Test_contract_degenerate_y
|
|
82
|
+
|
|
83
|
+
c = CtcSegment([[-5],[-5]], [[-5],[15]])
|
|
84
|
+
x = IntervalVector([Interval(-50, 50), Interval(-50, 50)])
|
|
85
|
+
c.contract(x)
|
|
86
|
+
self.assertTrue(x == IntervalVector([[-5,-5],[-5,15]]))
|
|
87
|
+
|
|
88
|
+
# Test_contract_empty
|
|
89
|
+
|
|
90
|
+
c = CtcSegment([[0],[0]], [[10],[20]])
|
|
91
|
+
x = IntervalVector([[-5,-2],[-5,50]])
|
|
92
|
+
c.contract(x)
|
|
93
|
+
self.assertTrue(x.is_empty())
|
|
94
|
+
|
|
95
|
+
# Test_call_with_empty_x
|
|
96
|
+
|
|
97
|
+
c = CtcSegment([[0],[0]], [[10],[20]])
|
|
98
|
+
x = IntervalVector(2)
|
|
99
|
+
c.contract(x)
|
|
100
|
+
self.assertTrue(x == IntervalVector([[0,10],[0,20]]))
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
if __name__ == '__main__':
|
|
104
|
+
unittest.main()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Codac tests
|
|
4
|
+
# ----------------------------------------------------------------------------
|
|
5
|
+
# \date 2024
|
|
6
|
+
# \author Morgan Louedec, (Simon Rohou)
|
|
7
|
+
# \copyright Copyright 2024 Codac Team
|
|
8
|
+
# \license GNU Lesser General Public License (LGPL)
|
|
9
|
+
|
|
10
|
+
import unittest
|
|
11
|
+
from codac import *
|
|
12
|
+
|
|
13
|
+
class TestEllipsoid(unittest.TestCase):
|
|
14
|
+
|
|
15
|
+
def tests_Ellipsoid(self):
|
|
16
|
+
|
|
17
|
+
self.assertTrue(True)
|
|
18
|
+
|
|
19
|
+
if __name__ == '__main__':
|
|
20
|
+
unittest.main()
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Codac tests
|
|
4
|
+
# ----------------------------------------------------------------------------
|
|
5
|
+
# \date 2024
|
|
6
|
+
# \author Damien Massé
|
|
7
|
+
# \copyright Copyright 2024 Codac Team
|
|
8
|
+
# \license GNU Lesser General Public License (LGPL)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
import unittest
|
|
12
|
+
from codac import *
|
|
13
|
+
|
|
14
|
+
class TestIntvFullPivLU(unittest.TestCase):
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# bindings not implemented
|
|
18
|
+
def tests_IntvFullPivLU_1(self):
|
|
19
|
+
M = Matrix([
|
|
20
|
+
[ 1, -4, 3, 7 ],
|
|
21
|
+
[ 2, 1, -4, 6 ],
|
|
22
|
+
[ 5, 2, 1 , 9 ],
|
|
23
|
+
[ -1, 0, 3, 2 ]
|
|
24
|
+
])
|
|
25
|
+
|
|
26
|
+
LUdec = IntvFullPivLU(M)
|
|
27
|
+
self.assertTrue(LUdec.is_injective()==BoolInterval.TRUE)
|
|
28
|
+
self.assertTrue(LUdec.is_surjective()==BoolInterval.TRUE)
|
|
29
|
+
self.assertTrue(LUdec.rank()==Interval(4))
|
|
30
|
+
self.assertTrue((LUdec.determinant()+602).mag()<=1e-10)
|
|
31
|
+
self.assertTrue((LUdec.reconstructed_matrix()-M).norm().ub()<=1e-10)
|
|
32
|
+
I1 = LUdec.solve(IntervalMatrix.eye(4,4));
|
|
33
|
+
self.assertTrue((I1*M-Matrix.eye(4,4)).norm().ub()<1e-10)
|
|
34
|
+
|
|
35
|
+
def tests_IntvFullPivLU_2(self):
|
|
36
|
+
M = Matrix([
|
|
37
|
+
[ 1, -4, 6, 7 ],
|
|
38
|
+
[ 2, 1, 3, 6 ],
|
|
39
|
+
[ 5, 2, 8 , 9 ],
|
|
40
|
+
[ -1, 0, -2, 2 ]
|
|
41
|
+
])
|
|
42
|
+
|
|
43
|
+
LUdec = IntvFullPivLU(M)
|
|
44
|
+
self.assertTrue(LUdec.is_injective()==BoolInterval.UNKNOWN)
|
|
45
|
+
self.assertTrue(LUdec.is_surjective()==BoolInterval.UNKNOWN)
|
|
46
|
+
self.assertTrue(LUdec.rank()==Interval([3,4]))
|
|
47
|
+
self.assertTrue((LUdec.determinant()).mag()<=1e-10)
|
|
48
|
+
self.assertTrue((LUdec.reconstructed_matrix()-M).norm().ub()<=1e-10)
|
|
49
|
+
K = LUdec.kernel()
|
|
50
|
+
self.assertTrue(K.cols()==1)
|
|
51
|
+
self.assertTrue((M*K).norm().ub()<1e-10)
|
|
52
|
+
Im = LUdec.image(M)
|
|
53
|
+
self.assertTrue(Im.cols()==3)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
if __name__ == '__main__':
|
|
57
|
+
unittest.main()
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Codac tests
|
|
4
|
+
#
|
|
5
|
+
# Most of these tests come from the IBEX library (Gilles Chabert)
|
|
6
|
+
# See more: https://ibex-lib.readthedocs.io
|
|
7
|
+
# They have been revised to fit with Codac (v2)
|
|
8
|
+
#
|
|
9
|
+
# ----------------------------------------------------------------------------
|
|
10
|
+
# \date 2024
|
|
11
|
+
# \author Gilles Chabert, (Simon Rohou)
|
|
12
|
+
# \copyright Copyright 2024 Codac Team
|
|
13
|
+
# \license GNU Lesser General Public License (LGPL)
|
|
14
|
+
|
|
15
|
+
import unittest
|
|
16
|
+
from codac import *
|
|
17
|
+
import sys
|
|
18
|
+
import math
|
|
19
|
+
|
|
20
|
+
class TestInterval(unittest.TestCase):
|
|
21
|
+
|
|
22
|
+
def tests_interval(self):
|
|
23
|
+
|
|
24
|
+
self.assertTrue(Interval() == Interval(-oo,oo))
|
|
25
|
+
self.assertTrue(Interval(1.0) == Interval(1.0,1.0))
|
|
26
|
+
self.assertTrue(Interval(-oo) == Interval.empty())
|
|
27
|
+
self.assertTrue(Interval(oo) == Interval.empty())
|
|
28
|
+
self.assertTrue(Interval(1,0) == Interval.empty())
|
|
29
|
+
|
|
30
|
+
self.assertTrue(Interval(-oo,oo) == Interval(-oo,oo))
|
|
31
|
+
self.assertTrue(Interval(-oo,oo) != Interval(0,oo))
|
|
32
|
+
self.assertTrue(Interval(0,1) == Interval(0,1))
|
|
33
|
+
self.assertTrue(Interval(0,2) != Interval(0,1))
|
|
34
|
+
self.assertTrue(Interval(0,2) != Interval(1,3))
|
|
35
|
+
self.assertTrue(Interval(0,oo) == Interval(0,oo))
|
|
36
|
+
self.assertTrue(Interval.empty() == Interval.empty())
|
|
37
|
+
self.assertTrue(Interval(0,0) == Interval(0,0))
|
|
38
|
+
|
|
39
|
+
self.assertTrue(Interval([1.]) == Interval(1.));
|
|
40
|
+
self.assertTrue(Interval([2,3]) == Interval(2,3));
|
|
41
|
+
self.assertTrue(Interval([3,2]) == Interval.empty());
|
|
42
|
+
self.assertTrue(Interval([-oo]) == Interval.empty());
|
|
43
|
+
self.assertTrue(Interval([oo]) == Interval.empty());
|
|
44
|
+
self.assertTrue(Interval([oo,0]) == Interval.empty());
|
|
45
|
+
self.assertTrue(Interval([-oo,oo]) == Interval(-oo,oo));
|
|
46
|
+
self.assertTrue(Interval([oo,-oo]) == Interval.empty());
|
|
47
|
+
|
|
48
|
+
x = Interval() ; y = Interval() ; z = Interval()
|
|
49
|
+
|
|
50
|
+
x = Interval(0,1); x.set_empty()
|
|
51
|
+
self.assertTrue(x == Interval.empty())
|
|
52
|
+
self.assertTrue(x.is_empty())
|
|
53
|
+
|
|
54
|
+
x = Interval(Interval.empty()); x.set_empty()
|
|
55
|
+
self.assertTrue(x == Interval.empty())
|
|
56
|
+
|
|
57
|
+
x = Interval(0,1); y = Interval(2,3); z = Interval(0,3)
|
|
58
|
+
self.assertTrue((x|y) == z); self.assertTrue((y|x) == z)
|
|
59
|
+
x_ = x; x_|=y; self.assertTrue(x_ == z); y_ = y; y_|=x; self.assertTrue(y_ == z)
|
|
60
|
+
|
|
61
|
+
x = Interval(0,1); y = Interval.empty(); z = Interval(0,1)
|
|
62
|
+
self.assertTrue((x|y) == z); self.assertTrue((y|x) == z)
|
|
63
|
+
x_ = x; x_|=y; self.assertTrue(x_ == z); y_ = y; y_|=x; self.assertTrue(y_ == z)
|
|
64
|
+
|
|
65
|
+
x = Interval(-1); y = Interval(0,oo); z = Interval(-1,oo)
|
|
66
|
+
self.assertTrue((x|y) == z); self.assertTrue((y|x) == z)
|
|
67
|
+
x_ = x; x_|=y; self.assertTrue(x_ == z); y_ = y; y_|=x; self.assertTrue(y_ == z)
|
|
68
|
+
|
|
69
|
+
x = Interval(0,1); y = Interval(2,3); z = Interval.empty()
|
|
70
|
+
self.assertTrue((x&y) == z); self.assertTrue((y&x) == z)
|
|
71
|
+
x_ = x; x_&=y; self.assertTrue(x_ == z); y_ = y; y_&=x; self.assertTrue(y_ == z)
|
|
72
|
+
|
|
73
|
+
x = Interval(0,1); y = Interval.empty(); z = Interval.empty()
|
|
74
|
+
self.assertTrue((x&y) == z); self.assertTrue((y&x) == z)
|
|
75
|
+
x_ = x; x_&=y; self.assertTrue(x_ == z); y_ = y; y_&=x; self.assertTrue(y_ == z)
|
|
76
|
+
|
|
77
|
+
x = Interval(0,2); y = Interval(-1,1); z = Interval(0,1)
|
|
78
|
+
self.assertTrue((x&y) == z); self.assertTrue((y&x) == z)
|
|
79
|
+
x_ = x; x_&=y; self.assertTrue(x_ == z); y_ = y; y_&=x; self.assertTrue(y_ == z)
|
|
80
|
+
|
|
81
|
+
x = Interval(0,1); y = Interval(0,oo); z = Interval(0,1)
|
|
82
|
+
self.assertTrue((x&y) == z); self.assertTrue((y&x) == z)
|
|
83
|
+
x_ = x; x_&=y; self.assertTrue(x_ == z); y_ = y; y_&=x; self.assertTrue(y_ == z)
|
|
84
|
+
|
|
85
|
+
x = Interval(0,1); y = Interval(-oo,0); z = Interval(0)
|
|
86
|
+
self.assertTrue((x&y) == z); self.assertTrue((y&x) == z)
|
|
87
|
+
x_ = x; x_&=y; self.assertTrue(x_ == z); y_ = y; y_&=x; self.assertTrue(y_ == z)
|
|
88
|
+
|
|
89
|
+
x = Interval(0,1); y = Interval(1,2); z = Interval(1,1)
|
|
90
|
+
self.assertTrue((x&y) == z); self.assertTrue((y&x) == z)
|
|
91
|
+
x_ = x; x_&=y; self.assertTrue(x_ == z); y_ = y; y_&=x; self.assertTrue(y_ == z)
|
|
92
|
+
|
|
93
|
+
x = Interval(0,2)
|
|
94
|
+
|
|
95
|
+
self.assertTrue(x.lb() == 0)
|
|
96
|
+
self.assertTrue(x.ub() == 2)
|
|
97
|
+
self.assertTrue(x.mid() == 1)
|
|
98
|
+
self.assertTrue(x.rad() == 1)
|
|
99
|
+
self.assertTrue(x.diam() == 2)
|
|
100
|
+
|
|
101
|
+
x = Interval(-3,-1)
|
|
102
|
+
|
|
103
|
+
self.assertTrue(x.lb() == -3)
|
|
104
|
+
self.assertTrue(x.ub() == -1)
|
|
105
|
+
self.assertTrue(x.mid() == -2)
|
|
106
|
+
self.assertTrue(x.rad() == 1)
|
|
107
|
+
self.assertTrue(x.diam() == 2)
|
|
108
|
+
|
|
109
|
+
x = Interval(-3,1)
|
|
110
|
+
|
|
111
|
+
self.assertTrue(x.lb() == -3)
|
|
112
|
+
self.assertTrue(x.ub() == 1)
|
|
113
|
+
self.assertTrue(x.mid() == -1)
|
|
114
|
+
self.assertTrue(x.rad() == 2)
|
|
115
|
+
self.assertTrue(x.diam() == 4)
|
|
116
|
+
|
|
117
|
+
x = Interval(-oo,0)
|
|
118
|
+
|
|
119
|
+
self.assertTrue(x.lb() == -oo)
|
|
120
|
+
self.assertTrue(x.ub() == 0)
|
|
121
|
+
self.assertTrue(x.mid() == -sys.float_info.max)
|
|
122
|
+
self.assertTrue(x.rad() == oo)
|
|
123
|
+
self.assertTrue(x.diam() == oo)
|
|
124
|
+
|
|
125
|
+
x = Interval(-oo,oo)
|
|
126
|
+
|
|
127
|
+
self.assertTrue(x.lb() == -oo)
|
|
128
|
+
self.assertTrue(x.ub() == oo)
|
|
129
|
+
self.assertTrue(x.mid() == 0)
|
|
130
|
+
self.assertTrue(x.rad() == oo)
|
|
131
|
+
self.assertTrue(x.diam() == oo)
|
|
132
|
+
|
|
133
|
+
x = Interval(sys.float_info.max,oo)
|
|
134
|
+
|
|
135
|
+
self.assertTrue(x.lb() == sys.float_info.max)
|
|
136
|
+
self.assertTrue(x.ub() == oo)
|
|
137
|
+
self.assertTrue(x.mid() == sys.float_info.max)
|
|
138
|
+
self.assertTrue(x.rad() == oo)
|
|
139
|
+
self.assertTrue(x.diam() == oo)
|
|
140
|
+
|
|
141
|
+
x = Interval(-1,1)
|
|
142
|
+
for i in range(10):
|
|
143
|
+
self.assertTrue(x.contains(x.rand()))
|
|
144
|
+
x = Interval(-oo,0);
|
|
145
|
+
for i in range(10):
|
|
146
|
+
self.assertTrue(x.contains(x.rand()))
|
|
147
|
+
x = Interval(0,oo);
|
|
148
|
+
for i in range(10):
|
|
149
|
+
self.assertTrue(x.contains(x.rand()))
|
|
150
|
+
x = Interval(-oo,oo);
|
|
151
|
+
for i in range(10):
|
|
152
|
+
self.assertTrue(x.contains(x.rand()))
|
|
153
|
+
x = Interval.empty()
|
|
154
|
+
self.assertTrue(math.isnan(x.rand()))
|
|
155
|
+
|
|
156
|
+
self.assertTrue(Interval(0,1).is_subset(Interval(0,2)))
|
|
157
|
+
self.assertTrue(not Interval(0,1).is_subset(Interval(1,2)))
|
|
158
|
+
self.assertTrue(not Interval(0,1).is_strict_interior_subset(Interval(0,2)))
|
|
159
|
+
self.assertTrue(Interval(-oo,0).is_strict_interior_subset(Interval(-oo,oo)))
|
|
160
|
+
self.assertTrue(Interval.empty().is_strict_interior_subset(Interval(0,1)))
|
|
161
|
+
self.assertTrue(Interval(0,2).is_superset(Interval(0,1)))
|
|
162
|
+
self.assertTrue(not Interval(1,2).is_superset(Interval(0,1)))
|
|
163
|
+
self.assertTrue(not Interval(0,2).is_strict_superset(Interval(0,2)))
|
|
164
|
+
self.assertTrue(Interval(-oo,oo).is_strict_superset(Interval(-oo,0)))
|
|
165
|
+
self.assertTrue(not Interval.empty().is_strict_superset(Interval.empty()))
|
|
166
|
+
self.assertTrue(Interval(0,2).contains(0))
|
|
167
|
+
self.assertTrue(Interval(-oo,oo).contains(oo))
|
|
168
|
+
self.assertTrue(not Interval(0,2).interior_contains(0))
|
|
169
|
+
self.assertTrue(Interval(0,2).interior_contains(1))
|
|
170
|
+
self.assertTrue(not Interval(-oo,0).is_disjoint(Interval(0,oo)))
|
|
171
|
+
self.assertTrue(Interval(0,1).is_disjoint(Interval(2,3)))
|
|
172
|
+
self.assertTrue(Interval(oo).is_empty())
|
|
173
|
+
self.assertTrue(not Interval(0,1).is_empty())
|
|
174
|
+
self.assertTrue(Interval(0).is_degenerated())
|
|
175
|
+
self.assertTrue(Interval.empty().is_degenerated())
|
|
176
|
+
self.assertTrue(not Interval.empty().is_unbounded())
|
|
177
|
+
self.assertTrue(not Interval(0,1).is_unbounded())
|
|
178
|
+
self.assertTrue(Interval(-oo,0).is_unbounded())
|
|
179
|
+
self.assertTrue(Interval(0,oo).is_unbounded())
|
|
180
|
+
self.assertTrue(not Interval.empty().is_bisectable())
|
|
181
|
+
self.assertTrue(not Interval(sys.float_info.max,oo).is_bisectable())
|
|
182
|
+
self.assertTrue(not Interval(-oo,-sys.float_info.max).is_bisectable())
|
|
183
|
+
self.assertTrue(not Interval(0,next_float(0)).is_bisectable())
|
|
184
|
+
self.assertTrue(Interval(0,next_float(next_float(0))).is_bisectable())
|
|
185
|
+
self.assertTrue(Interval(10,next_float(next_float(10))).is_bisectable())
|
|
186
|
+
self.assertTrue(Interval(previous_float(previous_float(0)),0).is_bisectable())
|
|
187
|
+
self.assertTrue(Interval(previous_float(previous_float(10)),10).is_bisectable())
|
|
188
|
+
self.assertTrue(not Interval(10,next_float(10)).is_bisectable())
|
|
189
|
+
self.assertTrue(not Interval(previous_float(0),0).is_bisectable())
|
|
190
|
+
|
|
191
|
+
self.assertTrue(Interval(0,2).mid() == 1.0)
|
|
192
|
+
self.assertTrue(Interval(-oo,oo).mid() == 0)
|
|
193
|
+
self.assertTrue(Interval(0,oo).mid() == sys.float_info.max)
|
|
194
|
+
self.assertTrue(Interval(-oo,0).mid() == -sys.float_info.max)
|
|
195
|
+
d = Interval(sys.float_info.max,oo).mid()
|
|
196
|
+
self.assertTrue((d == sys.float_info.max) or (d == -sys.float_info.max))
|
|
197
|
+
self.assertTrue(Interval(0).mid() == 0.0)
|
|
198
|
+
|
|
199
|
+
x = Interval(2.7629416257693772963,2.7629416257693835135)
|
|
200
|
+
y = x
|
|
201
|
+
m = x.mid()
|
|
202
|
+
x2 = x+m
|
|
203
|
+
x3 = x2-m
|
|
204
|
+
self.assertTrue(x3.is_superset(y))
|
|
205
|
+
|
|
206
|
+
self.assertTrue(Interval(0).diff(Interval(0)) == [])
|
|
207
|
+
self.assertTrue(Interval(0,0).diff(Interval(1,2)) == [Interval(0)])
|
|
208
|
+
self.assertTrue(Interval(0,0).diff(Interval(0,1)) == [])
|
|
209
|
+
self.assertTrue(Interval(0,0).diff(Interval.empty()) == [Interval(0)])
|
|
210
|
+
self.assertTrue(Interval.empty().diff(Interval(0.)) == [])
|
|
211
|
+
self.assertTrue(Interval(0,1).diff(Interval(0,1)) == [])
|
|
212
|
+
self.assertTrue(Interval(0,1).diff(Interval.empty()) == [Interval(0,1)])
|
|
213
|
+
self.assertTrue(Interval(0,1).diff(Interval(1,2)) == [Interval(0,1)])
|
|
214
|
+
self.assertTrue(Interval(0,1).diff(Interval(-1,1)) == [])
|
|
215
|
+
self.assertTrue(Interval(0,1).diff(Interval(0,0)) == [Interval(0,1)])
|
|
216
|
+
self.assertTrue(Interval(0,1).diff(Interval(1,1)) == [Interval(0,1)])
|
|
217
|
+
self.assertTrue(Interval(0,1).diff(Interval(2,3)) == [Interval(0,1)])
|
|
218
|
+
self.assertTrue(Interval(0,3).diff(Interval(1,2)) == [Interval(0,1),Interval(2,3)]) # order may not be respected
|
|
219
|
+
self.assertTrue(Interval(0,2).diff(Interval(1,4)) == [Interval(0,1)])
|
|
220
|
+
self.assertTrue(Interval(0,2).diff(Interval(-1,1)) == [Interval(1,2)])
|
|
221
|
+
self.assertTrue(Interval(0,2).diff(Interval(1,1), False) == [Interval(0,1),Interval(1,2)]) # order may not be respected
|
|
222
|
+
self.assertTrue(Interval(1,1).diff(Interval(0,2), False) == [])
|
|
223
|
+
|
|
224
|
+
a = Interval(3,8)
|
|
225
|
+
b = Interval(1,3) & Interval(6,7) # [b] is empty
|
|
226
|
+
c = a+b
|
|
227
|
+
self.assertTrue(c.is_empty())
|
|
228
|
+
|
|
229
|
+
if __name__ == '__main__':
|
|
230
|
+
unittest.main()
|