Skip to content

Commit 6f24c2c

Browse files
committed
Revert "remove pkg test which no longer passes in testthat 0.10.0"
This reverts commit f5f99cb.
1 parent f5f99cb commit 6f24c2c

File tree

10 files changed

+162
-0
lines changed

10 files changed

+162
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Package: RcppParallelTest
2+
Type: Package
3+
Title: What the Package Does (Title Case)
4+
Version: 0.1
5+
Date: 2015-03-09
6+
Author: Who wrote it
7+
Maintainer: Who to complain to <yourfault@somewhere.net>
8+
Description: More about what it does (maybe more than one line)
9+
License: GPL-2
10+
LazyData: TRUE
11+
Imports: Rcpp, RcppParallel
12+
LinkingTo: Rcpp, RcppParallel
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
exportPattern("^[[:alpha:]]+")
2+
importFrom(Rcpp, evalCpp)
3+
importFrom(RcppParallel, RcppParallelLibs)
4+
useDynLib(RcppParallelTest)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file was generated by Rcpp::compileAttributes
2+
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
3+
4+
parallelVectorSum <- function(x) {
5+
.Call('RcppParallelTest_parallelVectorSum', PACKAGE = 'RcppParallelTest', x)
6+
}
7+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
\name{parallelVectorSum}
2+
\alias{parallelVectorSum}
3+
\title{Parallel Vector Sum}
4+
\description{
5+
Parallel Vector Sum
6+
}
7+
\usage{
8+
parallelVectorSum(x)
9+
}
10+
\arguments{
11+
\item{x}{Vector}
12+
}
13+
14+
\value{
15+
Sum of Vector
16+
}
17+
18+
\examples{
19+
library(RcppParallelTest)
20+
parallelVectorSum(c(1:100))
21+
}
22+
23+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.o
2+
*.so
3+
*.dll
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PKG_LIBS += $(shell ${R_HOME}/bin/Rscript -e "RcppParallel::RcppParallelLibs()")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
PKG_CXXFLAGS += -DRCPP_PARALLEL_USE_TBB=1
2+
3+
PKG_LIBS += $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" \
4+
-e "RcppParallel::RcppParallelLibs()")
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This file was generated by Rcpp::compileAttributes
2+
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
3+
4+
#include <Rcpp.h>
5+
6+
using namespace Rcpp;
7+
8+
// parallelVectorSum
9+
double parallelVectorSum(NumericVector x);
10+
RcppExport SEXP RcppParallelTest_parallelVectorSum(SEXP xSEXP) {
11+
BEGIN_RCPP
12+
SEXP __sexp_result;
13+
{
14+
Rcpp::RNGScope __rngScope;
15+
Rcpp::traits::input_parameter< NumericVector >::type x(xSEXP );
16+
double __result = parallelVectorSum(x);
17+
PROTECT(__sexp_result = Rcpp::wrap(__result));
18+
}
19+
UNPROTECT(1);
20+
return __sexp_result;
21+
END_RCPP
22+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <Rcpp.h>
2+
using namespace Rcpp;
3+
4+
// [[Rcpp::depends(RcppParallel)]]
5+
#include <RcppParallel.h>
6+
using namespace RcppParallel;
7+
8+
struct Sum : public Worker
9+
{
10+
// source vector
11+
const RVector<int> input;
12+
13+
// accumulated value
14+
int value;
15+
16+
// constructors
17+
Sum(const IntegerVector input) : input(input), value(0) {}
18+
Sum(const Sum& sum, Split) : input(sum.input), value(0) {}
19+
20+
// accumulate just the element of the range I've been asked to
21+
void operator()(std::size_t begin, std::size_t end) {
22+
value += std::accumulate(input.begin() + begin, input.begin() + end, 0);
23+
}
24+
25+
// join my value with that of another Sum
26+
void join(const Sum& rhs) {
27+
value += rhs.value;
28+
}
29+
};
30+
31+
// [[Rcpp::export]]
32+
double parallelVectorSum(IntegerVector x) {
33+
34+
// declare the SumBody instance
35+
Sum sum(x);
36+
37+
// call parallel_reduce to start the work
38+
parallelReduce(0, x.length(), sum);
39+
40+
// return the computed sum
41+
return sum.value;
42+
}
43+
44+
// [[Rcpp::export]]
45+
void testMalloc() {
46+
47+
#if RCPP_PARALLEL_USE_TBB
48+
49+
std::vector<int,tbb::tbb_allocator<int> > vec;
50+
vec.push_back(42);
51+
52+
std::vector<int,tbb::scalable_allocator<int> > scalableVec;
53+
scalableVec.push_back(42);
54+
55+
std::vector<int,tbb::cache_aligned_allocator<int> > cacheAlignedVec;
56+
cacheAlignedVec.push_back(42);
57+
58+
#endif
59+
60+
}
61+
62+

tests/testthat/test-pkg.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
context( "package" )
2+
3+
test_that( "linking from a package works", {
4+
5+
templib <- tempfile()
6+
dir.create(templib)
7+
8+
oldWd <- getwd()
9+
on.exit(setwd(oldWd), add = TRUE)
10+
setwd("pkg")
11+
system(paste("R CMD INSTALL --preclean --no-multiarch ",
12+
"--library=", shQuote(templib), " ",
13+
"RcppParallelTest", sep = ""),
14+
intern = TRUE, ignore.stderr = TRUE)
15+
require(RcppParallelTest, lib.loc = templib, quietly = TRUE)
16+
17+
v <- c(1:1000)
18+
19+
expect_equal(
20+
sum(v),
21+
parallelVectorSum(v)
22+
)
23+
})
24+

0 commit comments

Comments
 (0)