1

I have a Rcpp code written with Armadillo. I would like to use the Eigen library to do the least square estimation with sparse matrix A in the equation Ax=b.

Question is how can I convert from an Armadillo sp_mat to an Eigen SparseMatrix and vice versa?

There is a similar question on How can I convert from an Armadillo Matrix to an Eigen MatrixXd and vice versa?

question link: Converting an Armadillo Matrix to an Eigen MatriXd and vice versa

EDIT mockup file

in the file mockup.cpp

#include <RcppArmadillo.h>
#include <RcppEigen.h>
#include <iostream>

// [[Rcpp::depends(RcppArmadillo, RcppEigen)]]

// the function logit is a demo in Rcpp
// [[Rcpp::export]]

List logit_(arma::sp_mat A, Eigen::SparseMatrix<double> B){

// arma documentation link: http://arma.sourceforge.net/docs.html#memptr
int numA = A.n_rows;
arma::sp_mat out_A;
out_A = A.t();

// eigen documentation link: http://eigen.tuxfamily.org/dox/group__QuickRefPage.html
int numB = B.rows();
Eigen::SparseMatrix<double> out_B;
out_B = B.transpose();

return List::create(Named("out_A") = out_A,Named("out_B") = out_B);

}

vtshen
  • 202
  • 1
  • 11
  • 1
    Not sure there is a clean solution here... Let me think about it. In the interim, why don't you mock up an example `sp_mat` and `SparseMatrixXd` – coatless Dec 22 '17 at 00:37
  • Also can't think of anything pre-cooked besides coming back to R's `dgCMatrix` and converting from there. – Dirk Eddelbuettel Dec 22 '17 at 15:17
  • Thanks a lot for taking time to help. I am going to rewrite the code with Eigen. – vtshen Dec 23 '17 at 06:03

0 Answers0