Rcpp Version 1.0.9
ConvolveBenchmarks/convolve2_c.c

The basic convolution example from Section 5.10.1 of 'Writing R Extensions'

/* This is from 'Writing R Extensions' section 5.10.1 */
#include <R.h>
#include <Rdefines.h>
SEXP convolve2(SEXP a, SEXP b)
{
int i, j, na, nb, nab;
double *xa, *xb, *xab;
SEXP ab;
PROTECT(a = AS_NUMERIC(a));
PROTECT(b = AS_NUMERIC(b));
na = LENGTH(a); nb = LENGTH(b); nab = na + nb - 1;
PROTECT(ab = NEW_NUMERIC(nab));
xa = NUMERIC_POINTER(a); xb = NUMERIC_POINTER(b);
xab = NUMERIC_POINTER(ab);
for(i = 0; i < nab; i++) xab[i] = 0.0;
for(i = 0; i < na; i++)
for(j = 0; j < nb; j++) xab[i + j] += xa[i] * xb[j];
UNPROTECT(3);
return(ab);
}
#include "loopmacro.h"
SEXP convolve2(SEXP a, SEXP b)
Definition: convolve2_c.c:7
#define LOOPMACRO_C(name)
Definition: loopmacro.h:2