rcpp

Vectorised Rcpp random binomial draws

若如初见. 提交于 2019-12-29 06:31:27
问题 This is a follow-on question from this one: Generating same random variable in Rcpp and R I'm trying to speed up a vectorised call to rbinom of this form: x <- c(0.1,0.4,0.6,0.7,0.8) rbinom(length(x),1 ,x) In the live code of x is a vector of variable length (but typically numbering in the millions). I have no experience with Rcpp but I was wondering could I use Rcpp to speed this up. From the linked question this Rcpp code was suggested for non-vectorised rbinom calls by @Dirk Eddelbuettel :

How to speed up or vectorize a for loop?

吃可爱长大的小学妹 提交于 2019-12-28 16:02:29
问题 I would like to increase the speed of my for loop via vectorization or using Data.table or something else. I have to run the code on 1,000,000 rows and my code is really slow. The code is fairly self-explanatory. I have included an explanation below just in case. I have included the input and the output of the function. Hopefully you will help me make the function faster. My goal is to bin the vector "Volume", where each bin is equal to 100 shares. The vector "Volume" contains the number of

Rcpp can't find Rtools: “Error 1 occurred building shared library”

喜夏-厌秋 提交于 2019-12-28 13:46:07
问题 I am running into a simple setup problem with Rcpp and I cannot get it to work. I tried to follow this example http://www.r-bloggers.com/user2013-the-rcpp-tutorial/ But when executing this code: library(Rcpp) evalCpp("1 + 1", showOutput= TRUE) I get this output C:/R/R-30~1.1/bin/x64/R CMD SHLIB -o "sourceCpp_33280.dll" "file8d01b0a675b.cpp" Error in sourceCpp(code = code, env = env, rebuild = rebuild, showOutput = showOutput, : Error 1 occurred building shared library. WARNING: Rtools is

How to build a R package which use Rcpp with external c++ libraries?

僤鯓⒐⒋嵵緔 提交于 2019-12-28 13:34:14
问题 Such as boost, where can I specify the following: 1.External c++ header file include path 2.External c++ source file 3.External c++ link library file path 回答1: It all goes into src/Makevars as explained in the fine manual Writing R Extensions that came with R either the Writing a package using Rcpp vignette or my book both of which I told you about in ... ... my replies to your post on rcpp-devel 来源: https://stackoverflow.com/questions/18570526/how-to-build-a-r-package-which-use-rcpp-with

Declare a variable as a reference in Rcpp

血红的双手。 提交于 2019-12-28 12:44:29
问题 In C++, we can declare a variable as a reference. int a = 10; int& b = a; If we set b=15 , a also changes. I want to do the similar thing in Rcpp. List X = obj_from_R["X"]; IntegerVector x_i = X[index]; x_i = value; I want to update an object from R called X by inserting a value to one of its vector. The code above did not work, so I tried this: IntegerVector& x_i = X[index]; and received an error. error: non-const lvalue reference to type 'IntegerVector' (aka 'Vector<13>') cannot bind to a

Element-Wise Matrix Multiplication in Rcpp

前提是你 提交于 2019-12-28 04:25:25
问题 I am working on a code that requires an element-wise matrix multiplication. I am trying to implement this in Rcpp since the code requires some expensive loops. I am fairly new to Rcpp, and may be missing something, but I cannot get the element-wise matrix multiplication to work. // [[Rcpp::export]] NumericMatrix multMat(NumericMatrix m1, NumericMatrix m2) { NumericMatrix multMatrix = m1 * m2 // How can this be implemented ? } I may be missing something very trivial, and wanted to ask if there

How to make openBLAS work with openMP?

*爱你&永不变心* 提交于 2019-12-25 14:25:28
问题 I got tons of warning from openBLAS like OpenBLAS Warning : Detect OpenMP Loop and this application may hang. Please rebuild the library with USE_OPENMP=1 option. OpenBLAS Warning : Detect OpenMP Loop and this application may hang. Please rebuild the library with USE_OPENMP=1 option. OpenBLAS Warning : Detect OpenMP Loop and this application may hang. Please rebuild the library with USE_OPENMP=1 option. OpenBLAS Warning : Detect OpenMP Loop and this application may hang. Please rebuild the

How to make openBLAS work with openMP?

你。 提交于 2019-12-25 14:25:08
问题 I got tons of warning from openBLAS like OpenBLAS Warning : Detect OpenMP Loop and this application may hang. Please rebuild the library with USE_OPENMP=1 option. OpenBLAS Warning : Detect OpenMP Loop and this application may hang. Please rebuild the library with USE_OPENMP=1 option. OpenBLAS Warning : Detect OpenMP Loop and this application may hang. Please rebuild the library with USE_OPENMP=1 option. OpenBLAS Warning : Detect OpenMP Loop and this application may hang. Please rebuild the

Why is this simplistic cpp function version slower?

我与影子孤独终老i 提交于 2019-12-25 09:51:33
问题 Consider this comparison: require(Rcpp) require(microbenchmark) cppFunction('int cppFun (int x) {return x;}') RFun = function(x) x x=as.integer(2) microbenchmark(RFun=RFun(x),cppFun=cppFun(x),times=1e5) Unit: nanoseconds expr min lq mean median uq max neval cld RFun 302 357 470.2047 449 513 110152 1e+06 a cppFun 2330 2598 4045.0059 2729 2879 68752603 1e+06 b cppFun seems slower than RFun . Why is it so? Do the times for calling the functions differ? Or is it the function itself that differ in

Why is this simplistic cpp function version slower?

纵然是瞬间 提交于 2019-12-25 09:50:05
问题 Consider this comparison: require(Rcpp) require(microbenchmark) cppFunction('int cppFun (int x) {return x;}') RFun = function(x) x x=as.integer(2) microbenchmark(RFun=RFun(x),cppFun=cppFun(x),times=1e5) Unit: nanoseconds expr min lq mean median uq max neval cld RFun 302 357 470.2047 449 513 110152 1e+06 a cppFun 2330 2598 4045.0059 2729 2879 68752603 1e+06 b cppFun seems slower than RFun . Why is it so? Do the times for calling the functions differ? Or is it the function itself that differ in