def broadcasts_to(tgt_shape):
    """
    Generates all shapes that broadcast to `tgt_shape`.
    """
    for mask in product([True, False], repeat=len(tgt_shape)):
        yield tuple(d if keep else 1 for (d, keep) in zip(tgt_shape, mask))

    Generates all shapes that broadcast to `tgt_shape`.
    
tests/integration/utils/generators.py