Skip to content

Commit 9c15577

Browse files
committed
'functors' -> 'ops'
1 parent 8174480 commit 9c15577

File tree

6 files changed

+47
-57
lines changed

6 files changed

+47
-57
lines changed

examples/boost-simd-abssum.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// [[Rcpp::depends(RcppParallel)]]
2-
#define RCPP_PARALLEL_USE_SIMD 1
2+
#define RCPP_PARALLEL_USE_SIMD
33
#include <RcppParallel.h>
44
#include <Rcpp.h>
55
using namespace Rcpp;

gallery/simd-vector-sum.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ print(res)
102102
* similarly efficient code when the `-ffast-math` optimization flag is set.
103103
* By default, the compiler is somewhat 'pessimistic' about the set of
104104
* optimizations it can perform around floating point arithmetic. This is
105-
* because it must respect the [IEEE floating
106-
* point](https://en.wikipedia.org/wiki/IEEE_floating_point) standard, and
107-
* this means respecting the fact that, for example, floating point
105+
* because it must respect the
106+
* [IEEE floating point standard](https://en.wikipedia.org/wiki/IEEE_floating_point),
107+
* and this means respecting the fact that, for example, floating point
108108
* operations are not assocative:
109109
*/
110110

@@ -116,6 +116,6 @@ print(res)
116116
* Surprisingly, the above computation does not evaluate to zero!
117117
*
118118
* In practice, you're likely safe to take advantage of the `-ffast-math`
119-
* optimizations, or Boost.SIMD, in your own work. However, be sure to test and
119+
* optimizations, or `Boost.SIMD`, in your own work. However, be sure to test and
120120
* verify!
121121
*/
Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
1-
path <- "inst/include/RcppParallel/simd/functors.h"
1+
path <- "inst/include/RcppParallel/simd/ops.h"
22
dir.create(dirname(path), recursive = TRUE, showWarnings = FALSE)
33

4+
forEach <- function(data, f) {
5+
nm <- names(data)
6+
for (i in seq_along(data)) {
7+
f(nm[[i]], data[[i]])
8+
}
9+
}
10+
11+
indent <- function(code, indent = " ") {
12+
code <- paste(indent, code, sep = "")
13+
gsub("\n", " \n", code, fixed = TRUE)
14+
}
15+
416
template <- paste(c(
517
"// Auto-generated functors for functions provided by Boost.SIMD.",
6-
"// See 'gen/simd-functors.R' for implementation.",
18+
"// See 'gen/simd-ops.R' for implementation.",
719
"",
820
"namespace boost {",
921
"namespace simd {",
10-
"namespace functors {",
22+
"namespace ops {",
1123
"",
1224
"%s",
1325
"",
14-
"} // namespace functors",
26+
"} // namespace ops",
1527
"} // namespace simd",
1628
"} // namespace boost"
1729
), collapse = "\n")
@@ -20,43 +32,43 @@ code <- NULL
2032

2133
# NOTE: Each function should accept a parameter called 'data'.
2234
unary <- list(
23-
sum = "boost::simd::sum(data)"
35+
sum = "return sum(data);"
2436
)
2537

2638
unary_template <- paste(c(
2739
"struct %s {",
2840
"template <typename T>",
2941
"inline T operator()(const T& data) {",
30-
" return %s;",
42+
"%s",
3143
"}",
3244
"};",
3345
""
3446
), collapse = "\n")
3547

36-
for (i in seq_along(unary)) {
37-
code <- c(code, sprintf(unary_template, names(unary)[i], unary[[i]]))
38-
}
48+
forEach(unary, function(name, value) {
49+
code <<- c(code, sprintf(unary_template, name, indent(value)))
50+
})
3951

4052
binary <- list(
41-
plus = "lhs + rhs",
42-
minus = "lhs - rhs",
43-
times = "lhs * rhs",
44-
divide = "lhs / rhs"
53+
plus = "return lhs + rhs;",
54+
minus = "return lhs - rhs;",
55+
times = "return lhs * rhs;",
56+
divide = "return lhs / rhs;"
4557
)
4658

4759
binary_template <- paste(c(
4860
"struct %s {",
4961
"template <typename T>",
5062
"inline T operator()(const T& lhs, const T& rhs) {",
51-
" return %s;",
63+
"%s",
5264
"}",
5365
"};",
5466
""
5567
), collapse = "\n")
5668

57-
for (i in seq_along(binary)) {
58-
code <- c(code, sprintf(binary_template, names(binary)[[i]], binary[[i]]))
59-
}
69+
forEach(binary, function(name, value) {
70+
code <<- c(code, sprintf(binary_template, name, indent(value)))
71+
})
6072

6173
compiled <- sprintf(template, paste(code, collapse = "\n"))
6274
cat(compiled, file = path, sep = "\n")

inst/include/RcppParallel.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ inline void parallelReduce(std::size_t begin, std::size_t end,
5353
} // namespace RcppParallel
5454

5555
// Refuse request for RCPP_PARALLEL_USE_SIMD if we don't have C++11
56-
#if RCPP_PARALLEL_USE_SIMD
57-
#if (__cplusplus <= 199711L)
58-
#undef RCPP_PARALLEL_USE_SIMD
59-
#endif
56+
#ifdef RCPP_PARALLEL_USE_SIMD
57+
# if (__cplusplus <= 199711L)
58+
# undef RCPP_PARALLEL_USE_SIMD
59+
# endif
6060
#endif
61-
#if RCPP_PARALLEL_USE_SIMD
62-
#include "RcppParallel/SIMD.h"
61+
62+
// Conditionally include SIMD
63+
#ifdef RCPP_PARALLEL_USE_SIMD
64+
# include "RcppParallel/SIMD.h"
6365
#endif
6466

6567
#endif // __RCPP_PARALLEL__

inst/include/RcppParallel/SIMD.h

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,6 @@
3030
#include <boost/simd/swar/swar.hpp>
3131

3232
// Auto-generated functors for use in 'transform()', 'accumulate()'
33-
#include <RcppParallel/simd/functors.h>
34-
35-
namespace RcppParallel {
36-
37-
template <typename DataType>
38-
class SimdTransformer
39-
{
40-
public:
41-
typedef DataType value_type;
42-
typedef boost::simd::pack<DataType> packed_type;
43-
};
44-
45-
template <typename DataType, class Transformer>
46-
DataType simdTransformAndReduce(const DataType* it, const DataType* end, Transformer transformer)
47-
{
48-
using boost::simd::pack;
49-
using boost::simd::load;
50-
51-
pack<DataType> accumulated = transformer.initialize(it, end);
52-
for (; it != end; it += pack<DataType>::static_size)
53-
transformer.update(load<pack<DataType>>(it), &accumulated);
54-
return transformer.reduce(accumulated);
55-
}
56-
57-
} // namespace RcppParallel
33+
#include <RcppParallel/simd/ops.h>
5834

5935
#endif /* RCPP_PARALLEL_SIMD_H */
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Auto-generated functors for functions provided by Boost.SIMD.
2-
// See 'gen/simd-functors.R' for implementation.
2+
// See 'gen/simd-ops.R' for implementation.
33

44
namespace boost {
55
namespace simd {
6-
namespace functors {
6+
namespace ops {
77

88
struct sum {
99
template <typename T>
1010
inline T operator()(const T& data) {
11-
return boost::simd::sum(data);
11+
return sum(data);
1212
}
1313
};
1414

@@ -41,6 +41,6 @@ inline T operator()(const T& lhs, const T& rhs) {
4141
};
4242

4343

44-
} // namespace functors
44+
} // namespace ops
4545
} // namespace simd
4646
} // namespace boost

0 commit comments

Comments
 (0)