|
7 | 7 |
|
8 | 8 | from codac._core import * |
9 | 9 | import sys |
| 10 | +import warnings |
10 | 11 |
|
11 | 12 |
|
12 | 13 | def codac_error(message): |
@@ -120,116 +121,28 @@ def copy(self): |
120 | 121 | return super().copy() |
121 | 122 |
|
122 | 123 |
|
123 | | -class CtcInverse(Ctc_IntervalVector): |
124 | | - |
125 | | - def __init__(self, f, y, with_centered_form=True): |
126 | | - |
127 | | - f = AnalyticFunction(f) |
128 | | - |
129 | | - if f.nb_args() > 1: |
130 | | - total_var = VectorVar(f.input_size()) |
131 | | - |
132 | | - i = 0 |
133 | | - f_args = [] |
134 | | - for a in f.args(): |
135 | | - if a.size() == 1: |
136 | | - f_args.append(total_var.get_item_0(i)) |
137 | | - i = i + 1 |
138 | | - else: |
139 | | - f_args.append(total_var.subvector_0(i, i + a.size() - 1)) |
140 | | - i = i + a.size() |
141 | | - |
142 | | - g = AnalyticFunction([total_var], f(*f_args)) |
143 | | - CtcInverse.__init__(self, g, y, with_centered_form) |
144 | | - |
145 | | - else: |
146 | | - Ctc_IntervalVector.__init__(self, f.input_size()) |
147 | | - if isinstance(f, AnalyticFunction_Scalar): |
148 | | - if not ( |
149 | | - isinstance(y, (int, float, Interval)) |
150 | | - or (isinstance(y, list) and len(y) > 0 and len(y) <= 2 and isinstance(y[0], (int, float))) |
151 | | - ): |
152 | | - codac_error("CtcInverse: inverse argument 'y' should be a scalar type (float,Interval)") |
153 | | - self.c = CtcInverse_Interval(f, Interval(y), with_centered_form) |
154 | | - elif isinstance(f, AnalyticFunction_Vector): |
155 | | - if not isinstance(y, (Vector, IntervalVector, list, Ctc_IntervalVector, Ctc_IntervalVector_)): |
156 | | - codac_error( |
157 | | - "CtcInverse: inverse argument 'y' should be a vector type " |
158 | | - "(Vector,IntervalVector,Ctc_IntervalVector,Ctc_IntervalVector_)" |
159 | | - ) |
160 | | - if isinstance(y, (Ctc_IntervalVector, Ctc_IntervalVector_)): |
161 | | - self.c = CtcInverse_IntervalVector(f, y, with_centered_form) |
162 | | - else: |
163 | | - self.c = CtcInverse_IntervalVector(f, IntervalVector(y), with_centered_form) |
164 | | - else: |
165 | | - codac_error("CtcInverse: can only build CtcInverse from scalar or vector functions") |
166 | | - |
167 | | - def contract(self, *x): |
168 | | - |
169 | | - if len(x) == 1: |
170 | | - return self.c.contract(x[0]) |
171 | | - |
172 | | - total = cart_prod(*x) |
173 | | - total = self.c.contract(total) |
174 | | - i = 0 |
175 | | - for xi in x: |
176 | | - k = xi.size() |
177 | | - if k == 1: |
178 | | - xi &= total.get_item_0(i) |
179 | | - else: |
180 | | - xi &= total.subvector_0(i, i + k - 1) |
181 | | - i = i + k |
182 | | - return x |
183 | | - |
184 | | - def contract_tube(self, *x): |
185 | | - |
186 | | - if len(x) == 1: |
187 | | - return self.c.contract_tube(x[0]) |
188 | | - |
189 | | - total = tube_cart_prod(*x) |
190 | | - total = self.c.contract_tube(total) |
191 | | - i = 0 |
192 | | - for xi in x: |
193 | | - k = xi.size() |
194 | | - if k == 1: |
195 | | - xi &= total.get_item_0(i) |
196 | | - else: |
197 | | - xi &= total.subvector_0(i, i + k - 1) |
198 | | - i = i + k |
199 | | - return x |
| 124 | +def CtcInverse(f, y, with_centered_form=True): |
| 125 | + f = AnalyticFunction(f) |
200 | 126 |
|
201 | | - def copy(self): |
202 | | - return self.c.copy() |
| 127 | + if isinstance(f, AnalyticFunction_Scalar): |
| 128 | + return CtcInverse_Interval(f, y, with_centered_form) |
203 | 129 |
|
204 | | - def fnc(self): |
205 | | - return self.c.fnc() |
| 130 | + if isinstance(f, AnalyticFunction_Vector): |
| 131 | + return CtcInverse_IntervalVector(f, y, with_centered_form) |
206 | 132 |
|
| 133 | + codac_error("CtcInverse: can only build CtcInverse from scalar or vector functions") |
207 | 134 |
|
208 | | -class CtcInverseNotIn(Ctc_IntervalVector): |
209 | 135 |
|
210 | | - def __init__(self, f, y, with_centered_form=True): |
211 | | - f = AnalyticFunction(f) |
| 136 | +def CtcInverseNotIn(f, y, with_centered_form=True): |
| 137 | + f = AnalyticFunction(f) |
212 | 138 |
|
213 | | - Ctc_IntervalVector.__init__(self, f.input_size()) |
214 | | - if isinstance(f, AnalyticFunction_Scalar): |
215 | | - if not ( |
216 | | - isinstance(y, (int, float, Interval)) |
217 | | - or (isinstance(y, list) and len(y) > 0 and len(y) <= 2 and isinstance(y[0], (int, float))) |
218 | | - ): |
219 | | - codac_error("CtcInverseNotIn: inverse argument 'y' should be a scalar type (float,Interval)") |
220 | | - self.c = CtcInverseNotIn_Interval(f, Interval(y), with_centered_form) |
221 | | - elif isinstance(f, AnalyticFunction_Vector): |
222 | | - if not isinstance(y, (Vector, IntervalVector, list)): |
223 | | - codac_error("CtcInverseNotIn: inverse argument 'y' should be a vector type (Vector,IntervalVector)") |
224 | | - self.c = CtcInverseNotIn_IntervalVector(f, IntervalVector(y), with_centered_form) |
225 | | - else: |
226 | | - codac_error("CtcInverseNotIn: can only build CtcInverseNotIn from scalar or vector functions") |
| 139 | + if isinstance(f, AnalyticFunction_Scalar): |
| 140 | + return CtcInverseNotIn_Interval(f, y, with_centered_form) |
227 | 141 |
|
228 | | - def contract(self, x): |
229 | | - return self.c.contract(x) |
| 142 | + if isinstance(f, AnalyticFunction_Vector): |
| 143 | + return CtcInverseNotIn_IntervalVector(f, y, with_centered_form) |
230 | 144 |
|
231 | | - def copy(self): |
232 | | - return self.c.copy() |
| 145 | + codac_error("CtcInverseNotIn: can only build CtcInverseNotIn from scalar or vector functions") |
233 | 146 |
|
234 | 147 |
|
235 | 148 | def Approx(x, eps=sys.float_info.epsilon*10): |
|
0 commit comments