[Rcpp-commits] r2013 - pkg/Rcpp/inst/include/Rcpp/stats/random
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Aug 15 13:51:15 CEST 2010
Author: romain
Date: 2010-08-15 13:51:15 +0200 (Sun, 15 Aug 2010)
New Revision: 2013
Modified:
pkg/Rcpp/inst/include/Rcpp/stats/random/rcauchy.h
Log:
default arguments for rcauchy
Modified: pkg/Rcpp/inst/include/Rcpp/stats/random/rcauchy.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/stats/random/rcauchy.h 2010-08-15 11:27:02 UTC (rev 2012)
+++ pkg/Rcpp/inst/include/Rcpp/stats/random/rcauchy.h 2010-08-15 11:51:15 UTC (rev 2013)
@@ -38,6 +38,32 @@
private:
double location, scale ;
} ;
+
+class CauchyGenerator_1 : public ::Rcpp::Generator<false,double> {
+public:
+
+ CauchyGenerator_1( double location_) :
+ location(location_){}
+
+ inline double operator()() const {
+ return location + ::tan(M_PI * unif_rand()) ;
+ }
+
+private:
+ double location ;
+} ;
+
+class CauchyGenerator_0 : public ::Rcpp::Generator<false,double> {
+public:
+
+ CauchyGenerator_0(){}
+
+ inline double operator()() const {
+ return ::tan(M_PI * unif_rand()) ;
+ }
+
+} ;
+
} // stats
// perhaps this should go to a cpp file
@@ -51,6 +77,20 @@
return NumericVector( n, stats::CauchyGenerator( location, scale ) ) ;
}
+inline NumericVector rcauchy( 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::CauchyGenerator_1( location ) ) ;
+}
+
+inline NumericVector rcauchy( int n /*, double location [=0.0] , double scale [=1.0] */ ){
+ return NumericVector( n, stats::CauchyGenerator_0() ) ;
+}
+
} // Rcpp
#endif
More information about the Rcpp-commits
mailing list