Skip to content

Commit a63ac8c

Browse files
committed
final set of stats/random/ header cleanups
1 parent 0fadf62 commit a63ac8c

File tree

14 files changed

+225
-228
lines changed

14 files changed

+225
-228
lines changed

ChangeLog

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@
1010
* inst/include/Rcpp/stats/random/runif.h: Idem
1111
* inst/include/Rcpp/stats/random/rweibull.h: Idem
1212
* inst/include/Rcpp/stats/random/random.h: Idem
13+
* inst/include/Rcpp/stats/random/rcauchy.h: Idem
14+
* inst/include/Rcpp/stats/random/rchisq.h: Idem
15+
* inst/include/Rcpp/stats/random/rexp.h: Idem
16+
* inst/include/Rcpp/stats/random/rf.h: Idem
17+
* inst/include/Rcpp/stats/random/rgeom.h: Idem
18+
* inst/include/Rcpp/stats/random/rlnorm.h: Idem
19+
* inst/include/Rcpp/stats/random/rbeta.h: Idem
20+
* inst/include/Rcpp/stats/random/rbinom.h: Idem
21+
* inst/include/Rcpp/stats/random/rgamma.h: Idem
22+
* inst/include/Rcpp/stats/random/rhyper.h: Idem
23+
* inst/include/Rcpp/stats/random/rpois.h: Idem
24+
* inst/include/Rcpp/stats/random/rsignrank.h: Idem
25+
* inst/include/Rcpp/stats/random/rwilcox.h: Idem
1326

1427
2016-03-07 Dirk Eddelbuettel <[email protected]>
1528

inst/include/Rcpp/stats/random/rbeta.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
1+
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
22
//
33
// rbeta.h: Rcpp R/C++ interface class library --
44
//
5-
// Copyright (C) 2010 - 2012 Douglas Bates, Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2010 - 2016 Douglas Bates, Dirk Eddelbuettel and Romain Francois
66
//
77
// This file is part of Rcpp.
88
//
@@ -25,19 +25,18 @@
2525
namespace Rcpp {
2626
namespace stats{
2727

28-
class BetaGenerator : public Generator<double>{
29-
public:
30-
BetaGenerator(double a_, double b_) : a(a_), b(b_){}
28+
class BetaGenerator : public Generator<double>{
29+
public:
30+
BetaGenerator(double a_, double b_) : a(a_), b(b_){}
3131

32-
inline double operator()() const {
33-
return ::Rf_rbeta(a, b) ;
34-
}
35-
private:
36-
double a, b ;
37-
} ;
32+
inline double operator()() const {
33+
return ::Rf_rbeta(a, b) ;
34+
}
35+
private:
36+
double a, b ;
37+
};
3838

3939
} // namespace stats
40-
4140
} // Rcpp
4241

4342
#endif

inst/include/Rcpp/stats/random/rbinom.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
1+
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
22
//
33
// rbinom.h: Rcpp R/C++ interface class library --
44
//
5-
// Copyright (C) 2010 - 2012 Douglas Bates, Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2010 - 2016 Douglas Bates, Dirk Eddelbuettel and Romain Francois
66
//
77
// This file is part of Rcpp.
88
//
@@ -25,18 +25,17 @@
2525
namespace Rcpp {
2626
namespace stats {
2727

28-
class BinomGenerator : public Generator<double>{
29-
public:
30-
BinomGenerator( double nin_, double pp_ ) : nin(nin_), pp(pp_){}
31-
inline double operator()() const{
32-
return ::Rf_rbinom( nin, pp ) ;
33-
}
34-
private:
35-
double nin, pp ;
36-
} ;
28+
class BinomGenerator : public Generator<double>{
29+
public:
30+
BinomGenerator( double nin_, double pp_ ) : nin(nin_), pp(pp_){}
31+
inline double operator()() const{
32+
return ::Rf_rbinom( nin, pp ) ;
33+
}
34+
private:
35+
double nin, pp ;
36+
};
3737

3838
} // stats
39-
4039
} // Rcpp
4140

