0

我正在研究一个代表一些networkx图的邻接矩阵的numpy矩阵adj 。当我按如下方式构造adj时:

adj = sparse.csr_matrix(nx.adjacency_matrix(graph), dtype='longdouble').todense()

然后运行adj = adj ** 2,然后我可以看到htopnumpy 使用了所有可用的线程。

然而,由于精度损失,我试图mpmath在两者之间进行整合。

我是这样做的:

mp.dps = 120
adj = sparse.csr_matrix(nx.adjacency_matrix(graph), dtype='longdouble').todense()
# ... just like before
adjmp = mp.matrix(adj)
# this casts all values to mpf
adj = np.matrix(adjmp, dtype=object)
# and get back the np matrix, now with mpfs inside

生成的adj看起来像这样

matrix([[mpf('0.0'), mpf('0.0'), mpf('0.0'), ..., mpf('0.0'), mpf('0.0'),
     mpf('0.125')], #  [...]

这是我所期望的。

计算包括两个步骤:第一个是平方adj,第二个是实际计算。从结果中,我可以看到精度要高得多,但htop由于某种原因,平方步骤仅在一个线程上运行。

当我运行 np.show_config() 时,我得到:

blas_mkl_info:
  NOT AVAILABLE
blis_info:
  NOT AVAILABLE
openblas_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
blas_opt_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
lapack_mkl_info:
  NOT AVAILABLE
openblas_lapack_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
lapack_opt_info:
    libraries = ['openblas', 'openblas']
    library_dirs = ['/usr/local/lib']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
4

0 回答 0