I want to use arma::mat for my list of matrices.
Converting R matrix to arma::mat is working well with const.
But when i use List with matrices as an arguments, It takes very long time.
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
using namespace Rcpp;
using namespace arma;
// [[Rcpp::export]]
int check1(List X)
{
int i;
for (i = 0; i < 10; i ++)
arma::mat y = as<arma::mat>(X[i]);
return 0;
}
// [[Rcpp::export]]
int check2(const List& X)
{
int i;
for (i = 0; i < 10; i ++)
arma::mat y = as<arma::mat>(X[i]);
return 0;
}
// [[Rcpp::export]]
int check3(List X)
{
int i;
for (i = 0; i < 10; i ++)
NumericMatrix y = X[i];
return 0;
}
matlist = lapply(1:10, function(x) matrix(rnorm(10000), 2000, 50))
microbenchmark::microbenchmark(
arma = check1(matlist),
carma = check2(matlist),
nm = check3(matlist)
)
Unit: microseconds
expr min lq mean median uq max neval
arma 558.081 597.6485 622.13757 614.702 625.928 1303.494 100
carma 551.950 600.4425 658.33583 612.761 626.683 1749.153 100
nm 2.288 4.3590 5.57801 5.123 5.901 39.743 100