Rcpp Version 0.9.10
convolve2_c.c
Go to the documentation of this file.
00001 
00002 /* This is from 'Writing R Extensions' section 5.10.1 */
00003 
00004 #include <R.h>
00005 #include <Rdefines.h>
00006 
00007 SEXP convolve2(SEXP a, SEXP b)
00008 {
00009     int i, j, na, nb, nab;
00010     double *xa, *xb, *xab;
00011     SEXP ab;
00012 
00013     PROTECT(a = AS_NUMERIC(a));
00014     PROTECT(b = AS_NUMERIC(b));
00015     na = LENGTH(a); nb = LENGTH(b); nab = na + nb - 1;
00016     PROTECT(ab = NEW_NUMERIC(nab));
00017     xa = NUMERIC_POINTER(a); xb = NUMERIC_POINTER(b);
00018     xab = NUMERIC_POINTER(ab);
00019     for(i = 0; i < nab; i++) xab[i] = 0.0;
00020     for(i = 0; i < na; i++)
00021         for(j = 0; j < nb; j++) xab[i + j] += xa[i] * xb[j];
00022     UNPROTECT(3);
00023     return(ab);
00024 }
00025 
00026 #include "loopmacro.h"
00027 LOOPMACRO_C(convolve2)
00028 
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Defines