Rcpp Version 1.0.14
Loading...
Searching...
No Matches
Export.cpp
Go to the documentation of this file.
1
2#include <Rcpp.h>
3
4using namespace Rcpp;
5
6// [[Rcpp::export]]
7int 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;
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}
NumericVector convolve(NumericVector a, NumericVector b)
Definition Export.cpp:17
int fibonacci(const int x)
Definition Export.cpp:7
List lapplyCpp(List input, Function f)
Definition Export.cpp:32
R_xlen_t size() const
Definition Vector.h:275
Rcpp API.
Definition algo.h:28
Function_Impl< PreserveStorage > Function
Definition Function.h:131
T as(SEXP x)
Definition as.h:151