Beispiel #1
0
def test_SBMtoSparse1():
    from Siconos.Numerics import getValueSBM, newFromFileSBM, printSBM, SBMtoSparse
    from scipy.sparse.csr import csr_matrix

    SBM=newFromFileSBM('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
Beispiel #2
0
def test_SBMtoSparseToSBM():

    from Siconos.Numerics import getValueSBM, newFromFileSBM, printSBM, SBMtoSparse, sparseToSBM
    from scipy.sparse.csr import csr_matrix

    SBM1=newFromFileSBM('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