Rcpp Version 1.0.14
Loading...
Searching...
No Matches
convolve2_c.c
Go to the documentation of this file.
1
2/* This is from 'Writing R Extensions' section 5.10.1 */
3
4#include <R.h>
5#include <Rdefines.h>
6
7SEXP convolve2(SEXP a, SEXP b)
8{
9 int i, j, na, nb, nab;
10 double *xa, *xb, *xab;
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 xa = NUMERIC_POINTER(a); xb = NUMERIC_POINTER(b);
18 xab = NUMERIC_POINTER(ab);
19 for(i = 0; i < nab; i++) xab[i] = 0.0;
20 for(i = 0; i < na; i++)
21 for(j = 0; j < nb; j++) xab[i + j] += xa[i] * xb[j];
22 UNPROTECT(3);
23 return(ab);
24}
25
26#include "loopmacro.h"
28
SEXP convolve2(SEXP a, SEXP b)
Definition convolve2_c.c:7
#define LOOPMACRO_C(name)
Definition loopmacro.h:2