Rcpp Version 0.9.10
convolve12_cpp.cpp
Go to the documentation of this file.
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 convolve12cpp(SEXP a, SEXP b){
00008     Rcpp::NumericVector xa(a), xb(b);
00009     int n_xa = xa.size(), n_xb = xb.size();
00010     Rcpp::NumericVector xab(n_xa + n_xb - 1);
00011     
00012     typedef Rcpp::NumericVector::iterator vec_iterator ;
00013     vec_iterator ia = xa.begin(), ib = xb.begin();
00014     vec_iterator iab = xab.begin();
00015     for (int i = 0; i < n_xa; i++)
00016         for (int j = 0; j < n_xb; j++) 
00017             iab[i + j] += ia[i] * ib[j];
00018 
00019     return xab;
00020 }
00021 
00022 #include "loopmacro.h"
00023 LOOPMACRO_CPP(convolve12cpp)
00024 
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Defines