Last active
March 13, 2018 11:44
-
-
Save pati-ni/f253e36e3ed681894c5ebe04fd962d49 to your computer and use it in GitHub Desktop.
Rcpp with armadillo
This file contains 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
// advanced constructor | |
// mat(ptr_aux_mem, n_rows, n_cols, copy_aux_mem = true, strict = false) | |
#include <RcppArmadillo.h> | |
#include <Rcpp.h> | |
// Pass by reference, readonly | |
arma::mat testmx( const arma::mat& dat) | |
{ | |
return dat; | |
} | |
// Pass by reference, can be modified | |
arma::mat testmx2(arma::mat& dat) | |
{ | |
return dat; | |
} |
This file contains 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
arma::mat testmx(const arma::mat& dat); | |
RcppExport SEXP _testmx(SEXP datSEXP) { | |
BEGIN_RCPP | |
Rcpp::RObject rcpp_result_gen; | |
Rcpp::RNGScope rcpp_rngScope_gen; | |
Rcpp::traits::input_parameter< const arma::mat& >::type dat(datSEXP); | |
rcpp_result_gen = Rcpp::wrap(testmx(dat)); | |
return rcpp_result_gen; | |
END_RCPP | |
} | |
arma::mat testmx2(arma::mat& dat); | |
RcppExport SEXP _testmx2(SEXP datSEXP) { | |
BEGIN_RCPP | |
Rcpp::RObject rcpp_result_gen; | |
Rcpp::RNGScope rcpp_rngScope_gen; | |
Rcpp::traits::input_parameter< arma::mat& >::type dat(datSEXP); | |
rcpp_result_gen = Rcpp::wrap(testmx2(dat)); | |
return rcpp_result_gen; | |
END_RCPP | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rcpp takes care of the memory management by wrapping the arrays accordingly.