[Rcpp-commits] r4000 - in pkg/Rcpp: . inst/include/Rcpp/stats/random

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Nov 20 15:13:46 CET 2012


Author: romain
Date: 2012-11-20 15:13:46 +0100 (Tue, 20 Nov 2012)
New Revision: 4000

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/stats/random/random.h
   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:
rework r** functions: rnorm, ...

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2012-11-20 12:22:11 UTC (rev 3999)
+++ pkg/Rcpp/ChangeLog	2012-11-20 14:13:46 UTC (rev 4000)
@@ -2,6 +2,10 @@
 
         * include/Rcpp/iostream/Rostream.h: change order of initiaization in 
         ctor. was making solaris compiler unhappy
+        * include/Rcpp/stats/random/rnorm.h: not using function pointer
+        generators, as this generates (anachronisms) warning on solaris. Also, 
+        this version is more efficient since there is no need to dereference
+        the function pointer
 
 2012-11-19  JJ Allaire <jj at rstudio.org>
 

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/random.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/random.h	2012-11-20 12:22:11 UTC (rev 3999)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/random.h	2012-11-20 14:13:46 UTC (rev 4000)
@@ -2,7 +2,7 @@
 //
 // random.h: Rcpp R/C++ interface class library -- 
 //
-// Copyright (C) 2010 - 2011 Douglas Bates, Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Douglas Bates, Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rbeta.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rbeta.h	2012-11-20 12:22:11 UTC (rev 3999)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rbeta.h	2012-11-20 14:13:46 UTC (rev 4000)
@@ -2,7 +2,7 @@
 //
 // rbeta.h: Rcpp R/C++ interface class library -- 
 //
-// Copyright (C) 2010 - 2011 Douglas Bates, Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Douglas Bates, Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -23,12 +23,27 @@
 #define Rcpp__stats__random_rbeta_h
 
 namespace Rcpp {
+namespace stats{
+    
+    template <bool seed>
+    class BetaGenerator : public Generator<seed,double>{
+    public: 
+        BetaGenerator(double a_, double b_) : a(a), b(b_){}
+        
+        inline double operator()() const {
+            return ::Rf_rbeta(a, b) ;    
+        }
+    private:
+        double a, b ;
+    } ;
+    
+} // namespace stats
 
 	// 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 ) ;
+		return NumericVector( n, stats::BetaGenerator<false>(a, b ) ) ;
 	}
 
 } // Rcpp

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rbinom.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rbinom.h	2012-11-20 12:22:11 UTC (rev 3999)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rbinom.h	2012-11-20 14:13:46 UTC (rev 4000)
@@ -2,7 +2,7 @@
 //
 // rbinom.h: Rcpp R/C++ interface class library -- 
 //
-// Copyright (C) 2010 - 2011 Douglas Bates, Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Douglas Bates, Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -23,12 +23,27 @@
 #define Rcpp__stats__random_rbinom_h
 
 namespace Rcpp {
-
+namespace stats {
+    
+    template <bool seed> 
+    class BinomGenerator : public Generator<seed,double>{
+    public:
+        BinomGenerator( double nin_, double pp_ ) : nin(nin_), pp(pp_){}
+        inline double operator()() const{
+            return ::Rf_rbinom( nin, pp ) ;    
+        }
+    private:
+        double nin, pp ;
+    } ;
+    
+}  // stats
+    
+    
 	// 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) ;
+		return NumericVector( n, stats::BinomGenerator<false>(nin, pp) ) ;
 	}
 
 } // Rcpp

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rcauchy.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rcauchy.h	2012-11-20 12:22:11 UTC (rev 3999)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rcauchy.h	2012-11-20 14:13:46 UTC (rev 4000)
@@ -2,7 +2,7 @@
 //
 // rcauchy.h: Rcpp R/C++ interface class library -- 
 //
