rcpp

Link the R Package Depending on RcppEigen with MKL in Microsoft R Open

*爱你&永不变心* 提交于 2019-12-04 13:43:49
I have built a custom package with some functions written in RcppEigen. I also have Microsoft R open with Intel MKL enabled. How could I link the R package to the Intel MKL feature? Setup 1 : Below are procedures that I have tried to link the package with MKL in the normal R, but failed: The Eigen documents says I need: 1. #define EIGEN_USE_MKL_ALL 2. link your program to MKL libraries ( the MKL linking advisor ) Based on 2, in my file Makevars PKG_CXXFLAGS = -I/opt/intel/mkl/include PKG_LIBS = ${LAPACK_LIBS} ${BLAS_LIBS} ${FLIBS} -L/opt/intel/mkl/lib/intel64 -Wl,--no-as-needed -lmkl_intel

Conversion of R matrices to armadillo is really slow

若如初见. 提交于 2019-12-04 13:29:48
问题 An Observation For medium-size matrices, the overheads on passing matrices from R to C++ are massively slower for arma::mat types than for NumericMatrix types. Like taking around 250x as long. Here's a minimal example #include <RcppArmadillo.h> // [[Rcpp::depends(RcppArmadillo)]] using namespace Rcpp; using namespace arma; // [[Rcpp::export]] double test_nm( NumericMatrix X ) { return 0.0 ; } // [[Rcpp::export]] double test_arma( mat X ) { return 0.0 ; } // [[Rcpp::export]] double test_nm

Understanding `Makevars` for linking to external C library in R package

僤鯓⒐⒋嵵緔 提交于 2019-12-04 12:15:25
I am working on a package which includes C code from third-party library (SUNDIALS). The package compiles and works (i.e., is able to solve a test ODE) with the following Makevars file performing static linking CXX=clang++ PKG_CPPFLAGS = -I../inst/include PKG_LDFLAGS = /usr/local/lib PKG_LIBS= $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) $(PKG_LDFLAGS)/libsundials_cvode.a $(PKG_LDFLAGS)/libsundials_nvecserial.a However, a slightly modified version (based on the example in R-Exts, i.e. - PKG_LIBS = -L$(XML_DIR)/lib -lxml2 ) of Makevars (below) fails CXX=clang++ PKG_CPPFLAGS = -I../inst/include PKG

Why my Rcpp code is not much faster?

牧云@^-^@ 提交于 2019-12-04 12:10:07
For practicing my C++, I'm trying to convert some R code to Rcpp. The code is a greedy algorithm implemented in this answer . Next, see my Rcpp code (in a .cpp file), and some benchmark of the two codes: #include <Rcpp.h> using namespace Rcpp; // [[Rcpp::export]] List create_groups2(const NumericVector& x, double thr) { int n = x.size(); List res(n); int c = 0; double sum; std::list<double> x2(n); std::copy(x.begin(), x.end(), x2.begin()); // copy x in x2 x2.sort(std::greater<double>()); // sort in descending order std::list<double>::iterator it; NumericVector x3(n); int i = 0, c2; while (x2

Passing RInside's 'R' instance as a parameter between classes/methods

邮差的信 提交于 2019-12-04 12:09:54
I have been using Rcpp and RInside, to integrate R and C++ . We have a complex, yet well designed C++ architecture, and I am finding it difficult to access R from within just 1 function. Is it possible to pass the R instance to different Classes / functions, to get a more OOP design ? If yes, are there any examples ? To elaborate the query, I want to say that something like this, void foo(RInside& R0, int& x0) { R0.assign(x0,"totalSum"); } void foo2(RInside& R0, int& y0) { R0.assign(y0,"temp"); R0.parseEvalQ("totalSum = totalSum + temp"); } int main(int argc, char *argv[]) { RInside R(int argc

Rcpp rank function that does average ties

情到浓时终转凉″ 提交于 2019-12-04 11:53:59
I have a custom rank function that I stole from here (with some modifications) :) Rcpp sugar for rank function The problem is that it does min ties and I need average ties Here is what I have #include <Rcpp.h> using namespace Rcpp; // [[Rcpp::export]] NumericVector sort_rcpp(NumericVector x) { std::vector<double> tmp = Rcpp::as< std::vector<double> > (x); std::sort(tmp.begin(), tmp.end()); return wrap(tmp); } // [[Rcpp::export]] IntegerVector rank_(NumericVector x) { return match(x, sort_rcpp(x)); } /*** R x <- c(1:5, 1:5) rank(x, ties = 'average') rank(x, ties = 'min') rank_(x) */ After

Link error installing Rcpp “library not found for -lintl”

北城以北 提交于 2019-12-04 11:17:26
问题 I just stumbled over a linker error when trying to install some R packages which have Rcpp as a dependency. My setup is Mac OS X 10.9.1 (Mavericks), R 3.0.2 installed by Homebrew. Here's the error output: > install.packages('Rcpp') trying URL 'http://cran.fhcrc.org/src/contrib/Rcpp_0.10.6.tar.gz' Content type 'application/x-gzip' length 1985569 bytes (1.9 Mb) opened URL ================================================== downloaded 1.9 Mb * installing *source* package ‘Rcpp’ ... ** package

Rcpp sugar for rank function

大城市里の小女人 提交于 2019-12-04 10:12:27
I have been trying to get the rank of a vector in c++ using Rcpp. I have used other sugar functions like is_na(); Is there a similar sugar function for rank R function in c++. Also is there any list of available R sugar functions in Rcpp/ G. Grothendieck 1) There is an order function here and order(order(x)) is rank(x, ties = "first") . 2) A second way would be: match(x, sort(x)) ADDED Second approach. 来源: https://stackoverflow.com/questions/23606266/rcpp-sugar-for-rank-function

Rcpp Copy a vector to a vector

爷,独闯天下 提交于 2019-12-04 08:09:56
I am new to Rcpp and C++ coding in general, so forgive me for asking basic questions. The cpp part of the code is // test.cpp #include <Rcpp.h> using namespace Rcpp; // [[Rcpp::export]] void testRun() { IntegerVector Grp1 = IntegerVector::create(1,2,3,4); IntegerVector Grp2 = IntegerVector::create(3,4,5,6); Rf_PrintValue(Grp1); Grp1 = Grp2; Rf_PrintValue(Grp1); Grp2[3] = Grp2[3]+1; Rf_PrintValue(Grp1); } and when I run testrun(), I get the output > Rcpp::sourceCpp('test.cpp') > testRun() [1] 1 2 3 4 [1] 3 4 5 6 [1] 3 4 5 7 When I assign Gr2 to Gr1 in Gr1 = Gr2 , changing elements in Gr2 after

Passing R Function as Parameter to RCpp Function

做~自己de王妃 提交于 2019-12-04 08:02:23
I'm trying to run something like R my_r_function <- function(input_a) {return(input_a**3)} RunFunction(c(1,2,3), my_r_function) CPP #include <Rcpp.h> using namespace Rcpp; // [[Rcpp::export]] NumericVector RunFunction(NumericVector a, Function func) { NumericVector b = NumericVector(a.size()); for(int i=0; i<a.size(); i++) b[i] = func(a[i]); return b; } How would I make "Function func" actually work in Rcpp? P.S. I understand there are ways to do this without Rcpp (apply comes to mind for this example) but I'm just using this as an example to demonstrate what I'm looking for. You should be