Rcpp Version 1.0.9
dpq.h
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 //
3 // dpq.h: Rcpp R/C++ interface class library -- normal distribution
4 //
5 // Copyright (C) 2010 - 2016 Dirk Eddelbuettel and Romain Francois
6 //
7 // This file is part of Rcpp.
8 //
9 // Rcpp is free software: you can redistribute it and/or modify it
10 // under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // Rcpp is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21 
22 #ifndef Rcpp__stats__dpq__dpq_h
23 #define Rcpp__stats__dpq__dpq_h
24 
25 #include <Rcpp/stats/dpq/macros.h>
26 
27 namespace Rcpp {
28 namespace stats {
29 
30 // D
31 
32 template <int RTYPE, bool NA, typename T>
33 class D0 : public Rcpp::VectorBase< REALSXP, NA, D0<RTYPE,NA,T> > {
34 public:
36  typedef double (*FunPtr)(double,int) ;
37 
38  D0( FunPtr ptr_, const VEC_TYPE& vec_, bool log_ ) :
39  ptr(ptr_), vec(vec_), log(log_) {}
40 
41  inline double operator[]( int i) const {
42  return ptr( vec[i], log );
43  }
44 
45  inline int size() const { return vec.size(); }
46 
47 private:
49  const VEC_TYPE& vec;
50  int log;
51 };
52 
53 template <int RTYPE, bool NA, typename T>
54 class D1 : public Rcpp::VectorBase< REALSXP, NA, D1<RTYPE,NA,T> > {
55 public:
57  typedef double (*FunPtr)(double,double,int) ;
58 
59  D1( FunPtr ptr_, const VEC_TYPE& vec_, double p0_ , bool log_) :
60  ptr(ptr_), vec(vec_), p0(p0_), log(log_) {}
61 
62  inline double operator[]( int i) const {
63  return ptr( vec[i], p0, log );
64  }
65 
66  inline int size() const { return vec.size(); }
67 
68 private:
70  const VEC_TYPE& vec;
71  double p0 ;
72  int log;
73 } ;
74 
75 template <int RTYPE, bool NA, typename T>
76 class D2 : public Rcpp::VectorBase< REALSXP, NA, D2<RTYPE,NA,T> > {
77 public:
79  typedef double (*FunPtr)(double,double,double,int) ;
80 
81  D2( FunPtr ptr_, const VEC_TYPE& vec_, double p0_, double p1_ , bool log_) :
82  ptr(ptr_), vec(vec_), p0(p0_), p1(p1_), log(log_) {}
83 
84  inline double operator[]( int i) const {
85  return ptr( vec[i], p0, p1, log );
86  }
87 
88  inline int size() const { return vec.size(); }
89 
90 private:
92  const VEC_TYPE& vec;
93  double p0, p1 ;
94  int log;
95 } ;
96 
97 template <int RTYPE, bool NA, typename T>
98 class D3 : public Rcpp::VectorBase< REALSXP, NA, D3<RTYPE,NA,T> > {
99 public:
101  typedef double (*FunPtr)(double,double,double,double,int) ;
102 
103  D3( FunPtr ptr_, const VEC_TYPE& vec_, double p0_, double p1_, double p2_ , bool log_ ) :
104  ptr(ptr_), vec(vec_), p0(p0_), p1(p1_), p2(p2_), log(log_) {}
105 
106  inline double operator[]( int i) const {
107  return ptr( vec[i], p0, p1, p2, log );
108  }
109 
110  inline int size() const { return vec.size(); }
111 
112 private:
114  const VEC_TYPE& vec;
115  double p0, p1, p2 ;
116  int log;
117 } ;
118 
119 // P
120 
121 
122 template <int RTYPE, bool NA, typename T>
123 class P0 : public Rcpp::VectorBase< REALSXP, NA, P0<RTYPE,NA,T> >{
124 public:
126  typedef double (*FunPtr)(double,int,int) ;
127 
128  P0( FunPtr ptr_, const VEC_TYPE& vec_,
129  bool lower_tail = true, bool log_ = false ) :
130  ptr(ptr_), vec(vec_), lower(lower_tail), log(log_) {}
131 
132  inline double operator[]( int i) const {
133  return ptr( vec[i], lower, log );
134  }
135 
136  inline int size() const { return vec.size(); }
137 
138 private:
140  const VEC_TYPE& vec;
141  int lower, log;
142 
143 };
144 
145 
146 template <int RTYPE, bool NA, typename T>
147 class P1 : public Rcpp::VectorBase< REALSXP, NA, P1<RTYPE,NA,T> >{
148 public:
150  typedef double (*FunPtr)(double,double,int,int) ;
151 
152  P1( FunPtr ptr_, const VEC_TYPE& vec_, double p0_,
153  bool lower_tail = true, bool log_ = false ) :
154  ptr(ptr_), vec(vec_), p0(p0_), lower(lower_tail), log(log_) {}
155 
156  inline double operator[]( int i) const {
157  return ptr( vec[i], p0, lower, log );
158  }
159 
160  inline int size() const { return vec.size(); }
161 
162 private:
164  const VEC_TYPE& vec;
165  double p0 ;
166  int lower, log;
167 
168 };
169 
170 
171 template <int RTYPE, bool NA, typename T>
172 class P2 : public Rcpp::VectorBase< REALSXP, NA, P2<RTYPE,NA,T> >{
173 public:
175  typedef double (*FunPtr)(double,double,double,int,int) ;
176 
177  P2( FunPtr ptr_, const VEC_TYPE& vec_, double p0_, double p1_,
178  bool lower_tail = true, bool log_ = false ) :
179  ptr(ptr_), vec(vec_), p0(p0_), p1(p1_), lower(lower_tail), log(log_) {}
180 
181  inline double operator[]( int i) const {
182  return ptr( vec[i], p0, p1, lower, log );
183  }
184 
185  inline int size() const { return vec.size(); }
186 
187 private:
189  const VEC_TYPE& vec;
190  double p0, p1 ;
191  int lower, log;
192 };
193 
194 template <int RTYPE, bool NA, typename T>
195 class P3 : public Rcpp::VectorBase< REALSXP, NA, P3<RTYPE,NA,T> >{
196 public:
198  typedef double (*FunPtr)(double,double,double,double,int,int) ;
199 
200  P3( FunPtr ptr_, const VEC_TYPE& vec_, double p0_, double p1_, double p2_,
201  bool lower_tail = true, bool log_ = false ) :
202  ptr(ptr_), vec(vec_), p0(p0_), p1(p1_), p2(p2_), lower(lower_tail), log(log_) {}
203 
204  inline double operator[]( int i) const {
205  return ptr( vec[i], p0, p1, p2, lower, log );
206  }
207 
208  inline int size() const { return vec.size(); }
209 
210 private:
212  const VEC_TYPE& vec;
213  double p0, p1,p2 ;
214  int lower, log;
215 
216 };
217 
218 // Q
219 
220 template <int RTYPE, bool NA, typename T>
221 class Q0 : public Rcpp::VectorBase< REALSXP, NA, Q0<RTYPE,NA,T> >{
222 public:
224  typedef double (*FunPtr)(double,int,int) ;
225 
226  Q0( FunPtr ptr_, const VEC_TYPE& vec_,
227  bool lower_tail = true, bool log_ = false ) :
228  ptr(ptr_), vec(vec_), lower(lower_tail), log(log_) {}
229 
230  inline double operator[]( int i) const {
231  return ptr( vec[i], lower, log );
232  }
233 
234  inline int size() const { return vec.size(); }
235 
236 private:
238  const VEC_TYPE& vec;
239  int lower, log;
240 
241 };
242 
243 template <int RTYPE, bool NA, typename T>
244 class Q1 : public Rcpp::VectorBase< REALSXP, NA, Q1<RTYPE,NA,T> >{
245 public:
247  typedef double (*FunPtr)(double,double,int,int) ;
248 
249  Q1( FunPtr ptr_, const VEC_TYPE& vec_, double p0_,
250  bool lower_tail = true, bool log_ = false ) :
251  ptr(ptr_), vec(vec_), p0(p0_), lower(lower_tail), log(log_) {}
252 
253  inline double operator[]( int i) const {
254  return ptr( vec[i], p0, lower, log );
255  }
256 
257  inline int size() const { return vec.size(); }
258 
259 private:
261  const VEC_TYPE& vec;
262  double p0 ;
263  int lower, log;
264 
265 };
266 
267 template <int RTYPE, bool NA, typename T>
268 class Q2 : public Rcpp::VectorBase< REALSXP, NA, Q2<RTYPE,NA,T> >{
269 public:
271  typedef double (*FunPtr)(double,double,double,int,int) ;
272 
273  Q2( FunPtr ptr_, const VEC_TYPE& vec_, double p0_, double p1_,
274  bool lower_tail = true, bool log_ = false ) :
275  ptr(ptr_), vec(vec_), p0(p0_), p1(p1_), lower(lower_tail), log(log_) {}
276 
277  inline double operator[]( int i) const {
278  return ptr( vec[i], p0, p1, lower, log );
279  }
280 
281  inline int size() const { return vec.size(); }
282 
283 private:
285  const VEC_TYPE& vec;
286  double p0, p1 ;
287  int lower, log;
288 
289 };
290 
291 template <int RTYPE, bool NA, typename T>
292 class Q3 : public Rcpp::VectorBase< REALSXP, NA, Q3<RTYPE,NA,T> >{
293 public:
295  typedef double (*FunPtr)(double,double,double,double,int,int) ;
296 
297  Q3( FunPtr ptr_, const VEC_TYPE& vec_, double p0_, double p1_, double p2_,
298  bool lower_tail = true, bool log_ = false ) :
299  ptr(ptr_), vec(vec_), p0(p0_), p1(p1_), p2(p2_), lower(lower_tail), log(log_) {}
300 
301  inline double operator[]( int i) const {
302  return ptr( vec[i], p0, p1, p2, lower, log );
303  }
304 
305  inline int size() const { return vec.size(); }
306 
307 private:
309  const VEC_TYPE& vec;
310  double p0, p1, p2 ;
311  int lower, log;
312 };
313 
314 
315 } // stats
316 } // Rcpp
317 
318 #define RCPP_DPQ_0(__NAME__,__D__,__P__,__Q__) \
319 namespace Rcpp { \
320 template <int RTYPE, bool NA, typename T> \
321 inline stats::D0<RTYPE,NA,T> d##__NAME__( \
322  const Rcpp::VectorBase<RTYPE,NA,T>& x, bool log = false \
323 ) { \
324  return stats::D0<RTYPE,NA,T>( __D__, x, log ); \
325 } \
326 template <int RTYPE, bool NA, typename T> \
327 inline stats::P0<RTYPE,NA,T> p##__NAME__( \
328  const Rcpp::VectorBase<RTYPE,NA,T>& x, bool lower = true, bool log = false \
329 ) { \
330  return stats::P0<RTYPE,NA,T>( __P__, x, lower, log ); \
331 } \
332 template <int RTYPE, bool NA, typename T> \
333 inline stats::Q0<RTYPE,NA,T> q##__NAME__( \
334  const Rcpp::VectorBase<RTYPE,NA,T>& x, bool lower = true, bool log = false \
335 ) { \
336  return stats::Q0<RTYPE,NA,T>( __Q__, x, lower, log ); \
337 } }
338 
339 
340 #define RCPP_DPQ_1(__NAME__,__D__,__P__,__Q__) \
341 namespace Rcpp { \
342 template <int RTYPE, bool NA, typename T> \
343 inline stats::D1<RTYPE,NA,T> d##__NAME__( \
344  const Rcpp::VectorBase<RTYPE,NA,T>& x, double p0, bool log = false \
345 ) { \
346  return stats::D1<RTYPE,NA,T>( __D__, x, p0, log ); \
347 } \
348 template <int RTYPE, bool NA, typename T> \
349 inline stats::P1<RTYPE,NA,T> p##__NAME__( \
350  const Rcpp::VectorBase<RTYPE,NA,T>& x, double p0, bool lower = true, bool log = false \
351 ) { \
352  return stats::P1<RTYPE,NA,T>( __P__, x, p0, lower, log ); \
353 } \
354 template <int RTYPE, bool NA, typename T> \
355 inline stats::Q1<RTYPE,NA,T> q##__NAME__( \
356  const Rcpp::VectorBase<RTYPE,NA,T>& x, double p0, bool lower = true, bool log = false \
357 ) { \
358  return stats::Q1<RTYPE,NA,T>( __Q__, x, p0, lower, log ); \
359 } }
360 
361 
362 
363 #define RCPP_DPQ_2(__NAME__,__D__,__P__,__Q__) \
364 namespace Rcpp { \
365 template <int RTYPE, bool NA, typename T> \
366 inline stats::D2<RTYPE,NA,T> d##__NAME__( \
367  const Rcpp::VectorBase<RTYPE,NA,T>& x, double p0, double p1, bool log = false \
368 ) { \
369  return stats::D2<RTYPE,NA,T>( __D__, x, p0, p1, log ); \
370 } \
371 template <int RTYPE, bool NA, typename T> \
372 inline stats::P2<RTYPE,NA,T> p##__NAME__( \
373  const Rcpp::VectorBase<RTYPE,NA,T>& x, double p0, double p1, bool lower = true, bool log = false \
374 ) { \
375  return stats::P2<RTYPE,NA,T>( __P__, x, p0, p1, lower, log ); \
376 } \
377 template <int RTYPE, bool NA, typename T> \
378 inline stats::Q2<RTYPE,NA,T> q##__NAME__( \
379  const Rcpp::VectorBase<RTYPE,NA,T>& x, double p0, double p1, bool lower = true, bool log = false \
380 ) { \
381  return stats::Q2<RTYPE,NA,T>( __Q__, x, p0, p1, lower, log ); \
382 } }
383 
384 
385 
386 #define RCPP_DPQ_3(__NAME__,__D__,__P__,__Q__) \
387 namespace Rcpp { \
388 template <int RTYPE, bool NA, typename T> \
389 inline stats::D3<RTYPE,NA,T> d##__NAME__( \
390  const Rcpp::VectorBase<RTYPE,NA,T>& x, double p0, double p1, double p2, bool log = false \
391 ) { \
392  return stats::D3<RTYPE,NA,T>( __D__, x, p0, p1, p2, log ); \
393 } \
394 template <int RTYPE, bool NA, typename T> \
395 inline stats::P3<RTYPE,NA,T> p##__NAME__( \
396  const Rcpp::VectorBase<RTYPE,NA,T>& x, double p0, double p1, double p2, bool lower = true, bool log = false \
397 ) { \
398  return stats::P3<RTYPE,NA,T>( __P__, x, p0, p1, p2, lower, log ); \
399 } \
400 template <int RTYPE, bool NA, typename T> \
401 inline stats::Q3<RTYPE,NA,T> q##__NAME__( \
402  const Rcpp::VectorBase<RTYPE,NA,T>& x, double p0, double p1, double p2, bool lower = true, bool log = false \
403 ) { \
404  return stats::Q3<RTYPE,NA,T>( __Q__, x, p0, p1, p2, lower, log ); \
405 } }
406 
407 
408 #endif
R_xlen_t size() const
Definition: VectorBase.h:49
const VEC_TYPE & vec
Definition: dpq.h:49
int size() const
Definition: dpq.h:45
double operator[](int i) const
Definition: dpq.h:41
double(* FunPtr)(double, int)
Definition: dpq.h:36
int log
Definition: dpq.h:50
FunPtr ptr
Definition: dpq.h:48
Rcpp::VectorBase< RTYPE, NA, T > VEC_TYPE
Definition: dpq.h:35
D0(FunPtr ptr_, const VEC_TYPE &vec_, bool log_)
Definition: dpq.h:38
double operator[](int i) const
Definition: dpq.h:62
D1(FunPtr ptr_, const VEC_TYPE &vec_, double p0_, bool log_)
Definition: dpq.h:59
FunPtr ptr
Definition: dpq.h:69
const VEC_TYPE & vec
Definition: dpq.h:70
double p0
Definition: dpq.h:71
int size() const
Definition: dpq.h:66
int log
Definition: dpq.h:72
double(* FunPtr)(double, double, int)
Definition: dpq.h:57
Rcpp::VectorBase< RTYPE, NA, T > VEC_TYPE
Definition: dpq.h:56
double operator[](int i) const
Definition: dpq.h:84
double p1
Definition: dpq.h:93
FunPtr ptr
Definition: dpq.h:91
double p0
Definition: dpq.h:93
D2(FunPtr ptr_, const VEC_TYPE &vec_, double p0_, double p1_, bool log_)
Definition: dpq.h:81
int size() const
Definition: dpq.h:88
Rcpp::VectorBase< RTYPE, NA, T > VEC_TYPE
Definition: dpq.h:78
int log
Definition: dpq.h:94
double(* FunPtr)(double, double, double, int)
Definition: dpq.h:79
const VEC_TYPE & vec
Definition: dpq.h:92
double p1
Definition: dpq.h:115
int size() const
Definition: dpq.h:110
double operator[](int i) const
Definition: dpq.h:106
double p2
Definition: dpq.h:115
D3(FunPtr ptr_, const VEC_TYPE &vec_, double p0_, double p1_, double p2_, bool log_)
Definition: dpq.h:103
double p0
Definition: dpq.h:115
double(* FunPtr)(double, double, double, double, int)
Definition: dpq.h:101
Rcpp::VectorBase< RTYPE, NA, T > VEC_TYPE
Definition: dpq.h:100
FunPtr ptr
Definition: dpq.h:113
const VEC_TYPE & vec
Definition: dpq.h:114
int size() const
Definition: dpq.h:136
double(* FunPtr)(double, int, int)
Definition: dpq.h:126
Rcpp::VectorBase< RTYPE, NA, T > VEC_TYPE
Definition: dpq.h:125
int lower
Definition: dpq.h:141
double operator[](int i) const
Definition: dpq.h:132
FunPtr ptr
Definition: dpq.h:139
P0(FunPtr ptr_, const VEC_TYPE &vec_, bool lower_tail=true, bool log_=false)
Definition: dpq.h:128
const VEC_TYPE & vec
Definition: dpq.h:140
double p0
Definition: dpq.h:165
double operator[](int i) const
Definition: dpq.h:156
int size() const
Definition: dpq.h:160
const VEC_TYPE & vec
Definition: dpq.h:164
double(* FunPtr)(double, double, int, int)
Definition: dpq.h:150
Rcpp::VectorBase< RTYPE, NA, T > VEC_TYPE
Definition: dpq.h:149
P1(FunPtr ptr_, const VEC_TYPE &vec_, double p0_, bool lower_tail=true, bool log_=false)
Definition: dpq.h:152
int lower
Definition: dpq.h:166
FunPtr ptr
Definition: dpq.h:163
FunPtr ptr
Definition: dpq.h:188
double p0
Definition: dpq.h:190
int size() const
Definition: dpq.h:185
double p1
Definition: dpq.h:190
const VEC_TYPE & vec
Definition: dpq.h:189
double operator[](int i) const
Definition: dpq.h:181
Rcpp::VectorBase< RTYPE, NA, T > VEC_TYPE
Definition: dpq.h:174
double(* FunPtr)(double, double, double, int, int)
Definition: dpq.h:175
P2(FunPtr ptr_, const VEC_TYPE &vec_, double p0_, double p1_, bool lower_tail=true, bool log_=false)
Definition: dpq.h:177
int lower
Definition: dpq.h:191
int size() const
Definition: dpq.h:208
double p1
Definition: dpq.h:213
Rcpp::VectorBase< RTYPE, NA, T > VEC_TYPE
Definition: dpq.h:197
FunPtr ptr
Definition: dpq.h:211
const VEC_TYPE & vec
Definition: dpq.h:212
double(* FunPtr)(double, double, double, double, int, int)
Definition: dpq.h:198
double p2
Definition: dpq.h:213
int lower
Definition: dpq.h:214
double p0
Definition: dpq.h:213
double operator[](int i) const
Definition: dpq.h:204
P3(FunPtr ptr_, const VEC_TYPE &vec_, double p0_, double p1_, double p2_, bool lower_tail=true, bool log_=false)
Definition: dpq.h:200
Rcpp::VectorBase< RTYPE, NA, T > VEC_TYPE
Definition: dpq.h:223
double operator[](int i) const
Definition: dpq.h:230
int lower
Definition: dpq.h:239
Q0(FunPtr ptr_, const VEC_TYPE &vec_, bool lower_tail=true, bool log_=false)
Definition: dpq.h:226
FunPtr ptr
Definition: dpq.h:237
const VEC_TYPE & vec
Definition: dpq.h:238
double(* FunPtr)(double, int, int)
Definition: dpq.h:224
int size() const
Definition: dpq.h:234
double operator[](int i) const
Definition: dpq.h:253
double p0
Definition: dpq.h:262
int lower
Definition: dpq.h:263
Rcpp::VectorBase< RTYPE, NA, T > VEC_TYPE
Definition: dpq.h:246
double(* FunPtr)(double, double, int, int)
Definition: dpq.h:247
FunPtr ptr
Definition: dpq.h:260
Q1(FunPtr ptr_, const VEC_TYPE &vec_, double p0_, bool lower_tail=true, bool log_=false)
Definition: dpq.h:249
const VEC_TYPE & vec
Definition: dpq.h:261
int size() const
Definition: dpq.h:257
int size() const
Definition: dpq.h:281
int lower
Definition: dpq.h:287
FunPtr ptr
Definition: dpq.h:284
const VEC_TYPE & vec
Definition: dpq.h:285
double operator[](int i) const
Definition: dpq.h:277
double(* FunPtr)(double, double, double, int, int)
Definition: dpq.h:271
double p0
Definition: dpq.h:286
Q2(FunPtr ptr_, const VEC_TYPE &vec_, double p0_, double p1_, bool lower_tail=true, bool log_=false)
Definition: dpq.h:273
Rcpp::VectorBase< RTYPE, NA, T > VEC_TYPE
Definition: dpq.h:270
double p1
Definition: dpq.h:286
int lower
Definition: dpq.h:311
int size() const
Definition: dpq.h:305
Rcpp::VectorBase< RTYPE, NA, T > VEC_TYPE
Definition: dpq.h:294
double(* FunPtr)(double, double, double, double, int, int)
Definition: dpq.h:295
double p1
Definition: dpq.h:310
double p0
Definition: dpq.h:310
Q3(FunPtr ptr_, const VEC_TYPE &vec_, double p0_, double p1_, double p2_, bool lower_tail=true, bool log_=false)
Definition: dpq.h:297
double operator[](int i) const
Definition: dpq.h:301
const VEC_TYPE & vec
Definition: dpq.h:309
double p2
Definition: dpq.h:310
FunPtr ptr
Definition: dpq.h:308
Rcpp API.
Definition: algo.h:28