예제 #1
0
def test_basis(gc):
    def test_vects():
        for i in range(24):
            yield gc.basis[i]
        for i in range(80):
            yield randint(0, 0xffffff)

    for v in test_vects():
        ve = gc.vect_to_vintern(v)
        assert ve == bit_mat_mul(v, gc.recip_basis), map(hex, [i, v, ve])
        ved = gc.vintern_to_vect(ve)
        assert ved == bit_mat_mul(ve, gc.basis), map(hex, [i, v, ve, ved])
        assert ved == v, map(hex, [i, v, ve, ved])
예제 #2
0
    @classmethod
    def perm_to_matrix(cls, p1):
        """Convert a permutation p1 in  Mat24 to a matrix.

        The matrix is a 12 x 12 bit matrix acting on the Golay code
        vectors by right multiplication.

        Permutation p is not checked to be a member of the Mathieu group.
        """
        mat = [cls.recip_basis[p1[i]] >> 12 for i in range(24)]
예제 #3
0
def test_orthogonal_complement():
    for a, ncols in orthogonal_complement_testcases():
        ra = bit_mat_rank(a)
        ao = bit_mat_orthogonal_complement(a, ncols)
        prod = bit_mat_mul(a, bit_mat_transpose(ao))
        assert bit_mat_iszero(prod), (a, ncols, ao)
        rao = bit_mat_rank(ao)
        if ncols:
            assert ra + rao == ncols, (ra, rao, ncols, a, ao)
    print("Test of othogonal complement computation passed")
예제 #4
0
def test_bitmatrix_mul_inv(verbose = 0):
    for ntest, (m1, m2, m2i) in enumerate(create_mul_inv_matrices()):
         #print(m1, m2, m2i)
         m1a = np.array(m1, dtype = np.uint64, copy = True)
         m2a = np.array(m2, dtype = np.uint64, copy = True)
         m3 =  bit_mat_mul(m1, m2)
         m3a = bitmatrix64_mul(m1a, m2a)
         assert list(m3a) == m3
         if m2i is not None:
            m2ia = bitmatrix64_inv(m2)
            assert list(m2ia) == m2i 
예제 #5
0
def test_inverse():
    print("Testing matrix inversion ...")
    MAXDIM_INVERSE_TEST = 20
    NSIGMA = 4.0
    elementary_testcases = [([3, 2], [3, 2]), ([2, 4, 1], [4, 1, 2])]
    for a, b in elementary_testcases:
        assert bit_mat_inverse(a) == b
        if a != b: assert bit_mat_inverse(b) == a

    n_cases = [0] * (MAXDIM_INVERSE_TEST + 1)
    n_ok = [0.0] * (MAXDIM_INVERSE_TEST + 1)
    for a in inverse_testcases():
        ok, n = False, len(a)
        if n > MAXDIM_INVERSE_TEST:
            continue
        n_cases[n] += 1
        try:
            inv = bit_mat_inverse(a)
            ok = True
            n_ok[n] += 1
        except:
            pass
        if ok:
            unit = [1 << i for i in range(n)]
            prod = bit_mat_mul(a, inv)
            assert prod == unit, (lmap(hex, a), lmap(hex,
                                                     inv), lmap(hex, prod))
    cases_displayed = [10]
    for n in range(1, MAXDIM_INVERSE_TEST):
        if n_cases[n] > 10:
            import math
            N, N_ok = n_cases[n], n_ok[n]
            p = 1.0
            for i in range(1, n + 1):
                p *= 1.0 - 0.5**i
            mu = N * p
            sigma = math.sqrt(N * p * (1.0 - p))
            if n in cases_displayed:
                print(
                    "Dim. %d, %d cases, ratio of invertibles: %.3f, expected: %.3f+-%.3f"
                    % (n, N, N_ok / N, p, sigma / N))
            assert abs(mu - N_ok) < NSIGMA * sigma, (n, p, mu, sigma, N, N_ok)
    print("Matrix inversion test passed")