Skip to content

Commit e8ed7e3

Browse files
committed
update examples
1 parent 405be74 commit e8ed7e3

10 files changed

+57
-63
lines changed

RcppNT2.Rproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ StripTrailingWhitespace: Yes
1818
BuildType: Package
1919
PackageUseDevtools: Yes
2020
PackageInstallArgs: --no-multiarch --with-keep.source
21-
PackageRoxygenize: rd,collate,namespace
21+
PackageRoxygenize: rd,collate,namespace,vignette

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Print the SIMD capabilities of your processor.
22

3-
// [[Rcpp::depends(RcppNt2)]]
4-
#include <RcppNt2.h>
5-
using namespace RcppNt2;
3+
// [[Rcpp::depends(RcppNT2)]]
4+
#include <RcppNT2.h>
5+
using namespace RcppNT2;
66

77
#include <Rcpp.h>
88
using namespace Rcpp;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
//
44
// See: http://nt2.metascale.fr/doc/html/tutorials/processing_data_the_simd_way.html
55

6-
// [[Rcpp::depends(RcppNt2)]]
7-
#include <RcppNt2.h>
8-
using namespace RcppNt2;
6+
// [[Rcpp::depends(RcppNT2)]]
7+
#include <RcppNT2.h>
8+
using namespace RcppNT2;
99

1010
#include <Rcpp.h>
1111
using namespace Rcpp;
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// Showcases how a stateful functor can be used with `simdFor()`,
22
// for arbitrary operations over a range of values.
33

4-
// [[Rcpp::depends(RcppParallel)]]
5-
#define RCPP_PARALLEL_USE_SIMD
6-
#include <RcppParallel.h>
7-
using namespace RcppParallel;
4+
// [[Rcpp::depends(RcppNT2)]]
5+
#include <RcppNT2.h>
6+
using namespace RcppNT2;
87

98
#include <Rcpp.h>
109
using namespace Rcpp;
@@ -13,19 +12,19 @@ using namespace Rcpp;
1312
class Accumulator
1413
{
1514
public:
16-
15+
1716
Accumulator() : result_(1.0) {}
18-
17+
1918
template <typename T>
2019
void operator()(const T& data)
2120
{
2221
result_ *= boost::simd::prod(data);
2322
}
24-
23+
2524
operator double() const {
2625
return result_;
2726
}
28-
27+
2928
private:
3029
double result_;
3130
};
@@ -38,4 +37,4 @@ double simdProd(NumericVector x) {
3837
/*** R
3938
x <- 1:16
4039
stopifnot(all.equal(prod(x), simdProd(x)))
41-
*/
40+
*/

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
//
44
// See: http://nt2.metascale.fr/doc/html/tutorials/simd_hello_world.html
55

6-
// [[Rcpp::depends(RcppParallel)]]
7-
#define RCPP_PARALLEL_USE_SIMD
8-
#include <RcppParallel.h>
9-
using namespace RcppParallel;
6+
// [[Rcpp::depends(RcppNT2)]]
7+
#include <RcppNT2.h>
8+
using namespace RcppNT2;
109

1110
#include <Rcpp.h>
1211
using namespace Rcpp;
@@ -15,16 +14,16 @@ using namespace Rcpp;
1514
void HelloWorld()
1615
{
1716
typedef boost::simd::pack<float> p_t;
18-
17+
1918
p_t res;
2019
p_t u(10);
2120
p_t r = boost::simd::splat<p_t>(11);
22-
21+
2322
res = (u + r) * 2.f;
24-
23+
2524
Rcout << res << std::endl;
2625
}
2726

2827
/*** R
2928
HelloWorld()
30-
*/
29+
*/

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
11
// Shows how 'simdMapReduce()' can be used to efficiently
22
// transform and accumulate values.
33

4-
// [[Rcpp::depends(RcppParallel)]]
5-
#define RCPP_PARALLEL_USE_SIMD
6-
#include <RcppParallel.h>
7-
using namespace RcppParallel;
4+
// [[Rcpp::depends(RcppNT2)]]
5+
#include <RcppNT2.h>
6+
using namespace RcppNT2;
87

98
#include <Rcpp.h>
109
using namespace Rcpp;
1110

1211
class SumOfSquaresReducer
1312
{
1413
public:
15-
14+
1615
explicit SumOfSquaresReducer(double mean)
1716
: mean_(mean)
1817
{}
19-
18+
2019
template <typename T>
2120
void map(const T& self, T* pBuffer)
2221
{
2322
*pBuffer += boost::simd::sqr(self - mean_);
2423
}
25-
24+
2625
template <typename T, typename U>
2726
void reduce(const T& data, U* pBuffer)
2827
{
2928
*pBuffer += boost::simd::sum(data);
3029
}
31-
30+
3231
private:
3332
double mean_;
3433
};
@@ -39,9 +38,9 @@ double simdVar(NumericVector x)
3938
double total = simdReduce(x.begin(), x.end(), 0.0, simd_ops::plus());
4039
double n = x.size();
4140
double mean = total / n;
42-
41+
4342
double ssq = simdMapReduce(x.begin(), x.end(), 0.0, SumOfSquaresReducer(mean));
44-
43+
4544
return ssq / (n - 1);
4645
}
4746

