Rcpp Version 0.12.12
Export.cpp
Go to the documentation of this file.
1 
2 #include <Rcpp.h>
3 
4 using namespace Rcpp;
5 
6 // [[Rcpp::export]]
7 int fibonacci(const int x) {
8 
9  if (x == 0) return(0);
10  if (x == 1) return(1);
11 
12  return (fibonacci(x - 1)) + fibonacci(x - 2);
13 }
14 
15 
16 // [[Rcpp::export("convolveCpp")]]
18 
19  int na = a.size(), nb = b.size();
20  int nab = na + nb - 1;
21  NumericVector xab(nab);
22 
23  for (int i = 0; i < na; i++)
24  for (int j = 0; j < nb; j++)
25  xab[i + j] += a[i] * b[j];
26 
27  return xab;
28 }
29 
30 
31 // [[Rcpp::export]]
33 
34  List output(input.size());
35 
36  std::transform(input.begin(), input.end(), output.begin(), f);
37  output.names() = input.names();
38 
39  return output;
40 }
Function_Impl< PreserveStorage > Function
Definition: Function.h:114
NamesProxy names()
Definition: NamesProxy.h:80
List lapplyCpp(List input, Function f)
Definition: Export.cpp:32
R_xlen_t size() const
Definition: Vector.h:274
NumericVector convolve(NumericVector a, NumericVector b)
Definition: Export.cpp:17
iterator end()
Definition: Vector.h:333
int fibonacci(const int x)
Definition: Export.cpp:7
Rcpp API.
Definition: algo.h:28
iterator begin()
Definition: Vector.h:332