Skip to content

Commit

Permalink
BUG: Fix infinite recursion in longdouble/large integer scalar ops
Browse files Browse the repository at this point in the history
A smal bug snuck in when implementing NEP 50 weak-scalar logic,
and unfortunately the tests didn't cover that specific path :/.

closes gh-22787
  • Loading branch information
seberg authored and charris committed Dec 13, 2022
1 parent 34e068c commit 21f7096
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
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

0 comments on commit 21f7096

Please sign in to comment.