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

BUG: Fix infinite recursion in longdouble/large integer scalar ops #22793

Merged
merged 1 commit into from Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion numpy/core/src/umath/scalarmath.c.src
Expand Up @@ -1004,7 +1004,7 @@ convert_to_@name@(PyObject *value, @type@ *result, npy_bool *may_need_deferring)
if (overflow) {
/* handle as if "unsafe" */
if (npy_promotion_state != NPY_USE_WEAK_PROMOTION) {
return PROMOTION_REQUIRED;
return OTHER_IS_UNKNOWN_OBJECT;
}
return CONVERT_PYSCALAR;
}
Expand Down
18 changes: 10 additions & 8 deletions numpy/core/tests/test_scalarmath.py
Expand Up @@ -860,27 +860,29 @@ def test_operator_scalars(op, type1, type2):


@pytest.mark.parametrize("op", reasonable_operators_for_scalars)
def test_longdouble_inf_loop(op):
@pytest.mark.parametrize("val", [None, 2**64])
def test_longdouble_inf_loop(op, val):
# Note: The 2**64 value will pass once NEP 50 is adopted.
try:
op(np.longdouble(3), None)
op(np.longdouble(3), val)
except TypeError:
pass
try:
op(None, np.longdouble(3))
op(val, np.longdouble(3))
except TypeError:
pass


@pytest.mark.parametrize("op", reasonable_operators_for_scalars)
def test_clongdouble_inf_loop(op):
if op in {operator.mod} and False:
pytest.xfail("The modulo operator is known to be broken")
@pytest.mark.parametrize("val", [None, 2**64])
def test_clongdouble_inf_loop(op, val):
# Note: The 2**64 value will pass once NEP 50 is adopted.
try:
op(np.clongdouble(3), None)
op(np.clongdouble(3), val)
except TypeError:
pass
try:
op(None, np.longdouble(3))
op(val, np.longdouble(3))
except TypeError:
pass

Expand Down