celestialgod

Rcpp call F77 BLAS/LAPACK (eigen_sym_cpp.cpp)

Jan 1st, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <Rcpp.h>
  2. #include <R_ext/Lapack.h>
  3. #include <R_ext/BLAS.h>
  4.  
  5. //[[Rcpp::export]]
  6. Rcpp::List eigen_sym_cpp(Rcpp::NumericMatrix X, int num_eig = -1, bool eigenvalues_only = false, double tol = 1.5e-8)
  7. {
  8.   Rcpp::NumericMatrix A = Rcpp::clone(X); // perform deep copy of input
  9.   char jobz = eigenvalues_only?'N':'V', range = (num_eig == -1)?'A':'I', uplo = 'U';
  10.   int N = A.nrow(), lda = std::max(1, N), il = 1, iu = (num_eig == -1)?N:num_eig;
  11.   int m = (range == 'A')?N:(iu-il+1), ldz = std::max(1, N), lwork = std::max(1, 26*N), liwork = std::max(1, 10*N), info = 0;
  12.   double abstol = tol, vl = 0.0, vu = 0.0;
  13.   Rcpp::IntegerVector isuppz(2 * std::max(1, m)), iwork(std::max(1, lwork));
  14.   Rcpp::NumericVector work(std::max(1, lwork)), W(N);
  15.   Rcpp::NumericMatrix Z(ldz, std::max(1, m));
  16.   F77_CALL(dsyevr)(&jobz, &range, &uplo, &N, A.begin(), &lda, &vl, &vu, &il, &iu, &abstol,
  17.            &m, W.begin(), Z.begin(), &ldz, isuppz.begin(), work.begin(), &lwork, iwork.begin(), &liwork, &info);
  18.   return Rcpp::List::create(Rcpp::Named("info") = info,
  19.                             Rcpp::Named("vectors") = Z,
  20.                             Rcpp::Named("values") = W);
  21. }
Add Comment
Please, Sign In to add comment