inst/examples/boost-simd/boost-simd-transform.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// A simple example demonstration how 'simdTransform()'
22
// can be used.
33

4-
// [[Rcpp::depends(RcppParallel)]]
5-
#define RCPP_PARALLEL_USE_SIMD
6-
#include <RcppParallel.h>
7-
using namespace RcppParallel;
4+
// [[Rcpp::depends(RcppNT2)]]
5+
#include <RcppNT2.h>
6+
using namespace RcppNT2;
87

98
#include <Rcpp.h>
109
using namespace Rcpp;

inst/examples/boost-simd/boost-simd-variance.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,33 @@
22
// See https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
33
// for more information.
44

5-
// [[Rcpp::depends(RcppParallel)]]
6-
#define RCPP_PARALLEL_USE_SIMD
7-
#include <RcppParallel.h>
8-
using namespace RcppParallel;
5+
// [[Rcpp::depends(RcppNT2)]]
6+
#include <RcppNT2.h>
7+
using namespace RcppNT2;
98

109
#include <Rcpp.h>
1110
using namespace Rcpp;
1211

1312
class SumOfSquaresReducer
1413
{
1514
public:
16-
15+
1716
explicit SumOfSquaresReducer(double mean)
1817
: mean_(mean)
1918
{}
20-
19+
2120
template <typename T>
2221
void map(const T& self, T* pBuffer)
2322
{
2423
*pBuffer += boost::simd::sqr(self - mean_);
2524
}
26-
25+
2726
template <typename T, typename U>
2827
void reduce(const T& data, U* pBuffer)
2928
{
3029
*pBuffer += boost::simd::sum(data);
3130
}
32-
31+
3332
private:
3433
double mean_;
3534
};
@@ -40,9 +39,9 @@ double simdVarTwoPass(NumericVector x)
4039
double total = simdReduce(x.begin(), x.end(), 0.0, simd_ops::plus());
4140
double n = x.size();
4241
double mean = total / n;
43-
42+
4443
double ssq = simdMapReduce(x.begin(), x.end(), 0.0, SumOfSquaresReducer(mean));
45-
44+
4645
return ssq / (n - 1);
4746
}
4847

@@ -52,36 +51,36 @@ double simdVarTwoPass(NumericVector x)
5251
class SumOfSquares
5352
{
5453
public:
55-
54+
5655
SumOfSquares(double shift, std::size_t n)
5756
: lhs_(0.0), pLhs_(0.0),
5857
rhs_(0.0), pRhs_(0.0),
5958
shift_(shift), n_(n)
6059
{}
61-
60+
6261
void operator()(double data) {
6362
lhs_ += (data - shift_) * (data - shift_);
6463
rhs_ += (data - shift_);
6564
}
66-
65+
6766
void operator()(const boost::simd::pack<double>& data) {
6867
pLhs_ += (data - shift_) * (data - shift_);
6968
pRhs_ += (data - shift_);
7069
}
71-
70+
7271
operator double() const {
7372
double lhs = lhs_ + boost::simd::sum(pLhs_);
7473
double rhs = rhs_ + boost::simd::sum(pRhs_);
7574
return lhs - (rhs * rhs) / n_;
7675
}
77-
76+
7877
private:
7978
double lhs_;
8079
boost::simd::pack<double> pLhs_;
81-
80+
8281
double rhs_;
8382
boost::simd::pack<double> pRhs_;
84-
83+
8584
double shift_;
8685
std::size_t n_;
8786
};
@@ -108,4 +107,4 @@ microbenchmark(
108107
simdVarOnePass(x, shift),
109108
simdVarTwoPass(x)
110109
)
111-
*/
110+
*/

inst/examples/nt2/nt2-sin.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
// Example using 'nt2::sin'.
1+
// Example using 'nt2::sin()'.
22

3-
// [[Rcpp::depends(RcppParallel)]]
4-
#define RCPP_PARALLEL_USE_SIMD
5-
#include <RcppParallel.h>
6-
using namespace RcppParallel;
3+
// [[Rcpp::depends(RcppNT2)]]
4+
#include <RcppNT2.h>
5+
using namespace RcppNT2;
76

87
#include <Rcpp.h>
98
using namespace Rcpp;
@@ -32,4 +31,4 @@ microbenchmark(
3231
R = sin(data),
3332
nt2 = nt2Sin(data)
3433
)
35-
*/
34+
*/

inst/include/RcppNT2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@
3939
#include <nt2/swar/swar.hpp>
4040
#include <nt2/trigonometric/trigonometric.hpp>
4141

42-
#include <RcppNt2/algorithm.h>
42+
#include <RcppNT2/algorithm.h>
4343

4444
#endif /* RCPP_NT2_H */

0 commit comments

Comments
 (0)