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 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)