From d1a356e7126720c1a357bfc30ff16c6844b9462b Mon Sep 17 00:00:00 2001 From: archibate <1931127624@qq.com> Date: Mon, 29 Jun 2020 10:05:55 +0800 Subject: [PATCH] [skip ci] revert ti.chain_compare --- python/taichi/lang/impl.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/python/taichi/lang/impl.py b/python/taichi/lang/impl.py index 32ebfc8998564..e7308597a21e8 100644 --- a/python/taichi/lang/impl.py +++ b/python/taichi/lang/impl.py @@ -102,10 +102,13 @@ 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' - ret = True + evaluated_comparators = [] + for i in range(len(comparators)): + evaluated_comparators += [expr_init(comparators[i])] + ret = expr_init(True) for i in range(len(ops)): - lhs = comparators[i] - rhs = comparators[i + 1] + lhs = evaluated_comparators[i] + rhs = evaluated_comparators[i + 1] if ops[i] == 'Lt': now = lhs < rhs elif ops[i] == 'LtE': @@ -120,7 +123,7 @@ def chain_compare(comparators, ops): now = lhs != rhs else: assert False, f'Unknown operator {ops[i]}' - ret = logical_and(ret, now) + ret = ret.logical_and(now) return ret