Skip to content

Commit

Permalink
Merge pull request #8469 from apmasell/issue8453
Browse files Browse the repository at this point in the history
Correctly handle optional types in parfors lowering
  • Loading branch information
sklam committed Oct 5, 2022
2 parents 99794c8 + 337971a commit babbf9e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 8 additions & 2 deletions numba/parfors/parfor_lowering.py
Original file line number Diff line number Diff line change
Expand Up @@ -1807,8 +1807,14 @@ def load_potential_tuple_var(x):
else:
if i < num_inps:
# Scalar input, need to store the value in an array of size 1
typ = (context.get_data_type(aty)
if not isinstance(aty, types.Boolean)
if isinstance(aty, types.Optional):
# Unpack optional type
unpacked_aty = aty.type
arg = context.cast(builder, arg, aty, unpacked_aty)
else:
unpacked_aty = aty
typ = (context.get_data_type(unpacked_aty)
if not isinstance(unpacked_aty, types.Boolean)
else llvmlite.ir.IntType(1))
ptr = cgutils.alloca_once(builder, typ)
builder.store(arg, ptr)
Expand Down
14 changes: 14 additions & 0 deletions numba/tests/test_parfors.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ def copy_args(*args):
new_args.append(x.copy())
elif isinstance(x, numbers.Number):
new_args.append(x)
elif x is None:
new_args.append(x)
elif isinstance(x, tuple):
new_args.append(copy.deepcopy(x))
elif isinstance(x, list):
Expand Down Expand Up @@ -2130,6 +2132,18 @@ def test_impl(a, b, size):
self.assertEqual(countParfors(test_impl, cptypes), 2)
self.check(test_impl, a, b, size)

def test_prange_optional(self):
def test_impl(arr, pred=None):
for i in prange(1):
if pred is not None:
arr[i] = 0.0

arr = np.ones(10)
self.check(test_impl, arr, None,
check_arg_equality=[np.testing.assert_almost_equal,
lambda x, y: x == y])
self.assertEqual(arr.sum(), 10.0)

def test_untraced_value_tuple(self):
# This is a test for issue #6478.
def test_impl():
Expand Down

0 comments on commit babbf9e

Please sign in to comment.