Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // [[Rcpp::depends(RcppArmadillo)]]
- #include <RcppArmadillo.h>
- arma::vec f(const arma::vec& x){
- return sin(x);
- }
- typedef arma::vec (*funcPtr)(const arma::vec& x);
- // [[Rcpp::export]]
- Rcpp::XPtr<funcPtr> ptr2f(){
- return Rcpp::XPtr<funcPtr>(new funcPtr(&f));
- }
- // [[Rcpp::export]]
- arma::vec callXPtr(const arma::vec& x, Rcpp::XPtr<funcPtr> xpfun) {
- funcPtr func = *xpfun;
- arma::vec y = func(x);
- return (y);
- }
- /*** R
- f <- ptr2f()
- callXPtr(1:10, f)
- */
Advertisement
Add Comment
Please, Sign In to add comment