conda-forge / numpy-feedstock

A conda-smithy repository for numpy.
BSD 3-Clause "New" or "Revised" License
8 stars 47 forks source link

linalg.eigh incorrect results for complex data on osx-arm64 #287

Open jcmgray opened 1 year ago

jcmgray commented 1 year ago

Solution to issue cannot be found in the documentation.

Issue

On osx-arm64 with numpy==1.24 installed from conda-forge, np.linalg.eigh produces incorrect results for complex data types:

import numpy as np

d = 3
A = np.random.randn(d, d) + 1j * np.random.randn(d, d)
A = (A + A.conj().T)

el, ev = np.linalg.eigh(A)

# following should all be close to zero
print(np.linalg.norm(np.identity(d) - (ev @ ev.conj().T)))
# 4.115852147734368
print(np.linalg.norm(np.identity(d) - (ev.conj().T @ ev)))
# 4.115852147734368
print(np.linalg.norm(A - (ev @ np.diag(el) @ ev.conj().T)))
# 11.555496471473255

Other linalg such as svd appears to be working (though I haven't checked exhaustively).

I have checked this with:

(Can't check with blas=*=openblas as this doesn't appear to work more generally)

Using numpy from pypi the code is working fine. Thus raising the issue here assuming it is something to do with the linked lapack, but apologies if this should be in the main numpy repo.

Possibly related to #21950, thought the issue here is not simply normalization of the eigenvectors.

Installed packages

# packages in environment at /Users/johnnie/conda/envs/numpy-latest:
#
# Name                    Version                   Build  Channel
bzip2                     1.0.8                h620ffc9_4  
ca-certificates           2022.10.11           hca03da5_0  
certifi                   2022.9.24       py311hca03da5_0  
libblas                   3.9.0           1_h9886b1c_netlib  
libcblas                  3.9.0           1_h9886b1c_netlib  
libcxx                    14.0.6               h848a8c0_0  
libffi                    3.4.2                hca03da5_6  
libgfortran               5.0.0           11_3_0_hca03da5_28  
libgfortran5              11.3.0              h009349e_28  
liblapack                 3.9.0           1_h9886b1c_netlib  
libsqlite                 3.40.0               h76d750c_0    conda-forge
libzlib                   1.2.13               h03a7124_4    conda-forge
llvm-openmp               14.0.6               hc6e5704_0  
ncurses                   6.3                  h1a28f6b_3  
numpy                     1.24.1          py311ha92fb03_0    conda-forge
openssl                   3.0.7                h03a7124_1    conda-forge
pip                       22.2.2          py311hca03da5_0  
python                    3.11.0          h3ba56d0_1_cpython    conda-forge
python_abi                3.11                    3_cp311    conda-forge
readline                  8.2                  h1a28f6b_0  
setuptools                65.5.0          py311hca03da5_0  
tk                        8.6.12               hb8d0fd4_0  
tzdata                    2022g                h04d1e81_0  
wheel                     0.37.1             pyhd3eb1b0_0  
xz                        5.2.8                h80987f9_0  
zlib                      1.2.13               h03a7124_4    conda-forge

Environment info

active environment : numpy-latest
    active env location : /Users/johnnie/conda/envs/numpy-latest
            shell level : 2
       user config file : /Users/johnnie/.condarc
 populated config files : /Users/johnnie/.condarc
          conda version : 22.11.1
    conda-build version : not installed
         python version : 3.9.15.final.0
       virtual packages : __archspec=1=arm64
                          __osx=13.1=0
                          __unix=0=0
       base environment : /Users/johnnie/conda  (writable)
      conda av data dir : /Users/johnnie/conda/etc/conda
  conda av metadata url : None
           channel URLs : https://repo.anaconda.com/pkgs/main/osx-arm64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/osx-arm64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://conda.anaconda.org/conda-forge/osx-arm64
                          https://conda.anaconda.org/conda-forge/noarch
          package cache : /Users/johnnie/conda/pkgs
                          /Users/johnnie/.conda/pkgs
       envs directories : /Users/johnnie/conda/envs
                          /Users/johnnie/.conda/envs
               platform : osx-arm64
             user-agent : conda/22.11.1 requests/2.28.1 CPython/3.9.15 Darwin/22.2.0 OSX/13.1
                UID:GID : 501:20
             netrc file : None
           offline mode : False
rgommers commented 1 year ago

Thanks for the report @jcmgray. This looks suspiciously similar to https://github.com/numpy/numpy/issues/21950, which ended up being a gfortran bug.

(Can't check with blas=*=openblas as this doesn't appear to work more generally)

That's a little odd. Either way, openblas is the default so a simple mamba create -n tmp-env numpy=1.24.1 will use openblas.

rgommers commented 1 year ago

I can confirm the problem with netlib and accelerate, while openblas works fine:

% mamba create -n numpy-arm64-issue python=3.11 numpy=1.24.1  # uses openblas
% mamba activate numpy-arm64-issue
% python eigh_issue.py
7.67097720664267e-16
7.703544722840589e-16
4.057796502112606e-15

% mamba install "libblas=*=*netlib"
% python eigh_issue.py
1.7417791256257247
1.741779125625725
7.5457859052319

% mamba install "libblas=*=*accelerate"
% python eigh_issue.py
1.7299060495984222
1.7299060495984222
7.154916026621027

% mamba install "libblas=*=*openblas"  # works fine
rgommers commented 1 year ago

There are other test failures. Here is the numpy.linalg test suite result for accelerate:

FAILED tests/test_linalg.py::TestSVDHermitian::test_herm_cases - AssertionError: In test case: <LinalgCase: hcsingle>
FAILED tests/test_linalg.py::TestPinvHermitian::test_herm_cases - AssertionError: In test case: <LinalgCase: hcsingle>
FAILED tests/test_linalg.py::TestEighCases::test_herm_cases - AssertionError: In test case: <LinalgCase: hcsingle>
3 failed, 383 passed, 2 skipped, 27 deselected, 2 xfailed in 1.63s
``` python -c "import numpy; numpy.linalg.test()" /Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/_pytesttester.py:143: DeprecationWarning: `numpy.distutils` is deprecated since NumPy 1.23.0, as a result of the deprecation of `distutils` itself. It will be removed for Python >= 3.12. For older Python versions it will remain present. It is recommended to use `setuptools < 60.0` for those Python versions. For more details, see: https://numpy.org/devdocs/reference/distutils_status_migration.html from numpy.distutils import cpuinfo NumPy version 1.24.1 NumPy relaxed strides checking option: True NumPy CPU features: NEON NEON_FP16 NEON_VFPV4 ASIMD ASIMDHP* ASIMDDP* ASIMDFHM? .........................................F.....x.....F.................................................................................. [ 34%] .....................................................................................F.................................................. [ 69%] ..................................................................................s........................sx......... [100%] =================================================================== FAILURES =================================================================== _______________________________________________________ TestSVDHermitian.test_herm_cases _______________________________________________________ self = , require = {'hermitian'}, exclude = {'generalized', 'size-0'} def check_cases(self, require=set(), exclude=set()): """ Run func on each of the cases with all of the tags in require, and none of the tags in exclude """ for case in self.TEST_CASES: # filter by require and exclude if case.tags & require != require: continue if case.tags & exclude: continue try: > case.check(self.do) case = exclude = {'generalized', 'size-0'} msg = 'In test case: \n\nTraceback (most recent call last):\n File "/Users/rgommers/mambaforge/envs/n...-08j, 3.780841+3.951701e+00j],\n [ 3.780841-3.951701e+00j, 0.848612-5.960464e-08j]],\n dtype=complex64)\n' require = {'hermitian'} self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:350: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = do = > def check(self, do): """ Run the function `do` on this test case, expanding arguments """ > do(self.a, self.b, tags=self.tags) do = > self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:85: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = a = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64), b = None, tags = frozenset({'hermitian'}) def do(self, a, b, tags): u, s, vt = linalg.svd(a, False, hermitian=True) > assert_allclose(a, dot_generalized(np.asarray(u) * np.asarray(s)[..., None, :], np.asarray(vt)), rtol=get_rtol(u.dtype)) a = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64) b = None s = array([4.6055512, 2.6055512], dtype=float32) self = tags = frozenset({'hermitian'}) u = array([[-0.70710677-0.20710678j, -0.70710677-0.70710677j], [-0.8082574 +0.31099832j, 0.9805807 -0.19611613j]], dtype=complex64) vt = array([[-0.70710677+0.20710678j, -0.8082574 -0.31099832j], [ 0.70710677-0.70710677j, -0.9805807 -0.19611613j]], dtype=complex64) ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:680: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ actual = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64) desired = array([[-0.10522884+5.9604645e-08j, 3.780841 +3.9517009e+00j], [ 3.780841 -3.9517009e+00j, 0.8486117 -5.9604645e-08j]], dtype=complex64) rtol = 1e-05, atol = 0, equal_nan = True, err_msg = '', verbose = True def assert_allclose(actual, desired, rtol=1e-7, atol=0, equal_nan=True, err_msg='', verbose=True): """ Raises an AssertionError if two objects are not equal up to desired tolerance. Given two array_like objects, check that their shapes and all elements are equal (but see the Notes for the special handling of a scalar). An exception is raised if the shapes mismatch or any values conflict. In contrast to the standard usage in numpy, NaNs are compared like numbers, no assertion is raised if both objects have NaNs in the same positions. The test is equivalent to ``allclose(actual, desired, rtol, atol)`` (note that ``allclose`` has different default values). It compares the difference between `actual` and `desired` to ``atol + rtol * abs(desired)``. .. versionadded:: 1.5.0 Parameters ---------- actual : array_like Array obtained. desired : array_like Array desired. rtol : float, optional Relative tolerance. atol : float, optional Absolute tolerance. equal_nan : bool, optional. If True, NaNs will compare equal. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_array_almost_equal_nulp, assert_array_max_ulp Notes ----- When one of `actual` and `desired` is a scalar and the other is array_like, the function checks that each element of the array_like object is equal to the scalar. Examples -------- >>> x = [1e-5, 1e-3, 1e-1] >>> y = np.arccos(np.cos(x)) >>> np.testing.assert_allclose(x, y, rtol=1e-5, atol=0) """ __tracebackhide__ = True # Hide traceback for py.test import numpy as np def compare(x, y): return np.core.numeric.isclose(x, y, rtol=rtol, atol=atol, equal_nan=equal_nan) actual, desired = np.asanyarray(actual), np.asanyarray(desired) header = f'Not equal to tolerance rtol={rtol:g}, atol={atol:g}' > assert_array_compare(compare, actual, desired, err_msg=str(err_msg), verbose=verbose, header=header, equal_nan=equal_nan) __tracebackhide__ = True actual = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64) atol = 0 compare = .compare at 0x10c89ab60> desired = array([[-0.10522884+5.9604645e-08j, 3.780841 +3.9517009e+00j], [ 3.780841 -3.9517009e+00j, 0.8486117 -5.9604645e-08j]], dtype=complex64) equal_nan = True err_msg = '' header = 'Not equal to tolerance rtol=1e-05, atol=0' np = rtol = 1e-05 verbose = True ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py:1590: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (.compare at 0x10c89ab60>, array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=... 3.780841 +3.9517009e+00j], [ 3.780841 -3.9517009e+00j, 0.8486117 -5.9604645e-08j]], dtype=complex64)) kwds = {'equal_nan': True, 'err_msg': '', 'header': 'Not equal to tolerance rtol=1e-05, atol=0', 'verbose': True} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) args = (.compare at 0x10c89ab60>, array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=... 3.780841 +3.9517009e+00j], [ 3.780841 -3.9517009e+00j, 0.8486117 -5.9604645e-08j]], dtype=complex64)) func = kwds = {'equal_nan': True, 'err_msg': '', 'header': 'Not equal to tolerance rtol=1e-05, atol=0', 'verbose': True} self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ comparison = .compare at 0x10c89ab60>, x = array([1.+0.j, 2.+3.j, 2.-3.j, 1.+0.j], dtype=complex64) y = array([-0.10522884+5.9604645e-08j, 3.780841 +3.9517009e+00j, 3.780841 -3.9517009e+00j, 0.8486117 -5.9604645e-08j], dtype=complex64) err_msg = '\nMismatched elements: 4 / 4 (100%)\nMax absolute difference: 2.0191903\nMax relative difference: 10.5030985', verbose = True header = 'Not equal to tolerance rtol=1e-05, atol=0', precision = 6, equal_nan = True, equal_inf = True @np._no_nep50_warning() def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='', precision=6, equal_nan=True, equal_inf=True, *, strict=False): __tracebackhide__ = True # Hide traceback for py.test from numpy.core import array, array2string, isnan, inf, bool_, errstate, all, max, object_ x = np.asanyarray(x) y = np.asanyarray(y) # original array for output formatting ox, oy = x, y def isnumber(x): return x.dtype.char in '?bhilqpBHILQPefdgFDG' def istime(x): return x.dtype.char in "Mm" def func_assert_same_pos(x, y, func=isnan, hasval='nan'): """Handling nan/inf. Combine results of running func on x and y, checking that they are True at the same locations. """ __tracebackhide__ = True # Hide traceback for py.test x_id = func(x) y_id = func(y) # We include work-arounds here to handle three types of slightly # pathological ndarray subclasses: # (1) all() on `masked` array scalars can return masked arrays, so we # use != True # (2) __eq__ on some ndarray subclasses returns Python booleans # instead of element-wise comparisons, so we cast to bool_() and # use isinstance(..., bool) checks # (3) subclasses with bare-bones __array_function__ implementations may # not implement np.all(), so favor using the .all() method # We are not committed to supporting such subclasses, but it's nice to # support them if possible. if bool_(x_id == y_id).all() != True: msg = build_err_msg([x, y], err_msg + '\nx and y %s location mismatch:' % (hasval), verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) # If there is a scalar, then here we know the array has the same # flag as it everywhere, so we should return the scalar flag. if isinstance(x_id, bool) or x_id.ndim == 0: return bool_(x_id) elif isinstance(y_id, bool) or y_id.ndim == 0: return bool_(y_id) else: return y_id try: if strict: cond = x.shape == y.shape and x.dtype == y.dtype else: cond = (x.shape == () or y.shape == ()) or x.shape == y.shape if not cond: if x.shape != y.shape: reason = f'\n(shapes {x.shape}, {y.shape} mismatch)' else: reason = f'\n(dtypes {x.dtype}, {y.dtype} mismatch)' msg = build_err_msg([x, y], err_msg + reason, verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) flagged = bool_(False) if isnumber(x) and isnumber(y): if equal_nan: flagged = func_assert_same_pos(x, y, func=isnan, hasval='nan') if equal_inf: flagged |= func_assert_same_pos(x, y, func=lambda xy: xy == +inf, hasval='+inf') flagged |= func_assert_same_pos(x, y, func=lambda xy: xy == -inf, hasval='-inf') elif istime(x) and istime(y): # If one is datetime64 and the other timedelta64 there is no point if equal_nan and x.dtype.type == y.dtype.type: flagged = func_assert_same_pos(x, y, func=isnat, hasval="NaT") if flagged.ndim > 0: x, y = x[~flagged], y[~flagged] # Only do the comparison if actual values are left if x.size == 0: return elif flagged: # no sense doing comparison if everything is flagged. return val = comparison(x, y) if isinstance(val, bool): cond = val reduced = array([val]) else: reduced = val.ravel() cond = reduced.all() # The below comparison is a hack to ensure that fully masked # results, for which val.ravel().all() returns np.ma.masked, # do not trigger a failure (np.ma.masked != True evaluates as # np.ma.masked, which is falsy). if cond != True: n_mismatch = reduced.size - reduced.sum(dtype=intp) n_elements = flagged.size if flagged.ndim != 0 else reduced.size percent_mismatch = 100 * n_mismatch / n_elements remarks = [ 'Mismatched elements: {} / {} ({:.3g}%)'.format( n_mismatch, n_elements, percent_mismatch)] with errstate(all='ignore'): # ignore errors for non-numeric types with contextlib.suppress(TypeError): error = abs(x - y) if np.issubdtype(x.dtype, np.unsignedinteger): error2 = abs(y - x) np.minimum(error, error2, out=error) max_abs_error = max(error) if getattr(error, 'dtype', object_) == object_: remarks.append('Max absolute difference: ' + str(max_abs_error)) else: remarks.append('Max absolute difference: ' + array2string(max_abs_error)) # note: this definition of relative error matches that one # used by assert_allclose (found in np.isclose) # Filter values where the divisor would be zero nonzero = bool_(y != 0) if all(~nonzero): max_rel_error = array(inf) else: max_rel_error = max(error[nonzero] / abs(y[nonzero])) if getattr(error, 'dtype', object_) == object_: remarks.append('Max relative difference: ' + str(max_rel_error)) else: remarks.append('Max relative difference: ' + array2string(max_rel_error)) err_msg += '\n' + '\n'.join(remarks) msg = build_err_msg([ox, oy], err_msg, verbose=verbose, header=header, names=('x', 'y'), precision=precision) > raise AssertionError(msg) E AssertionError: E Not equal to tolerance rtol=1e-05, atol=0 E E Mismatched elements: 4 / 4 (100%) E Max absolute difference: 2.0191903 E Max relative difference: 10.5030985 E x: array([[1.+0.j, 2.+3.j], E [2.-3.j, 1.+0.j]], dtype=complex64) E y: array([[-0.105229+5.960464e-08j, 3.780841+3.951701e+00j], E [ 3.780841-3.951701e+00j, 0.848612-5.960464e-08j]], E dtype=complex64) __tracebackhide__ = True all = array = array2string = bool_ = comparison = .compare at 0x10c89ab60> cond = False equal_inf = True equal_nan = True err_msg = '\nMismatched elements: 4 / 4 (100%)\nMax absolute difference: 2.0191903\nMax relative difference: 10.5030985' error = array([1.1052289 , 2.0191903 , 2.0191903 , 0.15138829], dtype=float32) errstate = flagged = array([[False, False], [False, False]]) func_assert_same_pos = .func_assert_same_pos at 0x10c89ad40> header = 'Not equal to tolerance rtol=1e-05, atol=0' inf = inf isnan = isnumber = .isnumber at 0x10c89ac00> istime = .istime at 0x10c89aca0> max = max_abs_error = 2.0191903 max_rel_error = 10.5030985 msg = '\nNot equal to tolerance rtol=1e-05, atol=0\n\nMismatched elements: 4 / 4 (100%)\nMax absolute difference: 2.0191903\...4e-08j, 3.780841+3.951701e+00j],\n [ 3.780841-3.951701e+00j, 0.848612-5.960464e-08j]],\n dtype=complex64)' n_elements = 4 n_mismatch = 4 nonzero = array([ True, True, True, True]) object_ = ox = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64) oy = array([[-0.10522884+5.9604645e-08j, 3.780841 +3.9517009e+00j], [ 3.780841 -3.9517009e+00j, 0.8486117 -5.9604645e-08j]], dtype=complex64) percent_mismatch = 100.0 precision = 6 reduced = array([False, False, False, False]) remarks = ['Mismatched elements: 4 / 4 (100%)', 'Max absolute difference: 2.0191903', 'Max relative difference: 10.5030985'] strict = False val = array([False, False, False, False]) verbose = True x = array([1.+0.j, 2.+3.j, 2.-3.j, 1.+0.j], dtype=complex64) y = array([-0.10522884+5.9604645e-08j, 3.780841 +3.9517009e+00j, 3.780841 -3.9517009e+00j, 0.8486117 -5.9604645e-08j], dtype=complex64) ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py:862: AssertionError The above exception was the direct cause of the following exception: self = def test_herm_cases(self): > self.check_cases(require={'hermitian'}, exclude={'generalized', 'size-0'}) self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:382: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , require = {'hermitian'}, exclude = {'generalized', 'size-0'} def check_cases(self, require=set(), exclude=set()): """ Run func on each of the cases with all of the tags in require, and none of the tags in exclude """ for case in self.TEST_CASES: # filter by require and exclude if case.tags & require != require: continue if case.tags & exclude: continue try: case.check(self.do) except Exception as e: msg = f'In test case: {case!r}\n\n' msg += traceback.format_exc() > raise AssertionError(msg) from e E AssertionError: In test case: E E Traceback (most recent call last): E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py", line 350, in check_cases E case.check(self.do) E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py", line 85, in check E do(self.a, self.b, tags=self.tags) E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py", line 680, in do E assert_allclose(a, dot_generalized(np.asarray(u) * np.asarray(s)[..., None, :], E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py", line 1590, in assert_allclose E assert_array_compare(compare, actual, desired, err_msg=str(err_msg), E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/contextlib.py", line 81, in inner E return func(*args, **kwds) E ^^^^^^^^^^^^^^^^^^^ E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py", line 862, in assert_array_compare E raise AssertionError(msg) E AssertionError: E Not equal to tolerance rtol=1e-05, atol=0 E E Mismatched elements: 4 / 4 (100%) E Max absolute difference: 2.0191903 E Max relative difference: 10.5030985 E x: array([[1.+0.j, 2.+3.j], E [2.-3.j, 1.+0.j]], dtype=complex64) E y: array([[-0.105229+5.960464e-08j, 3.780841+3.951701e+00j], E [ 3.780841-3.951701e+00j, 0.848612-5.960464e-08j]], E dtype=complex64) case = exclude = {'generalized', 'size-0'} msg = 'In test case: \n\nTraceback (most recent call last):\n File "/Users/rgommers/mambaforge/envs/n...-08j, 3.780841+3.951701e+00j],\n [ 3.780841-3.951701e+00j, 0.848612-5.960464e-08j]],\n dtype=complex64)\n' require = {'hermitian'} self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:354: AssertionError ______________________________________________________ TestPinvHermitian.test_herm_cases _______________________________________________________ actual = array([[0.5743457 +2.3841858e-07j, 3.473448 +4.2373457e+00j], [3.4734483 -4.2373452e+00j, 0.03471792+5.9604645e-08j]], dtype=complex64) desired = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64), decimal = 5, err_msg = '', verbose = True @np._no_nep50_warning() def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): """ Raises an AssertionError if two items are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies that the elements of `actual` and `desired` satisfy. ``abs(desired-actual) < float64(1.5 * 10**(-decimal))`` That is a looser test than originally documented, but agrees with what the actual implementation in `assert_array_almost_equal` did up to rounding vagaries. An exception is raised at conflicting values. For ndarrays this delegates to assert_array_almost_equal Parameters ---------- actual : array_like The object to check. desired : array_like The expected object. decimal : int, optional Desired precision, default is 7. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- >>> from numpy.testing import assert_almost_equal >>> assert_almost_equal(2.3333333333333, 2.33333334) >>> assert_almost_equal(2.3333333333333, 2.33333334, decimal=10) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 10 decimals ACTUAL: 2.3333333333333 DESIRED: 2.33333334 >>> assert_almost_equal(np.array([1.0,2.3333333333333]), ... np.array([1.0,2.33333334]), decimal=9) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 9 decimals Mismatched elements: 1 / 2 (50%) Max absolute difference: 6.66669964e-09 Max relative difference: 2.85715698e-09 x: array([1. , 2.333333333]) y: array([1. , 2.33333334]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import ndarray from numpy.lib import iscomplexobj, real, imag # Handle complex numbers: separate into real/imag to handle # nan/inf/negative zero correctly # XXX: catch ValueError for subclasses of ndarray where iscomplex fail try: usecomplex = iscomplexobj(actual) or iscomplexobj(desired) except ValueError: usecomplex = False def _build_err_msg(): header = ('Arrays are not almost equal to %d decimals' % decimal) return build_err_msg([actual, desired], err_msg, verbose=verbose, header=header) if usecomplex: if iscomplexobj(actual): actualr = real(actual) actuali = imag(actual) else: actualr = actual actuali = 0 if iscomplexobj(desired): desiredr = real(desired) desiredi = imag(desired) else: desiredr = desired desiredi = 0 try: > assert_almost_equal(actualr, desiredr, decimal=decimal) __tracebackhide__ = True _build_err_msg = ._build_err_msg at 0x10c970360> actual = array([[0.5743457 +2.3841858e-07j, 3.473448 +4.2373457e+00j], [3.4734483 -4.2373452e+00j, 0.03471792+5.9604645e-08j]], dtype=complex64) actuali = array([[ 2.3841858e-07, 4.2373457e+00], [-4.2373452e+00, 5.9604645e-08]], dtype=float32) actualr = array([[0.5743457 , 3.473448 ], [3.4734483 , 0.03471792]], dtype=float32) decimal = 5 desired = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64) desiredi = array([[ 0., 3.], [-3., 0.]], dtype=float32) desiredr = array([[1., 2.], [2., 1.]], dtype=float32) err_msg = '' imag = iscomplexobj = ndarray = real = usecomplex = True verbose = True ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py:581: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (array([[0.5743457 , 3.473448 ], [3.4734483 , 0.03471792]], dtype=float32), array([[1., 2.], [2., 1.]], dtype=float32)) kwds = {'decimal': 5} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) args = (array([[0.5743457 , 3.473448 ], [3.4734483 , 0.03471792]], dtype=float32), array([[1., 2.], [2., 1.]], dtype=float32)) func = kwds = {'decimal': 5} self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ actual = array([[0.5743457 , 3.473448 ], [3.4734483 , 0.03471792]], dtype=float32) desired = array([[1., 2.], [2., 1.]], dtype=float32), decimal = 5, err_msg = '', verbose = True @np._no_nep50_warning() def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): """ Raises an AssertionError if two items are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies that the elements of `actual` and `desired` satisfy. ``abs(desired-actual) < float64(1.5 * 10**(-decimal))`` That is a looser test than originally documented, but agrees with what the actual implementation in `assert_array_almost_equal` did up to rounding vagaries. An exception is raised at conflicting values. For ndarrays this delegates to assert_array_almost_equal Parameters ---------- actual : array_like The object to check. desired : array_like The expected object. decimal : int, optional Desired precision, default is 7. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- >>> from numpy.testing import assert_almost_equal >>> assert_almost_equal(2.3333333333333, 2.33333334) >>> assert_almost_equal(2.3333333333333, 2.33333334, decimal=10) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 10 decimals ACTUAL: 2.3333333333333 DESIRED: 2.33333334 >>> assert_almost_equal(np.array([1.0,2.3333333333333]), ... np.array([1.0,2.33333334]), decimal=9) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 9 decimals Mismatched elements: 1 / 2 (50%) Max absolute difference: 6.66669964e-09 Max relative difference: 2.85715698e-09 x: array([1. , 2.333333333]) y: array([1. , 2.33333334]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import ndarray from numpy.lib import iscomplexobj, real, imag # Handle complex numbers: separate into real/imag to handle # nan/inf/negative zero correctly # XXX: catch ValueError for subclasses of ndarray where iscomplex fail try: usecomplex = iscomplexobj(actual) or iscomplexobj(desired) except ValueError: usecomplex = False def _build_err_msg(): header = ('Arrays are not almost equal to %d decimals' % decimal) return build_err_msg([actual, desired], err_msg, verbose=verbose, header=header) if usecomplex: if iscomplexobj(actual): actualr = real(actual) actuali = imag(actual) else: actualr = actual actuali = 0 if iscomplexobj(desired): desiredr = real(desired) desiredi = imag(desired) else: desiredr = desired desiredi = 0 try: assert_almost_equal(actualr, desiredr, decimal=decimal) assert_almost_equal(actuali, desiredi, decimal=decimal) except AssertionError: raise AssertionError(_build_err_msg()) if isinstance(actual, (ndarray, tuple, list)) \ or isinstance(desired, (ndarray, tuple, list)): > return assert_array_almost_equal(actual, desired, decimal, err_msg) __tracebackhide__ = True _build_err_msg = ._build_err_msg at 0x10c970540> actual = array([[0.5743457 , 3.473448 ], [3.4734483 , 0.03471792]], dtype=float32) decimal = 5 desired = array([[1., 2.], [2., 1.]], dtype=float32) err_msg = '' imag = iscomplexobj = ndarray = real = usecomplex = False verbose = True ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py:588: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (array([[0.5743457 , 3.473448 ], [3.4734483 , 0.03471792]], dtype=float32), array([[1., 2.], [2., 1.]], dtype=float32), 5, '') kwds = {} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) args = (array([[0.5743457 , 3.473448 ], [3.4734483 , 0.03471792]], dtype=float32), array([[1., 2.], [2., 1.]], dtype=float32), 5, '') func = kwds = {} self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ x = array([[0.5743457 , 3.473448 ], [3.4734483 , 0.03471792]], dtype=float32), y = array([[1., 2.], [2., 1.]], dtype=float32) decimal = 5, err_msg = '', verbose = True @np._no_nep50_warning() def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True): """ Raises an AssertionError if two objects are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies identical shapes and that the elements of ``actual`` and ``desired`` satisfy. ``abs(desired-actual) < 1.5 * 10**(-decimal)`` That is a looser test than originally documented, but agrees with what the actual implementation did up to rounding vagaries. An exception is raised at shape mismatch or conflicting values. In contrast to the standard usage in numpy, NaNs are compared like numbers, no assertion is raised if both objects have NaNs in the same positions. Parameters ---------- x : array_like The actual object to check. y : array_like The desired, expected object. decimal : int, optional Desired precision, default is 6. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- the first assert does not raise an exception >>> np.testing.assert_array_almost_equal([1.0,2.333,np.nan], ... [1.0,2.333,np.nan]) >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], ... [1.0,2.33339,np.nan], decimal=5) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 5 decimals Mismatched elements: 1 / 3 (33.3%) Max absolute difference: 6.e-05 Max relative difference: 2.57136612e-05 x: array([1. , 2.33333, nan]) y: array([1. , 2.33339, nan]) >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], ... [1.0,2.33333, 5], decimal=5) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 5 decimals x and y nan location mismatch: x: array([1. , 2.33333, nan]) y: array([1. , 2.33333, 5. ]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import number, float_, result_type, array from numpy.core.numerictypes import issubdtype from numpy.core.fromnumeric import any as npany def compare(x, y): try: if npany(gisinf(x)) or npany( gisinf(y)): xinfid = gisinf(x) yinfid = gisinf(y) if not (xinfid == yinfid).all(): return False # if one item, x and y is +- inf if x.size == y.size == 1: return x == y x = x[~xinfid] y = y[~yinfid] except (TypeError, NotImplementedError): pass # make sure y is an inexact type to avoid abs(MIN_INT); will cause # casting of x later. dtype = result_type(y, 1.) y = np.asanyarray(y, dtype) z = abs(x - y) if not issubdtype(z.dtype, number): z = z.astype(float_) # handle object arrays return z < 1.5 * 10.0**(-decimal) > assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose, header=('Arrays are not almost equal to %d decimals' % decimal), precision=decimal) __tracebackhide__ = True array = compare = .compare at 0x10c9705e0> decimal = 5 err_msg = '' float_ = issubdtype = npany = number = result_type = verbose = True x = array([[0.5743457 , 3.473448 ], [3.4734483 , 0.03471792]], dtype=float32) y = array([[1., 2.], [2., 1.]], dtype=float32) ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py:1097: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (.compare at 0x10c9705e0>, array([[0.5743457 , 3.473448 ], [3.4734483 , 0.03471792]], dtype=float32), array([[1., 2.], [2., 1.]], dtype=float32)) kwds = {'err_msg': '', 'header': 'Arrays are not almost equal to 5 decimals', 'precision': 5, 'verbose': True} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) args = (.compare at 0x10c9705e0>, array([[0.5743457 , 3.473448 ], [3.4734483 , 0.03471792]], dtype=float32), array([[1., 2.], [2., 1.]], dtype=float32)) func = kwds = {'err_msg': '', 'header': 'Arrays are not almost equal to 5 decimals', 'precision': 5, 'verbose': True} self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ comparison = .compare at 0x10c9705e0> x = array([0.5743457 , 3.473448 , 3.4734483 , 0.03471792], dtype=float32), y = array([1., 2., 2., 1.], dtype=float32) err_msg = '\nMismatched elements: 4 / 4 (100%)\nMax absolute difference: 1.4734483\nMax relative difference: 0.9652821', verbose = True header = 'Arrays are not almost equal to 5 decimals', precision = 5, equal_nan = True, equal_inf = True @np._no_nep50_warning() def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='', precision=6, equal_nan=True, equal_inf=True, *, strict=False): __tracebackhide__ = True # Hide traceback for py.test from numpy.core import array, array2string, isnan, inf, bool_, errstate, all, max, object_ x = np.asanyarray(x) y = np.asanyarray(y) # original array for output formatting ox, oy = x, y def isnumber(x): return x.dtype.char in '?bhilqpBHILQPefdgFDG' def istime(x): return x.dtype.char in "Mm" def func_assert_same_pos(x, y, func=isnan, hasval='nan'): """Handling nan/inf. Combine results of running func on x and y, checking that they are True at the same locations. """ __tracebackhide__ = True # Hide traceback for py.test x_id = func(x) y_id = func(y) # We include work-arounds here to handle three types of slightly # pathological ndarray subclasses: # (1) all() on `masked` array scalars can return masked arrays, so we # use != True # (2) __eq__ on some ndarray subclasses returns Python booleans # instead of element-wise comparisons, so we cast to bool_() and # use isinstance(..., bool) checks # (3) subclasses with bare-bones __array_function__ implementations may # not implement np.all(), so favor using the .all() method # We are not committed to supporting such subclasses, but it's nice to # support them if possible. if bool_(x_id == y_id).all() != True: msg = build_err_msg([x, y], err_msg + '\nx and y %s location mismatch:' % (hasval), verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) # If there is a scalar, then here we know the array has the same # flag as it everywhere, so we should return the scalar flag. if isinstance(x_id, bool) or x_id.ndim == 0: return bool_(x_id) elif isinstance(y_id, bool) or y_id.ndim == 0: return bool_(y_id) else: return y_id try: if strict: cond = x.shape == y.shape and x.dtype == y.dtype else: cond = (x.shape == () or y.shape == ()) or x.shape == y.shape if not cond: if x.shape != y.shape: reason = f'\n(shapes {x.shape}, {y.shape} mismatch)' else: reason = f'\n(dtypes {x.dtype}, {y.dtype} mismatch)' msg = build_err_msg([x, y], err_msg + reason, verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) flagged = bool_(False) if isnumber(x) and isnumber(y): if equal_nan: flagged = func_assert_same_pos(x, y, func=isnan, hasval='nan') if equal_inf: flagged |= func_assert_same_pos(x, y, func=lambda xy: xy == +inf, hasval='+inf') flagged |= func_assert_same_pos(x, y, func=lambda xy: xy == -inf, hasval='-inf') elif istime(x) and istime(y): # If one is datetime64 and the other timedelta64 there is no point if equal_nan and x.dtype.type == y.dtype.type: flagged = func_assert_same_pos(x, y, func=isnat, hasval="NaT") if flagged.ndim > 0: x, y = x[~flagged], y[~flagged] # Only do the comparison if actual values are left if x.size == 0: return elif flagged: # no sense doing comparison if everything is flagged. return val = comparison(x, y) if isinstance(val, bool): cond = val reduced = array([val]) else: reduced = val.ravel() cond = reduced.all() # The below comparison is a hack to ensure that fully masked # results, for which val.ravel().all() returns np.ma.masked, # do not trigger a failure (np.ma.masked != True evaluates as # np.ma.masked, which is falsy). if cond != True: n_mismatch = reduced.size - reduced.sum(dtype=intp) n_elements = flagged.size if flagged.ndim != 0 else reduced.size percent_mismatch = 100 * n_mismatch / n_elements remarks = [ 'Mismatched elements: {} / {} ({:.3g}%)'.format( n_mismatch, n_elements, percent_mismatch)] with errstate(all='ignore'): # ignore errors for non-numeric types with contextlib.suppress(TypeError): error = abs(x - y) if np.issubdtype(x.dtype, np.unsignedinteger): error2 = abs(y - x) np.minimum(error, error2, out=error) max_abs_error = max(error) if getattr(error, 'dtype', object_) == object_: remarks.append('Max absolute difference: ' + str(max_abs_error)) else: remarks.append('Max absolute difference: ' + array2string(max_abs_error)) # note: this definition of relative error matches that one # used by assert_allclose (found in np.isclose) # Filter values where the divisor would be zero nonzero = bool_(y != 0) if all(~nonzero): max_rel_error = array(inf) else: max_rel_error = max(error[nonzero] / abs(y[nonzero])) if getattr(error, 'dtype', object_) == object_: remarks.append('Max relative difference: ' + str(max_rel_error)) else: remarks.append('Max relative difference: ' + array2string(max_rel_error)) err_msg += '\n' + '\n'.join(remarks) msg = build_err_msg([ox, oy], err_msg, verbose=verbose, header=header, names=('x', 'y'), precision=precision) > raise AssertionError(msg) E AssertionError: E Arrays are not almost equal to 5 decimals E E Mismatched elements: 4 / 4 (100%) E Max absolute difference: 1.4734483 E Max relative difference: 0.9652821 E x: array([[0.57435, 3.47345], E [3.47345, 0.03472]], dtype=float32) E y: array([[1., 2.], E [2., 1.]], dtype=float32) __tracebackhide__ = True all = array = array2string = bool_ = comparison = .compare at 0x10c9705e0> cond = False equal_inf = True equal_nan = True err_msg = '\nMismatched elements: 4 / 4 (100%)\nMax absolute difference: 1.4734483\nMax relative difference: 0.9652821' error = array([0.4256543, 1.473448 , 1.4734483, 0.9652821], dtype=float32) errstate = flagged = array([[False, False], [False, False]]) func_assert_same_pos = .func_assert_same_pos at 0x10c9707c0> header = 'Arrays are not almost equal to 5 decimals' inf = inf isnan = isnumber = .isnumber at 0x10c970680> istime = .istime at 0x10c970720> max = max_abs_error = 1.4734483 max_rel_error = 0.9652821 msg = '\nArrays are not almost equal to 5 decimals\n\nMismatched elements: 4 / 4 (100%)\nMax absolute difference: 1.4734483\...0.57435, 3.47345],\n [3.47345, 0.03472]], dtype=float32)\n y: array([[1., 2.],\n [2., 1.]], dtype=float32)' n_elements = 4 n_mismatch = 4 nonzero = array([ True, True, True, True]) object_ = ox = array([[0.5743457 , 3.473448 ], [3.4734483 , 0.03471792]], dtype=float32) oy = array([[1., 2.], [2., 1.]], dtype=float32) percent_mismatch = 100.0 precision = 5 reduced = array([False, False, False, False]) remarks = ['Mismatched elements: 4 / 4 (100%)', 'Max absolute difference: 1.4734483', 'Max relative difference: 0.9652821'] strict = False val = array([False, False, False, False]) verbose = True x = array([0.5743457 , 3.473448 , 3.4734483 , 0.03471792], dtype=float32) y = array([1., 2., 2., 1.], dtype=float32) ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py:862: AssertionError During handling of the above exception, another exception occurred: self = , require = {'hermitian'}, exclude = {'generalized', 'size-0'} def check_cases(self, require=set(), exclude=set()): """ Run func on each of the cases with all of the tags in require, and none of the tags in exclude """ for case in self.TEST_CASES: # filter by require and exclude if case.tags & require != require: continue if case.tags & exclude: continue try: > case.check(self.do) case = exclude = {'generalized', 'size-0'} msg = 'In test case: \n\nTraceback (most recent call last):\n File "/Users/rgommers/mambaforge/envs/n...4645e-08j]],\n dtype=complex64)\n DESIRED: array([[1.+0.j, 2.+3.j],\n [2.-3.j, 1.+0.j]], dtype=complex64)\n' require = {'hermitian'} self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:350: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = do = > def check(self, do): """ Run the function `do` on this test case, expanding arguments """ > do(self.a, self.b, tags=self.tags) do = > self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:85: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = a = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64), b = None, tags = frozenset({'hermitian'}) def do(self, a, b, tags): a_ginv = linalg.pinv(a, hermitian=True) # `a @ a_ginv == I` does not hold if a is singular dot = dot_generalized > assert_almost_equal(dot(dot(a, a_ginv), a), a, single_decimal=5, double_decimal=11) a = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64) a_ginv = array([[-0.26591796+0.0000000e+00j, 0.24816822+4.5332125e-01j], [ 0.24816824-4.5332125e-01j, -0.220949 +7.4505806e-09j]], dtype=complex64) b = None dot = self = tags = frozenset({'hermitian'}) ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:835: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ a = array([[0.5743457 +2.3841858e-07j, 3.473448 +4.2373457e+00j], [3.4734483 -4.2373452e+00j, 0.03471792+5.9604645e-08j]], dtype=complex64) b = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64), single_decimal = 5, double_decimal = 11, kw = {}, decimal = 5 def assert_almost_equal(a, b, single_decimal=6, double_decimal=12, **kw): if asarray(a).dtype.type in (single, csingle): decimal = single_decimal else: decimal = double_decimal > old_assert_almost_equal(a, b, decimal=decimal, **kw) a = array([[0.5743457 +2.3841858e-07j, 3.473448 +4.2373457e+00j], [3.4734483 -4.2373452e+00j, 0.03471792+5.9604645e-08j]], dtype=complex64) b = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64) decimal = 5 double_decimal = 11 kw = {} single_decimal = 5 ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:41: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (array([[0.5743457 +2.3841858e-07j, 3.473448 +4.2373457e+00j], [3.4734483 -4.2373452e+00j, 0.03471792+5.9604645e-08j]], dtype=complex64), array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64)) kwds = {'decimal': 5} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) args = (array([[0.5743457 +2.3841858e-07j, 3.473448 +4.2373457e+00j], [3.4734483 -4.2373452e+00j, 0.03471792+5.9604645e-08j]], dtype=complex64), array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64)) func = kwds = {'decimal': 5} self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ actual = array([[0.5743457 +2.3841858e-07j, 3.473448 +4.2373457e+00j], [3.4734483 -4.2373452e+00j, 0.03471792+5.9604645e-08j]], dtype=complex64) desired = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64), decimal = 5, err_msg = '', verbose = True @np._no_nep50_warning() def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): """ Raises an AssertionError if two items are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies that the elements of `actual` and `desired` satisfy. ``abs(desired-actual) < float64(1.5 * 10**(-decimal))`` That is a looser test than originally documented, but agrees with what the actual implementation in `assert_array_almost_equal` did up to rounding vagaries. An exception is raised at conflicting values. For ndarrays this delegates to assert_array_almost_equal Parameters ---------- actual : array_like The object to check. desired : array_like The expected object. decimal : int, optional Desired precision, default is 7. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- >>> from numpy.testing import assert_almost_equal >>> assert_almost_equal(2.3333333333333, 2.33333334) >>> assert_almost_equal(2.3333333333333, 2.33333334, decimal=10) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 10 decimals ACTUAL: 2.3333333333333 DESIRED: 2.33333334 >>> assert_almost_equal(np.array([1.0,2.3333333333333]), ... np.array([1.0,2.33333334]), decimal=9) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 9 decimals Mismatched elements: 1 / 2 (50%) Max absolute difference: 6.66669964e-09 Max relative difference: 2.85715698e-09 x: array([1. , 2.333333333]) y: array([1. , 2.33333334]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import ndarray from numpy.lib import iscomplexobj, real, imag # Handle complex numbers: separate into real/imag to handle # nan/inf/negative zero correctly # XXX: catch ValueError for subclasses of ndarray where iscomplex fail try: usecomplex = iscomplexobj(actual) or iscomplexobj(desired) except ValueError: usecomplex = False def _build_err_msg(): header = ('Arrays are not almost equal to %d decimals' % decimal) return build_err_msg([actual, desired], err_msg, verbose=verbose, header=header) if usecomplex: if iscomplexobj(actual): actualr = real(actual) actuali = imag(actual) else: actualr = actual actuali = 0 if iscomplexobj(desired): desiredr = real(desired) desiredi = imag(desired) else: desiredr = desired desiredi = 0 try: assert_almost_equal(actualr, desiredr, decimal=decimal) assert_almost_equal(actuali, desiredi, decimal=decimal) except AssertionError: > raise AssertionError(_build_err_msg()) E AssertionError: E Arrays are not almost equal to 5 decimals E ACTUAL: array([[0.5743457 +2.3841858e-07j, 3.473448 +4.2373457e+00j], E [3.4734483 -4.2373452e+00j, 0.03471792+5.9604645e-08j]], E dtype=complex64) E DESIRED: array([[1.+0.j, 2.+3.j], E [2.-3.j, 1.+0.j]], dtype=complex64) __tracebackhide__ = True _build_err_msg = ._build_err_msg at 0x10c970360> actual = array([[0.5743457 +2.3841858e-07j, 3.473448 +4.2373457e+00j], [3.4734483 -4.2373452e+00j, 0.03471792+5.9604645e-08j]], dtype=complex64) actuali = array([[ 2.3841858e-07, 4.2373457e+00], [-4.2373452e+00, 5.9604645e-08]], dtype=float32) actualr = array([[0.5743457 , 3.473448 ], [3.4734483 , 0.03471792]], dtype=float32) decimal = 5 desired = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64) desiredi = array([[ 0., 3.], [-3., 0.]], dtype=float32) desiredr = array([[1., 2.], [2., 1.]], dtype=float32) err_msg = '' imag = iscomplexobj = ndarray = real = usecomplex = True verbose = True ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py:584: AssertionError The above exception was the direct cause of the following exception: self = def test_herm_cases(self): > self.check_cases(require={'hermitian'}, exclude={'generalized', 'size-0'}) self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:382: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , require = {'hermitian'}, exclude = {'generalized', 'size-0'} def check_cases(self, require=set(), exclude=set()): """ Run func on each of the cases with all of the tags in require, and none of the tags in exclude """ for case in self.TEST_CASES: # filter by require and exclude if case.tags & require != require: continue if case.tags & exclude: continue try: case.check(self.do) except Exception as e: msg = f'In test case: {case!r}\n\n' msg += traceback.format_exc() > raise AssertionError(msg) from e E AssertionError: In test case: E E Traceback (most recent call last): E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py", line 581, in assert_almost_equal E assert_almost_equal(actualr, desiredr, decimal=decimal) E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/contextlib.py", line 81, in inner E return func(*args, **kwds) E ^^^^^^^^^^^^^^^^^^^ E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py", line 588, in assert_almost_equal E return assert_array_almost_equal(actual, desired, decimal, err_msg) E ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/contextlib.py", line 81, in inner E return func(*args, **kwds) E ^^^^^^^^^^^^^^^^^^^ E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py", line 1097, in assert_array_almost_equal E assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose, E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/contextlib.py", line 81, in inner E return func(*args, **kwds) E ^^^^^^^^^^^^^^^^^^^ E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py", line 862, in assert_array_compare E raise AssertionError(msg) E AssertionError: E Arrays are not almost equal to 5 decimals E E Mismatched elements: 4 / 4 (100%) E Max absolute difference: 1.4734483 E Max relative difference: 0.9652821 E x: array([[0.57435, 3.47345], E [3.47345, 0.03472]], dtype=float32) E y: array([[1., 2.], E [2., 1.]], dtype=float32) E E During handling of the above exception, another exception occurred: E E Traceback (most recent call last): E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py", line 350, in check_cases E case.check(self.do) E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py", line 85, in check E do(self.a, self.b, tags=self.tags) E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py", line 835, in do E assert_almost_equal(dot(dot(a, a_ginv), a), a, single_decimal=5, double_decimal=11) E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py", line 41, in assert_almost_equal E old_assert_almost_equal(a, b, decimal=decimal, **kw) E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/contextlib.py", line 81, in inner E return func(*args, **kwds) E ^^^^^^^^^^^^^^^^^^^ E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py", line 584, in assert_almost_equal E raise AssertionError(_build_err_msg()) E AssertionError: E Arrays are not almost equal to 5 decimals E ACTUAL: array([[0.5743457 +2.3841858e-07j, 3.473448 +4.2373457e+00j], E [3.4734483 -4.2373452e+00j, 0.03471792+5.9604645e-08j]], E dtype=complex64) E DESIRED: array([[1.+0.j, 2.+3.j], E [2.-3.j, 1.+0.j]], dtype=complex64) case = exclude = {'generalized', 'size-0'} msg = 'In test case: \n\nTraceback (most recent call last):\n File "/Users/rgommers/mambaforge/envs/n...4645e-08j]],\n dtype=complex64)\n DESIRED: array([[1.+0.j, 2.+3.j],\n [2.-3.j, 1.+0.j]], dtype=complex64)\n' require = {'hermitian'} self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:354: AssertionError ________________________________________________________ TestEighCases.test_herm_cases _________________________________________________________ self = , require = {'hermitian'}, exclude = {'generalized', 'size-0'} def check_cases(self, require=set(), exclude=set()): """ Run func on each of the cases with all of the tags in require, and none of the tags in exclude """ for case in self.TEST_CASES: # filter by require and exclude if case.tags & require != require: continue if case.tags & exclude: continue try: > case.check(self.do) case = exclude = {'generalized', 'size-0'} msg = 'In test case: \n\nTraceback (most recent call last):\n File "/Users/rgommers/mambaforge/envs/n...y([[ 1.842403+1.842403j, -3.256616-0.953841j],\n [-2.554953+0.510991j, -3.722471+1.432319j]], dtype=complex64)\n' require = {'hermitian'} self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:350: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , do = > def check(self, do): """ Run the function `do` on this test case, expanding arguments """ > do(self.a, self.b, tags=self.tags) do = > self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:85: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = a = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64), b = None, tags = frozenset({'hermitian'}) def do(self, a, b, tags): # 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) evalues.sort(axis=-1) assert_almost_equal(ev, evalues) > assert_allclose(dot_generalized(a, evc), np.asarray(ev)[..., None, :] * np.asarray(evc), rtol=get_rtol(ev.dtype)) a = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64) b = None ev = array([-2.6055512, 4.6055512], dtype=float32) evalues = array([-2.6055512-1.110223e-16j, 4.6055512+1.110223e-16j], dtype=complex64) evc = array([[-0.70710677-0.70710677j, -0.70710677-0.20710678j], [ 0.9805807 -0.19611613j, -0.8082574 +0.31099832j]], dtype=complex64) evectors = array([[ 0.39223227+0.5883484j, -0.39223227-0.5883484j], [ 0.70710677+0.j , 0.70710677+0.j ]], dtype=complex64) self = tags = frozenset({'hermitian'}) ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:1152: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ actual = array([[ 1.8424029+1.8424029j, -3.2566166-2.0098825j], [-2.554953 +0.5109906j, -2.8437915+2.018105j ]], dtype=complex64) desired = array([[ 1.8424029+1.8424029j, -3.2566164-0.9538409j], [-2.5549533+0.5109906j, -3.7224708+1.4323187j]], dtype=complex64) rtol = 1e-05, atol = 0, equal_nan = True, err_msg = '', verbose = True def assert_allclose(actual, desired, rtol=1e-7, atol=0, equal_nan=True, err_msg='', verbose=True): """ Raises an AssertionError if two objects are not equal up to desired tolerance. Given two array_like objects, check that their shapes and all elements are equal (but see the Notes for the special handling of a scalar). An exception is raised if the shapes mismatch or any values conflict. In contrast to the standard usage in numpy, NaNs are compared like numbers, no assertion is raised if both objects have NaNs in the same positions. The test is equivalent to ``allclose(actual, desired, rtol, atol)`` (note that ``allclose`` has different default values). It compares the difference between `actual` and `desired` to ``atol + rtol * abs(desired)``. .. versionadded:: 1.5.0 Parameters ---------- actual : array_like Array obtained. desired : array_like Array desired. rtol : float, optional Relative tolerance. atol : float, optional Absolute tolerance. equal_nan : bool, optional. If True, NaNs will compare equal. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_array_almost_equal_nulp, assert_array_max_ulp Notes ----- When one of `actual` and `desired` is a scalar and the other is array_like, the function checks that each element of the array_like object is equal to the scalar. Examples -------- >>> x = [1e-5, 1e-3, 1e-1] >>> y = np.arccos(np.cos(x)) >>> np.testing.assert_allclose(x, y, rtol=1e-5, atol=0) """ __tracebackhide__ = True # Hide traceback for py.test import numpy as np def compare(x, y): return np.core.numeric.isclose(x, y, rtol=rtol, atol=atol, equal_nan=equal_nan) actual, desired = np.asanyarray(actual), np.asanyarray(desired) header = f'Not equal to tolerance rtol={rtol:g}, atol={atol:g}' > assert_array_compare(compare, actual, desired, err_msg=str(err_msg), verbose=verbose, header=header, equal_nan=equal_nan) __tracebackhide__ = True actual = array([[ 1.8424029+1.8424029j, -3.2566166-2.0098825j], [-2.554953 +0.5109906j, -2.8437915+2.018105j ]], dtype=complex64) atol = 0 compare = .compare at 0x10c9c6520> desired = array([[ 1.8424029+1.8424029j, -3.2566164-0.9538409j], [-2.5549533+0.5109906j, -3.7224708+1.4323187j]], dtype=complex64) equal_nan = True err_msg = '' header = 'Not equal to tolerance rtol=1e-05, atol=0' np = rtol = 1e-05 verbose = True ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py:1590: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (.compare at 0x10c9c6520>, array([[ 1.8424029+1.8424029j, -3.2566166-2.0098825j], ...1.8424029+1.8424029j, -3.2566164-0.9538409j], [-2.5549533+0.5109906j, -3.7224708+1.4323187j]], dtype=complex64)) kwds = {'equal_nan': True, 'err_msg': '', 'header': 'Not equal to tolerance rtol=1e-05, atol=0', 'verbose': True} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) args = (.compare at 0x10c9c6520>, array([[ 1.8424029+1.8424029j, -3.2566166-2.0098825j], ...1.8424029+1.8424029j, -3.2566164-0.9538409j], [-2.5549533+0.5109906j, -3.7224708+1.4323187j]], dtype=complex64)) func = kwds = {'equal_nan': True, 'err_msg': '', 'header': 'Not equal to tolerance rtol=1e-05, atol=0', 'verbose': True} self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ comparison = .compare at 0x10c9c6520> x = array([ 1.8424029+1.8424029j, -3.2566166-2.0098825j, -2.554953 +0.5109906j, -2.8437915+2.018105j ], dtype=complex64) y = array([ 1.8424029+1.8424029j, -3.2566164-0.9538409j, -2.5549533+0.5109906j, -3.7224708+1.4323187j], dtype=complex64) err_msg = '\nMismatched elements: 2 / 4 (50%)\nMax absolute difference: 1.0560415\nMax relative difference: 0.31120184', verbose = True header = 'Not equal to tolerance rtol=1e-05, atol=0', precision = 6, equal_nan = True, equal_inf = True @np._no_nep50_warning() def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='', precision=6, equal_nan=True, equal_inf=True, *, strict=False): __tracebackhide__ = True # Hide traceback for py.test from numpy.core import array, array2string, isnan, inf, bool_, errstate, all, max, object_ x = np.asanyarray(x) y = np.asanyarray(y) # original array for output formatting ox, oy = x, y def isnumber(x): return x.dtype.char in '?bhilqpBHILQPefdgFDG' def istime(x): return x.dtype.char in "Mm" def func_assert_same_pos(x, y, func=isnan, hasval='nan'): """Handling nan/inf. Combine results of running func on x and y, checking that they are True at the same locations. """ __tracebackhide__ = True # Hide traceback for py.test x_id = func(x) y_id = func(y) # We include work-arounds here to handle three types of slightly # pathological ndarray subclasses: # (1) all() on `masked` array scalars can return masked arrays, so we # use != True # (2) __eq__ on some ndarray subclasses returns Python booleans # instead of element-wise comparisons, so we cast to bool_() and # use isinstance(..., bool) checks # (3) subclasses with bare-bones __array_function__ implementations may # not implement np.all(), so favor using the .all() method # We are not committed to supporting such subclasses, but it's nice to # support them if possible. if bool_(x_id == y_id).all() != True: msg = build_err_msg([x, y], err_msg + '\nx and y %s location mismatch:' % (hasval), verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) # If there is a scalar, then here we know the array has the same # flag as it everywhere, so we should return the scalar flag. if isinstance(x_id, bool) or x_id.ndim == 0: return bool_(x_id) elif isinstance(y_id, bool) or y_id.ndim == 0: return bool_(y_id) else: return y_id try: if strict: cond = x.shape == y.shape and x.dtype == y.dtype else: cond = (x.shape == () or y.shape == ()) or x.shape == y.shape if not cond: if x.shape != y.shape: reason = f'\n(shapes {x.shape}, {y.shape} mismatch)' else: reason = f'\n(dtypes {x.dtype}, {y.dtype} mismatch)' msg = build_err_msg([x, y], err_msg + reason, verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) flagged = bool_(False) if isnumber(x) and isnumber(y): if equal_nan: flagged = func_assert_same_pos(x, y, func=isnan, hasval='nan') if equal_inf: flagged |= func_assert_same_pos(x, y, func=lambda xy: xy == +inf, hasval='+inf') flagged |= func_assert_same_pos(x, y, func=lambda xy: xy == -inf, hasval='-inf') elif istime(x) and istime(y): # If one is datetime64 and the other timedelta64 there is no point if equal_nan and x.dtype.type == y.dtype.type: flagged = func_assert_same_pos(x, y, func=isnat, hasval="NaT") if flagged.ndim > 0: x, y = x[~flagged], y[~flagged] # Only do the comparison if actual values are left if x.size == 0: return elif flagged: # no sense doing comparison if everything is flagged. return val = comparison(x, y) if isinstance(val, bool): cond = val reduced = array([val]) else: reduced = val.ravel() cond = reduced.all() # The below comparison is a hack to ensure that fully masked # results, for which val.ravel().all() returns np.ma.masked, # do not trigger a failure (np.ma.masked != True evaluates as # np.ma.masked, which is falsy). if cond != True: n_mismatch = reduced.size - reduced.sum(dtype=intp) n_elements = flagged.size if flagged.ndim != 0 else reduced.size percent_mismatch = 100 * n_mismatch / n_elements remarks = [ 'Mismatched elements: {} / {} ({:.3g}%)'.format( n_mismatch, n_elements, percent_mismatch)] with errstate(all='ignore'): # ignore errors for non-numeric types with contextlib.suppress(TypeError): error = abs(x - y) if np.issubdtype(x.dtype, np.unsignedinteger): error2 = abs(y - x) np.minimum(error, error2, out=error) max_abs_error = max(error) if getattr(error, 'dtype', object_) == object_: remarks.append('Max absolute difference: ' + str(max_abs_error)) else: remarks.append('Max absolute difference: ' + array2string(max_abs_error)) # note: this definition of relative error matches that one # used by assert_allclose (found in np.isclose) # Filter values where the divisor would be zero nonzero = bool_(y != 0) if all(~nonzero): max_rel_error = array(inf) else: max_rel_error = max(error[nonzero] / abs(y[nonzero])) if getattr(error, 'dtype', object_) == object_: remarks.append('Max relative difference: ' + str(max_rel_error)) else: remarks.append('Max relative difference: ' + array2string(max_rel_error)) err_msg += '\n' + '\n'.join(remarks) msg = build_err_msg([ox, oy], err_msg, verbose=verbose, header=header, names=('x', 'y'), precision=precision) > raise AssertionError(msg) E AssertionError: E Not equal to tolerance rtol=1e-05, atol=0 E E Mismatched elements: 2 / 4 (50%) E Max absolute difference: 1.0560415 E Max relative difference: 0.31120184 E x: array([[ 1.842403+1.842403j, -3.256617-2.009882j], E [-2.554953+0.510991j, -2.843791+2.018105j]], dtype=complex64) E y: array([[ 1.842403+1.842403j, -3.256616-0.953841j], E [-2.554953+0.510991j, -3.722471+1.432319j]], dtype=complex64) __tracebackhide__ = True all = array = array2string = bool_ = comparison = .compare at 0x10c9c6520> cond = False equal_inf = True equal_nan = True err_msg = '\nMismatched elements: 2 / 4 (50%)\nMax absolute difference: 1.0560415\nMax relative difference: 0.31120184' error = array([0.0000000e+00, 1.0560415e+00, 2.3841858e-07, 1.0560411e+00], dtype=float32) errstate = flagged = array([[False, False], [False, False]]) func_assert_same_pos = .func_assert_same_pos at 0x10c9c6700> header = 'Not equal to tolerance rtol=1e-05, atol=0' inf = inf isnan = isnumber = .isnumber at 0x10c9c65c0> istime = .istime at 0x10c9c67a0> max = max_abs_error = 1.0560415 max_rel_error = 0.31120184 msg = '\nNot equal to tolerance rtol=1e-05, atol=0\n\nMismatched elements: 2 / 4 (50%)\nMax absolute difference: 1.0560415\n...ray([[ 1.842403+1.842403j, -3.256616-0.953841j],\n [-2.554953+0.510991j, -3.722471+1.432319j]], dtype=complex64)' n_elements = 4 n_mismatch = 2 nonzero = array([ True, True, True, True]) object_ = ox = array([[ 1.8424029+1.8424029j, -3.2566166-2.0098825j], [-2.554953 +0.5109906j, -2.8437915+2.018105j ]], dtype=complex64) oy = array([[ 1.8424029+1.8424029j, -3.2566164-0.9538409j], [-2.5549533+0.5109906j, -3.7224708+1.4323187j]], dtype=complex64) percent_mismatch = 50.0 precision = 6 reduced = array([ True, False, True, False]) remarks = ['Mismatched elements: 2 / 4 (50%)', 'Max absolute difference: 1.0560415', 'Max relative difference: 0.31120184'] strict = False val = array([ True, False, True, False]) verbose = True x = array([ 1.8424029+1.8424029j, -3.2566166-2.0098825j, -2.554953 +0.5109906j, -2.8437915+2.018105j ], dtype=complex64) y = array([ 1.8424029+1.8424029j, -3.2566164-0.9538409j, -2.5549533+0.5109906j, -3.7224708+1.4323187j], dtype=complex64) ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py:862: AssertionError The above exception was the direct cause of the following exception: self = def test_herm_cases(self): > self.check_cases(require={'hermitian'}, exclude={'generalized', 'size-0'}) self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:382: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , require = {'hermitian'}, exclude = {'generalized', 'size-0'} def check_cases(self, require=set(), exclude=set()): """ Run func on each of the cases with all of the tags in require, and none of the tags in exclude """ for case in self.TEST_CASES: # filter by require and exclude if case.tags & require != require: continue if case.tags & exclude: continue try: case.check(self.do) except Exception as e: msg = f'In test case: {case!r}\n\n' msg += traceback.format_exc() > raise AssertionError(msg) from e E AssertionError: In test case: E E Traceback (most recent call last): E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py", line 350, in check_cases E case.check(self.do) E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py", line 85, in check E do(self.a, self.b, tags=self.tags) E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py", line 1152, in do E assert_allclose(dot_generalized(a, evc), E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py", line 1590, in assert_allclose E assert_array_compare(compare, actual, desired, err_msg=str(err_msg), E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/contextlib.py", line 81, in inner E return func(*args, **kwds) E ^^^^^^^^^^^^^^^^^^^ E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py", line 862, in assert_array_compare E raise AssertionError(msg) E AssertionError: E Not equal to tolerance rtol=1e-05, atol=0 E E Mismatched elements: 2 / 4 (50%) E Max absolute difference: 1.0560415 E Max relative difference: 0.31120184 E x: array([[ 1.842403+1.842403j, -3.256617-2.009882j], E [-2.554953+0.510991j, -2.843791+2.018105j]], dtype=complex64) E y: array([[ 1.842403+1.842403j, -3.256616-0.953841j], E [-2.554953+0.510991j, -3.722471+1.432319j]], dtype=complex64) case = exclude = {'generalized', 'size-0'} msg = 'In test case: \n\nTraceback (most recent call last):\n File "/Users/rgommers/mambaforge/envs/n...y([[ 1.842403+1.842403j, -3.256616-0.953841j],\n [-2.554953+0.510991j, -3.722471+1.432319j]], dtype=complex64)\n' require = {'hermitian'} self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:354: AssertionError =========================================================== short test summary info ============================================================ FAILED tests/test_linalg.py::TestSVDHermitian::test_herm_cases - AssertionError: In test case: FAILED tests/test_linalg.py::TestPinvHermitian::test_herm_cases - AssertionError: In test case: FAILED tests/test_linalg.py::TestEighCases::test_herm_cases - AssertionError: In test case: 3 failed, 383 passed, 2 skipped, 27 deselected, 2 xfailed in 1.63s ```

And for netlib:

FAILED tests/test_linalg.py::TestSVDHermitian::test_herm_cases - AssertionError: In test case: <LinalgCase: hcsingle>
FAILED tests/test_linalg.py::TestPinvHermitian::test_herm_cases - AssertionError: In test case: <LinalgCase: hcsingle>
FAILED tests/test_linalg.py::TestEighCases::test_herm_cases - AssertionError: In test case: <LinalgCase: hcsingle>
FAILED tests/test_linalg.py::TestCholesky::test_basic_property[complex64-shape1] - numpy.linalg.LinAlgError: Matrix is not positive definite
FAILED tests/test_linalg.py::TestCholesky::test_basic_property[complex64-shape2] - numpy.linalg.LinAlgError: Matrix is not positive definite
FAILED tests/test_linalg.py::TestCholesky::test_basic_property[complex64-shape3] - numpy.linalg.LinAlgError: Matrix is not positive definite
FAILED tests/test_linalg.py::TestCholesky::test_basic_property[complex64-shape4] - numpy.linalg.LinAlgError: Matrix is not positive definite
FAILED tests/test_linalg.py::TestCholesky::test_basic_property[complex128-shape1] - numpy.linalg.LinAlgError: Matrix is not positive definite
FAILED tests/test_linalg.py::TestCholesky::test_basic_property[complex128-shape2] - numpy.linalg.LinAlgError: Matrix is not positive definite
FAILED tests/test_linalg.py::TestCholesky::test_basic_property[complex128-shape3] - numpy.linalg.LinAlgError: Matrix is not positive definite
FAILED tests/test_linalg.py::TestCholesky::test_basic_property[complex128-shape4] - numpy.linalg.LinAlgError: Matrix is not positive definite
11 failed, 375 passed, 2 skipped, 27 deselected, 2 xfailed in 1.93s
``` python -c "import numpy; numpy.linalg.test()" /Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/_pytesttester.py:143: DeprecationWarning: `numpy.distutils` is deprecated since NumPy 1.23.0, as a result of the deprecation of `distutils` itself. It will be removed for Python >= 3.12. For older Python versions it will remain present. It is recommended to use `setuptools < 60.0` for those Python versions. For more details, see: https://numpy.org/devdocs/reference/distutils_status_migration.html from numpy.distutils import cpuinfo NumPy version 1.24.1 NumPy relaxed strides checking option: True NumPy CPU features: NEON NEON_FP16 NEON_VFPV4 ASIMD ASIMDHP* ASIMDDP* ASIMDFHM? .........................................F.....x.....F.................................................................................. [ 34%] .....................................................................................F.................................................. [ 69%] ......................................................................FFFF.FFFF...s........................sx......... [100%] =================================================================== FAILURES =================================================================== _______________________________________________________ TestSVDHermitian.test_herm_cases _______________________________________________________ self = , require = {'hermitian'}, exclude = {'generalized', 'size-0'} def check_cases(self, require=set(), exclude=set()): """ Run func on each of the cases with all of the tags in require, and none of the tags in exclude """ for case in self.TEST_CASES: # filter by require and exclude if case.tags & require != require: continue if case.tags & exclude: continue try: > case.check(self.do) case = exclude = {'generalized', 'size-0'} msg = 'In test case: \n\nTraceback (most recent call last):\n File "/Users/rgommers/mambaforge/envs/n...-08j, 3.780841+3.951701e+00j],\n [ 3.780841-3.951701e+00j, 0.848612-4.494268e-08j]],\n dtype=complex64)\n' require = {'hermitian'} self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:350: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = do = > def check(self, do): """ Run the function `do` on this test case, expanding arguments """ > do(self.a, self.b, tags=self.tags) do = > self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:85: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = a = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64), b = None, tags = frozenset({'hermitian'}) def do(self, a, b, tags): u, s, vt = linalg.svd(a, False, hermitian=True) > assert_allclose(a, dot_generalized(np.asarray(u) * np.asarray(s)[..., None, :], np.asarray(vt)), rtol=get_rtol(u.dtype)) a = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64) b = None s = array([4.6055512, 2.6055512], dtype=float32) self = tags = frozenset({'hermitian'}) u = array([[-0.70710677-0.20710678j, -0.70710677-0.70710677j], [-0.8082574 +0.31099832j, 0.9805807 -0.19611613j]], dtype=complex64) vt = array([[-0.70710677+0.20710678j, -0.8082574 -0.31099832j], [ 0.70710677-0.70710677j, -0.9805807 -0.19611613j]], dtype=complex64) ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:680: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ actual = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64) desired = array([[-0.1052289 +7.4536189e-08j, 3.7808409 +3.9517009e+00j], [ 3.780841 -3.9517007e+00j, 0.84861183-4.4942681e-08j]], dtype=complex64) rtol = 1e-05, atol = 0, equal_nan = True, err_msg = '', verbose = True def assert_allclose(actual, desired, rtol=1e-7, atol=0, equal_nan=True, err_msg='', verbose=True): """ Raises an AssertionError if two objects are not equal up to desired tolerance. Given two array_like objects, check that their shapes and all elements are equal (but see the Notes for the special handling of a scalar). An exception is raised if the shapes mismatch or any values conflict. In contrast to the standard usage in numpy, NaNs are compared like numbers, no assertion is raised if both objects have NaNs in the same positions. The test is equivalent to ``allclose(actual, desired, rtol, atol)`` (note that ``allclose`` has different default values). It compares the difference between `actual` and `desired` to ``atol + rtol * abs(desired)``. .. versionadded:: 1.5.0 Parameters ---------- actual : array_like Array obtained. desired : array_like Array desired. rtol : float, optional Relative tolerance. atol : float, optional Absolute tolerance. equal_nan : bool, optional. If True, NaNs will compare equal. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_array_almost_equal_nulp, assert_array_max_ulp Notes ----- When one of `actual` and `desired` is a scalar and the other is array_like, the function checks that each element of the array_like object is equal to the scalar. Examples -------- >>> x = [1e-5, 1e-3, 1e-1] >>> y = np.arccos(np.cos(x)) >>> np.testing.assert_allclose(x, y, rtol=1e-5, atol=0) """ __tracebackhide__ = True # Hide traceback for py.test import numpy as np def compare(x, y): return np.core.numeric.isclose(x, y, rtol=rtol, atol=atol, equal_nan=equal_nan) actual, desired = np.asanyarray(actual), np.asanyarray(desired) header = f'Not equal to tolerance rtol={rtol:g}, atol={atol:g}' > assert_array_compare(compare, actual, desired, err_msg=str(err_msg), verbose=verbose, header=header, equal_nan=equal_nan) __tracebackhide__ = True actual = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64) atol = 0 compare = .compare at 0x10979ab60> desired = array([[-0.1052289 +7.4536189e-08j, 3.7808409 +3.9517009e+00j], [ 3.780841 -3.9517007e+00j, 0.84861183-4.4942681e-08j]], dtype=complex64) equal_nan = True err_msg = '' header = 'Not equal to tolerance rtol=1e-05, atol=0' np = rtol = 1e-05 verbose = True ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py:1590: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (.compare at 0x10979ab60>, array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=... 3.7808409 +3.9517009e+00j], [ 3.780841 -3.9517007e+00j, 0.84861183-4.4942681e-08j]], dtype=complex64)) kwds = {'equal_nan': True, 'err_msg': '', 'header': 'Not equal to tolerance rtol=1e-05, atol=0', 'verbose': True} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) args = (.compare at 0x10979ab60>, array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=... 3.7808409 +3.9517009e+00j], [ 3.780841 -3.9517007e+00j, 0.84861183-4.4942681e-08j]], dtype=complex64)) func = kwds = {'equal_nan': True, 'err_msg': '', 'header': 'Not equal to tolerance rtol=1e-05, atol=0', 'verbose': True} self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ comparison = .compare at 0x10979ab60>, x = array([1.+0.j, 2.+3.j, 2.-3.j, 1.+0.j], dtype=complex64) y = array([-0.1052289 +7.4536189e-08j, 3.7808409 +3.9517009e+00j, 3.780841 -3.9517007e+00j, 0.84861183-4.4942681e-08j], dtype=complex64) err_msg = '\nMismatched elements: 4 / 4 (100%)\nMax absolute difference: 2.0191903\nMax relative difference: 10.503093', verbose = True header = 'Not equal to tolerance rtol=1e-05, atol=0', precision = 6, equal_nan = True, equal_inf = True @np._no_nep50_warning() def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='', precision=6, equal_nan=True, equal_inf=True, *, strict=False): __tracebackhide__ = True # Hide traceback for py.test from numpy.core import array, array2string, isnan, inf, bool_, errstate, all, max, object_ x = np.asanyarray(x) y = np.asanyarray(y) # original array for output formatting ox, oy = x, y def isnumber(x): return x.dtype.char in '?bhilqpBHILQPefdgFDG' def istime(x): return x.dtype.char in "Mm" def func_assert_same_pos(x, y, func=isnan, hasval='nan'): """Handling nan/inf. Combine results of running func on x and y, checking that they are True at the same locations. """ __tracebackhide__ = True # Hide traceback for py.test x_id = func(x) y_id = func(y) # We include work-arounds here to handle three types of slightly # pathological ndarray subclasses: # (1) all() on `masked` array scalars can return masked arrays, so we # use != True # (2) __eq__ on some ndarray subclasses returns Python booleans # instead of element-wise comparisons, so we cast to bool_() and # use isinstance(..., bool) checks # (3) subclasses with bare-bones __array_function__ implementations may # not implement np.all(), so favor using the .all() method # We are not committed to supporting such subclasses, but it's nice to # support them if possible. if bool_(x_id == y_id).all() != True: msg = build_err_msg([x, y], err_msg + '\nx and y %s location mismatch:' % (hasval), verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) # If there is a scalar, then here we know the array has the same # flag as it everywhere, so we should return the scalar flag. if isinstance(x_id, bool) or x_id.ndim == 0: return bool_(x_id) elif isinstance(y_id, bool) or y_id.ndim == 0: return bool_(y_id) else: return y_id try: if strict: cond = x.shape == y.shape and x.dtype == y.dtype else: cond = (x.shape == () or y.shape == ()) or x.shape == y.shape if not cond: if x.shape != y.shape: reason = f'\n(shapes {x.shape}, {y.shape} mismatch)' else: reason = f'\n(dtypes {x.dtype}, {y.dtype} mismatch)' msg = build_err_msg([x, y], err_msg + reason, verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) flagged = bool_(False) if isnumber(x) and isnumber(y): if equal_nan: flagged = func_assert_same_pos(x, y, func=isnan, hasval='nan') if equal_inf: flagged |= func_assert_same_pos(x, y, func=lambda xy: xy == +inf, hasval='+inf') flagged |= func_assert_same_pos(x, y, func=lambda xy: xy == -inf, hasval='-inf') elif istime(x) and istime(y): # If one is datetime64 and the other timedelta64 there is no point if equal_nan and x.dtype.type == y.dtype.type: flagged = func_assert_same_pos(x, y, func=isnat, hasval="NaT") if flagged.ndim > 0: x, y = x[~flagged], y[~flagged] # Only do the comparison if actual values are left if x.size == 0: return elif flagged: # no sense doing comparison if everything is flagged. return val = comparison(x, y) if isinstance(val, bool): cond = val reduced = array([val]) else: reduced = val.ravel() cond = reduced.all() # The below comparison is a hack to ensure that fully masked # results, for which val.ravel().all() returns np.ma.masked, # do not trigger a failure (np.ma.masked != True evaluates as # np.ma.masked, which is falsy). if cond != True: n_mismatch = reduced.size - reduced.sum(dtype=intp) n_elements = flagged.size if flagged.ndim != 0 else reduced.size percent_mismatch = 100 * n_mismatch / n_elements remarks = [ 'Mismatched elements: {} / {} ({:.3g}%)'.format( n_mismatch, n_elements, percent_mismatch)] with errstate(all='ignore'): # ignore errors for non-numeric types with contextlib.suppress(TypeError): error = abs(x - y) if np.issubdtype(x.dtype, np.unsignedinteger): error2 = abs(y - x) np.minimum(error, error2, out=error) max_abs_error = max(error) if getattr(error, 'dtype', object_) == object_: remarks.append('Max absolute difference: ' + str(max_abs_error)) else: remarks.append('Max absolute difference: ' + array2string(max_abs_error)) # note: this definition of relative error matches that one # used by assert_allclose (found in np.isclose) # Filter values where the divisor would be zero nonzero = bool_(y != 0) if all(~nonzero): max_rel_error = array(inf) else: max_rel_error = max(error[nonzero] / abs(y[nonzero])) if getattr(error, 'dtype', object_) == object_: remarks.append('Max relative difference: ' + str(max_rel_error)) else: remarks.append('Max relative difference: ' + array2string(max_rel_error)) err_msg += '\n' + '\n'.join(remarks) msg = build_err_msg([ox, oy], err_msg, verbose=verbose, header=header, names=('x', 'y'), precision=precision) > raise AssertionError(msg) E AssertionError: E Not equal to tolerance rtol=1e-05, atol=0 E E Mismatched elements: 4 / 4 (100%) E Max absolute difference: 2.0191903 E Max relative difference: 10.503093 E x: array([[1.+0.j, 2.+3.j], E [2.-3.j, 1.+0.j]], dtype=complex64) E y: array([[-0.105229+7.453619e-08j, 3.780841+3.951701e+00j], E [ 3.780841-3.951701e+00j, 0.848612-4.494268e-08j]], E dtype=complex64) __tracebackhide__ = True all = array = array2string = bool_ = comparison = .compare at 0x10979ab60> cond = False equal_inf = True equal_nan = True err_msg = '\nMismatched elements: 4 / 4 (100%)\nMax absolute difference: 2.0191903\nMax relative difference: 10.503093' error = array([1.1052289 , 2.01919 , 2.0191903 , 0.15138817], dtype=float32) errstate = flagged = array([[False, False], [False, False]]) func_assert_same_pos = .func_assert_same_pos at 0x10979ad40> header = 'Not equal to tolerance rtol=1e-05, atol=0' inf = inf isnan = isnumber = .isnumber at 0x10979ac00> istime = .istime at 0x10979aca0> max = max_abs_error = 2.0191903 max_rel_error = 10.503093 msg = '\nNot equal to tolerance rtol=1e-05, atol=0\n\nMismatched elements: 4 / 4 (100%)\nMax absolute difference: 2.0191903\...9e-08j, 3.780841+3.951701e+00j],\n [ 3.780841-3.951701e+00j, 0.848612-4.494268e-08j]],\n dtype=complex64)' n_elements = 4 n_mismatch = 4 nonzero = array([ True, True, True, True]) object_ = ox = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64) oy = array([[-0.1052289 +7.4536189e-08j, 3.7808409 +3.9517009e+00j], [ 3.780841 -3.9517007e+00j, 0.84861183-4.4942681e-08j]], dtype=complex64) percent_mismatch = 100.0 precision = 6 reduced = array([False, False, False, False]) remarks = ['Mismatched elements: 4 / 4 (100%)', 'Max absolute difference: 2.0191903', 'Max relative difference: 10.503093'] strict = False val = array([False, False, False, False]) verbose = True x = array([1.+0.j, 2.+3.j, 2.-3.j, 1.+0.j], dtype=complex64) y = array([-0.1052289 +7.4536189e-08j, 3.7808409 +3.9517009e+00j, 3.780841 -3.9517007e+00j, 0.84861183-4.4942681e-08j], dtype=complex64) ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py:862: AssertionError The above exception was the direct cause of the following exception: self = def test_herm_cases(self): > self.check_cases(require={'hermitian'}, exclude={'generalized', 'size-0'}) self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:382: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , require = {'hermitian'}, exclude = {'generalized', 'size-0'} def check_cases(self, require=set(), exclude=set()): """ Run func on each of the cases with all of the tags in require, and none of the tags in exclude """ for case in self.TEST_CASES: # filter by require and exclude if case.tags & require != require: continue if case.tags & exclude: continue try: case.check(self.do) except Exception as e: msg = f'In test case: {case!r}\n\n' msg += traceback.format_exc() > raise AssertionError(msg) from e E AssertionError: In test case: E E Traceback (most recent call last): E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py", line 350, in check_cases E case.check(self.do) E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py", line 85, in check E do(self.a, self.b, tags=self.tags) E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py", line 680, in do E assert_allclose(a, dot_generalized(np.asarray(u) * np.asarray(s)[..., None, :], E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py", line 1590, in assert_allclose E assert_array_compare(compare, actual, desired, err_msg=str(err_msg), E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/contextlib.py", line 81, in inner E return func(*args, **kwds) E ^^^^^^^^^^^^^^^^^^^ E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py", line 862, in assert_array_compare E raise AssertionError(msg) E AssertionError: E Not equal to tolerance rtol=1e-05, atol=0 E E Mismatched elements: 4 / 4 (100%) E Max absolute difference: 2.0191903 E Max relative difference: 10.503093 E x: array([[1.+0.j, 2.+3.j], E [2.-3.j, 1.+0.j]], dtype=complex64) E y: array([[-0.105229+7.453619e-08j, 3.780841+3.951701e+00j], E [ 3.780841-3.951701e+00j, 0.848612-4.494268e-08j]], E dtype=complex64) case = exclude = {'generalized', 'size-0'} msg = 'In test case: \n\nTraceback (most recent call last):\n File "/Users/rgommers/mambaforge/envs/n...-08j, 3.780841+3.951701e+00j],\n [ 3.780841-3.951701e+00j, 0.848612-4.494268e-08j]],\n dtype=complex64)\n' require = {'hermitian'} self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:354: AssertionError ______________________________________________________ TestPinvHermitian.test_herm_cases _______________________________________________________ actual = array([[0.57434577+2.9802322e-08j, 3.4734485 +4.2373457e+00j], [3.4734483 -4.2373452e+00j, 0.03471804-1.4901161e-08j]], dtype=complex64) desired = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64), decimal = 5, err_msg = '', verbose = True @np._no_nep50_warning() def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): """ Raises an AssertionError if two items are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies that the elements of `actual` and `desired` satisfy. ``abs(desired-actual) < float64(1.5 * 10**(-decimal))`` That is a looser test than originally documented, but agrees with what the actual implementation in `assert_array_almost_equal` did up to rounding vagaries. An exception is raised at conflicting values. For ndarrays this delegates to assert_array_almost_equal Parameters ---------- actual : array_like The object to check. desired : array_like The expected object. decimal : int, optional Desired precision, default is 7. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- >>> from numpy.testing import assert_almost_equal >>> assert_almost_equal(2.3333333333333, 2.33333334) >>> assert_almost_equal(2.3333333333333, 2.33333334, decimal=10) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 10 decimals ACTUAL: 2.3333333333333 DESIRED: 2.33333334 >>> assert_almost_equal(np.array([1.0,2.3333333333333]), ... np.array([1.0,2.33333334]), decimal=9) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 9 decimals Mismatched elements: 1 / 2 (50%) Max absolute difference: 6.66669964e-09 Max relative difference: 2.85715698e-09 x: array([1. , 2.333333333]) y: array([1. , 2.33333334]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import ndarray from numpy.lib import iscomplexobj, real, imag # Handle complex numbers: separate into real/imag to handle # nan/inf/negative zero correctly # XXX: catch ValueError for subclasses of ndarray where iscomplex fail try: usecomplex = iscomplexobj(actual) or iscomplexobj(desired) except ValueError: usecomplex = False def _build_err_msg(): header = ('Arrays are not almost equal to %d decimals' % decimal) return build_err_msg([actual, desired], err_msg, verbose=verbose, header=header) if usecomplex: if iscomplexobj(actual): actualr = real(actual) actuali = imag(actual) else: actualr = actual actuali = 0 if iscomplexobj(desired): desiredr = real(desired) desiredi = imag(desired) else: desiredr = desired desiredi = 0 try: > assert_almost_equal(actualr, desiredr, decimal=decimal) __tracebackhide__ = True _build_err_msg = ._build_err_msg at 0x10b074360> actual = array([[0.57434577+2.9802322e-08j, 3.4734485 +4.2373457e+00j], [3.4734483 -4.2373452e+00j, 0.03471804-1.4901161e-08j]], dtype=complex64) actuali = array([[ 2.9802322e-08, 4.2373457e+00], [-4.2373452e+00, -1.4901161e-08]], dtype=float32) actualr = array([[0.57434577, 3.4734485 ], [3.4734483 , 0.03471804]], dtype=float32) decimal = 5 desired = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64) desiredi = array([[ 0., 3.], [-3., 0.]], dtype=float32) desiredr = array([[1., 2.], [2., 1.]], dtype=float32) err_msg = '' imag = iscomplexobj = ndarray = real = usecomplex = True verbose = True ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py:581: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (array([[0.57434577, 3.4734485 ], [3.4734483 , 0.03471804]], dtype=float32), array([[1., 2.], [2., 1.]], dtype=float32)) kwds = {'decimal': 5} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) args = (array([[0.57434577, 3.4734485 ], [3.4734483 , 0.03471804]], dtype=float32), array([[1., 2.], [2., 1.]], dtype=float32)) func = kwds = {'decimal': 5} self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ actual = array([[0.57434577, 3.4734485 ], [3.4734483 , 0.03471804]], dtype=float32) desired = array([[1., 2.], [2., 1.]], dtype=float32), decimal = 5, err_msg = '', verbose = True @np._no_nep50_warning() def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): """ Raises an AssertionError if two items are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies that the elements of `actual` and `desired` satisfy. ``abs(desired-actual) < float64(1.5 * 10**(-decimal))`` That is a looser test than originally documented, but agrees with what the actual implementation in `assert_array_almost_equal` did up to rounding vagaries. An exception is raised at conflicting values. For ndarrays this delegates to assert_array_almost_equal Parameters ---------- actual : array_like The object to check. desired : array_like The expected object. decimal : int, optional Desired precision, default is 7. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- >>> from numpy.testing import assert_almost_equal >>> assert_almost_equal(2.3333333333333, 2.33333334) >>> assert_almost_equal(2.3333333333333, 2.33333334, decimal=10) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 10 decimals ACTUAL: 2.3333333333333 DESIRED: 2.33333334 >>> assert_almost_equal(np.array([1.0,2.3333333333333]), ... np.array([1.0,2.33333334]), decimal=9) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 9 decimals Mismatched elements: 1 / 2 (50%) Max absolute difference: 6.66669964e-09 Max relative difference: 2.85715698e-09 x: array([1. , 2.333333333]) y: array([1. , 2.33333334]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import ndarray from numpy.lib import iscomplexobj, real, imag # Handle complex numbers: separate into real/imag to handle # nan/inf/negative zero correctly # XXX: catch ValueError for subclasses of ndarray where iscomplex fail try: usecomplex = iscomplexobj(actual) or iscomplexobj(desired) except ValueError: usecomplex = False def _build_err_msg(): header = ('Arrays are not almost equal to %d decimals' % decimal) return build_err_msg([actual, desired], err_msg, verbose=verbose, header=header) if usecomplex: if iscomplexobj(actual): actualr = real(actual) actuali = imag(actual) else: actualr = actual actuali = 0 if iscomplexobj(desired): desiredr = real(desired) desiredi = imag(desired) else: desiredr = desired desiredi = 0 try: assert_almost_equal(actualr, desiredr, decimal=decimal) assert_almost_equal(actuali, desiredi, decimal=decimal) except AssertionError: raise AssertionError(_build_err_msg()) if isinstance(actual, (ndarray, tuple, list)) \ or isinstance(desired, (ndarray, tuple, list)): > return assert_array_almost_equal(actual, desired, decimal, err_msg) __tracebackhide__ = True _build_err_msg = ._build_err_msg at 0x10b074540> actual = array([[0.57434577, 3.4734485 ], [3.4734483 , 0.03471804]], dtype=float32) decimal = 5 desired = array([[1., 2.], [2., 1.]], dtype=float32) err_msg = '' imag = iscomplexobj = ndarray = real = usecomplex = False verbose = True ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py:588: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (array([[0.57434577, 3.4734485 ], [3.4734483 , 0.03471804]], dtype=float32), array([[1., 2.], [2., 1.]], dtype=float32), 5, '') kwds = {} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) args = (array([[0.57434577, 3.4734485 ], [3.4734483 , 0.03471804]], dtype=float32), array([[1., 2.], [2., 1.]], dtype=float32), 5, '') func = kwds = {} self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ x = array([[0.57434577, 3.4734485 ], [3.4734483 , 0.03471804]], dtype=float32), y = array([[1., 2.], [2., 1.]], dtype=float32) decimal = 5, err_msg = '', verbose = True @np._no_nep50_warning() def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True): """ Raises an AssertionError if two objects are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies identical shapes and that the elements of ``actual`` and ``desired`` satisfy. ``abs(desired-actual) < 1.5 * 10**(-decimal)`` That is a looser test than originally documented, but agrees with what the actual implementation did up to rounding vagaries. An exception is raised at shape mismatch or conflicting values. In contrast to the standard usage in numpy, NaNs are compared like numbers, no assertion is raised if both objects have NaNs in the same positions. Parameters ---------- x : array_like The actual object to check. y : array_like The desired, expected object. decimal : int, optional Desired precision, default is 6. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- the first assert does not raise an exception >>> np.testing.assert_array_almost_equal([1.0,2.333,np.nan], ... [1.0,2.333,np.nan]) >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], ... [1.0,2.33339,np.nan], decimal=5) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 5 decimals Mismatched elements: 1 / 3 (33.3%) Max absolute difference: 6.e-05 Max relative difference: 2.57136612e-05 x: array([1. , 2.33333, nan]) y: array([1. , 2.33339, nan]) >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], ... [1.0,2.33333, 5], decimal=5) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 5 decimals x and y nan location mismatch: x: array([1. , 2.33333, nan]) y: array([1. , 2.33333, 5. ]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import number, float_, result_type, array from numpy.core.numerictypes import issubdtype from numpy.core.fromnumeric import any as npany def compare(x, y): try: if npany(gisinf(x)) or npany( gisinf(y)): xinfid = gisinf(x) yinfid = gisinf(y) if not (xinfid == yinfid).all(): return False # if one item, x and y is +- inf if x.size == y.size == 1: return x == y x = x[~xinfid] y = y[~yinfid] except (TypeError, NotImplementedError): pass # make sure y is an inexact type to avoid abs(MIN_INT); will cause # casting of x later. dtype = result_type(y, 1.) y = np.asanyarray(y, dtype) z = abs(x - y) if not issubdtype(z.dtype, number): z = z.astype(float_) # handle object arrays return z < 1.5 * 10.0**(-decimal) > assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose, header=('Arrays are not almost equal to %d decimals' % decimal), precision=decimal) __tracebackhide__ = True array = compare = .compare at 0x10b0745e0> decimal = 5 err_msg = '' float_ = issubdtype = npany = number = result_type = verbose = True x = array([[0.57434577, 3.4734485 ], [3.4734483 , 0.03471804]], dtype=float32) y = array([[1., 2.], [2., 1.]], dtype=float32) ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py:1097: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (.compare at 0x10b0745e0>, array([[0.57434577, 3.4734485 ], [3.4734483 , 0.03471804]], dtype=float32), array([[1., 2.], [2., 1.]], dtype=float32)) kwds = {'err_msg': '', 'header': 'Arrays are not almost equal to 5 decimals', 'precision': 5, 'verbose': True} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) args = (.compare at 0x10b0745e0>, array([[0.57434577, 3.4734485 ], [3.4734483 , 0.03471804]], dtype=float32), array([[1., 2.], [2., 1.]], dtype=float32)) func = kwds = {'err_msg': '', 'header': 'Arrays are not almost equal to 5 decimals', 'precision': 5, 'verbose': True} self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ comparison = .compare at 0x10b0745e0> x = array([0.57434577, 3.4734485 , 3.4734483 , 0.03471804], dtype=float32), y = array([1., 2., 2., 1.], dtype=float32) err_msg = '\nMismatched elements: 4 / 4 (100%)\nMax absolute difference: 1.4734485\nMax relative difference: 0.96528196', verbose = True header = 'Arrays are not almost equal to 5 decimals', precision = 5, equal_nan = True, equal_inf = True @np._no_nep50_warning() def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='', precision=6, equal_nan=True, equal_inf=True, *, strict=False): __tracebackhide__ = True # Hide traceback for py.test from numpy.core import array, array2string, isnan, inf, bool_, errstate, all, max, object_ x = np.asanyarray(x) y = np.asanyarray(y) # original array for output formatting ox, oy = x, y def isnumber(x): return x.dtype.char in '?bhilqpBHILQPefdgFDG' def istime(x): return x.dtype.char in "Mm" def func_assert_same_pos(x, y, func=isnan, hasval='nan'): """Handling nan/inf. Combine results of running func on x and y, checking that they are True at the same locations. """ __tracebackhide__ = True # Hide traceback for py.test x_id = func(x) y_id = func(y) # We include work-arounds here to handle three types of slightly # pathological ndarray subclasses: # (1) all() on `masked` array scalars can return masked arrays, so we # use != True # (2) __eq__ on some ndarray subclasses returns Python booleans # instead of element-wise comparisons, so we cast to bool_() and # use isinstance(..., bool) checks # (3) subclasses with bare-bones __array_function__ implementations may # not implement np.all(), so favor using the .all() method # We are not committed to supporting such subclasses, but it's nice to # support them if possible. if bool_(x_id == y_id).all() != True: msg = build_err_msg([x, y], err_msg + '\nx and y %s location mismatch:' % (hasval), verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) # If there is a scalar, then here we know the array has the same # flag as it everywhere, so we should return the scalar flag. if isinstance(x_id, bool) or x_id.ndim == 0: return bool_(x_id) elif isinstance(y_id, bool) or y_id.ndim == 0: return bool_(y_id) else: return y_id try: if strict: cond = x.shape == y.shape and x.dtype == y.dtype else: cond = (x.shape == () or y.shape == ()) or x.shape == y.shape if not cond: if x.shape != y.shape: reason = f'\n(shapes {x.shape}, {y.shape} mismatch)' else: reason = f'\n(dtypes {x.dtype}, {y.dtype} mismatch)' msg = build_err_msg([x, y], err_msg + reason, verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) flagged = bool_(False) if isnumber(x) and isnumber(y): if equal_nan: flagged = func_assert_same_pos(x, y, func=isnan, hasval='nan') if equal_inf: flagged |= func_assert_same_pos(x, y, func=lambda xy: xy == +inf, hasval='+inf') flagged |= func_assert_same_pos(x, y, func=lambda xy: xy == -inf, hasval='-inf') elif istime(x) and istime(y): # If one is datetime64 and the other timedelta64 there is no point if equal_nan and x.dtype.type == y.dtype.type: flagged = func_assert_same_pos(x, y, func=isnat, hasval="NaT") if flagged.ndim > 0: x, y = x[~flagged], y[~flagged] # Only do the comparison if actual values are left if x.size == 0: return elif flagged: # no sense doing comparison if everything is flagged. return val = comparison(x, y) if isinstance(val, bool): cond = val reduced = array([val]) else: reduced = val.ravel() cond = reduced.all() # The below comparison is a hack to ensure that fully masked # results, for which val.ravel().all() returns np.ma.masked, # do not trigger a failure (np.ma.masked != True evaluates as # np.ma.masked, which is falsy). if cond != True: n_mismatch = reduced.size - reduced.sum(dtype=intp) n_elements = flagged.size if flagged.ndim != 0 else reduced.size percent_mismatch = 100 * n_mismatch / n_elements remarks = [ 'Mismatched elements: {} / {} ({:.3g}%)'.format( n_mismatch, n_elements, percent_mismatch)] with errstate(all='ignore'): # ignore errors for non-numeric types with contextlib.suppress(TypeError): error = abs(x - y) if np.issubdtype(x.dtype, np.unsignedinteger): error2 = abs(y - x) np.minimum(error, error2, out=error) max_abs_error = max(error) if getattr(error, 'dtype', object_) == object_: remarks.append('Max absolute difference: ' + str(max_abs_error)) else: remarks.append('Max absolute difference: ' + array2string(max_abs_error)) # note: this definition of relative error matches that one # used by assert_allclose (found in np.isclose) # Filter values where the divisor would be zero nonzero = bool_(y != 0) if all(~nonzero): max_rel_error = array(inf) else: max_rel_error = max(error[nonzero] / abs(y[nonzero])) if getattr(error, 'dtype', object_) == object_: remarks.append('Max relative difference: ' + str(max_rel_error)) else: remarks.append('Max relative difference: ' + array2string(max_rel_error)) err_msg += '\n' + '\n'.join(remarks) msg = build_err_msg([ox, oy], err_msg, verbose=verbose, header=header, names=('x', 'y'), precision=precision) > raise AssertionError(msg) E AssertionError: E Arrays are not almost equal to 5 decimals E E Mismatched elements: 4 / 4 (100%) E Max absolute difference: 1.4734485 E Max relative difference: 0.96528196 E x: array([[0.57435, 3.47345], E [3.47345, 0.03472]], dtype=float32) E y: array([[1., 2.], E [2., 1.]], dtype=float32) __tracebackhide__ = True all = array = array2string = bool_ = comparison = .compare at 0x10b0745e0> cond = False equal_inf = True equal_nan = True err_msg = '\nMismatched elements: 4 / 4 (100%)\nMax absolute difference: 1.4734485\nMax relative difference: 0.96528196' error = array([0.42565423, 1.4734485 , 1.4734483 , 0.96528196], dtype=float32) errstate = flagged = array([[False, False], [False, False]]) func_assert_same_pos = .func_assert_same_pos at 0x10b0747c0> header = 'Arrays are not almost equal to 5 decimals' inf = inf isnan = isnumber = .isnumber at 0x10b074680> istime = .istime at 0x10b074720> max = max_abs_error = 1.4734485 max_rel_error = 0.96528196 msg = '\nArrays are not almost equal to 5 decimals\n\nMismatched elements: 4 / 4 (100%)\nMax absolute difference: 1.4734485\...0.57435, 3.47345],\n [3.47345, 0.03472]], dtype=float32)\n y: array([[1., 2.],\n [2., 1.]], dtype=float32)' n_elements = 4 n_mismatch = 4 nonzero = array([ True, True, True, True]) object_ = ox = array([[0.57434577, 3.4734485 ], [3.4734483 , 0.03471804]], dtype=float32) oy = array([[1., 2.], [2., 1.]], dtype=float32) percent_mismatch = 100.0 precision = 5 reduced = array([False, False, False, False]) remarks = ['Mismatched elements: 4 / 4 (100%)', 'Max absolute difference: 1.4734485', 'Max relative difference: 0.96528196'] strict = False val = array([False, False, False, False]) verbose = True x = array([0.57434577, 3.4734485 , 3.4734483 , 0.03471804], dtype=float32) y = array([1., 2., 2., 1.], dtype=float32) ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py:862: AssertionError During handling of the above exception, another exception occurred: self = , require = {'hermitian'}, exclude = {'generalized', 'size-0'} def check_cases(self, require=set(), exclude=set()): """ Run func on each of the cases with all of the tags in require, and none of the tags in exclude """ for case in self.TEST_CASES: # filter by require and exclude if case.tags & require != require: continue if case.tags & exclude: continue try: > case.check(self.do) case = exclude = {'generalized', 'size-0'} msg = 'In test case: \n\nTraceback (most recent call last):\n File "/Users/rgommers/mambaforge/envs/n...1161e-08j]],\n dtype=complex64)\n DESIRED: array([[1.+0.j, 2.+3.j],\n [2.-3.j, 1.+0.j]], dtype=complex64)\n' require = {'hermitian'} self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:350: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = do = > def check(self, do): """ Run the function `do` on this test case, expanding arguments """ > do(self.a, self.b, tags=self.tags) do = > self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:85: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = a = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64), b = None, tags = frozenset({'hermitian'}) def do(self, a, b, tags): a_ginv = linalg.pinv(a, hermitian=True) # `a @ a_ginv == I` does not hold if a is singular dot = dot_generalized > assert_almost_equal(dot(dot(a, a_ginv), a), a, single_decimal=5, double_decimal=11) a = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64) a_ginv = array([[-0.26591796-4.3245496e-09j, 0.24816822+4.5332125e-01j], [ 0.24816824-4.5332128e-01j, -0.22094898+1.2190652e-09j]], dtype=complex64) b = None dot = self = tags = frozenset({'hermitian'}) ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:835: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ a = array([[0.57434577+2.9802322e-08j, 3.4734485 +4.2373457e+00j], [3.4734483 -4.2373452e+00j, 0.03471804-1.4901161e-08j]], dtype=complex64) b = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64), single_decimal = 5, double_decimal = 11, kw = {}, decimal = 5 def assert_almost_equal(a, b, single_decimal=6, double_decimal=12, **kw): if asarray(a).dtype.type in (single, csingle): decimal = single_decimal else: decimal = double_decimal > old_assert_almost_equal(a, b, decimal=decimal, **kw) a = array([[0.57434577+2.9802322e-08j, 3.4734485 +4.2373457e+00j], [3.4734483 -4.2373452e+00j, 0.03471804-1.4901161e-08j]], dtype=complex64) b = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64) decimal = 5 double_decimal = 11 kw = {} single_decimal = 5 ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:41: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (array([[0.57434577+2.9802322e-08j, 3.4734485 +4.2373457e+00j], [3.4734483 -4.2373452e+00j, 0.03471804-1.4901161e-08j]], dtype=complex64), array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64)) kwds = {'decimal': 5} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) args = (array([[0.57434577+2.9802322e-08j, 3.4734485 +4.2373457e+00j], [3.4734483 -4.2373452e+00j, 0.03471804-1.4901161e-08j]], dtype=complex64), array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64)) func = kwds = {'decimal': 5} self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ actual = array([[0.57434577+2.9802322e-08j, 3.4734485 +4.2373457e+00j], [3.4734483 -4.2373452e+00j, 0.03471804-1.4901161e-08j]], dtype=complex64) desired = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64), decimal = 5, err_msg = '', verbose = True @np._no_nep50_warning() def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): """ Raises an AssertionError if two items are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point comparisons. The test verifies that the elements of `actual` and `desired` satisfy. ``abs(desired-actual) < float64(1.5 * 10**(-decimal))`` That is a looser test than originally documented, but agrees with what the actual implementation in `assert_array_almost_equal` did up to rounding vagaries. An exception is raised at conflicting values. For ndarrays this delegates to assert_array_almost_equal Parameters ---------- actual : array_like The object to check. desired : array_like The expected object. decimal : int, optional Desired precision, default is 7. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_allclose: Compare two array_like objects for equality with desired relative and/or absolute precision. assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal Examples -------- >>> from numpy.testing import assert_almost_equal >>> assert_almost_equal(2.3333333333333, 2.33333334) >>> assert_almost_equal(2.3333333333333, 2.33333334, decimal=10) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 10 decimals ACTUAL: 2.3333333333333 DESIRED: 2.33333334 >>> assert_almost_equal(np.array([1.0,2.3333333333333]), ... np.array([1.0,2.33333334]), decimal=9) Traceback (most recent call last): ... AssertionError: Arrays are not almost equal to 9 decimals Mismatched elements: 1 / 2 (50%) Max absolute difference: 6.66669964e-09 Max relative difference: 2.85715698e-09 x: array([1. , 2.333333333]) y: array([1. , 2.33333334]) """ __tracebackhide__ = True # Hide traceback for py.test from numpy.core import ndarray from numpy.lib import iscomplexobj, real, imag # Handle complex numbers: separate into real/imag to handle # nan/inf/negative zero correctly # XXX: catch ValueError for subclasses of ndarray where iscomplex fail try: usecomplex = iscomplexobj(actual) or iscomplexobj(desired) except ValueError: usecomplex = False def _build_err_msg(): header = ('Arrays are not almost equal to %d decimals' % decimal) return build_err_msg([actual, desired], err_msg, verbose=verbose, header=header) if usecomplex: if iscomplexobj(actual): actualr = real(actual) actuali = imag(actual) else: actualr = actual actuali = 0 if iscomplexobj(desired): desiredr = real(desired) desiredi = imag(desired) else: desiredr = desired desiredi = 0 try: assert_almost_equal(actualr, desiredr, decimal=decimal) assert_almost_equal(actuali, desiredi, decimal=decimal) except AssertionError: > raise AssertionError(_build_err_msg()) E AssertionError: E Arrays are not almost equal to 5 decimals E ACTUAL: array([[0.57434577+2.9802322e-08j, 3.4734485 +4.2373457e+00j], E [3.4734483 -4.2373452e+00j, 0.03471804-1.4901161e-08j]], E dtype=complex64) E DESIRED: array([[1.+0.j, 2.+3.j], E [2.-3.j, 1.+0.j]], dtype=complex64) __tracebackhide__ = True _build_err_msg = ._build_err_msg at 0x10b074360> actual = array([[0.57434577+2.9802322e-08j, 3.4734485 +4.2373457e+00j], [3.4734483 -4.2373452e+00j, 0.03471804-1.4901161e-08j]], dtype=complex64) actuali = array([[ 2.9802322e-08, 4.2373457e+00], [-4.2373452e+00, -1.4901161e-08]], dtype=float32) actualr = array([[0.57434577, 3.4734485 ], [3.4734483 , 0.03471804]], dtype=float32) decimal = 5 desired = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64) desiredi = array([[ 0., 3.], [-3., 0.]], dtype=float32) desiredr = array([[1., 2.], [2., 1.]], dtype=float32) err_msg = '' imag = iscomplexobj = ndarray = real = usecomplex = True verbose = True ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py:584: AssertionError The above exception was the direct cause of the following exception: self = def test_herm_cases(self): > self.check_cases(require={'hermitian'}, exclude={'generalized', 'size-0'}) self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:382: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , require = {'hermitian'}, exclude = {'generalized', 'size-0'} def check_cases(self, require=set(), exclude=set()): """ Run func on each of the cases with all of the tags in require, and none of the tags in exclude """ for case in self.TEST_CASES: # filter by require and exclude if case.tags & require != require: continue if case.tags & exclude: continue try: case.check(self.do) except Exception as e: msg = f'In test case: {case!r}\n\n' msg += traceback.format_exc() > raise AssertionError(msg) from e E AssertionError: In test case: E E Traceback (most recent call last): E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py", line 581, in assert_almost_equal E assert_almost_equal(actualr, desiredr, decimal=decimal) E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/contextlib.py", line 81, in inner E return func(*args, **kwds) E ^^^^^^^^^^^^^^^^^^^ E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py", line 588, in assert_almost_equal E return assert_array_almost_equal(actual, desired, decimal, err_msg) E ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/contextlib.py", line 81, in inner E return func(*args, **kwds) E ^^^^^^^^^^^^^^^^^^^ E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py", line 1097, in assert_array_almost_equal E assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose, E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/contextlib.py", line 81, in inner E return func(*args, **kwds) E ^^^^^^^^^^^^^^^^^^^ E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py", line 862, in assert_array_compare E raise AssertionError(msg) E AssertionError: E Arrays are not almost equal to 5 decimals E E Mismatched elements: 4 / 4 (100%) E Max absolute difference: 1.4734485 E Max relative difference: 0.96528196 E x: array([[0.57435, 3.47345], E [3.47345, 0.03472]], dtype=float32) E y: array([[1., 2.], E [2., 1.]], dtype=float32) E E During handling of the above exception, another exception occurred: E E Traceback (most recent call last): E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py", line 350, in check_cases E case.check(self.do) E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py", line 85, in check E do(self.a, self.b, tags=self.tags) E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py", line 835, in do E assert_almost_equal(dot(dot(a, a_ginv), a), a, single_decimal=5, double_decimal=11) E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py", line 41, in assert_almost_equal E old_assert_almost_equal(a, b, decimal=decimal, **kw) E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/contextlib.py", line 81, in inner E return func(*args, **kwds) E ^^^^^^^^^^^^^^^^^^^ E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py", line 584, in assert_almost_equal E raise AssertionError(_build_err_msg()) E AssertionError: E Arrays are not almost equal to 5 decimals E ACTUAL: array([[0.57434577+2.9802322e-08j, 3.4734485 +4.2373457e+00j], E [3.4734483 -4.2373452e+00j, 0.03471804-1.4901161e-08j]], E dtype=complex64) E DESIRED: array([[1.+0.j, 2.+3.j], E [2.-3.j, 1.+0.j]], dtype=complex64) case = exclude = {'generalized', 'size-0'} msg = 'In test case: \n\nTraceback (most recent call last):\n File "/Users/rgommers/mambaforge/envs/n...1161e-08j]],\n dtype=complex64)\n DESIRED: array([[1.+0.j, 2.+3.j],\n [2.-3.j, 1.+0.j]], dtype=complex64)\n' require = {'hermitian'} self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:354: AssertionError ________________________________________________________ TestEighCases.test_herm_cases _________________________________________________________ self = , require = {'hermitian'}, exclude = {'generalized', 'size-0'} def check_cases(self, require=set(), exclude=set()): """ Run func on each of the cases with all of the tags in require, and none of the tags in exclude """ for case in self.TEST_CASES: # filter by require and exclude if case.tags & require != require: continue if case.tags & exclude: continue try: > case.check(self.do) case = exclude = {'generalized', 'size-0'} msg = 'In test case: \n\nTraceback (most recent call last):\n File "/Users/rgommers/mambaforge/envs/n...y([[ 1.842403+1.842403j, -3.256616-0.953841j],\n [-2.554953+0.510991j, -3.722471+1.432319j]], dtype=complex64)\n' require = {'hermitian'} self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:350: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , do = > def check(self, do): """ Run the function `do` on this test case, expanding arguments """ > do(self.a, self.b, tags=self.tags) do = > self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:85: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = a = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64), b = None, tags = frozenset({'hermitian'}) def do(self, a, b, tags): # 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) evalues.sort(axis=-1) assert_almost_equal(ev, evalues) > assert_allclose(dot_generalized(a, evc), np.asarray(ev)[..., None, :] * np.asarray(evc), rtol=get_rtol(ev.dtype)) a = array([[1.+0.j, 2.+3.j], [2.-3.j, 1.+0.j]], dtype=complex64) b = None ev = array([-2.6055512, 4.6055512], dtype=float32) evalues = array([-2.6055512-1.110223e-16j, 4.6055512+1.110223e-16j], dtype=complex64) evc = array([[-0.70710677-0.70710677j, -0.70710677-0.20710678j], [ 0.9805807 -0.19611613j, -0.8082574 +0.31099832j]], dtype=complex64) evectors = array([[ 0.70710677+0.j , 0.70710677+0.j ], [ 0.39223227-0.5883484j, -0.39223227+0.5883484j]], dtype=complex64) self = tags = frozenset({'hermitian'}) ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:1152: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ actual = array([[ 1.8424029+1.842403j , -3.2566166-2.0098825j], [-2.554953 +0.5109906j, -2.8437912+2.018105j ]], dtype=complex64) desired = array([[ 1.8424029+1.8424029j, -3.2566164-0.9538409j], [-2.5549533+0.5109906j, -3.7224708+1.4323187j]], dtype=complex64) rtol = 1e-05, atol = 0, equal_nan = True, err_msg = '', verbose = True def assert_allclose(actual, desired, rtol=1e-7, atol=0, equal_nan=True, err_msg='', verbose=True): """ Raises an AssertionError if two objects are not equal up to desired tolerance. Given two array_like objects, check that their shapes and all elements are equal (but see the Notes for the special handling of a scalar). An exception is raised if the shapes mismatch or any values conflict. In contrast to the standard usage in numpy, NaNs are compared like numbers, no assertion is raised if both objects have NaNs in the same positions. The test is equivalent to ``allclose(actual, desired, rtol, atol)`` (note that ``allclose`` has different default values). It compares the difference between `actual` and `desired` to ``atol + rtol * abs(desired)``. .. versionadded:: 1.5.0 Parameters ---------- actual : array_like Array obtained. desired : array_like Array desired. rtol : float, optional Relative tolerance. atol : float, optional Absolute tolerance. equal_nan : bool, optional. If True, NaNs will compare equal. err_msg : str, optional The error message to be printed in case of failure. verbose : bool, optional If True, the conflicting values are appended to the error message. Raises ------ AssertionError If actual and desired are not equal up to specified precision. See Also -------- assert_array_almost_equal_nulp, assert_array_max_ulp Notes ----- When one of `actual` and `desired` is a scalar and the other is array_like, the function checks that each element of the array_like object is equal to the scalar. Examples -------- >>> x = [1e-5, 1e-3, 1e-1] >>> y = np.arccos(np.cos(x)) >>> np.testing.assert_allclose(x, y, rtol=1e-5, atol=0) """ __tracebackhide__ = True # Hide traceback for py.test import numpy as np def compare(x, y): return np.core.numeric.isclose(x, y, rtol=rtol, atol=atol, equal_nan=equal_nan) actual, desired = np.asanyarray(actual), np.asanyarray(desired) header = f'Not equal to tolerance rtol={rtol:g}, atol={atol:g}' > assert_array_compare(compare, actual, desired, err_msg=str(err_msg), verbose=verbose, header=header, equal_nan=equal_nan) __tracebackhide__ = True actual = array([[ 1.8424029+1.842403j , -3.2566166-2.0098825j], [-2.554953 +0.5109906j, -2.8437912+2.018105j ]], dtype=complex64) atol = 0 compare = .compare at 0x10b0d6520> desired = array([[ 1.8424029+1.8424029j, -3.2566164-0.9538409j], [-2.5549533+0.5109906j, -3.7224708+1.4323187j]], dtype=complex64) equal_nan = True err_msg = '' header = 'Not equal to tolerance rtol=1e-05, atol=0' np = rtol = 1e-05 verbose = True ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py:1590: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ args = (.compare at 0x10b0d6520>, array([[ 1.8424029+1.842403j , -3.2566166-2.0098825j], ...1.8424029+1.8424029j, -3.2566164-0.9538409j], [-2.5549533+0.5109906j, -3.7224708+1.4323187j]], dtype=complex64)) kwds = {'equal_nan': True, 'err_msg': '', 'header': 'Not equal to tolerance rtol=1e-05, atol=0', 'verbose': True} @wraps(func) def inner(*args, **kwds): with self._recreate_cm(): > return func(*args, **kwds) args = (.compare at 0x10b0d6520>, array([[ 1.8424029+1.842403j , -3.2566166-2.0098825j], ...1.8424029+1.8424029j, -3.2566164-0.9538409j], [-2.5549533+0.5109906j, -3.7224708+1.4323187j]], dtype=complex64)) func = kwds = {'equal_nan': True, 'err_msg': '', 'header': 'Not equal to tolerance rtol=1e-05, atol=0', 'verbose': True} self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/contextlib.py:81: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ comparison = .compare at 0x10b0d6520> x = array([ 1.8424029+1.842403j , -3.2566166-2.0098825j, -2.554953 +0.5109906j, -2.8437912+2.018105j ], dtype=complex64) y = array([ 1.8424029+1.8424029j, -3.2566164-0.9538409j, -2.5549533+0.5109906j, -3.7224708+1.4323187j], dtype=complex64) err_msg = '\nMismatched elements: 2 / 4 (50%)\nMax absolute difference: 1.0560415\nMax relative difference: 0.31120184', verbose = True header = 'Not equal to tolerance rtol=1e-05, atol=0', precision = 6, equal_nan = True, equal_inf = True @np._no_nep50_warning() def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='', precision=6, equal_nan=True, equal_inf=True, *, strict=False): __tracebackhide__ = True # Hide traceback for py.test from numpy.core import array, array2string, isnan, inf, bool_, errstate, all, max, object_ x = np.asanyarray(x) y = np.asanyarray(y) # original array for output formatting ox, oy = x, y def isnumber(x): return x.dtype.char in '?bhilqpBHILQPefdgFDG' def istime(x): return x.dtype.char in "Mm" def func_assert_same_pos(x, y, func=isnan, hasval='nan'): """Handling nan/inf. Combine results of running func on x and y, checking that they are True at the same locations. """ __tracebackhide__ = True # Hide traceback for py.test x_id = func(x) y_id = func(y) # We include work-arounds here to handle three types of slightly # pathological ndarray subclasses: # (1) all() on `masked` array scalars can return masked arrays, so we # use != True # (2) __eq__ on some ndarray subclasses returns Python booleans # instead of element-wise comparisons, so we cast to bool_() and # use isinstance(..., bool) checks # (3) subclasses with bare-bones __array_function__ implementations may # not implement np.all(), so favor using the .all() method # We are not committed to supporting such subclasses, but it's nice to # support them if possible. if bool_(x_id == y_id).all() != True: msg = build_err_msg([x, y], err_msg + '\nx and y %s location mismatch:' % (hasval), verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) # If there is a scalar, then here we know the array has the same # flag as it everywhere, so we should return the scalar flag. if isinstance(x_id, bool) or x_id.ndim == 0: return bool_(x_id) elif isinstance(y_id, bool) or y_id.ndim == 0: return bool_(y_id) else: return y_id try: if strict: cond = x.shape == y.shape and x.dtype == y.dtype else: cond = (x.shape == () or y.shape == ()) or x.shape == y.shape if not cond: if x.shape != y.shape: reason = f'\n(shapes {x.shape}, {y.shape} mismatch)' else: reason = f'\n(dtypes {x.dtype}, {y.dtype} mismatch)' msg = build_err_msg([x, y], err_msg + reason, verbose=verbose, header=header, names=('x', 'y'), precision=precision) raise AssertionError(msg) flagged = bool_(False) if isnumber(x) and isnumber(y): if equal_nan: flagged = func_assert_same_pos(x, y, func=isnan, hasval='nan') if equal_inf: flagged |= func_assert_same_pos(x, y, func=lambda xy: xy == +inf, hasval='+inf') flagged |= func_assert_same_pos(x, y, func=lambda xy: xy == -inf, hasval='-inf') elif istime(x) and istime(y): # If one is datetime64 and the other timedelta64 there is no point if equal_nan and x.dtype.type == y.dtype.type: flagged = func_assert_same_pos(x, y, func=isnat, hasval="NaT") if flagged.ndim > 0: x, y = x[~flagged], y[~flagged] # Only do the comparison if actual values are left if x.size == 0: return elif flagged: # no sense doing comparison if everything is flagged. return val = comparison(x, y) if isinstance(val, bool): cond = val reduced = array([val]) else: reduced = val.ravel() cond = reduced.all() # The below comparison is a hack to ensure that fully masked # results, for which val.ravel().all() returns np.ma.masked, # do not trigger a failure (np.ma.masked != True evaluates as # np.ma.masked, which is falsy). if cond != True: n_mismatch = reduced.size - reduced.sum(dtype=intp) n_elements = flagged.size if flagged.ndim != 0 else reduced.size percent_mismatch = 100 * n_mismatch / n_elements remarks = [ 'Mismatched elements: {} / {} ({:.3g}%)'.format( n_mismatch, n_elements, percent_mismatch)] with errstate(all='ignore'): # ignore errors for non-numeric types with contextlib.suppress(TypeError): error = abs(x - y) if np.issubdtype(x.dtype, np.unsignedinteger): error2 = abs(y - x) np.minimum(error, error2, out=error) max_abs_error = max(error) if getattr(error, 'dtype', object_) == object_: remarks.append('Max absolute difference: ' + str(max_abs_error)) else: remarks.append('Max absolute difference: ' + array2string(max_abs_error)) # note: this definition of relative error matches that one # used by assert_allclose (found in np.isclose) # Filter values where the divisor would be zero nonzero = bool_(y != 0) if all(~nonzero): max_rel_error = array(inf) else: max_rel_error = max(error[nonzero] / abs(y[nonzero])) if getattr(error, 'dtype', object_) == object_: remarks.append('Max relative difference: ' + str(max_rel_error)) else: remarks.append('Max relative difference: ' + array2string(max_rel_error)) err_msg += '\n' + '\n'.join(remarks) msg = build_err_msg([ox, oy], err_msg, verbose=verbose, header=header, names=('x', 'y'), precision=precision) > raise AssertionError(msg) E AssertionError: E Not equal to tolerance rtol=1e-05, atol=0 E E Mismatched elements: 2 / 4 (50%) E Max absolute difference: 1.0560415 E Max relative difference: 0.31120184 E x: array([[ 1.842403+1.842403j, -3.256617-2.009882j], E [-2.554953+0.510991j, -2.843791+2.018105j]], dtype=complex64) E y: array([[ 1.842403+1.842403j, -3.256616-0.953841j], E [-2.554953+0.510991j, -3.722471+1.432319j]], dtype=complex64) __tracebackhide__ = True all = array = array2string = bool_ = comparison = .compare at 0x10b0d6520> cond = False equal_inf = True equal_nan = True err_msg = '\nMismatched elements: 2 / 4 (50%)\nMax absolute difference: 1.0560415\nMax relative difference: 0.31120184' error = array([1.1920929e-07, 1.0560415e+00, 2.3841858e-07, 1.0560414e+00], dtype=float32) errstate = flagged = array([[False, False], [False, False]]) func_assert_same_pos = .func_assert_same_pos at 0x10b0d6700> header = 'Not equal to tolerance rtol=1e-05, atol=0' inf = inf isnan = isnumber = .isnumber at 0x10b0d65c0> istime = .istime at 0x10b0d67a0> max = max_abs_error = 1.0560415 max_rel_error = 0.31120184 msg = '\nNot equal to tolerance rtol=1e-05, atol=0\n\nMismatched elements: 2 / 4 (50%)\nMax absolute difference: 1.0560415\n...ray([[ 1.842403+1.842403j, -3.256616-0.953841j],\n [-2.554953+0.510991j, -3.722471+1.432319j]], dtype=complex64)' n_elements = 4 n_mismatch = 2 nonzero = array([ True, True, True, True]) object_ = ox = array([[ 1.8424029+1.842403j , -3.2566166-2.0098825j], [-2.554953 +0.5109906j, -2.8437912+2.018105j ]], dtype=complex64) oy = array([[ 1.8424029+1.8424029j, -3.2566164-0.9538409j], [-2.5549533+0.5109906j, -3.7224708+1.4323187j]], dtype=complex64) percent_mismatch = 50.0 precision = 6 reduced = array([ True, False, True, False]) remarks = ['Mismatched elements: 2 / 4 (50%)', 'Max absolute difference: 1.0560415', 'Max relative difference: 0.31120184'] strict = False val = array([ True, False, True, False]) verbose = True x = array([ 1.8424029+1.842403j , -3.2566166-2.0098825j, -2.554953 +0.5109906j, -2.8437912+2.018105j ], dtype=complex64) y = array([ 1.8424029+1.8424029j, -3.2566164-0.9538409j, -2.5549533+0.5109906j, -3.7224708+1.4323187j], dtype=complex64) ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py:862: AssertionError The above exception was the direct cause of the following exception: self = def test_herm_cases(self): > self.check_cases(require={'hermitian'}, exclude={'generalized', 'size-0'}) self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:382: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = , require = {'hermitian'}, exclude = {'generalized', 'size-0'} def check_cases(self, require=set(), exclude=set()): """ Run func on each of the cases with all of the tags in require, and none of the tags in exclude """ for case in self.TEST_CASES: # filter by require and exclude if case.tags & require != require: continue if case.tags & exclude: continue try: case.check(self.do) except Exception as e: msg = f'In test case: {case!r}\n\n' msg += traceback.format_exc() > raise AssertionError(msg) from e E AssertionError: In test case: E E Traceback (most recent call last): E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py", line 350, in check_cases E case.check(self.do) E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py", line 85, in check E do(self.a, self.b, tags=self.tags) E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py", line 1152, in do E assert_allclose(dot_generalized(a, evc), E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py", line 1590, in assert_allclose E assert_array_compare(compare, actual, desired, err_msg=str(err_msg), E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/contextlib.py", line 81, in inner E return func(*args, **kwds) E ^^^^^^^^^^^^^^^^^^^ E File "/Users/rgommers/mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/testing/_private/utils.py", line 862, in assert_array_compare E raise AssertionError(msg) E AssertionError: E Not equal to tolerance rtol=1e-05, atol=0 E E Mismatched elements: 2 / 4 (50%) E Max absolute difference: 1.0560415 E Max relative difference: 0.31120184 E x: array([[ 1.842403+1.842403j, -3.256617-2.009882j], E [-2.554953+0.510991j, -2.843791+2.018105j]], dtype=complex64) E y: array([[ 1.842403+1.842403j, -3.256616-0.953841j], E [-2.554953+0.510991j, -3.722471+1.432319j]], dtype=complex64) case = exclude = {'generalized', 'size-0'} msg = 'In test case: \n\nTraceback (most recent call last):\n File "/Users/rgommers/mambaforge/envs/n...y([[ 1.842403+1.842403j, -3.256616-0.953841j],\n [-2.554953+0.510991j, -3.722471+1.432319j]], dtype=complex64)\n' require = {'hermitian'} self = ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:354: AssertionError ______________________________________________ TestCholesky.test_basic_property[complex64-shape1] ______________________________________________ self = , shape = (2, 2), dtype = @pytest.mark.parametrize( 'shape', [(1, 1), (2, 2), (3, 3), (50, 50), (3, 10, 10)] ) @pytest.mark.parametrize( 'dtype', (np.float32, np.float64, np.complex64, np.complex128) ) def test_basic_property(self, shape, dtype): # Check A = L L^H np.random.seed(1) a = np.random.randn(*shape) if np.issubdtype(dtype, np.complexfloating): a = a + 1j*np.random.randn(*shape) t = list(range(len(shape))) t[-2:] = -1, -2 a = np.matmul(a.transpose(t).conj(), a) a = np.asarray(a, dtype=dtype) > c = np.linalg.cholesky(a) a = array([[ 6.7107615-9.0146355e-17j, -3.746924 -9.3489879e-01j], [-3.746924 +9.3489879e-01j, 7.402024 -6.6018370e-17j]], dtype=complex64) dtype = self = shape = (2, 2) t = [-1, -2] ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:1804: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ <__array_function__ internals>:200: in cholesky ??? args = (array([[ 6.7107615-9.0146355e-17j, -3.746924 -9.3489879e-01j], [-3.746924 +9.3489879e-01j, 7.402024 -6.6018370e-17j]], dtype=complex64),) dispatcher = implementation = kwargs = {} public_api = relevant_args = (array([[ 6.7107615-9.0146355e-17j, -3.746924 -9.3489879e-01j], [-3.746924 +9.3489879e-01j, 7.402024 -6.6018370e-17j]], dtype=complex64),) ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/linalg.py:756: in cholesky r = gufunc(a, signature=signature, extobj=extobj) a = array([[ 6.7107615-9.0146355e-17j, -3.746924 -9.3489879e-01j], [-3.746924 +9.3489879e-01j, 7.402024 -6.6018370e-17j]], dtype=complex64) extobj = [8192, 1536, ] gufunc = result_t = signature = 'D->D' t = wrap = _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ err = 'invalid value', flag = 8 def _raise_linalgerror_nonposdef(err, flag): > raise LinAlgError("Matrix is not positive definite") E numpy.linalg.LinAlgError: Matrix is not positive definite err = 'invalid value' flag = 8 ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/linalg.py:92: LinAlgError ______________________________________________ TestCholesky.test_basic_property[complex64-shape2] ______________________________________________ self = , shape = (3, 3), dtype = @pytest.mark.parametrize( 'shape', [(1, 1), (2, 2), (3, 3), (50, 50), (3, 10, 10)] ) @pytest.mark.parametrize( 'dtype', (np.float32, np.float64, np.complex64, np.complex128) ) def test_basic_property(self, shape, dtype): # Check A = L L^H np.random.seed(1) a = np.random.randn(*shape) if np.issubdtype(dtype, np.complexfloating): a = a + 1j*np.random.randn(*shape) t = list(range(len(shape))) t[-2:] = -1, -2 a = np.matmul(a.transpose(t).conj(), a) a = np.asarray(a, dtype=dtype) > c = np.linalg.cholesky(a) a = array([[ 8.210027 +9.7039469e-17j, -3.3015501+1.7754153e+00j, 3.2819488-6.6174345e+00j], [-3.3015501-1...j], [ 3.2819488+6.6174345e+00j, -5.207721 -2.8530483e+00j, 11.97808 -2.0396841e-16j]], dtype=complex64) dtype = self = shape = (3, 3) t = [-1, -2] ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:1804: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ <__array_function__ internals>:200: in cholesky ??? args = (array([[ 8.210027 +9.7039469e-17j, -3.3015501+1.7754153e+00j, 3.2819488-6.6174345e+00j], [-3.3015501-..., [ 3.2819488+6.6174345e+00j, -5.207721 -2.8530483e+00j, 11.97808 -2.0396841e-16j]], dtype=complex64),) dispatcher = implementation = kwargs = {} public_api = relevant_args = (array([[ 8.210027 +9.7039469e-17j, -3.3015501+1.7754153e+00j, 3.2819488-6.6174345e+00j], [-3.3015501-..., [ 3.2819488+6.6174345e+00j, -5.207721 -2.8530483e+00j, 11.97808 -2.0396841e-16j]], dtype=complex64),) ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/linalg.py:756: in cholesky r = gufunc(a, signature=signature, extobj=extobj) a = array([[ 8.210027 +9.7039469e-17j, -3.3015501+1.7754153e+00j, 3.2819488-6.6174345e+00j], [-3.3015501-1...j], [ 3.2819488+6.6174345e+00j, -5.207721 -2.8530483e+00j, 11.97808 -2.0396841e-16j]], dtype=complex64) extobj = [8192, 1536, ] gufunc = result_t = signature = 'D->D' t = wrap = _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ err = 'invalid value', flag = 8 def _raise_linalgerror_nonposdef(err, flag): > raise LinAlgError("Matrix is not positive definite") E numpy.linalg.LinAlgError: Matrix is not positive definite err = 'invalid value' flag = 8 ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/linalg.py:92: LinAlgError ______________________________________________ TestCholesky.test_basic_property[complex64-shape3] ______________________________________________ self = , shape = (50, 50), dtype = @pytest.mark.parametrize( 'shape', [(1, 1), (2, 2), (3, 3), (50, 50), (3, 10, 10)] ) @pytest.mark.parametrize( 'dtype', (np.float32, np.float64, np.complex64, np.complex128) ) def test_basic_property(self, shape, dtype): # Check A = L L^H np.random.seed(1) a = np.random.randn(*shape) if np.issubdtype(dtype, np.complexfloating): a = a + 1j*np.random.randn(*shape) t = list(range(len(shape))) t[-2:] = -1, -2 a = np.matmul(a.transpose(t).conj(), a) a = np.asarray(a, dtype=dtype) > c = np.linalg.cholesky(a) a = array([[ 86.08559 +1.8068895e-16j, 3.4421804 +1.5881272e+01j, -0.45363563-4.4661412e-01j, ..., 2.640359... 3.5472295 -1.0603434e+00j, -15.734409 +2.6528928e+00j, 89.70911 -1.6849805e-16j]], dtype=complex64) dtype = self = shape = (50, 50) t = [-1, -2] ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:1804: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ <__array_function__ internals>:200: in cholesky ??? args = (array([[ 86.08559 +1.8068895e-16j, 3.4421804 +1.5881272e+01j, -0.45363563-4.4661412e-01j, ..., 2.64035...3.5472295 -1.0603434e+00j, -15.734409 +2.6528928e+00j, 89.70911 -1.6849805e-16j]], dtype=complex64),) dispatcher = implementation = kwargs = {} public_api = relevant_args = (array([[ 86.08559 +1.8068895e-16j, 3.4421804 +1.5881272e+01j, -0.45363563-4.4661412e-01j, ..., 2.64035...3.5472295 -1.0603434e+00j, -15.734409 +2.6528928e+00j, 89.70911 -1.6849805e-16j]], dtype=complex64),) ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/linalg.py:756: in cholesky r = gufunc(a, signature=signature, extobj=extobj) a = array([[ 86.08559 +1.8068895e-16j, 3.4421804 +1.5881272e+01j, -0.45363563-4.4661412e-01j, ..., 2.640359... 3.5472295 -1.0603434e+00j, -15.734409 +2.6528928e+00j, 89.70911 -1.6849805e-16j]], dtype=complex64) extobj = [8192, 1536, ] gufunc = result_t = signature = 'D->D' t = wrap = _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ err = 'invalid value', flag = 8 def _raise_linalgerror_nonposdef(err, flag): > raise LinAlgError("Matrix is not positive definite") E numpy.linalg.LinAlgError: Matrix is not positive definite err = 'invalid value' flag = 8 ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/linalg.py:92: LinAlgError ______________________________________________ TestCholesky.test_basic_property[complex64-shape4] ______________________________________________ self = , shape = (3, 10, 10), dtype = @pytest.mark.parametrize( 'shape', [(1, 1), (2, 2), (3, 3), (50, 50), (3, 10, 10)] ) @pytest.mark.parametrize( 'dtype', (np.float32, np.float64, np.complex64, np.complex128) ) def test_basic_property(self, shape, dtype): # Check A = L L^H np.random.seed(1) a = np.random.randn(*shape) if np.issubdtype(dtype, np.complexfloating): a = a + 1j*np.random.randn(*shape) t = list(range(len(shape))) t[-2:] = -1, -2 a = np.matmul(a.transpose(t).conj(), a) a = np.asarray(a, dtype=dtype) > c = np.linalg.cholesky(a) a = array([[[ 2.0737574e+01+3.29707813e-16j, -9.5955276e+00+5.31176758e+00j, -3.3324742e+00+3.40434051e+00j, -7.6...+00-3.43903995e+00j, -1.0115569e+01-2.07136607e+00j, 2.4076559e+01-1.08485803e-16j]]], dtype=complex64) dtype = self = shape = (3, 10, 10) t = [0, -1, -2] ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:1804: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ <__array_function__ internals>:200: in cholesky ??? args = (array([[[ 2.0737574e+01+3.29707813e-16j, -9.5955276e+00+5.31176758e+00j, -3.3324742e+00+3.40434051e+00j, -7....0-3.43903995e+00j, -1.0115569e+01-2.07136607e+00j, 2.4076559e+01-1.08485803e-16j]]], dtype=complex64),) dispatcher = implementation = kwargs = {} public_api = relevant_args = (array([[[ 2.0737574e+01+3.29707813e-16j, -9.5955276e+00+5.31176758e+00j, -3.3324742e+00+3.40434051e+00j, -7....0-3.43903995e+00j, -1.0115569e+01-2.07136607e+00j, 2.4076559e+01-1.08485803e-16j]]], dtype=complex64),) ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/linalg.py:756: in cholesky r = gufunc(a, signature=signature, extobj=extobj) a = array([[[ 2.0737574e+01+3.29707813e-16j, -9.5955276e+00+5.31176758e+00j, -3.3324742e+00+3.40434051e+00j, -7.6...+00-3.43903995e+00j, -1.0115569e+01-2.07136607e+00j, 2.4076559e+01-1.08485803e-16j]]], dtype=complex64) extobj = [8192, 1536, ] gufunc = result_t = signature = 'D->D' t = wrap = _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ err = 'invalid value', flag = 8 def _raise_linalgerror_nonposdef(err, flag): > raise LinAlgError("Matrix is not positive definite") E numpy.linalg.LinAlgError: Matrix is not positive definite err = 'invalid value' flag = 8 ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/linalg.py:92: LinAlgError _____________________________________________ TestCholesky.test_basic_property[complex128-shape1] ______________________________________________ self = , shape = (2, 2), dtype = @pytest.mark.parametrize( 'shape', [(1, 1), (2, 2), (3, 3), (50, 50), (3, 10, 10)] ) @pytest.mark.parametrize( 'dtype', (np.float32, np.float64, np.complex64, np.complex128) ) def test_basic_property(self, shape, dtype): # Check A = L L^H np.random.seed(1) a = np.random.randn(*shape) if np.issubdtype(dtype, np.complexfloating): a = a + 1j*np.random.randn(*shape) t = list(range(len(shape))) t[-2:] = -1, -2 a = np.matmul(a.transpose(t).conj(), a) a = np.asarray(a, dtype=dtype) > c = np.linalg.cholesky(a) a = array([[ 6.71076172-9.01463546e-17j, -3.74692388-9.34898787e-01j], [-3.74692388+9.34898787e-01j, 7.40202389-6.60183692e-17j]]) dtype = self = shape = (2, 2) t = [-1, -2] ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:1804: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ <__array_function__ internals>:200: in cholesky ??? args = (array([[ 6.71076172-9.01463546e-17j, -3.74692388-9.34898787e-01j], [-3.74692388+9.34898787e-01j, 7.40202389-6.60183692e-17j]]),) dispatcher = implementation = kwargs = {} public_api = relevant_args = (array([[ 6.71076172-9.01463546e-17j, -3.74692388-9.34898787e-01j], [-3.74692388+9.34898787e-01j, 7.40202389-6.60183692e-17j]]),) ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/linalg.py:756: in cholesky r = gufunc(a, signature=signature, extobj=extobj) a = array([[ 6.71076172-9.01463546e-17j, -3.74692388-9.34898787e-01j], [-3.74692388+9.34898787e-01j, 7.40202389-6.60183692e-17j]]) extobj = [8192, 1536, ] gufunc = result_t = signature = 'D->D' t = wrap = _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ err = 'invalid value', flag = 8 def _raise_linalgerror_nonposdef(err, flag): > raise LinAlgError("Matrix is not positive definite") E numpy.linalg.LinAlgError: Matrix is not positive definite err = 'invalid value' flag = 8 ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/linalg.py:92: LinAlgError _____________________________________________ TestCholesky.test_basic_property[complex128-shape2] ______________________________________________ self = , shape = (3, 3), dtype = @pytest.mark.parametrize( 'shape', [(1, 1), (2, 2), (3, 3), (50, 50), (3, 10, 10)] ) @pytest.mark.parametrize( 'dtype', (np.float32, np.float64, np.complex64, np.complex128) ) def test_basic_property(self, shape, dtype): # Check A = L L^H np.random.seed(1) a = np.random.randn(*shape) if np.issubdtype(dtype, np.complexfloating): a = a + 1j*np.random.randn(*shape) t = list(range(len(shape))) t[-2:] = -1, -2 a = np.matmul(a.transpose(t).conj(), a) a = np.asarray(a, dtype=dtype) > c = np.linalg.cholesky(a) a = array([[ 8.21002685+9.70394725e-17j, -3.30155008+1.77541531e+00j, 3.28194873-6.61743449e+00j], [-3.301...5304839e+00j], [ 3.28194873+6.61743449e+00j, -5.20772107-2.85304839e+00j, 11.97808001-2.03968406e-16j]]) dtype = self = shape = (3, 3) t = [-1, -2] ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:1804: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ <__array_function__ internals>:200: in cholesky ??? args = (array([[ 8.21002685+9.70394725e-17j, -3.30155008+1.77541531e+00j, 3.28194873-6.61743449e+00j], [-3.30...04839e+00j], [ 3.28194873+6.61743449e+00j, -5.20772107-2.85304839e+00j, 11.97808001-2.03968406e-16j]]),) dispatcher = implementation = kwargs = {} public_api = relevant_args = (array([[ 8.21002685+9.70394725e-17j, -3.30155008+1.77541531e+00j, 3.28194873-6.61743449e+00j], [-3.30...04839e+00j], [ 3.28194873+6.61743449e+00j, -5.20772107-2.85304839e+00j, 11.97808001-2.03968406e-16j]]),) ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/linalg.py:756: in cholesky r = gufunc(a, signature=signature, extobj=extobj) a = array([[ 8.21002685+9.70394725e-17j, -3.30155008+1.77541531e+00j, 3.28194873-6.61743449e+00j], [-3.301...5304839e+00j], [ 3.28194873+6.61743449e+00j, -5.20772107-2.85304839e+00j, 11.97808001-2.03968406e-16j]]) extobj = [8192, 1536, ] gufunc = result_t = signature = 'D->D' t = wrap = _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ err = 'invalid value', flag = 8 def _raise_linalgerror_nonposdef(err, flag): > raise LinAlgError("Matrix is not positive definite") E numpy.linalg.LinAlgError: Matrix is not positive definite err = 'invalid value' flag = 8 ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/linalg.py:92: LinAlgError _____________________________________________ TestCholesky.test_basic_property[complex128-shape3] ______________________________________________ self = , shape = (50, 50), dtype = @pytest.mark.parametrize( 'shape', [(1, 1), (2, 2), (3, 3), (50, 50), (3, 10, 10)] ) @pytest.mark.parametrize( 'dtype', (np.float32, np.float64, np.complex64, np.complex128) ) def test_basic_property(self, shape, dtype): # Check A = L L^H np.random.seed(1) a = np.random.randn(*shape) if np.issubdtype(dtype, np.complexfloating): a = a + 1j*np.random.randn(*shape) t = list(range(len(shape))) t[-2:] = -1, -2 a = np.matmul(a.transpose(t).conj(), a) a = np.asarray(a, dtype=dtype) > c = np.linalg.cholesky(a) a = array([[ 86.08558859+1.80688949e-16j, 3.44218047+1.58812724e+01j, -0.45363563-4.46614131e-01j, ..., 2.640...34571312e-01j, ..., 3.54722947-1.06034335e+00j, -15.73440912+2.65289272e+00j, 89.70910493-1.68498058e-16j]]) dtype = self = shape = (50, 50) t = [-1, -2] ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:1804: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ <__array_function__ internals>:200: in cholesky ??? args = (array([[ 86.08558859+1.80688949e-16j, 3.44218047+1.58812724e+01j, -0.45363563-4.46614131e-01j, ..., 2.64...571312e-01j, ..., 3.54722947-1.06034335e+00j, -15.73440912+2.65289272e+00j, 89.70910493-1.68498058e-16j]]),) dispatcher = implementation = kwargs = {} public_api = relevant_args = (array([[ 86.08558859+1.80688949e-16j, 3.44218047+1.58812724e+01j, -0.45363563-4.46614131e-01j, ..., 2.64...571312e-01j, ..., 3.54722947-1.06034335e+00j, -15.73440912+2.65289272e+00j, 89.70910493-1.68498058e-16j]]),) ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/linalg.py:756: in cholesky r = gufunc(a, signature=signature, extobj=extobj) a = array([[ 86.08558859+1.80688949e-16j, 3.44218047+1.58812724e+01j, -0.45363563-4.46614131e-01j, ..., 2.640...34571312e-01j, ..., 3.54722947-1.06034335e+00j, -15.73440912+2.65289272e+00j, 89.70910493-1.68498058e-16j]]) extobj = [8192, 1536, ] gufunc = result_t = signature = 'D->D' t = wrap = _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ err = 'invalid value', flag = 8 def _raise_linalgerror_nonposdef(err, flag): > raise LinAlgError("Matrix is not positive definite") E numpy.linalg.LinAlgError: Matrix is not positive definite err = 'invalid value' flag = 8 ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/linalg.py:92: LinAlgError _____________________________________________ TestCholesky.test_basic_property[complex128-shape4] ______________________________________________ self = , shape = (3, 10, 10), dtype = @pytest.mark.parametrize( 'shape', [(1, 1), (2, 2), (3, 3), (50, 50), (3, 10, 10)] ) @pytest.mark.parametrize( 'dtype', (np.float32, np.float64, np.complex64, np.complex128) ) def test_basic_property(self, shape, dtype): # Check A = L L^H np.random.seed(1) a = np.random.randn(*shape) if np.issubdtype(dtype, np.complexfloating): a = a + 1j*np.random.randn(*shape) t = list(range(len(shape))) t[-2:] = -1, -2 a = np.matmul(a.transpose(t).conj(), a) a = np.asarray(a, dtype=dtype) > c = np.linalg.cholesky(a) a = array([[[ 2.07375744e+01+3.29707800e-16j, -9.59552753e+00+5.31176763e+00j, -3.33247414e+00+3.4043406... 1.89501151e+00-3.43904000e+00j, -1.01155689e+01-2.07136618e+00j, 2.40765597e+01-1.08485801e-16j]]]) dtype = self = shape = (3, 10, 10) t = [0, -1, -2] ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/tests/test_linalg.py:1804: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ <__array_function__ internals>:200: in cholesky ??? args = (array([[[ 2.07375744e+01+3.29707800e-16j, -9.59552753e+00+5.31176763e+00j, -3.33247414e+00+3.404340....89501151e+00-3.43904000e+00j, -1.01155689e+01-2.07136618e+00j, 2.40765597e+01-1.08485801e-16j]]]),) dispatcher = implementation = kwargs = {} public_api = relevant_args = (array([[[ 2.07375744e+01+3.29707800e-16j, -9.59552753e+00+5.31176763e+00j, -3.33247414e+00+3.404340....89501151e+00-3.43904000e+00j, -1.01155689e+01-2.07136618e+00j, 2.40765597e+01-1.08485801e-16j]]]),) ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/linalg.py:756: in cholesky r = gufunc(a, signature=signature, extobj=extobj) a = array([[[ 2.07375744e+01+3.29707800e-16j, -9.59552753e+00+5.31176763e+00j, -3.33247414e+00+3.4043406... 1.89501151e+00-3.43904000e+00j, -1.01155689e+01-2.07136618e+00j, 2.40765597e+01-1.08485801e-16j]]]) extobj = [8192, 1536, ] gufunc = result_t = signature = 'D->D' t = wrap = _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ err = 'invalid value', flag = 8 def _raise_linalgerror_nonposdef(err, flag): > raise LinAlgError("Matrix is not positive definite") E numpy.linalg.LinAlgError: Matrix is not positive definite err = 'invalid value' flag = 8 ../../mambaforge/envs/numpyp-arm64-issue/lib/python3.11/site-packages/numpy/linalg/linalg.py:92: LinAlgError =========================================================== short test summary info ============================================================ FAILED tests/test_linalg.py::TestSVDHermitian::test_herm_cases - AssertionError: In test case: FAILED tests/test_linalg.py::TestPinvHermitian::test_herm_cases - AssertionError: In test case: FAILED tests/test_linalg.py::TestEighCases::test_herm_cases - AssertionError: In test case: FAILED tests/test_linalg.py::TestCholesky::test_basic_property[complex64-shape1] - numpy.linalg.LinAlgError: Matrix is not positive definite FAILED tests/test_linalg.py::TestCholesky::test_basic_property[complex64-shape2] - numpy.linalg.LinAlgError: Matrix is not positive definite FAILED tests/test_linalg.py::TestCholesky::test_basic_property[complex64-shape3] - numpy.linalg.LinAlgError: Matrix is not positive definite FAILED tests/test_linalg.py::TestCholesky::test_basic_property[complex64-shape4] - numpy.linalg.LinAlgError: Matrix is not positive definite FAILED tests/test_linalg.py::TestCholesky::test_basic_property[complex128-shape1] - numpy.linalg.LinAlgError: Matrix is not positive definite FAILED tests/test_linalg.py::TestCholesky::test_basic_property[complex128-shape2] - numpy.linalg.LinAlgError: Matrix is not positive definite FAILED tests/test_linalg.py::TestCholesky::test_basic_property[complex128-shape3] - numpy.linalg.LinAlgError: Matrix is not positive definite FAILED tests/test_linalg.py::TestCholesky::test_basic_property[complex128-shape4] - numpy.linalg.LinAlgError: Matrix is not positive definite 11 failed, 375 passed, 2 skipped, 27 deselected, 2 xfailed in 1.93s ```

With openblas, all tests pass.

jcmgray commented 1 year ago

That's a little odd. Either way, openblas is the default so a simple mamba create -n tmp-env numpy=1.24.1 will use openblas.

Yes likely a separate issue, but thought I'd note that at least on my Mac the default install (i.e, this exact command) is the netlib blas variant, not openblas. When I use openblas I get an error that is essentially libcblas.3.dylib' (no such file).. perhaps I am missing some dep that makes conda/mamba avoid openblas.

rgommers commented 1 year ago

Hmm, no idea why. That's a significant performance penalty, so I'd consider getting netlib by default a bug. The openblas packages for both x86-64 and arm64 at https://anaconda.org/conda-forge/openblas are up to date, so I can't explain what is happening there. Maybe someone more familiar with the BLAS selection mechanism can.

h-vetinari commented 1 year ago

Seems like I need to get the blas testing series up to speed for 1.24.

Yes likely a separate issue, but thought I'd note that at least on my Mac the default install (i.e, this exact command) is the netlib blas variant, not openblas. When I use openblas I get an error that is essentially libcblas.3.dylib' (no such file).. perhaps I am missing some dep that makes conda/mamba avoid openblas.

openblas should be the default also on osx, and in any case it should definitely work. However, you're mixing channels (default and conda-forge), which is a very likely cause for these problems. Could you please try

conda config --add channels conda-forge
conda config --set channel_priority strict

and then either a new environment, or using conda update --all?

jcmgray commented 1 year ago

openblas should be the default also on osx, and in any case it should definitely work. However, you're mixing channels (default and conda-forge), which is a very likely cause for these problems. Could you please try

Ah sorry yes you are right, thanks for the suggestion.

rh996 commented 1 year ago

I am using a Mac mini M1 and recently found this issue. It works fine with "libblas=*=*openblas" and "libblas=*=*netlib". However, the eigh issue appears when I update Numpy using "libblas=*=*accelerate". Probably this is because they didn't update the libblas 3.9.0-16_osxarm64_accelerate in conda-forge? @jcmgray is your problem solved? Where can I ask for updating the libblas 3.9.0-16_osxarm64_accelerate package since complex eigenvector problems are significant in physics?

cosmic-latte commented 1 year ago

numpy/numpy#24640

cosmic-latte commented 1 year ago

Experienced the same problem on numpy 1.26.0 with accelerate blas.