Re: [Rcpp-devel] Segfault error during simulation in Rcpp

2013-05-06 Thread Matteo Fasiolo
Ok, I'll do exactly this and I'll report if I still encounter this problem in simpler programs. Thanks. On Mon, May 6, 2013 at 7:39 PM, Dirk Eddelbuettel wrote: > > On 6 May 2013 at 19:03, Matteo Fasiolo wrote: > | Sorry for the silly question, but since I'm using sourceCpp() too I > should't >

Re: [Rcpp-devel] Segfault error during simulation in Rcpp

2013-05-06 Thread Dirk Eddelbuettel
On 6 May 2013 at 19:03, Matteo Fasiolo wrote: | Sorry for the silly question, but since I'm using sourceCpp() too I should't | callĀ  | getRNGstate/putRNGstate, right? If you use any of the random number generators provided by R via Rcpp, then you __MUST__ also instantiate an RNGScope() object (wh

Re: [Rcpp-devel] Segfault error during simulation in Rcpp

2013-05-06 Thread Matteo Fasiolo
Thanks for the quick replies! I'm using log() and then exp() on the parameters because this function goes within an optimization routine, so I need it keep the parameters positive. Sorry for the silly question, but since I'm using sourceCpp() too I should't call getRNGstate/putRNGstate, right? I

Re: [Rcpp-devel] Segfault error during simulation in Rcpp

2013-05-06 Thread Dirk Eddelbuettel
On 6 May 2013 at 08:34, Douglas Bates wrote: | The segfaults seem to be related to PutRNGstate and I don't see that you have | declared an instance of the class that causes the RNGstate to be accessed and | restored (I have forgotten the name of the class but it should be fairly easy | to find in

Re: [Rcpp-devel] Segfault error during simulation in Rcpp

2013-05-06 Thread Dirk Eddelbuettel
Matteo, This may reveal a subtle bug somewhere in the handling of temporary expressions, with possible interactions with the garbage collection by R itself. That said, a trivial rewrite (below) which via a single sourceCpp() compiles and runs, or re-runs it, has not lead to a single segfault he

Re: [Rcpp-devel] Segfault error during simulation in Rcpp

2013-05-06 Thread Douglas Bates
The segfaults seem to be related to PutRNGstate and I don't see that you have declared an instance of the class that causes the RNGstate to be accessed and restored (I have forgotten the name of the class but it should be fairly easy to find in the examples). When you use random number generators

[Rcpp-devel] Segfault error during simulation in Rcpp

2013-05-06 Thread Matteo Fasiolo
Hi All, I am trying to simulate from the following model: Y_t = Pois( phi * N_t ); N_t = r * N_{t-1} * exp( -N_{t-1}^theta + e_t ) e_t ~ Norm(0, sigma) so I have written a Rcpp function with prototype: genRickerCpp(int days, int nSimul, int nBurn, NumericMatrix params) where: days = length o