Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/mingw32/Python27/Lib/site-packages/numpy/lib/tests/test_regression.py @ 87:2a2c65a20a8b
Add Python libs and headers
author | Chris Cannam |
---|---|
date | Wed, 25 Feb 2015 14:05:22 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
86:413a9d26189e | 87:2a2c65a20a8b |
---|---|
1 from __future__ import division, absolute_import, print_function | |
2 | |
3 import os | |
4 import sys | |
5 | |
6 import numpy as np | |
7 from numpy.testing import ( | |
8 run_module_suite, TestCase, assert_, assert_equal, assert_array_equal, | |
9 assert_array_almost_equal, assert_raises | |
10 ) | |
11 from numpy.testing.utils import _assert_valid_refcount | |
12 from numpy.compat import unicode | |
13 | |
14 rlevel = 1 | |
15 | |
16 | |
17 class TestRegression(TestCase): | |
18 def test_poly1d(self, level=rlevel): | |
19 # Ticket #28 | |
20 assert_equal(np.poly1d([1]) - np.poly1d([1, 0]), | |
21 np.poly1d([-1, 1])) | |
22 | |
23 def test_cov_parameters(self, level=rlevel): | |
24 # Ticket #91 | |
25 x = np.random.random((3, 3)) | |
26 y = x.copy() | |
27 np.cov(x, rowvar=1) | |
28 np.cov(y, rowvar=0) | |
29 assert_array_equal(x, y) | |
30 | |
31 def test_mem_digitize(self, level=rlevel): | |
32 # Ticket #95 | |
33 for i in range(100): | |
34 np.digitize([1, 2, 3, 4], [1, 3]) | |
35 np.digitize([0, 1, 2, 3, 4], [1, 3]) | |
36 | |
37 def test_unique_zero_sized(self, level=rlevel): | |
38 # Ticket #205 | |
39 assert_array_equal([], np.unique(np.array([]))) | |
40 | |
41 def test_mem_vectorise(self, level=rlevel): | |
42 # Ticket #325 | |
43 vt = np.vectorize(lambda *args: args) | |
44 vt(np.zeros((1, 2, 1)), np.zeros((2, 1, 1)), np.zeros((1, 1, 2))) | |
45 vt(np.zeros((1, 2, 1)), np.zeros((2, 1, 1)), np.zeros((1, | |
46 1, 2)), np.zeros((2, 2))) | |
47 | |
48 def test_mgrid_single_element(self, level=rlevel): | |
49 # Ticket #339 | |
50 assert_array_equal(np.mgrid[0:0:1j], [0]) | |
51 assert_array_equal(np.mgrid[0:0], []) | |
52 | |
53 def test_refcount_vectorize(self, level=rlevel): | |
54 # Ticket #378 | |
55 def p(x, y): | |
56 return 123 | |
57 v = np.vectorize(p) | |
58 _assert_valid_refcount(v) | |
59 | |
60 def test_poly1d_nan_roots(self, level=rlevel): | |
61 # Ticket #396 | |
62 p = np.poly1d([np.nan, np.nan, 1], r=0) | |
63 self.assertRaises(np.linalg.LinAlgError, getattr, p, "r") | |
64 | |
65 def test_mem_polymul(self, level=rlevel): | |
66 # Ticket #448 | |
67 np.polymul([], [1.]) | |
68 | |
69 def test_mem_string_concat(self, level=rlevel): | |
70 # Ticket #469 | |
71 x = np.array([]) | |
72 np.append(x, 'asdasd\tasdasd') | |
73 | |
74 def test_poly_div(self, level=rlevel): | |
75 # Ticket #553 | |
76 u = np.poly1d([1, 2, 3]) | |
77 v = np.poly1d([1, 2, 3, 4, 5]) | |
78 q, r = np.polydiv(u, v) | |
79 assert_equal(q*v + r, u) | |
80 | |
81 def test_poly_eq(self, level=rlevel): | |
82 # Ticket #554 | |
83 x = np.poly1d([1, 2, 3]) | |
84 y = np.poly1d([3, 4]) | |
85 assert_(x != y) | |
86 assert_(x == x) | |
87 | |
88 def test_mem_insert(self, level=rlevel): | |
89 # Ticket #572 | |
90 np.lib.place(1, 1, 1) | |
91 | |
92 def test_polyfit_build(self): | |
93 # Ticket #628 | |
94 ref = [-1.06123820e-06, 5.70886914e-04, -1.13822012e-01, | |
95 9.95368241e+00, -3.14526520e+02] | |
96 x = [90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, | |
97 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, | |
98 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 129, | |
99 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, | |
100 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, | |
101 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, | |
102 170, 171, 172, 173, 174, 175, 176] | |
103 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, | |
104 6.0, 5.0, 9.0, 8.0, 6.0, 10.0, 6.0, 10.0, 7.0, 6.0, 6.0, 6.0, | |
105 13.0, 4.0, 9.0, 11.0, 4.0, 5.0, 8.0, 5.0, 7.0, 7.0, 6.0, 12.0, | |
106 7.0, 7.0, 9.0, 4.0, 12.0, 6.0, 6.0, 4.0, 3.0, 9.0, 8.0, 8.0, | |
107 6.0, 7.0, 9.0, 10.0, 6.0, 8.0, 4.0, 7.0, 7.0, 10.0, 8.0, 8.0, | |
108 6.0, 3.0, 8.0, 4.0, 5.0, 7.0, 8.0, 6.0, 6.0, 4.0, 12.0, 9.0, | |
109 8.0, 8.0, 8.0, 6.0, 7.0, 4.0, 4.0, 5.0, 7.0] | |
110 tested = np.polyfit(x, y, 4) | |
111 assert_array_almost_equal(ref, tested) | |
112 | |
113 def test_polydiv_type(self): | |
114 # Make polydiv work for complex types | |
115 msg = "Wrong type, should be complex" | |
116 x = np.ones(3, dtype=np.complex) | |
117 q, r = np.polydiv(x, x) | |
118 assert_(q.dtype == np.complex, msg) | |
119 msg = "Wrong type, should be float" | |
120 x = np.ones(3, dtype=np.int) | |
121 q, r = np.polydiv(x, x) | |
122 assert_(q.dtype == np.float, msg) | |
123 | |
124 def test_histogramdd_too_many_bins(self): | |
125 # Ticket 928. | |
126 assert_raises(ValueError, np.histogramdd, np.ones((1, 10)), bins=2**10) | |
127 | |
128 def test_polyint_type(self): | |
129 # Ticket #944 | |
130 msg = "Wrong type, should be complex" | |
131 x = np.ones(3, dtype=np.complex) | |
132 assert_(np.polyint(x).dtype == np.complex, msg) | |
133 msg = "Wrong type, should be float" | |
134 x = np.ones(3, dtype=np.int) | |
135 assert_(np.polyint(x).dtype == np.float, msg) | |
136 | |
137 def test_ndenumerate_crash(self): | |
138 # Ticket 1140 | |
139 # Shouldn't crash: | |
140 list(np.ndenumerate(np.array([[]]))) | |
141 | |
142 def test_asfarray_none(self, level=rlevel): | |
143 # Test for changeset r5065 | |
144 assert_array_equal(np.array([np.nan]), np.asfarray([None])) | |
145 | |
146 def test_large_fancy_indexing(self, level=rlevel): | |
147 # Large enough to fail on 64-bit. | |
148 nbits = np.dtype(np.intp).itemsize * 8 | |
149 thesize = int((2**nbits)**(1.0/5.0)+1) | |
150 | |
151 def dp(): | |
152 n = 3 | |
153 a = np.ones((n,)*5) | |
154 i = np.random.randint(0, n, size=thesize) | |
155 a[np.ix_(i, i, i, i, i)] = 0 | |
156 | |
157 def dp2(): | |
158 n = 3 | |
159 a = np.ones((n,)*5) | |
160 i = np.random.randint(0, n, size=thesize) | |
161 a[np.ix_(i, i, i, i, i)] | |
162 | |
163 self.assertRaises(ValueError, dp) | |
164 self.assertRaises(ValueError, dp2) | |
165 | |
166 def test_void_coercion(self, level=rlevel): | |
167 dt = np.dtype([('a', 'f4'), ('b', 'i4')]) | |
168 x = np.zeros((1,), dt) | |
169 assert_(np.r_[x, x].dtype == dt) | |
170 | |
171 def test_who_with_0dim_array(self, level=rlevel): | |
172 # ticket #1243 | |
173 import os | |
174 import sys | |
175 | |
176 oldstdout = sys.stdout | |
177 sys.stdout = open(os.devnull, 'w') | |
178 try: | |
179 try: | |
180 np.who({'foo': np.array(1)}) | |
181 except: | |
182 raise AssertionError("ticket #1243") | |
183 finally: | |
184 sys.stdout.close() | |
185 sys.stdout = oldstdout | |
186 | |
187 def test_include_dirs(self): | |
188 # As a sanity check, just test that get_include | |
189 # includes something reasonable. Somewhat | |
190 # related to ticket #1405. | |
191 include_dirs = [np.get_include()] | |
192 for path in include_dirs: | |
193 assert_(isinstance(path, (str, unicode))) | |
194 assert_(path != '') | |
195 | |
196 def test_polyder_return_type(self): | |
197 # Ticket #1249 | |
198 assert_(isinstance(np.polyder(np.poly1d([1]), 0), np.poly1d)) | |
199 assert_(isinstance(np.polyder([1], 0), np.ndarray)) | |
200 assert_(isinstance(np.polyder(np.poly1d([1]), 1), np.poly1d)) | |
201 assert_(isinstance(np.polyder([1], 1), np.ndarray)) | |
202 | |
203 def test_append_fields_dtype_list(self): | |
204 # Ticket #1676 | |
205 from numpy.lib.recfunctions import append_fields | |
206 | |
207 base = np.array([1, 2, 3], dtype=np.int32) | |
208 names = ['a', 'b', 'c'] | |
209 data = np.eye(3).astype(np.int32) | |
210 dlist = [np.float64, np.int32, np.int32] | |
211 try: | |
212 append_fields(base, names, data, dlist) | |
213 except: | |
214 raise AssertionError() | |
215 | |
216 def test_loadtxt_fields_subarrays(self): | |
217 # For ticket #1936 | |
218 if sys.version_info[0] >= 3: | |
219 from io import StringIO | |
220 else: | |
221 from StringIO import StringIO | |
222 | |
223 dt = [("a", 'u1', 2), ("b", 'u1', 2)] | |
224 x = np.loadtxt(StringIO("0 1 2 3"), dtype=dt) | |
225 assert_equal(x, np.array([((0, 1), (2, 3))], dtype=dt)) | |
226 | |
227 dt = [("a", [("a", 'u1', (1, 3)), ("b", 'u1')])] | |
228 x = np.loadtxt(StringIO("0 1 2 3"), dtype=dt) | |
229 assert_equal(x, np.array([(((0, 1, 2), 3),)], dtype=dt)) | |
230 | |
231 dt = [("a", 'u1', (2, 2))] | |
232 x = np.loadtxt(StringIO("0 1 2 3"), dtype=dt) | |
233 assert_equal(x, np.array([(((0, 1), (2, 3)),)], dtype=dt)) | |
234 | |
235 dt = [("a", 'u1', (2, 3, 2))] | |
236 x = np.loadtxt(StringIO("0 1 2 3 4 5 6 7 8 9 10 11"), dtype=dt) | |
237 data = [((((0, 1), (2, 3), (4, 5)), ((6, 7), (8, 9), (10, 11))),)] | |
238 assert_equal(x, np.array(data, dtype=dt)) | |
239 | |
240 def test_nansum_with_boolean(self): | |
241 # gh-2978 | |
242 a = np.zeros(2, dtype=np.bool) | |
243 try: | |
244 np.nansum(a) | |
245 except: | |
246 raise AssertionError() | |
247 | |
248 def test_py3_compat(self): | |
249 # gh-2561 | |
250 # Test if the oldstyle class test is bypassed in python3 | |
251 class C(): | |
252 """Old-style class in python2, normal class in python3""" | |
253 pass | |
254 | |
255 out = open(os.devnull, 'w') | |
256 try: | |
257 np.info(C(), output=out) | |
258 except AttributeError: | |
259 raise AssertionError() | |
260 finally: | |
261 out.close() | |
262 | |
263 | |
264 if __name__ == "__main__": | |
265 run_module_suite() |