[Rcpp-commits] r4111 - in pkg/Rcpp: . inst/include inst/include/Rcpp inst/include/Rcpp/api/meat inst/include/Rcpp/stats/random inst/include/Rcpp/vector src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Dec 7 16:48:18 CET 2012


Author: romain
Date: 2012-12-07 16:48:17 +0100 (Fri, 07 Dec 2012)
New Revision: 4111

Added:
   pkg/Rcpp/src/random.cpp
Removed:
   pkg/Rcpp/inst/include/Rcpp/Generator.h
Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/Rmath.h
   pkg/Rcpp/inst/include/Rcpp/api/meat/Vector.h
   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
   pkg/Rcpp/inst/include/Rcpp/vector/Vector.h
   pkg/Rcpp/inst/include/RcppCommon.h
Log:
move around random generators

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2012-12-07 12:30:59 UTC (rev 4110)
+++ pkg/Rcpp/ChangeLog	2012-12-07 15:48:17 UTC (rev 4111)
@@ -1,3 +1,11 @@
+2012-12-07 Romain Francois <romain at r-enthusiasts.com>
+
+        * src/random.cpp: instantiations of random generators here
+        * include/Rcpp/stats/random/random.h: only have declarations of 
+        random generators here. Rework the Generator template so that 
+        it inherits RNGScope to provide automatic calls to GetRNGstate
+        and PutRNGstate
+        
 2012-12-06  JJ Allaire <jj at rstudio.org>
 
         * R/Attributes.R: revert DOS newlines; use new shared library name

Deleted: pkg/Rcpp/inst/include/Rcpp/Generator.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Generator.h	2012-12-07 12:30:59 UTC (rev 4110)
+++ pkg/Rcpp/inst/include/Rcpp/Generator.h	2012-12-07 15:48:17 UTC (rev 4111)
@@ -1,52 +0,0 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
-//
-// Generator.h: Rcpp R/C++ interface class library -- framework for random number generation
-//
-// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
-//
-// This file is part of Rcpp.
-//
-// Rcpp is free software: you can redistribute it and/or modify it
-// under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 2 of the License, or
-// (at your option) any later version.
-//
-// Rcpp is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Rcpp.  If not, see <http://www.gnu.org/licenses/>.
-
-#ifndef Rcpp__Generator_h
-#define Rcpp__Generator_h
-
-namespace Rcpp{
-
-template <bool seed, typename T>
-class Generator{
-public:
-	typedef T r_generator ;
-	Generator(){ GetRNGstate(); }
-	~Generator(){ PutRNGstate(); }	
-} ;
-
-template <typename T>
-class Generator<false,T> {
-public:
-	typedef T r_generator ;
-	Generator(){ }
-	~Generator(){ }	
-} ;
-
-class RNGScope{
-public:
-	RNGScope(){ GetRNGstate(); }
-	~RNGScope(){ PutRNGstate(); }	
-} ;
-
-
-}
-
-#endif

Modified: pkg/Rcpp/inst/include/Rcpp/Rmath.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Rmath.h	2012-12-07 12:30:59 UTC (rev 4110)
+++ pkg/Rcpp/inst/include/Rcpp/Rmath.h	2012-12-07 15:48:17 UTC (rev 4111)
@@ -2,7 +2,7 @@
 //
 // Rmath.h: Rcpp R/C++ interface class library -- Wrappers for R's Rmath API
 //
-// Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois
 //
 // This file is part of Rcpp.
 //

Modified: pkg/Rcpp/inst/include/Rcpp/api/meat/Vector.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/api/meat/Vector.h	2012-12-07 12:30:59 UTC (rev 4110)
+++ pkg/Rcpp/inst/include/Rcpp/api/meat/Vector.h	2012-12-07 15:48:17 UTC (rev 4111)
@@ -74,6 +74,67 @@
     }
     
     template <int RTYPE>
