|
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 template <typename T> 00008 T convolve( const T& a, const T& b ){ 00009 int na = a.size() ; int nb = b.size() ; 00010 T out(na + nb - 1); 00011 typename T::iterator iter_a(a.begin()), iter_b(b.begin()), iter_ab( out.begin() ) ; 00012 00013 for (int i = 0; i < na; i++) 00014 for (int j = 0; j < nb; j++) 00015 iter_ab[i + j] += iter_a[i] * iter_b[j]; 00016 00017 return out ; 00018 } 00019 00020 00021 RcppExport SEXP convolve13cpp(SEXP a, SEXP b){ 00022 return convolve( Rcpp::NumericVector(a), Rcpp::NumericVector(b) ) ; 00023 } 00024 00025 #include "loopmacro.h" 00026 LOOPMACRO_CPP(convolve13cpp) 00027