Rcpp Version 1.0.9
convolve8_cpp.cpp
Go to the documentation of this file.
1
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2
3
// this version is between the Rcpp_New_ptr and the Rcpp_New_std version
4
// test elapsed relative user.self sys.self
5
// 5 Rcpp_New_ptr(REPS, a, b) 0.214 1.000000 0.213 0.001
6
// 7 Rcpp_New_std_2(REPS, a, b) 0.223 1.042056 0.216 0.006
7
// 4 Rcpp_New_std(REPS, a, b) 0.524 2.448598 0.523 0.001
8
//
9
// so there is some overhead due to creating Vec objects and indexing them
10
// but much less than when we index the NumericVector
11
12
#include <
Rcpp.h
>
13
14
class
Vec
{
15
public
:
16
Vec
(
double
* data_ ) :
data
(data_){}
17
inline
double
&
operator[]
(
int
i){
return
data
[i] ; }
18
19
private
:
20
double
*
data
;
21
} ;
22
23
24
RcppExport
SEXP
convolve8cpp
(SEXP a, SEXP b){
25
Rcpp::NumericVector
xa(a);
26
Rcpp::NumericVector
xb(b);
27
int
n_xa = xa.
size
() ;
28
int
n_xb = xb.
size
() ;
29
int
nab = n_xa + n_xb - 1;
30
Rcpp::NumericVector
xab(nab);
31
32
Vec
vab(xab.
begin
()), va(xa.
begin
()), vb(xb.
begin
()) ;
33
34
for
(
int
i = 0; i < n_xa; i++)
35
for
(
int
j = 0; j < n_xb; j++)
36
vab[i + j] += va[i] * vb[j];
37
38
return
xab ;
39
}
40
41
#include "
loopmacro.h
"
42
LOOPMACRO_CPP
(
convolve8cpp
)
43
RcppExport
#define RcppExport
Definition:
RcppCommon.h:140
Rcpp.h
Rcpp::Vector
Definition:
Vector.h:36
Rcpp::Vector::size
R_xlen_t size() const
Definition:
Vector.h:276
Rcpp::Vector::begin
iterator begin()
Definition:
Vector.h:334
Vec
Definition:
convolve10_cpp.h:16
Vec::operator[]
double & operator[](int i)
Definition:
convolve8_cpp.cpp:17
Vec::Vec
Vec(double *data_)
Definition:
convolve8_cpp.cpp:16
Vec::data
double * data
Definition:
convolve8_cpp.cpp:20
convolve8cpp
RcppExport SEXP convolve8cpp(SEXP a, SEXP b)
Definition:
convolve8_cpp.cpp:24
loopmacro.h
LOOPMACRO_CPP
#define LOOPMACRO_CPP(name)
Definition:
loopmacro.h:12
inst
examples
ConvolveBenchmarks
convolve8_cpp.cpp
Generated on Sat Jul 9 2022 09:14:51 for Rcpp Version 1.0.9 by
1.9.1