+    template <typename U>
+    Vector<RTYPE>::Vector( const int& size, const U& u){
+    	RObject::setSEXP( Rf_allocVector( RTYPE, size) ) ;
+        fill_or_generate( u ) ;	
+    }
+    
+    template <int RTYPE>
+    template <typename U1>
+    Vector<RTYPE>::Vector( const int& siz, stored_type (*gen)(U1), const U1& u1){
+    	RObject::setSEXP( Rf_allocVector( RTYPE, siz) ) ;
+        iterator first = begin(), last = end() ;
+    	while( first != last ) *first++ = gen(u1) ;
+    }
+    
+    template <int RTYPE>
+    template <typename U1, typename U2>
+    Vector<RTYPE>::Vector( const int& siz, stored_type (*gen)(U1,U2), const U1& u1, const U2& u2){
+    	RObject::setSEXP( Rf_allocVector( RTYPE, siz) ) ;
+        iterator first = begin(), last = end() ;
+    	while( first != last ) *first++ = gen(u1,u2) ;
+    }
+
+    template <int RTYPE>
+    template <typename U1, typename U2, typename U3>
+    Vector<RTYPE>::Vector( const int& siz, stored_type (*gen)(U1,U2,U3), const U1& u1, const U2& u2, const U3& u3){
+    	RObject::setSEXP( Rf_allocVector( RTYPE, siz) ) ;
+        iterator first = begin(), last = end() ;
+    	while( first != last ) *first++ = gen(u1,u2,u3) ;
+    }
+
+    template <int RTYPE>
+    template <typename InputIterator>
+    Vector<RTYPE>::Vector( InputIterator first, InputIterator last) : RObject( ){
+        int n = std::distance(first, last) ;
+        RObject::setSEXP( Rf_allocVector(RTYPE, n) ) ;
+        std::copy( first, last, begin() ) ; 
+    }
+
+    template <int RTYPE>
+    template <typename InputIterator>
+    Vector<RTYPE>::Vector( InputIterator first, InputIterator last, int n) : RObject( ){
+        RObject::setSEXP( Rf_allocVector(RTYPE, n) ) ;
+        std::copy( first, last, begin() ) ; 
+    }
+
+    template <int RTYPE>
+    template <typename InputIterator, typename Func>
+    Vector<RTYPE>::Vector( InputIterator first, InputIterator last, Func func) : RObject( ){
+        RObject::setSEXP( Rf_allocVector( RTYPE, std::distance(first,last) ) ) ;
+        std::transform( first, last, begin(), func) ;
+    }
+    
+    template <int RTYPE>
+    template <typename InputIterator, typename Func>
+    Vector<RTYPE>::Vector( InputIterator first, InputIterator last, Func func, int n) : RObject(  ){
+        RObject::setSEXP( Rf_allocVector( RTYPE, n ) ) ;
+        std::transform( first, last, begin(), func) ;
+    }
+
+    
+    template <int RTYPE>
     template <bool NA, typename VEC>
     Vector<RTYPE>::Vector( const VectorBase<RTYPE,NA,VEC>& other ) : RObject() {
     	import_sugar_expression( other, typename traits::same_type<Vector,VEC>::type() ) ;
@@ -121,7 +182,50 @@
         RObject::setSEXP( r_cast<RTYPE>( wrap(x) ) ) ;
     }
     
+    template <int RTYPE>
+    template <bool NA, typename VEC>
+    inline void Vector<RTYPE>::import_sugar_expression( const Rcpp::VectorBase<RTYPE,NA,VEC>& other, traits::false_type ){
+        RCPP_DEBUG_4( "Vector<%d>::import_sugar_expression( VectorBase<%d,%d,%s>, false_type )", RTYPE, NA, RTYPE, DEMANGLE(VEC) ) ;
+    	int n = other.size() ;
+    	RObject::setSEXP( Rf_allocVector( RTYPE, n ) ) ;
+    	import_expression<VEC>( other.get_ref() , n ) ;
+    }   
     
