Re: [Rcpp-devel] Mersenne Twister in RcppArmadillo?

2013-02-11 Thread c s
On Sun, Feb 10, 2013 at 12:32 AM, Yan Zhou wrote: > To have Armadillo randn use MT19937 is not easy. > Since it use srand() for seed, I guess it also use C rand(), > whose quality is quite questionable. The quality of the rand() function from C depends on the implementation in libc, which varies

Re: [Rcpp-devel] Mersenne Twister in RcppArmadillo?

2013-02-11 Thread Darren Cook
> While I'd like to incorporate a Mersenne-Twister random number > generator directly in Armadillo, it would either add a dependency on > Boost, or on C++11. Boost might not be available on a user's system, > and the degree of support for C++11... I believe Boost.Random is header-only, and the bo

Re: [Rcpp-devel] Mersenne Twister in RcppArmadillo?

2013-02-11 Thread Yan Zhou
I don't think it is that simple. Boost.Random depends on a lot of things. Pull in Boost.Random means pull in Boost.TypeTraits, Boost.MPL and a lot of other things. There is tool for extract part of Boost, BCP. I tried to incorporate Boost.Random into my own library once. But the truth is that pu

Re: [Rcpp-devel] Mersenne Twister in RcppArmadillo?

2013-02-11 Thread Dirk Eddelbuettel
On 11 February 2013 at 12:17, Yan Zhou wrote: | I don't think it is that simple. Boost.Random depends on a lot of things. Pull in Boost.Random means pull in Boost.TypeTraits, Boost.MPL and a lot of other things. There is tool for extract part of Boost, BCP. I tried to incorporate Boost.Random i

Re: [Rcpp-devel] Mersenne Twister in RcppArmadillo?

2013-02-11 Thread Chris Jefferson
On 11/02/13 10:23, c s wrote: On Sun, Feb 10, 2013 at 12:32 AM, Yan Zhou wrote: To have Armadillo randn use MT19937 is not easy. Since it use srand() for seed, I guess it also use C rand(), whose quality is quite questionable. The quality of the rand() function from C depends on the implementa

[Rcpp-devel] gc() calls destructor twice when both class and XPtr deleted

2013-02-11 Thread Michael Shvartsman
Hi Rcpp-devel - In some of my code, I return an XPtr pointing to one C++ class (e.g. class A) to the R side, and then pass it back down to the C++ side in the constructor of another class (e.g. class B, which needs access to some methods in class A). If I rm() both class A and the pointer

Re: [Rcpp-devel] gc() calls destructor twice when both class and XPtr deleted

2013-02-11 Thread Dirk Eddelbuettel
On 11 February 2013 at 12:16, Michael Shvartsman wrote: | Hi Rcpp-devel - | | In some of my code, I return an XPtr pointing to one C++ class | (e.g. class A) to the R side, and then pass it back down to the C++ side | in the constructor of another class (e.g. class B, which needs access to

Re: [Rcpp-devel] gc() calls destructor twice when both class and XPtr deleted

2013-02-11 Thread Michael Shvartsman
Hi Dirk --     Thanks for the quick response. My design is (I think) textbook aggregation -- in my case, A is a logger class and B is an experiment class. The experiment calls methods from the logger, but the logger may be active for more than one experiment so it can't be created inside it.

Re: [Rcpp-devel] gc() calls destructor twice when both class and XPtr deleted

2013-02-11 Thread Yan Zhou
It seems to me that XPtr is like an ownership pointer. It is much like unique_ptr. What you need here is a non-owning reference pointer, like weak_ptr.Have you triedXPtr A::getPtr(){   return(XPtr(this, false));}With the optional argument, a finalizer is not set and the gc will not delete the C++ o

Re: [Rcpp-devel] "expecting a string" and not finding it in a CharacterVector

2013-02-11 Thread Davor Cubranic
Thank you. I'll send you unit tests for both "as" and "const ctor". Davor On 2013-02-10, at 6:06 AM, Romain Francois wrote: > > Right. I see what you mean. If it does bot disturbe anything else, i should > be able to bring it back. > > Romain > > > Le 10 févr. 2013 à 04:54, Davor Cubran

Re: [Rcpp-devel] gc() calls destructor twice when both class and XPtr deleted

2013-02-11 Thread Dirk Eddelbuettel
On 11 February 2013 at 19:10, Yan Zhou wrote: | It seems to me that XPtr is like an ownership pointer. It is much like | unique_ptr. What you need here is a non-owning reference pointer, like | weak_ptr. | | Have you tried | | XPtr A::getPtr(){ |return(XPtr(this, false)); | } | | With the o

Re: [Rcpp-devel] gc() calls destructor twice when both class and XPtr deleted

2013-02-11 Thread Michael Shvartsman
Yes, sorry for not being as quick with the follow-up, works exactly as described and perfect for my purposes. I now wonder whether I could've done this with RCPP_EXPOSED_CLASS without creating and passing around the XPtr (at least, the module in this example http://romainfrancois.blog.free