[Rcpp-commits] r2004 - in pkg/Rcpp/inst/include/Rcpp/stats: . dpq

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Aug 14 19:46:02 CEST 2010


Author: romain
Date: 2010-08-14 19:46:02 +0200 (Sat, 14 Aug 2010)
New Revision: 2004

Added:
   pkg/Rcpp/inst/include/Rcpp/stats/dpq/
   pkg/Rcpp/inst/include/Rcpp/stats/dpq/dpq.h
Modified:
   pkg/Rcpp/inst/include/Rcpp/stats/beta.h
   pkg/Rcpp/inst/include/Rcpp/stats/stats.h
Log:
draft at smarter code to generate the dpq functions, tested on beta so far

Modified: pkg/Rcpp/inst/include/Rcpp/stats/beta.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/beta.h	2010-08-13 21:14:35 UTC (rev 2003)
+++ pkg/Rcpp/inst/include/Rcpp/stats/beta.h	2010-08-14 17:46:02 UTC (rev 2004)
@@ -22,90 +22,6 @@
 #ifndef Rcpp__stats__beta_h
 #define Rcpp__stats__beta_h
 
-namespace Rcpp {
+RCPP_DPQ_2(beta,::dbeta,::pbeta,::qbeta)
 
-namespace stats {
-
-
-
-	template <bool NA, typename T>
-	class DBeta : public Rcpp::VectorBase< REALSXP, NA, DBeta<NA,T> > {
-	public:
-		typedef typename Rcpp::VectorBase<REALSXP,NA,T> VEC_TYPE;
-
-		DBeta( const VEC_TYPE& vec_, double a_, double b_, bool log_ = false ) : 
-			vec(vec_), a(a_), b(b_), log(log_) {}
-		
-		inline double operator[]( int i) const { return ::dbeta( vec[i], a, b, log ); }
-		
-		inline int size() const { return vec.size(); }
-		
-	private:
-		const VEC_TYPE& vec;
-		double a, b;
-		int log;
-	
-	};
-
-	template <bool NA, typename T>
-	class PBeta : public Rcpp::VectorBase< REALSXP, NA, PBeta<NA,T> > {
-	public:
-		typedef typename Rcpp::VectorBase<REALSXP,NA,T> VEC_TYPE;
-
-		PBeta( const VEC_TYPE& vec_, double a_, double b_, bool lowertail_ = true, bool log_ = false ) : 
-			vec(vec_), a(a_), b(b_), lowertail(lowertail_), log(log_) {}
-		
-		inline double operator[]( int i) const { return ::pbeta( vec[i], a, b, lowertail, log ); }
-		
-		inline int size() const { return vec.size(); }
-		
-	private:
-		const VEC_TYPE& vec;
-		double a, b;
-		int lowertail, log;
-	
-	};
-
-	template <bool NA, typename T>
-	class QBeta : public Rcpp::VectorBase< REALSXP, NA, QBeta<NA,T> > {
-	public:
-		typedef typename Rcpp::VectorBase<REALSXP,NA,T> VEC_TYPE;
-
-		QBeta( const VEC_TYPE& vec_, double a_, double b_, bool lowertail_ = true, bool log_ = false ) : 
-			vec(vec_), a(a_), b(b_), lowertail(lowertail_), log(log_) {}
-		
-		inline double operator[]( int i) const { return ::qbeta( vec[i], a, b, lowertail, log ); }
-		
-		inline int size() const { return vec.size(); }
-		
-	private:
-		const VEC_TYPE& vec;
-		double a, b;
-		int lowertail, log;
-	
-	};
-	
-} // stats
-
-template <bool NA, typename T>
-inline stats::DBeta<NA,T> dbeta( const Rcpp::VectorBase<REALSXP,NA,T>& x, double a, double b, bool log = false ) {
-	return stats::DBeta<NA,T>( x, a, b, log ); 
-}
-
-template <bool NA, typename T>
-inline stats::PBeta<NA,T> pbeta( const Rcpp::VectorBase<REALSXP,NA,T>& x,
-								double a, double b,
-								bool lowertail = true, bool log = false ) {
-	return stats::PBeta<NA,T>( x, a, b, lowertail, log ); 
-}
-
-template <bool NA, typename T>
-inline stats::QBeta<NA,T> qbeta( const Rcpp::VectorBase<REALSXP,NA,T>& x,
-								double a, double b,
-								bool lowertail = true, bool log = false ) {
-	return stats::QBeta<NA,T>( x, a, b, lowertail, log ); 
-}
-	
-}
-
 #endif

