Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support complex types #11

Open
paugier opened this issue Feb 24, 2022 · 0 comments
Open

Support complex types #11

paugier opened this issue Feb 24, 2022 · 0 comments

Comments

@paugier
Copy link

paugier commented Feb 24, 2022

It would be great to support complex types (as np.allclose).

import numpy as np

def test_allclose_complex(allclose):
    arr = np.zeros(2, dtype=complex)
    allclose(arr, arr)

gives

$ pytest test_allclose_complex.py                                                                                         
=========================================================== test session starts ===========================================================
platform linux -- Python 3.9.6, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
PyQt5 5.14.2 -- Qt runtime 5.14.2 -- Qt compiled 5.14.2
rootdir: /home/pierre/tmp
plugins: anyio-3.3.1, nbval-0.9.6, qt-4.0.2, datadir-1.3.1, allclose-1.0.0, cov-2.12.1
collected 1 item                                                                                                                          

test_allclose_complex.py F                                                                                                          [100%]

================================================================ FAILURES =================================================================
__________________________________________________________ test_allclose_complex __________________________________________________________

allclose = <function allclose.<locals>._allclose at 0x7effcf62b5e0>

    def test_allclose_complex(allclose):
        arr = np.zeros(2, dtype=complex)
>       allclose(arr, arr)

test_allclose_complex.py:6: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

a = array([0.+0.j, 0.+0.j]), b = array([0.+0.j, 0.+0.j]), rtol = 1e-05, atol = 1e-08, xtol = 0, equal_nan = False, print_fail = 5
record_rmse = True

    @_add_common_docs
    def _allclose(
        a,
        b,
        rtol=1e-5,
        atol=1e-8,
        xtol=0,
        equal_nan=False,
        print_fail=5,
        record_rmse=True,
    ):
        """Checks if two arrays are close, mimicking `numpy.allclose`.
        """
    
        if len(overrides) > 0:
            override_args = overrides[min(call_count[0], len(overrides) - 1)]
            atol = override_args.get("atol", atol)
            rtol = override_args.get("rtol", rtol)
            xtol = override_args.get("xtol", xtol)
            equal_nan = override_args.get("equal_nan", equal_nan)
            print_fail = override_args.get("print_fail", print_fail)
            record_rmse = override_args.get("record_rmse", record_rmse)
            call_count[0] += 1
    
        a = np.atleast_1d(a)
        b = np.atleast_1d(b)
    
        rmse = _safe_rms(a - b)
        if record_rmse and not np.any(np.isnan(rmse)):
            request.node.user_properties.append(("rmse", rmse))
    
            ab_rms = _safe_rms(a) + _safe_rms(b)
>           rmse_relative = (2 * rmse / ab_rms) if ab_rms > 0 else np.nan
E           TypeError: '>' not supported between instances of 'complex' and 'int'

../.pyenv/versions/3.9.6/lib/python3.9/site-packages/pytest_allclose/plugin.py:89: TypeError
========================================================= short test summary info =========================================================
FAILED test_allclose_complex.py::test_allclose_complex - TypeError: '>' not supported between instances of 'complex' and 'int'
============================================================ 1 failed in 0.11s ============================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant