rcpp

RcppArmadillo sample on armadillo vector classes

家住魔仙堡 提交于 2019-11-29 17:21:52
We have been using the sample function from RcppArmadillo to randomly sample a NumericVector object. However, we have noticed that it isn't possible to use the same function on Armadillo types ( vec or uvec ). We have looked at the function definitions from the sample.h file and it looks like a templated function that should be able to work with these types, but we haven't been able to figure out how to make it work with Armadillo classes without doing a lot of conversions to and from the NumericVector or IntegerVector types from the Rcpp library. For example, we have this function written in

Calling 'mypackage' function within public worker

别来无恙 提交于 2019-11-29 16:26:09
I know the problem I have is a thread-safety issue. As the code I have now will execute with 'seThreadOptions(1)'. My question is what would be a good practice to overcome this. I know this: Threadsafe function pointer with Rcpp and RcppParallel via std::shared_ptr Will come into play somehow. And I have also been thinking/playing around with making the internal function part of the structure for the parallel worker. Realistically, I am calling two internal functions and I would like one to be variable and the other to be constant, this tends me to think that i will need 2 solutions. The error

Can't run Rcpp function in foreach - “NULL value passed as symbol address”

↘锁芯ラ 提交于 2019-11-29 16:21:58
问题 Let me say first that I've read Writing R Extensions, the Rcpp package vignette, and that I've built a package from Rcpp.package.skeleton() . Since building my package, I added a function, multiGenerateCSVrow() , and then ran compileAttributes() on the package directory before R CMD build/R CMD install. After I load my package, I can run my function either directly or via foreach() with the %do% method. When I try to run in parallel however, I get an error: cl <- makePSOCKcluster(8)

Rcpp: my distance matrix program is slower than the function in package

我的未来我决定 提交于 2019-11-29 15:59:34
I would like to calculate the pairwise euclidean distance matrix. I wrote Rcpp programs by the suggestion of Dirk Eddelbuettel as follows NumericMatrix calcPWD1 (NumericMatrix x){ int outrows = x.nrow(); double d; NumericMatrix out(outrows,outrows); for (int i = 0 ; i < outrows - 1; i++){ for (int j = i + 1 ; j < outrows ; j ++){ NumericVector v1= x.row(i); NumericVector v2= x.row(j); NumericVector v3=v1-v2; d = sqrt(sum(pow(v3,2))); out(j,i)=d; out(i,j)=d; } } return (out) ; } But I find my program is slower than dist function. > benchmark(as.matrix(dist(b)),calcPWD1(b)) test replications

Adding an external library in R package using Rcpp

情到浓时终转凉″ 提交于 2019-11-29 15:25:44
问题 I am trying to develop an R package which uses the Sundials C library for solving differential equations. In order to not have the user install the library, I am putting the source code of the library in my package. I have put all the header files from the library in /inst/include/sundials-2.6.2 and the .c files in src/sundials-2.6.2 of my package folder. From my reading of the SO posts on this topic, sourceCpp of code in multiple files (e.g., separate .h and .cpp files should work if they

How can I use qnorm on Rcpp?

岁酱吖の 提交于 2019-11-29 14:30:59
require(inline) func <- cxxfunction(, 'return Rcpp::wrap( qnorm(0.95,0.0,1.0) );' ,plugin="Rcpp") error: no matching function for call to ‘qnorm5(double, int, int)’ require(inline) func <- cxxfunction(, 'return Rcpp::wrap( qnorm(0.95, 0.0, 1.0, 1, 0) );' ,plugin="Rcpp") error: no matching function for call to ‘qnorm5(double, double, double, int, int)’ require(inline) code <-' double a = qnorm(0.95, 0.0, 1.0); return Rcpp::wrap( a ); ' func <- cxxfunction(, code ,plugin="Rcpp") func() error: no matching function for call to ‘qnorm5(double, double, double)’ How can I use qnorm on Rcpp? By making

Rcpp Error with Xcode 5.0 and OSX 10.8.5 and R 3.0.2

跟風遠走 提交于 2019-11-29 11:26:10
I'm just trying to get Rcpp up and running on my Mac, but am struggling. I've installed the Command Line Tools. I've installed the Rcpp and inline packages. I try to run the following script in R, and get the following error. fx <- cxxfunction(signature( x = "numeric" ), 'NumericVector xx(x); return wrap( std::accumulate( xx.begin(), xx.end(), 0.0));', plugin = "Rcpp",verbose=TRUE) Error in compileCode(f, code, language = language, verbose = verbose) : Compilation ERROR, function(s)/method(s) not created! /bin/sh: llvm-g++-4.2: command not found make: *** [file2e731b1c0ff8.o] Error 127 I

Getting user input from R console: Rcpp and std::cin

坚强是说给别人听的谎言 提交于 2019-11-29 11:04:01
I have been doing some exercises to learn c++ and decided to integrate them into R since ultimately I want to write c++ backends for R functions. I am having trouble finding a solution to retrieve user input from the R console. While there is Rcpp::Rcout for printing and returning output, there doesn't seem to be a similar funciton for std::cin.... #include <Rcpp.h> // [[Rcpp::export]] Rcpp::String cola() { Rcpp::Rcout << "Pick a drink:" << std::endl << "1 - Espresso" << std::endl << "2 - Americano" << std::endl << "3 - Latte" << std::endl << "4 - Cafe dopio" << std::endl << "5 - Tea" << std:

Requiring OpenMP availability for use in an Rcpp package

泪湿孤枕 提交于 2019-11-29 09:58:31
问题 I have prepared a package in R by using RcppArmadillo and OpenMP libraries and following commands: RcppArmadillo.package.skeleton("mypackage") compileAttributes(verbose=TRUE) Also, in the DESCRIPTION file I added: Imports: Rcpp (>= 0.12.8), RcppArmadillo LinkingTo:Rcpp, RcppArmadillo Depends: RcppArmadillo and in the NAMESPACE file I added: import(RcppArmadillo) importFrom(Rcpp, evalCpp) Then I run the following codes in cmd : R CMD build mypackage R CMD INSTALL mypackage.tar.gz I build and

Matrix multiplication in Rcpp

倖福魔咒の 提交于 2019-11-29 09:26:31
问题 First of all, I am a novice user so forget my general ignorance. I am looking for a faster alternative to the %*% operator in R. Even though older posts suggest the use of RcppArmadillo, I have tried for 2 hours to make RcppArmadillo work without success. I always run into lexical issues that yield 'unexpected ...' errors. I have found the following function in Rcpp which I do can make work: library(Rcpp) func <- ' NumericMatrix mmult( NumericMatrix m , NumericMatrix v, bool byrow=true ) { if