def broadcast_collect(expr, broadcastable=Broadcastable, want_to_broadcast=WantToBroadcast, no_recurse=None):
 if (isinstance(expr, want_to_broadcast) and iscollection(expr.dshape)):
  leaves = leaves_of_type(broadcastable, expr)
  expr = broadcast(expr, sorted(leaves, key=str))
 if ((no_recurse is not None) and isinstance(expr, no_recurse)):
  return expr
 children = (broadcast_collect(i, broadcastable, want_to_broadcast, no_recurse) for i in expr._inputs)
 return expr._subs({e: c for (e, c) in zip(expr._inputs, children)})

def broadcast_collect ( expr , broadcastable = Broadcastable , want_to_broadcast = WantToBroadcast , no_recurse = None ) : if ( isinstance ( expr , want_to_broadcast ) and iscollection ( expr . dshape ) ) : leaves = leaves_of_type ( broadcastable , expr ) expr = broadcast ( expr , sorted ( leaves , key = str ) ) if ( ( no_recurse is not None ) and isinstance ( expr , no_recurse ) ) : return expr children = ( broadcast_collect ( i , broadcastable , want_to_broadcast , no_recurse ) for i in expr . _inputs ) return expr . _subs ( { e : c for ( e , c ) in zip ( expr . _inputs , children ) } )
collapse expression down using broadcast - tabular cases only expressions of type broadcastables are swallowed into broadcast operations .