要找到稀疏矩阵“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。
知道怎么做吗?提前谢谢你的帮助。