[Rcpp-devel] RNGScope
Rodney Sparapani
rsparapa at mcw.edu
Tue Aug 14 16:17:46 CEST 2012
This is my first post so please be gentle ;o) I have been through
all of the docs that I can find (but I haven't looked at the source
code directly). Here is the behavior that I see:
> require(inline)
Loading required package: inline
> source("helper.R")
> source("corrMH.R")
>
> set.seed(66)
>
> for(i in 1:3) print(corrMH(0.2, 0.5, 100, 0))
[1] -0.07071726
[1] -8.085111
[1] -4.004675
>
> corrMH.Rcpp <- cxxfunction(
+ signature(a="numeric", b="numeric", N="numeric", x="numeric"),
+ body=cat.file("corrMH.Rcpp.cpp"), plugin="Rcpp")
>
> set.seed(66)
>
> for(i in 1:3) print(corrMH.Rcpp(0.2, 0.5, 100, 0))
[1] -0.07071726
[1] -0.07071726
[1] -0.07071726
Notice that the Rcpp version of the function returns the same value
each time (only 3 shown, but this is true no matter how many times
that you do it). I guess this is because we follow the RNGScope state
of the RNG, but we don't update it. However, updating is really needed
in this case. I hope I am making this clear. Please let me know if
you have any ideas. Thanks
Attachments seem to be allowed so I'm including my code...
Red Hat Enterprise Linux Server release 6.2 (Santiago)
g++ (GCC) 4.4.6 20110731 (Red Hat 4.4.6-3)
R version 2.14.2 (2012-02-29)
> installed.packages()["Rcpp", ]
Package LibPath
"Rcpp" "/opt/local/lib64/R/library"
Version Priority
"0.9.10" NA
Depends Imports
"R (>= 2.12.0), methods" NA
LinkingTo Suggests
NA "RUnit, inline, rbenchmark"
Enhances OS_type
NA NA
License Built
"GPL (>= 2)" "2.14.2"
--
Rodney Sparapani, PhD Center for Patient Care and Outcomes Research
Sr. Biostatistician http://www.mcw.edu/pcor
4 wheels good, 2 wheels better! Medical College of Wisconsin (MCW)
WWLD?: What Would Lombardi Do? Milwaukee, WI, USA
-------------- next part --------------
A non-text attachment was scrubbed...
Name: corrMH.Rcpp.cpp
Type: text/x-c++src
Size: 372 bytes
Desc: not available
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20120814/980323f4/attachment.cpp>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: corrMH.R
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20120814/980323f4/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: helper.R
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20120814/980323f4/attachment-0001.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: corrMH.Rcpp.test.R
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20120814/980323f4/attachment-0002.ksh>
More information about the Rcpp-devel
mailing list