def permutes_to(tgt_shape):
    """
    Generates all the possible `(axes, src_shape)` pairs for which
    `x.transpose(axes).shape == tgt_shape`, where `x.shape == src_shape`.
    """
    for axes in permutations(range(len(tgt_shape))):
        src_shape = [-1] * len(tgt_shape)
        for i, j in enumerate(axes):
            src_shape[j] = tgt_shape[i]
        yield (axes, tuple(src_shape))

    Generates all the possible `(axes, src_shape)` pairs for which
    `x.transpose(axes).shape == tgt_shape`, where `x.shape == src_shape`.
    
tests/integration/utils/generators.py