Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upunconditionally get/put RNG state #825
Conversation
This comment has been minimized.
This comment has been minimized.
|
If we do this, we should probably also remove the |
|
I wanted to leave the counter there just because it's part of the API of Rcpp (in particular, they're registered routines) and I want to avoid touching anything around that interface just out of an abundance of caution. |
|
That seems ... weird. The entire block is https://github.com/RcppCore/Rcpp/blob/master/src/api.cpp#L66-L83 and the counter is not part of the interface. We could simply make it And FWIW the silversearcher agrees: edd@rob:~/git/rcpp(master)$ ag RNGScopeCounter
src/api.cpp
68: unsigned long RNGScopeCounter = 0;
73: if (RNGScopeCounter == 0) GetRNGstate();
74: RNGScopeCounter++;
75: return RNGScopeCounter;
80: RNGScopeCounter--;
81: if (RNGScopeCounter == 0) PutRNGstate();
82: return RNGScopeCounter;
edd@rob:~/git/rcpp(master)$ |
|
Sorry; I meant that I'll get rid of the counter. |
|
And I presume you and @wch tested this and ensured that it addressed the corner case seen with shiny? |
Resolves #823. With this PR, we ensure that Rcpp functions called by other Rcpp functions synchronize the RNG state.
Although @wch's example showed this through the use of
Rcpp::Function, in theory this could occur if an Rcpp function were to e.g. callsource()oreval()or another API that happened to call another Rcpp function.