1

要找到稀疏矩阵“A”的 10 个最小特征值,下面的最小代码效果很好:

g++ -std=c++17  -o test_sparse.o -c test_sparse.cpp
g++ -std=c++17  -o myapp test_sparse.o -larmadillo -larpack
#include <armadillo>
#include <iostream>
int main(){
    arma::SpMat<double> A = arma::sprandu(100,100,0.1) ;
    A = A.t()*A ;
    arma::dvec e = arma::eigs_sym(A,10,"sm") ;
    std::cout << e ; 
    return 0 ;
}

但是当我将 A 更改为复杂的稀疏矩阵时,例如:

#include <armadillo>
#include <iostream>
#include <complex>
int main(){
    arma::SpMat<arma::cx_double> A = arma::sprandu<arma::SpMat<arma::cx_double>>(100,100,0.1) ;
    A = A.t()*A ;
    arma::dvec e = arma::eigs_sym(A,1,"sm") ;
    std::cout << e ; 
    return 0 ;
}

使用相同的编译标志,我得到以下没有匹配的函数错误:

g++ -std=c++17  -o test_sparse.o -c test_sparse.cpp
test_sparse.cpp:8:43: error: no matching function for call to ‘eigs_sym(arma::SpMat<std::complex<double> >&, int, const char [3])’
    8 |     arma::dvec e = arma::eigs_sym(A,1,"sm") ;                    ^
make: *** [Makefile:47: test_sparse.o] Error 1

我从http://arma.sourceforge.net/docs.html#config_hpp知道

ARMA_USE_ARPACK 启用 ARPACK 或 ARPACK 的高速替代。犰狳需要 ARPACK 用于复杂稀疏矩阵的特征分解,即。eigs_gen()、eigs_sym() 和 svds()

所以我更改了 config.hpp 文件,这是我config.hpp文件中的相应行:

#if !defined(ARMA_USE_NEWARP)
#define ARMA_USE_NEWARP
#endif
#if !defined(ARMA_USE_ARPACK)
#define ARMA_USE_ARPACK
#endif
#if !defined(ARMA_USE_SUPERLU)
#define ARMA_USE_SUPERLU
#endif

更多信息:我可以毫无问题地从 gfortran 运行 arpack。

知道怎么做吗?提前谢谢你的帮助。

4

1 回答 1

0

这是库的固​​有限制。根据文档(强调我的):

eigs_sym 稀疏对称矩阵的特征值和特征向量数量有限

eigs_gen 稀疏通用方阵的特征值和特征向量数量有限

您应该使用eigs_genwhich 允许复杂的矩阵。或者您应该将矩阵转换为密集矩阵并使用eig_sym.

于 2020-08-20T10:43:35.690 回答