-// Copyright (C) 2010 - 2011 Douglas Bates, Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Douglas Bates, Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -25,7 +25,8 @@
 namespace Rcpp {
 namespace stats {
 
-class CauchyGenerator : public ::Rcpp::Generator<false,double> {
+template <bool seed>
+class CauchyGenerator : public ::Rcpp::Generator<seed,double> {
 public:
 	
 	CauchyGenerator( double location_, double scale_) : 
@@ -39,7 +40,8 @@
 	double location, scale ;
 } ;
 
-class CauchyGenerator_1 : public ::Rcpp::Generator<false,double> {
+template <bool seed>
+class CauchyGenerator_1 : public ::Rcpp::Generator<seed,double> {
 public:
 	
 	CauchyGenerator_1( double location_) : 
@@ -53,6 +55,7 @@
 	double location ;
 } ;
 
+template <bool seed>
 class CauchyGenerator_0 : public ::Rcpp::Generator<false,double> {
 public:
 	
@@ -78,7 +81,7 @@
     if (scale == 0. || !R_FINITE(location))
     	return NumericVector( n, location ) ;
     
-	return NumericVector( n, stats::CauchyGenerator( location, scale ) ) ;
+	return NumericVector( n, stats::CauchyGenerator<false>( location, scale ) ) ;
 }
 
 // Please make sure you to read Section 6.3 of "Writing R Extensions"
@@ -91,14 +94,14 @@
     if (!R_FINITE(location))
     	return NumericVector( n, location ) ;
     
-	return NumericVector( n, stats::CauchyGenerator_1( location ) ) ;
+	return NumericVector( n, stats::CauchyGenerator_1<false>( 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() ) ;
+	return NumericVector( n, stats::CauchyGenerator_0<false>() ) ;
 }
 
 } // Rcpp

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rchisq.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rchisq.h	2012-11-20 12:22:11 UTC (rev 3999)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rchisq.h	2012-11-20 14:13:46 UTC (rev 4000)
@@ -2,7 +2,7 @@
 //
 // rchisq.h: Rcpp R/C++ interface class library -- 
 //
-// Copyright (C) 2010 - 2011 Douglas Bates, Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Douglas Bates, Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -25,7 +25,8 @@
 namespace Rcpp {
 	namespace stats {
 		
-		class ChisqGenerator : public ::Rcpp::Generator<false,double> {
+	    template <bool seed>
+		class ChisqGenerator : public ::Rcpp::Generator<seed,double> {
 		public:
 			
 			ChisqGenerator( double df_ ) : df_2(df_ / 2.0) {}
@@ -44,7 +45,7 @@
 	// 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 ) ) ;
+		return NumericVector( n, stats::ChisqGenerator<false>( df ) ) ;
 	}
 
 } // Rcpp

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rexp.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rexp.h	2012-11-20 12:22:11 UTC (rev 3999)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rexp.h	2012-11-20 14:13:46 UTC (rev 4000)
@@ -2,7 +2,7 @@
 //
 // rexp.h: Rcpp R/C++ interface class library -- 
 //
-// Copyright (C) 2010 - 2011 Douglas Bates, Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Douglas Bates, Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -25,7 +25,8 @@
 namespace Rcpp {
 	namespace stats {
 
-		class ExpGenerator : public ::Rcpp::Generator<false,double> {
+	    template <bool seed>
+		class ExpGenerator : public ::Rcpp::Generator<seed,double> {
 		public:
 	
 			ExpGenerator( double scale_ ) : scale(scale_) {}
@@ -37,6 +38,13 @@
 		private:
 			double scale ;
 		} ;
+		
+		template <bool seed>
+		class ExpGenerator__rate1 : public Generator<seed,double>{
+		public:
+		    ExpGenerator__rate1(){}
+		    inline double operator()() const { return exp_rand() ; }
+		} ;
 
 	} // stats
 
@@ -50,12 +58,10 @@
 			/* else */
 			return NumericVector( n, R_NaN ) ;
 		}
-		if( scale == 1.0 )
-			return NumericVector( n, ::exp_rand ) ;
-		return NumericVector( n, stats::ExpGenerator( scale ) ) ;
+		return NumericVector( n, stats::ExpGenerator<false>( scale ) ) ;
 	}
-	inline NumericVector rexp( int n){
-		return NumericVector( n, ::exp_rand ) ;
+	inline NumericVector rexp( int n /* , rate = 1 */ ){
+		return NumericVector( n, stats::ExpGenerator__rate1<false>() ) ;
 	}
 
 }

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rf.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rf.h	2012-11-20 12:22:11 UTC (rev 3999)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rf.h	2012-11-20 14:13:46 UTC (rev 4000)
@@ -2,7 +2,7 @@
 //
 // rf.h: Rcpp R/C++ interface class library -- 
 //
-// Copyright (C) 2010 - 2011 Douglas Bates, Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Douglas Bates, Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -25,8 +25,8 @@
 namespace Rcpp {
 	namespace stats {
 
-
-		class FGenerator_Finite_Finite : public ::Rcpp::Generator<false,double> {
+	    template <bool seed>
+		class FGenerator_Finite_Finite : public ::Rcpp::Generator<seed,double> {
 		public:
 	
 			FGenerator_Finite_Finite( double n1_, double n2_ ) : 
@@ -42,8 +42,8 @@
 			double n1, n2, n1__2, n2__2, ratio ;
 		} ;
 
-
-		class FGenerator_NotFinite_Finite : public ::Rcpp::Generator<false,double> {
+		template <bool seed>
+		class FGenerator_NotFinite_Finite : public ::Rcpp::Generator<seed,double> {
 		public:
 	
 			FGenerator_NotFinite_Finite( double n2_ ) : n2( n2_), n2__2(n2_ / 2.0 ) {}
@@ -57,8 +57,8 @@
 			double n2, n2__2 ;
 		} ;
 
-
-		class FGenerator_Finite_NotFinite : public ::Rcpp::Generator<false,double> {
+		template <bool seed>
+		class FGenerator_Finite_NotFinite : public ::Rcpp::Generator<seed,double> {
 		public:
 	
 			FGenerator_Finite_NotFinite( double n1_ ) : n1(n1_), n1__2(n1_ / 2.0 ) {}
@@ -81,13 +81,13 @@
 		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 ) ) ;
+			return NumericVector( n, stats::FGenerator_Finite_Finite<false>( 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 ) ) ;
+			return NumericVector( n, stats::FGenerator_NotFinite_Finite<false>( n2 ) ) ;
 		} else {
-			return NumericVector( n, stats::FGenerator_Finite_NotFinite( n1 ) ) ;	
+			return NumericVector( n, stats::FGenerator_Finite_NotFinite<false>( n1 ) ) ;	
 		}
 	}
 

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rgamma.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rgamma.h	2012-11-20 12:22:11 UTC (rev 3999)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rgamma.h	2012-11-20 14:13:46 UTC (rev 4000)
@@ -1,8 +1,8 @@
 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
 //
-// rgammah: Rcpp R/C++ interface class library -- 
+// rgamma.h: Rcpp R/C++ interface class library -- 
 //
-// Copyright (C) 2010 - 2011 Douglas Bates, Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Douglas Bates, Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -23,7 +23,19 @@
 #define Rcpp__stats__random_rgamma_h
 
 namespace Rcpp {
-
+    namespace stats {
+        template <bool seed>
+        class GammaGenerator : public Generator<seed,double>{
+        public:
+            GammaGenerator(double a_, double scale_) : 
+                a(a_), scale(scale_) {}
+            inline double operator()() const { return ::Rf_rgamma(a, scale ) ;}    
+        private:
+            double a, scale ;
+        } ;
+    }    // stats
+    
+    
 	// 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.
@@ -33,8 +45,17 @@
 			return NumericVector( n, R_NaN ) ;
 		}
 		if( a == 0. ) return NumericVector(n, 0. ) ;
-		return NumericVector( n, ::Rf_rgamma, a, scale ) ;
-	}
+		return NumericVector( n, stats::GammaGenerator<false>(a, scale) ) ;
+	} 
+	inline NumericVector rgamma( int n, double a /* scale = 1.0 */ ){
+		if (!R_FINITE(a) || a < 0.0 ) {
+			return NumericVector( n, R_NaN ) ;
+		}
+		if( a == 0. ) return NumericVector(n, 0. ) ;
+		/* TODO: check if we can take advantage of the scale = 1 special case */
+		return NumericVector( n, stats::GammaGenerator<false>(a, 1.0) ) ;
+	} 
+	
 
 } // Rcpp
 

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rgeom.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rgeom.h	2012-11-20 12:22:11 UTC (rev 3999)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rgeom.h	2012-11-20 14:13:46 UTC (rev 4000)
@@ -2,7 +2,7 @@
 //
 // rgeom.h: Rcpp R/C++ interface class library -- 
 //
-// Copyright (C) 2010 - 2011 Douglas Bates, Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Douglas Bates, Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -25,7 +25,8 @@
 namespace Rcpp {
 	namespace stats {
 
-		class GeomGenerator : public ::Rcpp::Generator<false,double> {
+	    template <bool seed>
+		class GeomGenerator : public ::Rcpp::Generator<seed,double> {
 		public:
 	
 			GeomGenerator( double p ) : lambda( (1-p)/p  ) {}
@@ -45,7 +46,7 @@
 	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 ) ) ;
+		return NumericVector( n, stats::GeomGenerator<false>( p ) ) ;
 	}
 
 } // Rcpp

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rhyper.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rhyper.h	2012-11-20 12:22:11 UTC (rev 3999)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rhyper.h	2012-11-20 14:13:46 UTC (rev 4000)
@@ -2,7 +2,7 @@
 //
 // rhyper.h: Rcpp R/C++ interface class library -- 
 //
-// Copyright (C) 2010 - 2011 Douglas Bates, Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Douglas Bates, Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -23,12 +23,23 @@
 #define Rcpp__stats__random_rhyper_h
 
 namespace Rcpp {
-
+    namespace stats {
+        template <bool seed>
+        class HyperGenerator : public Generator<seed,double>{
+        public:
+            HyperGenerator( double nn1_, double nn2_, double kk_) : 
+                nn1(nn1_), nn2(nn2_), kk(kk_){}
+            inline double operator()() const { return ::Rf_rhyper(nn1, nn2, kk) ;}  
+        private:
+            double 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 ) ;
+		return NumericVector( n, stats::HyperGenerator<false>( nn1, nn2, kk ) ) ;
 	}
 
 } // Rcpp

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rlnorm.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rlnorm.h	2012-11-20 12:22:11 UTC (rev 3999)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rlnorm.h	2012-11-20 14:13:46 UTC (rev 4000)
@@ -2,7 +2,7 @@
 //
 // rlnorm.h: Rcpp R/C++ interface class library -- 
 //
-// Copyright (C) 2010 - 2011 Douglas Bates, Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Douglas Bates, Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -25,7 +25,8 @@
 namespace Rcpp {
 	namespace stats {
 
-		class LNormGenerator : public Generator<false,double> {
+	    template <bool seed>
+		class LNormGenerator : public Generator<seed,double> {
 		public:
 	
 			LNormGenerator( double meanlog_ = 0.0 , double sdlog_ = 1.0 ) : 
@@ -40,7 +41,8 @@
 			double sdlog ;
 		} ;
 
-		class LNormGenerator_1 : public Generator<false,double> {
+		template <bool seed>
+		class LNormGenerator_1 : public Generator<seed,double> {
 		public:
 	
 			LNormGenerator_1( double meanlog_ = 0.0 ) : 
@@ -54,7 +56,8 @@
 			double meanlog ;
 		} ;
 
-		class LNormGenerator_0 : public Generator<false,double> {
+		template <bool seed>
+		class LNormGenerator_0 : public Generator<seed,double> {
 		public:
 	
 			LNormGenerator_0( ) {}
@@ -77,7 +80,7 @@
 		}  else if (sdlog == 0. || !R_FINITE(meanlog)){
 			return NumericVector( n, ::exp( meanlog ) ) ;
 		} else {
-			return NumericVector( n, stats::LNormGenerator( meanlog, sdlog ) ); 
+			return NumericVector( n, stats::LNormGenerator<false>( meanlog, sdlog ) ); 
 		}
 	}
 
@@ -91,7 +94,7 @@
 		}  else if ( !R_FINITE(meanlog)){
 			return NumericVector( n, ::exp( meanlog ) ) ;
 		} else {
-			return NumericVector( n, stats::LNormGenerator_1( meanlog ) ); 
+			return NumericVector( n, stats::LNormGenerator_1<false>( meanlog ) ); 
 		}
 	}
 
@@ -99,7 +102,7 @@
 	// 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( ) ); 
+		return NumericVector( n, stats::LNormGenerator_0<false>( ) ); 
 	}
 
 

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rlogis.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rlogis.h	2012-11-20 12:22:11 UTC (rev 3999)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rlogis.h	2012-11-20 14:13:46 UTC (rev 4000)
@@ -2,7 +2,7 @@
 //
 // rlogis.h: Rcpp R/C++ interface class library -- 
 //
-// Copyright (C) 2010 - 2011 Douglas Bates, Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Douglas Bates, Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -24,8 +24,9 @@
 
 namespace Rcpp {
 	namespace stats {
-
-		class LogisGenerator : public ::Rcpp::Generator<false,double> {
+	    
+	    template <bool seed>
+		class LogisGenerator : public ::Rcpp::Generator<seed,double> {
 		public:
 	
 			LogisGenerator( double location_, double scale_ ) : 
@@ -41,7 +42,8 @@
 			double scale ;
 		} ;
 
-		class LogisGenerator_1 : public ::Rcpp::Generator<false,double> {
+		template <bool seed>
+		class LogisGenerator_1 : public ::Rcpp::Generator<seed,double> {
 		public:
 	
 			LogisGenerator_1( double location_) : 
@@ -56,7 +58,8 @@
 			double location ;
 		} ;
 
-		class LogisGenerator_0 : public ::Rcpp::Generator<false,double> {
+		template <bool seed>
+		class LogisGenerator_0 : public ::Rcpp::Generator<seed,double> {
 		public:
 	
 			LogisGenerator_0() {}
@@ -80,7 +83,7 @@
 		if (scale == 0. || !R_FINITE(location))
 			return NumericVector( n, location );
     
-		return NumericVector( n, stats::LogisGenerator( location, scale ) ) ;
+		return NumericVector( n, stats::LogisGenerator<false>( location, scale ) ) ;
 	}
 
 	// Please make sure you to read Section 6.3 of "Writing R Extensions"
@@ -93,14 +96,14 @@
 		if (!R_FINITE(location))
 			return NumericVector( n, location );
     
-		return NumericVector( n, stats::LogisGenerator_1( location ) ) ;
+		return NumericVector( n, stats::LogisGenerator_1<false>( 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 rlogis( int n /*, double location [=0.0], double scale =1.0 */ ){
-		return NumericVector( n, stats::LogisGenerator_0() ) ;
+		return NumericVector( n, stats::LogisGenerator_0<false>() ) ;
 	}
 
 } // Rcpp

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rnbinom.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rnbinom.h	2012-11-20 12:22:11 UTC (rev 3999)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rnbinom.h	2012-11-20 14:13:46 UTC (rev 4000)
@@ -2,7 +2,7 @@
 //
 // rnbinom.h: Rcpp R/C++ interface class library -- 
 //
-// Copyright (C) 2010 - 2011 Douglas Bates, Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Douglas Bates, Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -25,7 +25,8 @@
 namespace Rcpp {
 	namespace stats {
 
-		class NBinomGenerator : public ::Rcpp::Generator<false,double> {
+	    template <bool seed>
+		class NBinomGenerator : public ::Rcpp::Generator<seed,double> {
 		public:
 	
 			NBinomGenerator( double siz_, double prob_ ) : 
@@ -49,7 +50,7 @@
 			/* prob = 1 is ok, PR#1218 */
 			return NumericVector( n, R_NaN ) ;
     
-		return NumericVector( n, stats::NBinomGenerator( siz, prob ) ) ;
+		return NumericVector( n, stats::NBinomGenerator<false>( siz, prob ) ) ;
 	}
 
 } // Rcpp

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rnbinom_mu.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rnbinom_mu.h	2012-11-20 12:22:11 UTC (rev 3999)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rnbinom_mu.h	2012-11-20 14:13:46 UTC (rev 4000)
@@ -25,7 +25,8 @@
 namespace Rcpp {
 	namespace stats {
 
-		class NBinomGenerator_Mu : public ::Rcpp::Generator<false,double> {
+	    template <bool seed>
+		class NBinomGenerator_Mu : public ::Rcpp::Generator<seed,double> {
 		public:
 	
 			NBinomGenerator_Mu( double siz_, double mu_ ) : 
@@ -48,7 +49,7 @@
 		if(!R_FINITE(siz) || !R_FINITE(mu) || siz <= 0 || mu < 0)
 			return NumericVector( n, R_NaN ) ;
     
-		return NumericVector( n, stats::NBinomGenerator_Mu( siz, mu ) ) ;
+		return NumericVector( n, stats::NBinomGenerator_Mu<false>( siz, mu ) ) ;
 	}
 
 } // Rcpp

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rnchisq.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rnchisq.h	2012-11-20 12:22:11 UTC (rev 3999)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rnchisq.h	2012-11-20 14:13:46 UTC (rev 4000)
@@ -2,7 +2,7 @@
 //
 // rnchisq.h: Rcpp R/C++ interface class library -- 
 //
-// Copyright (C) 2010 - 2011 Douglas Bates, Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Douglas Bates, Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -25,7 +25,8 @@
 namespace Rcpp {
 	namespace stats {
 
-		class NChisqGenerator : public ::Rcpp::Generator<false,double> {
+		template <bool seed>
+		class NChisqGenerator : public ::Rcpp::Generator<seed,double> {
 		public:
 	
 			NChisqGenerator( double df_, double lambda_ ) : 
@@ -57,9 +58,9 @@
 			return NumericVector(n, R_NaN) ;
 		if( lambda == 0.0 ){
 			// using the central generator, see rchisq.h
-			return NumericVector( n, stats::ChisqGenerator( df ) ) ;
+			return NumericVector( n, stats::ChisqGenerator<false>( df ) ) ;
 		}
-		return NumericVector( n, stats::NChisqGenerator( df, lambda ) ) ;
+		return NumericVector( n, stats::NChisqGenerator<false>( df, lambda ) ) ;
 	}
 
 	// Please make sure you to read Section 6.3 of "Writing R Extensions"
@@ -68,7 +69,7 @@
 	inline NumericVector rnchisq( int n, double df /*, double lambda = 0.0 */ ){
 		if (!R_FINITE(df) || df < 0. ) 
 			return NumericVector(n, R_NaN) ;
-		return NumericVector( n, stats::ChisqGenerator( df ) ) ;
+		return NumericVector( n, stats::ChisqGenerator<false>( df ) ) ;
 	}
 
 } // Rcpp

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rnorm.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rnorm.h	2012-11-20 12:22:11 UTC (rev 3999)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rnorm.h	2012-11-20 14:13:46 UTC (rev 4000)
@@ -2,7 +2,7 @@
 //
 // rnorm.h: Rcpp R/C++ interface class library -- 
 //
-// Copyright (C) 2010 - 2011 Douglas Bates, Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Douglas Bates, Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -25,7 +25,8 @@
 namespace Rcpp {
 	namespace stats {
 
-		class NormGenerator : public Generator<false,double> {
+	    template <bool seed>
+		class NormGenerator : public Generator<seed,double> {
 		public:
 	
 			NormGenerator( double mean_ = 0.0 , double sd_ = 1.0 ) : 
@@ -41,7 +42,8 @@
 		} ;
 
 
-		class NormGenerator__sd1 : public Generator<false,double> {
+		template <bool seed>
+		class NormGenerator__sd1 : public Generator<seed,double> {
 		public:
 	
 			NormGenerator__sd1( double mean_ = 0.0 ) : mean(mean_) {}
@@ -55,7 +57,8 @@
 		} ;
 
 
-		class NormGenerator__mean0 : public Generator<false,double> {
+		template <bool seed>
+		class NormGenerator__mean0 : public Generator<seed,double> {
 		public:
 	
 			NormGenerator__mean0( double sd_ = 1.0 ) : sd(sd_) {}
@@ -68,7 +71,18 @@
 			double sd ;
 		} ;
 
-
+		template <bool seed>
+		class NormGenerator__mean0__sd1 : public Generator<seed,double> {
+		public:
+	
+			NormGenerator__mean0__sd1( ) {}
+	
+			inline double operator()() const {
+				return ::norm_rand() ;
+			}
+	
+		} ;
+		
 	} // stats
 
 	// Please make sure you to read Section 6.3 of "Writing R Extensions"
@@ -84,14 +98,14 @@
 			bool sd1 = sd == 1.0 ; 
 			bool mean0 = mean == 0.0 ;
 			if( sd1 && mean0 ){
-				return NumericVector( n, norm_rand ) ;
+				return NumericVector( n, stats::NormGenerator__mean0__sd1<false>() ) ;
 			} else if( sd1 ){
-				return NumericVector( n, stats::NormGenerator__sd1( mean ) );
+				return NumericVector( n, stats::NormGenerator__sd1<false>( mean ) );
 			} else if( mean0 ){
-				return NumericVector( n, stats::NormGenerator__mean0( sd ) );
+				return NumericVector( n, stats::NormGenerator__mean0<false>( sd ) );
 			} else {
 				// general case
-				return NumericVector( n, stats::NormGenerator( mean, sd ) );
+				return NumericVector( n, stats::NormGenerator<false>( mean, sd ) );
 			}
 		}
 	}
@@ -108,9 +122,9 @@
 		} else {
 			bool mean0 = mean == 0.0 ;
 			if( mean0 ){
-				return NumericVector( n, norm_rand ) ;
+				return NumericVector( n, stats::NormGenerator__mean0__sd1<false>() ) ;
 			} else {
-				return NumericVector( n, stats::NormGenerator__sd1( mean ) );
+				return NumericVector( n, stats::NormGenerator__sd1<false>( mean ) );
 			}
 		}
 	}
@@ -119,7 +133,7 @@
 	// about the need to call GetRNGstate() and PutRNGstate() when using 
 	// the random number generators provided by R.
 	inline NumericVector rnorm( int n /*, double mean [=0.0], double sd [=1.0] */ ){
-		return NumericVector( n, norm_rand ) ;
+		return NumericVector( n, stats::NormGenerator<false>() ) ;
 	}
 
 } // Rcpp

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rpois.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rpois.h	2012-11-20 12:22:11 UTC (rev 3999)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rpois.h	2012-11-20 14:13:46 UTC (rev 4000)
@@ -2,7 +2,7 @@
 //
 // rpois.h: Rcpp R/C++ interface class library -- 
 //
-// Copyright (C) 2010 - 2011 Douglas Bates, Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Douglas Bates, Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -23,12 +23,23 @@
 #define Rcpp__stats__random_rpois_h
 
 namespace Rcpp {
-
+    namespace stats{
+        
+        template <bool seed>
+    	class PoissonGenerator : public Generator<seed,double>{
+    	public:
+    	    PoissonGenerator( double mu_ ) : mu(mu_){}  
+    	    inline double operator()() const { return ::Rf_rpois(mu); }
+    	private:
+    	    double mu ;
+    	} ;
+    }  // stats
+    
 	// 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 rpois( int n, double mu ){
-		return NumericVector( n, ::Rf_rpois, mu ) ;
+		return NumericVector( n, stats::PoissonGenerator<false>(mu) ) ;
 	}
 
 } // Rcpp

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rsignrank.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rsignrank.h	2012-11-20 12:22:11 UTC (rev 3999)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rsignrank.h	2012-11-20 14:13:46 UTC (rev 4000)
@@ -2,7 +2,7 @@
 //
 // rsignrank.h: Rcpp R/C++ interface class library -- 
 //
-// Copyright (C) 2010 - 2011 Douglas Bates, Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012 Douglas Bates, Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //
@@ -23,12 +23,23 @@
 #define Rcpp__stats__random_rsignrank_h
 
 namespace Rcpp {
-
+    namespace stats{
+    
+        template <bool seed>
+		class SignRankGenerator : public Generator<seed,double>{
+		public:
+		    SignRankGenerator(double nn_) : nn(nn_){}
+		    inline double operator()() const { return ::Rf_rsignrank(nn) ; }
+		private:
+		    double nn ;
+		} ;
+    } // stats
+    
 	// 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 rsignrank( int n, double nn ){
-		return NumericVector( n, ::Rf_rsignrank, nn ) ;
+		return NumericVector( n, stats::SignRankGenerator<false>(nn) ) ;
 	}
 
 } // Rcpp

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rt.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rt.h	2012-11-20 12:22:11 UTC (rev 3999)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rt.h	2012-11-20 14:13:46 UTC (rev 4000)
@@ -25,7 +25,8 @@
 namespace Rcpp {
 	namespace stats {
 
-		class TGenerator : public ::Rcpp::Generator<false,double> {
+	    template <bool seed>
+		class TGenerator : public ::Rcpp::Generator<seed,double> {
 		public:
 	
 			TGenerator( double df_ ) : df(df_), df_2(df_/2.0) {}
@@ -56,10 +57,10 @@
 	
 		// just generating a N(0,1)
 		if(!R_FINITE(df))
-			return NumericVector( n, norm_rand ) ;
+			return NumericVector( n, stats::NormGenerator__mean0__sd1<false>() ) ;
 	
 		// general case
-		return NumericVector( n, stats::TGenerator( df ) ) ;
+		return NumericVector( n, stats::TGenerator<false>( df ) ) ;
 	}
 
 } // Rcpp

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/runif.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/runif.h	2012-11-20 12:22:11 UTC (rev 3999)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/runif.h	2012-11-20 14:13:46 UTC (rev 4000)
@@ -25,7 +25,8 @@
 namespace Rcpp {
 	namespace stats {
 
-		class UnifGenerator : public ::Rcpp::Generator<false,double> {
+		template <bool seed>
+		class UnifGenerator : public ::Rcpp::Generator<seed,double> {
 		public:
 	
 			UnifGenerator( double min_ = 0.0, double max_ = 1.0) : 
@@ -43,6 +44,18 @@
 			double diff ;
 		} ;
 
+		template <bool seed>
+		class UnifGenerator__0__1 : public ::Rcpp::Generator<seed,double> {
+		public:
+	
+			UnifGenerator__0__1( double min_ = 0.0, double max_ = 1.0) {}
+	
+			inline double operator()() const {
+				double u;
+				do {u = unif_rand();} while (u <= 0 || u >= 1);
+				return u;
+			}
+		} ;
 	} // stats
 
 	// Please make sure you to read Section 6.3 of "Writing R Extensions"
@@ -51,7 +64,7 @@
 	inline NumericVector runif( int n, double min, double max ){
 		if (!R_FINITE(min) || !R_FINITE(max) || max < min) return NumericVector( n, R_NaN ) ;
 		if( min == max ) return NumericVector( n, min ) ;
-		return NumericVector( n, stats::UnifGenerator( min, max ) ) ;
+		return NumericVector( n, stats::UnifGenerator<false>( min, max ) ) ;
 	}
 
 	// Please make sure you to read Section 6.3 of "Writing R Extensions"
@@ -60,14 +73,14 @@
 	inline NumericVector runif( int n, double min /*, double max = 1.0 */ ){
 		if (!R_FINITE(min) || 1.0 < min) return NumericVector( n, R_NaN ) ;
 		if( min == 1.0 ) return NumericVector( n, 1.0 ) ;
-		return NumericVector( n, stats::UnifGenerator( min, 1.0 ) ) ;
+		return NumericVector( n, stats::UnifGenerator<false>( min, 1.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 runif( int n /*, double min = 0.0, double max = 1.0 */ ){
-		return NumericVector( n, unif_rand ) ;
+		return NumericVector( n, stats::UnifGenerator__0__1<false>() ) ;
 	}
 
 } // Rcpp

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rweibull.h
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/rcpp -r 4000


More information about the Rcpp-commits mailing list