英文:
How to install the "FastAD" C++ library in Rcpp?
问题
我正在尝试在Rcpp中安装一个名为FastAD的C++库(https://github.com/JamesYang007/FastAD#user-guide),但安装说明是通用的(不是专门为Rcpp而写的)。
如果有人能为我提供如何安装并能够#include文件的指导,将不胜感激。
英文:
I am trying to install a C++ library called FastAD ( https://github.com/JamesYang007/FastAD#user-guide) in Rcpp but the installation instructions are generic (not specifically for Rcpp).
It would be greatly appreciated if someone coule give me some guidance for how to install and be able to #include the files?
答案1
得分: 2
FastAD是一个仅依赖于Eigen3的头文件库。这使得它非常适合用于Rcpp和相关工具的应用。
首先,依赖于RcppEigen.package.skeleton()
函数来创建一个最基本的RcppEigen包。
其次,我们将FastAD库复制到inst/include
目录下。我们在src/Makevars
文件中添加了一个PKG_CPPFLAGS
变量,以通知R从那里引用它。对于仅包含头文件的库来说,这就是编译器所需的一切。(编辑:除非你使用的编译器或R版本足够新,已经默认使用C++17,否则我们还会设置CXX_STD=CXX17
。)
第三,我们在src/
目录中创建了一个简单的示例,基于FastAD中的示例。我们选择了Black-Scholes示例。
第四,进行一些次要的清理工作,比如删除hello*
文件。
基本上就是这样。该包目前处于初级形态,可以在GitHub上找到。示例代码如下:
> library(RcppFastAD)
> blackScholesExamples()
56.5136
0.773818
51.4109
-0.226182
>
英文:
FastAD is a header-only library which only depends on Eigen3. That makes for a pretty straightforward application for Rcpp and friends.
First, rely on the RcppEigen.package.skeleton()
function to create the barebones RcppEigen-using package.
Second, we copy the FastAD library into inst/include
. We add a PKG_CPPFLAGS
variable in src/Makevars
to let R know to source it from there. That is all the compiler needs with a header-only library. (Edit: We also set CXX_STD=CXX17
unless one has a new enough compiler or R (currently: r-devel) which already default to C++17.)
Third, we create a simple example in src/
based on an example in FastAD. We picked the Black-Scholes example.
Fourth, minor cleanups like removing the hello*
stanza files.
That is pretty much it. In its embryonic form the package is now here on GitHub. An example is
> library(RcppFastAD)
> blackScholesExamples()
56.5136
0.773818
51.4109
-0.226182
>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论