Exemplo n.º 1
0
def sparse_tests(spm):
    print('in sparse_tests')
    #    sp_formats = ('bsr', 'coo', 'csc', 'csr', 'dia', 'dok', 'lil')
    sp_formats = ('bsr', 'coo', 'csc', 'csr', 'dia', 'lil')
    spm.check_format(True)

    spm_shape = spm.shape
    nm = sn.NumericsMatrix(spm)
    assert nm is not None
    check_size((nm.size0, nm.size1), spm_shape)

    for fmt in sp_formats:
        func = getattr(scipy.sparse, fmt + '_matrix')
        mm = func(spm)
        if fmt in ('csc', 'csr'):
            mm.check_format(True)
        elif fmt == 'coo':
            mm._check()

        nm = sn.NumericsMatrix(mm)
        check_size((nm.size0, nm.size1), spm_shape)
        assert nm is not None
        t1 = sn.NM_triplet(nm)
        t1._check()
        check_size(t1.shape, spm_shape)
        assert ((spm - t1).nnz == 0)

        t2 = sn.NM_csc(nm)
        t2.check_format(True)
        check_size(t2.shape, spm_shape)
        assert ((spm - t2).nnz == 0)

        t2bis = sn.NM_csc_trans(nm)
        t2bis.check_format(True)
        check_size(t2bis.T.shape, spm_shape)
        assert ((spm.T - t2bis).nnz == 0)

        t3 = sn.NM_triplet(mm)
        t3._check()
        check_size(t3.shape, spm_shape)
        assert ((spm - t3).nnz == 0)

        t4 = sn.NM_csc(mm)
        t4.check_format(True)
        check_size(t4.shape, spm_shape)
        assert ((spm - t4).nnz == 0)

        t4bis = sn.NM_csc_trans(mm)
        t4bis.check_format(True)
        check_size(t4bis.T.shape, spm_shape)
        assert ((spm.T - t4bis).nnz == 0)
Exemplo n.º 2
0
def test_nm_mumps():

    # this may be run with mpirun -np <nb processes>
    from siconos import numerics
    from mpi4py import MPI
    import scipy.sparse
    import numpy

    comm = MPI.COMM_WORLD

    # build an empty sparse matrix
    M = numerics.NumericsMatrix(scipy.sparse.eye(0))

    numerics.NM_MPI_set_comm(M, comm)
    numerics.NM_MUMPS_set_control_params(M)

    # start parallel MUMPS, processes with rank > 0 execute NM_MUMPS(M, -1)
    # then all next NM_MUMPS(M, x) with x!=0 then return when process with
    # rank 0 executes NM_MUMPS(M, 0)
    numerics.NM_MUMPS(M, -1)

    if (comm.Get_rank() > 0):
        # when rank 0 executes NM_MUMPS(M, 0)
        exit(0)

    # only on rank 0:

    # fill the matrix
    #     2*x - y = 1
    #     x   + y = 1
    # solution x: 2/3, y: 1/3 */
    numerics.NM_entry(M, 0, 0, 2.)
    numerics.NM_entry(M, 0, 1, -1.)
    numerics.NM_entry(M, 1, 0, 1.)
    numerics.NM_entry(M, 1, 1, 1.)

    b = numpy.array([1.0, 1.0])
    numerics.NM_MUMPS_set_matrix(M)
    numerics.NM_MUMPS_set_dense_rhs(M, 1, b)

    # analysis, factorization, solve.
    numerics.NM_MUMPS(M, 6)

    # end of the work with this matrix
    numerics.NM_MUMPS(M, -2)

    # send end of listening for ranks > 0
    numerics.NM_MUMPS(M, 0)

    print('solution:', b)

    assert (abs(b[0] - 2. / 3.) < 1e-7)
    assert (abs(b[1] - 1. / 3.) < 1e-7)
Exemplo n.º 3
0
def SBM_tests(sbm):
    print('in SBM_tests')
    # SBM_to_dense
    # SBM_to_sparse
    # SBM_from_csparse
    nm = sn.NumericsMatrix(sbm)
    assert nm is not None
    mcoo = sn.NM_triplet(nm)
    mcoo._check()
    check_size((nm.size0, nm.size1), mcoo.shape)
    compare_with_SBM(sbm, mcoo)

    mcsc = sn.NM_csc(nm)
    mcsc.check_format(True)
    check_size((nm.size0, nm.size1), mcsc.shape)
    compare_with_SBM(sbm, mcsc)

    mcsc_trans = sn.NM_csc_trans(nm)
    mcsc_trans.check_format(True)
    check_size((nm.size0, nm.size1), mcsc_trans.T.shape)
    compare_with_SBM(sbm, mcsc_trans.T)

    return copy.deepcopy(mcsc)
Exemplo n.º 4
0
def dense_tests(mdense):
    print('in dense_tests')
    nm = sn.NumericsMatrix(mdense)
    check_size((nm.size0, nm.size1), mdense.shape)
    assert nm is not None