Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions numba/tests/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@

skip_if_32bit = unittest.skipIf(_32bit, "Not supported on 32 bit")

def expected_failure_py311(fn):
if utils.PYVERSION == (3, 11):
return unittest.expectedFailure(fn)
else:
return fn

_msg = "SciPy needed for test"
skip_unless_scipy = unittest.skipIf(scipy is None, _msg)

Expand Down
21 changes: 15 additions & 6 deletions numba/tests/test_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,8 @@ def control_unsigned(a, b):
return control_unsigned

def run_binary(self, pyfunc, control_func, operands, types,
expected_type=int, **assertPreciseEqualArgs):
expected_type=int, force_type=lambda x: x,
**assertPreciseEqualArgs):
for xt, yt in types:
cr = compile_isolated(pyfunc, (xt, yt), flags=Noflags)
cfunc = cr.entry_point
Expand All @@ -1261,6 +1262,7 @@ def run_binary(self, pyfunc, control_func, operands, types,
self.assertIsInstance(got, expected_type)
msg = ("mismatch for (%r, %r) with types %s"
% (x, y, (xt, yt)))
got, expected = force_type(got), force_type(expected)
self.assertPreciseEqual(got, expected, msg=msg,
**assertPreciseEqualArgs)

Expand All @@ -1280,11 +1282,16 @@ def run_unary(self, pyfunc, control_func, operands, types,
% (x, xt, got, expected))

def run_arith_binop(self, pyfunc, opname, samples,
expected_type=int):
expected_type=int, force_type=lambda x: x,
**assertPreciseEqualArgs):
self.run_binary(pyfunc, self.get_control_signed(opname),
samples, self.signed_pairs, expected_type)
samples, self.signed_pairs, expected_type,
force_type=force_type,
**assertPreciseEqualArgs)
self.run_binary(pyfunc, self.get_control_unsigned(opname),
samples, self.unsigned_pairs, expected_type)
samples, self.unsigned_pairs, expected_type,
force_type=force_type,
**assertPreciseEqualArgs)

def test_add(self):
self.run_arith_binop(self.op.add_usecase, 'add', self.int_samples)
Expand All @@ -1304,11 +1311,13 @@ def test_mod(self):
self.run_arith_binop(self.op.mod_usecase, 'mod', samples)

def test_pow(self):
if utils.PYVERSION == (3, 11):
extra_cast = dict(force_type=float)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is an else branch needed to define extra_cast else this will fail on < 3.11 with a NameError?

Another option to "fix" this would be to just restrict the input on 3.11 to numerically smaller values. As noted in the comments, there are already challenges present in the inputs/testing/implementation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, i'll fix that. and check if smaller numbers make a easier fix.

pyfunc = self.op.pow_usecase
# Only test with positive values, as otherwise trying to write the
# control function in terms of Python or Numpy power turns out insane.
samples = [x for x in self.int_samples if x >= 0]
self.run_arith_binop(pyfunc, 'pow', samples)
self.run_arith_binop(pyfunc, 'pow', samples, **extra_cast)

# Now test all non-zero values, but only with signed types
def control_signed(a, b):
Expand All @@ -1325,7 +1334,7 @@ def control_signed(a, b):
signed_pairs = [(u, v) for u, v in self.type_pairs
if u.signed and v.signed]
self.run_binary(pyfunc, control_signed,
samples, signed_pairs)
samples, signed_pairs, **extra_cast)

def test_truediv(self):

Expand Down
4 changes: 3 additions & 1 deletion numba/tests/test_try_except.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)
from numba.tests.support import (
TestCase, unittest, captured_stdout, MemoryLeakMixin,
skip_parfors_unsupported, skip_unless_scipy,
skip_parfors_unsupported, skip_unless_scipy, expected_failure_py311
)


Expand Down Expand Up @@ -689,6 +689,7 @@ def udt(n, x):
self.assertEqual(list(udt(10, 5)), list(range(5)))
self.assertEqual(list(udt(10, 10)), list(range(10)))

@expected_failure_py311
def test_objmode(self):
@njit
def udt():
Expand All @@ -711,6 +712,7 @@ def udt():
str(raises.exception),
)

@expected_failure_py311
def test_objmode_output_type(self):
def bar(x):
return np.asarray(list(reversed(x.tolist())))
Expand Down
5 changes: 4 additions & 1 deletion numba/tests/test_withlifting.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
from numba.core.extending import overload
from numba.tests.support import (MemoryLeak, TestCase, captured_stdout,
skip_unless_scipy, linux_only,
strace_supported, strace)
strace_supported, strace,
expected_failure_py311)
from numba.core.utils import PYVERSION
from numba.experimental import jitclass
import unittest
Expand Down Expand Up @@ -287,6 +288,7 @@ def test_liftcall4(self):
# 3.7 fails to interpret the bytecode for this example
@unittest.skipIf(PYVERSION <= (3, 8),
"unsupported on py3.8 and before")
@expected_failure_py311
def test_liftcall5(self):
self.check_extracted_with(liftcall5, expect_count=1,
expected_stdout="0\n1\n2\n3\n4\n5\nA\n")
Expand Down Expand Up @@ -732,6 +734,7 @@ def foo(func, x):
fn = njit(lambda z: z + 5)
self.assert_equal_return_and_stdout(foo, fn, x)

@expected_failure_py311
def test_case19_recursion(self):
def foo(x):
with objmode_context():
Expand Down