Rcpp Version 0.9.10
convolve7_c.c
Go to the documentation of this file.
00001 
00002 // This is from 'Writing R Extensions' section 5.10.1 
00003 // BUT slowed down by using REAL() on each access which proves to be rather costly
00004 
00005 #include <R.h>
00006 #include <Rdefines.h>
00007 
00008 SEXP convolve7(SEXP a, SEXP b)
00009 {
00010     int i, j, na, nb, nab;
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     for(i = 0; i < nab; i++) REAL(ab)[i] = 0.0;
00018     for(i = 0; i < na; i++)
00019         for(j = 0; j < nb; j++) REAL(ab)[i + j] += REAL(a)[i] * REAL(b)[j];
00020     UNPROTECT(3);
00021     return(ab);
00022 
00023 }
00024 
00025 
00026 #include "loopmacro.h"
00027 LOOPMACRO_C(convolve7)
00028 
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Defines