summaryrefslogtreecommitdiff
path: root/numpy/linalg/tests/test_linalg.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/linalg/tests/test_linalg.py')
-rw-r--r--numpy/linalg/tests/test_linalg.py84
1 files changed, 67 insertions, 17 deletions
diff --git a/numpy/linalg/tests/test_linalg.py b/numpy/linalg/tests/test_linalg.py
index 173e81e9c..dae4ef61e 100644
--- a/numpy/linalg/tests/test_linalg.py
+++ b/numpy/linalg/tests/test_linalg.py
@@ -1,8 +1,6 @@
""" Test functions for linalg module
"""
-from __future__ import division, absolute_import, print_function
-
import os
import sys
import itertools
@@ -20,8 +18,9 @@ from numpy.linalg.linalg import _multi_dot_matrix_chain_order
from numpy.testing import (
assert_, assert_equal, assert_raises, assert_array_equal,
assert_almost_equal, assert_allclose, suppress_warnings,
- assert_raises_regex,
+ assert_raises_regex, HAS_LAPACK64,
)
+from numpy.testing._private.utils import requires_memory
def consistent_subclass(out, in_):
@@ -67,7 +66,7 @@ all_tags = {
}
-class LinalgCase(object):
+class LinalgCase:
def __init__(self, name, a, b, tags=set()):
"""
A bundle of arguments to be passed to a test case, with an identifying
@@ -332,7 +331,7 @@ CASES += _make_strided_cases()
#
# Test different routines against the above cases
#
-class LinalgTestCase(object):
+class LinalgTestCase:
TEST_CASES = CASES
def check_cases(self, require=set(), exclude=set()):
@@ -633,7 +632,7 @@ class TestEig(EigCases):
assert_(isinstance(a, np.ndarray))
-class SVDBaseTests(object):
+class SVDBaseTests:
hermitian = False
@pytest.mark.parametrize('dtype', [single, double, csingle, cdouble])
@@ -681,6 +680,14 @@ class SVDHermitianCases(HermitianTestCase, HermitianGeneralizedTestCase):
assert_allclose(a, dot_generalized(np.asarray(u) * np.asarray(s)[..., None, :],
np.asarray(vt)),
rtol=get_rtol(u.dtype))
+ def hermitian(mat):
+ axes = list(range(mat.ndim))
+ axes[-1], axes[-2] = axes[-2], axes[-1]
+ return np.conj(np.transpose(mat, axes=axes))
+
+ assert_almost_equal(np.matmul(u, hermitian(u)), np.broadcast_to(np.eye(u.shape[-1]), u.shape))
+ assert_almost_equal(np.matmul(vt, hermitian(vt)), np.broadcast_to(np.eye(vt.shape[-1]), vt.shape))
+ assert_equal(np.sort(s)[..., ::-1], s)
assert_(consistent_subclass(u, a))
assert_(consistent_subclass(vt, a))
@@ -975,7 +982,7 @@ class TestLstsq(LstsqCases):
@pytest.mark.parametrize('dt', [np.dtype(c) for c in '?bBhHiIqQefdgFDGO'])
-class TestMatrixPower(object):
+class TestMatrixPower:
rshft_0 = np.eye(4)
rshft_1 = rshft_0[[3, 0, 1, 2]]
@@ -1075,7 +1082,7 @@ class TestEigvalshCases(HermitianTestCase, HermitianGeneralizedTestCase):
assert_allclose(ev2, evalues, rtol=get_rtol(ev.dtype))
-class TestEigvalsh(object):
+class TestEigvalsh:
@pytest.mark.parametrize('dtype', [single, double, csingle, cdouble])
def test_types(self, dtype):
x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype)
@@ -1151,7 +1158,7 @@ class TestEighCases(HermitianTestCase, HermitianGeneralizedTestCase):
rtol=get_rtol(ev.dtype), err_msg=repr(a))
-class TestEigh(object):
+class TestEigh:
@pytest.mark.parametrize('dtype', [single, double, csingle, cdouble])
def test_types(self, dtype):
x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype)
@@ -1210,7 +1217,7 @@ class TestEigh(object):
assert_(isinstance(a, np.ndarray))
-class _TestNormBase(object):
+class _TestNormBase:
dt = None
dec = None
@@ -1473,11 +1480,12 @@ class _TestNorm2D(_TestNormBase):
# Using `axis=<integer>` or passing in a 1-D array implies vector
# norms are being computed, so also using `ord='fro'`
- # or `ord='nuc'` raises a ValueError.
+ # or `ord='nuc'` or any other string raises a ValueError.
assert_raises(ValueError, norm, A, 'fro', 0)
assert_raises(ValueError, norm, A, 'nuc', 0)
assert_raises(ValueError, norm, [3, 4], 'fro', None)
assert_raises(ValueError, norm, [3, 4], 'nuc', None)
+ assert_raises(ValueError, norm, [3, 4], 'test', None)
# Similarly, norm should raise an exception when ord is any finite
# number other than 1, 2, -1 or -2 when computing matrix norms.
@@ -1496,7 +1504,7 @@ class _TestNorm(_TestNorm2D, _TestNormGeneral):
pass
-class TestNorm_NonSystematic(object):
+class TestNorm_NonSystematic:
def test_longdouble_norm(self):
# Non-regression test: p-norm of longdouble would previously raise
@@ -1551,7 +1559,7 @@ class TestNormInt64(_TestNorm, _TestNormInt64Base):
pass
-class TestMatrixRank(object):
+class TestMatrixRank:
def test_matrix_rank(self):
# Full rank matrix
@@ -1600,7 +1608,7 @@ def test_reduced_rank():
assert_equal(matrix_rank(X), 8)
-class TestQR(object):
+class TestQR:
# Define the array class here, so run this on matrices elsewhere.
array = np.array
@@ -1700,7 +1708,7 @@ class TestQR(object):
self.check_qr(m2.T)
-class TestCholesky(object):
+class TestCholesky:
# TODO: are there no other tests for cholesky?
def test_basic_property(self):
@@ -1828,6 +1836,7 @@ def test_xerbla_override():
pytest.skip('Numpy xerbla not linked in.')
+@pytest.mark.slow
def test_sdot_bug_8577():
# Regression test that loading certain other libraries does not
# result to wrong results in float32 linear algebra.
@@ -1862,7 +1871,7 @@ def test_sdot_bug_8577():
subprocess.check_call([sys.executable, "-c", code])
-class TestMultiDot(object):
+class TestMultiDot:
def test_basic_function_with_three_arguments(self):
# multi_dot with three arguments uses a fast hand coded algorithm to
@@ -1956,7 +1965,7 @@ class TestMultiDot(object):
assert_raises(ValueError, multi_dot, [np.random.random((3, 3))])
-class TestTensorinv(object):
+class TestTensorinv:
@pytest.mark.parametrize("arr, ind", [
(np.ones((4, 6, 8, 2)), 2),
@@ -2002,3 +2011,44 @@ def test_unsupported_commontype():
arr = np.array([[1, -2], [2, 5]], dtype='float16')
with assert_raises_regex(TypeError, "unsupported in linalg"):
linalg.cholesky(arr)
+
+
+@pytest.mark.slow
+@pytest.mark.xfail(not HAS_LAPACK64, run=False,
+ reason="Numpy not compiled with 64-bit BLAS/LAPACK")
+@requires_memory(free_bytes=16e9)
+def test_blas64_dot():
+ n = 2**32
+ a = np.zeros([1, n], dtype=np.float32)
+ b = np.ones([1, 1], dtype=np.float32)
+ a[0,-1] = 1
+ c = np.dot(b, a)
+ assert_equal(c[0,-1], 1)
+
+
+@pytest.mark.xfail(not HAS_LAPACK64,
+ reason="Numpy not compiled with 64-bit BLAS/LAPACK")
+def test_blas64_geqrf_lwork_smoketest():
+ # Smoke test LAPACK geqrf lwork call with 64-bit integers
+ dtype = np.float64
+ lapack_routine = np.linalg.lapack_lite.dgeqrf
+
+ m = 2**32 + 1
+ n = 2**32 + 1
+ lda = m
+
+ # Dummy arrays, not referenced by the lapack routine, so don't
+ # need to be of the right size
+ a = np.zeros([1, 1], dtype=dtype)
+ work = np.zeros([1], dtype=dtype)
+ tau = np.zeros([1], dtype=dtype)
+
+ # Size query
+ results = lapack_routine(m, n, a, lda, tau, work, -1, 0)
+ assert_equal(results['info'], 0)
+ assert_equal(results['m'], m)
+ assert_equal(results['n'], m)
+
+ # Should result to an integer of a reasonable size
+ lwork = int(work.item())
+ assert_(2**32 < lwork < 2**42)