Skip to content

Commit

Permalink
Adding add_numbers.cpp for lecture 06
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Sep 24, 2024
1 parent eff77c5 commit 85731f1
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lecture-06/adds_numbers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <Rcpp.h>

using namespace Rcpp;

// [[Rcpp::export]]
NumericVector add_vectors(NumericVector a, NumericVector b) {

NumericVector c(a.size());

for(int i = 0; i < a.size(); i++) {
c[i] = a[i] + b[i];
}

return c;
}

// [[Rcpp::export]]
NumericVector add_vectors2(NumericVector a, NumericVector b) {
return a + b;
}

/*** R
add_vectors(1:5, 1:5)
add_vectors2(1:5, 1:5)
*/


0 comments on commit 85731f1

Please sign in to comment.