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.
Files changed (61) hide show
  1. codac4matlab/__init__.py +4 -0
  2. codac4matlab/_core.cp313-win32.pyd +0 -0
  3. codac4matlab/_graphics.cp313-win32.pyd +0 -0
  4. codac4matlab/_unsupported.cp313-win32.pyd +0 -0
  5. codac4matlab/core/__init__.py +340 -0
  6. codac4matlab/graphics/__init__.py +1 -0
  7. codac4matlab/tests/__init__.py +1 -0
  8. codac4matlab/tests/test_AnalyticFunction.py +419 -0
  9. codac4matlab/tests/test_AnalyticTraj.py +63 -0
  10. codac4matlab/tests/test_Approx.py +27 -0
  11. codac4matlab/tests/test_BoolInterval.py +40 -0
  12. codac4matlab/tests/test_Color.py +79 -0
  13. codac4matlab/tests/test_ConvexPolygon.py +207 -0
  14. codac4matlab/tests/test_CtcAction.py +30 -0
  15. codac4matlab/tests/test_CtcCartProd.py +39 -0
  16. codac4matlab/tests/test_CtcCtcBoundary.py +48 -0
  17. codac4matlab/tests/test_CtcFixpoint.py +65 -0
  18. codac4matlab/tests/test_CtcInter.py +39 -0
  19. codac4matlab/tests/test_CtcInverse.py +157 -0
  20. codac4matlab/tests/test_CtcInverseNotIn.py +129 -0
  21. codac4matlab/tests/test_CtcLazy.py +50 -0
  22. codac4matlab/tests/test_CtcPolygon.py +91 -0
  23. codac4matlab/tests/test_CtcSegment.py +104 -0
  24. codac4matlab/tests/test_Ellipsoid.py +20 -0
  25. codac4matlab/tests/test_IntFullPivLU.py +57 -0
  26. codac4matlab/tests/test_Interval.py +230 -0
  27. codac4matlab/tests/test_IntervalMatrix.py +664 -0
  28. codac4matlab/tests/test_IntervalVector.py +657 -0
  29. codac4matlab/tests/test_Interval_operations.py +293 -0
  30. codac4matlab/tests/test_Matrix.py +68 -0
  31. codac4matlab/tests/test_OctaSym.py +32 -0
  32. codac4matlab/tests/test_Polygon.py +108 -0
  33. codac4matlab/tests/test_SampledTraj.py +113 -0
  34. codac4matlab/tests/test_Segment.py +123 -0
  35. codac4matlab/tests/test_SepCartProd.py +34 -0
  36. codac4matlab/tests/test_SepCtcBoundary.py +52 -0
  37. codac4matlab/tests/test_SepInverse.py +104 -0
  38. codac4matlab/tests/test_SepPolygon.py +102 -0
  39. codac4matlab/tests/test_SepProj.py +39 -0
  40. codac4matlab/tests/test_SepTransform.py +41 -0
  41. codac4matlab/tests/test_Vector.py +41 -0
  42. codac4matlab/tests/test_arithmetic_add.py +54 -0
  43. codac4matlab/tests/test_arithmetic_div.py +46 -0
  44. codac4matlab/tests/test_arithmetic_mul.py +114 -0
  45. codac4matlab/tests/test_arithmetic_sub.py +54 -0
  46. codac4matlab/tests/test_capd.py +19 -0
  47. codac4matlab/tests/test_cart_prod.py +37 -0
  48. codac4matlab/tests/test_eigen.py +19 -0
  49. codac4matlab/tests/test_geometry.py +136 -0
  50. codac4matlab/tests/test_hull.py +35 -0
  51. codac4matlab/tests/test_ibex.py +19 -0
  52. codac4matlab/tests/test_inversion.py +57 -0
  53. codac4matlab/tests/test_linear_ctc.py +77 -0
  54. codac4matlab/tests/test_operators.py +348 -0
  55. codac4matlab/tests/test_transformations.py +61 -0
  56. codac4matlab/unsupported/__init__.py +1 -0
  57. codac4matlab/version.py +1 -0
  58. codac4matlab-2.0.0.dev14.dist-info/METADATA +23 -0
  59. codac4matlab-2.0.0.dev14.dist-info/RECORD +61 -0
  60. codac4matlab-2.0.0.dev14.dist-info/WHEEL +5 -0
  61. codac4matlab-2.0.0.dev14.dist-info/top_level.txt +1 -0
