Beispiel #1
0
def test_genAllMatrixPermutations_4():
    # Test that dhe dst-keyword works as expected
    m = np.array([[1, 4, 7],
                  [2, 5, 8],
                  [3, 6, 9]])
    dst = np.zeros_like(m)
    normal_gen = graph.genAllMatrixPermutations(m)
    dst_gen = graph.genAllMatrixPermutations(m, dst)
    for ng, dg in zip(normal_gen, dst_gen):
        assert ng[0] == dg[0]
        assert np.allclose(ng[1], dst)
Beispiel #2
0
def test_genAllMatrixPermutations_2():
    m = np.array([[1, 4, 7],
                  [2, 5, 8],
                  [3, 6, 9]])
    perms = list(graph.genAllMatrixPermutations(m))
    # Ensure that the original matrix is included in the permutations
    assert np.any([np.allclose(m, p[1]) for p in perms])
Beispiel #3
0
def test_genAllMatrixPermutations_3():
    m = np.array([[1, 4, 7],
                  [2, 5, 8],
                  [3, 6, 9]])
    perms = list(graph.genAllMatrixPermutations(m))
    for perm, mat in perms:
        if perm == (1, 0, 2):
            m_expected = np.array([[5, 2, 8],
                                   [4, 1, 7],
                                   [6, 3, 9]])
            assert np.allclose(mat, m_expected)
        elif perm == (0, 2, 1):
            m_expected = np.array([[1, 7, 4],
                                   [3, 9, 6],
                                   [2, 8, 5]])
            assert np.allclose(mat, m_expected)
        elif perm == (2, 1, 0):
            m_expected = np.array([[9, 6, 3],
                                   [8, 5, 2],
                                   [7, 4, 1]])
            assert np.allclose(mat, m_expected)
Beispiel #4
0
def test_genAllMatrixPermutations_5():
    m = np.arange(6).reshape((2, 3))
    with pytest.raises(ValueError):
        list(graph.genAllMatrixPermutations(m))
Beispiel #5
0
def test_genAllMatrixPermutations_1():
    m = np.array([[1, 4, 7],
                  [2, 5, 8],
                  [3, 6, 9]])
    perms = list(graph.genAllMatrixPermutations(m))
    assert len(perms) == np.math.factorial(m.shape[0])
Beispiel #6
0
import platform
import sys
import os
if platform.system() == 'Darwin':
    pth = '/Users/allan/scriptsMount'
elif platform.system() == 'Linux':
    pth = '/lscr_paper/allan/scripts'
else:
    raise OSError('Could not identify system "{}"'.format(platform.system()))
if not os.path.isdir(pth):
    raise FileNotFoundError(f"Could not find the file {pth}")
sys.path.append(pth)

from speclib.graph import genAllMatrixPermutations
import numpy as np


a = np.arange(16).reshape((4, -1))
ac = np.zeros_like(a)
af = a.flatten()
b = np.random.randint(0, 10, (4, 4))
bc = np.zeros_like(b)
bf = b.flatten()

gena = genAllMatrixPermutations(a, ac)
print(sorted([(ac.flatten() * bf).sum() for pa in gena]))

genb = genAllMatrixPermutations(b, bc)
print(sorted([(bc.flatten() * af).sum() for pb in genb]))