[Rcpp-commits] r2266 - in pkg/Rcpp/inst: . doc/Rcpp-sugar include/Rcpp/stats/random
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Oct 3 21:33:10 CEST 2010
Author: edd
Date: 2010-10-03 21:33:09 +0200 (Sun, 03 Oct 2010)
New Revision: 2266
Modified:
pkg/Rcpp/inst/ChangeLog
pkg/Rcpp/inst/doc/Rcpp-sugar/Rcpp-sugar.Rnw
pkg/Rcpp/inst/include/Rcpp/stats/random/rbeta.h
pkg/Rcpp/inst/include/Rcpp/stats/random/rbinom.h
pkg/Rcpp/inst/include/Rcpp/stats/random/rcauchy.h
pkg/Rcpp/inst/include/Rcpp/stats/random/rchisq.h
pkg/Rcpp/inst/include/Rcpp/stats/random/rexp.h
pkg/Rcpp/inst/include/Rcpp/stats/random/rf.h
pkg/Rcpp/inst/include/Rcpp/stats/random/rgamma.h
pkg/Rcpp/inst/include/Rcpp/stats/random/rgeom.h
pkg/Rcpp/inst/include/Rcpp/stats/random/rhyper.h
pkg/Rcpp/inst/include/Rcpp/stats/random/rlnorm.h
pkg/Rcpp/inst/include/Rcpp/stats/random/rlogis.h
pkg/Rcpp/inst/include/Rcpp/stats/random/rnbinom.h
pkg/Rcpp/inst/include/Rcpp/stats/random/rnbinom_mu.h
pkg/Rcpp/inst/include/Rcpp/stats/random/rnchisq.h
pkg/Rcpp/inst/include/Rcpp/stats/random/rnorm.h
pkg/Rcpp/inst/include/Rcpp/stats/random/rpois.h
pkg/Rcpp/inst/include/Rcpp/stats/random/rsignrank.h
pkg/Rcpp/inst/include/Rcpp/stats/random/rt.h
pkg/Rcpp/inst/include/Rcpp/stats/random/runif.h
pkg/Rcpp/inst/include/Rcpp/stats/random/rweibull.h
pkg/Rcpp/inst/include/Rcpp/stats/random/rwilcox.h
Log:
added note to sugar vignette about the need to init. the RNG as per Section 6.3 of Writing R Extensions
also added a short comment to each of the corresponding header files
reinident header files while we were at it (using Emacs/ESS)
reset ChangeLog to 80 columns (using Emacs)
Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog 2010-10-02 14:47:02 UTC (rev 2265)
+++ pkg/Rcpp/inst/ChangeLog 2010-10-03 19:33:09 UTC (rev 2266)
@@ -1,30 +1,36 @@
+2010-10-03 Dirk Eddelbuettel <edd at debian.org>
+
+ * inst/include/Rcpp/stats/random/r*: Added comment reminding users
+ read up on Section 6.3 of "Writing R Extensions" and the need to
+ call GetRNGstate() and PutRNGstate() when using R's RNGs
+
2010-09-30 Romain Francois <romain at r-enthusiasts.com>
- * inst/include/Rcpp/vector/MatrixRow.h: Matrix row inherits
- VectorBase so that it becomes a sugar expression, so that we can do
- something like this:
- NumericMatrix x( ... ) ;
- NumericVector x0 = x.row(0) ;
-
+ * inst/include/Rcpp/vector/MatrixRow.h: Matrix row inherits
+ VectorBase so that it becomes a sugar expression, so that we can do
+ something like this:
+ NumericMatrix x( ... ) ;
+ NumericVector x0 = x.row(0) ;
+
* inst/include/Rcpp/vector/MatrixColumn.h: idem for columns
-
- * cleanup: run make clean in the inst/doc directory to install
+
+ * cleanup: run make clean in the inst/doc directory to install
the fake vignettes
2010-09-27 Romain Francois <romain at r-enthusiasts.com>
* inst/include/Rcpp/traits/is_sugar_expression.h: new trait class
to recognize sugar expressions
-
- * inst/include/Rcpp/vector/Vector.h: operator=( sugar expression)
- no longer allocate unnecessary memory.
+ * inst/include/Rcpp/vector/Vector.h: operator=( sugar expression)
+ no longer allocate unnecessary memory.
+
2010-09-26 Romain Francois <romain at r-enthusiasts.com>
* inst/include/Rpp/Fast.h: new helper class Rcpp::Fast that allows
faster indexing of Vector
-
- * inst/include/Rcpp/sugar/operators/plus.h: port to operator+ the same
+
+ * inst/include/Rcpp/sugar/operators/plus.h: port to operator+ the same
improvements than in operator*
2010-09-25 Romain Francois <romain at r-enthusiasts.com>
@@ -33,74 +39,79 @@
* src/Rcpp_init.c: register routines
- * R/*.R: use registration information in many .Call and .External functions
- to speed things up
+ * R/*.R: use registration information in many .Call and .External
+ functions to speed things up
* inst/include/Rcpp/RangeIndexer.h: experimenting with loop unrolling
2010-09-24 Romain Francois <romain at r-enthusiasts.com>
- * inst/include/Rcpp/sugar/Range.h : Range gains some operators (++,--,n etc ...)
+ * inst/include/Rcpp/sugar/Range.h : Range gains some
+ operators (++,--,n etc ...)
- * inst/examples/ConvolveBenchmarks/convolve3_cpp.cpp: using the new Range
- operators
+ * inst/examples/ConvolveBenchmarks/convolve3_cpp.cpp: using the new
+ Range operators
- * inst/include/Rcpp/sugar/operators/times.h: speed improvements. Not using
- pointer to member functions seems to be beneficial.
+ * inst/include/Rcpp/sugar/operators/times.h: speed improvements. Not
+ using pointer to member functions seems to be beneficial.
- * inst/include/Rcpp/sugar/nona/nona.h: sugar function that wraps a sugar
- expression in an object that pretends it does not contain any missing
- values. This allows many sugar functions and operators to use their
- fast versions when we know that the object does not contain missing values.
+ * inst/include/Rcpp/sugar/nona/nona.h: sugar function that wraps a
+ sugar expression in an object that pretends it does not contain any
+ missing values. This allows many sugar functions and operators to use
+ their fast versions when we know that the object does not contain
+ missing values.
2010-09-22 Romain Francois <romain at r-enthusiasts.com>
- * R/Module.R: set [[ and [[<- as regular methods too, which restores previous
- behavior
+ * R/Module.R: set [[ and [[<- as regular methods too, which restores
+ previous behavior
2010-09-17 Romain Francois <romain at r-enthusiasts.com>
- * src/Reference.cpp: new objects are created via a callback to R's new
- function, as R_do_new_object did always return the same environment
+ * src/Reference.cpp: new objects are created via a callback to R's
+ new function, as R_do_new_object did always return the same
+ environment
- * R/00_classes.R: new ref class C++Method to represent C++ methods and holding
- their external pointers directly (same idea as C++Field)
+ * R/00_classes.R: new ref class C++Method to represent C++ methods
+ and holding their external pointers directly (same idea as C++Field)
- * inst/include/Rcpp/Module.h: internal support for C++Method (template class
- S4_CppMethod)
+ * inst/include/Rcpp/Module.h: internal support for
+ C++Method (template class S4_CppMethod)
2010-09-16 Romain Francois <romain at r-enthusiasts.com>
* R/00_classes.R: moving classes definition here
- * inst/Rcpp/Module.h: added C++ class S4_field that builds S4 objects of
- class C++Field. Build the list of fields as part of the creation of the
- C++Class objects
+ * inst/Rcpp/Module.h: added C++ class S4_field that builds S4 objects
+ of class C++Field. Build the list of fields as part of the creation
+ of the C++Class objects
- * src/Module.cpp: .Call functions CppField__get and CppField__set to get/set
- values of an object's field using external pointers directly (no std::map
- lookup internally)
+ * src/Module.cpp: .Call functions CppField__get and CppField__set to
+ get/set values of an object's field using external pointers
+ directly (no std::map lookup internally)
* R/Module.R: (unexported) functions .getField and .setField that
call CppField__get and CppField__set
- * inst/include/Rcpp/Reference.h: skeleton for a Rcpp::Reference class that
- will help dealing with reference classes on the C++ side
+ * inst/include/Rcpp/Reference.h: skeleton for a Rcpp::Reference class
+ that will help dealing with reference classes on the C++ side
* src/Reference.cpp: implementation (needs update)
2010-09-15 Romain Francois <romain at r-enthusiasts.com>
- * DESCRIPTION: added the declaration MinimumSvnRev to control which version
- of R-devel we need so that Rcpp fully works, currently set to 52905
+ * DESCRIPTION: added the declaration MinimumSvnRev to control which
+ version of R-devel we need so that Rcpp fully works, currently set to
+ 52905
- * R/zzz.R: check the svn revision of R against the declared MinimumSvnRev
- requirement and print a message if necessary (this will only stay for the
- interim period while we develop 0.8.7 so that we all are on the same page.
+ * R/zzz.R: check the svn revision of R against the declared
+ MinimumSvnRev requirement and print a message if necessary (this will
+ only stay for the interim period while we develop 0.8.7 so that we
+ all are on the same page.
- * inst/include/Rcpp/Module.h: added methods to class_Base : methods_arity
- and methods_voidness to query the number of arguments of methods of a class
- and if the method is void
+ * inst/include/Rcpp/Module.h: added methods to class_Base :
+ methods_arity and methods_voidness to query the number of arguments
+ of methods of a class and if the method is void
* R/Module.R: implement referenceMethods (from methods) for 'C++Class'
@@ -120,23 +131,25 @@
2010-09-08 Romain Francois <romain at r-enthusiasts.com>
- * inst/include/Rcpp/Module.h : added class_Base::property_names method
- to grab the names of all fields (properties)
+ * inst/include/Rcpp/Module.h : added class_Base::property_names
+ method to grab the names of all fields (properties)
- * src/Module.cpp : added R access (.Call) function CppClass__properties
- to grab the names of the fields (property) from the XP of a class
+ * src/Module.cpp : added R access (.Call) function
+ CppClass__properties to grab the names of the fields (property) from
+ the XP of a class
- * inst/include/Rcpp/Module.h : added class_Base::property_is_readonly method
- to query if a property is read only
+ * inst/include/Rcpp/Module.h : added class_Base::property_is_readonly
+ method to query if a property is read only
- * src/Module.cpp : added R access (.Call) function CppClass__property_is_readonly
- to query if a class property is read only
+ * src/Module.cpp : added R access (.Call) function
+ CppClass__property_is_readonly to query if a class property is read
+ only
- * inst/include/Rcpp/Module.h : added class_Base::property_class method
- to grab the C++ class of a property
+ * inst/include/Rcpp/Module.h : added class_Base::property_class
+ method to grab the C++ class of a property
- * src/Module.cpp : added R access (.Call) function CppClass__property_class
- to grab the C++ class of a property
+ * src/Module.cpp : added R access (.Call) function
+ CppClass__property_class to grab the C++ class of a property
2010-09-06 Dirk Eddelbuettel <edd at debian.org>
Modified: pkg/Rcpp/inst/doc/Rcpp-sugar/Rcpp-sugar.Rnw
===================================================================
--- pkg/Rcpp/inst/doc/Rcpp-sugar/Rcpp-sugar.Rnw 2010-10-02 14:47:02 UTC (rev 2265)
+++ pkg/Rcpp/inst/doc/Rcpp-sugar/Rcpp-sugar.Rnw 2010-10-03 19:33:09 UTC (rev 2266)
@@ -443,6 +443,31 @@
% log() and log10() maybe? Or ln() ?
+\subsection{The d/q/p/q statistical functions}
+
+The framework provided by \sugar also permits easy and efficient access the
+density, distribution function, quantile and random number generation
+functions function by \proglang{R} in the \code{Rmath} library.
+
+Currently, most of these functions are vectorised for the first element which
+denote size. Consequently, these calls works in \proglang{C++} just as they
+would in \proglang{R}:
+
+<<lang=cpp>>=
+x1 = dnorm(y1, 0, 1); // density of y1 at m=0, sd=1
+x2 = pnorm(y2, 0, 1); // distribution function of y2
+x3 = qnorm(y3, 0, 1); // quantiles of y3
+x4 = rnorm(n, 0, 1); // 'n' RNG draws of N(0, 1)
+@
+
+Similar d/q/p/r functions are provided for the most common distributions:
+beta, binom, cauchy, chisq, exp, f, gamma, geom, hyper, lnorm, logis, nbeta,
+nbinom, nbinom_mu, nchisq, nf, norm, nt, pois, t, unif, and weibull.
+
+One point to note is that the programmer using these functions needs to
+initialize the state of the random number generator as detailed in Section
+6.3 of the `Writing R Extensions' manual \citep{R:Extensions}.
+
\section{Performance}
\label{sec:performance}
Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rbeta.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rbeta.h 2010-10-02 14:47:02 UTC (rev 2265)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rbeta.h 2010-10-03 19:33:09 UTC (rev 2266)
@@ -24,9 +24,12 @@
namespace Rcpp {
-inline NumericVector rbeta( int n, double a, double b ){
- return NumericVector( n, ::Rf_rbeta, a, b ) ;
-}
+ // Please make sure you to read Section 6.3 of "Writing R Extensions"
+ // about the need to call GetRNGstate() and PutRNGstate() when using
+ // the random number generators provided by R.
+ inline NumericVector rbeta( int n, double a, double b ){
+ return NumericVector( n, ::Rf_rbeta, a, b ) ;
+ }
} // Rcpp
Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rbinom.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rbinom.h 2010-10-02 14:47:02 UTC (rev 2265)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rbinom.h 2010-10-03 19:33:09 UTC (rev 2266)
@@ -24,9 +24,12 @@
namespace Rcpp {
-inline NumericVector rbinom( int n, double nin, double pp ){
- return NumericVector( n, ::Rf_rbinom, nin, pp) ;
-}
+ // Please make sure you to read Section 6.3 of "Writing R Extensions"
+ // about the need to call GetRNGstate() and PutRNGstate() when using
+ // the random number generators provided by R.
+ inline NumericVector rbinom( int n, double nin, double pp ){
+ return NumericVector( n, ::Rf_rbinom, nin, pp) ;
+ }
} // Rcpp
Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rcauchy.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rcauchy.h 2010-10-02 14:47:02 UTC (rev 2265)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rcauchy.h 2010-10-03 19:33:09 UTC (rev 2266)
@@ -67,6 +67,10 @@
} // stats
// perhaps this should go to a cpp file
+
+// Please make sure you to read Section 6.3 of "Writing R Extensions"
+// about the need to call GetRNGstate() and PutRNGstate() when using
+// the random number generators provided by R.
inline NumericVector rcauchy( int n, double location, double scale ){
if (ISNAN(location) || !R_FINITE(scale) || scale < 0)
return NumericVector( n, R_NaN ) ;
@@ -77,6 +81,9 @@
return NumericVector( n, stats::CauchyGenerator( location, scale ) ) ;
}
+// Please make sure you to read Section 6.3 of "Writing R Extensions"
+// about the need to call GetRNGstate() and PutRNGstate() when using
+// the random number generators provided by R.
inline NumericVector rcauchy( int n, double location /* , double scale [=1.0] */ ){
if (ISNAN(location))
return NumericVector( n, R_NaN ) ;
@@ -87,6 +94,9 @@
return NumericVector( n, stats::CauchyGenerator_1( location ) ) ;
}
+// Please make sure you to read Section 6.3 of "Writing R Extensions"
+// about the need to call GetRNGstate() and PutRNGstate() when using
+// the random number generators provided by R.
inline NumericVector rcauchy( int n /*, double location [=0.0] , double scale [=1.0] */ ){
return NumericVector( n, stats::CauchyGenerator_0() ) ;
}
Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rchisq.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rchisq.h 2010-10-02 14:47:02 UTC (rev 2265)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rchisq.h 2010-10-03 19:33:09 UTC (rev 2266)
@@ -23,27 +23,30 @@
#define Rcpp__stats__random_rchisq_h
namespace Rcpp {
-namespace stats {
+ namespace stats {
+
+ class ChisqGenerator : public ::Rcpp::Generator<false,double> {
+ public:
+
+ ChisqGenerator( double df_ ) : df_2(df_ / 2.0) {}
+
+ inline double operator()() const {
+ return ::Rf_rgamma( df_2, 2.0 ) ;
+ }
+
+ private:
+ double df_2 ;
+ } ;
+ } // stats
-class ChisqGenerator : public ::Rcpp::Generator<false,double> {
-public:
-
- ChisqGenerator( double df_ ) : df_2(df_ / 2.0) {}
-
- inline double operator()() const {
- return ::Rf_rgamma( df_2, 2.0 ) ;
+ // Please make sure you to read Section 6.3 of "Writing R Extensions"
+ // about the need to call GetRNGstate() and PutRNGstate() when using
+ // the random number generators provided by R.
+ inline NumericVector rchisq( int n, double df ){
+ if (!R_FINITE(df) || df < 0.0) return NumericVector(n, R_NaN) ;
+ return NumericVector( n, stats::ChisqGenerator( df ) ) ;
}
-
-private:
- double df_2 ;
-} ;
-} // stats
-inline NumericVector rchisq( int n, double df ){
- if (!R_FINITE(df) || df < 0.0) return NumericVector(n, R_NaN) ;
- return NumericVector( n, stats::ChisqGenerator( df ) ) ;
-}
-
} // Rcpp
#endif
Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rexp.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rexp.h 2010-10-02 14:47:02 UTC (rev 2265)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rexp.h 2010-10-03 19:33:09 UTC (rev 2266)
@@ -23,37 +23,40 @@
#define Rcpp__stats__random_rexp_h
namespace Rcpp {
-namespace stats {
+ namespace stats {
-class ExpGenerator : public ::Rcpp::Generator<false,double> {
-public:
+ class ExpGenerator : public ::Rcpp::Generator<false,double> {
+ public:
- ExpGenerator( double scale_ ) : scale(scale_) {}
+ ExpGenerator( double scale_ ) : scale(scale_) {}
- inline double operator()() const {
- return scale * exp_rand() ;
- }
+ inline double operator()() const {
+ return scale * exp_rand() ;
+ }
-private:
- double scale ;
-} ;
+ private:
+ double scale ;
+ } ;
-} // stats
+ } // stats
-inline NumericVector rexp( int n, double rate ){
- double scale = 1.0 / rate ;
- if (!R_FINITE(scale) || scale <= 0.0) {
- if(scale == 0.) return NumericVector( n, 0.0 ) ;
- /* else */
- return NumericVector( n, R_NaN ) ;
- }
- if( scale == 1.0 )
- return NumericVector( n, ::exp_rand ) ;
- return NumericVector( n, stats::ExpGenerator( scale ) ) ;
-}
-inline NumericVector rexp( int n){
- return NumericVector( n, ::exp_rand ) ;
-}
+ // Please make sure you to read Section 6.3 of "Writing R Extensions"
+ // about the need to call GetRNGstate() and PutRNGstate() when using
+ // the random number generators provided by R.
+ inline NumericVector rexp( int n, double rate ){
+ double scale = 1.0 / rate ;
+ if (!R_FINITE(scale) || scale <= 0.0) {
+ if(scale == 0.) return NumericVector( n, 0.0 ) ;
+ /* else */
+ return NumericVector( n, R_NaN ) ;
+ }
+ if( scale == 1.0 )
+ return NumericVector( n, ::exp_rand ) ;
+ return NumericVector( n, stats::ExpGenerator( scale ) ) ;
+ }
+ inline NumericVector rexp( int n){
+ return NumericVector( n, ::exp_rand ) ;
+ }
}
Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rf.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rf.h 2010-10-02 14:47:02 UTC (rev 2265)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rf.h 2010-10-03 19:33:09 UTC (rev 2266)
@@ -23,70 +23,73 @@
#define Rcpp__stats__random_rf_h
namespace Rcpp {
-namespace stats {
+ namespace stats {
-class FGenerator_Finite_Finite : public ::Rcpp::Generator<false,double> {
-public:
+ class FGenerator_Finite_Finite : public ::Rcpp::Generator<false,double> {
+ public:
- FGenerator_Finite_Finite( double n1_, double n2_ ) :
- n1(n1_), n2(n2_), n1__2(n1_ / 2.0 ), n2__2(n2_ / 2.0 ), ratio(n2_/n1_) {}
+ FGenerator_Finite_Finite( double n1_, double n2_ ) :
+ n1(n1_), n2(n2_), n1__2(n1_ / 2.0 ), n2__2(n2_ / 2.0 ), ratio(n2_/n1_) {}
- inline double operator()() const {
- // here we know that both n1 and n2 are finite
- // return ( ::rchisq( n1 ) / n1 ) / ( ::rchisq( n2 ) / n2 );
- return ratio * ::Rf_rgamma( n1__2, 2.0 ) / ::Rf_rgamma( n2__2, 2.0 ) ;
- }
+ inline double operator()() const {
+ // here we know that both n1 and n2 are finite
+ // return ( ::rchisq( n1 ) / n1 ) / ( ::rchisq( n2 ) / n2 );
+ return ratio * ::Rf_rgamma( n1__2, 2.0 ) / ::Rf_rgamma( n2__2, 2.0 ) ;
+ }
-private:
- double n1, n2, n1__2, n2__2, ratio ;
-} ;
+ private:
+ double n1, n2, n1__2, n2__2, ratio ;
+ } ;
-class FGenerator_NotFinite_Finite : public ::Rcpp::Generator<false,double> {
-public:
+ class FGenerator_NotFinite_Finite : public ::Rcpp::Generator<false,double> {
+ public:
- FGenerator_NotFinite_Finite( double n2_ ) : n2( n2_), n2__2(n2_ / 2.0 ) {}
+ FGenerator_NotFinite_Finite( double n2_ ) : n2( n2_), n2__2(n2_ / 2.0 ) {}
- inline double operator()() const {
- // return n2 / ::rchisq( n2 ) ;
- return n2 / ::Rf_rgamma( n2__2, 2.0 ) ;
- }
+ inline double operator()() const {
+ // return n2 / ::rchisq( n2 ) ;
+ return n2 / ::Rf_rgamma( n2__2, 2.0 ) ;
+ }
-private:
- double n2, n2__2 ;
-} ;
+ private:
+ double n2, n2__2 ;
+ } ;
-class FGenerator_Finite_NotFinite : public ::Rcpp::Generator<false,double> {
-public:
+ class FGenerator_Finite_NotFinite : public ::Rcpp::Generator<false,double> {
+ public:
- FGenerator_Finite_NotFinite( double n1_ ) : n1(n1_), n1__2(n1_ / 2.0 ) {}
+ FGenerator_Finite_NotFinite( double n1_ ) : n1(n1_), n1__2(n1_ / 2.0 ) {}
- inline double operator()() const {
- // return ::rchisq( n1 ) / n1 ;
- return ::Rf_rgamma( n1__2, 2.0 ) / n1 ;
- }
+ inline double operator()() const {
+ // return ::rchisq( n1 ) / n1 ;
+ return ::Rf_rgamma( n1__2, 2.0 ) / n1 ;
+ }
-private:
- double n1, n1__2 ;
-} ;
+ private:
+ double n1, n1__2 ;
+ } ;
-} // stats
+ } // stats
-inline NumericVector rf( int n, double n1, double n2 ){
- if (ISNAN(n1) || ISNAN(n2) || n1 <= 0. || n2 <= 0.)
- return NumericVector( n, R_NaN ) ;
- if( R_FINITE( n1 ) && R_FINITE( n2 ) ){
- return NumericVector( n, stats::FGenerator_Finite_Finite( n1, n2 ) ) ;
- } else if( ! R_FINITE( n1 ) && ! R_FINITE( n2 ) ){
- return NumericVector( n, 1.0 ) ;
- } else if( ! R_FINITE( n1 ) ) {
- return NumericVector( n, stats::FGenerator_NotFinite_Finite( n2 ) ) ;
- } else {
- return NumericVector( n, stats::FGenerator_Finite_NotFinite( n1 ) ) ;
+ // Please make sure you to read Section 6.3 of "Writing R Extensions"
+ // about the need to call GetRNGstate() and PutRNGstate() when using
+ // the random number generators provided by R.
+ inline NumericVector rf( int n, double n1, double n2 ){
+ if (ISNAN(n1) || ISNAN(n2) || n1 <= 0. || n2 <= 0.)
+ return NumericVector( n, R_NaN ) ;
+ if( R_FINITE( n1 ) && R_FINITE( n2 ) ){
+ return NumericVector( n, stats::FGenerator_Finite_Finite( n1, n2 ) ) ;
+ } else if( ! R_FINITE( n1 ) && ! R_FINITE( n2 ) ){
+ return NumericVector( n, 1.0 ) ;
+ } else if( ! R_FINITE( n1 ) ) {
+ return NumericVector( n, stats::FGenerator_NotFinite_Finite( n2 ) ) ;
+ } else {
+ return NumericVector( n, stats::FGenerator_Finite_NotFinite( n1 ) ) ;
+ }
}
-}
} // Rcpp
Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rgamma.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rgamma.h 2010-10-02 14:47:02 UTC (rev 2265)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rgamma.h 2010-10-03 19:33:09 UTC (rev 2266)
@@ -24,14 +24,17 @@
namespace Rcpp {
-inline NumericVector rgamma( int n, double a, double scale ){
- if (!R_FINITE(a) || !R_FINITE(scale) || a < 0.0 || scale <= 0.0) {
- if(scale == 0.) return NumericVector( n, 0.) ;
- return NumericVector( n, R_NaN ) ;
- }
- if( a == 0. ) return NumericVector(n, 0. ) ;
- return NumericVector( n, ::Rf_rgamma, a, scale ) ;
-}
+ // Please make sure you to read Section 6.3 of "Writing R Extensions"
+ // about the need to call GetRNGstate() and PutRNGstate() when using
+ // the random number generators provided by R.
+ inline NumericVector rgamma( int n, double a, double scale ){
+ if (!R_FINITE(a) || !R_FINITE(scale) || a < 0.0 || scale <= 0.0) {
+ if(scale == 0.) return NumericVector( n, 0.) ;
+ return NumericVector( n, R_NaN ) ;
+ }
+ if( a == 0. ) return NumericVector(n, 0. ) ;
+ return NumericVector( n, ::Rf_rgamma, a, scale ) ;
+ }
} // Rcpp
Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rgeom.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rgeom.h 2010-10-02 14:47:02 UTC (rev 2265)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rgeom.h 2010-10-03 19:33:09 UTC (rev 2266)
@@ -23,27 +23,30 @@
#define Rcpp__stats__random_rgeom_h
namespace Rcpp {
-namespace stats {
+ namespace stats {
-class GeomGenerator : public ::Rcpp::Generator<false,double> {
-public:
+ class GeomGenerator : public ::Rcpp::Generator<false,double> {
+ public:
- GeomGenerator( double p ) : lambda( (1-p)/p ) {}
+ GeomGenerator( double p ) : lambda( (1-p)/p ) {}
- inline double operator()() const {
- return ::Rf_rpois(exp_rand() * lambda);
- }
+ inline double operator()() const {
+ return ::Rf_rpois(exp_rand() * lambda);
+ }
-private:
- double lambda ;
-} ;
-} // stats
+ private:
+ double lambda ;
+ } ;
+ } // stats
-inline NumericVector rgeom( int n, double p ){
- if (!R_FINITE(p) || p <= 0 || p > 1)
- return NumericVector( n, R_NaN );
- return NumericVector( n, stats::GeomGenerator( p ) ) ;
-}
+ // Please make sure you to read Section 6.3 of "Writing R Extensions"
+ // about the need to call GetRNGstate() and PutRNGstate() when using
+ // the random number generators provided by R.
+ inline NumericVector rgeom( int n, double p ){
+ if (!R_FINITE(p) || p <= 0 || p > 1)
+ return NumericVector( n, R_NaN );
+ return NumericVector( n, stats::GeomGenerator( p ) ) ;
+ }
} // Rcpp
Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rhyper.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rhyper.h 2010-10-02 14:47:02 UTC (rev 2265)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rhyper.h 2010-10-03 19:33:09 UTC (rev 2266)
@@ -24,9 +24,12 @@
namespace Rcpp {
-inline NumericVector rhyper( int n, double nn1, double nn2, double kk ){
- return NumericVector( n, ::Rf_rhyper, nn1, nn2, kk ) ;
-}
+ // Please make sure you to read Section 6.3 of "Writing R Extensions"
+ // about the need to call GetRNGstate() and PutRNGstate() when using
+ // the random number generators provided by R.
+ inline NumericVector rhyper( int n, double nn1, double nn2, double kk ){
+ return NumericVector( n, ::Rf_rhyper, nn1, nn2, kk ) ;
+ }
} // Rcpp
Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rlnorm.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rlnorm.h 2010-10-02 14:47:02 UTC (rev 2265)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rlnorm.h 2010-10-03 19:33:09 UTC (rev 2266)
@@ -23,75 +23,84 @@
#define Rcpp__stats__random_norm_h
namespace Rcpp {
-namespace stats {
+ namespace stats {
-class LNormGenerator : public Generator<false,double> {
-public:
+ class LNormGenerator : public Generator<false,double> {
+ public:
- LNormGenerator( double meanlog_ = 0.0 , double sdlog_ = 1.0 ) :
- meanlog(meanlog_), sdlog(sdlog_) {}
+ LNormGenerator( double meanlog_ = 0.0 , double sdlog_ = 1.0 ) :
+ meanlog(meanlog_), sdlog(sdlog_) {}
- inline double operator()() const {
- return exp( meanlog + sdlog * ::norm_rand() ) ;
- }
+ inline double operator()() const {
+ return exp( meanlog + sdlog * ::norm_rand() ) ;
+ }
-private:
- double meanlog ;
- double sdlog ;
-} ;
+ private:
+ double meanlog ;
+ double sdlog ;
+ } ;
-class LNormGenerator_1 : public Generator<false,double> {
-public:
+ class LNormGenerator_1 : public Generator<false,double> {
+ public:
- LNormGenerator_1( double meanlog_ = 0.0 ) :
- meanlog(meanlog_) {}
+ LNormGenerator_1( double meanlog_ = 0.0 ) :
+ meanlog(meanlog_) {}
- inline double operator()() const {
- return exp( meanlog + ::norm_rand() ) ;
- }
+ inline double operator()() const {
+ return exp( meanlog + ::norm_rand() ) ;
+ }
-private:
- double meanlog ;
-} ;
+ private:
+ double meanlog ;
+ } ;
-class LNormGenerator_0 : public Generator<false,double> {
-public:
+ class LNormGenerator_0 : public Generator<false,double> {
+ public:
- LNormGenerator_1( ) {}
+ LNormGenerator_1( ) {}
- inline double operator()() const {
- return exp(::norm_rand() ) ;
- }
+ inline double operator()() const {
+ return exp(::norm_rand() ) ;
+ }
-} ;
+ } ;
-} // stats
+ } // stats
-inline NumericVector rlnorm( int n, double meanlog, double sdlog ){
- if (ISNAN(meanlog) || !R_FINITE(sdlog) || sdlog < 0.){
- // TODO: R also throws a warning in that case, should we ?
- return NumericVector( n, R_NaN ) ;
- } else if (sdlog == 0. || !R_FINITE(meanlog)){
- return NumericVector( n, exp( meanlog ) ) ;
- } else {
- return NumericVector( n, stats::LNormGenerator( meanlog, sdlog ) );
+ // Please make sure you to read Section 6.3 of "Writing R Extensions"
+ // about the need to call GetRNGstate() and PutRNGstate() when using
+ // the random number generators provided by R.
+ inline NumericVector rlnorm( int n, double meanlog, double sdlog ){
+ if (ISNAN(meanlog) || !R_FINITE(sdlog) || sdlog < 0.){
+ // TODO: R also throws a warning in that case, should we ?
+ return NumericVector( n, R_NaN ) ;
+ } else if (sdlog == 0. || !R_FINITE(meanlog)){
+ return NumericVector( n, exp( meanlog ) ) ;
+ } else {
+ return NumericVector( n, stats::LNormGenerator( meanlog, sdlog ) );
+ }
}
-}
-inline NumericVector rlnorm( int n, double meanlog /*, double sdlog = 1.0 */){
- if (ISNAN(meanlog) ){
- // TODO: R also throws a warning in that case, should we ?
- return NumericVector( n, R_NaN ) ;
- } else if ( !R_FINITE(meanlog)){
- return NumericVector( n, ::exp( meanlog ) ) ;
- } else {
- return NumericVector( n, stats::LNormGenerator_1( meanlog ) );
+ // Please make sure you to read Section 6.3 of "Writing R Extensions"
+ // about the need to call GetRNGstate() and PutRNGstate() when using
+ // the random number generators provided by R.
+ inline NumericVector rlnorm( int n, double meanlog /*, double sdlog = 1.0 */){
+ if (ISNAN(meanlog) ){
+ // TODO: R also throws a warning in that case, should we ?
+ return NumericVector( n, R_NaN ) ;
+ } else if ( !R_FINITE(meanlog)){
+ return NumericVector( n, ::exp( meanlog ) ) ;
+ } else {
+ return NumericVector( n, stats::LNormGenerator_1( meanlog ) );
+ }
}
-}
-inline NumericVector rlnorm( int n /*, double meanlog [=0.], double sdlog = 1.0 */){
- return NumericVector( n, stats::LNormGenerator_0( ) );
-}
+ // Please make sure you to read Section 6.3 of "Writing R Extensions"
+ // about the need to call GetRNGstate() and PutRNGstate() when using
+ // the random number generators provided by R.
+ inline NumericVector rlnorm( int n /*, double meanlog [=0.], double sdlog = 1.0 */){
+ return NumericVector( n, stats::LNormGenerator_0( ) );
+ }
} // Rcpp
Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rlogis.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rlogis.h 2010-10-02 14:47:02 UTC (rev 2265)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rlogis.h 2010-10-03 19:33:09 UTC (rev 2266)
@@ -23,76 +23,85 @@
#define Rcpp__stats__random_rlogis_h
namespace Rcpp {
-namespace stats {
+ namespace stats {
-class LogisGenerator : public ::Rcpp::Generator<false,double> {
-public:
+ class LogisGenerator : public ::Rcpp::Generator<false,double> {
+ public:
- LogisGenerator( double location_, double scale_ ) :
- location(location_), scale(scale_) {}
+ LogisGenerator( double location_, double scale_ ) :
+ location(location_), scale(scale_) {}
- inline double operator()() const {
- double u = unif_rand() ;
- return location + scale * ::log(u / (1. - u));
- }
+ inline double operator()() const {
+ double u = unif_rand() ;
+ return location + scale * ::log(u / (1. - u));
+ }
-private:
- double location ;
- double scale ;
-} ;
+ private:
+ double location ;
+ double scale ;
+ } ;
-class LogisGenerator_1 : public ::Rcpp::Generator<false,double> {
-public:
+ class LogisGenerator_1 : public ::Rcpp::Generator<false,double> {
+ public:
- LogisGenerator_1( double location_) :
- location(location_) {}
+ LogisGenerator_1( double location_) :
+ location(location_) {}
- inline double operator()() const {
- double u = unif_rand() ;
- return location + ::log(u / (1. - u));
- }
+ inline double operator()() const {
+ double u = unif_rand() ;
+ return location + ::log(u / (1. - u));
+ }
-private:
- double location ;
-} ;
+ private:
+ double location ;
+ } ;
-class LogisGenerator_0 : public ::Rcpp::Generator<false,double> {
-public:
+ class LogisGenerator_0 : public ::Rcpp::Generator<false,double> {
+ public:
- LogisGenerator_0() {}
+ LogisGenerator_0() {}
- inline double operator()() const {
- double u = unif_rand() ;
- return ::log(u / (1. - u));
- }
+ inline double operator()() const {
+ double u = unif_rand() ;
+ return ::log(u / (1. - u));
+ }
-} ;
+ } ;
-} // stats
+ } // stats
-inline NumericVector rlogis( int n, double location, double scale ){
- if (ISNAN(location) || !R_FINITE(scale))
- return NumericVector( n, R_NaN ) ;
+ // Please make sure you to read Section 6.3 of "Writing R Extensions"
+ // about the need to call GetRNGstate() and PutRNGstate() when using
+ // the random number generators provided by R.
+ inline NumericVector rlogis( int n, double location, double scale ){
+ if (ISNAN(location) || !R_FINITE(scale))
+ return NumericVector( n, R_NaN ) ;
- if (scale == 0. || !R_FINITE(location))
- return NumericVector( n, location );
+ if (scale == 0. || !R_FINITE(location))
+ return NumericVector( n, location );
- return NumericVector( n, stats::LogisGenerator( location, scale ) ) ;
-}
+ return NumericVector( n, stats::LogisGenerator( location, scale ) ) ;
+ }
-inline NumericVector rlogis( int n, double location /*, double scale =1.0 */ ){
- if (ISNAN(location) )
- return NumericVector( n, R_NaN ) ;
+ // Please make sure you to read Section 6.3 of "Writing R Extensions"
+ // about the need to call GetRNGstate() and PutRNGstate() when using
+ // the random number generators provided by R.
+ inline NumericVector rlogis( int n, double location /*, double scale =1.0 */ ){
+ if (ISNAN(location) )
+ return NumericVector( n, R_NaN ) ;
- if (!R_FINITE(location))
- return NumericVector( n, location );
+ if (!R_FINITE(location))
+ return NumericVector( n, location );
- return NumericVector( n, stats::LogisGenerator_1( location ) ) ;
-}
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/rcpp -r 2266
More information about the Rcpp-commits
mailing list