我通过cxxfunction使用RcppArmadillo。我想加载定义为C ++头文件的函数。这仅适用于cxx函数,但是当RcppArmadillo添加到混合中时则不行。下面给出了一个最小的工作示例。任何帮助将不胜感激!
##### My R script
rm(list=ls())
require("inline")
require("Rcpp")
require("RcppArmadillo")
X<-matrix(rnorm(9),3,3)
###works with RcppArmadillo
src1<-'Rcpp::NumericMatrix XR(XS);
arma::mat X(XR.begin(), XR.nrow(), XR.ncol(), false);
return Rcpp::List::create(Rcpp::Named("X")=X);
'
Cfunc1<-cxxfunction(sig=signature(XS="numeric"), body=src1, plugin="RcppArmadillo")
print(X)
print(Cfunc1(X))
###works with myFunc.h
settings <- getPlugin("Rcpp")
settings$env$PKG_CXXFLAGS <- paste("-I", getwd(), sep="")
src2<-'Rcpp::NumericMatrix XR(XS);
Rcpp::NumericMatrix XU=myFunc(XR);
return Rcpp::List::create(Rcpp::Named("X")=XU);
'
Cfunc2<-cxxfunction(sig=signature(XS="numeric"), body=src2, includes=c('#include "myFunc.h"'),settings=settings)
print(X)
print(Cfunc2(X))
###Does not work with RcppArmadillo and myFunc.h
src3<-'Rcpp::NumericMatrix XR(XS);
Rcpp::NumericMatrix XU=myFunc(XR);
arma::mat X(XU.begin(), XU.nrow(), XU.ncol(), false);
return Rcpp::List::create(Rcpp::Named("X")=X);
'
Cfunc3<-cxxfunction(sig=signature(XS="numeric"), body=src3, plugin="RcppArmadillo", includes=c('#include "myFunc.h"'),settings=settings)
print(X)
print(Cfunc3(X))
-
blog_tags.py