Ejemplo n.º 1
0
def testD():
    odds, evens = 0, 0
    for p in itertools.permutations(range(6)):
        a = list(p)
        result = toCycles(a)
        parity = cycle_parity(a)
        print(a, result, cycle_parity(a))
        if parity == 1:
            evens += 1
        elif parity == -1:
            odds += 1
        else:
            assert False
    assert evens == odds
Ejemplo n.º 2
0
def evaluate_point(T, W, d):
    Q = sla.splu(T)
    det = np.prod(Q.U.diagonal()) * cycle_parity(Q.perm_r) * cycle_parity(
        Q.perm_c)

    if np.abs(det) >= 1e-6:
        X = Q.solve(W)
        WW = T.dot(X)

        assert np.allclose(WW, W)

        F = d.T.dot(X)
        D = det
        N = F * D
        return (D, N)
    else:
        return (None, None)
Ejemplo n.º 3
0
def testA():
    a = [1, 0]
    result = toCycles(a)
    assert len(result) == 1
    print(result)
    assert cycle_parity(a) == -1
Ejemplo n.º 4
0
def testC():
    a = [0, 2, 1]
    result = toCycles(a)
    assert len(result) == 2
    print(result)
    assert cycle_parity(a) == -1