[Rcpp-commits] r1931 - pkg/Rcpp/inst/include/Rcpp/stats

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Aug 6 00:39:57 CEST 2010


Author: dmbates
Date: 2010-08-06 00:39:57 +0200 (Fri, 06 Aug 2010)
New Revision: 1931

Modified:
   pkg/Rcpp/inst/include/Rcpp/stats/pois.h
Log:
ppois and qpois added and passing their tests


Modified: pkg/Rcpp/inst/include/Rcpp/stats/pois.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/pois.h	2010-08-05 22:39:26 UTC (rev 1930)
+++ pkg/Rcpp/inst/include/Rcpp/stats/pois.h	2010-08-05 22:39:57 UTC (rev 1931)
@@ -47,6 +47,48 @@
 	
 } ;
 
+template <bool NA, typename T>
+class PPois : public Rcpp::VectorBase< REALSXP, NA, PPois<NA,T> >{
+public:
+    typedef typename Rcpp::VectorBase<REALSXP,NA,T> VEC_TYPE ;
+	
+    PPois( const VEC_TYPE& vec_, double lambda_, bool lower_tail = true, bool log_ = false ) : 
+	vec(vec_), lambda(lambda_), lower(lower_tail), log(log_) {}
+	
+    inline double operator[]( int i) const {
+	return ::ppois( vec[i], lambda, lower, log ) ;
+    }
+	
+    inline int size() const { return vec.size(); }
+	
+private:
+    const VEC_TYPE& vec ;
+    double lambda ;
+    int lower, log ;
+	
+} ;
+
+template <bool NA, typename T>
+class QPois : public Rcpp::VectorBase< REALSXP, NA, QPois<NA,T> >{
+public:
+    typedef typename Rcpp::VectorBase<REALSXP,NA,T> VEC_TYPE ;
+	
+    QPois( const VEC_TYPE& vec_, double lambda_, bool lower_tail = true, bool log_ = false ) : 
+	vec(vec_), lambda(lambda_), lower(lower_tail), log(log_) {}
+	
+    inline double operator[]( int i) const {
+	return ::qpois( vec[i], lambda, lower, log ) ;
+    }
+	
+    inline int size() const { return vec.size(); }
+	
+private:
+    const VEC_TYPE& vec ;
+    double lambda ;
+    int lower, log ;
+	
+} ;
+
 } // impl
 
 template <bool NA, typename T>
@@ -54,7 +96,19 @@
 	return impl::DPois<NA,T>( x, lambda, log ); 
 }
 	
+template <bool NA, typename T>
+inline impl::PPois<NA,T> ppois( const Rcpp::VectorBase<REALSXP,NA,T>& x,
+				double lambda, bool lower = true, bool log = false ){
+    return impl::PPois<NA,T>( x, lambda, lower, log ); 
 }
+
+template <bool NA, typename T>
+inline impl::QPois<NA,T> qpois( const Rcpp::VectorBase<REALSXP,NA,T>& x,
+				double lambda, bool lower = true, bool log = false ){
+    return impl::QPois<NA,T>( x, lambda, lower, log ); 
 }
+	
+}
+}
 
 #endif



More information about the Rcpp-commits mailing list