search for: numericvector

Displaying 20 results from an estimated 42 matches for "numericvector".

2013 May 14
2
invalid operands of types ‘SEXPREC*’ and ‘R_len_t’ to binary ‘operator/’ with Rcpp.
Dear R-Developers, I just started learning how to use Rcpp. Earlier while using it, I encountered an error as shown below: file74d8254b96d4.cpp: In function ‘Rcpp::NumericVector foo(Rcpp::NumericVector, Rcpp::NumericVector, Rcpp::NumericVector, Rcpp::Function, Rcpp::Function)’: file74d8254b96d4.cpp:10: error: invalid operands of types ‘SEXPREC*’ and ‘R_len_t’ to binary ‘operator/’ make: *** [file74d8254b96d4.o] Error 1 Below is a mock function that can reproduce this erro...
2011 Dec 16
0
crash in using Rcpp and inline packages.
...or",sp0="vector",phyd0="matrix", rmax0="numeric",step0="numeric",binlength0="integer"), paste(readLines("mkc.cpp"),collapse = "\n"), plugin = "Rcpp") The codes in mkc.cpp file are: NumericVector fx(fx0); NumericVector fy(fy0); NumericVector fsp(fsp0); NumericVector x(x0); NumericVector y(y0); NumericVector sp(sp0); NumericMatrix phyd(phyd0); double rmax = as<double>(rmax0); double step = as<double>(step0); double totalcout = 0.0; double totalsum = 0.0; int binlength = as<...
2011 Dec 16
0
Fw: crash in using Rcpp and inline packages.
...or",sp0="vector",phyd0="matrix", rmax0="numeric",step0="numeric",binlength0="integer"), paste(readLines("mkc.cpp"),collapse = "\n"), plugin = "Rcpp") The codes in mkc.cpp file are: NumericVector fx(fx0); NumericVector fy(fy0); NumericVector fsp(fsp0); NumericVector x(x0); NumericVector y(y0); NumericVector sp(sp0); NumericMatrix phyd(phyd0); double rmax = as<double>(rmax0); double step = as<double>(step0); double totalcout = 0.0; double totalsum = 0.0; int binlength = as<...
2015 Nov 03
1
Fwd: Rcpp sugar dpois
..." to call the function dpois since in the examples I have always found directly "dpois" or "Rcpp::dpois" that both do not work in my code. Could anyone be so patient to explain me why should it be like that? Thaks a lot, Enrico #include <Rcpp.h> using namespace Rcpp; NumericVector pcUtildedatoU(NumericVector z, double j, double par) { int l_z=z.size(); NumericVector out(l_z); for (int w=0; w<= (l_z-1); w++) { double outcand=0; double d=z[w]; if (d >= j) outcand=1; else if (d>= -j) { for...
2015 Mar 02
3
R-devel does not update the C++ returned variables
...learning curve, but I think >> | it is easier than using the low-level code that you need to work with .Call. > >> Thanks for that vote, and I second that. > >> And these days the learning is a lot flatter than it was a decade ago: > >> R> Rcpp::cppFunction("NumericVector doubleThis(NumericVector x) { return(2*x); }") >> R> doubleThis(c(1,2,3,21,-4)) >> [1] 2 4 6 42 -8 >> R> > >> That defined, compiled, loaded and run/illustrated a simple function. > >> Dirk > > Indeed impressive, ... and it also works with in...
2010 Mar 25
1
Error using Rcpp
...mic Koala and am trying to use the Rcpp package. I am testing it using a simple code that takes in a vector and adds 1 to each element: #include <Rcpp.h> // This file takes in a vector and adds one to each entry RcppExport SEXP addone(SEXP vec){ // create a local copy of vec Rcpp::NumericVector orig(vec); // create an output vector Rcpp::NumericVector vecout(orig.size()); for(i=0;i<orig.size();i++) { vecout[i] = orig[i]+1; } Rcpp::Pairlist res(Rcpp::Named("result",vecout),Rcpp::Named("original",orig)); return res; } I then try to...
2015 Mar 02
3
R-devel does not update the C++ returned variables
...| problem, not the interface. It has its own learning curve, but I think | it is easier than using the low-level code that you need to work with .Call. Thanks for that vote, and I second that. And these days the learning is a lot flatter than it was a decade ago: R> Rcpp::cppFunction("NumericVector doubleThis(NumericVector x) { return(2*x); }") R> doubleThis(c(1,2,3,21,-4)) [1] 2 4 6 42 -8 R> That defined, compiled, loaded and run/illustrated a simple function. Dirk -- http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
2017 Dec 03
5
Rcpp, dyn.load and C++ problems
...e. Anyway, This is the C++-code: #include <Rcpp.h> using namespace Rcpp; // [[Rcpp::export]] List compute_values_cpp(int totalPoints = 1e5, double angle_increment = 0.01, int radius = 400, double grow = 3.64) { double xn = 0.5; double angle = 0.1; double xn_plus_one, yn_plus_one; NumericVector x(totalPoints); NumericVector y(totalPoints); for (int i=0; i<totalPoints; i++) { xn_plus_one = xn*cos(angle)*radius; yn_plus_one = xn*sin(angle)*radius; angle += angle_increment; xn = grow*xn*(1-xn); x[i] = xn_plus_one; y[i] = yn_plus_one; } return List::create(...
2011 Dec 13
1
Rcpp too good to be true?
...return(lam^y / (factorial(y)^nu * Z(lam, nu, max))) } function in Rcpp; header file; #include <Rcpp.h> RcppExport SEXP rcomp(SEXP n_, SEXP dist_); source file; #include "rcomp.h" SEXP rcomp(SEXP n_, SEXP dist_) { using namespace Rcpp ; int n = as<int>(n_); NumericVector dist(dist_); NumericVector ans(n); int count; double pr; RNGScope scope; NumericVector u = runif(n); for (int i = 0; i < n; ++i) { count = 0; pr = dist[0]; while (pr < u[i]) { count++; pr += dist[count]; }...
2013 May 24
0
Rcpp with OpenMP - Need example Makevars
...d developing a Rcpp package "OpenMPTest". Within that package I want to use OpenMP, as in the following code example: // header file #include <omp.h> using namespace Rcpp ; RcppExport SEXP testOpenMP( SEXP nThreads ) ; // cpp file SEXP testOpenMP( SEXP nThreads ) { BEGIN_RCPP NumericVector numberThreads = NumericVector( nThreads ); omp_set_num_threads( numberThreads(0) ); #pragma omp parallel { // Code inside this region runs in parallel. printf("Hello!\n"); } END_RCPP } As I am an absolute newbie with writing C++ extensions and have not much understandi...
2010 Dec 03
1
Error using Rcpp under windows xp
...oment variables 'path' to make C:\Program Files\R\R-2.12.0\library\Rcpp\include\ searchable The sample C++ code I used is from the original website: http://dirk.eddelbuettel.com/code/rcpp.examples.html #include <Rcpp.h> RcppExport SEXP newRcppVectorExample(SEXP vector) { Rcpp::NumericVector orig(vector); // keep a copy (as the classic version does) Rcpp::NumericVector vec(orig.size()); // create a target vector of the same size // we could query size via // int n = vec.size(); // and loop over the vector, but using the STL is so much nicer // so we use a STL...
2015 Mar 02
0
R-devel does not update the C++ returned variables
...| it is easier than using the low-level code that you need to work >>> with .Call. >> >>> Thanks for that vote, and I second that. >> >>> And these days the learning is a lot flatter than it was a decade ago: >> >>> R> Rcpp::cppFunction("NumericVector doubleThis(NumericVector x) { >>> return(2*x); }") >>> R> doubleThis(c(1,2,3,21,-4)) >>> [1] 2 4 6 42 -8 >>> R> >> >>> That defined, compiled, loaded and run/illustrated a simple function. >> >>> Dirk >> >>...
2011 Apr 15
1
[Rcpp-devel] Find number of elements less than some number: Elegant/fastsolution needed
...roducing using R's sort (src1, f1-f3). If i modify SEXP in-place (and this always confuses me, so I tend to avoid it), I'm seeing an additional ~5-10% speed gain (src2, f5) -- the advantage of this last seems to be primarily in memory-constrained applications. On to the code! src = ' NumericVector xx_(clone(x)), yy_(clone(y)); int nxx = xx_.size(); int nyy = yy_.size(); arma::vec xx(xx_), yy(yy_); yy = sort(yy); xx = sort(xx); // // int j = 0; //gt index for yy for (int i=0; i < nxx; i++) { while ((j < nyy) && ( xx(i) > yy(j) ) ) { j++; } xx_(i) = j; }...
2011 Apr 14
1
Rcpp segmentation faults on the simplest code
Hi all, I'm new to R and Rcpp, and I'm trying to learn Rcpp with the simplest code possible. My goal is to be able to call R functions from C++. The code I'm trying to run is: #include #include #include #include int main(int argc, char* argv[]) { Rcpp::NumericVector v(1); return 0; } It compiles and links fine. However, as soon as I run it, it segfaults. The following is the gdb trace: &lt;co(gdb) run Starting program: /home/jingy/tmp/stl [Thread debugging using libthread_db enabled] Program received signal SIGSEGV, Segmentation fault. 0x00002aaaabb8...
2011 Oct 12
1
Error in Rcpp/inline (Windows XP)
Hi, everyone, I am just trying to use Rcpp in my computer, and I would like to try a simple example from website, but R keeps reporting me error. I am using Windows XP, and has installed Rtools and GSI. Here is the response: > src = ' + Rcpp::NumericVector xa(a); + Rcpp::NumericVector xb(b); + int n_xa = xa.size(); + int n_xb = xb.size(); + + Rcpp::NumericVector xab(n_xa + n_xb - 1); + + for (int i = 0; i < n_xa; i++) + for (int j = 0; j < n_xb; j++) + xab[i + j] += xa[i] * xb[j]; + + return xab; + ' > > fun = cxxfunction...
2017 Dec 03
0
Rcpp, dyn.load and C++ problems
...e <Rcpp.h> > using namespace Rcpp; > > // [[Rcpp::export]] > List compute_values_cpp(int totalPoints = 1e5, double angle_increment = > 0.01, int radius = 400, double grow = 3.64) { > double xn = 0.5; > double angle = 0.1; > double xn_plus_one, yn_plus_one; > NumericVector x(totalPoints); > NumericVector y(totalPoints); > > for (int i=0; i<totalPoints; i++) { > xn_plus_one = xn*cos(angle)*radius; > yn_plus_one = xn*sin(angle)*radius; > angle += angle_increment; > xn = grow*xn*(1-xn); > x[i] = xn_plus_one; > y[...
2015 Mar 02
1
R-devel does not update the C++ returned variables
...has its own learning curve, but I think | > | it is easier than using the low-level code that you need to work with .Call. | | > Thanks for that vote, and I second that. | | > And these days the learning is a lot flatter than it was a decade ago: | | > R> Rcpp::cppFunction("NumericVector doubleThis(NumericVector x) { return(2*x); }") | > R> doubleThis(c(1,2,3,21,-4)) | > [1] 2 4 6 42 -8 | > R> | | > That defined, compiled, loaded and run/illustrated a simple function. | | > Dirk | | Indeed impressive, ... and it also works with integer vectors | so...
2012 May 03
1
Setting up a windows system for rcpp
...nline. Following Dirk's advice on stackoverflow, I hope someone is able to help me. My steps were to install MinGW 32 bit first, then installing Rtools, I disabled MinGW's entry in the PATH. I am trying to get the following code to work: library(Rcpp) library(inline) body <- ' NumericVector xx(x); return wrap( std::accumulate( xx.begin(), xx.end(), 0.0));' add <- cxxfunction(signature(x = "numeric"), body, plugin = "Rcpp", verbose=T) x <- 1 y <- 2 res <- add(c(x, y)) res I get the following error messages: >> setting environment varia...
2015 Mar 02
0
R-devel does not update the C++ returned variables
...interface. It has its own learning curve, but I think > | it is easier than using the low-level code that you need to work with .Call. > Thanks for that vote, and I second that. > And these days the learning is a lot flatter than it was a decade ago: > R> Rcpp::cppFunction("NumericVector doubleThis(NumericVector x) { return(2*x); }") > R> doubleThis(c(1,2,3,21,-4)) > [1] 2 4 6 42 -8 > R> > That defined, compiled, loaded and run/illustrated a simple function. > Dirk Indeed impressive, ... and it also works with integer vectors something also not 100...
2011 Sep 13
1
Getting Rcpp SEXP data in C++
Friends I am looking at Rcpp and I am a bit stuck on a simple matter. (I am calling R from c++, if there is a better way...) Given this simple example using the TTR package and the SMA function which returns a simple moving average.... Rcpp::NumericVector rv; for(int i = 0; i < 100; i++){ rv.push_back(rand()); } Rcpp::Environment TTR("package:TTR"); Rcpp::Function sma = TTR["SMA"]; SEXP sma_res = sma(rv); How do I get the values of sma_res from a SEXP type into something useful in C++, like a vector&...