了解 Rcpp 插件
Understanding Rcpp plugins
我正在查看 3.6 of the Rcpp-FAQ 中提供的演示,我试图了解这个插件是如何创建的。提供的独立示例是
gslrng <-
'int seed = Rcpp::as<int>(par) ;
gsl_rng_env_setup();
gsl_rng *r = gsl_rng_alloc (gsl_rng_default);
gsl_rng_set (r, (unsigned long) seed);
double v = gsl_rng_get (r);
gsl_rng_free(r);return Rcpp::wrap(v);'
plug <- Rcpp:::Rcpp.plugin.maker(
include.before = "#include <gsl/gsl_rng.h>",
libs = paste("-L/usr/local/lib/R/site-library/Rcpp/lib -lRcpp",
"-Wl,-rpath,/usr/local/lib/R/site-library/Rcpp/lib",
"-L/usr/lib -lgsl -lgslcblas -lm"))
registerPlugin("gslDemo", plug )
fun <- cxxfunction(signature(par="numeric"), gslrng, plugin="gslDemo")
fun(0)
具体来说,为什么对 paste()
的调用是这样用逗号分隔的? 所有 依赖项(头文件目录、链接器目录和库文件的名称)是否应该通过插件处理?
paste()
是基础 R 的 paste()
的普通用法——它创建一个包含 all[=29 的 single 字符串=] link 指令被传递给 libs
。
对于 include.before
我们不需要它,因为只传递了一个 header。
我建议您研究代码 及其使用 以及 RcppGSL 的实际插件,定义为 here 并查看它们如何在 等包中使用,例如 RcppZiggurat
。我所说的使用是指在客户端包编译和 links 时查看指令扩展到什么。
它看起来非常复杂,但嘿,它已经工作了大约十年:)
我正在查看 3.6 of the Rcpp-FAQ 中提供的演示,我试图了解这个插件是如何创建的。提供的独立示例是
gslrng <-
'int seed = Rcpp::as<int>(par) ;
gsl_rng_env_setup();
gsl_rng *r = gsl_rng_alloc (gsl_rng_default);
gsl_rng_set (r, (unsigned long) seed);
double v = gsl_rng_get (r);
gsl_rng_free(r);return Rcpp::wrap(v);'
plug <- Rcpp:::Rcpp.plugin.maker(
include.before = "#include <gsl/gsl_rng.h>",
libs = paste("-L/usr/local/lib/R/site-library/Rcpp/lib -lRcpp",
"-Wl,-rpath,/usr/local/lib/R/site-library/Rcpp/lib",
"-L/usr/lib -lgsl -lgslcblas -lm"))
registerPlugin("gslDemo", plug )
fun <- cxxfunction(signature(par="numeric"), gslrng, plugin="gslDemo")
fun(0)
具体来说,为什么对 paste()
的调用是这样用逗号分隔的? 所有 依赖项(头文件目录、链接器目录和库文件的名称)是否应该通过插件处理?
paste()
是基础 R 的 paste()
的普通用法——它创建一个包含 all[=29 的 single 字符串=] link 指令被传递给 libs
。
对于 include.before
我们不需要它,因为只传递了一个 header。
我建议您研究代码 及其使用 以及 RcppGSL 的实际插件,定义为 here 并查看它们如何在 等包中使用,例如 RcppZiggurat
。我所说的使用是指在客户端包编译和 links 时查看指令扩展到什么。
它看起来非常复杂,但嘿,它已经工作了大约十年:)