Converting between NumericVector/Matrix and VectorXd/MatrixXd in Rcpp(Eigen) to perform Cholesky solve

冷暖自知 提交于 2019-12-06 00:25:26

Look at the RcppEigen sources and the files src/fastLm.h and src/fastLm.cpp.

They set up a really nice factory over a number of different decomposition methods. Note how for each of the implemented solvers, the results is always the protected VectorXd m_coef (ie an Eigen type) which gets converted only at the very end:

        // Copy coefficients and install names, if any
NumericVector     coef(wrap(ans.coef()));
List          dimnames(NumericMatrix(Xs).attr("dimnames"));

It is quite conceivable that we could have done this differently -- but this example has been working fine for quite some time. I would just follow it.

The Choleski Decomposition is implemented in base. Here is the link to the documentation. If I'm misunderstanding, then perhaps you can write one yourself? Check this Rosetta Code link for Choleski decomposition in several languages to give you ideas.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!