Rcpp Version 1.0.9
convolve13_cpp.cpp
Go to the documentation of this file.
1
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2
3
// This is a rewrite of the 'Writing R Extensions' section 5.10.1 example
4
5
#include <
Rcpp.h
>
6
7
template
<
typename
T>
8
T
convolve
(
const
T& a,
const
T& b ){
9
int
na = a.size() ;
int
nb = b.size() ;
10
T out(na + nb - 1);
11
typename
T::iterator iter_a(a.begin()), iter_b(b.begin()), iter_ab( out.begin() ) ;
12
13
for
(
int
i = 0; i < na; i++)
14
for
(
int
j = 0; j < nb; j++)
15
iter_ab[i + j] += iter_a[i] * iter_b[j];
16
17
return
out ;
18
}
19
20
21
RcppExport
SEXP
convolve13cpp
(SEXP a, SEXP b){
22
return
convolve
(
Rcpp::NumericVector
(a),
Rcpp::NumericVector
(b) ) ;
23
}
24
25
#include "
loopmacro.h
"
26
LOOPMACRO_CPP
(
convolve13cpp
)
27
RcppExport
#define RcppExport
Definition:
RcppCommon.h:140
Rcpp.h
Rcpp::Vector
Definition:
Vector.h:36
convolve13cpp
RcppExport SEXP convolve13cpp(SEXP a, SEXP b)
Definition:
convolve13_cpp.cpp:21
convolve
T convolve(const T &a, const T &b)
Definition:
convolve13_cpp.cpp:8
loopmacro.h
LOOPMACRO_CPP
#define LOOPMACRO_CPP(name)
Definition:
loopmacro.h:12
inst
examples
ConvolveBenchmarks
convolve13_cpp.cpp
Generated on Sat Jul 9 2022 09:14:51 for Rcpp Version 1.0.9 by
1.9.1