1 | >>> import numpy |
---|
2 | >>> numpy.test('full') |
---|
3 | NumPy version 1.15.0 |
---|
4 | NumPy relaxed strides checking option: True |
---|
5 | .................x......................................................................................s............................................................................................ [ 3%] |
---|
6 | ..........s.......................................................s.................................................................................................................................. [ 7%] |
---|
7 | ................................................................................sss..........................................................................................................s....... [ 11%] |
---|
8 | ...............xx.................................................................................................................................................................................... [ 15%] |
---|
9 | ..................................................................................................................................................................................................... [ 19%] |
---|
10 | ..................................................................................................................................................................................................... [ 23%] |
---|
11 | ..........................................................................................................................................................x.......................................... [ 27%] |
---|
12 | ..................................................................................................................................................................................................... [ 31%] |
---|
13 | ...............s................................s....................s............................................................................................................................... [ 35%] |
---|
14 | ...........................................................................................................................................................ss.s..s.......s........................... [ 39%] |
---|
15 | .............................................................................ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss [ 43%] |
---|
16 | sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss [ 47%] |
---|
17 | ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss....................................................................................................................... [ 51%] |
---|
18 | .........................................................................................................s........................................................................................... [ 55%] |
---|
19 | ..................................................................................................................................................................................................... [ 59%] |
---|
20 | ..................................................................................................................................................................................................... [ 63%] |
---|
21 | ...............................................................................................F...............................................x....................F................................ [ 67%] |
---|
22 | .......................................................................................................................................................s............................................. [ 71%] |
---|
23 | ..........F.F.F.....................................................................s................................................................................................................ [ 75%] |
---|
24 | .....................................................................................................................................................................s.xx............................ [ 79%] |
---|
25 | ............................................FF....................................................................................................................................................... [ 83%] |
---|
26 | ......................................................................F.....................................................F........................................................................ [ 87%] |
---|
27 | ..................................FFFFFF............................................................................................................................................................F [ 91%] |
---|
28 | ................................F................................F................................F......................................F........................................................... [ 95%] |
---|
29 | ......................................................................................................................................................................................sss............ [ 99%] |
---|
30 | ................................................ [100%] |
---|
31 | ================================================================================================= FAILURES ================================================================================================== |
---|
32 | ___________________________________________________________________________________________ TestDocs.test_polyfit ___________________________________________________________________________________________ |
---|
33 | |
---|
34 | self = <numpy.lib.tests.test_polynomial.TestDocs object at 0x10b053e48> |
---|
35 | |
---|
36 | def test_polyfit(self): |
---|
37 | c = np.array([3., 2., 1.]) |
---|
38 | x = np.linspace(0, 2, 7) |
---|
39 | y = np.polyval(c, x) |
---|
40 | err = [1, -1, 1, -1, 1, -1, 1] |
---|
41 | weights = np.arange(8, 1, -1)**2/7.0 |
---|
42 | |
---|
43 | # Check exception when too few points for variance estimate. Note that |
---|
44 | # the Bayesian estimate requires the number of data points to exceed |
---|
45 | # degree + 3. |
---|
46 | assert_raises(ValueError, np.polyfit, |
---|
47 | [0, 1, 3], [0, 1, 3], deg=0, cov=True) |
---|
48 | |
---|
49 | # check 1D case |
---|
50 | > m, cov = np.polyfit(x, y+err, 2, cov=True) |
---|
51 | |
---|
52 | c = array([3., 2., 1.]) |
---|
53 | err = [1, -1, 1, -1, 1, -1, ...] |
---|
54 | self = <numpy.lib.tests.test_polynomial.TestDocs object at 0x10b053e48> |
---|
55 | weights = array([9.14285714, 7. , 5.14285714, 3.57142857, 2.28571429, |
---|
56 | 1.28571429, 0.57142857]) |
---|
57 | x = array([0. , 0.33333333, 0.66666667, 1. , 1.33333333, |
---|
58 | 1.66666667, 2. ]) |
---|
59 | y = array([ 1. , 2. , 3.66666667, 6. , 9. , |
---|
60 | 12.66666667, 17. ]) |
---|
61 | |
---|
62 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/lib/tests/test_polynomial.py:145: |
---|
63 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
64 | |
---|
65 | x = array([0. , 0.33333333, 0.66666667, 1. , 1.33333333, |
---|
66 | 1.66666667, 2. ]) |
---|
67 | y = array([ 2. , 1. , 4.66666667, 5. , 10. , |
---|
68 | 11.66666667, 18. ]), deg = 2, rcond = 1.5543122344752192e-15, full = False, w = None, cov = True |
---|
69 | |
---|
70 | def polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False): |
---|
71 | """ |
---|
72 | Least squares polynomial fit. |
---|
73 | |
---|
74 | Fit a polynomial ``p(x) = p[0] * x**deg + ... + p[deg]`` of degree `deg` |
---|
75 | to points `(x, y)`. Returns a vector of coefficients `p` that minimises |
---|
76 | the squared error. |
---|
77 | |
---|
78 | Parameters |
---|
79 | ---------- |
---|
80 | x : array_like, shape (M,) |
---|
81 | x-coordinates of the M sample points ``(x[i], y[i])``. |
---|
82 | y : array_like, shape (M,) or (M, K) |
---|
83 | y-coordinates of the sample points. Several data sets of sample |
---|
84 | points sharing the same x-coordinates can be fitted at once by |
---|
85 | passing in a 2D-array that contains one dataset per column. |
---|
86 | deg : int |
---|
87 | Degree of the fitting polynomial |
---|
88 | rcond : float, optional |
---|
89 | Relative condition number of the fit. Singular values smaller than |
---|
90 | this relative to the largest singular value will be ignored. The |
---|
91 | default value is len(x)*eps, where eps is the relative precision of |
---|
92 | the float type, about 2e-16 in most cases. |
---|
93 | full : bool, optional |
---|
94 | Switch determining nature of return value. When it is False (the |
---|
95 | default) just the coefficients are returned, when True diagnostic |
---|
96 | information from the singular value decomposition is also returned. |
---|
97 | w : array_like, shape (M,), optional |
---|
98 | Weights to apply to the y-coordinates of the sample points. For |
---|
99 | gaussian uncertainties, use 1/sigma (not 1/sigma**2). |
---|
100 | cov : bool, optional |
---|
101 | Return the estimate and the covariance matrix of the estimate |
---|
102 | If full is True, then cov is not returned. |
---|
103 | |
---|
104 | Returns |
---|
105 | ------- |
---|
106 | p : ndarray, shape (deg + 1,) or (deg + 1, K) |
---|
107 | Polynomial coefficients, highest power first. If `y` was 2-D, the |
---|
108 | coefficients for `k`-th data set are in ``p[:,k]``. |
---|
109 | |
---|
110 | residuals, rank, singular_values, rcond |
---|
111 | Present only if `full` = True. Residuals of the least-squares fit, |
---|
112 | the effective rank of the scaled Vandermonde coefficient matrix, |
---|
113 | its singular values, and the specified value of `rcond`. For more |
---|
114 | details, see `linalg.lstsq`. |
---|
115 | |
---|
116 | V : ndarray, shape (M,M) or (M,M,K) |
---|
117 | Present only if `full` = False and `cov`=True. The covariance |
---|
118 | matrix of the polynomial coefficient estimates. The diagonal of |
---|
119 | this matrix are the variance estimates for each coefficient. If y |
---|
120 | is a 2-D array, then the covariance matrix for the `k`-th data set |
---|
121 | are in ``V[:,:,k]`` |
---|
122 | |
---|
123 | |
---|
124 | Warns |
---|
125 | ----- |
---|
126 | RankWarning |
---|
127 | The rank of the coefficient matrix in the least-squares fit is |
---|
128 | deficient. The warning is only raised if `full` = False. |
---|
129 | |
---|
130 | The warnings can be turned off by |
---|
131 | |
---|
132 | >>> import warnings |
---|
133 | >>> warnings.simplefilter('ignore', np.RankWarning) |
---|
134 | |
---|
135 | See Also |
---|
136 | -------- |
---|
137 | polyval : Compute polynomial values. |
---|
138 | linalg.lstsq : Computes a least-squares fit. |
---|
139 | scipy.interpolate.UnivariateSpline : Computes spline fits. |
---|
140 | |
---|
141 | Notes |
---|
142 | ----- |
---|
143 | The solution minimizes the squared error |
---|
144 | |
---|
145 | .. math :: |
---|
146 | E = \\sum_{j=0}^k |p(x_j) - y_j|^2 |
---|
147 | |
---|
148 | in the equations:: |
---|
149 | |
---|
150 | x[0]**n * p[0] + ... + x[0] * p[n-1] + p[n] = y[0] |
---|
151 | x[1]**n * p[0] + ... + x[1] * p[n-1] + p[n] = y[1] |
---|
152 | ... |
---|
153 | x[k]**n * p[0] + ... + x[k] * p[n-1] + p[n] = y[k] |
---|
154 | |
---|
155 | The coefficient matrix of the coefficients `p` is a Vandermonde matrix. |
---|
156 | |
---|
157 | `polyfit` issues a `RankWarning` when the least-squares fit is badly |
---|
158 | conditioned. This implies that the best fit is not well-defined due |
---|
159 | to numerical error. The results may be improved by lowering the polynomial |
---|
160 | degree or by replacing `x` by `x` - `x`.mean(). The `rcond` parameter |
---|
161 | can also be set to a value smaller than its default, but the resulting |
---|
162 | fit may be spurious: including contributions from the small singular |
---|
163 | values can add numerical noise to the result. |
---|
164 | |
---|
165 | Note that fitting polynomial coefficients is inherently badly conditioned |
---|
166 | when the degree of the polynomial is large or the interval of sample points |
---|
167 | is badly centered. The quality of the fit should always be checked in these |
---|
168 | cases. When polynomial fits are not satisfactory, splines may be a good |
---|
169 | alternative. |
---|
170 | |
---|
171 | References |
---|
172 | ---------- |
---|
173 | .. [1] Wikipedia, "Curve fitting", |
---|
174 | http://en.wikipedia.org/wiki/Curve_fitting |
---|
175 | .. [2] Wikipedia, "Polynomial interpolation", |
---|
176 | http://en.wikipedia.org/wiki/Polynomial_interpolation |
---|
177 | |
---|
178 | Examples |
---|
179 | -------- |
---|
180 | >>> x = np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0]) |
---|
181 | >>> y = np.array([0.0, 0.8, 0.9, 0.1, -0.8, -1.0]) |
---|
182 | >>> z = np.polyfit(x, y, 3) |
---|
183 | >>> z |
---|
184 | array([ 0.08703704, -0.81349206, 1.69312169, -0.03968254]) |
---|
185 | |
---|
186 | It is convenient to use `poly1d` objects for dealing with polynomials: |
---|
187 | |
---|
188 | >>> p = np.poly1d(z) |
---|
189 | >>> p(0.5) |
---|
190 | 0.6143849206349179 |
---|
191 | >>> p(3.5) |
---|
192 | -0.34732142857143039 |
---|
193 | >>> p(10) |
---|
194 | 22.579365079365115 |
---|
195 | |
---|
196 | High-order polynomials may oscillate wildly: |
---|
197 | |
---|
198 | >>> p30 = np.poly1d(np.polyfit(x, y, 30)) |
---|
199 | /... RankWarning: Polyfit may be poorly conditioned... |
---|
200 | >>> p30(4) |
---|
201 | -0.80000000000000204 |
---|
202 | >>> p30(5) |
---|
203 | -0.99999999999999445 |
---|
204 | >>> p30(4.5) |
---|
205 | -0.10547061179440398 |
---|
206 | |
---|
207 | Illustration: |
---|
208 | |
---|
209 | >>> import matplotlib.pyplot as plt |
---|
210 | >>> xp = np.linspace(-2, 6, 100) |
---|
211 | >>> _ = plt.plot(x, y, '.', xp, p(xp), '-', xp, p30(xp), '--') |
---|
212 | >>> plt.ylim(-2,2) |
---|
213 | (-2, 2) |
---|
214 | >>> plt.show() |
---|
215 | |
---|
216 | """ |
---|
217 | order = int(deg) + 1 |
---|
218 | x = NX.asarray(x) + 0.0 |
---|
219 | y = NX.asarray(y) + 0.0 |
---|
220 | |
---|
221 | # check arguments. |
---|
222 | if deg < 0: |
---|
223 | raise ValueError("expected deg >= 0") |
---|
224 | if x.ndim != 1: |
---|
225 | raise TypeError("expected 1D vector for x") |
---|
226 | if x.size == 0: |
---|
227 | raise TypeError("expected non-empty vector for x") |
---|
228 | if y.ndim < 1 or y.ndim > 2: |
---|
229 | raise TypeError("expected 1D or 2D array for y") |
---|
230 | if x.shape[0] != y.shape[0]: |
---|
231 | raise TypeError("expected x and y to have same length") |
---|
232 | |
---|
233 | # set rcond |
---|
234 | if rcond is None: |
---|
235 | rcond = len(x)*finfo(x.dtype).eps |
---|
236 | |
---|
237 | # set up least squares equation for powers of x |
---|
238 | lhs = vander(x, order) |
---|
239 | rhs = y |
---|
240 | |
---|
241 | # apply weighting |
---|
242 | if w is not None: |
---|
243 | w = NX.asarray(w) + 0.0 |
---|
244 | if w.ndim != 1: |
---|
245 | raise TypeError("expected a 1-d array for weights") |
---|
246 | if w.shape[0] != y.shape[0]: |
---|
247 | raise TypeError("expected w and y to have the same length") |
---|
248 | lhs *= w[:, NX.newaxis] |
---|
249 | if rhs.ndim == 2: |
---|
250 | rhs *= w[:, NX.newaxis] |
---|
251 | else: |
---|
252 | rhs *= w |
---|
253 | |
---|
254 | # scale lhs to improve condition number and solve |
---|
255 | scale = NX.sqrt((lhs*lhs).sum(axis=0)) |
---|
256 | lhs /= scale |
---|
257 | c, resids, rank, s = lstsq(lhs, rhs, rcond) |
---|
258 | c = (c.T/scale).T # broadcast scale coefficients |
---|
259 | |
---|
260 | # warn on rank reduction, which indicates an ill conditioned matrix |
---|
261 | if rank != order and not full: |
---|
262 | msg = "Polyfit may be poorly conditioned" |
---|
263 | warnings.warn(msg, RankWarning, stacklevel=2) |
---|
264 | |
---|
265 | if full: |
---|
266 | return c, resids, rank, s, rcond |
---|
267 | elif cov: |
---|
268 | Vbase = inv(dot(lhs.T, lhs)) |
---|
269 | Vbase /= NX.outer(scale, scale) |
---|
270 | # Some literature ignores the extra -2.0 factor in the denominator, but |
---|
271 | # it is included here because the covariance of Multivariate Student-T |
---|
272 | # (which is implied by a Bayesian uncertainty analysis) includes it. |
---|
273 | # Plus, it gives a slightly more conservative estimate of uncertainty. |
---|
274 | if len(x) <= order + 2: |
---|
275 | raise ValueError("the number of data points must exceed order + 2 " |
---|
276 | "for Bayesian estimate the covariance matrix") |
---|
277 | fac = resids / (len(x) - order - 2.0) |
---|
278 | if y.ndim == 1: |
---|
279 | > return c, Vbase * fac |
---|
280 | E ValueError: operands could not be broadcast together with shapes (3,3) (0,) |
---|
281 | |
---|
282 | Vbase = array([[ 0.96428571, -1.92857143, 0.53571429], |
---|
283 | [-1.92857143, 4.17857143, -1.39285714], |
---|
284 | [ 0.53571429, -1.39285714, 0.76190476]]) |
---|
285 | c = array([5.29966223, 3.17979734, 2.64575131]) |
---|
286 | cov = True |
---|
287 | deg = 2 |
---|
288 | fac = array([], dtype=float64) |
---|
289 | full = False |
---|
290 | lhs = array([[0. , 0. , 0.37796447], |
---|
291 | [0.0209657 , 0.10482848, 0.37796447], |
---|
292 | [0.08386279, 0.209656...15, 0.41931393, 0.37796447], |
---|
293 | [0.52414242, 0.52414242, 0.37796447], |
---|
294 | [0.75476508, 0.6289709 , 0.37796447]]) |
---|
295 | msg = 'Polyfit may be poorly conditioned' |
---|
296 | order = 3 |
---|
297 | rank = 16843008 |
---|
298 | rcond = 1.5543122344752192e-15 |
---|
299 | resids = array([], dtype=float64) |
---|
300 | rhs = array([ 2. , 1. , 4.66666667, 5. , 10. , |
---|
301 | 11.66666667, 18. ]) |
---|
302 | s = array([0., 1., 3.]) |
---|
303 | scale = array([5.29966223, 3.17979734, 2.64575131]) |
---|
304 | w = None |
---|
305 | x = array([0. , 0.33333333, 0.66666667, 1. , 1.33333333, |
---|
306 | 1.66666667, 2. ]) |
---|
307 | y = array([ 2. , 1. , 4.66666667, 5. , 10. , |
---|
308 | 11.66666667, 18. ]) |
---|
309 | |
---|
310 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/lib/polynomial.py:602: ValueError |
---|
311 | ------------------------------------------------------------------------------------------- Captured stderr call -------------------------------------------------------------------------------------------- |
---|
312 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438800384) failed (error code=3) |
---|
313 | *** error: can't allocate region |
---|
314 | *** set a breakpoint in malloc_error_break to debug |
---|
315 | init_dgelsd failed init |
---|
316 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438812672) failed (error code=3) |
---|
317 | *** error: can't allocate region |
---|
318 | *** set a breakpoint in malloc_error_break to debug |
---|
319 | init_dgelsd failed init |
---|
320 | _____________________________________________________________________________________ TestRegression.test_polyfit_build _____________________________________________________________________________________ |
---|
321 | |
---|
322 | self = <numpy.lib.tests.test_regression.TestRegression object at 0x10b3d42e8> |
---|
323 | |
---|
324 | def test_polyfit_build(self): |
---|
325 | # Ticket #628 |
---|
326 | ref = [-1.06123820e-06, 5.70886914e-04, -1.13822012e-01, |
---|
327 | 9.95368241e+00, -3.14526520e+02] |
---|
328 | x = [90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, |
---|
329 | 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, |
---|
330 | 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 129, |
---|
331 | 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, |
---|
332 | 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, |
---|
333 | 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, |
---|
334 | 170, 171, 172, 173, 174, 175, 176] |
---|
335 | y = [9.0, 3.0, 7.0, 4.0, 4.0, 8.0, 6.0, 11.0, 9.0, 8.0, 11.0, 5.0, |
---|
336 | 6.0, 5.0, 9.0, 8.0, 6.0, 10.0, 6.0, 10.0, 7.0, 6.0, 6.0, 6.0, |
---|
337 | 13.0, 4.0, 9.0, 11.0, 4.0, 5.0, 8.0, 5.0, 7.0, 7.0, 6.0, 12.0, |
---|
338 | 7.0, 7.0, 9.0, 4.0, 12.0, 6.0, 6.0, 4.0, 3.0, 9.0, 8.0, 8.0, |
---|
339 | 6.0, 7.0, 9.0, 10.0, 6.0, 8.0, 4.0, 7.0, 7.0, 10.0, 8.0, 8.0, |
---|
340 | 6.0, 3.0, 8.0, 4.0, 5.0, 7.0, 8.0, 6.0, 6.0, 4.0, 12.0, 9.0, |
---|
341 | 8.0, 8.0, 8.0, 6.0, 7.0, 4.0, 4.0, 5.0, 7.0] |
---|
342 | tested = np.polyfit(x, y, 4) |
---|
343 | > assert_array_almost_equal(ref, tested) |
---|
344 | E AssertionError: |
---|
345 | E Arrays are not almost equal to 6 decimals |
---|
346 | E |
---|
347 | E (mismatch 100.0%) |
---|
348 | E x: array([-1.061238e-06, 5.708869e-04, -1.138220e-01, 9.953682e+00, |
---|
349 | E -3.145265e+02]) |
---|
350 | E y: array([4.191277e+09, 2.668547e+07, 1.757346e+05, 1.216110e+03, |
---|
351 | E 9.000000e+00]) |
---|
352 | |
---|
353 | ref = [-1.0612382e-06, 0.000570886914, -0.113822012, 9.95368241, -314.52652] |
---|
354 | self = <numpy.lib.tests.test_regression.TestRegression object at 0x10b3d42e8> |
---|
355 | tested = array([4.19127652e+09, 2.66854699e+07, 1.75734565e+05, 1.21611019e+03, |
---|
356 | 9.00000000e+00]) |
---|
357 | x = [90, 91, 92, 93, 94, 95, ...] |
---|
358 | y = [9.0, 3.0, 7.0, 4.0, 4.0, 8.0, ...] |
---|
359 | |
---|
360 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/lib/tests/test_regression.py:104: AssertionError |
---|
361 | ------------------------------------------------------------------------------------------- Captured stderr call -------------------------------------------------------------------------------------------- |
---|
362 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438812672) failed (error code=3) |
---|
363 | *** error: can't allocate region |
---|
364 | *** set a breakpoint in malloc_error_break to debug |
---|
365 | init_dgelsd failed init |
---|
366 | __________________________________________________________________________________________ TestLstsq.test_sq_cases __________________________________________________________________________________________ |
---|
367 | |
---|
368 | self = <numpy.linalg.tests.test_linalg.TestLstsq object at 0x10b066208>, require = {'square'}, exclude = {'generalized', 'size-0'} |
---|
369 | |
---|
370 | def check_cases(self, require=set(), exclude=set()): |
---|
371 | """ |
---|
372 | Run func on each of the cases with all of the tags in require, and none |
---|
373 | of the tags in exclude |
---|
374 | """ |
---|
375 | for case in self.TEST_CASES: |
---|
376 | # filter by require and exclude |
---|
377 | if case.tags & require != require: |
---|
378 | continue |
---|
379 | if case.tags & exclude: |
---|
380 | continue |
---|
381 | |
---|
382 | try: |
---|
383 | > case.check(self.do) |
---|
384 | |
---|
385 | case = <LinalgCase: single> |
---|
386 | exclude = {'generalized', 'size-0'} |
---|
387 | msg = 'In test case: <LinalgCase: single>\n\nTraceback (most recent call last):\n File "/opt/local/Library/Frameworks/Pytho...ost equal to 6 decimals\n\n(mismatch 100.0%)\n x: array([2., 1.], dtype=float32)\n y: array([0., 0.], dtype=float32)\n' |
---|
388 | require = {'square'} |
---|
389 | self = <numpy.linalg.tests.test_linalg.TestLstsq object at 0x10b066208> |
---|
390 | |
---|
391 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py:350: |
---|
392 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
393 | |
---|
394 | self = <LinalgCase: single>, do = <bound method LstsqCases.do of <numpy.linalg.tests.test_linalg.TestLstsq object at 0x10b066208>> |
---|
395 | |
---|
396 | def check(self, do): |
---|
397 | """ |
---|
398 | Run the function `do` on this test case, expanding arguments |
---|
399 | """ |
---|
400 | > do(self.a, self.b, tags=self.tags) |
---|
401 | |
---|
402 | do = <bound method LstsqCases.do of <numpy.linalg.tests.test_linalg.TestLstsq object at 0x10b066208>> |
---|
403 | self = <LinalgCase: single> |
---|
404 | |
---|
405 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py:85: |
---|
406 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
407 | |
---|
408 | self = <numpy.linalg.tests.test_linalg.TestLstsq object at 0x10b066208>, a = array([[1., 2.], |
---|
409 | [3., 4.]], dtype=float32), b = array([2., 1.], dtype=float32), tags = frozenset({'square'}) |
---|
410 | |
---|
411 | def do(self, a, b, tags): |
---|
412 | if 'size-0' in tags: |
---|
413 | assert_raises(LinAlgError, linalg.lstsq, a, b) |
---|
414 | return |
---|
415 | |
---|
416 | arr = np.asarray(a) |
---|
417 | m, n = arr.shape |
---|
418 | u, s, vt = linalg.svd(a, 0) |
---|
419 | x, residuals, rank, sv = linalg.lstsq(a, b, rcond=-1) |
---|
420 | if m <= n: |
---|
421 | > assert_almost_equal(b, dot(a, x)) |
---|
422 | |
---|
423 | a = array([[1., 2.], |
---|
424 | [3., 4.]], dtype=float32) |
---|
425 | arr = array([[1., 2.], |
---|
426 | [3., 4.]], dtype=float32) |
---|
427 | b = array([2., 1.], dtype=float32) |
---|
428 | m = 2 |
---|
429 | n = 2 |
---|
430 | rank = 0 |
---|
431 | residuals = array([], dtype=float32) |
---|
432 | s = array([5.464986 , 0.3659662], dtype=float32) |
---|
433 | self = <numpy.linalg.tests.test_linalg.TestLstsq object at 0x10b066208> |
---|
434 | sv = array([0., 0.], dtype=float32) |
---|
435 | tags = frozenset({'square'}) |
---|
436 | u = array([[-0.4045536, -0.9145143], |
---|
437 | [-0.9145143, 0.4045536]], dtype=float32) |
---|
438 | vt = array([[-0.57604843, -0.81741554], |
---|
439 | [ 0.81741554, -0.57604843]], dtype=float32) |
---|
440 | x = array([0., 0.], dtype=float32) |
---|
441 | |
---|
442 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py:887: |
---|
443 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
444 | |
---|
445 | a = array([2., 1.], dtype=float32), b = array([0., 0.], dtype=float32), single_decimal = 6, double_decimal = 12, kw = {}, decimal = 6 |
---|
446 | |
---|
447 | def assert_almost_equal(a, b, single_decimal=6, double_decimal=12, **kw): |
---|
448 | if asarray(a).dtype.type in (single, csingle): |
---|
449 | decimal = single_decimal |
---|
450 | else: |
---|
451 | decimal = double_decimal |
---|
452 | > old_assert_almost_equal(a, b, decimal=decimal, **kw) |
---|
453 | |
---|
454 | a = array([2., 1.], dtype=float32) |
---|
455 | b = array([0., 0.], dtype=float32) |
---|
456 | decimal = 6 |
---|
457 | double_decimal = 12 |
---|
458 | kw = {} |
---|
459 | single_decimal = 6 |
---|
460 | |
---|
461 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py:41: |
---|
462 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
463 | |
---|
464 | actual = array([2., 1.], dtype=float32), desired = array([0., 0.], dtype=float32), decimal = 6, err_msg = '', verbose = True |
---|
465 | |
---|
466 | def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): |
---|
467 | """ |
---|
468 | Raises an AssertionError if two items are not equal up to desired |
---|
469 | precision. |
---|
470 | |
---|
471 | .. note:: It is recommended to use one of `assert_allclose`, |
---|
472 | `assert_array_almost_equal_nulp` or `assert_array_max_ulp` |
---|
473 | instead of this function for more consistent floating point |
---|
474 | comparisons. |
---|
475 | |
---|
476 | The test verifies that the elements of ``actual`` and ``desired`` satisfy. |
---|
477 | |
---|
478 | ``abs(desired-actual) < 1.5 * 10**(-decimal)`` |
---|
479 | |
---|
480 | That is a looser test than originally documented, but agrees with what the |
---|
481 | actual implementation in `assert_array_almost_equal` did up to rounding |
---|
482 | vagaries. An exception is raised at conflicting values. For ndarrays this |
---|
483 | delegates to assert_array_almost_equal |
---|
484 | |
---|
485 | Parameters |
---|
486 | ---------- |
---|
487 | actual : array_like |
---|
488 | The object to check. |
---|
489 | desired : array_like |
---|
490 | The expected object. |
---|
491 | decimal : int, optional |
---|
492 | Desired precision, default is 7. |
---|
493 | err_msg : str, optional |
---|
494 | The error message to be printed in case of failure. |
---|
495 | verbose : bool, optional |
---|
496 | If True, the conflicting values are appended to the error message. |
---|
497 | |
---|
498 | Raises |
---|
499 | ------ |
---|
500 | AssertionError |
---|
501 | If actual and desired are not equal up to specified precision. |
---|
502 | |
---|
503 | See Also |
---|
504 | -------- |
---|
505 | assert_allclose: Compare two array_like objects for equality with desired |
---|
506 | relative and/or absolute precision. |
---|
507 | assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal |
---|
508 | |
---|
509 | Examples |
---|
510 | -------- |
---|
511 | >>> import numpy.testing as npt |
---|
512 | >>> npt.assert_almost_equal(2.3333333333333, 2.33333334) |
---|
513 | >>> npt.assert_almost_equal(2.3333333333333, 2.33333334, decimal=10) |
---|
514 | ... |
---|
515 | <type 'exceptions.AssertionError'>: |
---|
516 | Items are not equal: |
---|
517 | ACTUAL: 2.3333333333333002 |
---|
518 | DESIRED: 2.3333333399999998 |
---|
519 | |
---|
520 | >>> npt.assert_almost_equal(np.array([1.0,2.3333333333333]), |
---|
521 | ... np.array([1.0,2.33333334]), decimal=9) |
---|
522 | ... |
---|
523 | <type 'exceptions.AssertionError'>: |
---|
524 | Arrays are not almost equal |
---|
525 | <BLANKLINE> |
---|
526 | (mismatch 50.0%) |
---|
527 | x: array([ 1. , 2.33333333]) |
---|
528 | y: array([ 1. , 2.33333334]) |
---|
529 | |
---|
530 | """ |
---|
531 | __tracebackhide__ = True # Hide traceback for py.test |
---|
532 | from numpy.core import ndarray |
---|
533 | from numpy.lib import iscomplexobj, real, imag |
---|
534 | |
---|
535 | # Handle complex numbers: separate into real/imag to handle |
---|
536 | # nan/inf/negative zero correctly |
---|
537 | # XXX: catch ValueError for subclasses of ndarray where iscomplex fail |
---|
538 | try: |
---|
539 | usecomplex = iscomplexobj(actual) or iscomplexobj(desired) |
---|
540 | except ValueError: |
---|
541 | usecomplex = False |
---|
542 | |
---|
543 | def _build_err_msg(): |
---|
544 | header = ('Arrays are not almost equal to %d decimals' % decimal) |
---|
545 | return build_err_msg([actual, desired], err_msg, verbose=verbose, |
---|
546 | header=header) |
---|
547 | |
---|
548 | if usecomplex: |
---|
549 | if iscomplexobj(actual): |
---|
550 | actualr = real(actual) |
---|
551 | actuali = imag(actual) |
---|
552 | else: |
---|
553 | actualr = actual |
---|
554 | actuali = 0 |
---|
555 | if iscomplexobj(desired): |
---|
556 | desiredr = real(desired) |
---|
557 | desiredi = imag(desired) |
---|
558 | else: |
---|
559 | desiredr = desired |
---|
560 | desiredi = 0 |
---|
561 | try: |
---|
562 | assert_almost_equal(actualr, desiredr, decimal=decimal) |
---|
563 | assert_almost_equal(actuali, desiredi, decimal=decimal) |
---|
564 | except AssertionError: |
---|
565 | raise AssertionError(_build_err_msg()) |
---|
566 | |
---|
567 | if isinstance(actual, (ndarray, tuple, list)) \ |
---|
568 | or isinstance(desired, (ndarray, tuple, list)): |
---|
569 | > return assert_array_almost_equal(actual, desired, decimal, err_msg) |
---|
570 | |
---|
571 | __tracebackhide__ = True |
---|
572 | _build_err_msg = <function assert_almost_equal.<locals>._build_err_msg at 0x10c1f49d8> |
---|
573 | actual = array([2., 1.], dtype=float32) |
---|
574 | decimal = 6 |
---|
575 | desired = array([0., 0.], dtype=float32) |
---|
576 | err_msg = '' |
---|
577 | imag = <function imag at 0x103d8f620> |
---|
578 | iscomplexobj = <function iscomplexobj at 0x103d8f7b8> |
---|
579 | ndarray = <class 'numpy.ndarray'> |
---|
580 | real = <function real at 0x103d8f598> |
---|
581 | usecomplex = False |
---|
582 | verbose = True |
---|
583 | |
---|
584 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/testing/_private/utils.py:568: |
---|
585 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
586 | |
---|
587 | x = array([2., 1.], dtype=float32), y = array([0., 0.], dtype=float32), decimal = 6, err_msg = '', verbose = True |
---|
588 | |
---|
589 | def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True): |
---|
590 | """ |
---|
591 | Raises an AssertionError if two objects are not equal up to desired |
---|
592 | precision. |
---|
593 | |
---|
594 | .. note:: It is recommended to use one of `assert_allclose`, |
---|
595 | `assert_array_almost_equal_nulp` or `assert_array_max_ulp` |
---|
596 | instead of this function for more consistent floating point |
---|
597 | comparisons. |
---|
598 | |
---|
599 | The test verifies identical shapes and that the elements of ``actual`` and |
---|
600 | ``desired`` satisfy. |
---|
601 | |
---|
602 | ``abs(desired-actual) < 1.5 * 10**(-decimal)`` |
---|
603 | |
---|
604 | That is a looser test than originally documented, but agrees with what the |
---|
605 | actual implementation did up to rounding vagaries. An exception is raised |
---|
606 | at shape mismatch or conflicting values. In contrast to the standard usage |
---|
607 | in numpy, NaNs are compared like numbers, no assertion is raised if both |
---|
608 | objects have NaNs in the same positions. |
---|
609 | |
---|
610 | Parameters |
---|
611 | ---------- |
---|
612 | x : array_like |
---|
613 | The actual object to check. |
---|
614 | y : array_like |
---|
615 | The desired, expected object. |
---|
616 | decimal : int, optional |
---|
617 | Desired precision, default is 6. |
---|
618 | err_msg : str, optional |
---|
619 | The error message to be printed in case of failure. |
---|
620 | verbose : bool, optional |
---|
621 | If True, the conflicting values are appended to the error message. |
---|
622 | |
---|
623 | Raises |
---|
624 | ------ |
---|
625 | AssertionError |
---|
626 | If actual and desired are not equal up to specified precision. |
---|
627 | |
---|
628 | See Also |
---|
629 | -------- |
---|
630 | assert_allclose: Compare two array_like objects for equality with desired |
---|
631 | relative and/or absolute precision. |
---|
632 | assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal |
---|
633 | |
---|
634 | Examples |
---|
635 | -------- |
---|
636 | the first assert does not raise an exception |
---|
637 | |
---|
638 | >>> np.testing.assert_array_almost_equal([1.0,2.333,np.nan], |
---|
639 | [1.0,2.333,np.nan]) |
---|
640 | |
---|
641 | >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], |
---|
642 | ... [1.0,2.33339,np.nan], decimal=5) |
---|
643 | ... |
---|
644 | <type 'exceptions.AssertionError'>: |
---|
645 | AssertionError: |
---|
646 | Arrays are not almost equal |
---|
647 | <BLANKLINE> |
---|
648 | (mismatch 50.0%) |
---|
649 | x: array([ 1. , 2.33333, NaN]) |
---|
650 | y: array([ 1. , 2.33339, NaN]) |
---|
651 | |
---|
652 | >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], |
---|
653 | ... [1.0,2.33333, 5], decimal=5) |
---|
654 | <type 'exceptions.ValueError'>: |
---|
655 | ValueError: |
---|
656 | Arrays are not almost equal |
---|
657 | x: array([ 1. , 2.33333, NaN]) |
---|
658 | y: array([ 1. , 2.33333, 5. ]) |
---|
659 | |
---|
660 | """ |
---|
661 | __tracebackhide__ = True # Hide traceback for py.test |
---|
662 | from numpy.core import around, number, float_, result_type, array |
---|
663 | from numpy.core.numerictypes import issubdtype |
---|
664 | from numpy.core.fromnumeric import any as npany |
---|
665 | |
---|
666 | def compare(x, y): |
---|
667 | try: |
---|
668 | if npany(gisinf(x)) or npany( gisinf(y)): |
---|
669 | xinfid = gisinf(x) |
---|
670 | yinfid = gisinf(y) |
---|
671 | if not (xinfid == yinfid).all(): |
---|
672 | return False |
---|
673 | # if one item, x and y is +- inf |
---|
674 | if x.size == y.size == 1: |
---|
675 | return x == y |
---|
676 | x = x[~xinfid] |
---|
677 | y = y[~yinfid] |
---|
678 | except (TypeError, NotImplementedError): |
---|
679 | pass |
---|
680 | |
---|
681 | # make sure y is an inexact type to avoid abs(MIN_INT); will cause |
---|
682 | # casting of x later. |
---|
683 | dtype = result_type(y, 1.) |
---|
684 | y = array(y, dtype=dtype, copy=False, subok=True) |
---|
685 | z = abs(x - y) |
---|
686 | |
---|
687 | if not issubdtype(z.dtype, number): |
---|
688 | z = z.astype(float_) # handle object arrays |
---|
689 | |
---|
690 | return z < 1.5 * 10.0**(-decimal) |
---|
691 | |
---|
692 | assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose, |
---|
693 | header=('Arrays are not almost equal to %d decimals' % decimal), |
---|
694 | > precision=decimal) |
---|
695 | |
---|
696 | __tracebackhide__ = True |
---|
697 | around = <function around at 0x10385c8c8> |
---|
698 | array = <built-in function array> |
---|
699 | compare = <function assert_array_almost_equal.<locals>.compare at 0x10c1f4730> |
---|
700 | decimal = 6 |
---|
701 | err_msg = '' |
---|
702 | float_ = <class 'numpy.float64'> |
---|
703 | issubdtype = <function issubdtype at 0x10371cae8> |
---|
704 | npany = <function any at 0x10385c2f0> |
---|
705 | number = <class 'numpy.number'> |
---|
706 | result_type = <built-in function result_type> |
---|
707 | verbose = True |
---|
708 | x = array([2., 1.], dtype=float32) |
---|
709 | y = array([0., 0.], dtype=float32) |
---|
710 | |
---|
711 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/testing/_private/utils.py:964: |
---|
712 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
713 | |
---|
714 | comparison = <function assert_array_almost_equal.<locals>.compare at 0x10c1f4730>, x = array([2., 1.], dtype=float32), y = array([0., 0.], dtype=float32), err_msg = '', verbose = True |
---|
715 | header = 'Arrays are not almost equal to 6 decimals', precision = 6, equal_nan = True, equal_inf = True |
---|
716 | |
---|
717 | def assert_array_compare(comparison, x, y, err_msg='', verbose=True, |
---|
718 | header='', precision=6, equal_nan=True, |
---|
719 | equal_inf=True): |
---|
720 | __tracebackhide__ = True # Hide traceback for py.test |
---|
721 | from numpy.core import array, isnan, inf, bool_ |
---|
722 | x = array(x, copy=False, subok=True) |
---|
723 | y = array(y, copy=False, subok=True) |
---|
724 | |
---|
725 | def isnumber(x): |
---|
726 | return x.dtype.char in '?bhilqpBHILQPefdgFDG' |
---|
727 | |
---|
728 | def istime(x): |
---|
729 | return x.dtype.char in "Mm" |
---|
730 | |
---|
731 | def func_assert_same_pos(x, y, func=isnan, hasval='nan'): |
---|
732 | """Handling nan/inf: combine results of running func on x and y, |
---|
733 | checking that they are True at the same locations.""" |
---|
734 | # Both the != True comparison here and the cast to bool_ at |
---|
735 | # the end are done to deal with `masked`, which cannot be |
---|
736 | # compared usefully, and for which .all() yields masked. |
---|
737 | x_id = func(x) |
---|
738 | y_id = func(y) |
---|
739 | if (x_id == y_id).all() != True: |
---|
740 | msg = build_err_msg([x, y], |
---|
741 | err_msg + '\nx and y %s location mismatch:' |
---|
742 | % (hasval), verbose=verbose, header=header, |
---|
743 | names=('x', 'y'), precision=precision) |
---|
744 | raise AssertionError(msg) |
---|
745 | # If there is a scalar, then here we know the array has the same |
---|
746 | # flag as it everywhere, so we should return the scalar flag. |
---|
747 | if x_id.ndim == 0: |
---|
748 | return bool_(x_id) |
---|
749 | elif y_id.ndim == 0: |
---|
750 | return bool_(y_id) |
---|
751 | else: |
---|
752 | return y_id |
---|
753 | |
---|
754 | try: |
---|
755 | cond = (x.shape == () or y.shape == ()) or x.shape == y.shape |
---|
756 | if not cond: |
---|
757 | msg = build_err_msg([x, y], |
---|
758 | err_msg |
---|
759 | + '\n(shapes %s, %s mismatch)' % (x.shape, |
---|
760 | y.shape), |
---|
761 | verbose=verbose, header=header, |
---|
762 | names=('x', 'y'), precision=precision) |
---|
763 | raise AssertionError(msg) |
---|
764 | |
---|
765 | flagged = bool_(False) |
---|
766 | if isnumber(x) and isnumber(y): |
---|
767 | if equal_nan: |
---|
768 | flagged = func_assert_same_pos(x, y, func=isnan, hasval='nan') |
---|
769 | |
---|
770 | if equal_inf: |
---|
771 | flagged |= func_assert_same_pos(x, y, |
---|
772 | func=lambda xy: xy == +inf, |
---|
773 | hasval='+inf') |
---|
774 | flagged |= func_assert_same_pos(x, y, |
---|
775 | func=lambda xy: xy == -inf, |
---|
776 | hasval='-inf') |
---|
777 | |
---|
778 | elif istime(x) and istime(y): |
---|
779 | # If one is datetime64 and the other timedelta64 there is no point |
---|
780 | if equal_nan and x.dtype.type == y.dtype.type: |
---|
781 | flagged = func_assert_same_pos(x, y, func=isnat, hasval="NaT") |
---|
782 | |
---|
783 | if flagged.ndim > 0: |
---|
784 | x, y = x[~flagged], y[~flagged] |
---|
785 | # Only do the comparison if actual values are left |
---|
786 | if x.size == 0: |
---|
787 | return |
---|
788 | elif flagged: |
---|
789 | # no sense doing comparison if everything is flagged. |
---|
790 | return |
---|
791 | |
---|
792 | val = comparison(x, y) |
---|
793 | |
---|
794 | if isinstance(val, bool): |
---|
795 | cond = val |
---|
796 | reduced = [0] |
---|
797 | else: |
---|
798 | reduced = val.ravel() |
---|
799 | cond = reduced.all() |
---|
800 | reduced = reduced.tolist() |
---|
801 | # The below comparison is a hack to ensure that fully masked |
---|
802 | # results, for which val.ravel().all() returns np.ma.masked, |
---|
803 | # do not trigger a failure (np.ma.masked != True evaluates as |
---|
804 | # np.ma.masked, which is falsy). |
---|
805 | if cond != True: |
---|
806 | match = 100-100.0*reduced.count(1)/len(reduced) |
---|
807 | msg = build_err_msg([x, y], |
---|
808 | err_msg |
---|
809 | + '\n(mismatch %s%%)' % (match,), |
---|
810 | verbose=verbose, header=header, |
---|
811 | names=('x', 'y'), precision=precision) |
---|
812 | > raise AssertionError(msg) |
---|
813 | E AssertionError: |
---|
814 | E Arrays are not almost equal to 6 decimals |
---|
815 | E |
---|
816 | E (mismatch 100.0%) |
---|
817 | E x: array([2., 1.], dtype=float32) |
---|
818 | E y: array([0., 0.], dtype=float32) |
---|
819 | |
---|
820 | __tracebackhide__ = True |
---|
821 | array = <built-in function array> |
---|
822 | bool_ = <class 'numpy.bool_'> |
---|
823 | comparison = <function assert_array_almost_equal.<locals>.compare at 0x10c1f4730> |
---|
824 | cond = False |
---|
825 | equal_inf = True |
---|
826 | equal_nan = True |
---|
827 | err_msg = '' |
---|
828 | flagged = array([False, False]) |
---|
829 | func_assert_same_pos = <function assert_array_compare.<locals>.func_assert_same_pos at 0x10c1f4a60> |
---|
830 | header = 'Arrays are not almost equal to 6 decimals' |
---|
831 | inf = inf |
---|
832 | isnan = <ufunc 'isnan'> |
---|
833 | isnumber = <function assert_array_compare.<locals>.isnumber at 0x10c1f46a8> |
---|
834 | istime = <function assert_array_compare.<locals>.istime at 0x10c1f4840> |
---|
835 | match = 100.0 |
---|
836 | msg = '\nArrays are not almost equal to 6 decimals\n\n(mismatch 100.0%)\n x: array([2., 1.], dtype=float32)\n y: array([0., 0.], dtype=float32)' |
---|
837 | precision = 6 |
---|
838 | reduced = [False, False] |
---|
839 | val = array([False, False]) |
---|
840 | verbose = True |
---|
841 | x = array([2., 1.], dtype=float32) |
---|
842 | y = array([0., 0.], dtype=float32) |
---|
843 | |
---|
844 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/testing/_private/utils.py:780: AssertionError |
---|
845 | |
---|
846 | During handling of the above exception, another exception occurred: |
---|
847 | |
---|
848 | self = <numpy.linalg.tests.test_linalg.TestLstsq object at 0x10b066208> |
---|
849 | |
---|
850 | def test_sq_cases(self): |
---|
851 | self.check_cases(require={'square'}, |
---|
852 | > exclude={'generalized', 'size-0'}) |
---|
853 | |
---|
854 | self = <numpy.linalg.tests.test_linalg.TestLstsq object at 0x10b066208> |
---|
855 | |
---|
856 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py:361: |
---|
857 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
858 | |
---|
859 | self = <numpy.linalg.tests.test_linalg.TestLstsq object at 0x10b066208>, require = {'square'}, exclude = {'generalized', 'size-0'} |
---|
860 | |
---|
861 | def check_cases(self, require=set(), exclude=set()): |
---|
862 | """ |
---|
863 | Run func on each of the cases with all of the tags in require, and none |
---|
864 | of the tags in exclude |
---|
865 | """ |
---|
866 | for case in self.TEST_CASES: |
---|
867 | # filter by require and exclude |
---|
868 | if case.tags & require != require: |
---|
869 | continue |
---|
870 | if case.tags & exclude: |
---|
871 | continue |
---|
872 | |
---|
873 | try: |
---|
874 | case.check(self.do) |
---|
875 | except Exception: |
---|
876 | msg = "In test case: %r\n\n" % case |
---|
877 | msg += traceback.format_exc() |
---|
878 | > raise AssertionError(msg) |
---|
879 | E AssertionError: In test case: <LinalgCase: single> |
---|
880 | E |
---|
881 | E Traceback (most recent call last): |
---|
882 | E File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py", line 350, in check_cases |
---|
883 | E case.check(self.do) |
---|
884 | E File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py", line 85, in check |
---|
885 | E do(self.a, self.b, tags=self.tags) |
---|
886 | E File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py", line 887, in do |
---|
887 | E assert_almost_equal(b, dot(a, x)) |
---|
888 | E File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py", line 41, in assert_almost_equal |
---|
889 | E old_assert_almost_equal(a, b, decimal=decimal, **kw) |
---|
890 | E File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/testing/_private/utils.py", line 568, in assert_almost_equal |
---|
891 | E return assert_array_almost_equal(actual, desired, decimal, err_msg) |
---|
892 | E File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/testing/_private/utils.py", line 964, in assert_array_almost_equal |
---|
893 | E precision=decimal) |
---|
894 | E File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/testing/_private/utils.py", line 780, in assert_array_compare |
---|
895 | E raise AssertionError(msg) |
---|
896 | E AssertionError: |
---|
897 | E Arrays are not almost equal to 6 decimals |
---|
898 | E |
---|
899 | E (mismatch 100.0%) |
---|
900 | E x: array([2., 1.], dtype=float32) |
---|
901 | E y: array([0., 0.], dtype=float32) |
---|
902 | |
---|
903 | case = <LinalgCase: single> |
---|
904 | exclude = {'generalized', 'size-0'} |
---|
905 | msg = 'In test case: <LinalgCase: single>\n\nTraceback (most recent call last):\n File "/opt/local/Library/Frameworks/Pytho...ost equal to 6 decimals\n\n(mismatch 100.0%)\n x: array([2., 1.], dtype=float32)\n y: array([0., 0.], dtype=float32)\n' |
---|
906 | require = {'square'} |
---|
907 | self = <numpy.linalg.tests.test_linalg.TestLstsq object at 0x10b066208> |
---|
908 | |
---|
909 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py:354: AssertionError |
---|
910 | ------------------------------------------------------------------------------------------- Captured stderr call -------------------------------------------------------------------------------------------- |
---|
911 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438804480) failed (error code=3) |
---|
912 | *** error: can't allocate region |
---|
913 | *** set a breakpoint in malloc_error_break to debug |
---|
914 | init_dgelsd failed init |
---|
915 | ________________________________________________________________________________________ TestLstsq.test_nonsq_cases _________________________________________________________________________________________ |
---|
916 | |
---|
917 | self = <numpy.linalg.tests.test_linalg.TestLstsq object at 0x10e52f470>, require = {'nonsquare'}, exclude = {'generalized', 'size-0'} |
---|
918 | |
---|
919 | def check_cases(self, require=set(), exclude=set()): |
---|
920 | """ |
---|
921 | Run func on each of the cases with all of the tags in require, and none |
---|
922 | of the tags in exclude |
---|
923 | """ |
---|
924 | for case in self.TEST_CASES: |
---|
925 | # filter by require and exclude |
---|
926 | if case.tags & require != require: |
---|
927 | continue |
---|
928 | if case.tags & exclude: |
---|
929 | continue |
---|
930 | |
---|
931 | try: |
---|
932 | > case.check(self.do) |
---|
933 | |
---|
934 | case = <LinalgCase: single_nsq_1> |
---|
935 | exclude = {'generalized', 'size-0'} |
---|
936 | msg = 'In test case: <LinalgCase: single_nsq_1>\n\nTraceback (most recent call last):\n File "/opt/local/Library/Frameworks...t equal to 6 decimals\n\n(mismatch 100.0%)\n x: array([2., 1.], dtype=float32)\n y: array([ 6., 13.], dtype=float32)\n' |
---|
937 | require = {'nonsquare'} |
---|
938 | self = <numpy.linalg.tests.test_linalg.TestLstsq object at 0x10e52f470> |
---|
939 | |
---|
940 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py:350: |
---|
941 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
942 | |
---|
943 | self = <LinalgCase: single_nsq_1>, do = <bound method LstsqCases.do of <numpy.linalg.tests.test_linalg.TestLstsq object at 0x10e52f470>> |
---|
944 | |
---|
945 | def check(self, do): |
---|
946 | """ |
---|
947 | Run the function `do` on this test case, expanding arguments |
---|
948 | """ |
---|
949 | > do(self.a, self.b, tags=self.tags) |
---|
950 | |
---|
951 | do = <bound method LstsqCases.do of <numpy.linalg.tests.test_linalg.TestLstsq object at 0x10e52f470>> |
---|
952 | self = <LinalgCase: single_nsq_1> |
---|
953 | |
---|
954 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py:85: |
---|
955 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
956 | |
---|
957 | self = <numpy.linalg.tests.test_linalg.TestLstsq object at 0x10e52f470>, a = array([[1., 2., 3.], |
---|
958 | [3., 4., 6.]], dtype=float32), b = array([2., 1.], dtype=float32), tags = frozenset({'nonsquare'}) |
---|
959 | |
---|
960 | def do(self, a, b, tags): |
---|
961 | if 'size-0' in tags: |
---|
962 | assert_raises(LinAlgError, linalg.lstsq, a, b) |
---|
963 | return |
---|
964 | |
---|
965 | arr = np.asarray(a) |
---|
966 | m, n = arr.shape |
---|
967 | u, s, vt = linalg.svd(a, 0) |
---|
968 | x, residuals, rank, sv = linalg.lstsq(a, b, rcond=-1) |
---|
969 | if m <= n: |
---|
970 | > assert_almost_equal(b, dot(a, x)) |
---|
971 | |
---|
972 | a = array([[1., 2., 3.], |
---|
973 | [3., 4., 6.]], dtype=float32) |
---|
974 | arr = array([[1., 2., 3.], |
---|
975 | [3., 4., 6.]], dtype=float32) |
---|
976 | b = array([2., 1.], dtype=float32) |
---|
977 | m = 2 |
---|
978 | n = 3 |
---|
979 | rank = 0 |
---|
980 | residuals = array([], dtype=float32) |
---|
981 | s = array([8.650218 , 0.41681626], dtype=float32) |
---|
982 | self = <numpy.linalg.tests.test_linalg.TestLstsq object at 0x10e52f470> |
---|
983 | sv = array([-1.0533684e-03, -7.4266063e-05], dtype=float32) |
---|
984 | tags = frozenset({'nonsquare'}) |
---|
985 | u = array([[-0.4303583 , -0.90265816], |
---|
986 | [-0.90265816, 0.4303583 ]], dtype=float32) |
---|
987 | vt = array([[-0.3628039 , -0.51690596, -0.775359 ], |
---|
988 | [ 0.9318655 , -0.2012474 , -0.3018711 ]], dtype=float32) |
---|
989 | x = array([1., 1., 1.], dtype=float32) |
---|
990 | |
---|
991 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py:887: |
---|
992 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
993 | |
---|
994 | a = array([2., 1.], dtype=float32), b = array([ 6., 13.], dtype=float32), single_decimal = 6, double_decimal = 12, kw = {}, decimal = 6 |
---|
995 | |
---|
996 | def assert_almost_equal(a, b, single_decimal=6, double_decimal=12, **kw): |
---|
997 | if asarray(a).dtype.type in (single, csingle): |
---|
998 | decimal = single_decimal |
---|
999 | else: |
---|
1000 | decimal = double_decimal |
---|
1001 | > old_assert_almost_equal(a, b, decimal=decimal, **kw) |
---|
1002 | |
---|
1003 | a = array([2., 1.], dtype=float32) |
---|
1004 | b = array([ 6., 13.], dtype=float32) |
---|
1005 | decimal = 6 |
---|
1006 | double_decimal = 12 |
---|
1007 | kw = {} |
---|
1008 | single_decimal = 6 |
---|
1009 | |
---|
1010 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py:41: |
---|
1011 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
1012 | |
---|
1013 | actual = array([2., 1.], dtype=float32), desired = array([ 6., 13.], dtype=float32), decimal = 6, err_msg = '', verbose = True |
---|
1014 | |
---|
1015 | def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): |
---|
1016 | """ |
---|
1017 | Raises an AssertionError if two items are not equal up to desired |
---|
1018 | precision. |
---|
1019 | |
---|
1020 | .. note:: It is recommended to use one of `assert_allclose`, |
---|
1021 | `assert_array_almost_equal_nulp` or `assert_array_max_ulp` |
---|
1022 | instead of this function for more consistent floating point |
---|
1023 | comparisons. |
---|
1024 | |
---|
1025 | The test verifies that the elements of ``actual`` and ``desired`` satisfy. |
---|
1026 | |
---|
1027 | ``abs(desired-actual) < 1.5 * 10**(-decimal)`` |
---|
1028 | |
---|
1029 | That is a looser test than originally documented, but agrees with what the |
---|
1030 | actual implementation in `assert_array_almost_equal` did up to rounding |
---|
1031 | vagaries. An exception is raised at conflicting values. For ndarrays this |
---|
1032 | delegates to assert_array_almost_equal |
---|
1033 | |
---|
1034 | Parameters |
---|
1035 | ---------- |
---|
1036 | actual : array_like |
---|
1037 | The object to check. |
---|
1038 | desired : array_like |
---|
1039 | The expected object. |
---|
1040 | decimal : int, optional |
---|
1041 | Desired precision, default is 7. |
---|
1042 | err_msg : str, optional |
---|
1043 | The error message to be printed in case of failure. |
---|
1044 | verbose : bool, optional |
---|
1045 | If True, the conflicting values are appended to the error message. |
---|
1046 | |
---|
1047 | Raises |
---|
1048 | ------ |
---|
1049 | AssertionError |
---|
1050 | If actual and desired are not equal up to specified precision. |
---|
1051 | |
---|
1052 | See Also |
---|
1053 | -------- |
---|
1054 | assert_allclose: Compare two array_like objects for equality with desired |
---|
1055 | relative and/or absolute precision. |
---|
1056 | assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal |
---|
1057 | |
---|
1058 | Examples |
---|
1059 | -------- |
---|
1060 | >>> import numpy.testing as npt |
---|
1061 | >>> npt.assert_almost_equal(2.3333333333333, 2.33333334) |
---|
1062 | >>> npt.assert_almost_equal(2.3333333333333, 2.33333334, decimal=10) |
---|
1063 | ... |
---|
1064 | <type 'exceptions.AssertionError'>: |
---|
1065 | Items are not equal: |
---|
1066 | ACTUAL: 2.3333333333333002 |
---|
1067 | DESIRED: 2.3333333399999998 |
---|
1068 | |
---|
1069 | >>> npt.assert_almost_equal(np.array([1.0,2.3333333333333]), |
---|
1070 | ... np.array([1.0,2.33333334]), decimal=9) |
---|
1071 | ... |
---|
1072 | <type 'exceptions.AssertionError'>: |
---|
1073 | Arrays are not almost equal |
---|
1074 | <BLANKLINE> |
---|
1075 | (mismatch 50.0%) |
---|
1076 | x: array([ 1. , 2.33333333]) |
---|
1077 | y: array([ 1. , 2.33333334]) |
---|
1078 | |
---|
1079 | """ |
---|
1080 | __tracebackhide__ = True # Hide traceback for py.test |
---|
1081 | from numpy.core import ndarray |
---|
1082 | from numpy.lib import iscomplexobj, real, imag |
---|
1083 | |
---|
1084 | # Handle complex numbers: separate into real/imag to handle |
---|
1085 | # nan/inf/negative zero correctly |
---|
1086 | # XXX: catch ValueError for subclasses of ndarray where iscomplex fail |
---|
1087 | try: |
---|
1088 | usecomplex = iscomplexobj(actual) or iscomplexobj(desired) |
---|
1089 | except ValueError: |
---|
1090 | usecomplex = False |
---|
1091 | |
---|
1092 | def _build_err_msg(): |
---|
1093 | header = ('Arrays are not almost equal to %d decimals' % decimal) |
---|
1094 | return build_err_msg([actual, desired], err_msg, verbose=verbose, |
---|
1095 | header=header) |
---|
1096 | |
---|
1097 | if usecomplex: |
---|
1098 | if iscomplexobj(actual): |
---|
1099 | actualr = real(actual) |
---|
1100 | actuali = imag(actual) |
---|
1101 | else: |
---|
1102 | actualr = actual |
---|
1103 | actuali = 0 |
---|
1104 | if iscomplexobj(desired): |
---|
1105 | desiredr = real(desired) |
---|
1106 | desiredi = imag(desired) |
---|
1107 | else: |
---|
1108 | desiredr = desired |
---|
1109 | desiredi = 0 |
---|
1110 | try: |
---|
1111 | assert_almost_equal(actualr, desiredr, decimal=decimal) |
---|
1112 | assert_almost_equal(actuali, desiredi, decimal=decimal) |
---|
1113 | except AssertionError: |
---|
1114 | raise AssertionError(_build_err_msg()) |
---|
1115 | |
---|
1116 | if isinstance(actual, (ndarray, tuple, list)) \ |
---|
1117 | or isinstance(desired, (ndarray, tuple, list)): |
---|
1118 | > return assert_array_almost_equal(actual, desired, decimal, err_msg) |
---|
1119 | |
---|
1120 | __tracebackhide__ = True |
---|
1121 | _build_err_msg = <function assert_almost_equal.<locals>._build_err_msg at 0x10e33a048> |
---|
1122 | actual = array([2., 1.], dtype=float32) |
---|
1123 | decimal = 6 |
---|
1124 | desired = array([ 6., 13.], dtype=float32) |
---|
1125 | err_msg = '' |
---|
1126 | imag = <function imag at 0x103d8f620> |
---|
1127 | iscomplexobj = <function iscomplexobj at 0x103d8f7b8> |
---|
1128 | ndarray = <class 'numpy.ndarray'> |
---|
1129 | real = <function real at 0x103d8f598> |
---|
1130 | usecomplex = False |
---|
1131 | verbose = True |
---|
1132 | |
---|
1133 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/testing/_private/utils.py:568: |
---|
1134 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
1135 | |
---|
1136 | x = array([2., 1.], dtype=float32), y = array([ 6., 13.], dtype=float32), decimal = 6, err_msg = '', verbose = True |
---|
1137 | |
---|
1138 | def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True): |
---|
1139 | """ |
---|
1140 | Raises an AssertionError if two objects are not equal up to desired |
---|
1141 | precision. |
---|
1142 | |
---|
1143 | .. note:: It is recommended to use one of `assert_allclose`, |
---|
1144 | `assert_array_almost_equal_nulp` or `assert_array_max_ulp` |
---|
1145 | instead of this function for more consistent floating point |
---|
1146 | comparisons. |
---|
1147 | |
---|
1148 | The test verifies identical shapes and that the elements of ``actual`` and |
---|
1149 | ``desired`` satisfy. |
---|
1150 | |
---|
1151 | ``abs(desired-actual) < 1.5 * 10**(-decimal)`` |
---|
1152 | |
---|
1153 | That is a looser test than originally documented, but agrees with what the |
---|
1154 | actual implementation did up to rounding vagaries. An exception is raised |
---|
1155 | at shape mismatch or conflicting values. In contrast to the standard usage |
---|
1156 | in numpy, NaNs are compared like numbers, no assertion is raised if both |
---|
1157 | objects have NaNs in the same positions. |
---|
1158 | |
---|
1159 | Parameters |
---|
1160 | ---------- |
---|
1161 | x : array_like |
---|
1162 | The actual object to check. |
---|
1163 | y : array_like |
---|
1164 | The desired, expected object. |
---|
1165 | decimal : int, optional |
---|
1166 | Desired precision, default is 6. |
---|
1167 | err_msg : str, optional |
---|
1168 | The error message to be printed in case of failure. |
---|
1169 | verbose : bool, optional |
---|
1170 | If True, the conflicting values are appended to the error message. |
---|
1171 | |
---|
1172 | Raises |
---|
1173 | ------ |
---|
1174 | AssertionError |
---|
1175 | If actual and desired are not equal up to specified precision. |
---|
1176 | |
---|
1177 | See Also |
---|
1178 | -------- |
---|
1179 | assert_allclose: Compare two array_like objects for equality with desired |
---|
1180 | relative and/or absolute precision. |
---|
1181 | assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal |
---|
1182 | |
---|
1183 | Examples |
---|
1184 | -------- |
---|
1185 | the first assert does not raise an exception |
---|
1186 | |
---|
1187 | >>> np.testing.assert_array_almost_equal([1.0,2.333,np.nan], |
---|
1188 | [1.0,2.333,np.nan]) |
---|
1189 | |
---|
1190 | >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], |
---|
1191 | ... [1.0,2.33339,np.nan], decimal=5) |
---|
1192 | ... |
---|
1193 | <type 'exceptions.AssertionError'>: |
---|
1194 | AssertionError: |
---|
1195 | Arrays are not almost equal |
---|
1196 | <BLANKLINE> |
---|
1197 | (mismatch 50.0%) |
---|
1198 | x: array([ 1. , 2.33333, NaN]) |
---|
1199 | y: array([ 1. , 2.33339, NaN]) |
---|
1200 | |
---|
1201 | >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], |
---|
1202 | ... [1.0,2.33333, 5], decimal=5) |
---|
1203 | <type 'exceptions.ValueError'>: |
---|
1204 | ValueError: |
---|
1205 | Arrays are not almost equal |
---|
1206 | x: array([ 1. , 2.33333, NaN]) |
---|
1207 | y: array([ 1. , 2.33333, 5. ]) |
---|
1208 | |
---|
1209 | """ |
---|
1210 | __tracebackhide__ = True # Hide traceback for py.test |
---|
1211 | from numpy.core import around, number, float_, result_type, array |
---|
1212 | from numpy.core.numerictypes import issubdtype |
---|
1213 | from numpy.core.fromnumeric import any as npany |
---|
1214 | |
---|
1215 | def compare(x, y): |
---|
1216 | try: |
---|
1217 | if npany(gisinf(x)) or npany( gisinf(y)): |
---|
1218 | xinfid = gisinf(x) |
---|
1219 | yinfid = gisinf(y) |
---|
1220 | if not (xinfid == yinfid).all(): |
---|
1221 | return False |
---|
1222 | # if one item, x and y is +- inf |
---|
1223 | if x.size == y.size == 1: |
---|
1224 | return x == y |
---|
1225 | x = x[~xinfid] |
---|
1226 | y = y[~yinfid] |
---|
1227 | except (TypeError, NotImplementedError): |
---|
1228 | pass |
---|
1229 | |
---|
1230 | # make sure y is an inexact type to avoid abs(MIN_INT); will cause |
---|
1231 | # casting of x later. |
---|
1232 | dtype = result_type(y, 1.) |
---|
1233 | y = array(y, dtype=dtype, copy=False, subok=True) |
---|
1234 | z = abs(x - y) |
---|
1235 | |
---|
1236 | if not issubdtype(z.dtype, number): |
---|
1237 | z = z.astype(float_) # handle object arrays |
---|
1238 | |
---|
1239 | return z < 1.5 * 10.0**(-decimal) |
---|
1240 | |
---|
1241 | assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose, |
---|
1242 | header=('Arrays are not almost equal to %d decimals' % decimal), |
---|
1243 | > precision=decimal) |
---|
1244 | |
---|
1245 | __tracebackhide__ = True |
---|
1246 | around = <function around at 0x10385c8c8> |
---|
1247 | array = <built-in function array> |
---|
1248 | compare = <function assert_array_almost_equal.<locals>.compare at 0x10e33a0d0> |
---|
1249 | decimal = 6 |
---|
1250 | err_msg = '' |
---|
1251 | float_ = <class 'numpy.float64'> |
---|
1252 | issubdtype = <function issubdtype at 0x10371cae8> |
---|
1253 | npany = <function any at 0x10385c2f0> |
---|
1254 | number = <class 'numpy.number'> |
---|
1255 | result_type = <built-in function result_type> |
---|
1256 | verbose = True |
---|
1257 | x = array([2., 1.], dtype=float32) |
---|
1258 | y = array([ 6., 13.], dtype=float32) |
---|
1259 | |
---|
1260 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/testing/_private/utils.py:964: |
---|
1261 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
1262 | |
---|
1263 | comparison = <function assert_array_almost_equal.<locals>.compare at 0x10e33a0d0>, x = array([2., 1.], dtype=float32), y = array([ 6., 13.], dtype=float32), err_msg = '', verbose = True |
---|
1264 | header = 'Arrays are not almost equal to 6 decimals', precision = 6, equal_nan = True, equal_inf = True |
---|
1265 | |
---|
1266 | def assert_array_compare(comparison, x, y, err_msg='', verbose=True, |
---|
1267 | header='', precision=6, equal_nan=True, |
---|
1268 | equal_inf=True): |
---|
1269 | __tracebackhide__ = True # Hide traceback for py.test |
---|
1270 | from numpy.core import array, isnan, inf, bool_ |
---|
1271 | x = array(x, copy=False, subok=True) |
---|
1272 | y = array(y, copy=False, subok=True) |
---|
1273 | |
---|
1274 | def isnumber(x): |
---|
1275 | return x.dtype.char in '?bhilqpBHILQPefdgFDG' |
---|
1276 | |
---|
1277 | def istime(x): |
---|
1278 | return x.dtype.char in "Mm" |
---|
1279 | |
---|
1280 | def func_assert_same_pos(x, y, func=isnan, hasval='nan'): |
---|
1281 | """Handling nan/inf: combine results of running func on x and y, |
---|
1282 | checking that they are True at the same locations.""" |
---|
1283 | # Both the != True comparison here and the cast to bool_ at |
---|
1284 | # the end are done to deal with `masked`, which cannot be |
---|
1285 | # compared usefully, and for which .all() yields masked. |
---|
1286 | x_id = func(x) |
---|
1287 | y_id = func(y) |
---|
1288 | if (x_id == y_id).all() != True: |
---|
1289 | msg = build_err_msg([x, y], |
---|
1290 | err_msg + '\nx and y %s location mismatch:' |
---|
1291 | % (hasval), verbose=verbose, header=header, |
---|
1292 | names=('x', 'y'), precision=precision) |
---|
1293 | raise AssertionError(msg) |
---|
1294 | # If there is a scalar, then here we know the array has the same |
---|
1295 | # flag as it everywhere, so we should return the scalar flag. |
---|
1296 | if x_id.ndim == 0: |
---|
1297 | return bool_(x_id) |
---|
1298 | elif y_id.ndim == 0: |
---|
1299 | return bool_(y_id) |
---|
1300 | else: |
---|
1301 | return y_id |
---|
1302 | |
---|
1303 | try: |
---|
1304 | cond = (x.shape == () or y.shape == ()) or x.shape == y.shape |
---|
1305 | if not cond: |
---|
1306 | msg = build_err_msg([x, y], |
---|
1307 | err_msg |
---|
1308 | + '\n(shapes %s, %s mismatch)' % (x.shape, |
---|
1309 | y.shape), |
---|
1310 | verbose=verbose, header=header, |
---|
1311 | names=('x', 'y'), precision=precision) |
---|
1312 | raise AssertionError(msg) |
---|
1313 | |
---|
1314 | flagged = bool_(False) |
---|
1315 | if isnumber(x) and isnumber(y): |
---|
1316 | if equal_nan: |
---|
1317 | flagged = func_assert_same_pos(x, y, func=isnan, hasval='nan') |
---|
1318 | |
---|
1319 | if equal_inf: |
---|
1320 | flagged |= func_assert_same_pos(x, y, |
---|
1321 | func=lambda xy: xy == +inf, |
---|
1322 | hasval='+inf') |
---|
1323 | flagged |= func_assert_same_pos(x, y, |
---|
1324 | func=lambda xy: xy == -inf, |
---|
1325 | hasval='-inf') |
---|
1326 | |
---|
1327 | elif istime(x) and istime(y): |
---|
1328 | # If one is datetime64 and the other timedelta64 there is no point |
---|
1329 | if equal_nan and x.dtype.type == y.dtype.type: |
---|
1330 | flagged = func_assert_same_pos(x, y, func=isnat, hasval="NaT") |
---|
1331 | |
---|
1332 | if flagged.ndim > 0: |
---|
1333 | x, y = x[~flagged], y[~flagged] |
---|
1334 | # Only do the comparison if actual values are left |
---|
1335 | if x.size == 0: |
---|
1336 | return |
---|
1337 | elif flagged: |
---|
1338 | # no sense doing comparison if everything is flagged. |
---|
1339 | return |
---|
1340 | |
---|
1341 | val = comparison(x, y) |
---|
1342 | |
---|
1343 | if isinstance(val, bool): |
---|
1344 | cond = val |
---|
1345 | reduced = [0] |
---|
1346 | else: |
---|
1347 | reduced = val.ravel() |
---|
1348 | cond = reduced.all() |
---|
1349 | reduced = reduced.tolist() |
---|
1350 | # The below comparison is a hack to ensure that fully masked |
---|
1351 | # results, for which val.ravel().all() returns np.ma.masked, |
---|
1352 | # do not trigger a failure (np.ma.masked != True evaluates as |
---|
1353 | # np.ma.masked, which is falsy). |
---|
1354 | if cond != True: |
---|
1355 | match = 100-100.0*reduced.count(1)/len(reduced) |
---|
1356 | msg = build_err_msg([x, y], |
---|
1357 | err_msg |
---|
1358 | + '\n(mismatch %s%%)' % (match,), |
---|
1359 | verbose=verbose, header=header, |
---|
1360 | names=('x', 'y'), precision=precision) |
---|
1361 | > raise AssertionError(msg) |
---|
1362 | E AssertionError: |
---|
1363 | E Arrays are not almost equal to 6 decimals |
---|
1364 | E |
---|
1365 | E (mismatch 100.0%) |
---|
1366 | E x: array([2., 1.], dtype=float32) |
---|
1367 | E y: array([ 6., 13.], dtype=float32) |
---|
1368 | |
---|
1369 | __tracebackhide__ = True |
---|
1370 | array = <built-in function array> |
---|
1371 | bool_ = <class 'numpy.bool_'> |
---|
1372 | comparison = <function assert_array_almost_equal.<locals>.compare at 0x10e33a0d0> |
---|
1373 | cond = False |
---|
1374 | equal_inf = True |
---|
1375 | equal_nan = True |
---|
1376 | err_msg = '' |
---|
1377 | flagged = array([False, False]) |
---|
1378 | func_assert_same_pos = <function assert_array_compare.<locals>.func_assert_same_pos at 0x10e33a268> |
---|
1379 | header = 'Arrays are not almost equal to 6 decimals' |
---|
1380 | inf = inf |
---|
1381 | isnan = <ufunc 'isnan'> |
---|
1382 | isnumber = <function assert_array_compare.<locals>.isnumber at 0x10e33a158> |
---|
1383 | istime = <function assert_array_compare.<locals>.istime at 0x10e33a1e0> |
---|
1384 | match = 100.0 |
---|
1385 | msg = '\nArrays are not almost equal to 6 decimals\n\n(mismatch 100.0%)\n x: array([2., 1.], dtype=float32)\n y: array([ 6., 13.], dtype=float32)' |
---|
1386 | precision = 6 |
---|
1387 | reduced = [False, False] |
---|
1388 | val = array([False, False]) |
---|
1389 | verbose = True |
---|
1390 | x = array([2., 1.], dtype=float32) |
---|
1391 | y = array([ 6., 13.], dtype=float32) |
---|
1392 | |
---|
1393 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/testing/_private/utils.py:780: AssertionError |
---|
1394 | |
---|
1395 | During handling of the above exception, another exception occurred: |
---|
1396 | |
---|
1397 | self = <numpy.linalg.tests.test_linalg.TestLstsq object at 0x10e52f470> |
---|
1398 | |
---|
1399 | def test_nonsq_cases(self): |
---|
1400 | self.check_cases(require={'nonsquare'}, |
---|
1401 | > exclude={'generalized', 'size-0'}) |
---|
1402 | |
---|
1403 | self = <numpy.linalg.tests.test_linalg.TestLstsq object at 0x10e52f470> |
---|
1404 | |
---|
1405 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py:372: |
---|
1406 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
1407 | |
---|
1408 | self = <numpy.linalg.tests.test_linalg.TestLstsq object at 0x10e52f470>, require = {'nonsquare'}, exclude = {'generalized', 'size-0'} |
---|
1409 | |
---|
1410 | def check_cases(self, require=set(), exclude=set()): |
---|
1411 | """ |
---|
1412 | Run func on each of the cases with all of the tags in require, and none |
---|
1413 | of the tags in exclude |
---|
1414 | """ |
---|
1415 | for case in self.TEST_CASES: |
---|
1416 | # filter by require and exclude |
---|
1417 | if case.tags & require != require: |
---|
1418 | continue |
---|
1419 | if case.tags & exclude: |
---|
1420 | continue |
---|
1421 | |
---|
1422 | try: |
---|
1423 | case.check(self.do) |
---|
1424 | except Exception: |
---|
1425 | msg = "In test case: %r\n\n" % case |
---|
1426 | msg += traceback.format_exc() |
---|
1427 | > raise AssertionError(msg) |
---|
1428 | E AssertionError: In test case: <LinalgCase: single_nsq_1> |
---|
1429 | E |
---|
1430 | E Traceback (most recent call last): |
---|
1431 | E File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py", line 350, in check_cases |
---|
1432 | E case.check(self.do) |
---|
1433 | E File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py", line 85, in check |
---|
1434 | E do(self.a, self.b, tags=self.tags) |
---|
1435 | E File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py", line 887, in do |
---|
1436 | E assert_almost_equal(b, dot(a, x)) |
---|
1437 | E File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py", line 41, in assert_almost_equal |
---|
1438 | E old_assert_almost_equal(a, b, decimal=decimal, **kw) |
---|
1439 | E File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/testing/_private/utils.py", line 568, in assert_almost_equal |
---|
1440 | E return assert_array_almost_equal(actual, desired, decimal, err_msg) |
---|
1441 | E File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/testing/_private/utils.py", line 964, in assert_array_almost_equal |
---|
1442 | E precision=decimal) |
---|
1443 | E File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/testing/_private/utils.py", line 780, in assert_array_compare |
---|
1444 | E raise AssertionError(msg) |
---|
1445 | E AssertionError: |
---|
1446 | E Arrays are not almost equal to 6 decimals |
---|
1447 | E |
---|
1448 | E (mismatch 100.0%) |
---|
1449 | E x: array([2., 1.], dtype=float32) |
---|
1450 | E y: array([ 6., 13.], dtype=float32) |
---|
1451 | |
---|
1452 | case = <LinalgCase: single_nsq_1> |
---|
1453 | exclude = {'generalized', 'size-0'} |
---|
1454 | msg = 'In test case: <LinalgCase: single_nsq_1>\n\nTraceback (most recent call last):\n File "/opt/local/Library/Frameworks...t equal to 6 decimals\n\n(mismatch 100.0%)\n x: array([2., 1.], dtype=float32)\n y: array([ 6., 13.], dtype=float32)\n' |
---|
1455 | require = {'nonsquare'} |
---|
1456 | self = <numpy.linalg.tests.test_linalg.TestLstsq object at 0x10e52f470> |
---|
1457 | |
---|
1458 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py:354: AssertionError |
---|
1459 | ------------------------------------------------------------------------------------------- Captured stderr call -------------------------------------------------------------------------------------------- |
---|
1460 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438804480) failed (error code=3) |
---|
1461 | *** error: can't allocate region |
---|
1462 | *** set a breakpoint in malloc_error_break to debug |
---|
1463 | init_dgelsd failed init |
---|
1464 | ________________________________________________________________________________________ TestLstsq.test_future_rcond ________________________________________________________________________________________ |
---|
1465 | |
---|
1466 | self = <numpy.linalg.tests.test_linalg.TestLstsq object at 0x10b0b50f0> |
---|
1467 | |
---|
1468 | def test_future_rcond(self): |
---|
1469 | a = np.array([[0., 1., 0., 1., 2., 0.], |
---|
1470 | [0., 2., 0., 0., 1., 0.], |
---|
1471 | [1., 0., 1., 0., 0., 4.], |
---|
1472 | [0., 0., 0., 2., 3., 0.]]).T |
---|
1473 | |
---|
1474 | b = np.array([1, 0, 0, 0, 0, 0]) |
---|
1475 | with suppress_warnings() as sup: |
---|
1476 | w = sup.record(FutureWarning, "`rcond` parameter will change") |
---|
1477 | x, residuals, rank, s = linalg.lstsq(a, b) |
---|
1478 | > assert_(rank == 4) |
---|
1479 | E AssertionError |
---|
1480 | |
---|
1481 | a = array([[0., 0., 1., 0.], |
---|
1482 | [1., 2., 0., 0.], |
---|
1483 | [0., 0., 1., 0.], |
---|
1484 | [1., 0., 0., 2.], |
---|
1485 | [2., 1., 0., 3.], |
---|
1486 | [0., 0., 4., 0.]]) |
---|
1487 | b = array([1, 0, 0, 0, 0, 0]) |
---|
1488 | rank = 1095761920 |
---|
1489 | residuals = array([], dtype=float64) |
---|
1490 | s = array([-0.40455358, -0.9145143 , -0.9145143 , 0.40455358]) |
---|
1491 | self = <numpy.linalg.tests.test_linalg.TestLstsq object at 0x10b0b50f0> |
---|
1492 | sup = <numpy.testing._private.utils.suppress_warnings object at 0x10b0b5a20> |
---|
1493 | w = [<warnings.WarningMessage object at 0x10b0b5ac8>] |
---|
1494 | x = array([-0.43035828, -0.90265816, -0.90265816, 0.43035828]) |
---|
1495 | |
---|
1496 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py:918: AssertionError |
---|
1497 | ------------------------------------------------------------------------------------------- Captured stderr call -------------------------------------------------------------------------------------------- |
---|
1498 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438816768) failed (error code=3) |
---|
1499 | *** error: can't allocate region |
---|
1500 | *** set a breakpoint in malloc_error_break to debug |
---|
1501 | init_dgelsd failed init |
---|
1502 | ________________________________________________________________________________________ TestPolynomial.test_polyfit ________________________________________________________________________________________ |
---|
1503 | |
---|
1504 | self = <numpy.ma.tests.test_extras.TestPolynomial object at 0x10e6b0c50> |
---|
1505 | |
---|
1506 | def test_polyfit(self): |
---|
1507 | # Tests polyfit |
---|
1508 | # On ndarrays |
---|
1509 | x = np.random.rand(10) |
---|
1510 | y = np.random.rand(20).reshape(-1, 2) |
---|
1511 | assert_almost_equal(polyfit(x, y, 3), np.polyfit(x, y, 3)) |
---|
1512 | # ON 1D maskedarrays |
---|
1513 | x = x.view(MaskedArray) |
---|
1514 | x[0] = masked |
---|
1515 | y = y.view(MaskedArray) |
---|
1516 | y[0, 0] = y[-1, -1] = masked |
---|
1517 | # |
---|
1518 | (C, R, K, S, D) = polyfit(x, y[:, 0], 3, full=True) |
---|
1519 | (c, r, k, s, d) = np.polyfit(x[1:], y[1:, 0].compressed(), 3, |
---|
1520 | full=True) |
---|
1521 | for (a, a_) in zip((C, R, K, S, D), (c, r, k, s, d)): |
---|
1522 | > assert_almost_equal(a, a_) |
---|
1523 | |
---|
1524 | C = array([1.10107647, 1.33707346, 1.75813242, 3. ]) |
---|
1525 | D = 1.9984014443252818e-15 |
---|
1526 | K = 16843009 |
---|
1527 | R = array([], dtype=float64) |
---|
1528 | S = array([1. , 0.5034478, 0.5034478, 1. ]) |
---|
1529 | a = array([1. , 0.5034478, 0.5034478, 1. ]) |
---|
1530 | a_ = array([0., 0., 0., 0.]) |
---|
1531 | c = array([1.10107647, 1.33707346, 1.75813242, 3. ]) |
---|
1532 | d = 1.9984014443252818e-15 |
---|
1533 | k = 16843009 |
---|
1534 | r = array([], dtype=float64) |
---|
1535 | s = array([0., 0., 0., 0.]) |
---|
1536 | self = <numpy.ma.tests.test_extras.TestPolynomial object at 0x10e6b0c50> |
---|
1537 | x = masked_array(data=[--, 0.9241423902691124, 0.5615918401132496, |
---|
1538 | 0.25356523046838064, 0.4678691307098...ask=[ True, False, False, False, False, False, False, False, |
---|
1539 | False, False], |
---|
1540 | fill_value=1e+20) |
---|
1541 | y = masked_array( |
---|
1542 | data=[[--, 0.07553868406697983], |
---|
1543 | [0.5637507914837855, 0.9932431418933281], |
---|
1544 | [0.94514463...], |
---|
1545 | [False, False], |
---|
1546 | [False, False], |
---|
1547 | [False, False], |
---|
1548 | [False, True]], |
---|
1549 | fill_value=1e+20) |
---|
1550 | |
---|
1551 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/ma/tests/test_extras.py:1272: |
---|
1552 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
1553 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/ma/testutils.py:187: in assert_almost_equal |
---|
1554 | err_msg=err_msg, verbose=verbose) |
---|
1555 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/ma/testutils.py:268: in assert_array_almost_equal |
---|
1556 | header='Arrays are not almost equal') |
---|
1557 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
1558 | |
---|
1559 | comparison = <function assert_array_almost_equal.<locals>.compare at 0x10d9f8598>, x = masked_array(data=[1. , 0.5034478, 0.5034478, 1. ], |
---|
1560 | mask=False, |
---|
1561 | fill_value=1e+20) |
---|
1562 | y = masked_array(data=[0., 0., 0., 0.], |
---|
1563 | mask=False, |
---|
1564 | fill_value=1e+20), err_msg = '', verbose = True, header = 'Arrays are not almost equal', fill_value = True |
---|
1565 | |
---|
1566 | def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='', |
---|
1567 | fill_value=True): |
---|
1568 | """ |
---|
1569 | Asserts that comparison between two masked arrays is satisfied. |
---|
1570 | |
---|
1571 | The comparison is elementwise. |
---|
1572 | |
---|
1573 | """ |
---|
1574 | # Allocate a common mask and refill |
---|
1575 | m = mask_or(getmask(x), getmask(y)) |
---|
1576 | x = masked_array(x, copy=False, mask=m, keep_mask=False, subok=False) |
---|
1577 | y = masked_array(y, copy=False, mask=m, keep_mask=False, subok=False) |
---|
1578 | if ((x is masked) and not (y is masked)) or \ |
---|
1579 | ((y is masked) and not (x is masked)): |
---|
1580 | msg = build_err_msg([x, y], err_msg=err_msg, verbose=verbose, |
---|
1581 | header=header, names=('x', 'y')) |
---|
1582 | raise ValueError(msg) |
---|
1583 | # OK, now run the basic tests on filled versions |
---|
1584 | return np.testing.assert_array_compare(comparison, |
---|
1585 | x.filled(fill_value), |
---|
1586 | y.filled(fill_value), |
---|
1587 | err_msg=err_msg, |
---|
1588 | > verbose=verbose, header=header) |
---|
1589 | E AssertionError: |
---|
1590 | E Arrays are not almost equal |
---|
1591 | E |
---|
1592 | E (mismatch 100.0%) |
---|
1593 | E x: array([1. , 0.503448, 0.503448, 1. ]) |
---|
1594 | E y: array([0., 0., 0., 0.]) |
---|
1595 | |
---|
1596 | comparison = <function assert_array_almost_equal.<locals>.compare at 0x10d9f8598> |
---|
1597 | err_msg = '' |
---|
1598 | fill_value = True |
---|
1599 | header = 'Arrays are not almost equal' |
---|
1600 | m = False |
---|
1601 | verbose = True |
---|
1602 | x = masked_array(data=[1. , 0.5034478, 0.5034478, 1. ], |
---|
1603 | mask=False, |
---|
1604 | fill_value=1e+20) |
---|
1605 | y = masked_array(data=[0., 0., 0., 0.], |
---|
1606 | mask=False, |
---|
1607 | fill_value=1e+20) |
---|
1608 | |
---|
1609 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/ma/testutils.py:219: AssertionError |
---|
1610 | ------------------------------------------------------------------------------------------- Captured stderr call -------------------------------------------------------------------------------------------- |
---|
1611 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438808576) failed (error code=3) |
---|
1612 | *** error: can't allocate region |
---|
1613 | *** set a breakpoint in malloc_error_break to debug |
---|
1614 | init_dgelsd failed init |
---|
1615 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438812672) failed (error code=3) |
---|
1616 | *** error: can't allocate region |
---|
1617 | *** set a breakpoint in malloc_error_break to debug |
---|
1618 | init_dgelsd failed init |
---|
1619 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438808576) failed (error code=3) |
---|
1620 | *** error: can't allocate region |
---|
1621 | *** set a breakpoint in malloc_error_break to debug |
---|
1622 | init_dgelsd failed init |
---|
1623 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438812672) failed (error code=3) |
---|
1624 | *** error: can't allocate region |
---|
1625 | *** set a breakpoint in malloc_error_break to debug |
---|
1626 | init_dgelsd failed init |
---|
1627 | _______________________________________________________________________________ TestPolynomial.test_polyfit_with_masked_NaNs ________________________________________________________________________________ |
---|
1628 | |
---|
1629 | self = <numpy.ma.tests.test_extras.TestPolynomial object at 0x10ea492e8> |
---|
1630 | |
---|
1631 | def test_polyfit_with_masked_NaNs(self): |
---|
1632 | x = np.random.rand(10) |
---|
1633 | y = np.random.rand(20).reshape(-1, 2) |
---|
1634 | |
---|
1635 | x[0] = np.nan |
---|
1636 | y[-1,-1] = np.nan |
---|
1637 | x = x.view(MaskedArray) |
---|
1638 | y = y.view(MaskedArray) |
---|
1639 | x[0] = masked |
---|
1640 | y[-1,-1] = masked |
---|
1641 | |
---|
1642 | (C, R, K, S, D) = polyfit(x, y, 3, full=True) |
---|
1643 | (c, r, k, s, d) = np.polyfit(x[1:-1], y[1:-1,:], 3, full=True) |
---|
1644 | for (a, a_) in zip((C, R, K, S, D), (c, r, k, s, d)): |
---|
1645 | > assert_almost_equal(a, a_) |
---|
1646 | |
---|
1647 | C = array([[ 0.10055815, 0.10049137], |
---|
1648 | [-0.01941448, -0.11460321], |
---|
1649 | [ 0.07912554, -0.01445208], |
---|
1650 | [-0.0267252 , 0.03503432]]) |
---|
1651 | D = 1.7763568394002505e-15 |
---|
1652 | K = 0 |
---|
1653 | R = array([], dtype=float64) |
---|
1654 | S = array([1.56110891, 2.31229114, 3.77085666, 8. ]) |
---|
1655 | a = array([[ 0.10055815, 0.10049137], |
---|
1656 | [-0.01941448, -0.11460321], |
---|
1657 | [ 0.07912554, -0.01445208], |
---|
1658 | [-0.0267252 , 0.03503432]]) |
---|
1659 | a_ = array([[0.24052139, 0.61934872], |
---|
1660 | [0.25971278, 0.5234543 ], |
---|
1661 | [0.4704521 , 0.24757803], |
---|
1662 | [0.25471504, 0.29736637]]) |
---|
1663 | c = array([[0.24052139, 0.61934872], |
---|
1664 | [0.25971278, 0.5234543 ], |
---|
1665 | [0.4704521 , 0.24757803], |
---|
1666 | [0.25471504, 0.29736637]]) |
---|
1667 | d = 1.7763568394002505e-15 |
---|
1668 | k = 0 |
---|
1669 | r = array([], dtype=float64) |
---|
1670 | s = array([1.56110891, 2.31229114, 3.77085666, 8. ]) |
---|
1671 | self = <numpy.ma.tests.test_extras.TestPolynomial object at 0x10ea492e8> |
---|
1672 | x = masked_array(data=[--, 0.3005178781983737, 0.7738411999597311, |
---|
1673 | 0.3949249488730213, 0.79597610287801...ask=[ True, False, False, False, False, False, False, False, |
---|
1674 | False, False], |
---|
1675 | fill_value=1e+20) |
---|
1676 | y = masked_array( |
---|
1677 | data=[[0.37568931468158495, 0.16236135212063585], |
---|
1678 | [0.4371055455264542, 0.20680234608690984], |
---|
1679 | ...], |
---|
1680 | [False, False], |
---|
1681 | [False, False], |
---|
1682 | [False, False], |
---|
1683 | [False, True]], |
---|
1684 | fill_value=1e+20) |
---|
1685 | |
---|
1686 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/ma/tests/test_extras.py:1309: |
---|
1687 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
1688 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/ma/testutils.py:187: in assert_almost_equal |
---|
1689 | err_msg=err_msg, verbose=verbose) |
---|
1690 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/ma/testutils.py:268: in assert_array_almost_equal |
---|
1691 | header='Arrays are not almost equal') |
---|
1692 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
1693 | |
---|
1694 | comparison = <function assert_array_almost_equal.<locals>.compare at 0x10d9ce730> |
---|
1695 | x = masked_array( |
---|
1696 | data=[[ 0.10055815, 0.10049137], |
---|
1697 | [-0.01941448, -0.11460321], |
---|
1698 | [ 0.07912554, -0.01445208], |
---|
1699 | [-0.0267252 , 0.03503432]], |
---|
1700 | mask=False, |
---|
1701 | fill_value=1e+20) |
---|
1702 | y = masked_array( |
---|
1703 | data=[[0.24052139, 0.61934872], |
---|
1704 | [0.25971278, 0.5234543 ], |
---|
1705 | [0.4704521 , 0.24757803], |
---|
1706 | [0.25471504, 0.29736637]], |
---|
1707 | mask=False, |
---|
1708 | fill_value=1e+20), err_msg = '' |
---|
1709 | verbose = True, header = 'Arrays are not almost equal', fill_value = True |
---|
1710 | |
---|
1711 | def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='', |
---|
1712 | fill_value=True): |
---|
1713 | """ |
---|
1714 | Asserts that comparison between two masked arrays is satisfied. |
---|
1715 | |
---|
1716 | The comparison is elementwise. |
---|
1717 | |
---|
1718 | """ |
---|
1719 | # Allocate a common mask and refill |
---|
1720 | m = mask_or(getmask(x), getmask(y)) |
---|
1721 | x = masked_array(x, copy=False, mask=m, keep_mask=False, subok=False) |
---|
1722 | y = masked_array(y, copy=False, mask=m, keep_mask=False, subok=False) |
---|
1723 | if ((x is masked) and not (y is masked)) or \ |
---|
1724 | ((y is masked) and not (x is masked)): |
---|
1725 | msg = build_err_msg([x, y], err_msg=err_msg, verbose=verbose, |
---|
1726 | header=header, names=('x', 'y')) |
---|
1727 | raise ValueError(msg) |
---|
1728 | # OK, now run the basic tests on filled versions |
---|
1729 | return np.testing.assert_array_compare(comparison, |
---|
1730 | x.filled(fill_value), |
---|
1731 | y.filled(fill_value), |
---|
1732 | err_msg=err_msg, |
---|
1733 | > verbose=verbose, header=header) |
---|
1734 | E AssertionError: |
---|
1735 | E Arrays are not almost equal |
---|
1736 | E |
---|
1737 | E (mismatch 100.0%) |
---|
1738 | E x: array([ 0.100558, 0.100491, -0.019414, -0.114603, 0.079126, -0.014452, |
---|
1739 | E -0.026725, 0.035034]) |
---|
1740 | E y: array([0.240521, 0.619349, 0.259713, 0.523454, 0.470452, 0.247578, |
---|
1741 | E 0.254715, 0.297366]) |
---|
1742 | |
---|
1743 | comparison = <function assert_array_almost_equal.<locals>.compare at 0x10d9ce730> |
---|
1744 | err_msg = '' |
---|
1745 | fill_value = True |
---|
1746 | header = 'Arrays are not almost equal' |
---|
1747 | m = False |
---|
1748 | verbose = True |
---|
1749 | x = masked_array( |
---|
1750 | data=[[ 0.10055815, 0.10049137], |
---|
1751 | [-0.01941448, -0.11460321], |
---|
1752 | [ 0.07912554, -0.01445208], |
---|
1753 | [-0.0267252 , 0.03503432]], |
---|
1754 | mask=False, |
---|
1755 | fill_value=1e+20) |
---|
1756 | y = masked_array( |
---|
1757 | data=[[0.24052139, 0.61934872], |
---|
1758 | [0.25971278, 0.5234543 ], |
---|
1759 | [0.4704521 , 0.24757803], |
---|
1760 | [0.25471504, 0.29736637]], |
---|
1761 | mask=False, |
---|
1762 | fill_value=1e+20) |
---|
1763 | |
---|
1764 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/ma/testutils.py:219: AssertionError |
---|
1765 | ------------------------------------------------------------------------------------------- Captured stderr call -------------------------------------------------------------------------------------------- |
---|
1766 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438808576) failed (error code=3) |
---|
1767 | *** error: can't allocate region |
---|
1768 | *** set a breakpoint in malloc_error_break to debug |
---|
1769 | init_dgelsd failed init |
---|
1770 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438812672) failed (error code=3) |
---|
1771 | *** error: can't allocate region |
---|
1772 | *** set a breakpoint in malloc_error_break to debug |
---|
1773 | init_dgelsd failed init |
---|
1774 | _______________________________________________________________________________________ TestLstsqMatrix.test_sq_cases _______________________________________________________________________________________ |
---|
1775 | |
---|
1776 | self = <numpy.matrixlib.tests.test_matrix_linalg.TestLstsqMatrix object at 0x10d8f7898>, require = {'square'}, exclude = {'generalized', 'size-0'} |
---|
1777 | |
---|
1778 | def check_cases(self, require=set(), exclude=set()): |
---|
1779 | """ |
---|
1780 | Run func on each of the cases with all of the tags in require, and none |
---|
1781 | of the tags in exclude |
---|
1782 | """ |
---|
1783 | for case in self.TEST_CASES: |
---|
1784 | # filter by require and exclude |
---|
1785 | if case.tags & require != require: |
---|
1786 | continue |
---|
1787 | if case.tags & exclude: |
---|
1788 | continue |
---|
1789 | |
---|
1790 | try: |
---|
1791 | > case.check(self.do) |
---|
1792 | |
---|
1793 | case = <LinalgCase: matrix_b_only> |
---|
1794 | exclude = {'generalized', 'size-0'} |
---|
1795 | msg = 'In test case: <LinalgCase: matrix_b_only>\n\nTraceback (most recent call last):\n File "/opt/local/Library/Framework...o 12 decimals\n\n(mismatch 100.0%)\n x: matrix([[2., 1.]])\n y: matrix([[4.475004438720e-154, 1.044167702368e-153]])\n' |
---|
1796 | require = {'square'} |
---|
1797 | self = <numpy.matrixlib.tests.test_matrix_linalg.TestLstsqMatrix object at 0x10d8f7898> |
---|
1798 | |
---|
1799 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py:350: |
---|
1800 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
1801 | |
---|
1802 | self = <LinalgCase: matrix_b_only>, do = <bound method LstsqCases.do of <numpy.matrixlib.tests.test_matrix_linalg.TestLstsqMatrix object at 0x10d8f7898>> |
---|
1803 | |
---|
1804 | def check(self, do): |
---|
1805 | """ |
---|
1806 | Run the function `do` on this test case, expanding arguments |
---|
1807 | """ |
---|
1808 | > do(self.a, self.b, tags=self.tags) |
---|
1809 | |
---|
1810 | do = <bound method LstsqCases.do of <numpy.matrixlib.tests.test_matrix_linalg.TestLstsqMatrix object at 0x10d8f7898>> |
---|
1811 | self = <LinalgCase: matrix_b_only> |
---|
1812 | |
---|
1813 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py:85: |
---|
1814 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
1815 | |
---|
1816 | self = <numpy.matrixlib.tests.test_matrix_linalg.TestLstsqMatrix object at 0x10d8f7898>, a = array([[1., 2.], |
---|
1817 | [3., 4.]]), b = matrix([[2.], |
---|
1818 | [1.]]), tags = frozenset({'square'}) |
---|
1819 | |
---|
1820 | def do(self, a, b, tags): |
---|
1821 | if 'size-0' in tags: |
---|
1822 | assert_raises(LinAlgError, linalg.lstsq, a, b) |
---|
1823 | return |
---|
1824 | |
---|
1825 | arr = np.asarray(a) |
---|
1826 | m, n = arr.shape |
---|
1827 | u, s, vt = linalg.svd(a, 0) |
---|
1828 | x, residuals, rank, sv = linalg.lstsq(a, b, rcond=-1) |
---|
1829 | if m <= n: |
---|
1830 | > assert_almost_equal(b, dot(a, x)) |
---|
1831 | |
---|
1832 | a = array([[1., 2.], |
---|
1833 | [3., 4.]]) |
---|
1834 | arr = array([[1., 2.], |
---|
1835 | [3., 4.]]) |
---|
1836 | b = matrix([[2.], |
---|
1837 | [1.]]) |
---|
1838 | m = 2 |
---|
1839 | n = 2 |
---|
1840 | rank = 16843009 |
---|
1841 | residuals = matrix([], shape=(1, 0), dtype=float64) |
---|
1842 | s = array([5.4649857 , 0.36596619]) |
---|
1843 | self = <numpy.matrixlib.tests.test_matrix_linalg.TestLstsqMatrix object at 0x10d8f7898> |
---|
1844 | sv = array([1.49166815e-154, 1.49166815e-154]) |
---|
1845 | tags = frozenset({'square'}) |
---|
1846 | u = array([[-0.40455358, -0.9145143 ], |
---|
1847 | [-0.9145143 , 0.40455358]]) |
---|
1848 | vt = array([[-0.57604844, -0.81741556], |
---|
1849 | [ 0.81741556, -0.57604844]]) |
---|
1850 | x = matrix([[1.49166815e-154], |
---|
1851 | [1.49166815e-154]]) |
---|
1852 | |
---|
1853 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py:887: |
---|
1854 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
1855 | |
---|
1856 | a = matrix([[2.], |
---|
1857 | [1.]]), b = matrix([[4.47500444e-154], |
---|
1858 | [1.04416770e-153]]), single_decimal = 6, double_decimal = 12, kw = {}, decimal = 12 |
---|
1859 | |
---|
1860 | def assert_almost_equal(a, b, single_decimal=6, double_decimal=12, **kw): |
---|
1861 | if asarray(a).dtype.type in (single, csingle): |
---|
1862 | decimal = single_decimal |
---|
1863 | else: |
---|
1864 | decimal = double_decimal |
---|
1865 | > old_assert_almost_equal(a, b, decimal=decimal, **kw) |
---|
1866 | |
---|
1867 | a = matrix([[2.], |
---|
1868 | [1.]]) |
---|
1869 | b = matrix([[4.47500444e-154], |
---|
1870 | [1.04416770e-153]]) |
---|
1871 | decimal = 12 |
---|
1872 | double_decimal = 12 |
---|
1873 | kw = {} |
---|
1874 | single_decimal = 6 |
---|
1875 | |
---|
1876 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py:41: |
---|
1877 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
1878 | |
---|
1879 | actual = matrix([[2.], |
---|
1880 | [1.]]), desired = matrix([[4.47500444e-154], |
---|
1881 | [1.04416770e-153]]), decimal = 12, err_msg = '', verbose = True |
---|
1882 | |
---|
1883 | def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): |
---|
1884 | """ |
---|
1885 | Raises an AssertionError if two items are not equal up to desired |
---|
1886 | precision. |
---|
1887 | |
---|
1888 | .. note:: It is recommended to use one of `assert_allclose`, |
---|
1889 | `assert_array_almost_equal_nulp` or `assert_array_max_ulp` |
---|
1890 | instead of this function for more consistent floating point |
---|
1891 | comparisons. |
---|
1892 | |
---|
1893 | The test verifies that the elements of ``actual`` and ``desired`` satisfy. |
---|
1894 | |
---|
1895 | ``abs(desired-actual) < 1.5 * 10**(-decimal)`` |
---|
1896 | |
---|
1897 | That is a looser test than originally documented, but agrees with what the |
---|
1898 | actual implementation in `assert_array_almost_equal` did up to rounding |
---|
1899 | vagaries. An exception is raised at conflicting values. For ndarrays this |
---|
1900 | delegates to assert_array_almost_equal |
---|
1901 | |
---|
1902 | Parameters |
---|
1903 | ---------- |
---|
1904 | actual : array_like |
---|
1905 | The object to check. |
---|
1906 | desired : array_like |
---|
1907 | The expected object. |
---|
1908 | decimal : int, optional |
---|
1909 | Desired precision, default is 7. |
---|
1910 | err_msg : str, optional |
---|
1911 | The error message to be printed in case of failure. |
---|
1912 | verbose : bool, optional |
---|
1913 | If True, the conflicting values are appended to the error message. |
---|
1914 | |
---|
1915 | Raises |
---|
1916 | ------ |
---|
1917 | AssertionError |
---|
1918 | If actual and desired are not equal up to specified precision. |
---|
1919 | |
---|
1920 | See Also |
---|
1921 | -------- |
---|
1922 | assert_allclose: Compare two array_like objects for equality with desired |
---|
1923 | relative and/or absolute precision. |
---|
1924 | assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal |
---|
1925 | |
---|
1926 | Examples |
---|
1927 | -------- |
---|
1928 | >>> import numpy.testing as npt |
---|
1929 | >>> npt.assert_almost_equal(2.3333333333333, 2.33333334) |
---|
1930 | >>> npt.assert_almost_equal(2.3333333333333, 2.33333334, decimal=10) |
---|
1931 | ... |
---|
1932 | <type 'exceptions.AssertionError'>: |
---|
1933 | Items are not equal: |
---|
1934 | ACTUAL: 2.3333333333333002 |
---|
1935 | DESIRED: 2.3333333399999998 |
---|
1936 | |
---|
1937 | >>> npt.assert_almost_equal(np.array([1.0,2.3333333333333]), |
---|
1938 | ... np.array([1.0,2.33333334]), decimal=9) |
---|
1939 | ... |
---|
1940 | <type 'exceptions.AssertionError'>: |
---|
1941 | Arrays are not almost equal |
---|
1942 | <BLANKLINE> |
---|
1943 | (mismatch 50.0%) |
---|
1944 | x: array([ 1. , 2.33333333]) |
---|
1945 | y: array([ 1. , 2.33333334]) |
---|
1946 | |
---|
1947 | """ |
---|
1948 | __tracebackhide__ = True # Hide traceback for py.test |
---|
1949 | from numpy.core import ndarray |
---|
1950 | from numpy.lib import iscomplexobj, real, imag |
---|
1951 | |
---|
1952 | # Handle complex numbers: separate into real/imag to handle |
---|
1953 | # nan/inf/negative zero correctly |
---|
1954 | # XXX: catch ValueError for subclasses of ndarray where iscomplex fail |
---|
1955 | try: |
---|
1956 | usecomplex = iscomplexobj(actual) or iscomplexobj(desired) |
---|
1957 | except ValueError: |
---|
1958 | usecomplex = False |
---|
1959 | |
---|
1960 | def _build_err_msg(): |
---|
1961 | header = ('Arrays are not almost equal to %d decimals' % decimal) |
---|
1962 | return build_err_msg([actual, desired], err_msg, verbose=verbose, |
---|
1963 | header=header) |
---|
1964 | |
---|
1965 | if usecomplex: |
---|
1966 | if iscomplexobj(actual): |
---|
1967 | actualr = real(actual) |
---|
1968 | actuali = imag(actual) |
---|
1969 | else: |
---|
1970 | actualr = actual |
---|
1971 | actuali = 0 |
---|
1972 | if iscomplexobj(desired): |
---|
1973 | desiredr = real(desired) |
---|
1974 | desiredi = imag(desired) |
---|
1975 | else: |
---|
1976 | desiredr = desired |
---|
1977 | desiredi = 0 |
---|
1978 | try: |
---|
1979 | assert_almost_equal(actualr, desiredr, decimal=decimal) |
---|
1980 | assert_almost_equal(actuali, desiredi, decimal=decimal) |
---|
1981 | except AssertionError: |
---|
1982 | raise AssertionError(_build_err_msg()) |
---|
1983 | |
---|
1984 | if isinstance(actual, (ndarray, tuple, list)) \ |
---|
1985 | or isinstance(desired, (ndarray, tuple, list)): |
---|
1986 | > return assert_array_almost_equal(actual, desired, decimal, err_msg) |
---|
1987 | |
---|
1988 | __tracebackhide__ = True |
---|
1989 | _build_err_msg = <function assert_almost_equal.<locals>._build_err_msg at 0x10ea23048> |
---|
1990 | actual = matrix([[2.], |
---|
1991 | [1.]]) |
---|
1992 | decimal = 12 |
---|
1993 | desired = matrix([[4.47500444e-154], |
---|
1994 | [1.04416770e-153]]) |
---|
1995 | err_msg = '' |
---|
1996 | imag = <function imag at 0x103d8f620> |
---|
1997 | iscomplexobj = <function iscomplexobj at 0x103d8f7b8> |
---|
1998 | ndarray = <class 'numpy.ndarray'> |
---|
1999 | real = <function real at 0x103d8f598> |
---|
2000 | usecomplex = False |
---|
2001 | verbose = True |
---|
2002 | |
---|
2003 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/testing/_private/utils.py:568: |
---|
2004 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
2005 | |
---|
2006 | x = matrix([[2.], |
---|
2007 | [1.]]), y = matrix([[4.47500444e-154], |
---|
2008 | [1.04416770e-153]]), decimal = 12, err_msg = '', verbose = True |
---|
2009 | |
---|
2010 | def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True): |
---|
2011 | """ |
---|
2012 | Raises an AssertionError if two objects are not equal up to desired |
---|
2013 | precision. |
---|
2014 | |
---|
2015 | .. note:: It is recommended to use one of `assert_allclose`, |
---|
2016 | `assert_array_almost_equal_nulp` or `assert_array_max_ulp` |
---|
2017 | instead of this function for more consistent floating point |
---|
2018 | comparisons. |
---|
2019 | |
---|
2020 | The test verifies identical shapes and that the elements of ``actual`` and |
---|
2021 | ``desired`` satisfy. |
---|
2022 | |
---|
2023 | ``abs(desired-actual) < 1.5 * 10**(-decimal)`` |
---|
2024 | |
---|
2025 | That is a looser test than originally documented, but agrees with what the |
---|
2026 | actual implementation did up to rounding vagaries. An exception is raised |
---|
2027 | at shape mismatch or conflicting values. In contrast to the standard usage |
---|
2028 | in numpy, NaNs are compared like numbers, no assertion is raised if both |
---|
2029 | objects have NaNs in the same positions. |
---|
2030 | |
---|
2031 | Parameters |
---|
2032 | ---------- |
---|
2033 | x : array_like |
---|
2034 | The actual object to check. |
---|
2035 | y : array_like |
---|
2036 | The desired, expected object. |
---|
2037 | decimal : int, optional |
---|
2038 | Desired precision, default is 6. |
---|
2039 | err_msg : str, optional |
---|
2040 | The error message to be printed in case of failure. |
---|
2041 | verbose : bool, optional |
---|
2042 | If True, the conflicting values are appended to the error message. |
---|
2043 | |
---|
2044 | Raises |
---|
2045 | ------ |
---|
2046 | AssertionError |
---|
2047 | If actual and desired are not equal up to specified precision. |
---|
2048 | |
---|
2049 | See Also |
---|
2050 | -------- |
---|
2051 | assert_allclose: Compare two array_like objects for equality with desired |
---|
2052 | relative and/or absolute precision. |
---|
2053 | assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal |
---|
2054 | |
---|
2055 | Examples |
---|
2056 | -------- |
---|
2057 | the first assert does not raise an exception |
---|
2058 | |
---|
2059 | >>> np.testing.assert_array_almost_equal([1.0,2.333,np.nan], |
---|
2060 | [1.0,2.333,np.nan]) |
---|
2061 | |
---|
2062 | >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], |
---|
2063 | ... [1.0,2.33339,np.nan], decimal=5) |
---|
2064 | ... |
---|
2065 | <type 'exceptions.AssertionError'>: |
---|
2066 | AssertionError: |
---|
2067 | Arrays are not almost equal |
---|
2068 | <BLANKLINE> |
---|
2069 | (mismatch 50.0%) |
---|
2070 | x: array([ 1. , 2.33333, NaN]) |
---|
2071 | y: array([ 1. , 2.33339, NaN]) |
---|
2072 | |
---|
2073 | >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], |
---|
2074 | ... [1.0,2.33333, 5], decimal=5) |
---|
2075 | <type 'exceptions.ValueError'>: |
---|
2076 | ValueError: |
---|
2077 | Arrays are not almost equal |
---|
2078 | x: array([ 1. , 2.33333, NaN]) |
---|
2079 | y: array([ 1. , 2.33333, 5. ]) |
---|
2080 | |
---|
2081 | """ |
---|
2082 | __tracebackhide__ = True # Hide traceback for py.test |
---|
2083 | from numpy.core import around, number, float_, result_type, array |
---|
2084 | from numpy.core.numerictypes import issubdtype |
---|
2085 | from numpy.core.fromnumeric import any as npany |
---|
2086 | |
---|
2087 | def compare(x, y): |
---|
2088 | try: |
---|
2089 | if npany(gisinf(x)) or npany( gisinf(y)): |
---|
2090 | xinfid = gisinf(x) |
---|
2091 | yinfid = gisinf(y) |
---|
2092 | if not (xinfid == yinfid).all(): |
---|
2093 | return False |
---|
2094 | # if one item, x and y is +- inf |
---|
2095 | if x.size == y.size == 1: |
---|
2096 | return x == y |
---|
2097 | x = x[~xinfid] |
---|
2098 | y = y[~yinfid] |
---|
2099 | except (TypeError, NotImplementedError): |
---|
2100 | pass |
---|
2101 | |
---|
2102 | # make sure y is an inexact type to avoid abs(MIN_INT); will cause |
---|
2103 | # casting of x later. |
---|
2104 | dtype = result_type(y, 1.) |
---|
2105 | y = array(y, dtype=dtype, copy=False, subok=True) |
---|
2106 | z = abs(x - y) |
---|
2107 | |
---|
2108 | if not issubdtype(z.dtype, number): |
---|
2109 | z = z.astype(float_) # handle object arrays |
---|
2110 | |
---|
2111 | return z < 1.5 * 10.0**(-decimal) |
---|
2112 | |
---|
2113 | assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose, |
---|
2114 | header=('Arrays are not almost equal to %d decimals' % decimal), |
---|
2115 | > precision=decimal) |
---|
2116 | |
---|
2117 | __tracebackhide__ = True |
---|
2118 | around = <function around at 0x10385c8c8> |
---|
2119 | array = <built-in function array> |
---|
2120 | compare = <function assert_array_almost_equal.<locals>.compare at 0x10ea230d0> |
---|
2121 | decimal = 12 |
---|
2122 | err_msg = '' |
---|
2123 | float_ = <class 'numpy.float64'> |
---|
2124 | issubdtype = <function issubdtype at 0x10371cae8> |
---|
2125 | npany = <function any at 0x10385c2f0> |
---|
2126 | number = <class 'numpy.number'> |
---|
2127 | result_type = <built-in function result_type> |
---|
2128 | verbose = True |
---|
2129 | x = matrix([[2.], |
---|
2130 | [1.]]) |
---|
2131 | y = matrix([[4.47500444e-154], |
---|
2132 | [1.04416770e-153]]) |
---|
2133 | |
---|
2134 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/testing/_private/utils.py:964: |
---|
2135 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
2136 | |
---|
2137 | comparison = <function assert_array_almost_equal.<locals>.compare at 0x10ea230d0>, x = matrix([[2., 1.]]), y = matrix([[4.47500444e-154, 1.04416770e-153]]), err_msg = '', verbose = True |
---|
2138 | header = 'Arrays are not almost equal to 12 decimals', precision = 12, equal_nan = True, equal_inf = True |
---|
2139 | |
---|
2140 | def assert_array_compare(comparison, x, y, err_msg='', verbose=True, |
---|
2141 | header='', precision=6, equal_nan=True, |
---|
2142 | equal_inf=True): |
---|
2143 | __tracebackhide__ = True # Hide traceback for py.test |
---|
2144 | from numpy.core import array, isnan, inf, bool_ |
---|
2145 | x = array(x, copy=False, subok=True) |
---|
2146 | y = array(y, copy=False, subok=True) |
---|
2147 | |
---|
2148 | def isnumber(x): |
---|
2149 | return x.dtype.char in '?bhilqpBHILQPefdgFDG' |
---|
2150 | |
---|
2151 | def istime(x): |
---|
2152 | return x.dtype.char in "Mm" |
---|
2153 | |
---|
2154 | def func_assert_same_pos(x, y, func=isnan, hasval='nan'): |
---|
2155 | """Handling nan/inf: combine results of running func on x and y, |
---|
2156 | checking that they are True at the same locations.""" |
---|
2157 | # Both the != True comparison here and the cast to bool_ at |
---|
2158 | # the end are done to deal with `masked`, which cannot be |
---|
2159 | # compared usefully, and for which .all() yields masked. |
---|
2160 | x_id = func(x) |
---|
2161 | y_id = func(y) |
---|
2162 | if (x_id == y_id).all() != True: |
---|
2163 | msg = build_err_msg([x, y], |
---|
2164 | err_msg + '\nx and y %s location mismatch:' |
---|
2165 | % (hasval), verbose=verbose, header=header, |
---|
2166 | names=('x', 'y'), precision=precision) |
---|
2167 | raise AssertionError(msg) |
---|
2168 | # If there is a scalar, then here we know the array has the same |
---|
2169 | # flag as it everywhere, so we should return the scalar flag. |
---|
2170 | if x_id.ndim == 0: |
---|
2171 | return bool_(x_id) |
---|
2172 | elif y_id.ndim == 0: |
---|
2173 | return bool_(y_id) |
---|
2174 | else: |
---|
2175 | return y_id |
---|
2176 | |
---|
2177 | try: |
---|
2178 | cond = (x.shape == () or y.shape == ()) or x.shape == y.shape |
---|
2179 | if not cond: |
---|
2180 | msg = build_err_msg([x, y], |
---|
2181 | err_msg |
---|
2182 | + '\n(shapes %s, %s mismatch)' % (x.shape, |
---|
2183 | y.shape), |
---|
2184 | verbose=verbose, header=header, |
---|
2185 | names=('x', 'y'), precision=precision) |
---|
2186 | raise AssertionError(msg) |
---|
2187 | |
---|
2188 | flagged = bool_(False) |
---|
2189 | if isnumber(x) and isnumber(y): |
---|
2190 | if equal_nan: |
---|
2191 | flagged = func_assert_same_pos(x, y, func=isnan, hasval='nan') |
---|
2192 | |
---|
2193 | if equal_inf: |
---|
2194 | flagged |= func_assert_same_pos(x, y, |
---|
2195 | func=lambda xy: xy == +inf, |
---|
2196 | hasval='+inf') |
---|
2197 | flagged |= func_assert_same_pos(x, y, |
---|
2198 | func=lambda xy: xy == -inf, |
---|
2199 | hasval='-inf') |
---|
2200 | |
---|
2201 | elif istime(x) and istime(y): |
---|
2202 | # If one is datetime64 and the other timedelta64 there is no point |
---|
2203 | if equal_nan and x.dtype.type == y.dtype.type: |
---|
2204 | flagged = func_assert_same_pos(x, y, func=isnat, hasval="NaT") |
---|
2205 | |
---|
2206 | if flagged.ndim > 0: |
---|
2207 | x, y = x[~flagged], y[~flagged] |
---|
2208 | # Only do the comparison if actual values are left |
---|
2209 | if x.size == 0: |
---|
2210 | return |
---|
2211 | elif flagged: |
---|
2212 | # no sense doing comparison if everything is flagged. |
---|
2213 | return |
---|
2214 | |
---|
2215 | val = comparison(x, y) |
---|
2216 | |
---|
2217 | if isinstance(val, bool): |
---|
2218 | cond = val |
---|
2219 | reduced = [0] |
---|
2220 | else: |
---|
2221 | reduced = val.ravel() |
---|
2222 | cond = reduced.all() |
---|
2223 | reduced = reduced.tolist() |
---|
2224 | # The below comparison is a hack to ensure that fully masked |
---|
2225 | # results, for which val.ravel().all() returns np.ma.masked, |
---|
2226 | # do not trigger a failure (np.ma.masked != True evaluates as |
---|
2227 | # np.ma.masked, which is falsy). |
---|
2228 | if cond != True: |
---|
2229 | match = 100-100.0*reduced.count(1)/len(reduced) |
---|
2230 | msg = build_err_msg([x, y], |
---|
2231 | err_msg |
---|
2232 | + '\n(mismatch %s%%)' % (match,), |
---|
2233 | verbose=verbose, header=header, |
---|
2234 | names=('x', 'y'), precision=precision) |
---|
2235 | > raise AssertionError(msg) |
---|
2236 | E AssertionError: |
---|
2237 | E Arrays are not almost equal to 12 decimals |
---|
2238 | E |
---|
2239 | E (mismatch 100.0%) |
---|
2240 | E x: matrix([[2., 1.]]) |
---|
2241 | E y: matrix([[4.475004438720e-154, 1.044167702368e-153]]) |
---|
2242 | |
---|
2243 | __tracebackhide__ = True |
---|
2244 | array = <built-in function array> |
---|
2245 | bool_ = <class 'numpy.bool_'> |
---|
2246 | comparison = <function assert_array_almost_equal.<locals>.compare at 0x10ea230d0> |
---|
2247 | cond = False |
---|
2248 | equal_inf = True |
---|
2249 | equal_nan = True |
---|
2250 | err_msg = '' |
---|
2251 | flagged = matrix([[False], |
---|
2252 | [False]]) |
---|
2253 | func_assert_same_pos = <function assert_array_compare.<locals>.func_assert_same_pos at 0x10ea232f0> |
---|
2254 | header = 'Arrays are not almost equal to 12 decimals' |
---|
2255 | inf = inf |
---|
2256 | isnan = <ufunc 'isnan'> |
---|
2257 | isnumber = <function assert_array_compare.<locals>.isnumber at 0x10ea23ea0> |
---|
2258 | istime = <function assert_array_compare.<locals>.istime at 0x10ea23400> |
---|
2259 | match = 100.0 |
---|
2260 | msg = '\nArrays are not almost equal to 12 decimals\n\n(mismatch 100.0%)\n x: matrix([[2., 1.]])\n y: matrix([[4.475004438720e-154, 1.044167702368e-153]])' |
---|
2261 | precision = 12 |
---|
2262 | reduced = [[False, False]] |
---|
2263 | val = matrix([[False, False]]) |
---|
2264 | verbose = True |
---|
2265 | x = matrix([[2., 1.]]) |
---|
2266 | y = matrix([[4.47500444e-154, 1.04416770e-153]]) |
---|
2267 | |
---|
2268 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/testing/_private/utils.py:780: AssertionError |
---|
2269 | |
---|
2270 | During handling of the above exception, another exception occurred: |
---|
2271 | |
---|
2272 | self = <numpy.matrixlib.tests.test_matrix_linalg.TestLstsqMatrix object at 0x10d8f7898> |
---|
2273 | |
---|
2274 | def test_sq_cases(self): |
---|
2275 | self.check_cases(require={'square'}, |
---|
2276 | > exclude={'generalized', 'size-0'}) |
---|
2277 | |
---|
2278 | self = <numpy.matrixlib.tests.test_matrix_linalg.TestLstsqMatrix object at 0x10d8f7898> |
---|
2279 | |
---|
2280 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py:361: |
---|
2281 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |
---|
2282 | |
---|
2283 | self = <numpy.matrixlib.tests.test_matrix_linalg.TestLstsqMatrix object at 0x10d8f7898>, require = {'square'}, exclude = {'generalized', 'size-0'} |
---|
2284 | |
---|
2285 | def check_cases(self, require=set(), exclude=set()): |
---|
2286 | """ |
---|
2287 | Run func on each of the cases with all of the tags in require, and none |
---|
2288 | of the tags in exclude |
---|
2289 | """ |
---|
2290 | for case in self.TEST_CASES: |
---|
2291 | # filter by require and exclude |
---|
2292 | if case.tags & require != require: |
---|
2293 | continue |
---|
2294 | if case.tags & exclude: |
---|
2295 | continue |
---|
2296 | |
---|
2297 | try: |
---|
2298 | case.check(self.do) |
---|
2299 | except Exception: |
---|
2300 | msg = "In test case: %r\n\n" % case |
---|
2301 | msg += traceback.format_exc() |
---|
2302 | > raise AssertionError(msg) |
---|
2303 | E AssertionError: In test case: <LinalgCase: matrix_b_only> |
---|
2304 | E |
---|
2305 | E Traceback (most recent call last): |
---|
2306 | E File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py", line 350, in check_cases |
---|
2307 | E case.check(self.do) |
---|
2308 | E File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py", line 85, in check |
---|
2309 | E do(self.a, self.b, tags=self.tags) |
---|
2310 | E File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py", line 887, in do |
---|
2311 | E assert_almost_equal(b, dot(a, x)) |
---|
2312 | E File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py", line 41, in assert_almost_equal |
---|
2313 | E old_assert_almost_equal(a, b, decimal=decimal, **kw) |
---|
2314 | E File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/testing/_private/utils.py", line 568, in assert_almost_equal |
---|
2315 | E return assert_array_almost_equal(actual, desired, decimal, err_msg) |
---|
2316 | E File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/testing/_private/utils.py", line 964, in assert_array_almost_equal |
---|
2317 | E precision=decimal) |
---|
2318 | E File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/testing/_private/utils.py", line 780, in assert_array_compare |
---|
2319 | E raise AssertionError(msg) |
---|
2320 | E AssertionError: |
---|
2321 | E Arrays are not almost equal to 12 decimals |
---|
2322 | E |
---|
2323 | E (mismatch 100.0%) |
---|
2324 | E x: matrix([[2., 1.]]) |
---|
2325 | E y: matrix([[4.475004438720e-154, 1.044167702368e-153]]) |
---|
2326 | |
---|
2327 | case = <LinalgCase: matrix_b_only> |
---|
2328 | exclude = {'generalized', 'size-0'} |
---|
2329 | msg = 'In test case: <LinalgCase: matrix_b_only>\n\nTraceback (most recent call last):\n File "/opt/local/Library/Framework...o 12 decimals\n\n(mismatch 100.0%)\n x: matrix([[2., 1.]])\n y: matrix([[4.475004438720e-154, 1.044167702368e-153]])\n' |
---|
2330 | require = {'square'} |
---|
2331 | self = <numpy.matrixlib.tests.test_matrix_linalg.TestLstsqMatrix object at 0x10d8f7898> |
---|
2332 | |
---|
2333 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/linalg/tests/test_linalg.py:354: AssertionError |
---|
2334 | ------------------------------------------------------------------------------------------- Captured stderr call -------------------------------------------------------------------------------------------- |
---|
2335 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438804480) failed (error code=3) |
---|
2336 | *** error: can't allocate region |
---|
2337 | *** set a breakpoint in malloc_error_break to debug |
---|
2338 | init_dgelsd failed init |
---|
2339 | _________________________________________________________________________________________ TestFitting.test_chebfit __________________________________________________________________________________________ |
---|
2340 | |
---|
2341 | self = <numpy.polynomial.tests.test_chebyshev.TestFitting object at 0x10d974ba8> |
---|
2342 | |
---|
2343 | def test_chebfit(self): |
---|
2344 | def f(x): |
---|
2345 | return x*(x - 1)*(x - 2) |
---|
2346 | |
---|
2347 | def f2(x): |
---|
2348 | return x**4 + x**2 + 1 |
---|
2349 | |
---|
2350 | # Test exceptions |
---|
2351 | assert_raises(ValueError, cheb.chebfit, [1], [1], -1) |
---|
2352 | assert_raises(TypeError, cheb.chebfit, [[1]], [1], 0) |
---|
2353 | assert_raises(TypeError, cheb.chebfit, [], [1], 0) |
---|
2354 | assert_raises(TypeError, cheb.chebfit, [1], [[[1]]], 0) |
---|
2355 | assert_raises(TypeError, cheb.chebfit, [1, 2], [1], 0) |
---|
2356 | assert_raises(TypeError, cheb.chebfit, [1], [1, 2], 0) |
---|
2357 | assert_raises(TypeError, cheb.chebfit, [1], [1], 0, w=[[1]]) |
---|
2358 | assert_raises(TypeError, cheb.chebfit, [1], [1], 0, w=[1, 1]) |
---|
2359 | assert_raises(ValueError, cheb.chebfit, [1], [1], [-1,]) |
---|
2360 | assert_raises(ValueError, cheb.chebfit, [1], [1], [2, -1, 6]) |
---|
2361 | assert_raises(TypeError, cheb.chebfit, [1], [1], []) |
---|
2362 | |
---|
2363 | # Test fit |
---|
2364 | x = np.linspace(0, 2) |
---|
2365 | y = f(x) |
---|
2366 | # |
---|
2367 | coef3 = cheb.chebfit(x, y, 3) |
---|
2368 | assert_equal(len(coef3), 4) |
---|
2369 | > assert_almost_equal(cheb.chebval(x, coef3), y) |
---|
2370 | E AssertionError: |
---|
2371 | E Arrays are not almost equal to 7 decimals |
---|
2372 | E |
---|
2373 | E (mismatch 100.0%) |
---|
2374 | E x: array([ -13.9110103, -21.5538453, -28.9493612, -35.9900612, |
---|
2375 | E -42.5684484, -48.577026 , -53.9082971, -58.4547649, |
---|
2376 | E -62.1089326, -64.7633034, -66.3103803, -66.6426665,... |
---|
2377 | E y: array([ 0. , 0.0767027, 0.1438176, 0.2017527, 0.2509159, |
---|
2378 | E 0.2917152, 0.3245586, 0.3498542, 0.3680099, 0.3794337, |
---|
2379 | E 0.3845337, 0.3837177, 0.3773938, 0.36597 , 0.3498542,... |
---|
2380 | |
---|
2381 | coef3 = array([ 7.07106781, 8.20651807, 20.98207809, 65.86924807]) |
---|
2382 | f = <function TestFitting.test_chebfit.<locals>.f at 0x10ea23488> |
---|
2383 | f2 = <function TestFitting.test_chebfit.<locals>.f2 at 0x10d9eb620> |
---|
2384 | self = <numpy.polynomial.tests.test_chebyshev.TestFitting object at 0x10d974ba8> |
---|
2385 | x = array([0. , 0.04081633, 0.08163265, 0.12244898, 0.16326531, |
---|
2386 | 0.20408163, 0.24489796, 0.28571429, 0.326530...06, 1.67346939, 1.71428571, 1.75510204, 1.79591837, |
---|
2387 | 1.83673469, 1.87755102, 1.91836735, 1.95918367, 2. ]) |
---|
2388 | y = array([ 0. , 0.07670273, 0.14381763, 0.20175267, 0.25091586, |
---|
2389 | 0.29171519, 0.32455864, 0.34985423, ...800993, -0.34985423, -0.32455864, -0.29171519, |
---|
2390 | -0.25091586, -0.20175267, -0.14381763, -0.07670273, 0. ]) |
---|
2391 | |
---|
2392 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/polynomial/tests/test_chebyshev.py:427: AssertionError |
---|
2393 | ------------------------------------------------------------------------------------------- Captured stderr call -------------------------------------------------------------------------------------------- |
---|
2394 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438812672) failed (error code=3) |
---|
2395 | *** error: can't allocate region |
---|
2396 | *** set a breakpoint in malloc_error_break to debug |
---|
2397 | init_dgelsd failed init |
---|
2398 | ___________________________________________________________________________________________ test_fit[Polynomial] ____________________________________________________________________________________________ |
---|
2399 | |
---|
2400 | Poly = <class 'numpy.polynomial.polynomial.Polynomial'> |
---|
2401 | |
---|
2402 | def test_fit(Poly): |
---|
2403 | |
---|
2404 | def f(x): |
---|
2405 | return x*(x - 1)*(x - 2) |
---|
2406 | x = np.linspace(0, 3) |
---|
2407 | y = f(x) |
---|
2408 | |
---|
2409 | # check default value of domain and window |
---|
2410 | p = Poly.fit(x, y, 3) |
---|
2411 | assert_almost_equal(p.domain, [0, 3]) |
---|
2412 | > assert_almost_equal(p(x), y) |
---|
2413 | E AssertionError: |
---|
2414 | E Arrays are not almost equal to 7 decimals |
---|
2415 | E |
---|
2416 | E (mismatch 100.0%) |
---|
2417 | E x: array([ 3.3609449, 3.6010559, 3.8249429, 4.033763 , 4.2286731, |
---|
2418 | E 4.41083 , 4.5813906, 4.741512 , 4.892351 , 5.0350645, |
---|
2419 | E 5.1708095, 5.3007428, 5.4260214, 5.5478022, 5.6672422,... |
---|
2420 | E y: array([ 0. , 0.1114332, 0.2017527, 0.2723355, 0.3245586, |
---|
2421 | E 0.3597991, 0.3794337, 0.3848397, 0.3773938, 0.3584731, |
---|
2422 | E 0.3294546, 0.2917152, 0.2466319, 0.1955818, 0.1399417,... |
---|
2423 | |
---|
2424 | Poly = <class 'numpy.polynomial.polynomial.Polynomial'> |
---|
2425 | f = <function test_fit.<locals>.f at 0x10d9eb158> |
---|
2426 | p = Polynomial([7.07106781, 4.16496564, 3.29047206, 2.83562932], domain=[0., 3.], window=[-1., 1.]) |
---|
2427 | x = array([0. , 0.06122449, 0.12244898, 0.18367347, 0.24489796, |
---|
2428 | 0.30612245, 0.36734694, 0.42857143, 0.489795...59, 2.51020408, 2.57142857, 2.63265306, 2.69387755, |
---|
2429 | 2.75510204, 2.81632653, 2.87755102, 2.93877551, 3. ]) |
---|
2430 | y = array([ 0. , 0.11143316, 0.20175267, 0.27233551, 0.32455864, |
---|
2431 | 0.35979906, 0.37943374, 0.38483965, ...414309, 2.3090379 , 2.71927513, 3.16623176, |
---|
2432 | 3.65128475, 4.1758111 , 4.74118777, 5.34879174, 6. ]) |
---|
2433 | |
---|
2434 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/polynomial/tests/test_classes.py:146: AssertionError |
---|
2435 | ------------------------------------------------------------------------------------------- Captured stderr call -------------------------------------------------------------------------------------------- |
---|
2436 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438808576) failed (error code=3) |
---|
2437 | *** error: can't allocate region |
---|
2438 | *** set a breakpoint in malloc_error_break to debug |
---|
2439 | init_dgelsd failed init |
---|
2440 | ____________________________________________________________________________________________ test_fit[Legendre] _____________________________________________________________________________________________ |
---|
2441 | |
---|
2442 | Poly = <class 'numpy.polynomial.legendre.Legendre'> |
---|
2443 | |
---|
2444 | def test_fit(Poly): |
---|
2445 | |
---|
2446 | def f(x): |
---|
2447 | return x*(x - 1)*(x - 2) |
---|
2448 | x = np.linspace(0, 3) |
---|
2449 | y = f(x) |
---|
2450 | |
---|
2451 | # check default value of domain and window |
---|
2452 | p = Poly.fit(x, y, 3) |
---|
2453 | assert_almost_equal(p.domain, [0, 3]) |
---|
2454 | > assert_almost_equal(p(x), y) |
---|
2455 | E AssertionError: |
---|
2456 | E Arrays are not almost equal to 7 decimals |
---|
2457 | E |
---|
2458 | E (mismatch 100.0%) |
---|
2459 | E x: array([ 3.3558378, 3.7920559, 4.176589 , 4.5123368, 4.8021987, |
---|
2460 | E 5.0490744, 5.2558636, 5.4254658, 5.5607806, 5.6647077, |
---|
2461 | E 5.7401467, 5.7899972, 5.8171587, 5.824531 , 5.8150135,... |
---|
2462 | E y: array([ 0. , 0.1114332, 0.2017527, 0.2723355, 0.3245586, |
---|
2463 | E 0.3597991, 0.3794337, 0.3848397, 0.3773938, 0.3584731, |
---|
2464 | E 0.3294546, 0.2917152, 0.2466319, 0.1955818, 0.1399417,... |
---|
2465 | |
---|
2466 | Poly = <class 'numpy.polynomial.legendre.Legendre'> |
---|
2467 | f = <function test_fit.<locals>.f at 0x10d9eb950> |
---|
2468 | p = Legendre([7.07106781, 4.16496564, 3.29253795, 2.84280232], domain=[0., 3.], window=[-1., 1.]) |
---|
2469 | x = array([0. , 0.06122449, 0.12244898, 0.18367347, 0.24489796, |
---|
2470 | 0.30612245, 0.36734694, 0.42857143, 0.489795...59, 2.51020408, 2.57142857, 2.63265306, 2.69387755, |
---|
2471 | 2.75510204, 2.81632653, 2.87755102, 2.93877551, 3. ]) |
---|
2472 | y = array([ 0. , 0.11143316, 0.20175267, 0.27233551, 0.32455864, |
---|
2473 | 0.35979906, 0.37943374, 0.38483965, ...414309, 2.3090379 , 2.71927513, 3.16623176, |
---|
2474 | 3.65128475, 4.1758111 , 4.74118777, 5.34879174, 6. ]) |
---|
2475 | |
---|
2476 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/polynomial/tests/test_classes.py:146: AssertionError |
---|
2477 | ------------------------------------------------------------------------------------------- Captured stderr call -------------------------------------------------------------------------------------------- |
---|
2478 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438808576) failed (error code=3) |
---|
2479 | *** error: can't allocate region |
---|
2480 | *** set a breakpoint in malloc_error_break to debug |
---|
2481 | init_dgelsd failed init |
---|
2482 | ____________________________________________________________________________________________ test_fit[Chebyshev] ____________________________________________________________________________________________ |
---|
2483 | |
---|
2484 | Poly = <class 'numpy.polynomial.chebyshev.Chebyshev'> |
---|
2485 | |
---|
2486 | def test_fit(Poly): |
---|
2487 | |
---|
2488 | def f(x): |
---|
2489 | return x*(x - 1)*(x - 2) |
---|
2490 | x = np.linspace(0, 3) |
---|
2491 | y = f(x) |
---|
2492 | |
---|
2493 | # check default value of domain and window |
---|
2494 | p = Poly.fit(x, y, 3) |
---|
2495 | assert_almost_equal(p.domain, [0, 3]) |
---|
2496 | > assert_almost_equal(p(x), y) |
---|
2497 | E AssertionError: |
---|
2498 | E Arrays are not almost equal to 7 decimals |
---|
2499 | E |
---|
2500 | E (mismatch 100.0%) |
---|
2501 | E x: array([ 2.8048058, 3.9280131, 4.8923547, 5.7059778, 6.3770296, |
---|
2502 | E 6.9136571, 7.3240076, 7.6162282, 7.798466 , 7.8788683, |
---|
2503 | E 7.8655822, 7.7667548, 7.5905333, 7.3450649, 7.0384967,... |
---|
2504 | E y: array([ 0. , 0.1114332, 0.2017527, 0.2723355, 0.3245586, |
---|
2505 | E 0.3597991, 0.3794337, 0.3848397, 0.3773938, 0.3584731, |
---|
2506 | E 0.3294546, 0.2917152, 0.2466319, 0.1955818, 0.1399417,... |
---|
2507 | |
---|
2508 | Poly = <class 'numpy.polynomial.chebyshev.Chebyshev'> |
---|
2509 | f = <function test_fit.<locals>.f at 0x10ea1f400> |
---|
2510 | p = Chebyshev([7.07106781, 4.16496564, 4.89091712, 4.99221346], domain=[0., 3.], window=[-1., 1.]) |
---|
2511 | x = array([0. , 0.06122449, 0.12244898, 0.18367347, 0.24489796, |
---|
2512 | 0.30612245, 0.36734694, 0.42857143, 0.489795...59, 2.51020408, 2.57142857, 2.63265306, 2.69387755, |
---|
2513 | 2.75510204, 2.81632653, 2.87755102, 2.93877551, 3. ]) |
---|
2514 | y = array([ 0. , 0.11143316, 0.20175267, 0.27233551, 0.32455864, |
---|
2515 | 0.35979906, 0.37943374, 0.38483965, ...414309, 2.3090379 , 2.71927513, 3.16623176, |
---|
2516 | 3.65128475, 4.1758111 , 4.74118777, 5.34879174, 6. ]) |
---|
2517 | |
---|
2518 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/polynomial/tests/test_classes.py:146: AssertionError |
---|
2519 | ------------------------------------------------------------------------------------------- Captured stderr call -------------------------------------------------------------------------------------------- |
---|
2520 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438808576) failed (error code=3) |
---|
2521 | *** error: can't allocate region |
---|
2522 | *** set a breakpoint in malloc_error_break to debug |
---|
2523 | init_dgelsd failed init |
---|
2524 | ____________________________________________________________________________________________ test_fit[Laguerre] _____________________________________________________________________________________________ |
---|
2525 | |
---|
2526 | Poly = <class 'numpy.polynomial.laguerre.Laguerre'> |
---|
2527 | |
---|
2528 | def test_fit(Poly): |
---|
2529 | |
---|
2530 | def f(x): |
---|
2531 | return x*(x - 1)*(x - 2) |
---|
2532 | x = np.linspace(0, 3) |
---|
2533 | y = f(x) |
---|
2534 | |
---|
2535 | # check default value of domain and window |
---|
2536 | p = Poly.fit(x, y, 3) |
---|
2537 | assert_almost_equal(p.domain, [0, 3]) |
---|
2538 | > assert_almost_equal(p(x), y) |
---|
2539 | E AssertionError: |
---|
2540 | E Arrays are not almost equal to 7 decimals |
---|
2541 | E |
---|
2542 | E (mismatch 100.0%) |
---|
2543 | E x: array([18.0443235, 17.6113131, 17.1840627, 16.7625426, 16.3467228, |
---|
2544 | E 15.9365734, 15.5320646, 15.1331665, 14.7398491, 14.3520826, |
---|
2545 | E 13.9698372, 13.5930829, 13.2217898, 12.8559282, 12.4954679,... |
---|
2546 | E y: array([ 0. , 0.1114332, 0.2017527, 0.2723355, 0.3245586, |
---|
2547 | E 0.3597991, 0.3794337, 0.3848397, 0.3773938, 0.3584731, |
---|
2548 | E 0.3294546, 0.2917152, 0.2466319, 0.1955818, 0.1399417,... |
---|
2549 | |
---|
2550 | Poly = <class 'numpy.polynomial.laguerre.Laguerre'> |
---|
2551 | f = <function test_fit.<locals>.f at 0x10ea1f048> |
---|
2552 | p = Laguerre([7.07106781, 4.10325903, 3.35412731, 3.51586935], domain=[0., 3.], window=[0., 1.]) |
---|
2553 | x = array([0. , 0.06122449, 0.12244898, 0.18367347, 0.24489796, |
---|
2554 | 0.30612245, 0.36734694, 0.42857143, 0.489795...59, 2.51020408, 2.57142857, 2.63265306, 2.69387755, |
---|
2555 | 2.75510204, 2.81632653, 2.87755102, 2.93877551, 3. ]) |
---|
2556 | y = array([ 0. , 0.11143316, 0.20175267, 0.27233551, 0.32455864, |
---|
2557 | 0.35979906, 0.37943374, 0.38483965, ...414309, 2.3090379 , 2.71927513, 3.16623176, |
---|
2558 | 3.65128475, 4.1758111 , 4.74118777, 5.34879174, 6. ]) |
---|
2559 | |
---|
2560 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/polynomial/tests/test_classes.py:146: AssertionError |
---|
2561 | ------------------------------------------------------------------------------------------- Captured stderr call -------------------------------------------------------------------------------------------- |
---|
2562 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438808576) failed (error code=3) |
---|
2563 | *** error: can't allocate region |
---|
2564 | *** set a breakpoint in malloc_error_break to debug |
---|
2565 | init_dgelsd failed init |
---|
2566 | _____________________________________________________________________________________________ test_fit[Hermite] _____________________________________________________________________________________________ |
---|
2567 | |
---|
2568 | Poly = <class 'numpy.polynomial.hermite.Hermite'> |
---|
2569 | |
---|
2570 | def test_fit(Poly): |
---|
2571 | |
---|
2572 | def f(x): |
---|
2573 | return x*(x - 1)*(x - 2) |
---|
2574 | x = np.linspace(0, 3) |
---|
2575 | y = f(x) |
---|
2576 | |
---|
2577 | # check default value of domain and window |
---|
2578 | p = Poly.fit(x, y, 3) |
---|
2579 | assert_almost_equal(p.domain, [0, 3]) |
---|
2580 | > assert_almost_equal(p(x), y) |
---|
2581 | E AssertionError: |
---|
2582 | E Arrays are not almost equal to 7 decimals |
---|
2583 | E |
---|
2584 | E (mismatch 100.0%) |
---|
2585 | E x: array([ 132.2039282, 143.5167037, 152.6160237, 159.6016254, |
---|
2586 | E 164.5732461, 167.630623 , 168.8734935, 168.4015948, |
---|
2587 | E 166.314664 , 162.7124386, 157.6946558, 151.3610527,... |
---|
2588 | E y: array([ 0. , 0.1114332, 0.2017527, 0.2723355, 0.3245586, |
---|
2589 | E 0.3597991, 0.3794337, 0.3848397, 0.3773938, 0.3584731, |
---|
2590 | E 0.3294546, 0.2917152, 0.2466319, 0.1955818, 0.1399417,... |
---|
2591 | |
---|
2592 | Poly = <class 'numpy.polynomial.hermite.Hermite'> |
---|
2593 | f = <function test_fit.<locals>.f at 0x10ea1fd90> |
---|
2594 | p = Hermite([ 7.07106781, 8.32993128, 9.78183425, 30.5572636 ], domain=[0., 3.], window=[-1., 1.]) |
---|
2595 | x = array([0. , 0.06122449, 0.12244898, 0.18367347, 0.24489796, |
---|
2596 | 0.30612245, 0.36734694, 0.42857143, 0.489795...59, 2.51020408, 2.57142857, 2.63265306, 2.69387755, |
---|
2597 | 2.75510204, 2.81632653, 2.87755102, 2.93877551, 3. ]) |
---|
2598 | y = array([ 0. , 0.11143316, 0.20175267, 0.27233551, 0.32455864, |
---|
2599 | 0.35979906, 0.37943374, 0.38483965, ...414309, 2.3090379 , 2.71927513, 3.16623176, |
---|
2600 | 3.65128475, 4.1758111 , 4.74118777, 5.34879174, 6. ]) |
---|
2601 | |
---|
2602 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/polynomial/tests/test_classes.py:146: AssertionError |
---|
2603 | ------------------------------------------------------------------------------------------- Captured stderr call -------------------------------------------------------------------------------------------- |
---|
2604 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438808576) failed (error code=3) |
---|
2605 | *** error: can't allocate region |
---|
2606 | *** set a breakpoint in malloc_error_break to debug |
---|
2607 | init_dgelsd failed init |
---|
2608 | ____________________________________________________________________________________________ test_fit[HermiteE] _____________________________________________________________________________________________ |
---|
2609 | |
---|
2610 | Poly = <class 'numpy.polynomial.hermite_e.HermiteE'> |
---|
2611 | |
---|
2612 | def test_fit(Poly): |
---|
2613 | |
---|
2614 | def f(x): |
---|
2615 | return x*(x - 1)*(x - 2) |
---|
2616 | x = np.linspace(0, 3) |
---|
2617 | y = f(x) |
---|
2618 | |
---|
2619 | # check default value of domain and window |
---|
2620 | p = Poly.fit(x, y, 3) |
---|
2621 | assert_almost_equal(p.domain, [0, 3]) |
---|
2622 | > assert_almost_equal(p(x), y) |
---|
2623 | E AssertionError: |
---|
2624 | E Arrays are not almost equal to 7 decimals |
---|
2625 | E |
---|
2626 | E (mismatch 100.0%) |
---|
2627 | E x: array([ 22.825942 , 22.5380432, 22.1716834, 21.7309262, 21.2198352, |
---|
2628 | E 20.642474 , 20.0029061, 19.3051951, 18.5534047, 17.7515983, |
---|
2629 | E 16.9038396, 16.0141921, 15.0867194, 14.1254852, 13.1345529,... |
---|
2630 | E y: array([ 0. , 0.1114332, 0.2017527, 0.2723355, 0.3245586, |
---|
2631 | E 0.3597991, 0.3794337, 0.3848397, 0.3773938, 0.3584731, |
---|
2632 | E 0.3294546, 0.2917152, 0.2466319, 0.1955818, 0.1399417,... |
---|
2633 | |
---|
2634 | Poly = <class 'numpy.polynomial.hermite_e.HermiteE'> |
---|
2635 | f = <function test_fit.<locals>.f at 0x10ea18b70> |
---|
2636 | p = HermiteE([7.07106781, 4.16496564, 5.11207676, 9.95991991], domain=[0., 3.], window=[-1., 1.]) |
---|
2637 | x = array([0. , 0.06122449, 0.12244898, 0.18367347, 0.24489796, |
---|
2638 | 0.30612245, 0.36734694, 0.42857143, 0.489795...59, 2.51020408, 2.57142857, 2.63265306, 2.69387755, |
---|
2639 | 2.75510204, 2.81632653, 2.87755102, 2.93877551, 3. ]) |
---|
2640 | y = array([ 0. , 0.11143316, 0.20175267, 0.27233551, 0.32455864, |
---|
2641 | 0.35979906, 0.37943374, 0.38483965, ...414309, 2.3090379 , 2.71927513, 3.16623176, |
---|
2642 | 3.65128475, 4.1758111 , 4.74118777, 5.34879174, 6. ]) |
---|
2643 | |
---|
2644 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/polynomial/tests/test_classes.py:146: AssertionError |
---|
2645 | ------------------------------------------------------------------------------------------- Captured stderr call -------------------------------------------------------------------------------------------- |
---|
2646 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438808576) failed (error code=3) |
---|
2647 | *** error: can't allocate region |
---|
2648 | *** set a breakpoint in malloc_error_break to debug |
---|
2649 | init_dgelsd failed init |
---|
2650 | _________________________________________________________________________________________ TestFitting.test_hermfit __________________________________________________________________________________________ |
---|
2651 | |
---|
2652 | self = <numpy.polynomial.tests.test_hermite.TestFitting object at 0x10da295c0> |
---|
2653 | |
---|
2654 | def test_hermfit(self): |
---|
2655 | def f(x): |
---|
2656 | return x*(x - 1)*(x - 2) |
---|
2657 | |
---|
2658 | def f2(x): |
---|
2659 | return x**4 + x**2 + 1 |
---|
2660 | |
---|
2661 | # Test exceptions |
---|
2662 | assert_raises(ValueError, herm.hermfit, [1], [1], -1) |
---|
2663 | assert_raises(TypeError, herm.hermfit, [[1]], [1], 0) |
---|
2664 | assert_raises(TypeError, herm.hermfit, [], [1], 0) |
---|
2665 | assert_raises(TypeError, herm.hermfit, [1], [[[1]]], 0) |
---|
2666 | assert_raises(TypeError, herm.hermfit, [1, 2], [1], 0) |
---|
2667 | assert_raises(TypeError, herm.hermfit, [1], [1, 2], 0) |
---|
2668 | assert_raises(TypeError, herm.hermfit, [1], [1], 0, w=[[1]]) |
---|
2669 | assert_raises(TypeError, herm.hermfit, [1], [1], 0, w=[1, 1]) |
---|
2670 | assert_raises(ValueError, herm.hermfit, [1], [1], [-1,]) |
---|
2671 | assert_raises(ValueError, herm.hermfit, [1], [1], [2, -1, 6]) |
---|
2672 | assert_raises(TypeError, herm.hermfit, [1], [1], []) |
---|
2673 | |
---|
2674 | # Test fit |
---|
2675 | x = np.linspace(0, 2) |
---|
2676 | y = f(x) |
---|
2677 | # |
---|
2678 | coef3 = herm.hermfit(x, y, 3) |
---|
2679 | assert_equal(len(coef3), 4) |
---|
2680 | > assert_almost_equal(herm.hermval(x, coef3), y) |
---|
2681 | E AssertionError: |
---|
2682 | E Arrays are not almost equal to 7 decimals |
---|
2683 | E |
---|
2684 | E (mismatch 100.0%) |
---|
2685 | E x: array([ -76.8572445, -121.1264933, -164.5303156, -206.7625738, |
---|
2686 | E -247.5171306, -286.4878483, -323.3685896, -357.853217 , |
---|
2687 | E -389.635593 , -418.4095801, -443.8690407, -465.7078375,... |
---|
2688 | E y: array([ 0. , 0.0767027, 0.1438176, 0.2017527, 0.2509159, |
---|
2689 | E 0.2917152, 0.3245586, 0.3498542, 0.3680099, 0.3794337, |
---|
2690 | E 0.3845337, 0.3837177, 0.3773938, 0.36597 , 0.3498542,... |
---|
2691 | |
---|
2692 | coef3 = array([ 7.07106781, 16.41303613, 41.96415618, 93.79366829]) |
---|
2693 | f = <function TestFitting.test_hermfit.<locals>.f at 0x10ea1f2f0> |
---|
2694 | f2 = <function TestFitting.test_hermfit.<locals>.f2 at 0x10ea18400> |
---|
2695 | self = <numpy.polynomial.tests.test_hermite.TestFitting object at 0x10da295c0> |
---|
2696 | x = array([0. , 0.04081633, 0.08163265, 0.12244898, 0.16326531, |
---|
2697 | 0.20408163, 0.24489796, 0.28571429, 0.326530...06, 1.67346939, 1.71428571, 1.75510204, 1.79591837, |
---|
2698 | 1.83673469, 1.87755102, 1.91836735, 1.95918367, 2. ]) |
---|
2699 | y = array([ 0. , 0.07670273, 0.14381763, 0.20175267, 0.25091586, |
---|
2700 | 0.29171519, 0.32455864, 0.34985423, ...800993, -0.34985423, -0.32455864, -0.29171519, |
---|
2701 | -0.25091586, -0.20175267, -0.14381763, -0.07670273, 0. ]) |
---|
2702 | |
---|
2703 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/polynomial/tests/test_hermite.py:415: AssertionError |
---|
2704 | ------------------------------------------------------------------------------------------- Captured stderr call -------------------------------------------------------------------------------------------- |
---|
2705 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438812672) failed (error code=3) |
---|
2706 | *** error: can't allocate region |
---|
2707 | *** set a breakpoint in malloc_error_break to debug |
---|
2708 | init_dgelsd failed init |
---|
2709 | _________________________________________________________________________________________ TestFitting.test_hermefit _________________________________________________________________________________________ |
---|
2710 | |
---|
2711 | self = <numpy.polynomial.tests.test_hermite_e.TestFitting object at 0x10bd0e278> |
---|
2712 | |
---|
2713 | def test_hermefit(self): |
---|
2714 | def f(x): |
---|
2715 | return x*(x - 1)*(x - 2) |
---|
2716 | |
---|
2717 | def f2(x): |
---|
2718 | return x**4 + x**2 + 1 |
---|
2719 | |
---|
2720 | # Test exceptions |
---|
2721 | assert_raises(ValueError, herme.hermefit, [1], [1], -1) |
---|
2722 | assert_raises(TypeError, herme.hermefit, [[1]], [1], 0) |
---|
2723 | assert_raises(TypeError, herme.hermefit, [], [1], 0) |
---|
2724 | assert_raises(TypeError, herme.hermefit, [1], [[[1]]], 0) |
---|
2725 | assert_raises(TypeError, herme.hermefit, [1, 2], [1], 0) |
---|
2726 | assert_raises(TypeError, herme.hermefit, [1], [1, 2], 0) |
---|
2727 | assert_raises(TypeError, herme.hermefit, [1], [1], 0, w=[[1]]) |
---|
2728 | assert_raises(TypeError, herme.hermefit, [1], [1], 0, w=[1, 1]) |
---|
2729 | assert_raises(ValueError, herme.hermefit, [1], [1], [-1,]) |
---|
2730 | assert_raises(ValueError, herme.hermefit, [1], [1], [2, -1, 6]) |
---|
2731 | assert_raises(TypeError, herme.hermefit, [1], [1], []) |
---|
2732 | |
---|
2733 | # Test fit |
---|
2734 | x = np.linspace(0, 2) |
---|
2735 | y = f(x) |
---|
2736 | # |
---|
2737 | coef3 = herme.hermefit(x, y, 3) |
---|
2738 | assert_equal(len(coef3), 4) |
---|
2739 | > assert_almost_equal(herme.hermeval(x, coef3), y) |
---|
2740 | E AssertionError: |
---|
2741 | E Arrays are not almost equal to 7 decimals |
---|
2742 | E |
---|
2743 | E (mismatch 100.0%) |
---|
2744 | E x: array([-1.8852127, -2.7426461, -3.5662127, -4.3518875, -5.0956457, |
---|
2745 | E -5.7934623, -6.4413124, -7.035171 , -7.5710132, -8.044814 , |
---|
2746 | E -8.4525486, -8.7901919, -9.0537191, -9.2391051, -9.3423251,... |
---|
2747 | E y: array([ 0. , 0.0767027, 0.1438176, 0.2017527, 0.2509159, |
---|
2748 | E 0.2917152, 0.3245586, 0.3498542, 0.3680099, 0.3794337, |
---|
2749 | E 0.3845337, 0.3837177, 0.3773938, 0.36597 , 0.3498542,... |
---|
2750 | |
---|
2751 | coef3 = array([7.07106781, 8.20651807, 8.95628056, 9.86521087]) |
---|
2752 | f = <function TestFitting.test_hermefit.<locals>.f at 0x10ea18ea0> |
---|
2753 | f2 = <function TestFitting.test_hermefit.<locals>.f2 at 0x10ea18158> |
---|
2754 | self = <numpy.polynomial.tests.test_hermite_e.TestFitting object at 0x10bd0e278> |
---|
2755 | x = array([0. , 0.04081633, 0.08163265, 0.12244898, 0.16326531, |
---|
2756 | 0.20408163, 0.24489796, 0.28571429, 0.326530...06, 1.67346939, 1.71428571, 1.75510204, 1.79591837, |
---|
2757 | 1.83673469, 1.87755102, 1.91836735, 1.95918367, 2. ]) |
---|
2758 | y = array([ 0. , 0.07670273, 0.14381763, 0.20175267, 0.25091586, |
---|
2759 | 0.29171519, 0.32455864, 0.34985423, ...800993, -0.34985423, -0.32455864, -0.29171519, |
---|
2760 | -0.25091586, -0.20175267, -0.14381763, -0.07670273, 0. ]) |
---|
2761 | |
---|
2762 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/polynomial/tests/test_hermite_e.py:416: AssertionError |
---|
2763 | ------------------------------------------------------------------------------------------- Captured stderr call -------------------------------------------------------------------------------------------- |
---|
2764 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438812672) failed (error code=3) |
---|
2765 | *** error: can't allocate region |
---|
2766 | *** set a breakpoint in malloc_error_break to debug |
---|
2767 | init_dgelsd failed init |
---|
2768 | __________________________________________________________________________________________ TestFitting.test_lagfit __________________________________________________________________________________________ |
---|
2769 | |
---|
2770 | self = <numpy.polynomial.tests.test_laguerre.TestFitting object at 0x10bd1d390> |
---|
2771 | |
---|
2772 | def test_lagfit(self): |
---|
2773 | def f(x): |
---|
2774 | return x*(x - 1)*(x - 2) |
---|
2775 | |
---|
2776 | # Test exceptions |
---|
2777 | assert_raises(ValueError, lag.lagfit, [1], [1], -1) |
---|
2778 | assert_raises(TypeError, lag.lagfit, [[1]], [1], 0) |
---|
2779 | assert_raises(TypeError, lag.lagfit, [], [1], 0) |
---|
2780 | assert_raises(TypeError, lag.lagfit, [1], [[[1]]], 0) |
---|
2781 | assert_raises(TypeError, lag.lagfit, [1, 2], [1], 0) |
---|
2782 | assert_raises(TypeError, lag.lagfit, [1], [1, 2], 0) |
---|
2783 | assert_raises(TypeError, lag.lagfit, [1], [1], 0, w=[[1]]) |
---|
2784 | assert_raises(TypeError, lag.lagfit, [1], [1], 0, w=[1, 1]) |
---|
2785 | assert_raises(ValueError, lag.lagfit, [1], [1], [-1,]) |
---|
2786 | assert_raises(ValueError, lag.lagfit, [1], [1], [2, -1, 6]) |
---|
2787 | assert_raises(TypeError, lag.lagfit, [1], [1], []) |
---|
2788 | |
---|
2789 | # Test fit |
---|
2790 | x = np.linspace(0, 2) |
---|
2791 | y = f(x) |
---|
2792 | # |
---|
2793 | coef3 = lag.lagfit(x, y, 3) |
---|
2794 | assert_equal(len(coef3), 4) |
---|
2795 | > assert_almost_equal(lag.lagval(x, coef3), y) |
---|
2796 | E AssertionError: |
---|
2797 | E Arrays are not almost equal to 7 decimals |
---|
2798 | E |
---|
2799 | E (mismatch 100.0%) |
---|
2800 | E x: array([20.158221 , 19.1092779, 18.0883703, 17.0952239, 16.1295643, |
---|
2801 | E 15.1911171, 14.2796079, 13.3947622, 12.5363056, 11.7039638, |
---|
2802 | E 10.8974624, 10.1165269, 9.3608829, 8.6302561, 7.9243719,... |
---|
2803 | E y: array([ 0. , 0.0767027, 0.1438176, 0.2017527, 0.2509159, |
---|
2804 | E 0.2917152, 0.3245586, 0.3498542, 0.3680099, 0.3794337, |
---|
2805 | E 0.3845337, 0.3837177, 0.3773938, 0.36597 , 0.3498542,... |
---|
2806 | |
---|
2807 | coef3 = array([7.07106781, 4.16496564, 4.88674441, 4.03544314]) |
---|
2808 | f = <function TestFitting.test_lagfit.<locals>.f at 0x10ea188c8> |
---|
2809 | self = <numpy.polynomial.tests.test_laguerre.TestFitting object at 0x10bd1d390> |
---|
2810 | x = array([0. , 0.04081633, 0.08163265, 0.12244898, 0.16326531, |
---|
2811 | 0.20408163, 0.24489796, 0.28571429, 0.326530...06, 1.67346939, 1.71428571, 1.75510204, 1.79591837, |
---|
2812 | 1.83673469, 1.87755102, 1.91836735, 1.95918367, 2. ]) |
---|
2813 | y = array([ 0. , 0.07670273, 0.14381763, 0.20175267, 0.25091586, |
---|
2814 | 0.29171519, 0.32455864, 0.34985423, ...800993, -0.34985423, -0.32455864, -0.29171519, |
---|
2815 | -0.25091586, -0.20175267, -0.14381763, -0.07670273, 0. ]) |
---|
2816 | |
---|
2817 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/polynomial/tests/test_laguerre.py:409: AssertionError |
---|
2818 | ------------------------------------------------------------------------------------------- Captured stderr call -------------------------------------------------------------------------------------------- |
---|
2819 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438812672) failed (error code=3) |
---|
2820 | *** error: can't allocate region |
---|
2821 | *** set a breakpoint in malloc_error_break to debug |
---|
2822 | init_dgelsd failed init |
---|
2823 | __________________________________________________________________________________________ TestFitting.test_legfit __________________________________________________________________________________________ |
---|
2824 | |
---|
2825 | self = <numpy.polynomial.tests.test_legendre.TestFitting object at 0x10d982b38> |
---|
2826 | |
---|
2827 | def test_legfit(self): |
---|
2828 | def f(x): |
---|
2829 | return x*(x - 1)*(x - 2) |
---|
2830 | |
---|
2831 | def f2(x): |
---|
2832 | return x**4 + x**2 + 1 |
---|
2833 | |
---|
2834 | # Test exceptions |
---|
2835 | assert_raises(ValueError, leg.legfit, [1], [1], -1) |
---|
2836 | assert_raises(TypeError, leg.legfit, [[1]], [1], 0) |
---|
2837 | assert_raises(TypeError, leg.legfit, [], [1], 0) |
---|
2838 | assert_raises(TypeError, leg.legfit, [1], [[[1]]], 0) |
---|
2839 | assert_raises(TypeError, leg.legfit, [1, 2], [1], 0) |
---|
2840 | assert_raises(TypeError, leg.legfit, [1], [1, 2], 0) |
---|
2841 | assert_raises(TypeError, leg.legfit, [1], [1], 0, w=[[1]]) |
---|
2842 | assert_raises(TypeError, leg.legfit, [1], [1], 0, w=[1, 1]) |
---|
2843 | assert_raises(ValueError, leg.legfit, [1], [1], [-1,]) |
---|
2844 | assert_raises(ValueError, leg.legfit, [1], [1], [2, -1, 6]) |
---|
2845 | assert_raises(TypeError, leg.legfit, [1], [1], []) |
---|
2846 | |
---|
2847 | # Test fit |
---|
2848 | x = np.linspace(0, 2) |
---|
2849 | y = f(x) |
---|
2850 | # |
---|
2851 | coef3 = leg.legfit(x, y, 3) |
---|
2852 | assert_equal(len(coef3), 4) |
---|
2853 | > assert_almost_equal(leg.legval(x, coef3), y) |
---|
2854 | E AssertionError: |
---|
2855 | E Arrays are not almost equal to 7 decimals |
---|
2856 | E |
---|
2857 | E (mismatch 100.0%) |
---|
2858 | E x: array([ -1.3331644, -3.6306353, -5.7994195, -7.7948375, -9.57221 , |
---|
2859 | E -11.0868576, -12.2941009, -13.1492604, -13.6076569, -13.6246108, |
---|
2860 | E -13.1554427, -12.1554734, -10.5800233, -8.3844131, -5.5239633,... |
---|
2861 | E y: array([ 0. , 0.0767027, 0.1438176, 0.2017527, 0.2509159, |
---|
2862 | E 0.2917152, 0.3245586, 0.3498542, 0.3680099, 0.3794337, |
---|
2863 | E 0.3845337, 0.3837177, 0.3773938, 0.36597 , 0.3498542,... |
---|
2864 | |
---|
2865 | coef3 = array([ 7.07106781, 8.20651807, 16.80846452, 43.80405673]) |
---|
2866 | f = <function TestFitting.test_legfit.<locals>.f at 0x10ea18048> |
---|
2867 | f2 = <function TestFitting.test_legfit.<locals>.f2 at 0x10d9ed620> |
---|
2868 | self = <numpy.polynomial.tests.test_legendre.TestFitting object at 0x10d982b38> |
---|
2869 | x = array([0. , 0.04081633, 0.08163265, 0.12244898, 0.16326531, |
---|
2870 | 0.20408163, 0.24489796, 0.28571429, 0.326530...06, 1.67346939, 1.71428571, 1.75510204, 1.79591837, |
---|
2871 | 1.83673469, 1.87755102, 1.91836735, 1.95918367, 2. ]) |
---|
2872 | y = array([ 0. , 0.07670273, 0.14381763, 0.20175267, 0.25091586, |
---|
2873 | 0.29171519, 0.32455864, 0.34985423, ...800993, -0.34985423, -0.32455864, -0.29171519, |
---|
2874 | -0.25091586, -0.20175267, -0.14381763, -0.07670273, 0. ]) |
---|
2875 | |
---|
2876 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/polynomial/tests/test_legendre.py:416: AssertionError |
---|
2877 | ------------------------------------------------------------------------------------------- Captured stderr call -------------------------------------------------------------------------------------------- |
---|
2878 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438812672) failed (error code=3) |
---|
2879 | *** error: can't allocate region |
---|
2880 | *** set a breakpoint in malloc_error_break to debug |
---|
2881 | init_dgelsd failed init |
---|
2882 | ___________________________________________________________________________________________ TestMisc.test_polyfit ___________________________________________________________________________________________ |
---|
2883 | |
---|
2884 | self = <numpy.polynomial.tests.test_polynomial.TestMisc object at 0x10d9c0e80> |
---|
2885 | |
---|
2886 | def test_polyfit(self): |
---|
2887 | def f(x): |
---|
2888 | return x*(x - 1)*(x - 2) |
---|
2889 | |
---|
2890 | def f2(x): |
---|
2891 | return x**4 + x**2 + 1 |
---|
2892 | |
---|
2893 | # Test exceptions |
---|
2894 | assert_raises(ValueError, poly.polyfit, [1], [1], -1) |
---|
2895 | assert_raises(TypeError, poly.polyfit, [[1]], [1], 0) |
---|
2896 | assert_raises(TypeError, poly.polyfit, [], [1], 0) |
---|
2897 | assert_raises(TypeError, poly.polyfit, [1], [[[1]]], 0) |
---|
2898 | assert_raises(TypeError, poly.polyfit, [1, 2], [1], 0) |
---|
2899 | assert_raises(TypeError, poly.polyfit, [1], [1, 2], 0) |
---|
2900 | assert_raises(TypeError, poly.polyfit, [1], [1], 0, w=[[1]]) |
---|
2901 | assert_raises(TypeError, poly.polyfit, [1], [1], 0, w=[1, 1]) |
---|
2902 | assert_raises(ValueError, poly.polyfit, [1], [1], [-1,]) |
---|
2903 | assert_raises(ValueError, poly.polyfit, [1], [1], [2, -1, 6]) |
---|
2904 | assert_raises(TypeError, poly.polyfit, [1], [1], []) |
---|
2905 | |
---|
2906 | # Test fit |
---|
2907 | x = np.linspace(0, 2) |
---|
2908 | y = f(x) |
---|
2909 | # |
---|
2910 | coef3 = poly.polyfit(x, y, 3) |
---|
2911 | assert_equal(len(coef3), 4) |
---|
2912 | > assert_almost_equal(poly.polyval(x, coef3), y) |
---|
2913 | E AssertionError: |
---|
2914 | E Arrays are not almost equal to 7 decimals |
---|
2915 | E |
---|
2916 | E (mismatch 100.0%) |
---|
2917 | E x: array([ 7.0710678, 7.4289124, 7.8384896, 8.308744 , 8.8486206, |
---|
2918 | E 9.4670639, 10.1730189, 10.9754302, 11.8832427, 12.905401 , |
---|
2919 | E 14.05085 , 15.3285343, 16.7473989, 18.3163884, 20.0444476,... |
---|
2920 | E y: array([ 0. , 0.0767027, 0.1438176, 0.2017527, 0.2509159, |
---|
2921 | E 0.2917152, 0.3245586, 0.3498542, 0.3680099, 0.3794337, |
---|
2922 | E 0.3845337, 0.3837177, 0.3773938, 0.36597 , 0.3498542,... |
---|
2923 | |
---|
2924 | coef3 = array([ 7.07106781, 8.20651807, 12.84168365, 21.92379918]) |
---|
2925 | f = <function TestMisc.test_polyfit.<locals>.f at 0x10d9ed840> |
---|
2926 | f2 = <function TestMisc.test_polyfit.<locals>.f2 at 0x10d9edbf8> |
---|
2927 | self = <numpy.polynomial.tests.test_polynomial.TestMisc object at 0x10d9c0e80> |
---|
2928 | x = array([0. , 0.04081633, 0.08163265, 0.12244898, 0.16326531, |
---|
2929 | 0.20408163, 0.24489796, 0.28571429, 0.326530...06, 1.67346939, 1.71428571, 1.75510204, 1.79591837, |
---|
2930 | 1.83673469, 1.87755102, 1.91836735, 1.95918367, 2. ]) |
---|
2931 | y = array([ 0. , 0.07670273, 0.14381763, 0.20175267, 0.25091586, |
---|
2932 | 0.29171519, 0.32455864, 0.34985423, ...800993, -0.34985423, -0.32455864, -0.29171519, |
---|
2933 | -0.25091586, -0.20175267, -0.14381763, -0.07670273, 0. ]) |
---|
2934 | |
---|
2935 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/polynomial/tests/test_polynomial.py:511: AssertionError |
---|
2936 | ------------------------------------------------------------------------------------------- Captured stderr call -------------------------------------------------------------------------------------------- |
---|
2937 | Python(85346,0x7fff9e546380) malloc: *** mach_vm_map(size=18446744072438812672) failed (error code=3) |
---|
2938 | *** error: can't allocate region |
---|
2939 | *** set a breakpoint in malloc_error_break to debug |
---|
2940 | init_dgelsd failed init |
---|
2941 | ============================================================================================= warnings summary ============================================================================================== |
---|
2942 | numpy/lib/tests/test_polynomial.py::TestDocs::()::test_polyfit |
---|
2943 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/case.py:178: RankWarning: Polyfit may be poorly conditioned |
---|
2944 | callable_obj(*args, **kwargs) |
---|
2945 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/lib/tests/test_polynomial.py:145: RankWarning: Polyfit may be poorly conditioned |
---|
2946 | m, cov = np.polyfit(x, y+err, 2, cov=True) |
---|
2947 | |
---|
2948 | numpy/lib/tests/test_regression.py::TestRegression::()::test_polyfit_build |
---|
2949 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/lib/tests/test_regression.py:103: RankWarning: Polyfit may be poorly conditioned |
---|
2950 | tested = np.polyfit(x, y, 4) |
---|
2951 | |
---|
2952 | numpy/ma/tests/test_extras.py::TestPolynomial::()::test_polyfit |
---|
2953 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/ma/extras.py:1899: RankWarning: Polyfit may be poorly conditioned |
---|
2954 | return np.polyfit(x, y, deg, rcond, full, w, cov) |
---|
2955 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/ma/tests/test_extras.py:1261: RankWarning: Polyfit may be poorly conditioned |
---|
2956 | assert_almost_equal(polyfit(x, y, 3), np.polyfit(x, y, 3)) |
---|
2957 | |
---|
2958 | numpy/polynomial/tests/test_chebyshev.py::TestFitting::()::test_chebfit |
---|
2959 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/polynomial/tests/test_chebyshev.py:425: RankWarning: The fit may be poorly conditioned |
---|
2960 | coef3 = cheb.chebfit(x, y, 3) |
---|
2961 | |
---|
2962 | numpy/polynomial/tests/test_classes.py::test_fit[Polynomial] |
---|
2963 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/polynomial/_polybase.py:798: RankWarning: The fit may be poorly conditioned |
---|
2964 | res = cls._fit(xnew, y, deg, w=w, rcond=rcond, full=full) |
---|
2965 | |
---|
2966 | numpy/polynomial/tests/test_classes.py::test_fit[Legendre] |
---|
2967 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/polynomial/_polybase.py:798: RankWarning: The fit may be poorly conditioned |
---|
2968 | res = cls._fit(xnew, y, deg, w=w, rcond=rcond, full=full) |
---|
2969 | |
---|
2970 | numpy/polynomial/tests/test_classes.py::test_fit[Chebyshev] |
---|
2971 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/polynomial/_polybase.py:798: RankWarning: The fit may be poorly conditioned |
---|
2972 | res = cls._fit(xnew, y, deg, w=w, rcond=rcond, full=full) |
---|
2973 | |
---|
2974 | numpy/polynomial/tests/test_classes.py::test_fit[Laguerre] |
---|
2975 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/polynomial/_polybase.py:798: RankWarning: The fit may be poorly conditioned |
---|
2976 | res = cls._fit(xnew, y, deg, w=w, rcond=rcond, full=full) |
---|
2977 | |
---|
2978 | numpy/polynomial/tests/test_classes.py::test_fit[Hermite] |
---|
2979 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/polynomial/_polybase.py:798: RankWarning: The fit may be poorly conditioned |
---|
2980 | res = cls._fit(xnew, y, deg, w=w, rcond=rcond, full=full) |
---|
2981 | |
---|
2982 | numpy/polynomial/tests/test_classes.py::test_fit[HermiteE] |
---|
2983 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/polynomial/_polybase.py:798: RankWarning: The fit may be poorly conditioned |
---|
2984 | res = cls._fit(xnew, y, deg, w=w, rcond=rcond, full=full) |
---|
2985 | |
---|
2986 | numpy/polynomial/tests/test_hermite.py::TestFitting::()::test_hermfit |
---|
2987 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/polynomial/tests/test_hermite.py:413: RankWarning: The fit may be poorly conditioned |
---|
2988 | coef3 = herm.hermfit(x, y, 3) |
---|
2989 | |
---|
2990 | numpy/polynomial/tests/test_hermite_e.py::TestFitting::()::test_hermefit |
---|
2991 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/polynomial/tests/test_hermite_e.py:414: RankWarning: The fit may be poorly conditioned |
---|
2992 | coef3 = herme.hermefit(x, y, 3) |
---|
2993 | |
---|
2994 | numpy/polynomial/tests/test_laguerre.py::TestFitting::()::test_lagfit |
---|
2995 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/polynomial/tests/test_laguerre.py:407: RankWarning: The fit may be poorly conditioned |
---|
2996 | coef3 = lag.lagfit(x, y, 3) |
---|
2997 | |
---|
2998 | numpy/polynomial/tests/test_legendre.py::TestFitting::()::test_legfit |
---|
2999 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/polynomial/tests/test_legendre.py:414: RankWarning: The fit may be poorly conditioned |
---|
3000 | coef3 = leg.legfit(x, y, 3) |
---|
3001 | |
---|
3002 | numpy/polynomial/tests/test_polynomial.py::TestMisc::()::test_polyfit |
---|
3003 | /opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/polynomial/tests/test_polynomial.py:509: RankWarning: The fit may be poorly conditioned |
---|
3004 | coef3 = poly.polyfit(x, y, 3) |
---|
3005 | |
---|
3006 | -- Docs: http://doc.pytest.org/en/latest/warnings.html |
---|
3007 | 20 failed, 4529 passed, 417 skipped, 7 xfailed, 17 warnings in 161.32 seconds |
---|
3008 | False |
---|
3009 | >>> |
---|