Rcpp Version 1.0.14
Loading...
Searching...
No Matches
convolve7_c.c
Go to the documentation of this file.
1
2// This is from 'Writing R Extensions' section 5.10.1
3// BUT slowed down by using REAL() on each access which proves to be rather costly
4
5#include <R.h>
6#include <Rdefines.h>
7
8SEXP convolve7(SEXP a, SEXP b)
9{
10 int i, j, na, nb, nab;
11 SEXP ab;
12
13 PROTECT(a = AS_NUMERIC(a));
14 PROTECT(b = AS_NUMERIC(b));
15 na = LENGTH(a); nb = LENGTH(b); nab = na + nb - 1;
16 PROTECT(ab = NEW_NUMERIC(nab));
17 for(i = 0; i < nab; i++) REAL(ab)[i] = 0.0;
18 for(i = 0; i < na; i++)
19 for(j = 0; j < nb; j++) REAL(ab)[i + j] += REAL(a)[i] * REAL(b)[j];
20 UNPROTECT(3);
21 return(ab);
22
23}
24
25
26#include "loopmacro.h"
28
SEXP convolve7(SEXP a, SEXP b)
Definition convolve7_c.c:8
#define LOOPMACRO_C(name)
Definition loopmacro.h:2