Created
May 3, 2017 03:17
-
-
Save kbroman/280f31f2b9f15907bba325c27acf1057 to your computer and use it in GitHub Desktop.
Rcpp problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [[Rcpp::depends(RcppEigen)]] | |
#include <RcppEigen.h> | |
using namespace Rcpp; | |
using namespace Eigen; | |
MatrixXd AtA(const MatrixXd A) { | |
int n = A.cols(); | |
return MatrixXd(n,n).setZero().selfadjointView<Lower>() | |
.rankUpdate(A.adjoint()); | |
} | |
// [[Rcpp::export]] | |
List cholAtA(const MatrixXd A) | |
{ | |
LLT<MatrixXd> llt = AtA(A); | |
return List::create(Named("L") = MatrixXd(llt.matrixL()), | |
Named("R") = MatrixXd(llt.matrixU())); | |
} | |
/*** R | |
A <- matrix(1:6, ncol=2) | |
storage.mode(A) <- "double" | |
fp <- cholAtA(A) | |
fp$L - t(chol(t(A) %*% A)) | |
fp$R - chol(t(A) %*% A) | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!> sourceCpp("eigen_cholAtA.cpp") | |
eigen_cholAtA.cpp:19:19: error: no viable conversion from 'MatrixXd' (aka 'Matrix<double, Dynamic, Dynamic>') to 'LLT<MatrixXd>' (aka 'LLT<Matrix<double, Dynamic, Dynamic> >') | |
LLT<MatrixXd> llt = AtA(A); | |
^ ~~~~~~ | |
/Users/kbroman/Rlibs/RcppEigen/include/Eigen/src/Cholesky/LLT.h:52:49: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'MatrixXd' \ | |
(aka 'Matrix<double, Dynamic, Dynamic>') to 'const Eigen::LLT<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 1> &' for 1st argument | |
template<typename _MatrixType, int _UpLo> class LLT | |
^ | |
1 error generated. | |
make: *** [eigen_cholAtA.o] Error 1 | |
ccache clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I"/Users/kbroman/Rlibs/Rcpp/include" -I"/Users/kbroman/Rlibs/RcppEigen/include" -I"/Users/kbroman/Co\ | |
de/RcppEx" -I/usr/local/include -fPIC -g -O2 -Wall -Wno-sign-conversion -Wno-unused -fcolor-diagnostics -pedantic -mtune=native -Qunused-arguments -stdlib=libc++ -Wsign-compare\ | |
-c eigen_cholAtA.cpp -o eigen_cholAtA.o | |
Error in sourceCpp("eigen_cholAtA.cpp") : | |
Error 1 occurred building shared library. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(Rcpp) | |
library(RcppEigen) | |
sourceCpp("eigencholAtA.cpp") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment