diff options
-rw-r--r-- | numpy/lib/npyio.py | 4 | ||||
-rw-r--r-- | numpy/lib/tests/test_type_check.py | 6 | ||||
-rw-r--r-- | numpy/lib/type_check.py | 19 | ||||
-rw-r--r-- | numpy/linalg/linalg.py | 7 | ||||
-rw-r--r-- | numpy/linalg/tests/test_linalg.py | 24 |
5 files changed, 31 insertions, 29 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index 078c6d7ca..0cf627e7c 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -798,7 +798,7 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, Examples -------- - >>> from StringIO import StringIO # StringIO behaves like a file object + >>> from io import StringIO # StringIO behaves like a file object >>> c = StringIO("0 1\\n2 3") >>> np.loadtxt(c) array([[ 0., 1.], @@ -1420,7 +1420,7 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None, Examples --------- - >>> from StringIO import StringIO + >>> from io import StringIO >>> import numpy as np Comma delimited file with mixed dtype diff --git a/numpy/lib/tests/test_type_check.py b/numpy/lib/tests/test_type_check.py index 7afd1206c..f7430c27d 100644 --- a/numpy/lib/tests/test_type_check.py +++ b/numpy/lib/tests/test_type_check.py @@ -18,11 +18,13 @@ def assert_all(x): class TestCommonType(TestCase): def test_basic(self): ai32 = np.array([[1, 2], [3, 4]], dtype=np.int32) + af16 = np.array([[1, 2], [3, 4]], dtype=np.float16) af32 = np.array([[1, 2], [3, 4]], dtype=np.float32) af64 = np.array([[1, 2], [3, 4]], dtype=np.float64) acs = np.array([[1+5j, 2+6j], [3+7j, 4+8j]], dtype=np.csingle) acd = np.array([[1+5j, 2+6j], [3+7j, 4+8j]], dtype=np.cdouble) assert_(common_type(ai32) == np.float64) + assert_(common_type(af16) == np.float16) assert_(common_type(af32) == np.float32) assert_(common_type(af64) == np.float64) assert_(common_type(acs) == np.csingle) @@ -186,7 +188,7 @@ class TestIsnan(TestCase): class TestIsfinite(TestCase): - # Fixme, wrong place, isfinite now ufunc + # Fixme, wrong place, isfinite now ufunc def test_goodvalues(self): z = np.array((-1., 0., 1.)) @@ -217,7 +219,7 @@ class TestIsfinite(TestCase): class TestIsinf(TestCase): - # Fixme, wrong place, isinf now ufunc + # Fixme, wrong place, isinf now ufunc def test_goodvalues(self): z = np.array((-1., 0., 1.)) diff --git a/numpy/lib/type_check.py b/numpy/lib/type_check.py index 99677b394..2fe4e7d23 100644 --- a/numpy/lib/type_check.py +++ b/numpy/lib/type_check.py @@ -532,14 +532,15 @@ def typename(char): #----------------------------------------------------------------------------- #determine the "minimum common type" for a group of arrays. -array_type = [[_nx.single, _nx.double, _nx.longdouble], - [_nx.csingle, _nx.cdouble, _nx.clongdouble]] -array_precision = {_nx.single: 0, - _nx.double: 1, - _nx.longdouble: 2, - _nx.csingle: 0, - _nx.cdouble: 1, - _nx.clongdouble: 2} +array_type = [[_nx.half, _nx.single, _nx.double, _nx.longdouble], + [None, _nx.csingle, _nx.cdouble, _nx.clongdouble]] +array_precision = {_nx.half: 0, + _nx.single: 1, + _nx.double: 2, + _nx.longdouble: 3, + _nx.csingle: 1, + _nx.cdouble: 2, + _nx.clongdouble: 3} def common_type(*arrays): """ Return a scalar type which is common to the input arrays. @@ -583,7 +584,7 @@ def common_type(*arrays): if iscomplexobj(a): is_complex = True if issubclass(t, _nx.integer): - p = 1 + p = 2 # array_precision[_nx.double] else: p = array_precision.get(t, None) if p is None: diff --git a/numpy/linalg/linalg.py b/numpy/linalg/linalg.py index 45e12f1a3..07a7a0d42 100644 --- a/numpy/linalg/linalg.py +++ b/numpy/linalg/linalg.py @@ -953,7 +953,7 @@ def eigvalsh(a, UPLO='L'): Broadcasting rules apply, see the `numpy.linalg` documentation for details. - The eigenvalues are computed using LAPACK routines _ssyevd, _heevd + The eigenvalues are computed using LAPACK routines _syevd, _heevd Examples -------- @@ -1151,7 +1151,8 @@ def eigh(a, UPLO='L'): Returns ------- w : (..., M) ndarray - The eigenvalues, not necessarily ordered. + The eigenvalues in ascending order, each repeated according to + its multiplicity. v : {(..., M, M) ndarray, (..., M, M) matrix} The column ``v[:, i]`` is the normalized eigenvector corresponding to the eigenvalue ``w[i]``. Will return a matrix object if `a` is @@ -1175,7 +1176,7 @@ def eigh(a, UPLO='L'): Broadcasting rules apply, see the `numpy.linalg` documentation for details. - The eigenvalues/eigenvectors are computed using LAPACK routines _ssyevd, + The eigenvalues/eigenvectors are computed using LAPACK routines _syevd, _heevd The eigenvalues of real symmetric or complex Hermitian matrices are diff --git a/numpy/linalg/tests/test_linalg.py b/numpy/linalg/tests/test_linalg.py index c6d84706a..b179f3019 100644 --- a/numpy/linalg/tests/test_linalg.py +++ b/numpy/linalg/tests/test_linalg.py @@ -718,28 +718,27 @@ class TestEigvalsh(HermitianTestCase, HermitianGeneralizedTestCase): # Check default is 'L' w = np.linalg.eigvalsh(Klo) - assert_allclose(np.sort(w), tgt, rtol=rtol) + assert_allclose(w, tgt, rtol=rtol) # Check 'L' w = np.linalg.eigvalsh(Klo, UPLO='L') - assert_allclose(np.sort(w), tgt, rtol=rtol) + assert_allclose(w, tgt, rtol=rtol) # Check 'l' w = np.linalg.eigvalsh(Klo, UPLO='l') - assert_allclose(np.sort(w), tgt, rtol=rtol) + assert_allclose(w, tgt, rtol=rtol) # Check 'U' w = np.linalg.eigvalsh(Kup, UPLO='U') - assert_allclose(np.sort(w), tgt, rtol=rtol) + assert_allclose(w, tgt, rtol=rtol) # Check 'u' w = np.linalg.eigvalsh(Kup, UPLO='u') - assert_allclose(np.sort(w), tgt, rtol=rtol) + assert_allclose(w, tgt, rtol=rtol) class TestEigh(HermitianTestCase, HermitianGeneralizedTestCase): def do(self, a, b): - # note that eigenvalue arrays must be sorted since + # note that eigenvalue arrays returned by eig must be sorted since # their order isn't guaranteed. ev, evc = linalg.eigh(a) evalues, evectors = linalg.eig(a) - ev.sort(axis=-1) evalues.sort(axis=-1) assert_almost_equal(ev, evalues) @@ -748,7 +747,6 @@ class TestEigh(HermitianTestCase, HermitianGeneralizedTestCase): rtol=get_rtol(ev.dtype)) ev2, evc2 = linalg.eigh(a, 'U') - ev2.sort(axis=-1) assert_almost_equal(ev2, evalues) assert_allclose(dot_generalized(a, evc2), @@ -778,19 +776,19 @@ class TestEigh(HermitianTestCase, HermitianGeneralizedTestCase): # Check default is 'L' w, v = np.linalg.eigh(Klo) - assert_allclose(np.sort(w), tgt, rtol=rtol) + assert_allclose(w, tgt, rtol=rtol) # Check 'L' w, v = np.linalg.eigh(Klo, UPLO='L') - assert_allclose(np.sort(w), tgt, rtol=rtol) + assert_allclose(w, tgt, rtol=rtol) # Check 'l' w, v = np.linalg.eigh(Klo, UPLO='l') - assert_allclose(np.sort(w), tgt, rtol=rtol) + assert_allclose(w, tgt, rtol=rtol) # Check 'U' w, v = np.linalg.eigh(Kup, UPLO='U') - assert_allclose(np.sort(w), tgt, rtol=rtol) + assert_allclose(w, tgt, rtol=rtol) # Check 'u' w, v = np.linalg.eigh(Kup, UPLO='u') - assert_allclose(np.sort(w), tgt, rtol=rtol) + assert_allclose(w, tgt, rtol=rtol) class _TestNorm(object): |