+    template <int RTYPE>
+    template <bool NA, typename VEC>
+    inline void Vector<RTYPE>::import_sugar_expression( const Rcpp::VectorBase<RTYPE,NA,VEC>& other, traits::true_type ){
+        RCPP_DEBUG_4( "Vector<%d>::import_sugar_expression( VectorBase<%d,%d,%s>, true_type )", RTYPE, NA, RTYPE, DEMANGLE(VEC) ) ;
+    	RObject::setSEXP( other.get_ref() ) ;
+    }   
+
+    template <int RTYPE>
+    template <typename T>
+    inline void Vector<RTYPE>::import_expression( const T& other, int n ){
+        iterator start = begin() ; 
+        RCPP_LOOP_UNROLL(start,other)
+    }
+    
+    template <int RTYPE>
+    template <typename T>
+    inline void Vector<RTYPE>::fill_or_generate( const T& t){
+    	fill_or_generate__impl( t, typename traits::is_generator<T>::type() ) ;
+    }
+    
+    template <int RTYPE>
+    template <typename T>
+    inline void Vector<RTYPE>::fill_or_generate__impl( const T& gen, traits::true_type){
+    	iterator first = begin() ;
+    	iterator last = end() ;
+    	while( first != last ) *first++ = gen() ;
+    }
+    
+    template <int RTYPE>
+    template <typename T>
+    inline void Vector<RTYPE>::fill_or_generate__impl( const T& t, traits::false_type){
+    	fill(t) ;
+    }
+    
+    
 } // namespace Rcpp
 
 #endif

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/random.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/random.h	2012-12-07 12:30:59 UTC (rev 4110)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/random.h	2012-12-07 15:48:17 UTC (rev 4111)
@@ -22,26 +22,60 @@
 #ifndef Rcpp__stats__random_random_h
 #define Rcpp__stats__random_random_h
 
