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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Aug 10 09:23:53 CEST 2010


Author: romain
Date: 2010-08-10 09:23:52 +0200 (Tue, 10 Aug 2010)
New Revision: 1965

Added:
   pkg/Rcpp/inst/include/Rcpp/stats/random/rf.h
Modified:
   pkg/Rcpp/inst/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/rcauchy.h
   pkg/Rcpp/inst/include/Rcpp/stats/random/rexp.h
Log:
various fixes

Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog	2010-08-10 07:00:35 UTC (rev 1964)
+++ pkg/Rcpp/inst/ChangeLog	2010-08-10 07:23:52 UTC (rev 1965)
@@ -10,8 +10,10 @@
 
 	* inst/include/Rcpp/stats/random/rchisq.h: Added rchisq and rchisq_
 
-	* inst/include/Rcpp/stats/random/rchisq.h: Added rexp and rexp_
+	* inst/include/Rcpp/stats/random/rexp.h: Added rexp and rexp_
 
+	* inst/include/Rcpp/stats/random/rf.h: Added rf and rf_
+
 	* inst/include/Rcpp/stats/stats.h : fixed name clash reported on Rcpp-devel
 	http://permalink.gmane.org/gmane.comp.lang.r.rcpp/610
 

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/random.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/random.h	2010-08-10 07:00:35 UTC (rev 1964)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/random.h	2010-08-10 07:23:52 UTC (rev 1965)
@@ -28,5 +28,6 @@
 #include <Rcpp/stats/random/runif.h>
 #include <Rcpp/stats/random/rchisq.h>
 #include <Rcpp/stats/random/rexp.h>
+#include <Rcpp/stats/random/rf.h>
 
 #endif

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rbeta.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rbeta.h	2010-08-10 07:00:35 UTC (rev 1964)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rbeta.h	2010-08-10 07:23:52 UTC (rev 1965)
@@ -32,7 +32,7 @@
 	BetaGenerator( double a_, double b_ ) : a(a_), b(b_) {}
 	
 	inline double operator()() const {
-		return ::dbeta( a, b );
+		return ::rbeta( a, b );
 	}
 	
 private:
@@ -41,7 +41,7 @@
 
 template <bool seed>
 Rcpp::NumericVector rbeta__impl( int n, double a, double b ){
-	return Rcpp::NumericVector( n, BetaGenerator<seed>( min, max ) ) ;
+	return Rcpp::NumericVector( n, BetaGenerator<seed>( a, b ) ) ;
 }
 inline Rcpp::NumericVector rbeta( int n, double a, double b ){
 	return rbeta__impl<true>( n, a, b );

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rcauchy.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rcauchy.h	2010-08-10 07:00:35 UTC (rev 1964)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rcauchy.h	2010-08-10 07:23:52 UTC (rev 1965)
@@ -33,7 +33,7 @@
 		location(location_) , scale(scale_) {}
 	
 	inline double operator()() const {
-		return location + scale * tan(M_PI * unif_rand())
+		return location + scale * tan(M_PI * unif_rand()) ;
 	}
 	
 private:
@@ -53,7 +53,7 @@
 inline Rcpp::NumericVector rcauchy( int n, double location, double scale ){
 	return rcauchy__impl<true>( n, location, scale );
 }
-inline Rcpp::NumericVector rcauchy_( int n, ddouble location, double scale ){
+inline Rcpp::NumericVector rcauchy_( int n, double location, double scale ){
 	return rcauchy__impl<false>( n, location, scale );
 }
 

Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rexp.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rexp.h	2010-08-10 07:00:35 UTC (rev 1964)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rexp.h	2010-08-10 07:23:52 UTC (rev 1965)
@@ -36,7 +36,7 @@
 	}
 	
 private:
-	double rate ;
+	double scale ;
 } ;
 
 template <bool seed>

Added: pkg/Rcpp/inst/include/Rcpp/stats/random/rf.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rf.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rf.h	2010-08-10 07:23:52 UTC (rev 1965)
@@ -0,0 +1,98 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
+//
+// rf.h: Rcpp R/C++ interface class library -- 
+//
+// Copyright (C) 2010 Douglas Bates, 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__stats__random_rf_h
+#define Rcpp__stats__random_rf_h
+
+namespace Rcpp {
+namespace stats {
+
+template <bool seed>
+class FGenerator_Finite_Finite : public Rcpp::Generator<seed,double> {
+public:
+	
+	FGenerator_Finite_Finite( double n1_, double n2_ ) : n1__2(n1_ / 2.0 ), n2__2(n2_ / 2.0 ) {}
+	
+	inline double operator()() const {
+		// here we know that both n1 and n2 are finite
+		// return ::rchisq( n1 ) / ::rchisq( n2 ) ;
+		return ::rgamma( n1__2, 2.0 ) / ::rgamma( n2__2, 2.0 ) ;
+	}
+	
+private:
+	double n1__2, n2__2 ;
+} ;
+
+template <bool seed>
+class FGenerator_NotFinite_Finite : public Rcpp::Generator<seed,double> {
+public:
+	
+	FGenerator_NotFinite_Finite( double n2_ ) : n2__2(n2_ / 2.0 ) {}
+	
+	inline double operator()() const {
+		// return 1.0  / ::rchisq( n2 ) ;
+		return 1.0 / ::rgamma( n2__2, 2.0 ) ;
+	}
+	
+private:
+	double n2__2 ;
+} ;
+
+template <bool seed>
+class FGenerator_Finite_NotFinite : public Rcpp::Generator<seed,double> {
+public:
+	
+	FGenerator_Finite_NotFinite( double n1_ ) : n1__2(n1_ / 2.0 ) {}
+	
+	inline double operator()() const {
+		// return ::rchisq( n1 ) ;
+		return ::rgamma( n1__2, 2.0 ) ;
+	}
+	
+private:
+	double n1__2 ;
+} ;
+
+template <bool seed>
+Rcpp::NumericVector rf__impl( int n, double n1, double n2 ){
+	if (ISNAN(n1) || ISNAN(n2) || n1 <= 0. || n2 <= 0.)
+		return Rcpp::NumericVector( n, R_NaN ) ;
+	if( R_FINITE( n1 ) && R_FINITE( n2 ) ){
+		return Rcpp::NumericVector( n, FGenerator_Finite_Finite<seed>( n1, n2 ) ) ;
+	} else if( ! R_FINITE( n1 ) && ! R_FINITE( n2 ) ){
+		return Rcpp::NumericVector( n, 1.0 ) ;
+	} else if( ! R_FINITE( n1 ) ) {
+		return Rcpp::NumericVector( n, FGenerator_NotFinite_Finite<seed>( n2 ) ) ;
+	} else if( ! R_FINITE( n2 ) ){
+		return Rcpp::NumericVector( n, FGenerator_Finite_NotFinite<seed>( n1 ) ) ;	
+	}
+}
+inline Rcpp::NumericVector rf( int n, double n1, double n2 ){
+	return rf__impl<true>( n, n1, n2 );
+}
+inline Rcpp::NumericVector rf_( int n, double n1, double n2 ){
+	return rf__impl<false>( n, n1, n2 );
+}
+
+}
+}
+
+#endif



More information about the Rcpp-commits mailing list