[Rcpp-devel] for loop and random draws

Dirk Eddelbuettel edd at debian.org
Tue Oct 1 19:19:22 CEST 2024


On 1 October 2024 at 11:57, Denis Haine wrote:
| But adding the regression to define_e1() (as define_e2() in previous email)
| does not give the same. The first iteration in the loop is identical in both,
| but not the subsequent ones. That's why I was thinking it could be linked to
| the seed, but (sorry for my limited knowledge of C++) it would be strange to
| manually "re-seed" at each iteration. Moreover, I believe the seed set in R is
| transferred to Rcpp and so does not need to be taken specifically care of.

Nice. So it seems to me that you identified fastglm as the source of your
problem. When we call it, your results differ and there is a side-effect.

But when we don't it is still true. I added

  Environment pkg2 = Environment::namespace_env("base");
  Function f2 = pkg2["dim"];

  // ...

      RObject ro = f2(ematrix);

while keeping the lines relevant to fastglm calls and result storage
commented out.  Now we get TRUE from all.equal(t0,t1).

That seems to rule out Rcpp::Function, and may indicate you need to look into
what fastglm may be doing.

Cheers, Dirk

-- 
dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org


More information about the Rcpp-devel mailing list