Skip to content

Commit 20d3a8a

Browse files
committed
re-organize namespacing; add 'simdReduce'
1 parent 08d5582 commit 20d3a8a

File tree

11 files changed

+55
-388
lines changed

11 files changed

+55
-388
lines changed

examples/boost-simd-accumulate.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// [[Rcpp::depends(RcppParallel)]]
22
#define RCPP_PARALLEL_USE_SIMD
33
#include <RcppParallel.h>
4+
using namespace RcppParallel;
5+
46
#include <Rcpp.h>
57
using namespace Rcpp;
68

@@ -16,7 +18,7 @@ struct plus
1618
// [[Rcpp::export]]
1719
double simd_sum(NumericVector x)
1820
{
19-
return boost::simd::accumulate(x.begin(), x.end(), 0.0, plus());
21+
return simdReduce(x.begin(), x.end(), 0.0, plus());
2022
}
2123

2224
// [[Rcpp::export]]

examples/boost-simd-for-each.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// [[Rcpp::depends(RcppParallel)]]
22
#define RCPP_PARALLEL_USE_SIMD
33
#include <RcppParallel.h>
4+
using namespace RcppParallel;
5+
46
#include <Rcpp.h>
57
using namespace Rcpp;
68

@@ -27,8 +29,9 @@ class Accumulator
2729

2830
// [[Rcpp::export]]
2931
double vectorProd(NumericVector x) {
30-
auto accumulator = Accumulator();
31-
return boost::simd::for_each(x.begin(), x.end(), accumulator);
32+
Accumulator accumulator;
33+
simdFor(x.begin(), x.end(), accumulator);
34+
return accumulator;
3235
}
3336

3437
/*** R

examples/simd-operations.Rmd

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ elements in a vector, using `Boost.SIMD`.
3333
// [[Rcpp::depends(RcppParallel)]]
3434
#define RCPP_PARALLEL_USE_SIMD
3535
#include <RcppParallel.h>
36-
#include <Rcpp.h>
37-
3836
using namespace RcppParallel;
37+
38+
#include <Rcpp.h>
3939
using namespace Rcpp;
4040
4141
// Define a functor -- a C++ class which defines a templated 'function call'
@@ -49,7 +49,7 @@ struct add_two {
4949
5050
// [[Rcpp::export]]
5151
double simd_sum(NumericVector x) {
52-
return boost::simd::accumulate(x.begin(), x.end(), 0.0, add_two());
52+
return simdReduce(x.begin(), x.end(), 0.0, add_two());
5353
}
5454
```
5555

@@ -67,8 +67,8 @@ if (requireNamespace("microbenchmark", quietly = TRUE)) {
6767
`Boost.SIMD` provides two primary abstractions for the
6868
implementation of SIMD algorithms:
6969

70-
- `simd::accumulate()`, for vector -> scalar transformations, and
71-
- `simd::transform()`, for vector -> vector transformations.
70+
- `boost::simd::transform()` --- for vector -> vector transformations, and
71+
- `boost::simd::accumulate()` --- for vector -> scalar transformations.
7272

7373
These functions operate like their `std::` counterparts, but
7474
expect a functor with a templated call operator. By making
@@ -77,6 +77,12 @@ using its own optimized SIMD functions when appropriate, and
7777
fall back to a default implementation (based on the types
7878
provided) when not.
7979

80+
`RcppParallel` augments this with its own algorithms as well,
81+
for consistency with `parallelFor()` and `parallelReduce()`:
82+
83+
- `RcppParallel::simdFor()` --- apply an operation over a range, and
84+
- `RcppParallel::simdReduce()` --- accumulate elements in a range.
85+
8086
## Using SIMD in an R Package
8187

8288
To build an R package that uses `Boost.SIMD`, you need to

gallery/simd-variance.cpp

Lines changed: 0 additions & 160 deletions
This file was deleted.

gallery/simd-vector-sum.cpp

Lines changed: 0 additions & 137 deletions
This file was deleted.

0 commit comments

Comments
 (0)