codac4matlab 2.0.0.dev25__cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.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.cpython-314-aarch64-linux-gnu.so +0 -0
- codac4matlab/_graphics.cpython-314-aarch64-linux-gnu.so +0 -0
- codac4matlab/_unsupported.cpython-314-aarch64-linux-gnu.so +0 -0
- codac4matlab/core/__init__.py +588 -0
- codac4matlab/empty.cpython-314-aarch64-linux-gnu.so +0 -0
- codac4matlab/graphics/__init__.py +1 -0
- codac4matlab/tests/__init__.py +1 -0
- codac4matlab/tests/test_AnalyticFunction.py +442 -0
- codac4matlab/tests/test_AnalyticTraj.py +62 -0
- codac4matlab/tests/test_Approx.py +27 -0
- codac4matlab/tests/test_BoolInterval.py +96 -0
- codac4matlab/tests/test_Color.py +77 -0
- codac4matlab/tests/test_ConvexPolygon.py +300 -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_CtcDeriv.py +434 -0
- codac4matlab/tests/test_CtcEval.py +214 -0
- codac4matlab/tests/test_CtcFixpoint.py +65 -0
- codac4matlab/tests/test_CtcInter.py +39 -0
- codac4matlab/tests/test_CtcInverse.py +213 -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_GaussJordan.py +34 -0
- codac4matlab/tests/test_IntFullPivLU.py +84 -0
- codac4matlab/tests/test_Interval.py +254 -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 +81 -0
- codac4matlab/tests/test_OctaSym.py +41 -0
- codac4matlab/tests/test_Parallelepiped.py +35 -0
- codac4matlab/tests/test_Parallelepiped_eval.py +62 -0
- codac4matlab/tests/test_Polygon.py +120 -0
- codac4matlab/tests/test_SampledTraj.py +135 -0
- codac4matlab/tests/test_Segment.py +138 -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_Slice.py +78 -0
- codac4matlab/tests/test_Slice_polygon.py +208 -0
- codac4matlab/tests/test_SlicedTube.py +562 -0
- codac4matlab/tests/test_SlicedTube_integral.py +380 -0
- codac4matlab/tests/test_TDomain.py +115 -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 +38 -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 +377 -0
- codac4matlab/tests/test_peibos.py +83 -0
- codac4matlab/tests/test_predefined_tubes.py +193 -0
- codac4matlab/tests/test_serialization.py +30 -0
- codac4matlab/tests/test_transformations.py +61 -0
- codac4matlab/tests/test_trunc.py +95 -0
- codac4matlab/unsupported/__init__.py +1 -0
- codac4matlab/version.py +1 -0
- codac4matlab-2.0.0.dev25.dist-info/METADATA +23 -0
- codac4matlab-2.0.0.dev25.dist-info/RECORD +76 -0
- codac4matlab-2.0.0.dev25.dist-info/WHEEL +6 -0
- codac4matlab-2.0.0.dev25.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,664 @@
|
|
|
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 TestIntervalMatrix(unittest.TestCase):
|
|
21
|
+
|
|
22
|
+
def M1(self):
|
|
23
|
+
return IntervalMatrix([
|
|
24
|
+
[[0,1],[0,2],[0,3]],
|
|
25
|
+
[[-1,0],[-2,0],[-3,0]]
|
|
26
|
+
])
|
|
27
|
+
|
|
28
|
+
def M2(self): # the transpose of M1
|
|
29
|
+
return IntervalMatrix([
|
|
30
|
+
[[0,1],[-1,0]],
|
|
31
|
+
[[0,2],[-2,0]],
|
|
32
|
+
[[0,3],[-3,0]]
|
|
33
|
+
])
|
|
34
|
+
|
|
35
|
+
def M3(self): # non-null intersection with M1
|
|
36
|
+
return IntervalMatrix([
|
|
37
|
+
[[1,2],[1,2],[2,4]],
|
|
38
|
+
[[-2,-1],[-2,-1],[-4,-2]]
|
|
39
|
+
])
|
|
40
|
+
|
|
41
|
+
def test_0_intervalmatrix(self):
|
|
42
|
+
|
|
43
|
+
x = IntervalMatrix([
|
|
44
|
+
[ [-1,1], [-2,2] ],
|
|
45
|
+
[ [-3,3], [-4,4] ],
|
|
46
|
+
])
|
|
47
|
+
|
|
48
|
+
x[0,1] = Interval()
|
|
49
|
+
x[1,1] = Interval()
|
|
50
|
+
|
|
51
|
+
self.assertTrue(x == IntervalMatrix([
|
|
52
|
+
[ [-1,1], [-oo,oo] ],
|
|
53
|
+
[ [-3,3], [-oo,oo] ],
|
|
54
|
+
]))
|
|
55
|
+
|
|
56
|
+
#m = IntervalMatrix(x)
|
|
57
|
+
|
|
58
|
+
def test_intervalmatrix(self):
|
|
59
|
+
|
|
60
|
+
m1 = IntervalMatrix(2,3)
|
|
61
|
+
m2 = IntervalMatrix(3,2)
|
|
62
|
+
self.assertTrue(m1 != m2)
|
|
63
|
+
self.assertTrue(not (m1 == m2))
|
|
64
|
+
|
|
65
|
+
m1 = IntervalMatrix(3,2)
|
|
66
|
+
m2 = IntervalMatrix(2,2)
|
|
67
|
+
self.assertTrue(m1 != m2)
|
|
68
|
+
self.assertTrue(not (m1 == m2))
|
|
69
|
+
|
|
70
|
+
m1 = IntervalMatrix(2,3)
|
|
71
|
+
m2 = IntervalMatrix(2,3)
|
|
72
|
+
|
|
73
|
+
self.assertTrue(m1.rows() == 2)
|
|
74
|
+
self.assertTrue(m1.cols() == 3)
|
|
75
|
+
self.assertTrue(m2.rows() == 2)
|
|
76
|
+
self.assertTrue(m2.cols() == 3)
|
|
77
|
+
|
|
78
|
+
m1[0,0] = 1.
|
|
79
|
+
m1[0,1] = 2.
|
|
80
|
+
m1[0,2] = 3.
|
|
81
|
+
m1[1,0] = 4.
|
|
82
|
+
m1[1,1] = 5.
|
|
83
|
+
m1[1,2] = 6.
|
|
84
|
+
m2[0,0] = 1.
|
|
85
|
+
m2[0,1] = 2.
|
|
86
|
+
m2[0,2] = 3.
|
|
87
|
+
m2[1,0] = 4.
|
|
88
|
+
m2[1,1] = 5.
|
|
89
|
+
m2[1,2] = 6.
|
|
90
|
+
|
|
91
|
+
self.assertTrue(m1 == m2)
|
|
92
|
+
self.assertTrue(not (m1 != m2))
|
|
93
|
+
|
|
94
|
+
m2[1,2] = 7.
|
|
95
|
+
self.assertTrue(m1 != m2)
|
|
96
|
+
self.assertTrue(not (m1 == m2))
|
|
97
|
+
|
|
98
|
+
m1 = IntervalMatrix(2,3)
|
|
99
|
+
m2 = IntervalMatrix(2,3)
|
|
100
|
+
m1[1,1] = -1
|
|
101
|
+
m2[1,1] = -2
|
|
102
|
+
self.assertTrue(m1 != m2)
|
|
103
|
+
self.assertTrue(not (m1 == m2))
|
|
104
|
+
m1.set_empty()
|
|
105
|
+
m2.set_empty()
|
|
106
|
+
self.assertTrue(m1 == m2)
|
|
107
|
+
self.assertTrue(not (m1 != m2))
|
|
108
|
+
|
|
109
|
+
m = IntervalMatrix(2,3)
|
|
110
|
+
self.assertTrue(m.rows() == 2)
|
|
111
|
+
self.assertTrue(m.cols() == 3)
|
|
112
|
+
self.assertTrue(m(0,0) == Interval(-oo,oo))
|
|
113
|
+
self.assertTrue(m(0,1) == Interval(-oo,oo))
|
|
114
|
+
self.assertTrue(m(0,2) == Interval(-oo,oo))
|
|
115
|
+
self.assertTrue(m(1,0) == Interval(-oo,oo))
|
|
116
|
+
self.assertTrue(m(1,1) == Interval(-oo,oo))
|
|
117
|
+
self.assertTrue(m(1,2) == Interval(-oo,oo))
|
|
118
|
+
|
|
119
|
+
self.assertTrue(m == IntervalMatrix(m))
|
|
120
|
+
#self.assertTrue(m == (IntervalMatrix(2,3)=m))
|
|
121
|
+
|
|
122
|
+
m1 = IntervalMatrix.zero(2,3)
|
|
123
|
+
r1_0 = IntervalVector([[0,1],[0,2],[0,3]])
|
|
124
|
+
self.assertTrue(r1_0.cols() == 1)
|
|
125
|
+
self.assertTrue(r1_0.rows() == 3)
|
|
126
|
+
r1 = IntervalVector([[0,1],[0,2],[0,3]]).transpose()
|
|
127
|
+
self.assertTrue(r1.cols() == 3)
|
|
128
|
+
self.assertTrue(r1.rows() == 1)
|
|
129
|
+
r2 = IntervalVector([[-1,0],[-2,0],[-3,0]]).transpose()
|
|
130
|
+
self.assertTrue(r2.cols() == 3)
|
|
131
|
+
self.assertTrue(r2.rows() == 1)
|
|
132
|
+
self.assertTrue(r1 == IntervalMatrix([
|
|
133
|
+
[ [0,1], [0,2], [0,3] ]
|
|
134
|
+
]))
|
|
135
|
+
|
|
136
|
+
m1.set_row(0,r1)
|
|
137
|
+
m1.set_row(1,r2)
|
|
138
|
+
|
|
139
|
+
c1 = IntervalVector([[0,1],[-1,0]])
|
|
140
|
+
c2 = IntervalVector([[0,2],[-2,0]])
|
|
141
|
+
c3 = IntervalVector([[0,3],[-3,0]])
|
|
142
|
+
|
|
143
|
+
self.assertTrue(m1.rows() == 2)
|
|
144
|
+
self.assertTrue(m1.cols() == 3)
|
|
145
|
+
|
|
146
|
+
a1 = IntervalRow(r1)
|
|
147
|
+
a2 = IntervalRow(m1.row(0))
|
|
148
|
+
self.assertTrue(a1 == a2)
|
|
149
|
+
|
|
150
|
+
self.assertTrue((m1.row(0) == r1))
|
|
151
|
+
self.assertTrue((m1.row(1) == r2))
|
|
152
|
+
self.assertTrue((m1.row(0) == r1))
|
|
153
|
+
self.assertTrue((m1.row(1) == r2))
|
|
154
|
+
|
|
155
|
+
self.assertTrue((m1.col(0) == c1))
|
|
156
|
+
self.assertTrue((m1.col(1) == c2))
|
|
157
|
+
self.assertTrue((m1.col(2) == c3))
|
|
158
|
+
self.assertTrue(m1(0,0) == Interval(0,1))
|
|
159
|
+
self.assertTrue(m1(0,1) == Interval(0,2))
|
|
160
|
+
self.assertTrue(m1(0,2) == Interval(0,3))
|
|
161
|
+
self.assertTrue(m1(1,0) == Interval(-1,0))
|
|
162
|
+
self.assertTrue(m1(1,1) == Interval(-2,0))
|
|
163
|
+
self.assertTrue(m1(1,2) == Interval(-3,0))
|
|
164
|
+
|
|
165
|
+
self.assertTrue(m1 == IntervalMatrix(m1))
|
|
166
|
+
#self.assertTrue(m1 == (IntervalMatrix(2,3)=m1))
|
|
167
|
+
|
|
168
|
+
x = Interval(-1,2)
|
|
169
|
+
m = IntervalMatrix.constant(2,3,x)
|
|
170
|
+
|
|
171
|
+
self.assertTrue(m.rows() == 2)
|
|
172
|
+
self.assertTrue(m.cols() == 3)
|
|
173
|
+
for i in range (0,2):
|
|
174
|
+
for j in range (0,3):
|
|
175
|
+
self.assertTrue(m(i,j) == x)
|
|
176
|
+
|
|
177
|
+
self.assertTrue(m == IntervalMatrix(m))
|
|
178
|
+
#self.assertTrue(m == (IntervalMatrix(2,3)=m))
|
|
179
|
+
|
|
180
|
+
#double _m[][2] = [
|
|
181
|
+
# [0,1], [0,2], [0,3],
|
|
182
|
+
# [-1,0],[-2,0],[-3,0]
|
|
183
|
+
#]
|
|
184
|
+
#m = IntervalMatrix(2,3,_m)
|
|
185
|
+
#self.assertTrue(m == self.M1())
|
|
186
|
+
|
|
187
|
+
m = IntervalMatrix([
|
|
188
|
+
[[0,1], [0,2], [0,3]],
|
|
189
|
+
[[-1,0],[-2,0],[-3,0]]
|
|
190
|
+
])
|
|
191
|
+
self.assertTrue(m == self.M1())
|
|
192
|
+
|
|
193
|
+
m = IntervalMatrix(2,3)
|
|
194
|
+
# accessor (row,col)
|
|
195
|
+
m[0,0] = Interval(0,1)
|
|
196
|
+
m[0,1] = Interval(0,2)
|
|
197
|
+
m[0,2] = Interval(0,3)
|
|
198
|
+
m[1,0] = Interval(-1,0)
|
|
199
|
+
m[1,1] = Interval(-2,0)
|
|
200
|
+
m[1,2] = Interval(-3,0)
|
|
201
|
+
self.assertTrue(m == self.M1())
|
|
202
|
+
|
|
203
|
+
self.assertTrue(IntervalMatrix.empty(2,3).rows() == 2)
|
|
204
|
+
self.assertTrue(IntervalMatrix.empty(2,3).cols() == 3)
|
|
205
|
+
|
|
206
|
+
self.assertTrue(IntervalMatrix(IntervalMatrix.empty(2,3)) == IntervalMatrix.empty(2,3))
|
|
207
|
+
#self.assertTrue((IntervalMatrix(2,3)=IntervalMatrix.empty(2,3)) == IntervalMatrix.empty(2,3))
|
|
208
|
+
|
|
209
|
+
self.assertTrue(not IntervalMatrix(2,3).is_empty())
|
|
210
|
+
self.assertTrue(IntervalMatrix.empty(2,3).is_empty())
|
|
211
|
+
|
|
212
|
+
m = IntervalMatrix(2,3)
|
|
213
|
+
m.set_empty()
|
|
214
|
+
self.assertTrue(m.is_empty())
|
|
215
|
+
|
|
216
|
+
# Intersection of a matrix with itself
|
|
217
|
+
m1 = self.M1()
|
|
218
|
+
m1 &= self.M1()
|
|
219
|
+
self.assertTrue(m1 == self.M1())
|
|
220
|
+
|
|
221
|
+
# Intersection of two overlapping matrices
|
|
222
|
+
m = IntervalMatrix([
|
|
223
|
+
[[1,1], [1,2], [2,3]],
|
|
224
|
+
[[-1,-1],[-2,-1],[-3,-2]]
|
|
225
|
+
])
|
|
226
|
+
|
|
227
|
+
m1 = self.M1()
|
|
228
|
+
m1 &= self.M3()
|
|
229
|
+
self.assertTrue(m1 == m)
|
|
230
|
+
|
|
231
|
+
# Intersection of two non-overlapping matrices
|
|
232
|
+
m3 = IntervalMatrix(self.M3())
|
|
233
|
+
m3[1,2] = Interval(-5,-4)
|
|
234
|
+
m1 = IntervalMatrix(self.M1())
|
|
235
|
+
m1 &= m3
|
|
236
|
+
self.assertTrue(m1.is_empty())
|
|
237
|
+
|
|
238
|
+
m1 = IntervalMatrix(self.M1())
|
|
239
|
+
|
|
240
|
+
v = IntervalVector(2)
|
|
241
|
+
v[0] = Interval(1,2)
|
|
242
|
+
v[1] = Interval(-2,-1)
|
|
243
|
+
|
|
244
|
+
m1.set_col(1,v)
|
|
245
|
+
|
|
246
|
+
m2 = IntervalMatrix([
|
|
247
|
+
[[0,1], [1,2], [0,3]],
|
|
248
|
+
[[-1,0],[-2,-1],[-3,0]]
|
|
249
|
+
])
|
|
250
|
+
self.assertTrue(m1 == m2)
|
|
251
|
+
|
|
252
|
+
self.assertTrue(self.M1().block(0,0,2,3) == self.M1())
|
|
253
|
+
self.assertTrue(self.M1().block(0,0,1,3) == IntervalMatrix([[[0,1],[0,2],[0,3]]]))
|
|
254
|
+
self.assertTrue(self.M1().block(1,0,1,3) == IntervalMatrix([[[-1,0],[-2,0],[-3,0]]]))
|
|
255
|
+
self.assertTrue(self.M1().block(0,0,2,1) == IntervalMatrix([[[0,1]],[[-1,0]]]))
|
|
256
|
+
self.assertTrue(self.M1().block(0,1,2,1) == IntervalMatrix([[[0,2]],[[-2,0]]]))
|
|
257
|
+
self.assertTrue(self.M1().block(0,2,2,1) == IntervalMatrix([[[0,3]],[[-3,0]]]))
|
|
258
|
+
self.assertTrue(self.M1().block(0,1,2,2) == IntervalMatrix([[[0,2],[0,3]],[[-2,0],[-3,0]]]))
|
|
259
|
+
|
|
260
|
+
m1 = IntervalMatrix(2,2)
|
|
261
|
+
r1 = IntervalVector([[0,1],[0,2]])
|
|
262
|
+
r2 = IntervalVector([[-1,0],[-2,0]])
|
|
263
|
+
m1.set_row(0,r1.transpose())
|
|
264
|
+
m1.set_row(1,r2.transpose())
|
|
265
|
+
m1.resize_save_values(2,3)
|
|
266
|
+
m1[0,2] = Interval(0,3)
|
|
267
|
+
m1[1,2] = Interval(-3,0)
|
|
268
|
+
|
|
269
|
+
self.assertTrue(m1 == self.M1())
|
|
270
|
+
|
|
271
|
+
m1 = IntervalMatrix(1,3)
|
|
272
|
+
r1 = IntervalVector([[0,1],[0,2],[0,3]])
|
|
273
|
+
m1.set_row(0,r1.transpose())
|
|
274
|
+
m1.resize_save_values(2,3)
|
|
275
|
+
m1[1,0] = Interval(-1,0)
|
|
276
|
+
m1[1,1] = Interval(-2,0)
|
|
277
|
+
m1[1,2] = Interval(-3,0)
|
|
278
|
+
|
|
279
|
+
self.assertTrue(m1 == self.M1())
|
|
280
|
+
|
|
281
|
+
e = IntervalMatrix.empty(1,1)
|
|
282
|
+
e.resize_save_values(2,3)
|
|
283
|
+
self.assertTrue(e.is_empty())
|
|
284
|
+
|
|
285
|
+
m1 = IntervalMatrix(self.M1())
|
|
286
|
+
m2 = IntervalMatrix(-m1)
|
|
287
|
+
for i in range (0,2):
|
|
288
|
+
for j in range(0,3):
|
|
289
|
+
self.assertTrue(m2(i,j) == -m1(i,j))
|
|
290
|
+
|
|
291
|
+
self.assertTrue((-IntervalMatrix.empty(2,3)).is_empty())
|
|
292
|
+
|
|
293
|
+
m1 = IntervalMatrix(self.M1())
|
|
294
|
+
m2 = IntervalMatrix(m1+m1)
|
|
295
|
+
|
|
296
|
+
for i in range (0,2):
|
|
297
|
+
for j in range(0,3):
|
|
298
|
+
self.assertTrue(m2(i,j) == m1(i,j)+m1(i,j))
|
|
299
|
+
|
|
300
|
+
m0 = IntervalMatrix(m1)
|
|
301
|
+
m0 += m1
|
|
302
|
+
self.assertTrue(m2 == m0)
|
|
303
|
+
|
|
304
|
+
m1 = IntervalMatrix.empty(2,3)
|
|
305
|
+
m2 = IntervalMatrix(2,3)
|
|
306
|
+
|
|
307
|
+
self.assertTrue((m1+m2).is_empty())
|
|
308
|
+
m1+=m2
|
|
309
|
+
self.assertTrue(m1.is_empty())
|
|
310
|
+
m2+=m1
|
|
311
|
+
self.assertTrue(m2.is_empty())
|
|
312
|
+
|
|
313
|
+
m1 = IntervalMatrix(self.M1())
|
|
314
|
+
m2 = IntervalMatrix(m1-m1)
|
|
315
|
+
for i in range (0,2):
|
|
316
|
+
for j in range(0,3):
|
|
317
|
+
self.assertTrue(m2(i,j) == m1(i,j)-m1(i,j))
|
|
318
|
+
|
|
319
|
+
m0 = IntervalMatrix(m1)
|
|
320
|
+
m0 -= m1
|
|
321
|
+
self.assertTrue(m2 == m0)
|
|
322
|
+
|
|
323
|
+
m1 = IntervalMatrix.empty(2,3)
|
|
324
|
+
m2 = IntervalMatrix(2,3)
|
|
325
|
+
|
|
326
|
+
self.assertTrue((m1-m2).is_empty())
|
|
327
|
+
m1-=m2
|
|
328
|
+
self.assertTrue(m1.is_empty())
|
|
329
|
+
m2-=m1
|
|
330
|
+
self.assertTrue(m2.is_empty())
|
|
331
|
+
|
|
332
|
+
m1 = IntervalMatrix(self.M1())
|
|
333
|
+
m2 = IntervalMatrix(self.M2())
|
|
334
|
+
m3 = IntervalMatrix(m1*m2)
|
|
335
|
+
self.assertTrue(m3.rows() == 2)
|
|
336
|
+
self.assertTrue(m3.cols() == 2)
|
|
337
|
+
|
|
338
|
+
for i in range (0,2):
|
|
339
|
+
for j in range(0,2):
|
|
340
|
+
self.assertTrue(m3(i,j) == m1(i,0)*m2(0,j)+m1(i,1)*m2(1,j)+m1(i,2)*m2(2,j))
|
|
341
|
+
|
|
342
|
+
# Not supported by Eigen: self.assertTrue(m3 == (IntervalMatrix(m1)*=m2))
|
|
343
|
+
|
|
344
|
+
m1 = IntervalMatrix.empty(2,3)
|
|
345
|
+
m2 = IntervalMatrix(3,2)
|
|
346
|
+
|
|
347
|
+
self.assertTrue((m1*m2).is_empty())
|
|
348
|
+
# Not supported by Eigen: self.assertTrue((m1*=m2).is_empty())
|
|
349
|
+
# Not supported by Eigen: self.assertTrue((m2*=m1).is_empty())
|
|
350
|
+
|
|
351
|
+
M1 = IntervalMatrix(Matrix.eye(2,2))
|
|
352
|
+
self.assertTrue(M1 == IntervalMatrix([
|
|
353
|
+
[ [1,1],[0,0] ],
|
|
354
|
+
[ [0,0],[1,1] ]
|
|
355
|
+
]))
|
|
356
|
+
|
|
357
|
+
M2 = IntervalMatrix(2.*Matrix.eye(2,2))
|
|
358
|
+
self.assertTrue(M2 == IntervalMatrix([
|
|
359
|
+
[ [2,2],[0,0] ],
|
|
360
|
+
[ [0,0],[2,2] ]
|
|
361
|
+
]))
|
|
362
|
+
|
|
363
|
+
M3_degenerate = Matrix(-1.*Matrix.eye(2,2))
|
|
364
|
+
self.assertTrue(M3_degenerate == Matrix([
|
|
365
|
+
[ -1,0 ],
|
|
366
|
+
[ 0,-1 ]
|
|
367
|
+
]))
|
|
368
|
+
|
|
369
|
+
M3_Matrix = IntervalMatrix(Interval(-1,1)*Matrix.eye(2,2))
|
|
370
|
+
self.assertTrue(M3_Matrix == IntervalMatrix([
|
|
371
|
+
[ [-1,1],[0,0] ],
|
|
372
|
+
[ [0,0],[-1,1] ]
|
|
373
|
+
]))
|
|
374
|
+
|
|
375
|
+
M3_IntervalMatrix = IntervalMatrix(Interval(-1,1)*IntervalMatrix.eye(2,2))
|
|
376
|
+
self.assertTrue(M3_IntervalMatrix == IntervalMatrix([
|
|
377
|
+
[ [-1,1],[0,0] ],
|
|
378
|
+
[ [0,0],[-1,1] ]
|
|
379
|
+
]))
|
|
380
|
+
|
|
381
|
+
M1 = IntervalMatrix(2.*Matrix.eye(3,3))
|
|
382
|
+
V1 = IntervalVector(3)
|
|
383
|
+
V1[0] = 3
|
|
384
|
+
V1[1] = 4
|
|
385
|
+
V1[2] = 5
|
|
386
|
+
res = IntervalMatrix(4,4)
|
|
387
|
+
res.set_block(0,0,3,3,M1)
|
|
388
|
+
res.set_block(0,3,3,1,V1)
|
|
389
|
+
res.set_block(3,0,1,3,IntervalVector.ones(3).transpose())
|
|
390
|
+
res[3,3] = 6
|
|
391
|
+
|
|
392
|
+
self.assertTrue((res == Matrix([
|
|
393
|
+
[2,0,0,3],
|
|
394
|
+
[0,2,0,4],
|
|
395
|
+
[0,0,2,5],
|
|
396
|
+
[1,1,1,6]
|
|
397
|
+
])))
|
|
398
|
+
|
|
399
|
+
m1 = Matrix([
|
|
400
|
+
[ 0,2 ],
|
|
401
|
+
[ 3,10 ]
|
|
402
|
+
])
|
|
403
|
+
m2 = Matrix([
|
|
404
|
+
[ -1,7 ],
|
|
405
|
+
[ 8,4 ]
|
|
406
|
+
])
|
|
407
|
+
|
|
408
|
+
self.assertTrue((IntervalMatrix(m1) | m2) == IntervalMatrix([
|
|
409
|
+
[ [-1,0],[2,7] ],
|
|
410
|
+
[ [3,8],[4,10] ]
|
|
411
|
+
]))
|
|
412
|
+
|
|
413
|
+
m1 = IntervalMatrix([
|
|
414
|
+
[ [0,1],[0,2] ],
|
|
415
|
+
[ [0,0],Interval.empty() ]
|
|
416
|
+
])
|
|
417
|
+
m2 = IntervalMatrix([
|
|
418
|
+
[ [-oo,oo],[-1,3] ],
|
|
419
|
+
[ [2,4],[1,1] ]
|
|
420
|
+
])
|
|
421
|
+
|
|
422
|
+
self.assertTrue((m1 | m2) == IntervalMatrix([
|
|
423
|
+
[ [-oo,oo],[-1,3] ],
|
|
424
|
+
[ [0,4],[1,1] ]
|
|
425
|
+
]))
|
|
426
|
+
|
|
427
|
+
m1 = IntervalMatrix([
|
|
428
|
+
[ [0,1],[0,2] ],
|
|
429
|
+
[ [0,0],Interval.empty() ]
|
|
430
|
+
])
|
|
431
|
+
m2 = IntervalMatrix([
|
|
432
|
+
[ [-oo,oo],[-1,3] ],
|
|
433
|
+
[ [2,4],[1,1] ]
|
|
434
|
+
])
|
|
435
|
+
|
|
436
|
+
self.assertTrue((m1 & m2) == IntervalMatrix([
|
|
437
|
+
[ [0,1],[0,2] ],
|
|
438
|
+
[ Interval.empty(),Interval.empty() ]
|
|
439
|
+
]))
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
def test_intervalmatrix_mixing_type(self):
|
|
443
|
+
|
|
444
|
+
m1 = Matrix([
|
|
445
|
+
[ 1,2 ],
|
|
446
|
+
[ 3,4 ]
|
|
447
|
+
])
|
|
448
|
+
|
|
449
|
+
# Interval - Matrix
|
|
450
|
+
self.assertTrue((Interval(-1,1) * m1) == IntervalMatrix([
|
|
451
|
+
[ [-1,1],[-2,2] ],
|
|
452
|
+
[ [-3,3],[-4,4] ]
|
|
453
|
+
]))
|
|
454
|
+
|
|
455
|
+
# Matrix - Interval
|
|
456
|
+
self.assertTrue((m1 / Interval(2)) == IntervalMatrix([
|
|
457
|
+
[ [1./2.],[2./2.] ],
|
|
458
|
+
[ [3./2.],[4./2.] ]
|
|
459
|
+
]))
|
|
460
|
+
|
|
461
|
+
v1 = IntervalVector([
|
|
462
|
+
-1,
|
|
463
|
+
-2
|
|
464
|
+
])
|
|
465
|
+
|
|
466
|
+
self.assertTrue(v1[0] == -1)
|
|
467
|
+
self.assertTrue(v1[1] == -2)
|
|
468
|
+
|
|
469
|
+
iv1 = IntervalVector([
|
|
470
|
+
[-1,1],
|
|
471
|
+
[-1,1]
|
|
472
|
+
])
|
|
473
|
+
|
|
474
|
+
# Matrix - IntervalVector
|
|
475
|
+
self.assertTrue((m1 * iv1) == IntervalVector([
|
|
476
|
+
[-3,3],
|
|
477
|
+
[-7,7]
|
|
478
|
+
]))
|
|
479
|
+
|
|
480
|
+
# double - IntervalVector
|
|
481
|
+
self.assertTrue((-3 * iv1) == IntervalVector([
|
|
482
|
+
[-3,3],
|
|
483
|
+
[-3,3]
|
|
484
|
+
]))
|
|
485
|
+
|
|
486
|
+
# Interval - Vector
|
|
487
|
+
self.assertTrue((Interval(-1,1) * v1) == IntervalVector([
|
|
488
|
+
[-1,1],
|
|
489
|
+
[-2,2]
|
|
490
|
+
]))
|
|
491
|
+
|
|
492
|
+
im1 = IntervalMatrix([
|
|
493
|
+
[ [-1,1],[-2,2] ],
|
|
494
|
+
[ [-3,3],[-4,4] ]
|
|
495
|
+
])
|
|
496
|
+
|
|
497
|
+
# Matrix - IntervalMatrix
|
|
498
|
+
self.assertTrue((m1 + im1) == IntervalMatrix([
|
|
499
|
+
[ [0,2],[0,4] ],
|
|
500
|
+
[ [0,6],[0,8] ]
|
|
501
|
+
]))
|
|
502
|
+
|
|
503
|
+
# IntervalMatrix - Matrix
|
|
504
|
+
self.assertTrue((im1 + m1) == IntervalMatrix([
|
|
505
|
+
[ [0,2],[0,4] ],
|
|
506
|
+
[ [0,6],[0,8] ]
|
|
507
|
+
]))
|
|
508
|
+
|
|
509
|
+
# IntervalMatrix - Matrix block
|
|
510
|
+
self.assertTrue((im1 + m1.block(0,0,2,2)) == IntervalMatrix([
|
|
511
|
+
[ [0,2],[0,4] ],
|
|
512
|
+
[ [0,6],[0,8] ]
|
|
513
|
+
]))
|
|
514
|
+
|
|
515
|
+
# Matrix block - IntervalMatrix
|
|
516
|
+
self.assertTrue((m1.block(0,0,2,2) + im1) == IntervalMatrix([
|
|
517
|
+
[ [0,2],[0,4] ],
|
|
518
|
+
[ [0,6],[0,8] ]
|
|
519
|
+
]))
|
|
520
|
+
|
|
521
|
+
# Matrix - IntervalMatrix
|
|
522
|
+
self.assertTrue((m1 - im1) == IntervalMatrix([
|
|
523
|
+
[ [0,2],[0,4] ],
|
|
524
|
+
[ [0,6],[0,8] ]
|
|
525
|
+
]))
|
|
526
|
+
|
|
527
|
+
# IntervalMatrix - Matrix
|
|
528
|
+
self.assertTrue((im1 - m1) == IntervalMatrix([
|
|
529
|
+
[ [-2,0],[-4,0] ],
|
|
530
|
+
[ [-6,0],[-8,0] ]
|
|
531
|
+
]))
|
|
532
|
+
|
|
533
|
+
# Matrix - col of IntervalMatrix
|
|
534
|
+
self.assertTrue((m1 * im1.col(0)) == IntervalMatrix([
|
|
535
|
+
[ [-7,7] ],
|
|
536
|
+
[ [-15,15] ]
|
|
537
|
+
]))
|
|
538
|
+
|
|
539
|
+
# Row of Matrix - col of Matrix
|
|
540
|
+
# operations on Row types not supported yet in Python: self.assertTrue((m1.row(1) * m1.col(0)) == Matrix([[15]]))
|
|
541
|
+
|
|
542
|
+
# Row of Matrix - col of IntervalMatrix
|
|
543
|
+
# operations on Row types not supported yet in Python: self.assertTrue((m1.row(1) * im1.col(0)) == IntervalMatrix([[[-15,15]]]))
|
|
544
|
+
|
|
545
|
+
# Row of IntervalMatrix - col of IntervalMatrix
|
|
546
|
+
# operations on Row types not supported yet in Python: self.assertTrue((im1.row(1) * im1.col(0)) == IntervalMatrix([[[-15,15]]]))
|
|
547
|
+
|
|
548
|
+
m1 = Matrix([
|
|
549
|
+
[ 1,2 ],
|
|
550
|
+
[ 3,4 ]
|
|
551
|
+
])
|
|
552
|
+
|
|
553
|
+
m2 = Matrix([
|
|
554
|
+
[ 2,3 ],
|
|
555
|
+
[ 4,5 ]
|
|
556
|
+
])
|
|
557
|
+
|
|
558
|
+
im = IntervalMatrix(m1,m2)
|
|
559
|
+
self.assertTrue(im == IntervalMatrix([
|
|
560
|
+
[ [1,2],[2,3] ],
|
|
561
|
+
[ [3,4],[4,5] ]
|
|
562
|
+
]))
|
|
563
|
+
|
|
564
|
+
m2[0,1] = 1.
|
|
565
|
+
|
|
566
|
+
im_empty = IntervalMatrix(m1,m2)
|
|
567
|
+
self.assertTrue(im_empty == IntervalMatrix.empty(2,2))
|
|
568
|
+
|
|
569
|
+
m1 = IntervalMatrix.ones(3,3)
|
|
570
|
+
m2 = IntervalMatrix.zero(3,3)
|
|
571
|
+
self.assertTrue(m1.volume() == 0.)
|
|
572
|
+
self.assertTrue(m2.volume() == 0.)
|
|
573
|
+
self.assertTrue((m1+m2).volume() == 0.)
|
|
574
|
+
|
|
575
|
+
m1 = IntervalMatrix([
|
|
576
|
+
[ [1,2],[2,3] ],
|
|
577
|
+
[ [3,4],[4,5] ]
|
|
578
|
+
])
|
|
579
|
+
m2 = Matrix([
|
|
580
|
+
[ 1.5, 2.5 ],
|
|
581
|
+
[ 3.5, 4.5 ]
|
|
582
|
+
])
|
|
583
|
+
|
|
584
|
+
self.assertTrue(m1.contains(m2))
|
|
585
|
+
self.assertTrue(IntervalMatrix(m2).is_strict_subset(m1))
|
|
586
|
+
|
|
587
|
+
m3 = Matrix(2,2)
|
|
588
|
+
m3 = m2+m2
|
|
589
|
+
self.assertTrue(m3 == Matrix([
|
|
590
|
+
[ 3, 5 ],
|
|
591
|
+
[ 7, 9 ]
|
|
592
|
+
]))
|
|
593
|
+
|
|
594
|
+
m4 = IntervalMatrix(m2+m2)
|
|
595
|
+
self.assertTrue(m4 == IntervalMatrix([
|
|
596
|
+
[[3,3],[5,5]],
|
|
597
|
+
[[7,7],[9,9]]
|
|
598
|
+
]))
|
|
599
|
+
|
|
600
|
+
m5 = IntervalMatrix(m2*m2)
|
|
601
|
+
self.assertTrue(m5 == IntervalMatrix([
|
|
602
|
+
[[11,11],[15,15]],
|
|
603
|
+
[[21,21],[29,29]]
|
|
604
|
+
]))
|
|
605
|
+
|
|
606
|
+
test1 = IntervalMatrix([
|
|
607
|
+
[ [0,1], [0,2], [0,0] ]
|
|
608
|
+
])
|
|
609
|
+
self.assertTrue(test1.rows() == 1)
|
|
610
|
+
self.assertTrue(test1.cols() == 3)
|
|
611
|
+
self.assertTrue(test1(0,0) == Interval(0,1))
|
|
612
|
+
self.assertTrue(test1(0,1) == Interval(0,2))
|
|
613
|
+
self.assertTrue(test1(0,2) == Interval(0,0))
|
|
614
|
+
|
|
615
|
+
test2 = IntervalMatrix([
|
|
616
|
+
[0,1],
|
|
617
|
+
[2,3],
|
|
618
|
+
[4,5]
|
|
619
|
+
])
|
|
620
|
+
self.assertTrue(test2.rows() == 3)
|
|
621
|
+
self.assertTrue(test2.cols() == 2)
|
|
622
|
+
self.assertTrue(test2(0,0) == Interval(0))
|
|
623
|
+
self.assertTrue(test2(0,1) == Interval(1))
|
|
624
|
+
self.assertTrue(test2(1,0) == Interval(2))
|
|
625
|
+
self.assertTrue(test2(1,1) == Interval(3))
|
|
626
|
+
self.assertTrue(test2(2,0) == Interval(4))
|
|
627
|
+
self.assertTrue(test2(2,1) == Interval(5))
|
|
628
|
+
|
|
629
|
+
test3 = IntervalMatrix([
|
|
630
|
+
[[1,oo],[2,oo]],
|
|
631
|
+
[[3,oo],[4,oo]],
|
|
632
|
+
[[5,oo],[6,oo]]
|
|
633
|
+
])
|
|
634
|
+
self.assertTrue(test3.rows() == 3)
|
|
635
|
+
self.assertTrue(test3.cols() == 2)
|
|
636
|
+
self.assertTrue(test3(0,0) == Interval(1,oo))
|
|
637
|
+
self.assertTrue(test3(0,1) == Interval(2,oo))
|
|
638
|
+
self.assertTrue(test3(1,0) == Interval(3,oo))
|
|
639
|
+
self.assertTrue(test3(1,1) == Interval(4,oo))
|
|
640
|
+
self.assertTrue(test3(2,0) == Interval(5,oo))
|
|
641
|
+
self.assertTrue(test3(2,1) == Interval(6,oo))
|
|
642
|
+
|
|
643
|
+
test4 = IntervalMatrix([
|
|
644
|
+
[[1,2]],
|
|
645
|
+
[[3,4]],
|
|
646
|
+
[[5,6]]
|
|
647
|
+
])
|
|
648
|
+
self.assertTrue(test4.rows() == 3)
|
|
649
|
+
self.assertTrue(test4.cols() == 1)
|
|
650
|
+
self.assertTrue(test4(0,0) == Interval(1,2))
|
|
651
|
+
self.assertTrue(test4(1,0) == Interval(3,4))
|
|
652
|
+
self.assertTrue(test4(2,0) == Interval(5,6))
|
|
653
|
+
|
|
654
|
+
iv = IntervalVector([[1,2],[3,4],[5,6]])
|
|
655
|
+
test5 = IntervalMatrix(iv)
|
|
656
|
+
self.assertTrue(test5.rows() == 3)
|
|
657
|
+
self.assertTrue(test5.cols() == 1)
|
|
658
|
+
self.assertTrue(test5(0,0) == Interval(1,2))
|
|
659
|
+
self.assertTrue(test5(1,0) == Interval(3,4))
|
|
660
|
+
self.assertTrue(test5(2,0) == Interval(5,6))
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
if __name__ == '__main__':
|
|
664
|
+
unittest.main()
|