We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 05872c4 commit 57faf42Copy full SHA for 57faf42
examples/boost-simd-accumulate.cpp
@@ -0,0 +1,33 @@
1
+// [[Rcpp::depends(RcppParallel)]]
2
+#include <RcppParallel.h>
3
+#include <Rcpp.h>
4
+using namespace Rcpp;
5
+
6
+#include <boost/simd/sdk/simd/algorithm.hpp>
7
8
+struct plus
9
+{
10
+ template <class T>
11
+ T operator()(const T& lhs, const T& rhs) const
12
+ {
13
+ return lhs + rhs;
14
+ }
15
+};
16
17
+// [[Rcpp::export]]
18
+double simd_sum(NumericVector x)
19
20
+ return boost::simd::accumulate(
21
+ x.begin(),
22
+ x.end(),
23
+ 0.0,
24
+ plus()
25
+ );
26
+}
27
28
+/***R
29
+n <- 1024 * 1000
30
+data <- rnorm(n)
31
+simd_sum(data)
32
+microbenchmark(R = sum(data), simd = simd_sum(data))
33
+*/
0 commit comments