4241
#endif
Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
1+
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
22
//
33
// rcauchy.h: Rcpp R/C++ interface class library --
44
//
5-
// Copyright (C) 2010 - 2012 Douglas Bates, Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2010 - 2016 Douglas Bates, Dirk Eddelbuettel and Romain Francois
66
//
77
// This file is part of Rcpp.
88
//
@@ -28,44 +28,43 @@ namespace stats {
2828
class CauchyGenerator : public ::Rcpp::Generator<double> {
2929
public:
3030

31-
CauchyGenerator( double location_, double scale_) :
32-
location(location_) , scale(scale_) {}
31+
CauchyGenerator( double location_, double scale_) :
32+
location(location_) , scale(scale_) {}
3333

34-
inline double operator()() const {
35-
return location + scale * ::tan(M_PI * unif_rand()) ;
36-
}
34+
inline double operator()() const {
35+
return location + scale * ::tan(M_PI * unif_rand()) ;
36+
}
3737

3838
private:
39-
double location, scale ;
40-
} ;
39+
double location, scale ;
40+
};
4141

4242
class CauchyGenerator_1 : public ::Rcpp::Generator<double> {
4343
public:
4444

45-
CauchyGenerator_1( double location_) :
46-
location(location_){}
45+
CauchyGenerator_1( double location_) :
46+
location(location_){}
4747

48-
inline double operator()() const {
49-
return location + ::tan(M_PI * unif_rand()) ;
50-
}
48+
inline double operator()() const {
49+
return location + ::tan(M_PI * unif_rand()) ;
50+
}
5151

5252
private:
53-
double location ;
54-
} ;
53+
double location ;
54+
};
5555

5656
class CauchyGenerator_0 : public ::Rcpp::Generator<double> {
5757
public:
5858

59-
CauchyGenerator_0(){}
59+
CauchyGenerator_0(){}
6060

61-
inline double operator()() const {
62-
return ::tan(M_PI * unif_rand()) ;
63-
}
61+
inline double operator()() const {
62+
return ::tan(M_PI * unif_rand()) ;
63+
}
6464

65-
} ;
65+
};
6666

6767
} // stats
68-
6968
} // Rcpp
7069

7170
#endif
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
1+
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
22
//
33
// rchisq.h: Rcpp R/C++ interface class library --
44
//
5-
// Copyright (C) 2010 - 2012 Douglas Bates, Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2010 - 2016 Douglas Bates, Dirk Eddelbuettel and Romain Francois
66
//
77
// This file is part of Rcpp.
88
//
@@ -23,23 +23,22 @@
2323
#define Rcpp__stats__random_rchisq_h
2424

2525
namespace Rcpp {
26-
namespace stats {
26+
namespace stats {
2727

28+
class ChisqGenerator : public ::Rcpp::Generator<double> {
29+
public:
2830

29-
class ChisqGenerator : public ::Rcpp::Generator<double> {
30-
public:
31+
ChisqGenerator( double df_ ) : df_2(df_ / 2.0) {}
3132

32-
ChisqGenerator( double df_ ) : df_2(df_ / 2.0) {}
33+
inline double operator()() const {
34+
return ::Rf_rgamma( df_2, 2.0 ) ;
35+
}
3336

34-
inline double operator()() const {
35-
return ::Rf_rgamma( df_2, 2.0 ) ;
36-
}
37-
38-
private:
39-
double df_2 ;
40-
} ;
41-
} // stats
37+
private:
38+
double df_2 ;
39+
};
4240

41+
} // stats
4342
} // Rcpp
4443

4544
#endif

inst/include/Rcpp/stats/random/rexp.h

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
1+
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
22
//
33
// rexp.h: Rcpp R/C++ interface class library --
44
//
5-
// Copyright (C) 2010 - 2012 Douglas Bates, Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2010 - 2016 Douglas Bates, Dirk Eddelbuettel and Romain Francois
66
//
77
// This file is part of Rcpp.
88
//
@@ -23,31 +23,28 @@
2323
#define Rcpp__stats__random_rexp_h
2424

2525
namespace Rcpp {
26-
namespace stats {
26+
namespace stats {
2727

28+
class ExpGenerator : public ::Rcpp::Generator<double> {
29+
public:
2830

29-
class ExpGenerator : public ::Rcpp::Generator<double> {
30-
public:
31+
ExpGenerator( double scale_ ) : scale(scale_) {}
3132

32-
ExpGenerator( double scale_ ) : scale(scale_) {}
33+
inline double operator()() const {
34+
return scale * exp_rand() ;
35+
}
3336

34-
inline double operator()() const {
35-
return scale * exp_rand() ;
36-
}
37+
private:
38+
double scale ;
39+
};
3740

38-
private:
39-
double scale ;
40-
} ;
41-
42-
43-
class ExpGenerator__rate1 : public Generator<double>{
44-
public:
45-
ExpGenerator__rate1(){}
46-
inline double operator()() const { return exp_rand() ; }
47-
} ;
48-
49-
} // stats
41+
class ExpGenerator__rate1 : public Generator<double>{
42+
public:
43+
ExpGenerator__rate1(){}
44+
inline double operator()() const { return exp_rand() ; }
45+
};
5046

47+
} // stats
5148
}
5249