@@ -0,0 +1,419 @@
1
+ #!/usr/bin/env python
2
+
3
+ # Codac tests
4
+ # ----------------------------------------------------------------------------
5
+ # \date 2024
6
+ # \author Simon Rohou, Damien Massé
7
+ # \copyright Copyright 2024 Codac Team
8
+ # \license GNU Lesser General Public License (LGPL)
9
+
10
+ import sys, os
11
+ import unittest
12
+ import math
13
+ from codac import *
14
+
15
+ def create_f():
16
+ x = ScalarVar()
17
+ return AnalyticFunction([x], x*cos(x))
18
+
19
+ class TestAnalyticFunction(unittest.TestCase):
20
+
21
+ def tests_AnalyticFunction(self):
22
+
23
+ def invalid_function():
24
+ x = ScalarVar()
25
+ f = AnalyticFunction([3], cos(x))
26
+
27
+ self.assertRaises(ValueError, invalid_function)
28
+
29
+ x = ScalarVar()
30
+ self.assertTrue(x.size() == 1)
31
+
32
+ y = VectorVar(3)
33
+ self.assertTrue(y.size() == 3)
34
+ self.assertTrue(type(y[0]) == ScalarExpr)
35
+ self.assertTrue(type(y[2]) == ScalarExpr)
36
+
37
+ for i in range(0,2):
38
+
39
+ def test_eval(f,*args):
40
+
41
+ if(i == 0): # natural
42
+ return f.eval(EvalMode.NATURAL,*args)
43
+
44
+ elif(i == 1): # centered
45
+ return f.eval(EvalMode.CENTERED,*args)
46
+
47
+ else: # centered and natural
48
+ return f.eval(*args)
49
+
50
+ f = AnalyticFunction([x], x)
51
+ self.assertTrue(Approx(test_eval(f,Interval(0))) == 0)
52
+ f = AnalyticFunction([x], x+Interval(2))
53
+ self.assertTrue(Approx(test_eval(f,Interval(3))) == 5)
54
+ f = AnalyticFunction([x], x+x)
55
+ self.assertTrue(Approx(test_eval(f,Interval(2))) == 4)
56
+ f = AnalyticFunction([x], x+x+2)
57
+ self.assertTrue(Approx(test_eval(f,Interval(2))) == 6)
58
+ f = AnalyticFunction([x], pow(x,2))
59
+ self.assertTrue(Approx(test_eval(f,Interval(3))) == 9)
60
+ f = AnalyticFunction([x], x^2)
61
+ self.assertTrue(Approx(test_eval(f,Interval(3))) == 9)
62
+ f = AnalyticFunction([x], (0.+x)^(1.*x))
63
+ self.assertTrue(Approx(test_eval(f,Interval(3))) == 27)
64
+ f = AnalyticFunction([x], x**2)
65
+ self.assertTrue(Approx(test_eval(f,Interval(3))) == 9)
66
+ f = AnalyticFunction([x], (0.+x)**(1.*x))
67
+ self.assertTrue(Approx(test_eval(f,Interval(3))) == 27)
68
+ f = AnalyticFunction([x], cos(x))
69
+ self.assertTrue(Approx(test_eval(f,Interval(0))) == 1)
70
+
71
+ f = AnalyticFunction([x], [x,x])
72
+
73
+ fvec = AnalyticFunction([x], [x,x])
74
+ self.assertTrue(Approx(test_eval(f,1)) == IntervalVector([[1],[1]]))
75
+
76
+ self.assertTrue(test_eval(AnalyticFunction([], +4)) == 4)
77
+ self.assertTrue(test_eval(AnalyticFunction([], +4.)) == 4.)
78
+ self.assertTrue(test_eval(AnalyticFunction([], +Interval(4,5))) == Interval(4,5))
79
+ self.assertTrue(test_eval(AnalyticFunction([], Vector([2,9]))) == Vector([2,9]))
80
+ self.assertTrue(test_eval(AnalyticFunction([], IntervalVector(3))) == IntervalVector([[-oo,oo],[-oo,oo],[-oo,oo]]))
81
+
82
+ x1 = ScalarVar()
83
+ x2 = ScalarVar()
84
+ v1 = VectorVar(2)
85
+ v2 = VectorVar(2)
86
+
87
+ # ======> ScalarVar
88
+
89
+ # .def("__pos__", [](const ScalarVar& e1)
90
+ self.assertTrue(test_eval(AnalyticFunction([x1], +x1), 5.) == 5.)
91
+ # .def("__add__", [](const ScalarVar& e1, const ScalarVar& e2)
92
+ self.assertTrue(test_eval(AnalyticFunction([x1,x2], x1+x2), 5.,6.) == 11.)
93
+ # .def("__add__", [](const ScalarVar& e1, const Interval& e2)
94
+ self.assertTrue(test_eval(AnalyticFunction([x1], x1+Interval(3)), 5.) == 8.)
95
+ # .def("__radd__", [](const ScalarVar& e1, const Interval& e2)
96
+ self.assertTrue(test_eval(AnalyticFunction([x1], Interval(3)+x1), 5.) == 8.)
97
+ # .def("__neg__", [](const ScalarVar& e1)
98
+ self.assertTrue(test_eval(AnalyticFunction([x2], -x2), 6.) == -6.)
99
+ # .def("__sub__", [](const ScalarVar& e1, const ScalarVar& e2)
100
+ self.assertTrue(test_eval(AnalyticFunction([x1,x2], x1-x2), 5.,6.) == -1.)
101
+ # .def("__sub__", [](const ScalarVar& e1, const Interval& e2)
102
+ self.assertTrue(test_eval(AnalyticFunction([x1], x1-Interval(2.)), 5.) == 3.)
103
+ # .def("__rsub__", [](const ScalarVar& e1, const Interval& e2)
104
+ self.assertTrue(test_eval(AnalyticFunction([x1], Interval(2.)-x1), 5.) == -3.)
105
+ # .def("__mul__", [](const ScalarVar& e1, const ScalarVar& e2)
106
+ self.assertTrue(test_eval(AnalyticFunction([x1,x2], x1*x2), 5.,6.) == 30.)
107
+ # .def("__mul__", [](const ScalarVar& e1, const Interval& e2)
108
+ self.assertTrue(test_eval(AnalyticFunction([x1], x1*Interval(6.)), 5.) == 30.)
109
+ # .def("__rmul__", [](const ScalarVar& e1, const Interval& e2)
110
+ self.assertTrue(test_eval(AnalyticFunction([x1], Interval(6.)*x1), 5.) == 30.)
111
+ # .def("__mul__", [](const ScalarVar& e1, const VectorVar& e2)
112
+ self.assertTrue(test_eval(AnalyticFunction([v1,v2], v1[0]*v2), Vector([5.,10.]),IntervalVector([[3],[3]])) == Vector([15,15]))
113
+ # .def("__mul__", [](const ScalarVar& e1, const IntervalVector& e2)
114
+ self.assertTrue(test_eval(AnalyticFunction([x1], x1*IntervalVector([[-2,3],[0,1]])), 5.) == IntervalVector([[-10,15],[0,5]]))
115
+ # .def("__truediv__", [](const ScalarVar& e1, const ScalarVar& e2)
116
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1,x2], x1/x2), 1.,10.)) == 0.1)
117
+ # .def("__truediv__", [](const ScalarVar& e1, const Interval& e2)
118
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], x1/Interval(10)), 1.)) == 0.1)
119
+ # .def("__rtruediv__", [](const ScalarVar& e1, const Interval& e2)
120
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], Interval(2.)/x1), 10.)) == 0.2)
121
+
122
+ # ======> VectorVar
123
+
124
+ #.def("__pos__", [](const VectorVar& e1)
125
+ self.assertTrue(test_eval(AnalyticFunction([v1], +v1), Vector([5.,6.])) == Vector([5.,6.]))
126
+ #.def("__add__", [](const VectorVar& e1, const VectorVar& e2)
127
+ self.assertTrue(test_eval(AnalyticFunction([v1,v2], v1+v2), Vector([5.,6.]),Vector([2.,3.])) == Vector([7.,9.]))
128
+ #.def("__add__", [](const VectorVar& e1, const IntervalVector& e2)
129
+ self.assertTrue(test_eval(AnalyticFunction([v1], v1+IntervalVector([[2],[3]])), Vector([5.,6.])) == IntervalVector([[7.],[9.]]))
130
+ #.def("__radd__", [](const VectorVar& e1, const IntervalVector& e2)
131
+ self.assertTrue(test_eval(AnalyticFunction([v1], IntervalVector([[2],[3]])+v1), Vector([5.,6.])) == IntervalVector([[7.],[9.]]))
132
+ #.def("__neg__", [](const VectorVar& e1)
133
+ self.assertTrue(test_eval(AnalyticFunction([v1], -v1), Vector([5.,6.])) == -Vector([5.,6.]))
134
+ #.def("__sub__", [](const VectorVar& e1, const VectorVar& e2)
135
+ self.assertTrue(test_eval(AnalyticFunction([v1,v2], v1-v2), Vector([5.,6.]),Vector([2.,3.])) == Vector([3.,3.]))
136
+ #.def("__sub__", [](const VectorVar& e1, const IntervalVector& e2)
137
+ self.assertTrue(test_eval(AnalyticFunction([v1], v1-IntervalVector([[2],[3]])), Vector([5.,6.])) == IntervalVector([[3.],[3.]]))
138
+ #.def("__rsub__", [](const VectorVar& e1, const IntervalVector& e2)
139
+ self.assertTrue(test_eval(AnalyticFunction([v1], IntervalVector([[2],[3]])-v1), Vector([5.,6.])) == IntervalVector([[-3.],[-3.]]))
140
+
141
+ # ======> ScalarExpr
142
+
143
+ #.def("__pos__", [](const ScalarExpr& e1)
144
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], +cos(x1)), Interval(0.))) == Interval(1.))
145
+ #.def(py::self + py::self)
146
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], cos(x1)+cos(x1)), Interval(0.))) == Interval(2.))
147
+ #.def("__add__", [](const ScalarExpr& e1, const ScalarVar& e2)
148
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], cos(x1)+x1), math.pi)) == math.pi-1)
149
+ #.def("__radd__", [](const ScalarExpr& e1, const ScalarVar& e2)
150
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], x1+cos(x1)), math.pi)) == math.pi-1)
151
+ #.def("__add__", [](const ScalarExpr& e1, const Interval& e2)
152
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], cos(x1)+Interval(10.)), math.pi)) == Interval(9))
153
+ #.def("__radd__", [](const ScalarExpr& e1, const Interval& e2)
154
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], 10+cos(x1)), math.pi)) == Interval(9))
155
+ #.def(- py::self)
156
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], -cos(x1)), Interval(0.))) == Interval(-1.))
157
+ #.def(py::self - py::self)
158
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], cos(x1)-cos(x1)), Interval(0.))) == Interval(0.))
159
+ #.def("__sub__", [](const ScalarExpr& e1, const ScalarVar& e2)
160
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], cos(x1)-x1), math.pi)) == -math.pi-1)
161
+ #.def("__rsub__", [](const ScalarExpr& e1, const ScalarVar& e2)
162
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], x1-cos(x1)), math.pi)) == math.pi+1)
163
+ #.def("__sub__", [](const ScalarExpr& e1, const Interval& e2)
164
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], cos(x1)-Interval(10.)), math.pi)) == -Interval(11))
165
+ #.def("__rsub__", [](const ScalarExpr& e1, const Interval& e2)
166
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], 10-cos(x1)), math.pi)) == Interval(11))
167
+ #.def(py::self * py::self)
168
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], cos(x1)*cos(x1)), Interval(0.))) == Interval(1.))
169
+ #.def("__mul__", [](const ScalarExpr& e1, const ScalarVar& e2)
170
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], cos(x1)*x1), math.pi)) == -1*math.pi)
171
+ #.def("__rmul__", [](const ScalarExpr& e1, const ScalarVar& e2)
172
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], x1*cos(x1)), math.pi)) == -1*math.pi)
173
+ #.def("__mul__", [](const ScalarExpr& e1, const Interval& e2)
174
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], cos(x1)*Interval(10.)), math.pi),1e-9) == -Interval(10))
175
+ #.def("__rmul__", [](const ScalarExpr& e1, const Interval& e2)
176
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], Interval(10.)*cos(x1)), math.pi),1e-9) == -10)
177
+ #.def("__mul__", [](const ScalarExpr& e1, const VectorExpr& e2)
178
+ self.assertTrue(Approx(test_eval(AnalyticFunction([v1,v2], cos(v1[0])*(v2+v2)), Vector([math.pi,-1]),Vector([2,3])),1e-9) == IntervalVector([[-4],[-6]]))
179
+ #.def("__truediv__", [](const ScalarExpr& e1, const ScalarExpr& e2)
180
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], cos(x1)/cos(x1)), Interval(0.))) == Interval(1.))
181
+ #.def("__truediv__", [](const ScalarExpr& e1, const ScalarVar& e2)
182
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], cos(x1)/x1), math.pi)) == -1/math.pi)
183
+ #.def("__rtruediv__", [](const ScalarExpr& e1, const ScalarVar& e2)
184
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], x1/cos(x1)), math.pi)) == -math.pi)
185
+ #.def("__truediv__", [](const ScalarExpr& e1, const Interval& e2)
186
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], cos(x1)/Interval(4.)), math.pi)) == -1./4)
187
+ #.def("__rtruediv__", [](const ScalarExpr& e1, const Interval& e2)
188
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], 4./cos(x1)), math.pi)) == -4)
189
+
190
+ # ======> VectorExpr
191
+
192
+ #.def("__pos__", [](const VectorExpr& e1)
193
+ self.assertTrue(Approx(test_eval(AnalyticFunction([v1], +(v1+v1)), IntervalVector([[0.],[-oo,5]]))) ==
194
+ IntervalVector([[0.],[-oo,oo]]) if i==1 else IntervalVector([[0.],[-oo,10]]))
195
+ #.def(py::self + py::self)
196
+ self.assertTrue(Approx(test_eval(AnalyticFunction([v1], v1+v1), IntervalVector([[0.],[-oo,5]]))) ==
197
+ IntervalVector([[0.],[-oo,oo]]) if i==1 else IntervalVector([[0.],[-oo,10]]))
198
+ #.def("__radd__", [](const VectorExpr& e1, const VectorVar& e2)
199
+ self.assertTrue(Approx(test_eval(AnalyticFunction([v1], (v1+v1)+v1), IntervalVector([[0.],[-oo,5]]))) ==
200
+ IntervalVector([[0.],[-oo,oo]]) if i==1 else IntervalVector([[0.],[-oo,15]]))
201
+ #.def("__radd__", [](const VectorExpr& e1, const IntervalVector& e2)
202
+ self.assertTrue(Approx(test_eval(AnalyticFunction([v1], v1+(v1+v1)), IntervalVector([[0.],[-oo,5]]))) ==
203
+ IntervalVector([[0.],[-oo,oo]]) if i==1 else IntervalVector([[0.],[-oo,15]]))
204
+ #.def(- py::self)
205
+ self.assertTrue(Approx(test_eval(AnalyticFunction([v1], -(v1+v1)), IntervalVector([[0.],[-oo,5]]))) ==
206
+ -IntervalVector([[0.],[-oo,oo]]) if i==1 else -IntervalVector([[0.],[-oo,10]]))
207
+ #.def(py::self - py::self)
208
+ self.assertTrue(Approx(test_eval(AnalyticFunction([v1,v2], (v1-v2)), IntervalVector([[2],[3]]),Vector([1,5]))) == IntervalVector([[1],[-2]]))
209
+ #.def("__sub__", [](const VectorExpr& e1, const VectorVar& e2)
210
+ self.assertTrue(Approx(test_eval(AnalyticFunction([v1,v2], (v1-v2)-v1), IntervalVector([[2],[3]]),Vector([1,5]))) == IntervalVector([[-1],[-5]]))
211
+ #.def("__rsub__", [](const VectorExpr& e1, const VectorVar& e2)
212
+ self.assertTrue(Approx(test_eval(AnalyticFunction([v1,v2], v2-(v1-v2)), IntervalVector([[2],[3]]),Vector([1,5]))) == IntervalVector([[0],[7]]))
213
+ #.def("__sub__", [](const VectorExpr& e1, const IntervalVector& e2)
214
+ self.assertTrue(Approx(test_eval(AnalyticFunction([v1,v2], (v1-v2)-IntervalVector([[2],[3]])), IntervalVector([[2],[3]]),Vector([1,5]))) == IntervalVector([[-1],[-5]]))
215
+ #.def("__rsub__", [](const VectorExpr& e1, const IntervalVector& e2)
216
+ self.assertTrue(Approx(test_eval(AnalyticFunction([v1,v2], Vector([1,5])-(v1-v2)), IntervalVector([[2],[3]]),Vector([1,5]))) == IntervalVector([[0],[7]]))
217
+ #.def("__rmul__", [](const VectorExpr& e1, const ScalarExpr& e2)
218
+ self.assertTrue(Approx(test_eval(AnalyticFunction([v1,v2], cos(v1[0])*(v2+v2)), Vector([math.pi,-1]),Vector([2,3])),1e-9) == IntervalVector([[-4],[-6]]))
219
+ #.def("__rmul__", [](const VectorExpr& e1, const ScalarVar& e2)
220
+ self.assertTrue(Approx(test_eval(AnalyticFunction([x1], x1*vec(3*x1,2*x1)), 3),1e-9) == IntervalVector([[27],[18]]))
221
+
222
+ x = VectorVar(2)
223
+ f = AnalyticFunction([x], x[0]*(x[0]+x[1])+sqr(x[1]))
224
+ self.assertTrue(f.diff(Vector([2,3]))(0,0) == 7)
225
+ self.assertTrue(f.diff(Vector([2,3]))(0,1) == 8)
226
+
227
+ # int values
228
+ x,y = ScalarVar(), ScalarVar()
229
+ f = AnalyticFunction([x,y], x*(x+y)+sqr(y))
230
+ self.assertTrue(f.diff(2,3)(0,0) == 7)
231
+ self.assertTrue(f.diff(2,3)(0,1) == 8)
232
+
233
+ # double values
234
+ x,y = ScalarVar(), ScalarVar()
235
+ f = AnalyticFunction([x,y], x*(x+y)+sqr(y))
236
+ self.assertTrue(f.diff(2.,3.)(0,0) == 7)
237
+ self.assertTrue(f.diff(2.,3.)(0,1) == 8)
238
+
239
+ # Interval values
240
+ x,y = ScalarVar(), ScalarVar()
241
+ f = AnalyticFunction([x,y], x*(x+y)+sqr(y))
242
+ self.assertTrue(f.diff(Interval(2.),Interval(3.))(0,0) == 7)
243
+ self.assertTrue(f.diff(Interval(2.),Interval(3.))(0,1) == 8)
244
+
245
+ # Evaluation modes
246
+ x = ScalarVar()
247
+ f = AnalyticFunction([x], x-x)
248
+ self.assertTrue(f.eval(EvalMode.NATURAL,Interval(-1,1)) == Interval(-2,2))
249
+ self.assertTrue(f.eval(EvalMode.CENTERED,Interval(-1,1)) == Interval(0))
250
+ self.assertTrue(f.eval(Interval(-1,1)) == Interval(0))
251
+
252
+ # Scalar outputs
253
+ f1 = AnalyticFunction([], 3)
254
+ self.assertTrue(f1.eval() == Interval(3))
255
+ f2 = AnalyticFunction([], 3.)
256
+ self.assertTrue(f2.eval() == Interval(3))
257
+ f3 = AnalyticFunction([], Interval(3.))
258
+ self.assertTrue(f3.eval() == Interval(3))
259
+ x = ScalarVar()
260
+ f4 = AnalyticFunction([x], x*x)
261
+ self.assertTrue(f4.eval(2.) == Interval(4))
262
+
263
+ # Vectorial outputs
264
+
265
+ f1 = AnalyticFunction([], [ 3 ])
266
+ self.assertTrue(f1.eval() == IntervalVector([3]))
267
+ f2 = AnalyticFunction([], [ 3. ])
268
+ self.assertTrue(f2.eval() == IntervalVector([3]))
269
+ f3 = AnalyticFunction([], [ Interval(3.) ])
270
+ self.assertTrue(f3.eval() == IntervalVector([3]))
271
+ x = ScalarVar()
272
+ f4 = AnalyticFunction([x], [ x*x ])
273
+ self.assertTrue(f4.eval(2.) == IntervalVector([4]))
274
+
275
+ f_2args = AnalyticFunction([x], [ x*x,x*x ])
276
+ self.assertTrue(f_2args.eval(1.) == IntervalVector.constant(2,[1]))
277
+ f_3args = AnalyticFunction([x], [ x,x*x,1 ])
278
+ self.assertTrue(f_3args.eval(1.) == IntervalVector.constant(3,[1]))
279
+ f_4args = AnalyticFunction([x], [ x,x*x,1,x ])
280
+ self.assertTrue(f_4args.eval(1.) == IntervalVector.constant(4,[1]))
281
+ f_5args = AnalyticFunction([x], [ x,x*x,1,x,x ])
282
+ self.assertTrue(f_5args.eval(1.) == IntervalVector.constant(5,[1]))
283
+ f_6args = AnalyticFunction([x], [ x,x*x,1,x,x,1*x ])
284
+ self.assertTrue(f_6args.eval(1.) == IntervalVector.constant(6,[1]))
285
+ f_7args = AnalyticFunction([x], [ x,x*x,1,x,x,1*x,x*x ])
286
+ self.assertTrue(f_7args.eval(1.) == IntervalVector.constant(7,[1]))
287
+ f_8args = AnalyticFunction([x], [ x,x*x,1,x,x,1*x,x*x,1 ])
288
+ self.assertTrue(f_8args.eval(1.) == IntervalVector.constant(8,[1]))
289
+ f_9args = AnalyticFunction([x], [ x,x*x,1,x,x,1*x,x*x,1,x ])
290
+ self.assertTrue(f_9args.eval(1.) == IntervalVector.constant(9,[1]))
291
+ f_10args = AnalyticFunction([x], [ x,x*x,1,x,x,1*x,x*x,1,x,1*x ])
292
+ self.assertTrue(f_10args.eval(1.) == IntervalVector.constant(10,[1]))
293
+
294
+ # Subvector on variables
295
+ p = VectorVar(2)
296
+ x = VectorVar(4)
297
+ f = AnalyticFunction([p], p[0]*p[1])
298
+ g = AnalyticFunction([x], f(x.subvector(0,1)) + f(x.subvector(2,3)))
299
+
300
+ a = IntervalVector(4)
301
+
302
+ a = IntervalVector([[1],[2],[3],[4]])
303
+ self.assertTrue(g.eval(EvalMode.NATURAL,a) == 14)
304
+ self.assertTrue(g.eval(EvalMode.CENTERED,a) == 14)
305
+ self.assertTrue(g.eval(a) == 14)
306
+
307
+ a = IntervalVector([[0],[2],[5],[4]])
308
+ self.assertTrue(g.eval(EvalMode.NATURAL,a) == 20)
309
+ self.assertTrue(g.eval(EvalMode.CENTERED,a) == 20)
310
+ self.assertTrue(g.eval(a) == 20)
311
+
312
+
313
+ # Sign, floor, ceil, min, max
314
+ x1 = ScalarVar()
315
+ x2 = ScalarVar()
316
+
317
+ f = AnalyticFunction([x1,x2], 2*max(x1,x2+1))
318
+ self.assertTrue(f.eval(0.,1.) == 4.)
319
+ self.assertTrue(f.eval(2.,1.) == 4.)
320
+ self.assertTrue(f.eval(3.,1.) == 6.)
321
+
322
+ f = AnalyticFunction([x1,x2], 2*min(x1,x2+1))
323
+ self.assertTrue(f.eval(0.,1.) == 0.)
324
+ self.assertTrue(f.eval(2.,1.) == 4.)
325
+ self.assertTrue(f.eval(3.,1.) == 4.)
326
+
327
+ f = AnalyticFunction([x1], 2*sign(x1+1))
328
+ self.assertTrue(f.eval(0.) == 2.)
329
+ self.assertTrue(sign(Interval.zero()) == Interval(-1,1))
330
+ self.assertTrue(sign(Interval(-0,0)) == Interval(-1,1))
331
+ self.assertTrue(f.eval(-1.) == Interval(-2,2))
332
+ self.assertTrue(f.eval(-2.) == -2.)
333
+
334
+ f = AnalyticFunction([x1], 2*floor(x1))
335
+ self.assertTrue(f.eval(0.) == 0.)
336
+ self.assertTrue(f.eval(1.5) == 2.)
337
+ self.assertTrue(f.eval(-1.5) == -4.)
338
+
339
+ f = AnalyticFunction([x1], 2*ceil(x1))
340
+ self.assertTrue(f.eval(0.) == 0.)
341
+ self.assertTrue(f.eval(1.5) == 4.)
342
+ self.assertTrue(f.eval(-1.5) == -2.)
343
+
344
+
345
+ # Issue #201
346
+ # Input argument is a py::list instead of a Vector
347
+ x1 = VectorVar(2)
348
+ f = AnalyticFunction([x1], 2.*x1)
349
+ self.assertTrue(f.eval([2,3]) == IntervalVector([[4],[6]]))
350
+ self.assertTrue(f.eval([[2,3],[4,5]]) == IntervalVector([[4,6],[8,10]]))
351
+
352
+
353
+ I = Matrix([[0,2],[-1,0]])
354
+ x = VectorVar(2)
355
+ f = AnalyticFunction([x], I*x)
356
+ self.assertTrue(f.eval(IntervalVector([[0,1],[2,3]])) == IntervalVector([[4,6],[-1,0]]))
357
+
358
+ I = Matrix([[1,0],[0,1]])
359
+ x = VectorVar(2)
360
+ f = AnalyticFunction([x], I*I*x)
361
+ self.assertTrue(f.eval(IntervalVector([[-1,1],[2,3]])) == IntervalVector([[-1,1],[2,3]]))
362
+
363
+ A = MatrixVar(2,2)
364
+ x = VectorVar(2)
365
+ h = AnalyticFunction([A], A*A)
366
+ f = AnalyticFunction([x,A], h(A)*x)
367
+ g = AnalyticFunction([x], f(x,Matrix([[0,2],[-1,0]])))
368
+ self.assertTrue(g.eval(IntervalVector([[-1,1],[2,3]])) == IntervalVector([[-2,2],[-6,-4]]))
369
+
370
+ A = MatrixVar(2,2)
371
+ f_det = AnalyticFunction([A], A(0,0)*A(1,1)-A(1,0)*A(0,1))
372
+ self.assertTrue(f_det.eval(Matrix([[1,2],[3,4]])) == -2)
373
+ self.assertTrue(f_det.eval(IntervalMatrix([[[0,1],[1,2]],[[2,3],[3,4]]])) == Interval(-6,2))
374
+
375
+ f = create_f()
376
+ self.assertTrue(Approx(f.eval(PI)) == -PI)
377
+
378
+ x = ScalarVar()
379
+ f = AnalyticFunction([x],sqrt(x))
380
+ self.assertTrue(Interval(0.).is_subset([0,oo]))
381
+ self.assertTrue(Interval(0.,10.).is_subset([0,oo]))
382
+ self.assertTrue(Approx(f.eval(EvalMode.NATURAL, 0.)) == 0.)
383
+ self.assertTrue(Approx(f.eval(EvalMode.NATURAL, 1e-10),1e-3) == 0.)
384
+ # Cannot compute in pure centered form due to the
385
+ # definition domain of the derivative of sqrt:
386
+ self.assertTrue(f.eval(EvalMode.CENTERED, 0.).is_empty())
387
+ self.assertTrue(Approx(f.eval(EvalMode.CENTERED, 1e-10),1e-3) == 0.)
388
+ self.assertTrue(Approx(f.eval(0.)) == 0.)
389
+ self.assertTrue(Approx(f.eval(1e-10),1e-3) == 0.)
390
+
391
+ x1,x2,x3 = VectorVar(2),VectorVar(2),VectorVar(2)
392
+ f = AnalyticFunction([x1,x2,x3], mat(+x1,-x2,2*x3))
393
+ self.assertTrue(f.eval(EvalMode.NATURAL, Vector([1,2]),Vector([-1,8]),IntervalVector([[-1,1],[2,oo]]))
394
+ == IntervalMatrix([[1,1,[-2,2]],[2,-8,[4,oo]]]))
395
+
396
+ x1 = VectorVar(2)
397
+ f = AnalyticFunction([x1],det(mat(+x1,2*x1)))
398
+ self.assertTrue(Approx(f.eval(EvalMode.NATURAL, IntervalVector([[0.9,1.1],[0.4,0.5]])),1e-9) == Interval(-0.38,0.38))
399
+ self.assertTrue(Approx(f.eval(EvalMode.CENTERED, IntervalVector([[0.9,1.1],[0.4,0.5]])),1e-9) == Interval(-0.04,0.04))
400
+
401
+ M1 = MatrixVar(2,3)
402
+ M2 = MatrixVar(3,2)
403
+ f = AnalyticFunction([M1,M2], M1*M2-M1*M2)
404
+ self.assertTrue(Approx(f.eval(EvalMode.NATURAL,
405
+ Matrix([[1,0,1],[0,1,0]]),
406
+ IntervalMatrix([[[-0.2,0.2],[-0.1,0.1]],
407
+ [[0.2,0.4],[-0.4,-0.1]],
408
+ [[1.0,2.0],[-0.2,-0.1]]])),1e-9)
409
+ == IntervalMatrix([[[-1.4,1.4],[-0.3,0.3]],
410
+ [[-0.2,0.2],[-0.3,0.3]]]))
411
+ self.assertTrue(Approx(f.eval(EvalMode.CENTERED,
412
+ Matrix([[1,0,1],[0,1,0]]),
413
+ IntervalMatrix([[[-0.2,0.2],[-0.1,0.1]],
414
+ [[0.2,0.4],[-0.4,-0.1]],
415
+ [[1.0,2.0],[-0.2,-0.1]]])),1e-9)
416
+ == Matrix([[0,0],[0,0]]))
417
+
418
+ if __name__ == '__main__':
419
+ unittest.main()
@@ -0,0 +1,63 @@
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
+ def prim_value(x):
16
+ return 1.+(1./3.)*math.pow(x,3)
17
+
18
+ class TestAnalyticTraj(unittest.TestCase):
19
+
20
+ def tests_AnalyticTraj(self):
21
+
22
+ t = ScalarVar()
23
+ f = AnalyticFunction(
24
+ [t],
25
+ sqr(t)
26
+ )
27
+
28
+ traj = AnalyticTraj(f, [-1,10])
29
+
30
+ self.assertTrue(traj.tdomain() == Interval(-1,10))
31
+ self.assertTrue(traj.codomain() == Interval(0,100))
32
+ self.assertTrue(traj.size() == 1)
33
+ self.assertTrue(Approx(traj(5.3),1e-3) == 28.09)
34
+ self.assertTrue(traj(traj.tdomain()) == traj.codomain())
35
+ self.assertTrue(traj([-oo,oo]) == Interval(-oo,oo))
36
+
37
+ # Testing sampled trajectory from analytic trajectory
38
+ sampled_traj = traj.sampled(0.01)
39
+ self.assertTrue(sampled_traj.tdomain() == Interval(-1,10))
40
+ self.assertTrue(Approx(sampled_traj.codomain()) == Interval(0,100))
41
+ self.assertTrue(sampled_traj.size() == 1)
42
+ self.assertTrue(Approx(sampled_traj(sampled_traj.tdomain())) == sampled_traj.codomain())
43
+ self.assertTrue(sampled_traj([-oo,oo]) == Interval(-oo,oo))
44
+ self.assertTrue(Approx(sampled_traj(0.)) == 0.)
45
+ self.assertTrue(Approx(sampled_traj(2.),1e-2) == 4.)
46
+ self.assertTrue(Approx(sampled_traj(5.),1e-2) == 25.)
47
+ self.assertTrue(Approx(sampled_traj(5.3),1e-2) == 28.09)
48
+ self.assertTrue(Approx(sampled_traj(9.),1e-2) == 81.)
49
+
50
+ # Testing primitive computation from analytic trajectory
51
+ x0 = f.real_eval(-1) # == 1.
52
+ sampled_prim_traj = traj.primitive(x0,0.01)
53
+ self.assertTrue(sampled_prim_traj.tdomain() == Interval(-1,10))
54
+ self.assertTrue(Approx(sampled_prim_traj.codomain(),4e-1) == Interval(prim_value(0),prim_value(10.)))
55
+ self.assertTrue(sampled_prim_traj(-1.) == x0)
56
+ self.assertTrue(Approx(sampled_prim_traj(0.),4e-1) == prim_value(0.))
57
+ self.assertTrue(Approx(sampled_prim_traj(2.),4e-1) == prim_value(2.))
58
+ self.assertTrue(Approx(sampled_prim_traj(5.),4e-1) == prim_value(5.))
59
+ self.assertTrue(Approx(sampled_prim_traj(5.3),4e-1) == prim_value(5.3))
60
+ self.assertTrue(Approx(sampled_prim_traj(9.),4e-1) == prim_value(9.))
61
+
62
+ if __name__ == '__main__':
63
+ unittest.main()
@@ -0,0 +1,27 @@
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
+
14
+ class TestApprox(unittest.TestCase):
15
+
16
+ def tests_approx(self):
17
+
18
+ self.assertFalse(Interval(0.1) == Interval(1.)/Interval(10.))
19
+ self.assertTrue(Approx(Interval(0.1)) == Interval(1.)/Interval(10.))
20
+ self.assertTrue(Interval(0.1) == Approx(Interval(1.)/Interval(10.)))
21
+
22
+ #self.assertTrue(IntervalVector([[0.1]]) != IntervalVector([1.])/Interval(10.))
23
+ #self.assertTrue(Approx(IntervalVector([[0.1]])) == IntervalVector([1.])/Interval(10.))
24
+ #self.assertTrue(IntervalVector([[0.1]]) == Approx(IntervalVector([1.])/Interval(10.)))
25
+
26
+ if __name__ == '__main__':
27
+ unittest.main()
@@ -0,0 +1,40 @@
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 TestBoolInterval(unittest.TestCase):
14
+
15
+ def tests_BoolInterval(self):
16
+
17
+ self.assertTrue((BoolInterval.TRUE & BoolInterval.TRUE) == BoolInterval.TRUE)
18
+ self.assertTrue((BoolInterval.TRUE & BoolInterval.FALSE) == BoolInterval.EMPTY)
19
+ self.assertTrue((BoolInterval.TRUE & BoolInterval.UNKNOWN) == BoolInterval.TRUE)
20
+ self.assertTrue((BoolInterval.TRUE & BoolInterval.EMPTY) == BoolInterval.EMPTY)
21
+ self.assertTrue((BoolInterval.FALSE & BoolInterval.FALSE) == BoolInterval.FALSE)
22
+ self.assertTrue((BoolInterval.FALSE & BoolInterval.UNKNOWN) == BoolInterval.FALSE)
23
+ self.assertTrue((BoolInterval.FALSE & BoolInterval.EMPTY) == BoolInterval.EMPTY)
24
+ self.assertTrue((BoolInterval.EMPTY & BoolInterval.EMPTY) == BoolInterval.EMPTY)
25
+ self.assertTrue((BoolInterval.EMPTY & BoolInterval.UNKNOWN) == BoolInterval.EMPTY)
26
+ self.assertTrue((BoolInterval.UNKNOWN & BoolInterval.UNKNOWN) == BoolInterval.UNKNOWN)
27
+
28
+ self.assertTrue((BoolInterval.TRUE | BoolInterval.TRUE) == BoolInterval.TRUE)
29
+ self.assertTrue((BoolInterval.TRUE | BoolInterval.FALSE) == BoolInterval.UNKNOWN)
30
+ self.assertTrue((BoolInterval.TRUE | BoolInterval.UNKNOWN) == BoolInterval.UNKNOWN)
31
+ self.assertTrue((BoolInterval.TRUE | BoolInterval.EMPTY) == BoolInterval.TRUE)
32
+ self.assertTrue((BoolInterval.FALSE | BoolInterval.FALSE) == BoolInterval.FALSE)
33
+ self.assertTrue((BoolInterval.FALSE | BoolInterval.UNKNOWN) == BoolInterval.UNKNOWN)
34
+ self.assertTrue((BoolInterval.FALSE | BoolInterval.EMPTY) == BoolInterval.FALSE)
35
+ self.assertTrue((BoolInterval.EMPTY | BoolInterval.EMPTY) == BoolInterval.EMPTY)
36
+ self.assertTrue((BoolInterval.EMPTY | BoolInterval.UNKNOWN) == BoolInterval.UNKNOWN)
37
+ self.assertTrue((BoolInterval.UNKNOWN | BoolInterval.UNKNOWN) == BoolInterval.UNKNOWN)
38
+
39
+ if __name__ == '__main__':
40
+ unittest.main()
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env python
2
+
3
+ # Codac tests
4
+ # ----------------------------------------------------------------------------
5
+ # \date 2024
6
+ # \author Simon Rohou, 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
+
13
+
14
+ class TestColor(unittest.TestCase):
15
+
16
+ def test_Color(self):
17
+ # Red
18
+
19
+ d_rgb = [255, 0, 0]
20
+ d_rgba = [255, 0, 0, 255]
21
+ d_hsv = [0, 100, 100]
22
+ d_hsva = [0, 100, 100, 100]
23
+
24
+
25
+ colors = [
26
+ Color(d_rgb, Model.RGB),
27
+ Color(d_rgba, Model.RGB),
28
+ Color(d_hsv, Model.HSV),
29
+ Color(d_hsva, Model.HSV),
30
+ Color("#FF0000")
31
+ ]
32
+
33
+ for c in colors:
34
+ self.assertTrue(Approx(c.rgb().vec(), 1.0)==Color([255, 0, 0]).rgb().vec())
35
+ self.assertTrue(Approx(c.rgb().vec(), 1.0)==Color([255, 0, 0, 255]).rgb().vec())
36
+ self.assertTrue(Approx(c.hsv().vec(), 1.0)==Color([0, 100, 100],Model.HSV).hsv().vec())
37
+ self.assertTrue(Approx(c.hsv().vec(), 1.0)==Color([0, 100, 100, 100],Model.HSV).hsv().vec())
38
+
39
+ # Pink full opacity
40
+
41
+ d_rgb = [229,128,255]
42
+ d_rgba = [229,128,255,255]
43
+ d_hsv = [288,50,100]
44
+ d_hsva = [288,50,100,100]
45
+
46
+ colors = [
47
+ Color(d_rgb, Model.RGB),
48
+ Color(d_rgba, Model.RGB),
49
+ Color(d_hsv, Model.HSV),
50
+ Color(d_hsva, Model.HSV),
51
+ Color("#E580FF")
52
+ ]
53
+
54
+ for c in colors:
55
+ self.assertTrue(Approx(c.rgb().vec(), 1.0)==Color([229,128,255]).rgb().vec())
56
+ self.assertTrue(Approx(c.rgb().vec(), 1.0)==Color([229,128,255,255]).rgb().vec())
57
+ self.assertTrue(Approx(c.hsv().vec(), 1.0)==Color([288,50,100],Model.HSV).hsv().vec())
58
+ self.assertTrue(Approx(c.hsv().vec(), 1.0)==Color([288,50,100,100],Model.HSV).hsv().vec())
59
+
60
+ # Pink 40% opacity
61
+
62
+ a_rgb=102
63
+ a_hsv=40
64
+ d_rgba = [229,128,255,a_rgb]
65
+ d_hsva = [288,50,100,a_hsv]
66
+
67
+
68
+ colors = [
69
+ Color(d_rgba, Model.RGB),
70
+ Color(d_hsva, Model.HSV),
71
+ Color("#E580FF66")
72
+ ]
73
+ for c in colors:
74
+ self.assertTrue(Approx(c.rgb().vec(), 1.0)==Color([229,128,255,a_rgb]).rgb().vec())
75
+ self.assertTrue(Approx(c.hsv().vec(), 1.0)==Color([288,50,100,a_hsv],Model.HSV).hsv().vec())
76
+
77
+
78
+ if __name__ == '__main__':
79
+ unittest.main()