[Rcpp-commits] r1963 - 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 08:49:06 CEST 2010


Author: romain
Date: 2010-08-10 08:49:05 +0200 (Tue, 10 Aug 2010)
New Revision: 1963

Added:
   pkg/Rcpp/inst/include/Rcpp/stats/random/rcauchy.h
Modified:
   pkg/Rcpp/inst/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/stats/random/random.h
Log:
rcauchy

Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog	2010-08-10 06:26:10 UTC (rev 1962)
+++ pkg/Rcpp/inst/ChangeLog	2010-08-10 06:49:05 UTC (rev 1963)
@@ -6,6 +6,8 @@
 	
 	* inst/include/Rcpp/stats/random/rbeta.h: Added rbeta and rbeta_
 
+	* inst/include/Rcpp/stats/random/rcauchy.h: Added rcauchy and rcauchy_
+
 	* 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 06:26:10 UTC (rev 1962)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/random.h	2010-08-10 06:49:05 UTC (rev 1963)
@@ -24,6 +24,7 @@
 
 #include <Rcpp/stats/random/rbeta.h>
 #include <Rcpp/stats/random/rnorm.h>
+#include <Rcpp/stats/random/rcauchy.h>
 #include <Rcpp/stats/random/runif.h>
 
 #endif

Added: pkg/Rcpp/inst/include/Rcpp/stats/random/rcauchy.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rcauchy.h	                        (rev 0)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rcauchy.h	2010-08-10 06:49:05 UTC (rev 1963)
@@ -0,0 +1,63 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
+//
+// rcauchy.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_rcauchy_h
+#define Rcpp__stats__random_rcauchy_h
+
+namespace Rcpp {
+namespace stats {
+
+template <bool seed>
+class CauchyGenerator : public Rcpp::Generator<seed,double> {
+public:
+	
+	CauchyGenerator( double location_, double scale_) : 
+		location(location_) , scale(scale_) {}
+	
+	inline double operator()() const {
+		return location + scale * tan(M_PI * unif_rand())
+	}
+	
+private:
+	double location, scale ;
+} ;
+
+template <bool seed>
+Rcpp::NumericVector rcauchy__impl( int n, double location, double scale ){
+	if (ISNAN(location) || !R_FINITE(scale) || scale < 0)
+		return Rcpp::NumericVector( n, R_NaN ) ;
+	
+    if (scale == 0. || !R_FINITE(location))
+    	return Rcpp::NumericVector( n, location ) ;
+    
+	return Rcpp::NumericVector( n, CauchyGenerator<seed>( location, scale ) ) ;
+}
+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 ){
+	return rcauchy__impl<false>( n, location, scale );
+}
+
+}
+}
+
+#endif



More information about the Rcpp-commits mailing list