Le téléchargement de votre SlideShare est en cours. ×
0
Rcpp11 useR2014
Rcpp11 useR2014
Rcpp11 useR2014
Rcpp11 useR2014
Rcpp11 useR2014
Rcpp11 useR2014
Rcpp11 useR2014
Rcpp11 useR2014
Rcpp11 useR2014
Rcpp11 useR2014
Rcpp11 useR2014
Rcpp11 useR2014
Rcpp11 useR2014
Rcpp11 useR2014
Rcpp11 useR2014
Prochain SlideShare
Chargement dans... 5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Rcpp11 useR2014

1,461

Published on

useR! 2014 presentation about Rcpp11

useR! 2014 presentation about Rcpp11

Published in: Technologies, Affaires
0 commentaires
5 mentions J'aime
Statistiques
Remarques
  • Soyez le premier à commenter

Aucun téléchargement
Vues
Total des vues
1,461
Sur Slideshare
0
À partir des ajouts
0
Nombre d'ajouts
1
Actions
Partages
0
Téléchargements
25
Commentaires
0
J'aime
5
Ajouts 0
No embeds

Signaler un contenu
Signalé comme inapproprié Signaler comme inapproprié
Signaler comme inapproprié

Indiquez la raison pour laquelle vous avez signalé cette présentation comme n'étant pas appropriée.

Annuler
No notes for slide

Transcript

  • 1. Rcpp11 Romain François romain@r-enthusiasts.com @romain_francois
  • 2. Rcpp11 • Targets C++11 • Smaller code base (than Rcpp) • Header only
  • 3. #include <Rcpp.h> ! // [[Rcpp::export]] int foo(){ return 2 ; } Rcpp Rcpp11 0 1 2 3 4 Less complexity -> faster compiles
  • 4. ! Some examples
  • 5. NumericVector constructors // C++ uniform initialization NumericVector x = {1.0, 2.0, 3.0} ; ! // init with given size NumericVector y( 2 ) ; // data is not initialized NumericVector y( 2, 3.0 ) ; // initialize all to 3.0 ! // fuse several vectors (similar to c in R) NumericVector z = fuse(x, y) ; NumericVector z = fuse(x, y, 3.0) ;
  • 6. create NumericVector x = {1.0, 2.0, 3.0} ; ! // old school NumericVector::create (Rcpp style). NumericVector x = NumericVector::create(1.0, 2.0, 3.0) ; NumericVector x = NumericVector::create( _["a"] = 1.0, _["b"] = 2.0, _["c"] = 3.0 ) ; ! !// create as a free function. Rcpp11 style NumericVector x = create(1.0, 2.0, 3.0) ; NumericVector x = create( _["a"] = 1.0, _["b"] = 2.0, _["c"] = 3.0 ) ;
  • 7. sugar #include <Rcpp11> ! // [[export]] NumericVector foo( NumericVector x ){ return sqrt(exp(x)) + 1.0 ; } ! /*** R foo( c(1,2,3) ) # [1] 2.648721 3.718282 5.481689 */
  • 8. sapply + lambda
  • 9. sapply + lambda #include <Rcpp11> ! // [[export]] NumericVector foo( NumericVector x ){ return sapply(x, [](double d){ return exp(d * 2) ; }); } x <- 1:3 sapply( x, function(d){ exp(d*2) ; })
  • 10. sapply + lambda + … #include <Rcpp11> ! // [[export]] NumericVector foo( NumericVector x ){ auto fun = [](double d, double y, double z){ return exp(d * y) + z ; } ; return sapply(x, fun, 3.0, 4.6); } x <- 1:3 sapply( x, function(d, y, z){ exp(d*y) + z ; }, 3.0, 4.6 )
  • 11. Rcpp11 release cycle • Available from CRAN: ! • Evolves quickly. Get it from github ! • Next Release: 3.1.1 (same time as R 3.1.1) > install.packages( "Rcpp11" ) > install_github( "Rcpp11/Rcpp11" )
  • 12. attributes companion package • Standalone impl of Rcpp attributes [[Rcpp::export]], sourceCpp, compileAttributes ! • Only available from github: > install_github( "Rcpp11/attributes" )
  • 13. Use Rcpp11 in your package • Write your .cpp files #include <Rcpp11> ! // [[export]] void foo( … ) { … } // your code SystemRequirements: C++11 LinkingTo: Rcpp11 library(attributes) compileAttributes( "mypkg" ) • Express dep on C++11 and Rcpp11 headers • Generate the boiler plate
  • 14. Romain François romain@r-enthusiasts.com @romain_francois Questions ?

×