codac4matlab 2.0.0.dev20__cp39-cp39-win_amd64.whl → 2.0.0.dev25__cp39-cp39-win_amd64.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/_core.cp39-win_amd64.pyd +0 -0
- codac4matlab/_graphics.cp39-win_amd64.pyd +0 -0
- codac4matlab/_unsupported.cp39-win_amd64.pyd +0 -0
- codac4matlab/core/__init__.py +39 -14
- codac4matlab/tests/test_AnalyticTraj.py +3 -4
- codac4matlab/tests/test_BoolInterval.py +57 -1
- codac4matlab/tests/test_ConvexPolygon.py +111 -18
- codac4matlab/tests/test_CtcCtcBoundary.py +1 -1
- codac4matlab/tests/test_CtcDeriv.py +434 -0
- codac4matlab/tests/test_CtcEval.py +214 -0
- codac4matlab/tests/test_CtcInverse.py +13 -4
- codac4matlab/tests/test_CtcPolygon.py +1 -1
- codac4matlab/tests/test_GaussJordan.py +34 -0
- codac4matlab/tests/test_IntFullPivLU.py +27 -0
- codac4matlab/tests/test_Interval.py +30 -6
- codac4matlab/tests/test_Interval_operations.py +6 -6
- codac4matlab/tests/test_OctaSym.py +9 -0
- codac4matlab/tests/test_Parallelepiped.py +35 -0
- codac4matlab/tests/test_Parallelepiped_eval.py +62 -0
- codac4matlab/tests/test_Polygon.py +14 -2
- codac4matlab/tests/test_SampledTraj.py +14 -1
- codac4matlab/tests/test_Segment.py +17 -2
- codac4matlab/tests/test_SepCtcBoundary.py +1 -1
- codac4matlab/tests/test_SepPolygon.py +1 -1
- codac4matlab/tests/test_SepTransform.py +5 -5
- codac4matlab/tests/test_Slice.py +78 -0
- codac4matlab/tests/test_Slice_polygon.py +208 -0
- codac4matlab/tests/test_SlicedTube.py +263 -5
- codac4matlab/tests/test_cart_prod.py +1 -0
- codac4matlab/tests/test_peibos.py +83 -0
- codac4matlab/tests/test_predefined_tubes.py +6 -6
- codac4matlab/tests/test_trunc.py +95 -0
- {codac4matlab-2.0.0.dev20.dist-info → codac4matlab-2.0.0.dev25.dist-info}/METADATA +1 -1
- {codac4matlab-2.0.0.dev20.dist-info → codac4matlab-2.0.0.dev25.dist-info}/RECORD +36 -27
- {codac4matlab-2.0.0.dev20.dist-info → codac4matlab-2.0.0.dev25.dist-info}/WHEEL +1 -1
- {codac4matlab-2.0.0.dev20.dist-info → codac4matlab-2.0.0.dev25.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,208 @@
|
|
|
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
|
+
import sys
|
|
13
|
+
import math
|
|
14
|
+
|
|
15
|
+
class TestPolygonSlice(unittest.TestCase):
|
|
16
|
+
|
|
17
|
+
def test_polygon_slice_1(self):
|
|
18
|
+
|
|
19
|
+
tdomain = create_tdomain([-1,3])
|
|
20
|
+
x = SlicedTube(tdomain, Interval())
|
|
21
|
+
v = SlicedTube(tdomain, Interval(-1,1))
|
|
22
|
+
|
|
23
|
+
sx = x.first_slice()
|
|
24
|
+
sv = v.first_slice()
|
|
25
|
+
|
|
26
|
+
self.assertTrue(sx.t0_tf() == Interval(-1,3))
|
|
27
|
+
self.assertTrue(sx.codomain() == Interval())
|
|
28
|
+
x.set([-1,2],-1)
|
|
29
|
+
x.set([-2,0],3)
|
|
30
|
+
|
|
31
|
+
ctc_deriv = CtcDeriv(TimePropag.FWD_BWD, False)
|
|
32
|
+
ctc_deriv.contract(sx, sv)
|
|
33
|
+
|
|
34
|
+
p1 = sx.polygon_slice(sv)
|
|
35
|
+
self.assertTrue(p1.box()[0] == Interval(-1.,3.))
|
|
36
|
+
self.assertTrue(p1.box()[1] == Interval(-3.5,3.))
|
|
37
|
+
|
|
38
|
+
p2 = ConvexPolygon([ [-1,-1],[-1,2],[0,3],[3,0],[3,-2],[1.5,-3.5] ])
|
|
39
|
+
self.assertTrue(Approx(p1) == p2)
|
|
40
|
+
|
|
41
|
+
def test_polygon_slice_2(self):
|
|
42
|
+
|
|
43
|
+
tdomain = create_tdomain([-1,3])
|
|
44
|
+
x = SlicedTube(tdomain, Interval(-5,3))
|
|
45
|
+
v = SlicedTube(tdomain, Interval(-1))
|
|
46
|
+
|
|
47
|
+
sx = x.first_slice()
|
|
48
|
+
sv = v.first_slice()
|
|
49
|
+
|
|
50
|
+
x.set([-1,3],-1)
|
|
51
|
+
x.set([-5,0.5],3)
|
|
52
|
+
|
|
53
|
+
ctc_deriv = CtcDeriv(TimePropag.FWD_BWD, False)
|
|
54
|
+
ctc_deriv.contract(sx, sv)
|
|
55
|
+
|
|
56
|
+
p1 = sx.polygon_slice(sv)
|
|
57
|
+
self.assertTrue(p1.box()[0] == Interval(-1.,3.))
|
|
58
|
+
self.assertTrue(p1.box()[1] == Interval(-5,3.))
|
|
59
|
+
|
|
60
|
+
p2 = ConvexPolygon([ [-1,-1],[-1,3],[3,-1],[3,-5],[-1,1] ])
|
|
61
|
+
self.assertTrue(Approx(p1) == p2)
|
|
62
|
+
|
|
63
|
+
def test_polygon_slice_3(self):
|
|
64
|
+
|
|
65
|
+
tdomain = create_tdomain([-1,3])
|
|
66
|
+
x = SlicedTube(tdomain, Interval(-5,3))
|
|
67
|
+
v = SlicedTube(tdomain, Interval(-1,1))
|
|
68
|
+
|
|
69
|
+
sx = x.first_slice()
|
|
70
|
+
sv = v.first_slice()
|
|
71
|
+
|
|
72
|
+
x.set([1,3],-1)
|
|
73
|
+
x.set([-4,-3],3)
|
|
74
|
+
|
|
75
|
+
ctc_deriv = CtcDeriv(TimePropag.FWD_BWD, False)
|
|
76
|
+
ctc_deriv.contract(sx, sv)
|
|
77
|
+
|
|
78
|
+
p1 = sx.polygon_slice(sv)
|
|
79
|
+
self.assertTrue(p1.box()[0] == Interval(-1.,3.))
|
|
80
|
+
self.assertTrue(p1.box()[1] == Interval(-3,1.))
|
|
81
|
+
|
|
82
|
+
#DefaultFigure::draw_polygon(p1)
|
|
83
|
+
|
|
84
|
+
p2 = ConvexPolygon([ [-1,1],[3,-3] ])
|
|
85
|
+
|
|
86
|
+
self.assertTrue(Approx(p1) == p2)
|
|
87
|
+
self.assertTrue(p1.size() == 1)
|
|
88
|
+
|
|
89
|
+
def test_polygon_slice_4(self):
|
|
90
|
+
|
|
91
|
+
tdomain = create_tdomain([0,4])
|
|
92
|
+
x = SlicedTube(tdomain, Interval(-1,7))
|
|
93
|
+
v = SlicedTube(tdomain, Interval(-1.5,4))
|
|
94
|
+
|
|
95
|
+
sx = x.first_slice()
|
|
96
|
+
sv = v.first_slice()
|
|
97
|
+
|
|
98
|
+
x.set([2,3],0)
|
|
99
|
+
x.set([3,4],4)
|
|
100
|
+
|
|
101
|
+
ctc_deriv = CtcDeriv(TimePropag.FWD_BWD, False)
|
|
102
|
+
ctc_deriv.contract(sx, sv)
|
|
103
|
+
|
|
104
|
+
p1 = sx.polygon_slice(sv)
|
|
105
|
+
self.assertTrue(p1.box()[0] == Interval(0,4))
|
|
106
|
+
self.assertTrue(p1.box()[1] == Interval(-1,7))
|
|
107
|
+
|
|
108
|
+
p2 = ConvexPolygon([ [0,2],[0,3],[1,7],[2,7],[4,4],[4,3],[3,-1],[2,-1] ])
|
|
109
|
+
self.assertTrue(Approx(p1) == p2)
|
|
110
|
+
|
|
111
|
+
def test_polygon_slice_4b(self):
|
|
112
|
+
|
|
113
|
+
tdomain = create_tdomain([4,8])
|
|
114
|
+
x = SlicedTube(tdomain, Interval(-1,7))
|
|
115
|
+
v = SlicedTube(tdomain, Interval(-0.75,-0.5))
|
|
116
|
+
|
|
117
|
+
sx = x.first_slice()
|
|
118
|
+
sv = v.first_slice()
|
|
119
|
+
|
|
120
|
+
x.set([3,4],4)
|
|
121
|
+
x.set([1],8)
|
|
122
|
+
|
|
123
|
+
ctc_deriv = CtcDeriv(TimePropag.FWD_BWD, False)
|
|
124
|
+
ctc_deriv.contract(sx, sv)
|
|
125
|
+
|
|
126
|
+
p1 = sx.polygon_slice(sv)
|
|
127
|
+
self.assertTrue(p1.box()[0] == Interval(4,8))
|
|
128
|
+
self.assertTrue(p1.box()[1] == Interval(1,4))
|
|
129
|
+
|
|
130
|
+
#DefaultFigure::draw_polygon(p1)
|
|
131
|
+
|
|
132
|
+
p2 = ConvexPolygon([ [4,3],[4,4],[8,1] ])
|
|
133
|
+
self.assertTrue(Approx(p1,1e-10) == p2)
|
|
134
|
+
|
|
135
|
+
def test_polygon_slice_5(self):
|
|
136
|
+
|
|
137
|
+
tdomain = create_tdomain([8,12])
|
|
138
|
+
x = SlicedTube(tdomain, Interval(-1,7))
|
|
139
|
+
v = SlicedTube(tdomain, Interval(-1./3.,1))
|
|
140
|
+
|
|
141
|
+
sx = x.first_slice()
|
|
142
|
+
sv = v.first_slice()
|
|
143
|
+
|
|
144
|
+
x.set([1],8)
|
|
145
|
+
x.set([1],12)
|
|
146
|
+
|
|
147
|
+
ctc_deriv = CtcDeriv(TimePropag.FWD_BWD, False)
|
|
148
|
+
ctc_deriv.contract(sx, sv)
|
|
149
|
+
|
|
150
|
+
p1 = sx.polygon_slice(sv)
|
|
151
|
+
self.assertTrue(p1.box()[0] == Interval(8,12))
|
|
152
|
+
self.assertTrue(Approx(p1.box()[1]) == Interval(0,2))
|
|
153
|
+
|
|
154
|
+
#DefaultFigure::draw_polygon(p1)
|
|
155
|
+
|
|
156
|
+
p2 = ConvexPolygon([ [8,1],[9,2],[12,1],[11,0] ])
|
|
157
|
+
self.assertTrue(Approx(p1,1e-10) == p2)
|
|
158
|
+
|
|
159
|
+
def test_polygon_slice_6(self):
|
|
160
|
+
|
|
161
|
+
tdomain = create_tdomain([12,14])
|
|
162
|
+
x = SlicedTube(tdomain, Interval(-1,7))
|
|
163
|
+
v = SlicedTube(tdomain, Interval(4.5)/2)
|
|
164
|
+
|
|
165
|
+
sx = x.first_slice()
|
|
166
|
+
sv = v.first_slice()
|
|
167
|
+
|
|
168
|
+
x.set([1],12)
|
|
169
|
+
x.set([5.5],14)
|
|
170
|
+
|
|
171
|
+
ctc_deriv = CtcDeriv(TimePropag.FWD_BWD, False)
|
|
172
|
+
ctc_deriv.contract(sx, sv)
|
|
173
|
+
|
|
174
|
+
p1 = sx.polygon_slice(sv)
|
|
175
|
+
self.assertTrue(p1.box()[0] == Interval(12,14))
|
|
176
|
+
self.assertTrue(Approx(p1.box()[1]) == Interval(1,5.5))
|
|
177
|
+
|
|
178
|
+
#DefaultFigure::draw_polygon(p1)
|
|
179
|
+
|
|
180
|
+
p2 = ConvexPolygon([ [12,1],[14,5.5] ])
|
|
181
|
+
self.assertTrue(Approx(p1,1e-10) == p2)
|
|
182
|
+
|
|
183
|
+
def test_polygon_from_tubint_paper(self):
|
|
184
|
+
|
|
185
|
+
tdomain = create_tdomain([4,5])
|
|
186
|
+
x = SlicedTube(tdomain, (Interval(7)/2)|(Interval(17)/4))
|
|
187
|
+
v = SlicedTube(tdomain, (-Interval(1)/2)|(Interval(1)/2))
|
|
188
|
+
|
|
189
|
+
sx = x.first_slice()
|
|
190
|
+
sv = v.first_slice()
|
|
191
|
+
|
|
192
|
+
x.set((Interval(7)/2)|4,4)
|
|
193
|
+
x.set([4],5)
|
|
194
|
+
|
|
195
|
+
p = sx.polygon_slice(sv);
|
|
196
|
+
self.assertTrue(p == ConvexPolygon([[4,4],[4,3.5],[5,4],[4.5,4.25]]))
|
|
197
|
+
|
|
198
|
+
ctc_deriv = CtcDeriv(TimePropag.FWD_BWD, False)
|
|
199
|
+
ctc_deriv.contract(sx,sv)
|
|
200
|
+
p = sx.polygon_slice(sv);
|
|
201
|
+
self.assertTrue(p == ConvexPolygon([[4,4],[4,3.5],[5,4],[4.5,4.25]]))
|
|
202
|
+
|
|
203
|
+
y = Interval(41)/10
|
|
204
|
+
self.assertTrue(Approx(x.invert(y, v, x.tdomain().t0_tf()),1e-10) == ((Interval(21)/5)|(Interval(24)/5)))
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
if __name__ == '__main__':
|
|
208
|
+
unittest.main()
|
|
@@ -12,9 +12,13 @@ from codac import *
|
|
|
12
12
|
import sys
|
|
13
13
|
import math
|
|
14
14
|
|
|
15
|
+
import os
|
|
16
|
+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '.')))
|
|
17
|
+
import codac2_tests_predefined_tubes as predef
|
|
18
|
+
|
|
15
19
|
def return_a_tube():
|
|
16
20
|
return SlicedTube(
|
|
17
|
-
create_tdomain(Interval(0,2),0.5),
|
|
21
|
+
create_tdomain(Interval(0,2),0.5,False),
|
|
18
22
|
IntervalVector.constant(3,Interval(-1.5,1)))
|
|
19
23
|
|
|
20
24
|
class TestSlicedTube(unittest.TestCase):
|
|
@@ -50,7 +54,7 @@ class TestSlicedTube(unittest.TestCase):
|
|
|
50
54
|
self.assertTrue(tdomain.tslice(0.01) == Interval(0,1))
|
|
51
55
|
self.assertTrue(tdomain.tslice(1) == Interval(1,2))
|
|
52
56
|
self.assertTrue(tdomain.tslice(2) == Interval(2,3))
|
|
53
|
-
self.assertTrue(tdomain.tslice(
|
|
57
|
+
self.assertTrue(tdomain.tslice(prev_float(3.)) == Interval(2,3))
|
|
54
58
|
self.assertTrue(tdomain.tslice(3) == Interval(3,oo))
|
|
55
59
|
self.assertTrue(tdomain.tslice(next_float(3.)) == Interval(3,oo))
|
|
56
60
|
|
|
@@ -184,7 +188,7 @@ class TestSlicedTube(unittest.TestCase):
|
|
|
184
188
|
self.assertTrue(v[3].codomain() == IntervalVector.constant(3,Interval(-10,10)))
|
|
185
189
|
|
|
186
190
|
self.assertTrue(x(-42.) == IntervalVector.constant(3,Interval(2.,3.)))
|
|
187
|
-
self.assertTrue(x(
|
|
191
|
+
self.assertTrue(x(prev_float(-42.)) == IntervalVector(3))
|
|
188
192
|
self.assertTrue(x(next_float(-42.)) == IntervalVector(3))
|
|
189
193
|
|
|
190
194
|
# Eval: affectation at interval t
|
|
@@ -204,12 +208,12 @@ class TestSlicedTube(unittest.TestCase):
|
|
|
204
208
|
self.assertTrue(v[13].codomain() == IntervalVector.constant(3,Interval(9.,10.)))
|
|
205
209
|
|
|
206
210
|
self.assertTrue(x(Interval(44,55)) == IntervalVector.constant(3,Interval(9.,10.)))
|
|
207
|
-
self.assertTrue(x(
|
|
211
|
+
self.assertTrue(x(prev_float(44.)) == IntervalVector(3))
|
|
208
212
|
self.assertTrue(x(next_float(55.)) == IntervalVector(3))
|
|
209
213
|
|
|
210
214
|
def test_sliceT(self):
|
|
211
215
|
|
|
212
|
-
tdomain = create_tdomain(Interval(0,1), 0.1)
|
|
216
|
+
tdomain = create_tdomain(Interval(0,1), 0.1, False)
|
|
213
217
|
x = SlicedTube(tdomain, IntervalVector(2))
|
|
214
218
|
self.assertTrue(x.nb_slices() == 10)
|
|
215
219
|
# C++ like: self.assertTrue(tdomain.tslice(-oo) == tdomain.end())
|
|
@@ -300,5 +304,259 @@ class TestSlicedTube(unittest.TestCase):
|
|
|
300
304
|
self.assertTrue(Approx(tdomain.tslice(2.)) == Interval(1.900000000000001, 2.000000000000002))
|
|
301
305
|
self.assertTrue(Approx(a(Interval(1,2)),1e-4) == Interval(-2.17496, 7.13757))
|
|
302
306
|
|
|
307
|
+
def test_specific_detected_bug_from_sampling(self):
|
|
308
|
+
|
|
309
|
+
tdomain = create_tdomain([0.,46.], 0.5, False)
|
|
310
|
+
x = SlicedTube(tdomain, Interval())
|
|
311
|
+
tdomain.sample(46, False)
|
|
312
|
+
x.set([-1,3], [30,31])
|
|
313
|
+
self.assertTrue(x([30,31]) == Interval(-1,3))
|
|
314
|
+
x.set([-1,3], [45,46])
|
|
315
|
+
self.assertTrue(x([45,46]) == Interval(-1,3))
|
|
316
|
+
self.assertTrue(x([45.5,46]) == Interval(-1,3))
|
|
317
|
+
self.assertTrue(x(45.8) == Interval(-1,3))
|
|
318
|
+
self.assertTrue(x(45.2) == Interval(-1,3))
|
|
319
|
+
|
|
320
|
+
def test_SlicedTube_as_operator_1dcase(self):
|
|
321
|
+
|
|
322
|
+
t = ScalarVar()
|
|
323
|
+
f = AnalyticFunction([t], cos(t))
|
|
324
|
+
analytic_traj = AnalyticTraj(f, [-PI,PI])
|
|
325
|
+
sampled_traj = analytic_traj.sampled(1e-2)
|
|
326
|
+
tdomain = create_tdomain([-PI,PI],1e-2,False)
|
|
327
|
+
tube = SlicedTube(tdomain, sampled_traj)
|
|
328
|
+
g = tube.as_function()
|
|
329
|
+
|
|
330
|
+
h = AnalyticFunction([t], g(t))
|
|
331
|
+
|
|
332
|
+
t_ = -math.pi
|
|
333
|
+
while t_ < math.pi:
|
|
334
|
+
self.assertTrue(Approx(h.real_eval(t_),1e-4) == math.cos(t_))
|
|
335
|
+
t_=t_+1e-2
|
|
336
|
+
|
|
337
|
+
def test_SlicedTube_as_operator_ndcase(self):
|
|
338
|
+
|
|
339
|
+
t = ScalarVar()
|
|
340
|
+
f = AnalyticFunction(
|
|
341
|
+
[t],
|
|
342
|
+
vec(2*cos(t),sin(2*t))
|
|
343
|
+
)
|
|
344
|
+
|
|
345
|
+
analytic_traj = AnalyticTraj(f, [0,5])
|
|
346
|
+
sampled_traj = analytic_traj.sampled(1e-2)
|
|
347
|
+
tdomain = create_tdomain([0,5],1e-3,False)
|
|
348
|
+
tube = SlicedTube(tdomain, sampled_traj)
|
|
349
|
+
g = tube.as_function()
|
|
350
|
+
|
|
351
|
+
h = AnalyticFunction(
|
|
352
|
+
[t],
|
|
353
|
+
g(t)
|
|
354
|
+
)
|
|
355
|
+
|
|
356
|
+
t_ = 0
|
|
357
|
+
while t_ < 5:
|
|
358
|
+
self.assertTrue(Approx(h.eval(t_),1e-2) == IntervalVector([2*math.cos(t_),math.sin(2*t_)]))
|
|
359
|
+
t_=t_+1e-2
|
|
360
|
+
|
|
361
|
+
h = AnalyticFunction(
|
|
362
|
+
[t],
|
|
363
|
+
[ g(t)[0],g(t)[1] ]
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
t_ = 0
|
|
367
|
+
while t_ < 5:
|
|
368
|
+
self.assertTrue(Approx(h.eval(t_),1e-2) == IntervalVector([2*math.cos(t_),math.sin(2*t_)]))
|
|
369
|
+
t_=t_+1e-2
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
def test_inversion_scalar_tube(self):
|
|
373
|
+
|
|
374
|
+
x = predef.tube_test_1()
|
|
375
|
+
x.set_ith_slice(Interval(-4,2), 14) # to test primitives pre-computation
|
|
376
|
+
|
|
377
|
+
self.assertTrue(x.invert([0], x.tdomain().t0_tf()) == Interval(3,46))
|
|
378
|
+
self.assertTrue(x.invert([-7], x.tdomain().t0_tf()) == Interval(4,12))
|
|
379
|
+
self.assertTrue(x.invert(Interval(), x.tdomain().t0_tf()) == Interval(0,46))
|
|
380
|
+
self.assertTrue(x.invert([-12,14], x.tdomain().t0_tf()) == Interval(0,46))
|
|
381
|
+
self.assertTrue(x.invert([-20,-18], x.tdomain().t0_tf()) == Interval.empty())
|
|
382
|
+
self.assertTrue(x.invert([-1,1], x.tdomain().t0_tf()) == Interval(2,46))
|
|
383
|
+
self.assertTrue(x.invert([-10.5], x.tdomain().t0_tf()) == Interval(7,8))
|
|
384
|
+
self.assertTrue(x.invert([-12,-7], x.tdomain().t0_tf()) == Interval(4,12))
|
|
385
|
+
self.assertTrue(x.invert([10,11], x.tdomain().t0_tf()) == Interval(20,27))
|
|
386
|
+
self.assertTrue(x.invert([6.01,7], x.tdomain().t0_tf()) == Interval(0,30))
|
|
387
|
+
self.assertTrue(x.invert([6,7], x.tdomain().t0_tf()) == Interval(0,43))
|
|
388
|
+
self.assertTrue(x.invert([5.9,7], x.tdomain().t0_tf()) == Interval(0,43))
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
def test_inversion_scalar_tube_subsets(self):
|
|
392
|
+
|
|
393
|
+
x = predef.tube_test_1()
|
|
394
|
+
x.set_ith_slice(Interval(-4,2), 14) # to test primitives pre-computation
|
|
395
|
+
|
|
396
|
+
v = []
|
|
397
|
+
|
|
398
|
+
x.invert(Interval(0), v, x.tdomain().t0_tf())
|
|
399
|
+
self.assertTrue(len(v) == 4)
|
|
400
|
+
|
|
401
|
+
if len(v) == 4:
|
|
402
|
+
self.assertTrue(v[0] == Interval(3,4))
|
|
403
|
+
self.assertTrue(v[1] == Interval(14,17))
|
|
404
|
+
self.assertTrue(v[2] == Interval(37,42))
|
|
405
|
+
self.assertTrue(v[3] == Interval(43,46))
|
|
406
|
+
|
|
407
|
+
# The same, with a custom domain:
|
|
408
|
+
x.invert(Interval(0), v, Interval(3.8,42.5))
|
|
409
|
+
self.assertTrue(len(v) == 3)
|
|
410
|
+
|
|
411
|
+
if len(v) == 3:
|
|
412
|
+
self.assertTrue(v[0] == Interval(3.8,4))
|
|
413
|
+
self.assertTrue(v[1] == Interval(14,17))
|
|
414
|
+
self.assertTrue(v[2] == Interval(37,42))
|
|
415
|
+
|
|
416
|
+
x.invert(Interval(-1,1), v, x.tdomain().t0_tf())
|
|
417
|
+
self.assertTrue(len(v) == 4)
|
|
418
|
+
|
|
419
|
+
if len(v) == 4:
|
|
420
|
+
self.assertTrue(v[0] == Interval(2,5))
|
|
421
|
+
self.assertTrue(v[1] == Interval(13,17))
|
|
422
|
+
self.assertTrue(v[2] == Interval(34,35))
|
|
423
|
+
self.assertTrue(v[3] == Interval(36,46))
|
|
424
|
+
|
|
425
|
+
# The same, with a custom domain (empty):
|
|
426
|
+
x.invert(Interval(-1,1), v, Interval.empty())
|
|
427
|
+
self.assertTrue(len(v) == 0)
|
|
428
|
+
|
|
429
|
+
x.invert(Interval(-6.9999), v, x.tdomain().t0_tf())
|
|
430
|
+
self.assertTrue(len(v) == 2)
|
|
431
|
+
|
|
432
|
+
if len(v) == 2:
|
|
433
|
+
self.assertTrue(v[0] == Interval(4,7))
|
|
434
|
+
self.assertTrue(v[1] == Interval(8,12))
|
|
435
|
+
|
|
436
|
+
x.invert(Interval(), v, x.tdomain().t0_tf())
|
|
437
|
+
self.assertTrue(len(v) == 1)
|
|
438
|
+
|
|
439
|
+
if len(v) == 1:
|
|
440
|
+
self.assertTrue(v[0] == Interval(0,46))
|
|
441
|
+
|
|
442
|
+
x.invert(Interval(-30,-29), v, x.tdomain().t0_tf())
|
|
443
|
+
self.assertTrue(len(v) == 0)
|
|
444
|
+
|
|
445
|
+
x.invert(Interval(3.5), v, x.tdomain().t0_tf())
|
|
446
|
+
self.assertTrue(len(v) == 5)
|
|
447
|
+
|
|
448
|
+
if len(v) == 5:
|
|
449
|
+
self.assertTrue(v[0] == Interval(1,4))
|
|
450
|
+
self.assertTrue(v[1] == Interval(15,18))
|
|
451
|
+
self.assertTrue(v[2] == Interval(26,27))
|
|
452
|
+
self.assertTrue(v[3] == Interval(30,38))
|
|
453
|
+
self.assertTrue(v[4] == Interval(40,45))
|
|
454
|
+
|
|
455
|
+
x.invert(Interval(9.5,30), v, x.tdomain().t0_tf())
|
|
456
|
+
self.assertTrue(len(v) == 1)
|
|
457
|
+
|
|
458
|
+
if len(v) == 1:
|
|
459
|
+
self.assertTrue(v[0] == Interval(20,27))
|
|
460
|
+
|
|
461
|
+
x.invert(Interval(12,13), v, x.tdomain().t0_tf())
|
|
462
|
+
self.assertTrue(len(v) == 1)
|
|
463
|
+
|
|
464
|
+
if len(v) == 1:
|
|
465
|
+
self.assertTrue(v[0] == Interval(22,25))
|
|
466
|
+
|
|
467
|
+
x.invert(Interval(-4,-3), v, x.tdomain().t0_tf())
|
|
468
|
+
self.assertTrue(len(v) == 3)
|
|
469
|
+
|
|
470
|
+
if len(v) == 3:
|
|
471
|
+
self.assertTrue(v[0] == Interval(3,5))
|
|
472
|
+
self.assertTrue(v[1] == Interval(9,10))
|
|
473
|
+
self.assertTrue(v[2] == Interval(11,15))
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
def test_inversion_derivative(self):
|
|
477
|
+
|
|
478
|
+
tdomain = create_tdomain([0,5],1.)
|
|
479
|
+
x = SlicedTube(tdomain, Interval())
|
|
480
|
+
v = SlicedTube(tdomain, Interval())
|
|
481
|
+
|
|
482
|
+
x.set([0], 0)
|
|
483
|
+
x.set([4], 5)
|
|
484
|
+
|
|
485
|
+
v.set_ith_slice([1,2], 0*2+1)
|
|
486
|
+
v.set_ith_slice((Interval(1)/2) | (Interval(3)/2), 1*2+1)
|
|
487
|
+
v.set_ith_slice(Interval(0) | (Interval(1)/2), 2*2+1)
|
|
488
|
+
v.set_ith_slice([0], 3*2+1)
|
|
489
|
+
v.set_ith_slice((Interval(-1)/2) | (Interval(1)/2), 4*2+1)
|
|
490
|
+
|
|
491
|
+
ctc = CtcDeriv(TimePropag.FWD_BWD)
|
|
492
|
+
ctc.contract(x, v)
|
|
493
|
+
ctc.contract(x, v)
|
|
494
|
+
ctc.contract(x, v)
|
|
495
|
+
|
|
496
|
+
self.assertTrue(x.invert(x.codomain(), x.tdomain().t0_tf()) == x.tdomain().t0_tf())
|
|
497
|
+
self.assertTrue(x.invert(Interval(), x.tdomain().t0_tf()) == x.tdomain().t0_tf())
|
|
498
|
+
|
|
499
|
+
# Using derivative
|
|
500
|
+
self.assertTrue(x.invert(x.codomain(), v, x.tdomain().t0_tf()) == x.tdomain().t0_tf())
|
|
501
|
+
self.assertTrue(x.invert(Interval(), v, x.tdomain().t0_tf()) == x.tdomain().t0_tf())
|
|
502
|
+
self.assertTrue(x.invert(Interval(0.), v, x.tdomain().t0_tf()) == Interval(0))
|
|
503
|
+
self.assertTrue(Approx(x.slice(tdomain.tslice(4.5)).invert(Interval(4.25), v.slice(tdomain.tslice(4.5)), tdomain.tslice(4.5)),1e-10) == Interval(9)/2)
|
|
504
|
+
self.assertTrue(x.invert(Interval(17)/4, v, x.tdomain().t0_tf()) == Interval(Interval(9)/2))
|
|
505
|
+
self.assertTrue(Approx(x.invert(Interval(4), v, x.tdomain().t0_tf()),1e-10) == Interval(3,5))
|
|
506
|
+
|
|
507
|
+
self.assertTrue(Approx(x.slice(tdomain.tslice(4.5)).invert(Interval(41)/10, v.slice(tdomain.tslice(4.5)), tdomain.tslice(4.5)),1e-10) == ((Interval(21)/5)|(Interval(24)/5)))
|
|
508
|
+
|
|
509
|
+
self.assertTrue(Approx(x.invert(Interval(41)/10, v, x.tdomain().t0_tf()),1e-10) == ((Interval(21)/5)|(Interval(24)/5)))
|
|
510
|
+
self.assertTrue(x.invert((Interval(7)/2), v, x.tdomain().t0_tf()) == Interval(2,4))
|
|
511
|
+
self.assertTrue(x.invert(Interval.empty(), v, x.tdomain().t0_tf()) == Interval.empty())
|
|
512
|
+
self.assertTrue(x.invert(Interval(10), v, x.tdomain().t0_tf()) == Interval.empty())
|
|
513
|
+
self.assertTrue(x.invert(Interval(2,3), v, x.tdomain().t0_tf()) == Interval(1,2))
|
|
514
|
+
self.assertTrue(x.invert(Interval(1), v, x.tdomain().t0_tf()) == Interval(0.5,0.75))
|
|
515
|
+
self.assertTrue(x.invert((Interval(7)/2) | Interval(4), v, x.tdomain().t0_tf()) == Interval(2,5))
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
def test_inversion_another_test(self):
|
|
519
|
+
|
|
520
|
+
tdomain = create_tdomain([-20,20],0.05)
|
|
521
|
+
t = ScalarVar()
|
|
522
|
+
f = AnalyticFunction([t], Interval(-1,1)*((t^2)+1))
|
|
523
|
+
x = SlicedTube(tdomain, f)
|
|
524
|
+
self.assertTrue(x.invert(0., x.tdomain().t0_tf()) == x.tdomain().t0_tf())
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
def test_inversion_vector_tube(self):
|
|
528
|
+
|
|
529
|
+
x0 = predef.tube_test_1()
|
|
530
|
+
x = SlicedTube(x0.tdomain(), IntervalVector(2))
|
|
531
|
+
|
|
532
|
+
for xi, x0i in zip(x, x0):
|
|
533
|
+
xi.set(cart_prod(x0i.codomain(), x0i.codomain() - 3), False)
|
|
534
|
+
|
|
535
|
+
inv_val = IntervalVector.constant(2,[0.5,0.5])
|
|
536
|
+
v_t = []
|
|
537
|
+
x.invert(inv_val, v_t, x.tdomain().t0_tf())
|
|
538
|
+
|
|
539
|
+
self.assertTrue(len(v_t) == 5)
|
|
540
|
+
self.assertTrue(v_t[0] == Interval(3,4))
|
|
541
|
+
self.assertTrue(v_t[1] == Interval(15,17))
|
|
542
|
+
self.assertTrue(v_t[2] == Interval(37,38))
|
|
543
|
+
self.assertTrue(v_t[3] == Interval(40,42))
|
|
544
|
+
self.assertTrue(v_t[4] == Interval(43,45))
|
|
545
|
+
|
|
546
|
+
# Union inversion:
|
|
547
|
+
inv = x.invert(inv_val, x.tdomain().t0_tf())
|
|
548
|
+
self.assertTrue(inv == Interval(3,45))
|
|
549
|
+
|
|
550
|
+
# Restricted domain
|
|
551
|
+
restricted = Interval(15.2,39)
|
|
552
|
+
x.invert(inv_val, v_t, restricted)
|
|
553
|
+
self.assertTrue(len(v_t) == 2)
|
|
554
|
+
self.assertTrue(v_t[0] == Interval(15.2,17))
|
|
555
|
+
self.assertTrue(v_t[1] == Interval(37,38))
|
|
556
|
+
|
|
557
|
+
inv = x.invert(inv_val, restricted)
|
|
558
|
+
self.assertTrue(inv == Interval(15.2,38))
|
|
559
|
+
|
|
560
|
+
|
|
303
561
|
if __name__ == '__main__':
|
|
304
562
|
unittest.main()
|
|
@@ -32,6 +32,7 @@ class TestIntervalVector(unittest.TestCase):
|
|
|
32
32
|
self.assertTrue(cart_prod(IntervalVector.empty(3)) == IntervalVector.empty(3))
|
|
33
33
|
self.assertTrue(cart_prod([[0,1],[2,3],[4,5]],[[8,9]]) == IntervalVector([[0,1],[2,3],[4,5],[8,9]]))
|
|
34
34
|
self.assertTrue(cart_prod(25.,[[0,1],[2,3],[4,5]],[[8,9]],Vector.ones(3)) == IntervalVector([[25],[0,1],[2,3],[4,5],[8,9],[1],[1],[1]]))
|
|
35
|
+
self.assertTrue(cart_prod([-oo,oo],[-oo,oo],42.) == IntervalVector([[-oo,oo],[-oo,oo],[42.,42.]]))
|
|
35
36
|
|
|
36
37
|
if __name__ == '__main__':
|
|
37
38
|
unittest.main()
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Codac tests
|
|
4
|
+
# ----------------------------------------------------------------------------
|
|
5
|
+
# \date 2025
|
|
6
|
+
# \author Maël Godard
|
|
7
|
+
# \copyright Copyright 2024 Codac Team
|
|
8
|
+
# \license GNU Lesser General Public License (LGPL)
|
|
9
|
+
|
|
10
|
+
import unittest
|
|
11
|
+
from codac import *
|
|
12
|
+
import sys
|
|
13
|
+
import math
|
|
14
|
+
|
|
15
|
+
class TestPeibos(unittest.TestCase):
|
|
16
|
+
|
|
17
|
+
def test_peibos(self):
|
|
18
|
+
|
|
19
|
+
# 2D checks of the PEIBOS algorithm
|
|
20
|
+
|
|
21
|
+
y_2d = VectorVar(2)
|
|
22
|
+
f_2d = AnalyticFunction([y_2d],[sqr(y_2d[0])-sqr(y_2d[1])+y_2d[0],2.*y_2d[0]*y_2d[1] + y_2d[1]])
|
|
23
|
+
|
|
24
|
+
X_2d = VectorVar(1)
|
|
25
|
+
psi0_2d = AnalyticFunction([X_2d],[cos(X_2d[0]*PI/4.),sin(X_2d[0]*PI/4.)])
|
|
26
|
+
|
|
27
|
+
id_2d = OctaSym([1, 2])
|
|
28
|
+
s = OctaSym([-2, 1])
|
|
29
|
+
|
|
30
|
+
v_par_2d = PEIBOS(f_2d,psi0_2d,[id_2d,s,s*s,s.invert()],0.25,[-0.2,0.])
|
|
31
|
+
|
|
32
|
+
b0 = Vector([-0.5,0.0])
|
|
33
|
+
b1 = Vector([0.0,1.45])
|
|
34
|
+
b2 = Vector([-1.165,0.0])
|
|
35
|
+
|
|
36
|
+
count_b0, count_b1, count_b2 = 0, 0, 0
|
|
37
|
+
|
|
38
|
+
for p in v_par_2d:
|
|
39
|
+
if (p.contains(b0))==BoolInterval.TRUE:
|
|
40
|
+
count_b0 += 1
|
|
41
|
+
if (p.contains(b1))==BoolInterval.TRUE:
|
|
42
|
+
count_b1 += 1
|
|
43
|
+
if (p.contains(b2))==BoolInterval.TRUE:
|
|
44
|
+
count_b2 += 1
|
|
45
|
+
|
|
46
|
+
self.assertTrue(count_b0 == 0)
|
|
47
|
+
self.assertTrue(count_b1 == 1)
|
|
48
|
+
self.assertTrue(count_b2 == 2)
|
|
49
|
+
|
|
50
|
+
# 3D checks of the PEIBOS algorithm
|
|
51
|
+
|
|
52
|
+
y_3d = VectorVar(3)
|
|
53
|
+
f_3d = AnalyticFunction([y_3d],[y_3d[0],y_3d[1],y_3d[2]])
|
|
54
|
+
|
|
55
|
+
X_3d = VectorVar(2)
|
|
56
|
+
psi0_3d = AnalyticFunction([X_3d],[1/sqrt(1+sqr(X_3d[0])+sqr(X_3d[1])),X_3d[0]/sqrt(1+sqr(X_3d[0])+sqr(X_3d[1])),X_3d[1]/sqrt(1+sqr(X_3d[0])+sqr(X_3d[1]))])
|
|
57
|
+
|
|
58
|
+
id_3d = OctaSym([1, 2, 3])
|
|
59
|
+
s1 = OctaSym([-2, 1, 3])
|
|
60
|
+
s2 = OctaSym([3, 2, -1])
|
|
61
|
+
|
|
62
|
+
v_par_3d = PEIBOS(f_3d,psi0_3d,[id_3d,s1,s1*s1,s1.invert(),s2,s2.invert()],2.0)
|
|
63
|
+
|
|
64
|
+
self.assertTrue(len(v_par_3d) == 6)
|
|
65
|
+
|
|
66
|
+
self.assertTrue(Approx(v_par_3d[0].z,1e-6) == Vector([1.,0.,0.]))
|
|
67
|
+
self.assertTrue(Approx(v_par_3d[1].z,1e-6) == Vector([0.,1.,0.]))
|
|
68
|
+
self.assertTrue(Approx(v_par_3d[2].z,1e-6) == Vector([-1,0.,0.]))
|
|
69
|
+
self.assertTrue(Approx(v_par_3d[3].z,1e-6) == Vector([0.,-1.,0.]))
|
|
70
|
+
self.assertTrue(Approx(v_par_3d[4].z,1e-6) == Vector([0.,0.,-1.]))
|
|
71
|
+
self.assertTrue(Approx(v_par_3d[5].z,1e-6) == Vector([0.,0.,1.]))
|
|
72
|
+
|
|
73
|
+
a = 4.35066
|
|
74
|
+
|
|
75
|
+
self.assertTrue(Approx(v_par_3d[0].A,1e-5) == Matrix([[0.,0.,a],[a+1,0.,0.],[0.,a+1,0.]]))
|
|
76
|
+
self.assertTrue(Approx(v_par_3d[1].A,1e-5) == Matrix([[-(a+1),0.,0.],[0.,0.,a],[0.,a+1,0.]]))
|
|
77
|
+
self.assertTrue(Approx(v_par_3d[2].A,1e-5) == Matrix([[0.,0.,a],[-(a+1),0.,0.],[0.,a+1,0.]]))
|
|
78
|
+
self.assertTrue(Approx(v_par_3d[3].A,1e-5) == Matrix([[a+1,0.,0.],[0.,0.,a],[0.,a+1,0.]]))
|
|
79
|
+
self.assertTrue(Approx(v_par_3d[4].A,1e-5) == Matrix([[0.,a+1,0.],[a+1,0.,0.],[0.,0.,a]]))
|
|
80
|
+
self.assertTrue(Approx(v_par_3d[5].A,1e-5) == Matrix([[0.,-(a+1),0.],[a+1,0.,0.],[0.,0.,a]]))
|
|
81
|
+
|
|
82
|
+
if __name__ == '__main__':
|
|
83
|
+
unittest.main()
|
|
@@ -2,7 +2,7 @@ from codac import *
|
|
|
2
2
|
|
|
3
3
|
def tube_test_1():
|
|
4
4
|
|
|
5
|
-
x = SlicedTube(create_tdomain([0.,46.], 1
|
|
5
|
+
x = SlicedTube(create_tdomain([0.,46.], 1., False), Interval())
|
|
6
6
|
x.set_ith_slice([4,8], 0)
|
|
7
7
|
x.set_ith_slice([2,7], 1)
|
|
8
8
|
x.set_ith_slice([1,6], 2)
|
|
@@ -53,7 +53,7 @@ def tube_test_1():
|
|
|
53
53
|
|
|
54
54
|
def tube_test_1_01():
|
|
55
55
|
|
|
56
|
-
x = SlicedTube(create_tdomain([0.,46.], 0.5), Interval())
|
|
56
|
+
x = SlicedTube(create_tdomain([0.,46.], 0.5, False), Interval())
|
|
57
57
|
|
|
58
58
|
x.set([4,8], [0,1])
|
|
59
59
|
x.set([2,7], [1,2])
|
|
@@ -105,7 +105,7 @@ def tube_test_1_01():
|
|
|
105
105
|
|
|
106
106
|
def tube_test2():
|
|
107
107
|
|
|
108
|
-
x = SlicedTube(create_tdomain([0.,46.], 1
|
|
108
|
+
x = SlicedTube(create_tdomain([0.,46.], 1., False), Interval())
|
|
109
109
|
|
|
110
110
|
x.set_ith_slice([-2,0], 0)
|
|
111
111
|
x.set_ith_slice([-3,1], 1)
|
|
@@ -157,7 +157,7 @@ def tube_test2():
|
|
|
157
157
|
|
|
158
158
|
def tube_test3():
|
|
159
159
|
|
|
160
|
-
x = SlicedTube(create_tdomain([0.,5.], 1
|
|
160
|
+
x = SlicedTube(create_tdomain([0.,5.], 1., False), Interval())
|
|
161
161
|
|
|
162
162
|
x.set_ith_slice([1,3], 0)
|
|
163
163
|
x.set_ith_slice([0,2], 1)
|
|
@@ -168,7 +168,7 @@ def tube_test3():
|
|
|
168
168
|
|
|
169
169
|
def tube_test4():
|
|
170
170
|
|
|
171
|
-
x = SlicedTube(create_tdomain([0.,21.], 1
|
|
171
|
+
x = SlicedTube(create_tdomain([0.,21.], 1., False), Interval())
|
|
172
172
|
|
|
173
173
|
x.set([1,2], [0,9])
|
|
174
174
|
x.set([0.5,1.5], [9,11])
|
|
@@ -181,7 +181,7 @@ def tube_test4():
|
|
|
181
181
|
|
|
182
182
|
def tube_test4_05():
|
|
183
183
|
|
|
184
|
-
x = SlicedTube(create_tdomain([0.,21.], 0.5), Interval())
|
|
184
|
+
x = SlicedTube(create_tdomain([0.,21.], 0.5, False), Interval())
|
|
185
185
|
|
|
186
186
|
x.set([1,2], [0,9])
|
|
187
187
|
x.set([0.5,1.5], [9,10])
|