rcpp

Linking Rcpp to interp2d (GSL-type library)

ぐ巨炮叔叔 提交于 2019-12-23 20:46:01
问题 I need some help with a linker error I get during installation of an Rcpp package on a linux system where I don't have admin rights. In a nutshell, I get this error: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC I have a file solve.cpp that uses external library interp2d, which in turn has a GSL dependency. I specify my dependencies via [[Rcpp::depends(RcppArmadillo,RcppGSL)]] and in the DESCRIPTION . My Makevars is like the one

Is there performance difference between NumericVector and vector<double>?

筅森魡賤 提交于 2019-12-23 14:06:29
问题 Suppose one uses NumericVector and the other uses vector<double> in their Rcpp code. Is there notable difference between the two usages, especially in performance? 回答1: Generally, yes. All of the Rcpp(11) types are "thin proxy objects" (which we talk about in several places, talks, slide decks, my book, ...) around the underlying SEXP objects. That means no copies are made when you go from R to C++, and when you go back from C++ to R. Using standard C++ types like std::vector<T> , however,

Is there performance difference between NumericVector and vector<double>?

时光怂恿深爱的人放手 提交于 2019-12-23 14:05:29
问题 Suppose one uses NumericVector and the other uses vector<double> in their Rcpp code. Is there notable difference between the two usages, especially in performance? 回答1: Generally, yes. All of the Rcpp(11) types are "thin proxy objects" (which we talk about in several places, talks, slide decks, my book, ...) around the underlying SEXP objects. That means no copies are made when you go from R to C++, and when you go back from C++ to R. Using standard C++ types like std::vector<T> , however,

The specified module could not be found in R

别来无恙 提交于 2019-12-23 12:50:04
问题 I am developing a package using Rcpp and another third party C++ library. When I tried to install the package, I got Error in inDL(x, as.logical(local), as.logical(now), ...) : unable to load shared object 'C:/Users/Admin/Documents/R/win-library/2.15/packagename/libs/i386/package.dll': LoadLibrary failure: The specified module could not be found. In 32-bit Windows OS, following an advice from my colleague, I fixed the problem by adding location of following dlls from MingW to system path.

Rcpp: Error: not compatible with requested type

南楼画角 提交于 2019-12-23 10:42:08
问题 I have this C++ code: #include <R.h> #include <Rcpp.h> using namespace Rcpp; extern "C" { SEXP gensampleRcpp2( Function rlawfunc, SEXP n) { Rcpp::RNGScope __rngScope; return Rcpp::List::create(Rcpp::Named("sample") = rlawfunc(n), Rcpp::Named("law.name") = " ", Rcpp::Named("law.pars") = R_NilValue); } RcppExport SEXP gensampleRcpp(SEXP rlawfuncSEXP, SEXP nSEXP) { BEGIN_RCPP Function rlawfunc = Rcpp::as<Function >(rlawfuncSEXP); IntegerVector n = Rcpp::as<IntegerVector >(nSEXP); SEXP __result =

Rcpp: Error: not compatible with requested type

爷,独闯天下 提交于 2019-12-23 10:42:03
问题 I have this C++ code: #include <R.h> #include <Rcpp.h> using namespace Rcpp; extern "C" { SEXP gensampleRcpp2( Function rlawfunc, SEXP n) { Rcpp::RNGScope __rngScope; return Rcpp::List::create(Rcpp::Named("sample") = rlawfunc(n), Rcpp::Named("law.name") = " ", Rcpp::Named("law.pars") = R_NilValue); } RcppExport SEXP gensampleRcpp(SEXP rlawfuncSEXP, SEXP nSEXP) { BEGIN_RCPP Function rlawfunc = Rcpp::as<Function >(rlawfuncSEXP); IntegerVector n = Rcpp::as<IntegerVector >(nSEXP); SEXP __result =

Rcpp exported module not exposed

China☆狼群 提交于 2019-12-23 10:26:38
问题 I have an R package called multicool which handles permutations of multisets. Currently, internally, there exists a C++ class, and a call to initMC creates a new object of class Multicool which then can do all the things I need it to do. However, there is no simple way to release the memory allocated to this object. It doesn't matter for simple uses, but I have an application which might call this hundreds of thousands of times. The solution, I think, is to expose the class to R using an Rcpp

In Rcpp - how to return a vector with names

两盒软妹~` 提交于 2019-12-23 10:19:07
问题 Suppose I have the following matrix: testM <- as.matrix(read.table(textConnection(" 1 5 4 1 3 2 2 1 5 4 1 3 2 2 1 5 4 1 3 2 2 1 5 4 1 3 2 2 1 5 4 1 3 2 2 1 1 5 4 1 3 2 2 1 5 4 1 3 2 2 1 5 4 1 3 2 2 1 5 4 1 3 2 2 1 5 4 1 3 2 2 1 "))) This matrix has column names V1 to V6 Suppose that there is another matrix where I remove the column name: > testM2<-testM > colnames(testM2)<-NULL Then if I try colMeans on testM and testM2 R returns a numeric class in both cases, except in the first case the

Make cumulative sum faster

坚强是说给别人听的谎言 提交于 2019-12-23 07:57:01
问题 I'm trying to take cumulative sums for each column of a matrix. Here's my code in R: testMatrix = matrix(1:65536, ncol=256); microbenchmark(apply(testMatrix, 2, cumsum), times=100L); Unit: milliseconds expr min lq mean median uq max neval apply(testMatrix, 2, cumsum) 1.599051 1.766112 2.329932 2.15326 2.221538 93.84911 10000 I used Rcpp for comparison: cppFunction('NumericMatrix apply_cumsum_col(NumericMatrix m) { for (int j = 0; j < m.ncol(); ++j) { for (int i = 1; i < m.nrow(); ++i) { m(i,

Rcpp How to generate random multivariate normal vector in Rcpp?

你说的曾经没有我的故事 提交于 2019-12-23 06:42:41
问题 I would like to generate some large random multivariate (more than 6 dimensions) normal samples. In R, many packages can do this such as rmnorm, rmvn... But the problem is the speed! So I tried to write some C code through Rcpp. I went through some tutorial online but it seems there is no "sugar" for multivariate distribution, neither in STL library. Any help is appreciated! Thanks! 回答1: I'm not sure that Rcpp will help unless you find a good algorithm to approximate your multivariate