Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/mingw32/Python27/Lib/site-packages/numpy/linalg/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 """ Test functions for linalg module | |
2 """ | |
3 from __future__ import division, absolute_import, print_function | |
4 | |
5 | |
6 from numpy.testing import * | |
7 import numpy as np | |
8 from numpy import linalg, arange, float64, array, dot, transpose | |
9 | |
10 rlevel = 1 | |
11 | |
12 class TestRegression(TestCase): | |
13 def test_eig_build(self, level = rlevel): | |
14 """Ticket #652""" | |
15 rva = array([1.03221168e+02 +0.j, | |
16 -1.91843603e+01 +0.j, | |
17 -6.04004526e-01+15.84422474j, | |
18 -6.04004526e-01-15.84422474j, | |
19 -1.13692929e+01 +0.j, | |
20 -6.57612485e-01+10.41755503j, | |
21 -6.57612485e-01-10.41755503j, | |
22 1.82126812e+01 +0.j, | |
23 1.06011014e+01 +0.j, | |
24 7.80732773e+00 +0.j, | |
25 -7.65390898e-01 +0.j, | |
26 1.51971555e-15 +0.j, | |
27 -1.51308713e-15 +0.j]) | |
28 a = arange(13*13, dtype = float64) | |
29 a.shape = (13, 13) | |
30 a = a%17 | |
31 va, ve = linalg.eig(a) | |
32 va.sort() | |
33 rva.sort() | |
34 assert_array_almost_equal(va, rva) | |
35 | |
36 def test_eigh_build(self, level = rlevel): | |
37 """Ticket 662.""" | |
38 rvals = [68.60568999, 89.57756725, 106.67185574] | |
39 | |
40 cov = array([[ 77.70273908, 3.51489954, 15.64602427], | |
41 [3.51489954, 88.97013878, -1.07431931], | |
42 [15.64602427, -1.07431931, 98.18223512]]) | |
43 | |
44 vals, vecs = linalg.eigh(cov) | |
45 assert_array_almost_equal(vals, rvals) | |
46 | |
47 def test_svd_build(self, level = rlevel): | |
48 """Ticket 627.""" | |
49 a = array([[ 0., 1.], [ 1., 1.], [ 2., 1.], [ 3., 1.]]) | |
50 m, n = a.shape | |
51 u, s, vh = linalg.svd(a) | |
52 | |
53 b = dot(transpose(u[:, n:]), a) | |
54 | |
55 assert_array_almost_equal(b, np.zeros((2, 2))) | |
56 | |
57 def test_norm_vector_badarg(self): | |
58 """Regression for #786: Froebenius norm for vectors raises | |
59 TypeError.""" | |
60 self.assertRaises(ValueError, linalg.norm, array([1., 2., 3.]), 'fro') | |
61 | |
62 def test_lapack_endian(self): | |
63 # For bug #1482 | |
64 a = array([[5.7998084, -2.1825367 ], | |
65 [-2.1825367, 9.85910595]], dtype='>f8') | |
66 b = array(a, dtype='<f8') | |
67 | |
68 ap = linalg.cholesky(a) | |
69 bp = linalg.cholesky(b) | |
70 assert_array_equal(ap, bp) | |
71 | |
72 def test_large_svd_32bit(self): | |
73 # See gh-4442, 64bit would require very large/slow matrices. | |
74 x = np.eye(1000, 66) | |
75 np.linalg.svd(x) | |
76 | |
77 def test_svd_no_uv(self): | |
78 # gh-4733 | |
79 for shape in (3, 4), (4, 4), (4, 3): | |
80 for t in float, complex: | |
81 a = np.ones(shape, dtype=t) | |
82 w = linalg.svd(a, compute_uv=False) | |
83 c = np.count_nonzero(np.absolute(w) > 0.5) | |
84 assert_equal(c, 1) | |
85 assert_equal(np.linalg.matrix_rank(a), 1) | |
86 assert_array_less(1, np.linalg.norm(a, ord=2)) | |
87 | |
88 | |
89 if __name__ == '__main__': | |
90 run_module_suite() |