|
Rcpp Version 0.9.10
|
00001 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*- 00002 00003 // This is a rewrite of the 'Writing R Extensions' section 5.10.1 example 00004 00005 #include <Rcpp.h> 00006 00007 RcppExport SEXP convolve4cpp(SEXP a, SEXP b) { 00008 Rcpp::NumericVector xa(a); 00009 Rcpp::NumericVector xb(b); 00010 int n_xa = xa.size() ; 00011 int n_xb = xb.size() ; 00012 int nab = n_xa + n_xb - 1; 00013 Rcpp::NumericVector xab(nab,0.0); 00014 00015 double* pa = xa.begin() ; 00016 double* pb = xb.begin() ; 00017 double* pab = xab.begin() ; 00018 int i,j=0; 00019 for (i = 0; i < n_xa; i++) 00020 for (j = 0; j < n_xb; j++) 00021 pab[i + j] += pa[i] * pb[j]; 00022 00023 return xab ; 00024 } 00025 00026 #include "loopmacro.h" 00027 LOOPMACRO_CPP(convolve4cpp) 00028 00029