[Rcpp-commits] r2020 - pkg/Rcpp/inst/include/Rcpp/stats/random

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Aug 15 14:11:56 CEST 2010


Author: romain
Date: 2010-08-15 14:11:55 +0200 (Sun, 15 Aug 2010)
New Revision: 2020

Modified:
   pkg/Rcpp/inst/include/Rcpp/stats/random/rlogis.h
Log:
compile time handling of default for rlogis

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rlogis.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rlogis.h	2010-08-15 12:09:25 UTC (rev 2019)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rlogis.h	2010-08-15 12:11:55 UTC (rev 2020)
@@ -40,9 +40,36 @@
 	double location ;
 	double scale ;
 } ;
+
+class LogisGenerator_1 : public ::Rcpp::Generator<false,double> {
+public:
+	
+	LogisGenerator_1( double location_) : 
+		location(location_) {}
+	
+	inline double operator()() const {
+		double u = unif_rand() ;
+		return location + ::log(u / (1. - u));
+	}
+	
+private:
+	double location ;
+} ;
+
+class LogisGenerator_0 : public ::Rcpp::Generator<false,double> {
+public:
+	
+	LogisGenerator_0() {}
+	
+	inline double operator()() const {
+		double u = unif_rand() ;
+		return ::log(u / (1. - u));
+	}
+
+} ;
+
 } // stats
 
-// TODO: move the default arguments to compile-time dispatch
 inline NumericVector rlogis( int n, double location, double scale ){
 	if (ISNAN(location) || !R_FINITE(scale))
 	return NumericVector( n, R_NaN ) ;
@@ -53,6 +80,20 @@
 	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 ) ;
+
+    if (!R_FINITE(location))
+	return NumericVector( n, location );
+    
+	return NumericVector( n, stats::LogisGenerator_1( location ) ) ;
+}
+
+inline NumericVector rlogis( int n /*, double location [=0.0], double scale =1.0 */ ){
+	return NumericVector( n, stats::LogisGenerator_0() ) ;
+}
+
 } // Rcpp
 
 #endif



More information about the Rcpp-commits mailing list