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

[lang] "ti.chain_compare" now can return python-scope constants #1356

Merged
Merged
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
11 changes: 4 additions & 7 deletions python/taichi/lang/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,10 @@ def subscript(value, *indices):
def chain_compare(comparators, ops):
assert len(comparators) == len(ops) + 1, \
f'Chain comparison invoked with {len(comparators)} comparators but {len(ops)} operators'
evaluated_comparators = []
for i in range(len(comparators)):
evaluated_comparators += [expr_init(comparators[i])]
ret = expr_init(True)
ret = True
for i in range(len(ops)):
lhs = evaluated_comparators[i]
rhs = evaluated_comparators[i + 1]
lhs = comparators[i]
rhs = comparators[i + 1]
if ops[i] == 'Lt':
now = lhs < rhs
elif ops[i] == 'LtE':
Expand All @@ -123,7 +120,7 @@ def chain_compare(comparators, ops):
now = lhs != rhs
else:
assert False, f'Unknown operator {ops[i]}'
ret = ret.logical_and(now)
ret = logical_and(ret, now)
return ret


Expand Down