Exemplo n.º 1
0
def test_SBMtoSparse1():
    from siconos.numerics import getValueSBM, newFromFileSBM, printSBM, SBMtoSparse
    from scipy.sparse.csr import csr_matrix

    SBM=newFromFileSBM(os.path.join(working_dir, 'data/SBM1.dat'))

    printSBM(SBM)

    r,A = SBMtoSparse(SBM)

    for i in range(A.shape[0]):
        for j in range(A.shape[1]):
            assert abs(A[i,j] - getValueSBM(SBM,i,j)) < eps
Exemplo n.º 2
0
def test_SBMtoSparseToSBM():

    from siconos.numerics import getValueSBM, newFromFileSBM, printSBM, SBMtoSparse, sparseToSBM
    from scipy.sparse.csr import csr_matrix

    SBM1=newFromFileSBM(os.path.join(working_dir, 'data/SBM1.dat'))

    printSBM(SBM1)

    r,SPARSE = SBMtoSparse(SBM1)

    v,SBM2 = sparseToSBM(3,SPARSE)

    printSBM(SBM2)

    assert SBM1.nbblocks == SBM2.nbblocks
    assert SBM1.blocknumber0 == SBM2.blocknumber0
    assert SBM1.blocknumber1 == SBM2.blocknumber1

    for i in range(SPARSE.shape[0]):
        for j in range(SPARSE.shape[1]):
            print(i,j, getValueSBM(SBM1,i,j), getValueSBM(SBM2,i,j))
            assert (getValueSBM(SBM1,i,j) - getValueSBM(SBM2,i,j)) < eps