@@ -10,14 +10,18 @@ using namespace Rcpp;
1010#include < cmath>
1111#include < algorithm>
1212
13+ double timesTwo (double x) {
14+ return x * 2 ;
15+ }
16+
1317// [[Rcpp::export]]
14- NumericMatrix matrixSqrt (NumericMatrix orig) {
18+ NumericMatrix matrixTimesTwo (NumericMatrix orig) {
1519
1620 // allocate the matrix we will return
1721 NumericMatrix mat (orig.nrow (), orig.ncol ());
1822
1923 // transform it
20- std::transform (orig.begin (), orig.end (), mat.begin (), ::sqrt );
24+ std::transform (orig.begin (), orig.end (), mat.begin (), ::timesTwo );
2125
2226 // return the new matrix
2327 return mat;
@@ -26,7 +30,7 @@ NumericMatrix matrixSqrt(NumericMatrix orig) {
2630#include < RcppParallel.h>
2731using namespace RcppParallel ;
2832
29- struct SquareRoot : public Worker
33+ struct TimesTwo : public Worker
3034{
3135 // source matrix
3236 const RMatrix<double > input;
@@ -35,29 +39,28 @@ struct SquareRoot : public Worker
3539 RMatrix<double > output;
3640
3741 // initialize with source and destination
38- SquareRoot (const NumericMatrix input, NumericMatrix output)
42+ TimesTwo (const NumericMatrix input, NumericMatrix output)
3943 : input(input), output(output) {}
4044
41- // take the square root of the range of elements requested
4245 void operator ()(std::size_t begin, std::size_t end) {
4346 std::transform (input.begin () + begin,
4447 input.begin () + end,
4548 output.begin () + begin,
46- ::sqrt );
49+ ::timesTwo );
4750 }
4851};
4952
5053// [[Rcpp::export]]
51- NumericMatrix parallelMatrixSqrt (NumericMatrix x) {
54+ NumericMatrix parallelMatrixTimesTwo (NumericMatrix x) {
5255
5356 // allocate the output matrix
5457 NumericMatrix output (x.nrow (), x.ncol ());
5558
56- // SquareRoot functor (pass input and output matrixes)
57- SquareRoot squareRoot (x, output);
59+ // TimesTwo functor (pass input and output matrixes)
60+ TimesTwo timesTwo (x, output);
5861
5962 // call parallelFor to do the work
60- parallelFor (0 , x.nrow () * x.ncol (), squareRoot );
63+ parallelFor (0 , x.nrow () * x.ncol (), timesTwo );
6164
6265 // return the output matrix
6366 return output;
0 commit comments