def build_Compare(ctx, node): build_stmt(ctx, node.left) build_stmts(ctx, node.comparators) ops = { ast.Eq: lambda l, r: l == r, ast.NotEq: lambda l, r: l != r, ast.Lt: lambda l, r: l < r, ast.LtE: lambda l, r: l <= r, ast.Gt: lambda l, r: l > r, ast.GtE: lambda l, r: l >= r, } ops_static = { ast.In: lambda l, r: l in r, ast.NotIn: lambda l, r: l not in r, ast.Is: lambda l, r: l is r, ast.IsNot: lambda l, r: l is not r, } if ctx.is_in_static_scope(): ops = {**ops, **ops_static} operands = [node.left.ptr ] + [comparator.ptr for comparator in node.comparators] val = True for i, node_op in enumerate(node.ops): l = operands[i] r = operands[i + 1] op = ops.get(type(node_op)) if isinstance(node_op, (ast.Is, ast.IsNot)): name = "is" if isinstance(node_op, ast.Is) else "is not" warnings.warn_explicit( f'Operator "{name}" in Taichi scope is deprecated. Please avoid using it.', DeprecationWarning, ctx.file, node.lineno + ctx.lineno_offset) if op is None: if type(node_op) in ops_static: raise TaichiSyntaxError( f'"{type(node_op).__name__}" is only supported inside `ti.static`.' ) else: raise TaichiSyntaxError( f'"{type(node_op).__name__}" is not supported in Taichi kernels.' ) val = ti_ops.bit_and(val, op(l, r)) node.ptr = val return node.ptr
def __rand__(self, other): return ops.bit_and(other, self)
def __and__(self, other): return ops.bit_and(self, other)