Skip to content

Commit 0ee5e1e

Browse files
committed
add utility for pre-compiling 'RcppNT2.h'
1 parent bb5db54 commit 0ee5e1e

File tree

5 files changed

+63
-2
lines changed

5 files changed

+63
-2
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
export(precompileRcppNT2)

R/plugin.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
inlineCxxPlugin <- function() {
33
list(
44
env = list(
5-
PKG_CXXFLAGS = paste("$(CXX1XSTD)")
5+
PKG_CXXFLAGS = paste(
6+
"$(CXX1XSTD)",
7+
"-include", system.file("include/RcppNT2.h", package = "RcppNT2")
8+
)
69
),
710
includes = "#include <RcppNt2.h>"
811
)

R/precompiled-headers.R

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#' Pre-compile the RcppNT2 header
2+
#'
3+
#' Pre-compiles the \code{RcppNT2.h} header, for faster compilation. This can be
4+
#' useful if you need to improve the speed of compilation when iterating with,
5+
#' for example, \code{Rcpp::sourceCpp()}.
6+
#'
7+
#' Note that the precompiled header can be quite large (~400MB) so be sure that
8+
#' you have ample disk space before precompiling the header.
9+
#'
10+
#' @export
11+
precompileRcppNT2 <- function() {
12+
13+
header <- system.file("include/RcppNT2.h", package = "RcppNT2")
14+
include <- system.file("include", package = "RcppNT2")
15+
output <- file.path(include, "RcppNT2.h.gch")
16+
17+
R <- file.path(R.home("bin"), "R")
18+
CXX <- system(paste(shQuote(R), "CMD config CXX"), intern = TRUE)
19+
CXXFLAGS <- system(paste(shQuote(R), "CMD config CXXFLAGS"), intern = TRUE)
20+
CXX1XFLAGS <- system(paste(shQuote(R), "CMD config CXX1XFLAGS"), intern = TRUE)
21+
22+
cxxFlags <- if (nzchar(CXX1XFLAGS)) CXX1XFLAGS else CXXFLAGS
23+
24+
cmd <- paste(
25+
CXX,
26+
"-x c++-header", header,
27+
paste("-I", include, sep = ""),
28+
"-std=c++11",
29+
cxxFlags
30+
)
31+
32+
message("Pre-compiling 'RcppNT2.h'...")
33+
status <- system(cmd)
34+
if (status || !file.exists(output))
35+
stop("Failed to compile 'RcppNT2.h'", call. = FALSE)
36+
37+
message("Successfully compiled 'RcppNT2.h'.")
38+
invisible(output)
39+
}

inst/examples/boost-simd/boost-simd-variance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class SumOfSquaresReducer
3636
// [[Rcpp::export]]
3737
double simdVarTwoPass(NumericVector x)
3838
{
39-
double total = simdReduce(x.begin(), x.end(), 0.0, simd_ops::plus());
39+
double total = simdReduce(x.begin(), x.end(), 0.0, functor::plus());
4040
double n = x.size();
4141
double mean = total / n;
4242

man/precompileRcppNT2.Rd

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)