-#include <Rcpp/stats/random/rnorm.h>
-#include <Rcpp/stats/random/runif.h>
-#include <Rcpp/stats/random/rgamma.h>
-#include <Rcpp/stats/random/rbeta.h>
-#include <Rcpp/stats/random/rlnorm.h>
-#include <Rcpp/stats/random/rchisq.h>
-#include <Rcpp/stats/random/rnchisq.h>
-#include <Rcpp/stats/random/rf.h>
-#include <Rcpp/stats/random/rt.h>
-#include <Rcpp/stats/random/rbinom.h>
-#include <Rcpp/stats/random/rcauchy.h>
-#include <Rcpp/stats/random/rexp.h>
-#include <Rcpp/stats/random/rgeom.h>
-#include <Rcpp/stats/random/rnbinom.h>
-#include <Rcpp/stats/random/rnbinom_mu.h>
-#include <Rcpp/stats/random/rpois.h>
-#include <Rcpp/stats/random/rweibull.h>
-#include <Rcpp/stats/random/rlogis.h>
-#include <Rcpp/stats/random/rwilcox.h>
-#include <Rcpp/stats/random/rsignrank.h>
-#include <Rcpp/stats/random/rhyper.h>
+namespace Rcpp{ 
+    
+NumericVector rbeta( int n, double a, double b ) ;
+NumericVector rbinom( int n, double nin, double pp ) ;
+NumericVector rcauchy( int n, double location, double scale ) ;
+NumericVector rcauchy( int n, double location /* , double scale [=1.0] */ ) ;
+NumericVector rcauchy( int n /*, double location [=0.0] , double scale [=1.0] */ ) ;
+NumericVector rchisq( int n, double df ) ;
+NumericVector rexp( int n, double rate ) ;
+NumericVector rexp( int n /* , rate = 1 */ ) ;
+NumericVector rf( int n, double n1, double n2 ) ;
+NumericVector rgamma( int n, double a, double scale ) ;
+NumericVector rgamma( int n, double a /* scale = 1.0 */ ) ;
+NumericVector rgeom( int n, double p ) ;
+NumericVector rhyper( int n, double nn1, double nn2, double kk ) ;
+NumericVector rlnorm( int n, double meanlog, double sdlog ) ;
+NumericVector rlnorm( int n, double meanlog /*, double sdlog = 1.0 */) ;
+NumericVector rlnorm( int n /*, double meanlog [=0.], double sdlog = 1.0 */) ;
+NumericVector rlogis( int n, double location, double scale ) ;
+NumericVector rlogis( int n, double location /*, double scale =1.0 */ ) ;
+NumericVector rlogis( int n /*, double location [=0.0], double scale =1.0 */ ) ;
+NumericVector rnbinom( int n, double siz, double prob ) ;
+NumericVector rnbinom_mu( int n, double siz, double mu ) ;
+NumericVector rnchisq( int n, double df, double lambda ) ;
+NumericVector rnchisq( int n, double df /*, double lambda = 0.0 */ ) ;
+NumericVector rnorm( int n, double mean, double sd) ;
+NumericVector rnorm( int n, double mean /*, double sd [=1.0] */ ) ;
+NumericVector rnorm( int n /*, double mean [=0.0], double sd [=1.0] */ ) ;
+NumericVector rpois( int n, double mu ) ;
+NumericVector rsignrank( int n, double nn ) ;
+NumericVector rt( int n, double df ) ;
+NumericVector runif( int n, double min, double max ) ;
+NumericVector runif( int n, double min /*, double max = 1.0 */ ) ;
+NumericVector runif( int n /*, double min = 0.0, double max = 1.0 */ ) ;
+NumericVector rweibull( int n, double shape, double scale ) ;
+NumericVector rweibull( int n, double shape /* scale = 1 */ ) ;
+NumericVector rwilcox( int n, double mm, double nn ) ;
 
+namespace internal {
+    void enterRNGScope();
+    void exitRNGScope();
+}
+
+class RNGScope{
+public:
+	RNGScope(){ internal::enterRNGScope(); }
+	~RNGScope(){ internal::exitRNGScope(); }	
+} ;
+
+template <typename T>
+class Generator : public RNGScope {
+public:
+	typedef T r_generator ;
+} ;
+
+}
 #endif

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rbeta.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rbeta.h	2012-12-07 12:30:59 UTC (rev 4110)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rbeta.h	2012-12-07 15:48:17 UTC (rev 4111)
@@ -25,8 +25,7 @@
 namespace Rcpp {
 namespace stats{
     
-    template <bool seed>
-    class BetaGenerator : public Generator<seed,double>{
+    class BetaGenerator : public Generator<double>{
     public: 
         BetaGenerator(double a_, double b_) : a(a_), b(b_){}
         
@@ -39,13 +38,6 @@
     
 } // 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, stats::BetaGenerator<false>(a, b ) ) ;
-	}
-
 } // Rcpp
 
 #endif

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rbinom.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rbinom.h	2012-12-07 12:30:59 UTC (rev 4110)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rbinom.h	2012-12-07 15:48:17 UTC (rev 4111)
@@ -25,8 +25,7 @@
 namespace Rcpp {
 namespace stats {
     
-    template <bool seed> 
-    class BinomGenerator : public Generator<seed,double>{
+    class BinomGenerator : public Generator<double>{
     public:
         BinomGenerator( double nin_, double pp_ ) : nin(nin_), pp(pp_){}
         inline double operator()() const{
@@ -38,14 +37,6 @@
     
 }  // 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, stats::BinomGenerator<false>(nin, pp) ) ;
-	}
-
 } // Rcpp
 
 #endif

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rcauchy.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rcauchy.h	2012-12-07 12:30:59 UTC (rev 4110)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rcauchy.h	2012-12-07 15:48:17 UTC (rev 4111)
@@ -25,8 +25,7 @@
 namespace Rcpp {
 namespace stats {
 
-template <bool seed>
-class CauchyGenerator : public ::Rcpp::Generator<seed,double> {
+class CauchyGenerator : public ::Rcpp::Generator<double> {
 public:
 	
 	CauchyGenerator( double location_, double scale_) : 
@@ -40,8 +39,7 @@
 	double location, scale ;
 } ;
 
-template <bool seed>
-class CauchyGenerator_1 : public ::Rcpp::Generator<seed,double> {
+class CauchyGenerator_1 : public ::Rcpp::Generator<double> {
 public:
 	
 	CauchyGenerator_1( double location_) : 
@@ -55,8 +53,7 @@
 	double location ;
 } ;
 
-template <bool seed>
-class CauchyGenerator_0 : public ::Rcpp::Generator<false,double> {
+class CauchyGenerator_0 : public ::Rcpp::Generator<double> {
 public:
 	
 	CauchyGenerator_0(){}
@@ -69,41 +66,6 @@
 
 } // 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 ) ;
-	
-    if (scale == 0. || !R_FINITE(location))
-    	return NumericVector( n, location ) ;
-    
-	return NumericVector( n, stats::CauchyGenerator<false>( 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 ) ;
-	
-    if (!R_FINITE(location))
-    	return NumericVector( n, 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<false>() ) ;
-}
-
 } // Rcpp
 
 #endif

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rchisq.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rchisq.h	2012-12-07 12:30:59 UTC (rev 4110)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rchisq.h	2012-12-07 15:48:17 UTC (rev 4111)
@@ -25,8 +25,8 @@
 namespace Rcpp {
 	namespace stats {
 		
-	    template <bool seed>
-		class ChisqGenerator : public ::Rcpp::Generator<seed,double> {
+	    
+		class ChisqGenerator : public ::Rcpp::Generator<double> {
 		public:
 			
 			ChisqGenerator( double df_ ) : df_2(df_ / 2.0) {}
@@ -40,14 +40,6 @@
 		} ;
 	} // 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 rchisq( int n, double df ){
-		if (!R_FINITE(df) || df < 0.0) return NumericVector(n, R_NaN) ;
-		return NumericVector( n, stats::ChisqGenerator<false>( df ) ) ;
-	}
-
 } // Rcpp
 
 #endif

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rexp.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rexp.h	2012-12-07 12:30:59 UTC (rev 4110)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rexp.h	2012-12-07 15:48:17 UTC (rev 4111)
@@ -25,8 +25,8 @@
 namespace Rcpp {
 	namespace stats {
 
-	    template <bool seed>
-		class ExpGenerator : public ::Rcpp::Generator<seed,double> {
+	    
+		class ExpGenerator : public ::Rcpp::Generator<double> {
 		public:
 	
 			ExpGenerator( double scale_ ) : scale(scale_) {}
@@ -39,8 +39,8 @@
 			double scale ;
 		} ;
 		
-		template <bool seed>
-		class ExpGenerator__rate1 : public Generator<seed,double>{
+		
+		class ExpGenerator__rate1 : public Generator<double>{
 		public:
 		    ExpGenerator__rate1(){}
 		    inline double operator()() const { return exp_rand() ; }
@@ -48,22 +48,6 @@
 
 	} // 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 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 ) ;
-		}
-		return NumericVector( n, stats::ExpGenerator<false>( scale ) ) ;
-	}
-	inline NumericVector rexp( int n /* , rate = 1 */ ){
-		return NumericVector( n, stats::ExpGenerator__rate1<false>() ) ;
-	}
-
 }
 
 #endif

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rf.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rf.h	2012-12-07 12:30:59 UTC (rev 4110)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rf.h	2012-12-07 15:48:17 UTC (rev 4111)
@@ -25,8 +25,8 @@
 namespace Rcpp {
 	namespace stats {
 
-	    template <bool seed>
-		class FGenerator_Finite_Finite : public ::Rcpp::Generator<seed,double> {
+	    
+		class FGenerator_Finite_Finite : public ::Rcpp::Generator<double> {
 		public:
 	
 			FGenerator_Finite_Finite( double n1_, double n2_ ) : 
@@ -42,8 +42,8 @@
 			double n1, n2, n1__2, n2__2, ratio ;
 		} ;
 
-		template <bool seed>
-		class FGenerator_NotFinite_Finite : public ::Rcpp::Generator<seed,double> {
+		
+		class FGenerator_NotFinite_Finite : public ::Rcpp::Generator<double> {
 		public:
 	
 			FGenerator_NotFinite_Finite( double n2_ ) : n2( n2_), n2__2(n2_ / 2.0 ) {}
@@ -57,8 +57,8 @@
 			double n2, n2__2 ;
 		} ;
 
-		template <bool seed>
-		class FGenerator_Finite_NotFinite : public ::Rcpp::Generator<seed,double> {
+		
+		class FGenerator_Finite_NotFinite : public ::Rcpp::Generator<double> {
 		public:
 	
 			FGenerator_Finite_NotFinite( double n1_ ) : n1(n1_), n1__2(n1_ / 2.0 ) {}
@@ -74,23 +74,6 @@
 
 	} // 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 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<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<false>( n2 ) ) ;
-		} else {
-			return NumericVector( n, stats::FGenerator_Finite_NotFinite<false>( n1 ) ) ;	
-		}
-	}
-
 } // Rcpp
 
 #endif

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rgamma.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rgamma.h	2012-12-07 12:30:59 UTC (rev 4110)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rgamma.h	2012-12-07 15:48:17 UTC (rev 4111)
@@ -24,8 +24,8 @@
 
 namespace Rcpp {
     namespace stats {
-        template <bool seed>
-        class GammaGenerator : public Generator<seed,double>{
+        
+        class GammaGenerator : public Generator<double>{
         public:
             GammaGenerator(double a_, double scale_) : 
                 a(a_), scale(scale_) {}
@@ -35,27 +35,6 @@
         } ;
     }    // 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 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, 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-12-07 12:30:59 UTC (rev 4110)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rgeom.h	2012-12-07 15:48:17 UTC (rev 4111)
@@ -25,8 +25,8 @@
 namespace Rcpp {
 	namespace stats {
 
-	    template <bool seed>
-		class GeomGenerator : public ::Rcpp::Generator<seed,double> {
+	    
+		class GeomGenerator : public ::Rcpp::Generator<double> {
 		public:
 	
 			GeomGenerator( double p ) : lambda( (1-p)/p  ) {}
@@ -40,15 +40,6 @@
 		} ;
 	} // 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 rgeom( int n, double p ){
-		if (!R_FINITE(p) || p <= 0 || p > 1) 
-			return NumericVector( n, R_NaN );
-		return NumericVector( n, stats::GeomGenerator<false>( p ) ) ;
-	}
-
 } // Rcpp
 
 #endif

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rhyper.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rhyper.h	2012-12-07 12:30:59 UTC (rev 4110)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rhyper.h	2012-12-07 15:48:17 UTC (rev 4111)
@@ -24,8 +24,8 @@
 
 namespace Rcpp {
     namespace stats {
-        template <bool seed>
-        class HyperGenerator : public Generator<seed,double>{
+        
+        class HyperGenerator : public Generator<double>{
         public:
             HyperGenerator( double nn1_, double nn2_, double kk_) : 
                 nn1(nn1_), nn2(nn2_), kk(kk_){}
@@ -35,13 +35,6 @@
         } ;
     }
     
-	// 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, stats::HyperGenerator<false>( nn1, nn2, kk ) ) ;
-	}
-
 } // Rcpp
 
 #endif

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rlnorm.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rlnorm.h	2012-12-07 12:30:59 UTC (rev 4110)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rlnorm.h	2012-12-07 15:48:17 UTC (rev 4111)
@@ -25,8 +25,8 @@
 namespace Rcpp {
 	namespace stats {
 
-	    template <bool seed>
-		class LNormGenerator : public Generator<seed,double> {
+	    
+		class LNormGenerator : public Generator<double> {
 		public:
 	
 			LNormGenerator( double meanlog_ = 0.0 , double sdlog_ = 1.0 ) : 
@@ -41,8 +41,8 @@
 			double sdlog ;
 		} ;
 
-		template <bool seed>
-		class LNormGenerator_1 : public Generator<seed,double> {
+		
+		class LNormGenerator_1 : public Generator<double> {
 		public:
 	
 			LNormGenerator_1( double meanlog_ = 0.0 ) : 
@@ -56,8 +56,8 @@
 			double meanlog ;
 		} ;
 
-		template <bool seed>
-		class LNormGenerator_0 : public Generator<seed,double> {
+		
+		class LNormGenerator_0 : public Generator<double> {
 		public:
 	
 			LNormGenerator_0( ) {}
@@ -70,42 +70,6 @@
 
 	} // 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 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<false>( 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 = 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<false>( 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 [=0.], double sdlog = 1.0 */){
-		return NumericVector( n, stats::LNormGenerator_0<false>( ) ); 
-	}
-
-
 } // Rcpp
 
 #endif

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rlogis.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rlogis.h	2012-12-07 12:30:59 UTC (rev 4110)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rlogis.h	2012-12-07 15:48:17 UTC (rev 4111)
@@ -25,8 +25,8 @@
 namespace Rcpp {
 	namespace stats {
 	    
-	    template <bool seed>
-		class LogisGenerator : public ::Rcpp::Generator<seed,double> {
+	    
+		class LogisGenerator : public ::Rcpp::Generator<double> {
 		public:
 	
 			LogisGenerator( double location_, double scale_ ) : 
@@ -42,8 +42,8 @@
 			double scale ;
 		} ;
 
-		template <bool seed>
-		class LogisGenerator_1 : public ::Rcpp::Generator<seed,double> {
+		
+		class LogisGenerator_1 : public ::Rcpp::Generator<double> {
 		public:
 	
 			LogisGenerator_1( double location_) : 
@@ -58,8 +58,8 @@
 			double location ;
 		} ;
 
-		template <bool seed>
-		class LogisGenerator_0 : public ::Rcpp::Generator<seed,double> {
+		
+		class LogisGenerator_0 : public ::Rcpp::Generator<double> {
 		public:
 	
 			LogisGenerator_0() {}
@@ -73,39 +73,6 @@
 
 	} // 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 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 );
-    
-		return NumericVector( n, stats::LogisGenerator<false>( 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 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 );
-    
-		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<false>() ) ;
-	}
-
 } // Rcpp
 
 #endif

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rnbinom.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rnbinom.h	2012-12-07 12:30:59 UTC (rev 4110)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rnbinom.h	2012-12-07 15:48:17 UTC (rev 4111)
@@ -25,8 +25,8 @@
 namespace Rcpp {
 	namespace stats {
 
-	    template <bool seed>
-		class NBinomGenerator : public ::Rcpp::Generator<seed,double> {
+	    
+		class NBinomGenerator : public ::Rcpp::Generator<double> {
 		public:
 	
 			NBinomGenerator( double siz_, double prob_ ) : 
@@ -42,17 +42,6 @@
 		} ;
 	} // 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 rnbinom( int n, double siz, double prob ){
-		if(!R_FINITE(siz) || !R_FINITE(prob) || siz <= 0 || prob <= 0 || prob > 1)
-			/* prob = 1 is ok, PR#1218 */
-			return NumericVector( n, R_NaN ) ;
-    
-		return NumericVector( n, stats::NBinomGenerator<false>( siz, prob ) ) ;
-	}
-
 } // Rcpp
 
 #endif

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rnbinom_mu.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rnbinom_mu.h	2012-12-07 12:30:59 UTC (rev 4110)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rnbinom_mu.h	2012-12-07 15:48:17 UTC (rev 4111)
@@ -25,8 +25,8 @@
 namespace Rcpp {
 	namespace stats {
 
-	    template <bool seed>
-		class NBinomGenerator_Mu : public ::Rcpp::Generator<seed,double> {
+	    
+		class NBinomGenerator_Mu : public ::Rcpp::Generator<double> {
 		public:
 	
 			NBinomGenerator_Mu( double siz_, double mu_ ) : 
@@ -42,16 +42,6 @@
 		} ;
 	} // 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 rnbinom_mu( int n, double siz, double mu ){
-		if(!R_FINITE(siz) || !R_FINITE(mu) || siz <= 0 || mu < 0)
-			return NumericVector( n, R_NaN ) ;
-    
-		return NumericVector( n, stats::NBinomGenerator_Mu<false>( siz, mu ) ) ;
-	}
-
 } // Rcpp
 
 #endif

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rnchisq.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rnchisq.h	2012-12-07 12:30:59 UTC (rev 4110)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rnchisq.h	2012-12-07 15:48:17 UTC (rev 4111)
@@ -25,8 +25,8 @@
 namespace Rcpp {
 	namespace stats {
 
-		template <bool seed>
-		class NChisqGenerator : public ::Rcpp::Generator<seed,double> {
+		
+		class NChisqGenerator : public ::Rcpp::Generator<double> {
 		public:
 	
 			NChisqGenerator( double df_, double lambda_ ) : 
@@ -50,28 +50,6 @@
 		} ;
 	} // 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 rnchisq( int n, double df, double lambda ){
-		if (!R_FINITE(df) || !R_FINITE(lambda) || df < 0. || lambda < 0.) 
-			return NumericVector(n, R_NaN) ;
-		if( lambda == 0.0 ){
-			// using the central generator, see rchisq.h
-			return NumericVector( n, stats::ChisqGenerator<false>( df ) ) ;
-		}
-		return NumericVector( n, stats::NChisqGenerator<false>( df, lambda ) ) ;
-	}
-
-	// 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 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<false>( df ) ) ;
-	}
-
 } // Rcpp
 
 #endif

[TRUNCATED]

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


More information about the Rcpp-commits mailing list