Beispiel #1
0
def alignment_permutation(target, *source):
    """
    Returns the list of permutations that would permute the elements in source to base.

    Assumes that target and all elements of source are permutations of each other.

    Args:
        target: sequence
        source: sequence of sequences

    Returns: [Permutation]
        The sequence of permutations
    """

    # base permutation
    p_base = Permutation.from_sequence(target)

    # perms = []
    # for seq in source:
    #     p_seq = Permutation.from_sequence(seq)
    #     perms.append(p_base*~p_seq)

    # to reorder seq to target we do:
    # 1. inv seq-permutation: will permute to 'normal' ordering
    # 2. p_base permutation: will permute from 'normal' ordering to target ordering
    return [p_base * ~Permutation.from_sequence(seq) for seq in source]
Beispiel #2
0
def radixPermutation(factors, n):
    a = radixReverse(factors, n)
    tps = []
    vectorizable = True
    for c in Permutation.from_sequence(a).cyclic_form:
        if (len(c) > 2):
            vectorizable = False
        for i in range(len(c) - 1, 0, -1):
            # 2 because those are indexes in an array of complex numbers but
            # with a real type.
            tps.append([2 * c[i], 2 * c[i - 1]])

    return (np.array(tps, dtype=int).flatten(), vectorizable)