Armadillo eigs_sym(A,k) 用于复杂的稀疏矩阵 A
Armadillo eigs_sym(A,k) for complex sparse matrix A
要找到稀疏矩阵的 10 个最小特征值 'A',下面的最小代码效果很好:
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 Enable use of ARPACK, or a high-speed replacement for ARPACK. Armadillo requires ARPACK for the eigen decomposition of complex sparse matrices, ie. eigs_gen(), eigs_sym() and 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 没有问题。
知道怎么做吗?
提前感谢您的帮助。
这是库的固有限制。根据 documentation(强调我的):
eigs_sym limited number of eigenvalues & eigenvectors of sparse
symmetric real matrix
eigs_gen limited number of eigenvalues &
eigenvectors of sparse general square matrix
要找到稀疏矩阵的 10 个最小特征值 'A',下面的最小代码效果很好:
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 Enable use of ARPACK, or a high-speed replacement for ARPACK. Armadillo requires ARPACK for the eigen decomposition of complex sparse matrices, ie. eigs_gen(), eigs_sym() and 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 没有问题。
知道怎么做吗? 提前感谢您的帮助。
这是库的固有限制。根据 documentation(强调我的):
eigs_sym limited number of eigenvalues & eigenvectors of sparse symmetric real matrix
eigs_gen limited number of eigenvalues & eigenvectors of sparse general square matrix