Skip to content

Commit 73fd918

Browse files
committed
revert reader/writer classes
1 parent 7664024 commit 73fd918

File tree

6 files changed

+23
-186
lines changed

6 files changed

+23
-186
lines changed

inst/examples/parallel-inner-product.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,24 @@ double innerProduct(NumericVector x, NumericVector y) {
1818

1919
// [[Rcpp::depends(RcppParallel)]]
2020
#include <RcppParallel.h>
21-
using namespace RcppParallel;
2221

23-
struct InnerProduct : public Worker
22+
struct InnerProduct : public RcppParallel::Worker
2423
{
2524
// source vectors
26-
NumericVectorReader x;
27-
NumericVectorReader y;
25+
double * x;
26+
double * y;
2827

2928
// product that I have accumulated
3029
double product;
3130

3231
// constructors
33-
InnerProduct(NumericVector x, NumericVector y) : x(x), y(y), product(0) {}
34-
InnerProduct(InnerProduct& innerProduct, Split)
32+
InnerProduct(double * const x, double * const y) : x(x), y(y), product(0) {}
33+
InnerProduct(InnerProduct& innerProduct, RcppParallel::Split)
3534
: x(innerProduct.x), y(innerProduct.y), product(0) {}
3635

3736
// process just the elements of the range I've been asked to
3837
void operator()(std::size_t begin, std::size_t end) {
39-
product += std::inner_product(x[begin], x[end], y[begin], 0.0);
38+
product += std::inner_product(x + begin, x + end, y + begin, 0.0);
4039
}
4140

4241
// join my value with that of another InnerProduct
@@ -49,10 +48,10 @@ struct InnerProduct : public Worker
4948
double parallelInnerProduct(NumericVector x, NumericVector y) {
5049

5150
// declare the InnerProduct instance that takes a pointer to the vector data
52-
InnerProduct innerProduct(x, y);
51+
InnerProduct innerProduct(x.begin(), y.begin());
5352

5453
// call paralleReduce to start the work
55-
parallelReduce(0, x.length(), innerProduct);
54+
RcppParallel::parallelReduce(0, x.length(), innerProduct);
5655

5756
// return the computed product
5857
return innerProduct.product;

inst/examples/parallel-matrix-transform.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,23 @@ NumericMatrix matrixSqrt(NumericMatrix orig) {
2828

2929
// [[Rcpp::depends(RcppParallel)]]
3030
#include <RcppParallel.h>
31-
using namespace RcppParallel;
3231

33-
struct SquareRoot : public Worker
32+
struct SquareRoot : public RcppParallel::Worker
3433
{
3534
// source matrix
36-
NumericMatrixReader input;
35+
double* input;
3736

3837
// destination matrix
39-
NumericMatrixWriter output;
38+
double* output;
4039

4140
// initialize with source and destination
42-
SquareRoot(NumericMatrix input, NumericMatrix output)
41+
SquareRoot() : input(NULL), output(NULL) {}
42+
SquareRoot(double* input, double* output)
4343
: input(input), output(output) {}
4444

4545
// take the square root of the range of elements requested
4646
void operator()(std::size_t begin, std::size_t end) {
47-
std::transform(input[begin], input[end], output[begin], ::sqrt);
47+
std::transform(input + begin, input + end, output + begin, ::sqrt);
4848
}
4949
};
5050

@@ -55,10 +55,10 @@ NumericMatrix parallelMatrixSqrt(NumericMatrix x) {
5555
NumericMatrix output(x.nrow(), x.ncol());
5656

5757
// SquareRoot instance that takes a pointer to the input & output data
58-
SquareRoot squareRoot(x, output);
58+
SquareRoot squareRoot(x.begin(), output.begin());
5959

6060
// call parallelFor to do the work
61-
parallelFor(0, x.length(), squareRoot);
61+
RcppParallel::parallelFor(0, x.length(), squareRoot);
6262

6363
// return the output matrix
6464
return output;

inst/examples/parallel-vector-sum.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,22 @@ double vectorSum(NumericVector x) {
1919

2020
// [[Rcpp::depends(RcppParallel)]]
2121
#include <RcppParallel.h>
22-
using namespace RcppParallel;
2322

24-
struct Sum : public Worker
23+
struct Sum : public RcppParallel::Worker
2524
{
2625
// source vector
27-
NumericVectorReader input;
26+
double * input;
2827

2928
// value that I have accumulated
3029
double value;
3130

3231
// constructors
33-
Sum(NumericVector x) : input(x), value(0) {}
34-
Sum(Sum& sum, Split) : input(sum.input), value(0) {}
32+
Sum(double* input) : input(input), value(0) {}
33+
Sum(Sum& sum, RcppParallel::Split) : input(sum.input), value(0) {}
3534

3635
// accumulate just the element of the range I've been asked to
3736
void operator()(std::size_t begin, std::size_t end) {
38-
value += std::accumulate(input[begin], input[end], 0.0);
37+
value += std::accumulate(input + begin, input + end, 0.0);
3938
}
4039

4140
// join my value with that of another Sum
@@ -48,10 +47,10 @@ struct Sum : public Worker
4847
double parallelVectorSum(NumericVector x) {
4948

5049
// declare the SumBody instance that takes a pointer to the vector data
51-
Sum sum(x);
50+
Sum sum(x.begin());
5251

5352
// call parallel_reduce to start the work
54-
parallelReduce(0, x.length(), sum);
53+
RcppParallel::parallelReduce(0, x.length(), sum);
5554

5655
// return the computed sum
5756
return sum.value;

inst/include/RcppParallel.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
#endif
1616
#endif
1717

18-
#include "RcppParallel/Vector.h"
19-
#include "RcppParallel/Matrix.h"
20-
2118
namespace RcppParallel {
2219

2320
inline void parallelFor(std::size_t begin, std::size_t end,

inst/include/RcppParallel/Matrix.h

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

inst/include/RcppParallel/Vector.h

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

0 commit comments

Comments
 (0)