Rcpp Version 1.0.9
ConvolveBenchmarks/convolve4_cpp.cpp

An even more efficient version of the basic convolution example from Section 5.10.1 of 'Writing R Extensions', now rewritten for Rcpp and using Rcpp::NumericVector as well as direct pointer operations for better performance.

// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
// This is a rewrite of the 'Writing R Extensions' section 5.10.1 example
#include <Rcpp.h>
RcppExport SEXP convolve4cpp(SEXP a, SEXP b) {
int n_xa = xa.size() ;
int n_xb = xb.size() ;
int nab = n_xa + n_xb - 1;
Rcpp::NumericVector xab(nab,0.0);
double* pa = xa.begin() ;
double* pb = xb.begin() ;
double* pab = xab.begin() ;
int i,j=0;
for (i = 0; i < n_xa; i++)
for (j = 0; j < n_xb; j++)
pab[i + j] += pa[i] * pb[j];
return xab ;
}
#include "loopmacro.h"
#define RcppExport
Definition: RcppCommon.h:140
R_xlen_t size() const
Definition: Vector.h:276
iterator begin()
Definition: Vector.h:334
RcppExport SEXP convolve4cpp(SEXP a, SEXP b)
#define LOOPMACRO_CPP(name)
Definition: loopmacro.h:12