5350
#endif

inst/include/Rcpp/stats/random/rf.h

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*-
1+
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
22
//
33
// rf.h: Rcpp R/C++ interface class library --
44
//
5-
// Copyright (C) 2010 - 2013 Douglas Bates, Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2010 - 2016 Douglas Bates, Dirk Eddelbuettel and Romain Francois
66
//
77
// This file is part of Rcpp.
88
//
@@ -23,57 +23,53 @@
2323
#define Rcpp__stats__random_rf_h
2424

2525
namespace Rcpp {
26-
namespace stats {
26+
namespace stats {
2727

28+
class FGenerator_Finite_Finite : public ::Rcpp::Generator<double> {
29+
public:
2830

29-
class FGenerator_Finite_Finite : public ::Rcpp::Generator<double> {
30-
public:
31+
FGenerator_Finite_Finite( double n1_, double n2_ ) :
32+
n1__2(n1_ / 2.0 ), n2__2(n2_ / 2.0 ), ratio(n2_/n1_) {}
3133

32-
FGenerator_Finite_Finite( double n1_, double n2_ ) :
33-
n1__2(n1_ / 2.0 ), n2__2(n2_ / 2.0 ), ratio(n2_/n1_) {}
34+
inline double operator()() const {
35+
// here we know that both n1 and n2 are finite
36+
// return ( ::rchisq( n1 ) / n1 ) / ( ::rchisq( n2 ) / n2 );
37+
return ratio * ::Rf_rgamma( n1__2, 2.0 ) / ::Rf_rgamma( n2__2, 2.0 ) ;
38+
}
3439

35-
inline double operator()() const {
36-
// here we know that both n1 and n2 are finite
37-
// return ( ::rchisq( n1 ) / n1 ) / ( ::rchisq( n2 ) / n2 );
38-
return ratio * ::Rf_rgamma( n1__2, 2.0 ) / ::Rf_rgamma( n2__2, 2.0 ) ;
39-
}
40+
private:
41+
double n1__2, n2__2, ratio ;
42+
};
4043

41-
private:
42-
double n1__2, n2__2, ratio ;
43-
} ;
44+
class FGenerator_NotFinite_Finite : public ::Rcpp::Generator<double> {
45+
public:
4446

47+
FGenerator_NotFinite_Finite( double n2_ ) : n2( n2_), n2__2(n2_ / 2.0 ) {}
4548

46-
class FGenerator_NotFinite_Finite : public ::Rcpp::Generator<double> {
47-
public:
49+
inline double operator()() const {
50+
// return n2 / ::rchisq( n2 ) ;
51+
return n2 / ::Rf_rgamma( n2__2, 2.0 ) ;
52+
}
4853

49-
FGenerator_NotFinite_Finite( double n2_ ) : n2( n2_), n2__2(n2_ / 2.0 ) {}
54+
private:
55+
double n2, n2__2 ;
56+
};
5057

51-
inline double operator()() const {
52-
// return n2 / ::rchisq( n2 ) ;
53-
return n2 / ::Rf_rgamma( n2__2, 2.0 ) ;
54-
}
58+
class FGenerator_Finite_NotFinite : public ::Rcpp::Generator<double> {
59+
public:
5560

56-
private:
57-
double n2, n2__2 ;
58-
} ;
61+
FGenerator_Finite_NotFinite( double n1_ ) : n1(n1_), n1__2(n1_ / 2.0 ) {}
5962

63+
inline double operator()() const {
64+
// return ::rchisq( n1 ) / n1 ;
65+
return ::Rf_rgamma( n1__2, 2.0 ) / n1 ;
66+
}
6067

61-
class FGenerator_Finite_NotFinite : public ::Rcpp::Generator<double> {
62-
public:
63-
64-
FGenerator_Finite_NotFinite( double n1_ ) : n1(n1_), n1__2(n1_ / 2.0 ) {}
65-
66-
inline double operator()() const {
67-
// return ::rchisq( n1 ) / n1 ;
68-
return ::Rf_rgamma( n1__2, 2.0 ) / n1 ;
69-
}
70-
71-
private:
72-
double n1, n1__2 ;
73-
} ;
74-
75-
} // stats
68+
private:
69+
double n1, n1__2 ;
70+
};
7671

72+
} // stats
7773
} // Rcpp
7874

7975
#endif

0 commit comments

Comments
 (0)