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

Fix for #1308 #1313

Merged
merged 3 commits into from
Jul 12, 2023
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: 2 additions & 0 deletions dace/frontend/python/newast.py
Original file line number Diff line number Diff line change
Expand Up @@ -2352,6 +2352,8 @@ def _visit_test(self, node: ast.Expr):
# Visit test-condition
if not is_test_simple:
parsed_node = self.visit(node)
if isinstance(parsed_node, (list, tuple)) and len(parsed_node) == 1:
parsed_node = parsed_node[0]
if isinstance(parsed_node, str) and parsed_node in self.sdfg.arrays:
datadesc = self.sdfg.arrays[parsed_node]
if isinstance(datadesc, data.Array):
Expand Down
2 changes: 2 additions & 0 deletions dace/frontend/python/replacements.py
Original file line number Diff line number Diff line change
Expand Up @@ -4370,6 +4370,8 @@ def _datatype_converter(sdfg: SDFG, state: SDFGState, arg: UfuncInput, dtype: dt
'outputs': ['__out'],
'code': "__out = dace.{}(__inp)".format(dtype.to_string())
}
if dtype in (dace.bool, dace.bool_):
impl['code'] = "__out = dace.bool_(__inp)"
tasklet_params = _set_tasklet_params(impl, [arg])

# Visitor input only needed when `has_where == True`.
Expand Down
14 changes: 14 additions & 0 deletions tests/python_frontend/conditionals_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ def if_return_chain(i: dace.int64):
assert if_return_chain(15)[0] == 4


def test_if_test_call():

@dace.program
def if_test_call(a, b):
if bool(a):
return a
else:
return b

assert if_test_call(0, 2)[0] == if_test_call.f(0, 2)
assert if_test_call(1, 2)[0] == if_test_call.f(1, 2)


if __name__ == "__main__":
test_simple_if()
test_call_if()
Expand All @@ -169,3 +182,4 @@ def if_return_chain(i: dace.int64):
test_call_while()
test_if_return_both()
test_if_return_chain()
test_if_test_call()