[Rcpp-devel] R random numbers vs c++

Dirk Eddelbuettel edd at debian.org
Thu Mar 22 18:52:29 CET 2012


On 22 March 2012 at 10:13, Michael Hannon wrote:
| >Is there a reason to prefer Rcpp::runif over the c++ rand() for, say,
| >accepting a state in a Markov chain simulation? Is one more random than
| >another? faster?
| 
| FWIW, the random-number stuff in C++11 appears to be greatly expanded:
| 
|     http://en.wikipedia.org/wiki/C%2B%2B11#Extensible_random_number_facility
| 
| This is discussed in some more detail in, for instance:
| 
|     http://www.amazon.com/Professional-C-Wrox-Guides/dp/0470932449/ref=sr_1_1?ie=UTF8&qid=1332436173&sr=8-1
| 
| It's my understanding the Rcpp does not (yet?) support C++11.

It is a bit more nuanced. 

Romain and I jumped on a few C++11 features early but then realized that we
are bound by what CRAN has as its standard compiler setup.  And that does not
yet support C++11.  But you can of course use it locally if you add the g++
flag "-std=c++0x" --- simply don't upload a src/Makevars with that to CRAN.

With this switch, you then get this activated in RcppCommon.h:

#ifdef __GNUC__
    #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
    #ifdef __GXX_EXPERIMENTAL_CXX0X__
        #define HAS_CXX0X
        #if GCC_VERSION >= 40300
            #define HAS_VARIADIC_TEMPLATES
        #endif
        #if GCC_VERSION >= 40400
            #define HAS_INIT_LISTS
        #endif
    #endif

so if a recent g++ with -std=c++0x (which gets us __GXX_EXPERIMENTAL_CXXOX_)
is used, HAS_CXX0X is active.  

You can grep around and see what that gets tested for that.  We haven't added
much recently due to the "hold" on C++0x at CRAN.  

But to come back to the thread, yes lots of nice new things in C++11. Not
your grandma's C++.  Now the compilers just need to catch up...

Dirk

-- 
"Outside of a dog, a book is a man's best friend. Inside of a dog, it is too
dark to read." -- Groucho Marx


More information about the Rcpp-devel mailing list