Added: pkg/Rcpp/inst/include/Rcpp/stats/dpq/dpq.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/dpq/dpq.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/stats/dpq/dpq.h	2010-08-14 17:46:02 UTC (rev 2004)
@@ -0,0 +1,409 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
+//
+// dpq.h: Rcpp R/C++ interface class library -- normal distribution
+//
+// Copyright (C) 2010 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__dpq__dpq_h
+#define Rcpp__stats__dpq__dpq_h
+
+namespace Rcpp {
+namespace stats {
+
+	// D
+	
+	template <bool NA, typename T>
+	class D0 : public Rcpp::VectorBase< REALSXP, NA, D0<NA,T> > {
+	public:
+		typedef typename Rcpp::VectorBase<REALSXP,NA,T> VEC_TYPE;
+		typedef double (*FunPtr)(int) ;
+		
+		D0( FunPtr ptr_, const VEC_TYPE& vec_, bool log_ ) : 
+			ptr(ptr_), vec(vec_), log(log_) {}
+		
+		inline double operator[]( int i) const {
+			return ptr( vec[i], log );
+		}
+		
+		inline int size() const { return vec.size(); }
+		
+	private:
+		FunPtr ptr ;
+		const VEC_TYPE& vec;
+		int log;
+	} ;
+
+	template <bool NA, typename T>
+	class D1 : public Rcpp::VectorBase< REALSXP, NA, D1<NA,T> > {
+	public:
+		typedef typename Rcpp::VectorBase<REALSXP,NA,T> VEC_TYPE;
+		typedef double (*FunPtr)(double,double,int) ;
+		
+		D1( FunPtr ptr_, const VEC_TYPE& vec_, double p0_ , bool log_) : 
+			ptr(ptr_), vec(vec_), p0(p0_), log(log_) {}
+		
+		inline double operator[]( int i) const {
+			return ptr( vec[i], p0, log );
+		}
+		
+		inline int size() const { return vec.size(); }
+		
+	private:
+		FunPtr ptr ;
+		const VEC_TYPE& vec;
+		double p0 ;
+		int log;
+	} ;
+	
+	template <bool NA, typename T>
+	class D2 : public Rcpp::VectorBase< REALSXP, NA, D2<NA,T> > {
+	public:
+		typedef typename Rcpp::VectorBase<REALSXP,NA,T> VEC_TYPE;
+		typedef double (*FunPtr)(double,double,double,int) ;
+		
+		D2( FunPtr ptr_, const VEC_TYPE& vec_, double p0_, double p1_ , bool log_) : 
+			ptr(ptr_), vec(vec_), p0(p0_), p1(p1_), log(log_) {}
+		
+		inline double operator[]( int i) const {
+			return ptr( vec[i], p0, p1, log );
+		}
+		
+		inline int size() const { return vec.size(); }
+		
+	private:
+		FunPtr ptr ;
+		const VEC_TYPE& vec;
+		double p0, p1 ;
+		int log;
+	} ;
+
+	template <bool NA, typename T>
+	class D3 : public Rcpp::VectorBase< REALSXP, NA, D3<NA,T> > {
+	public:
+		typedef typename Rcpp::VectorBase<REALSXP,NA,T> VEC_TYPE;
+		typedef double (*FunPtr)(double,double,double,double,int) ;
+		
+		D3( FunPtr ptr_, const VEC_TYPE& vec_, double p0_, double p1_, double p2_ , bool log_ ) : 
+			ptr(ptr_), vec(vec_), p0(p0_), p1(p1_), p2(p2_), log(log_) {}
+		
+		inline double operator[]( int i) const {
+			return ptr( vec[i], p0, p1, p2, log );
+		}
+		
+		inline int size() const { return vec.size(); }
+		
+	private:
+		FunPtr ptr ;
+		const VEC_TYPE& vec;
+		double p0, p1, p2 ;
+		int log;
+	} ;
+	
+	// P
+
+	
+	template <bool NA, typename T>
+	class P0 : public Rcpp::VectorBase< REALSXP, NA, P0<NA,T> >{
+	public:
+		typedef typename Rcpp::VectorBase<REALSXP,NA,T> VEC_TYPE;
+		typedef double (*FunPtr)(double,int,int) ;
+		
+		P0( FunPtr ptr_, const VEC_TYPE& vec_,
+			   bool lower_tail = true, bool log_ = false ) : 
+			ptr(ptr_), vec(vec_), lower(lower_tail), log(log_) {}
+		
+		inline double operator[]( int i) const {
+			return ptr( vec[i], lower, log );
+		}
+		
+		inline int size() const { return vec.size(); }
+		
+	private:
+		FunPtr ptr ;
+		const VEC_TYPE& vec;
+		int lower, log;
+	
+	};
+
+
+	template <bool NA, typename T>
+	class P1 : public Rcpp::VectorBase< REALSXP, NA, P1<NA,T> >{
+	public:
+		typedef typename Rcpp::VectorBase<REALSXP,NA,T> VEC_TYPE;
+		typedef double (*FunPtr)(double,double,int,int) ;
+		
+		P1( FunPtr ptr_, const VEC_TYPE& vec_, double p0_, 
+			   bool lower_tail = true, bool log_ = false ) : 
+			ptr(ptr_), vec(vec_), p0(p0_), lower(lower_tail), log(log_) {}
+		
+		inline double operator[]( int i) const {
+			return ptr( vec[i], p0, lower, log );
+		}
+		
+		inline int size() const { return vec.size(); }
+		
+	private:
+		FunPtr ptr ;
+		const VEC_TYPE& vec;
+		double p0 ;
+		int lower, log;
+	
+	};
+
+
+	template <bool NA, typename T>
+	class P2 : public Rcpp::VectorBase< REALSXP, NA, P2<NA,T> >{
+	public:
+		typedef typename Rcpp::VectorBase<REALSXP,NA,T> VEC_TYPE;
+		typedef double (*FunPtr)(double,double,double,int,int) ;
+		
+		P2( FunPtr ptr_, const VEC_TYPE& vec_, double p0_, double p1_, 
+			   bool lower_tail = true, bool log_ = false ) : 
+			ptr(ptr_), vec(vec_), p0(p0_), p1(p1_), lower(lower_tail), log(log_) {}
+		
+		inline double operator[]( int i) const {
+			return ptr( vec[i], p0, p1, lower, log );
+		}
+		
+		inline int size() const { return vec.size(); }
+		
+	private:
+		FunPtr ptr ;
+		const VEC_TYPE& vec;
+		double p0, p1 ;
+		int lower, log;
+	
+	};
+
+	template <bool NA, typename T>
+	class P3 : public Rcpp::VectorBase< REALSXP, NA, P3<NA,T> >{
+	public:
+		typedef typename Rcpp::VectorBase<REALSXP,NA,T> VEC_TYPE;
+		typedef double (*FunPtr)(double,double,double,double,int,int) ;
+		
+		P3( FunPtr ptr_, const VEC_TYPE& vec_, double p0_, double p1_, double p2_,  
+			   bool lower_tail = true, bool log_ = false ) : 
+			ptr(ptr_), vec(vec_), p0(p0_), p1(p1_), p2(p2_), lower(lower_tail), log(log_) {}
+		
+		inline double operator[]( int i) const {
+			return ptr( vec[i], p0, p1, p2, lower, log );
+		}
+		
+		inline int size() const { return vec.size(); }
+		
+	private:
+		FunPtr ptr ;
+		const VEC_TYPE& vec;
+		double p0, p1,p2 ;
+		int lower, log;
+	
+	};
+	
+	// Q
+	
+	
+	template <bool NA, typename T>
+	class Q0 : public Rcpp::VectorBase< REALSXP, NA, Q0<NA,T> >{
+	public:
+		typedef typename Rcpp::VectorBase<REALSXP,NA,T> VEC_TYPE;
+		typedef double (*FunPtr)(double,int,int) ;
+		
+		Q0( FunPtr ptr_, const VEC_TYPE& vec_,
+			   bool lower_tail = true, bool log_ = false ) : 
+			ptr(ptr_), vec(vec_), lower(lower_tail), log(log_) {}
+		
+		inline double operator[]( int i) const {
+			return ptr( vec[i], lower, log );
+		}
+		
+		inline int size() const { return vec.size(); }
+		
+	private:
+		FunPtr ptr ;
+		const VEC_TYPE& vec;
+		int lower, log;
+	
+	};
+
+	template <bool NA, typename T>
+	class Q1 : public Rcpp::VectorBase< REALSXP, NA, Q1<NA,T> >{
+	public:
+		typedef typename Rcpp::VectorBase<REALSXP,NA,T> VEC_TYPE;
+		typedef double (*FunPtr)(double,double,int,int) ;
+		
+		Q1( FunPtr ptr_, const VEC_TYPE& vec_, double p0_,
+			   bool lower_tail = true, bool log_ = false ) : 
+			ptr(ptr_), vec(vec_), p0(p0_), lower(lower_tail), log(log_) {}
+		
+		inline double operator[]( int i) const {
+			return ptr( vec[i], p0, lower, log );
+		}
+		
+		inline int size() const { return vec.size(); }
+		
+	private:
+		FunPtr ptr ;
+		const VEC_TYPE& vec;
+		double p0 ;
+		int lower, log;
+	
+	};
+
+	template <bool NA, typename T>
+	class Q2 : public Rcpp::VectorBase< REALSXP, NA, Q2<NA,T> >{
+	public:
+		typedef typename Rcpp::VectorBase<REALSXP,NA,T> VEC_TYPE;
+		typedef double (*FunPtr)(double,double,double,int,int) ;
+		
+		Q2( FunPtr ptr_, const VEC_TYPE& vec_, double p0_, double p1_,
+			   bool lower_tail = true, bool log_ = false ) : 
+			ptr(ptr_), vec(vec_), p0(p0_), p1(p1_), lower(lower_tail), log(log_) {}
+		
+		inline double operator[]( int i) const {
+			return ptr( vec[i], p0, p1, lower, log );
+		}
+		
+		inline int size() const { return vec.size(); }
+		
+	private:
+		FunPtr ptr ;
+		const VEC_TYPE& vec;
+		double p0, p1 ;
+		int lower, log;
+	
+	};
+
+	template <bool NA, typename T>
+	class Q3 : public Rcpp::VectorBase< REALSXP, NA, Q3<NA,T> >{
+	public:
+		typedef typename Rcpp::VectorBase<REALSXP,NA,T> VEC_TYPE;
+		typedef double (*FunPtr)(double,double,double,double,int,int) ;
+		
+		Q3( FunPtr ptr_, const VEC_TYPE& vec_, double p0_, double p1_, double p2_, 
+			   bool lower_tail = true, bool log_ = false ) : 
+			ptr(ptr_), vec(vec_), p0(p0_), p1(p1_), p2(p2_), lower(lower_tail), log(log_) {}
+		
+		inline double operator[]( int i) const {
+			return ptr( vec[i], p0, p1, p2, lower, log );
+		}
+		
+		inline int size() const { return vec.size(); }
+		
+	private:
+		FunPtr ptr ;
+		const VEC_TYPE& vec;
+		double p0, p1, p2 ;
+		int lower, log;
+	
+	};
+
+	
+} // stats
+} // Rcpp
+
+#define RCPP_DPQ_0(__NAME__,__D__,__P__,__Q__)                                         \
+namespace Rcpp {                                                                       \
+template <bool NA, typename T>                                                         \
+inline stats::D0<NA,T> d##__NAME__(                                                    \
+	const Rcpp::VectorBase<REALSXP,NA,T>& x, bool log = false                          \
+) {                                                                                    \
+	return stats::D0<NA,T>( __D__, x, log );                                           \
+}                                                                                      \
+template <bool NA, typename T>                                                         \
+inline stats::P0<NA,T> p##__NAME__(                                                    \
+	const Rcpp::VectorBase<REALSXP,NA,T>& x, bool lower = true, bool log = false       \
+) {                                                                                    \
+	return stats::P0<NA,T>( __P__, x, lower, log );                                    \
+}                                                                                      \
+template <bool NA, typename T>                                                         \
+inline stats::Q0<NA,T> q##__NAME__(                                                    \
+	const Rcpp::VectorBase<REALSXP,NA,T>& x, bool lower = true, bool log = false       \
+) {                                                                                    \
+	return stats::Q0<NA,T>( __Q__, x, lower, log );                                    \
+} }
+
+
+#define RCPP_DPQ_1(__NAME__,__D__,__P__,__Q__)                                         \
+namespace Rcpp {                                                                       \
+template <bool NA, typename T>                                                         \
+inline stats::D1<NA,T> d##__NAME__(                                                    \
+	const Rcpp::VectorBase<REALSXP,NA,T>& x, double p0, bool log = false                          \
+) {                                                                                    \
+	return stats::D1<NA,T>( __D__, x, p0, log );                                           \
+}                                                                                      \
+template <bool NA, typename T>                                                         \
+inline stats::P1<NA,T> p##__NAME__(                                                    \
+	const Rcpp::VectorBase<REALSXP,NA,T>& x, double p0, bool lower = true, bool log = false       \
+) {                                                                                    \
+	return stats::P1<NA,T>( __P__, x, p0, lower, log );                                    \
+}                                                                                      \
+template <bool NA, typename T>                                                         \
+inline stats::Q1<NA,T> q##__NAME__(                                                    \
+	const Rcpp::VectorBase<REALSXP,NA,T>& x, double p0, bool lower = true, bool log = false       \
+) {                                                                                    \
+	return stats::Q1<NA,T>( __Q__, x, p0, lower, log );                                    \
+} }
+
+
+
+#define RCPP_DPQ_2(__NAME__,__D__,__P__,__Q__)                                         \
+namespace Rcpp {                                                                       \
+template <bool NA, typename T>                                                         \
+inline stats::D2<NA,T> d##__NAME__(                                                    \
+	const Rcpp::VectorBase<REALSXP,NA,T>& x, double p0, double p1, bool log = false                          \
+) {                                                                                    \
+	return stats::D2<NA,T>( __D__, x, p0, p1, log );                                           \
+}                                                                                      \
+template <bool NA, typename T>                                                         \
+inline stats::P2<NA,T> p##__NAME__(                                                    \
+	const Rcpp::VectorBase<REALSXP,NA,T>& x, double p0, double p1, bool lower = true, bool log = false       \
+) {                                                                                    \
+	return stats::P2<NA,T>( __P__, x, p0, p1, lower, log );                                    \
+}                                                                                      \
+template <bool NA, typename T>                                                         \
+inline stats::Q2<NA,T> q##__NAME__(                                                    \
+	const Rcpp::VectorBase<REALSXP,NA,T>& x, double p0, double p1, bool lower = true, bool log = false       \
+) {                                                                                    \
+	return stats::Q2<NA,T>( __Q__, x, p0, p1, lower, log );                                    \
+} }
+
+
+
+#define RCPP_DPQ_3(__NAME__,__D__,__P__,__Q__)                                         \
+namespace Rcpp {                                                                       \
+template <bool NA, typename T>                                                         \
+inline stats::D3<NA,T> d##__NAME__(                                                    \
+	const Rcpp::VectorBase<REALSXP,NA,T>& x, double p0, double p1, double p2, bool log = false                          \
+) {                                                                                    \
+	return stats::D3<NA,T>( __D__, x, p0, p1, p2, log );                                           \
+}                                                                                      \
+template <bool NA, typename T>                                                         \
+inline stats::P3<NA,T> p##__NAME__(                                                    \
+	const Rcpp::VectorBase<REALSXP,NA,T>& x, double p0, double p1, double p2, bool lower = true, bool log = false       \
+) {                                                                                    \
+	return stats::P3<NA,T>( __P__, x, p0, p1, p2, lower, log );                                    \
+}                                                                                      \
+template <bool NA, typename T>                                                         \
+inline stats::Q3<NA,T> q##__NAME__(                                                    \
+	const Rcpp::VectorBase<REALSXP,NA,T>& x, double p0, double p1, double p2, bool lower = true, bool log = false       \
+) {                                                                                    \
+	return stats::Q3<NA,T>( __Q__, x, p0, p1, p2, lower, log );                                    \
+} }
+
+
+#endif

Modified: pkg/Rcpp/inst/include/Rcpp/stats/stats.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/stats.h	2010-08-13 21:14:35 UTC (rev 2003)
+++ pkg/Rcpp/inst/include/Rcpp/stats/stats.h	2010-08-14 17:46:02 UTC (rev 2004)
@@ -22,6 +22,8 @@
 #ifndef Rcpp__stats__stats_h
 #define Rcpp__stats__stats_h
 
+#include <Rcpp/stats/dpq/dpq.h>
+
 #include <Rcpp/stats/unif.h>
 #include <Rcpp/stats/norm.h>
 #include <Rcpp/stats/gamma.h>



More information about the Rcpp-commits mailing list