def logical_and(self, other): """Return the new expression of computing logical and between self and a given operand. Args: other (Any): Given operand. Returns: :class:`~taichi.lang.expr.Expr`: The computing expression of logical and.""" _taichi_skip_traceback = 1 return ti.logical_and(self, other)
def chain_compare(comparators, ops): _taichi_skip_traceback = 1 assert len(comparators) == len(ops) + 1, \ f'Chain comparison invoked with {len(comparators)} comparators but {len(ops)} operators' ret = True for i in range(len(ops)): lhs = comparators[i] rhs = comparators[i + 1] if ops[i] == 'Lt': now = lhs < rhs elif ops[i] == 'LtE': now = lhs <= rhs elif ops[i] == 'Gt': now = lhs > rhs elif ops[i] == 'GtE': now = lhs >= rhs elif ops[i] == 'Eq': now = lhs == rhs elif ops[i] == 'NotEq': now = lhs != rhs else: assert False, f'Unknown operator {ops[i]}' ret = ti.logical_and(ret, now) return ret
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, } 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 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.logical_and(val, op(l, r)) node.ptr = val return node.ptr
def logical_and(self, other): import taichi as ti return ti.logical_and(self, other)
def logical_and(self, other): import taichi as ti _taichi_skip_traceback = 1 return ti.logical_and(self, other)
def logical_and(self, other): _taichi_skip_traceback = 1 return ti.logical_and(self, other)