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

parallel=True to use better builtin mechanism to resolve call types. Resolves issue #3671 #3712

Merged
merged 3 commits into from
Jan 30, 2019
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
19 changes: 0 additions & 19 deletions numba/ir_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,25 +256,6 @@ def mk_loop_header(typemap, phi_var, calltypes, scope, loc):
return header_block


def find_op_typ(op, arg_typs):
for ft in typing.templates.builtin_registry.functions:
if ft.key == op:
try:
func_typ = types.Function(ft).get_call_type(typing.Context(),
arg_typs, {})
except TypingError:
func_typ = None
if func_typ is not None:
return func_typ
else:
for f, ft in typing.templates.builtin_registry.globals:
if f == op:
return ft.get_call_type(typing.Context(),
arg_typs, {})

raise RuntimeError("unknown array operation")


def legalize_names(varnames):
"""returns a dictionary for conversion of variable names to legal
parameter names.
Expand Down
5 changes: 2 additions & 3 deletions numba/parfor.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
get_np_ufunc_typ,
mk_range_block,
mk_loop_header,
find_op_typ,
get_name_var_table,
replace_vars,
replace_vars_inner,
Expand Down Expand Up @@ -2537,13 +2536,13 @@ def _arrayexpr_tree_to_ir(
el_typ1 = typemap[arg_vars[0].name]
if len(arg_vars) == 2:
el_typ2 = typemap[arg_vars[1].name]
func_typ = find_op_typ(op, [el_typ1, el_typ2])
func_typ = typingctx.resolve_function_type(op, (el_typ1, el_typ), {})
ir_expr = ir.Expr.binop(op, arg_vars[0], arg_vars[1], loc)
if op == operator.truediv:
func_typ, ir_expr = _gen_np_divide(
arg_vars[0], arg_vars[1], out_ir, typemap)
else:
func_typ = find_op_typ(op, [el_typ1])
func_typ = typingctx.resolve_function_type(op, (el_typ1,), {})
ir_expr = ir.Expr.unary(op, arg_vars[0], loc)
calltypes[ir_expr] = func_typ
el_typ = func_typ.return_type
Expand Down
4 changes: 2 additions & 2 deletions numba/stencilparfor.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,8 @@ def _add_index_offsets(self, index_list, index_offsets, new_body,
self.typemap[index_var.name] = types.intp
index_call = ir.Expr.binop(operator.add, old_index_var,
offset_var, loc)
self.calltypes[index_call] = ir_utils.find_op_typ(operator.add,
[types.intp, types.intp])
self.calltypes[index_call] = self.typingctx.resolve_function_type(
operator.add, (types.intp, types.intp), {})
index_assign = ir.Assign(index_call, index_var, loc)
out_nodes.append(index_assign)
index_vars.append(index_var)
Expand Down
12 changes: 12 additions & 0 deletions numba/tests/test_parfors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1378,6 +1378,18 @@ def test_impl(X):

self.check(test_impl, np.random.ranf(128))

@skip_unsupported
def test_array_compare_scalar(self):
""" issue3671: X != 0 becomes an arrayexpr with operator.ne.
That is turned into a parfor by devectorizing. Make sure
the return type of the devectorized operator.ne
on integer types works properly.
"""
def test_impl():
X = np.zeros(10, dtype=np.int_)
return X != 0

self.check(test_impl)

class TestPrangeBase(TestParforsBase):

Expand Down