Re: [Rcpp-devel] Rcpp sugar for double?

2017-02-22 Thread Dirk Eddelbuettel
Eridk, See these Rcpp Gallery article from 2012 for worked examples: - http://gallery.rcpp.org/articles/using-rmath-functions/ has an example on pnorm that applies to your dnorm case - http://gallery.rcpp.org/articles/random-number-generation/ discusses the RNGs, but the d/p/q

Re: [Rcpp-devel] Rcpp sugar for double?

2017-02-22 Thread Romain Francois
Hello, Functions in sugar only apply to vectors. For a single value, you’d have to use the dnorm function in the R:: namespace: // [[Rcpp::export]] double test6(double x){ double y = R::dnorm(x,5.0,2.0,true); return y; } > test6(3) [1] -2.112086 > dnorm(3, mean = 5, sd = 2, log = TRUE)

[Rcpp-devel] Rcpp sugar for double?

2017-02-22 Thread Eridk Poliruyt
Hi, I just tried to calculate the density of a normal variable using dnorm. I found that if the input is of type NumericVector, then it was fine. But if the input is of type double, it yielded error in compilation. For example: // [[Rcpp::export]] NumericVector test5(NumericVector x) { NumericV

Re: [Rcpp-devel] Rcpp sugar preserving attributes

2015-01-04 Thread Søren Højsgaard
gar::Vectorized_INTSXP<__SYMBOL__,NA,T>( t ) ; \ } \ } Thanks! Søren |-Original Message- |From: Dirk Eddelbuettel [mailto:[email protected]] |Sent: 4. januar 2015 21:51 |To: Søren Højsgaard |Cc: Dirk Eddelbuettel; [email protected] |Subject: RE: [Rcpp-devel] Rcpp sugar prese

Re: [Rcpp-devel] Rcpp sugar preserving attributes

2015-01-04 Thread Dirk Eddelbuettel
On 4 January 2015 at 19:58, Søren Højsgaard wrote: | Thanks! Probably a stupid question, but where are these functions defined? In math.h I see | | VECTORIZED_MATH_1(log,::log) | | but - where to look for the implementation? You mean where VECTORIZED_MATH is defined? Let me introduce you to

Re: [Rcpp-devel] Rcpp sugar preserving attributes

2015-01-04 Thread Søren Højsgaard
: Søren Højsgaard |Cc: [email protected] |Subject: Re: [Rcpp-devel] Rcpp sugar preserving attributes | | |Søren, | |Happy New Year! | |On 4 January 2015 at 09:53, Søren Højsgaard wrote: || Dear all, || || I have noticed an issue with preserving attributes (or rather |attributes that

Re: [Rcpp-devel] Rcpp sugar preserving attributes

2015-01-04 Thread Dirk Eddelbuettel
Søren, Happy New Year! On 4 January 2015 at 09:53, Søren Højsgaard wrote: | Dear all, | | I have noticed an issue with preserving attributes (or rather attributes that are not preserved). Consider this code where I take the log of an array: Quite possible. Attributes are just attached to ob

[Rcpp-devel] Rcpp sugar preserving attributes

2015-01-04 Thread Søren Højsgaard
Dear all, I have noticed an issue with preserving attributes (or rather attributes that are not preserved). Consider this code where I take the log of an array: #include using namespace Rcpp; //[[Rcpp::export]] NumericVector fun1(NumericVector x){ return log( x ); } //[[Rcpp::export]] Numer

Re: [Rcpp-devel] [RCPP Sugar] sapply function

2013-05-30 Thread Romain Francois
Le 10/05/13 17:40, Julien Duvanel a écrit : Hello again, I hope I don't disturb you too much. I have again a small question. I haven't seen the answer on your vignette, maybe this is not possible. Here's what I would like to do : /double Foo(double x, double a1, double a2) {/ /return f(x,a1,a2)

Re: [Rcpp-devel] [RCPP Sugar] sapply function

2013-05-10 Thread Julien Duvanel
Hello, Thanks for you quick answer (again!). After some research, I found the functions : Mapply_2, and Mapply_3. I'll have a look how it works. I haven't understood the second proposition but if the first one works it's fine. Have a nice evening, J. Le vendredi, 10 mai 2013 à 17:47, Roma

Re: [Rcpp-devel] [RCPP Sugar] sapply function

2013-05-10 Thread Romain Francois
Iirc we have mapply2 and mapply3. Otherwise you can make Foo a helper class instead of a function. And you embed the 3 variables in your class. Le 10 mai 2013 à 17:40, Julien Duvanel a écrit : > Hello again, > > I hope I don't disturb you too much. I have again a small question. I haven't

[Rcpp-devel] [RCPP Sugar] sapply function

2013-05-10 Thread Julien Duvanel
Hello again, I hope I don't disturb you too much. I have again a small question. I haven't seen the answer on your vignette, maybe this is not possible. Here's what I would like to do : double Foo(double x, double a1, double a2) { return f(x,a1,a2); } NumericVector myVec; sapply(myVec, Foo(

Re: [Rcpp-devel] rcpp sugar elementary question

2013-02-19 Thread Bharath Govindarajan
Thanks a lot. That helped. Regards Bharath On Tue, Feb 19, 2013 at 10:53 AM, Romain Francois wrote: > _ is defined in the Rcpp namespace, so perhaps you want to add : > > using namespace Rcpp ; > > somewhere on top. > > Also, you could use mat.row(1) instead of mat(1,_) > > Romain > > Le 19/02/1

Re: [Rcpp-devel] rcpp sugar elementary question

2013-02-19 Thread Romain Francois
_ is defined in the Rcpp namespace, so perhaps you want to add : using namespace Rcpp ; somewhere on top. Also, you could use mat.row(1) instead of mat(1,_) Romain Le 19/02/13 16:49, Bharath Govindarajan a écrit : Hi , I am trying a simple example to assign entire rows to a Rcpp::NumericMat

[Rcpp-devel] rcpp sugar elementary question

2013-02-19 Thread Bharath Govindarajan
Hi , I am trying a simple example to assign entire rows to a Rcpp::NumericMatrix. I read the Rcpp sugar document and looked at a few online examples. My simple code below produces errors: #include #include using std::cout; using std:endl; // [[Rcpp::export] void test() { Rcpp::Nume

[Rcpp-devel] Rcpp sugar

2010-06-14 Thread Romain Francois
Hello, Initially motivated by Doug's question: http://article.gmane.org/gmane.comp.lang.r.rcpp/412 and drafted quickly in : http://article.gmane.org/gmane.comp.lang.r.rcpp/422 I've added some code in Rcpp that I call "Rcpp sugar" (another name I had in mind was "Rcpp plasma". I like sugar be