Skip to content

Commit 2c22ea3

Browse files
committed
promote a number of examples to 'inst/' folder
1 parent 4459853 commit 2c22ea3

12 files changed

+53
-262
lines changed

.Rbuildignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,4 @@
99
^README.md
1010
^doc$
1111
^src/.*\.o$
12-
^examples/
13-
^gallery/
1412
^gen/

examples/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/boost-simd-abssum.cpp

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

examples/boost-simd-accumulate.cpp

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

examples/simd-operations.Rmd

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

examples/boost-simd-capabilities.cpp renamed to inst/examples/boost-simd/boost-simd-capabilities.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Print the SIMD capabilities of your processor.
2+
13
// [[Rcpp::depends(RcppParallel)]]
24
#define RCPP_PARALLEL_USE_SIMD
35
#include <RcppParallel.h>

examples/boost-simd-dot.cpp renamed to inst/examples/boost-simd/boost-simd-dot.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
// Demonstrates how Boost.SIMD could be used to compute the dot product
2+
// of two vectors, using a lower-level iteration over packs.
3+
//
4+
// See: http://nt2.metascale.fr/doc/html/tutorials/processing_data_the_simd_way.html
5+
16
// [[Rcpp::depends(RcppParallel)]]
27
#define RCPP_PARALLEL_USE_SIMD
38
#include <RcppParallel.h>
9+
using namespace RcppParallel;
10+
411
#include <Rcpp.h>
512
using namespace Rcpp;
613

7-
// http://nt2.metascale.fr/doc/html/tutorials/processing_data_the_simd_way.html
8-
914
template <typename Value>
1015
Value simd_dot_impl(Value* first1, Value* last1, Value* first2)
1116
{
@@ -44,10 +49,12 @@ double simd_dot(NumericVector lhs, NumericVector rhs)
4449
}
4550

4651
/*** R
52+
set.seed(123)
4753
lhs <- rnorm(1024 * 1000)
4854
rhs <- rnorm(1024 * 1000)
55+
stopifnot(all.equal(simd_dot(lhs, rhs), sum(lhs * rhs)))
4956
50-
all.equal(simd_dot(lhs, rhs), sum(lhs * rhs))
57+
library(microbenchmark)
5158
microbenchmark(
5259
simd = simd_dot(lhs, rhs),
5360
R = sum(lhs * rhs)

examples/boost-simd-for-each.cpp renamed to inst/examples/boost-simd/boost-simd-for-each.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Showcases how a stateful functor can be used with `simdFor()`,
2+
// for arbitrary operations over a range of values.
3+
14
// [[Rcpp::depends(RcppParallel)]]
25
#define RCPP_PARALLEL_USE_SIMD
36
#include <RcppParallel.h>
@@ -28,11 +31,11 @@ class Accumulator
2831
};
2932

3033
// [[Rcpp::export]]
31-
double vectorProd(NumericVector x) {
34+
double simdProd(NumericVector x) {
3235
return simdFor(x.begin(), x.end(), Accumulator());
3336
}
3437

3538
/*** R
3639
x <- 1:16
37-
vectorProd(x)
40+
stopifnot(all.equal(prod(x), simdProd(x)))
3841
*/

examples/boost-simd-hello-world.cpp renamed to inst/examples/boost-simd/boost-simd-hello-world.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
// The 'hello world' of Boost.SIMD, showing how packs can be
2+
// used and manipulated at a low level.
3+
//
4+
// See: http://nt2.metascale.fr/doc/html/tutorials/simd_hello_world.html
5+
16
// [[Rcpp::depends(RcppParallel)]]
27
#define RCPP_PARALLEL_USE_SIMD
38
#include <RcppParallel.h>
9+
using namespace RcppParallel;
10+
411
#include <Rcpp.h>
512
using namespace Rcpp;
613

7-
// http://nt2.metascale.fr/doc/html/tutorials/simd_hello_world.html
8-
914
// [[Rcpp::export]]
1015
void HelloWorld()
1116
{

examples/boost-simd-map-reduce.cpp renamed to inst/examples/boost-simd/boost-simd-map-reduce.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Shows how 'simdMapReduce()' can be used to efficiently
2+
// transform and accumulate values.
3+
14
// [[Rcpp::depends(RcppParallel)]]
25
#define RCPP_PARALLEL_USE_SIMD
36
#include <RcppParallel.h>
@@ -43,9 +46,9 @@ double simdVar(NumericVector x)
4346
}
4447

4548
/*** R
46-
x <- rnorm(1024 * 10000)
47-
var(x)
48-
simdVar(x)
49+
set.seed(123)
50+
x <- rnorm(1024)
51+
stopifnot(all.equal(var(x), simdVar(x)))
4952
library(microbenchmark)
5053
microbenchmark(var(x), simdVar(x))
5154
*/

0 commit comments

Comments
 (0)