Skip to content

Commit 781f06b

Browse files
committed
use RUnit for testing
1 parent 6f24c2c commit 781f06b

28 files changed

+99
-240
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Description: High level functions for doing parallel programming with 'Rcpp'.
1818
For example, the parallelFor() function can be used to convert the work of
1919
a standard serial "for" loop into a parallel one and the parallelReduce()
2020
function can be used for accumulating aggregate or other values.
21-
Suggests: Rcpp, testthat
21+
Suggests: Rcpp, RUnit
2222
SystemRequirements: GNU make, Windows: cmd.exe and cscript.exe, Solaris: g++ is required
2323
License: GPL-2
2424
URL: http://rcppcore.github.io/RcppParallel, https://github.com/RcppCore/RcppParallel
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ NumericMatrix rcpp_js_distance(NumericMatrix mat) {
6666
double d2 = kl_divergence(row2.begin(), row2.end(), avg.begin());
6767

6868
// write to output matrix
69-
rmat(i,j) = std::sqrt((double)(.5 * (d1 + d2)));
69+
rmat(i,j) = std::sqrt(.5 * (d1 + d2));
7070
}
7171
}
7272

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,14 @@ using namespace Rcpp;
1010
#include <cmath>
1111
#include <algorithm>
1212

13-
double timesTwo(double x) {
14-
return x * 2;
15-
}
16-
1713
// [[Rcpp::export]]
18-
NumericMatrix matrixTimesTwo(NumericMatrix orig) {
14+
NumericMatrix matrixSqrt(NumericMatrix orig) {
1915

2016
// allocate the matrix we will return
2117
NumericMatrix mat(orig.nrow(), orig.ncol());
2218

2319
// transform it
24-
std::transform(orig.begin(), orig.end(), mat.begin(), ::timesTwo);
20+
std::transform(orig.begin(), orig.end(), mat.begin(), ::sqrt);
2521

2622
// return the new matrix
2723
return mat;
@@ -30,7 +26,7 @@ NumericMatrix matrixTimesTwo(NumericMatrix orig) {
3026
#include <RcppParallel.h>
3127
using namespace RcppParallel;
3228

33-
struct TimesTwo : public Worker
29+
struct SquareRoot : public Worker
3430
{
3531
// source matrix
3632
const RMatrix<double> input;
@@ -39,28 +35,29 @@ struct TimesTwo : public Worker
3935
RMatrix<double> output;
4036

4137
// initialize with source and destination
42-
TimesTwo(const NumericMatrix input, NumericMatrix output)
38+
SquareRoot(const NumericMatrix input, NumericMatrix output)
4339
: input(input), output(output) {}
4440

41+
// take the square root of the range of elements requested
4542
void operator()(std::size_t begin, std::size_t end) {
4643
std::transform(input.begin() + begin,
4744
input.begin() + end,
4845
output.begin() + begin,
49-
::timesTwo);
46+
::sqrt);
5047
}
5148
};
5249

5350
// [[Rcpp::export]]
54-
NumericMatrix parallelMatrixTimesTwo(NumericMatrix x) {
51+
NumericMatrix parallelMatrixSqrt(NumericMatrix x) {
5552

5653
// allocate the output matrix
5754
NumericMatrix output(x.nrow(), x.ncol());
5855

59-
// TimesTwo functor (pass input and output matrixes)
60-
TimesTwo timesTwo(x, output);
56+
// SquareRoot functor (pass input and output matrixes)
57+
SquareRoot squareRoot(x, output);
6158

6259
// call parallelFor to do the work
63-
parallelFor(0, x.nrow() * x.ncol(), timesTwo);
60+
parallelFor(0, x.nrow() * x.ncol(), squareRoot);
6461

6562
// return the output matrix
6663
return output;

inst/tests/runit.distance.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
sourceCpp(system.file("tests/cpp/distance.cpp", package = "RcppParallel"))
3+
4+
test.distance <- function() {
5+
6+
n = 1000
7+
m = matrix(runif(n*10), ncol = 10)
8+
m = m/rowSums(m)
9+
10+
checkEquals(
11+
rcpp_js_distance(m),
12+
rcpp_parallel_js_distance(m)
13+
)
14+
}

inst/tests/runit.innerproduct.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
sourceCpp(system.file("tests/cpp/innerproduct.cpp", package = "RcppParallel"))
3+
4+
test.innerproduct <- function() {
5+
6+
x <- runif(1000000)
7+
y <- runif(1000000)
8+
9+
checkEquals(
10+
innerProduct(x, y),
11+
parallelInnerProduct(x, y)
12+
)
13+
}

inst/tests/runit.malloc.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
sourceCpp(system.file("tests/cpp/malloc.cpp", package = "RcppParallel"))
2+
3+
test.malloc <- function() {
4+
tbbMalloc()
5+
}
6+

inst/tests/runit.sum.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
sourceCpp(system.file("tests/cpp/sum.cpp", package = "RcppParallel"))
3+
4+
test.sum <- function() {
5+
6+
v <- as.numeric(c(1:10000000))
7+
8+
checkEquals(
9+
vectorSum(v),
10+
parallelVectorSum(v)
11+
)
12+
}

0 commit comments

Comments
 (0)