I want to pass a large matrix to a RcppArmadillo function (about 30,000*30,000) and have the feeling that this passing alone eats up all the performance gains. The question was also raised here with the suggested to solution to use advanced constructors with the copy_aux_mem = false
argument. This seems to be a good solution also because I only need to read rows from the matrix without changing anything. I am having problems implementing the solution correctly though. This is probably just a simply syntax question.
Here is my current set-up of the function call (simplified, of course):
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
arma::vec test(arma::mat M) {
return(M.row(0))
}
this is pretty slow with large a matrix M (e.g. M=matrix(rnorm(30000*30000), nrow=30000, ncol=30000)
. So I would like to use an advanced constructor as documented here. The syntax is mat(aux_mem*, n_rows, n_cols, copy_aux_mem = true, strict = true)
and copy_aux_mem
should be set to false
to 'pass-by-reference'. I just not sure about the syntax in the function definition. How do I use this in arma::vec test(arma::mat M) {
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…