def map_product(self, expr): def is_scalar(expr): return isinstance(expr, (int, float, complex, sym.ScalarParameter)) from pytools import len_iterable nonscalar_count = len_iterable(ch for ch in expr.children if not is_scalar(ch)) if nonscalar_count > 1: # too complicated, don't touch it self.extra_operator_count += 1 return op.InverseMassOperator()(self.outer_mass_contractor(expr)) else: def do_map(expr): if is_scalar(expr): return expr else: return self.rec(expr) return expr.__class__( tuple(do_map(child) for child in expr.children))
def count_subset(subset): from pytools import len_iterable return len_iterable(uc for uc in subset if uc)