Rcpp Version 1.0.14
Loading...
Searching...
No Matches
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
14class Vec {
15public:
16 Vec( double* data_ ) : data(data_){}
17 inline double& operator[]( int i){ return data[i] ; }
18
19private:
20 double* data ;
21} ;
22
23
24RcppExport SEXP convolve8cpp(SEXP a, SEXP 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"
43
#define RcppExport
Definition RcppCommon.h:141
R_xlen_t size() const
Definition Vector.h:275
iterator begin()
Definition Vector.h:333
Vec(double *data_)
double & operator[](int i)
double * data
RcppExport SEXP convolve8cpp(SEXP a, SEXP b)
#define LOOPMACRO_CPP(name)
Definition loopmacro.h:12