Rcpp Version 1.0.14
Loading...
Searching...
No Matches
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
26
27namespace Rcpp {
28namespace stats {
29
30// D
31
32template <int RTYPE, bool NA, typename T>
33class D0 : public Rcpp::VectorBase< REALSXP, NA, D0<RTYPE,NA,T> > {
34public:
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
47private:
49 const VEC_TYPE& vec;
50 int log;
51};
52
53template <int RTYPE, bool NA, typename T>
54class D1 : public Rcpp::VectorBase< REALSXP, NA, D1<RTYPE,NA,T> > {
55public:
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
68private:
70 const VEC_TYPE& vec;
71 double p0 ;
72 int log;
73} ;
74
75template <int RTYPE, bool NA, typename T>
76class D2 : public Rcpp::VectorBase< REALSXP, NA, D2<RTYPE,NA,T> > {
77public:
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
90private:
92 const VEC_TYPE& vec;
93 double p0, p1 ;
94 int log;
95} ;
96
97template <int RTYPE, bool NA, typename T>
98class D3 : public Rcpp::VectorBase< REALSXP, NA, D3<RTYPE,NA,T> > {
99public:
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
112private:
114 const VEC_TYPE& vec;
115 double p0, p1, p2 ;
116 int log;
117} ;
118
119// P
120
121
122template <int RTYPE, bool NA, typename T>
123class P0 : public Rcpp::VectorBase< REALSXP, NA, P0<RTYPE,NA,T> >{
124public:
126 typedef double (*FunPtr)(double,int,int) ;
127
129 bool lower_tail = true, bool log_ = false ) :
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
138private:
140 const VEC_TYPE& vec;
141 int lower, log;
142
143};
144
145
146template <int RTYPE, bool NA, typename T>
147class P1 : public Rcpp::VectorBase< REALSXP, NA, P1<RTYPE,NA,T> >{
148public:
151
152 P1( FunPtr ptr_, const VEC_TYPE& vec_, double p0_,
153 bool lower_tail = true, bool log_ = false ) :
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
162private:
164 const VEC_TYPE& vec;
165 double p0 ;
166 int lower, log;
167
168};
169
170
171template <int RTYPE, bool NA, typename T>
172class P2 : public Rcpp::VectorBase< REALSXP, NA, P2<RTYPE,NA,T> >{
173public:
176
177 P2( FunPtr ptr_, const VEC_TYPE& vec_, double p0_, double p1_,
178 bool lower_tail = true, bool log_ = false ) :
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
187private:
189 const VEC_TYPE& vec;
190 double p0, p1 ;
191 int lower, log;
192};
193
194template <int RTYPE, bool NA, typename T>
195class P3 : public Rcpp::VectorBase< REALSXP, NA, P3<RTYPE,NA,T> >{
196public:
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
210private:
212 const VEC_TYPE& vec;
213 double p0, p1,p2 ;
214 int lower, log;
215
216};
217
218// Q
219
220template <int RTYPE, bool NA, typename T>
221class Q0 : public Rcpp::VectorBase< REALSXP, NA, Q0<RTYPE,NA,T> >{
222public:
224 typedef double (*FunPtr)(double,int,int) ;
225
227 bool lower_tail = true, bool log_ = false ) :
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
236private:
238 const VEC_TYPE& vec;
239 int lower, log;
240
241};
242
243template <int RTYPE, bool NA, typename T>
244class Q1 : public Rcpp::VectorBase< REALSXP, NA, Q1<RTYPE,NA,T> >{
245public:
248
249 Q1( FunPtr ptr_, const VEC_TYPE& vec_, double p0_,
250 bool lower_tail = true, bool log_ = false ) :
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
259private:
261 const VEC_TYPE& vec;
262 double p0 ;
263 int lower, log;
264
265};
266
267template <int RTYPE, bool NA, typename T>
268class Q2 : public Rcpp::VectorBase< REALSXP, NA, Q2<RTYPE,NA,T> >{
269public:
272
273 Q2( FunPtr ptr_, const VEC_TYPE& vec_, double p0_, double p1_,
274 bool lower_tail = true, bool log_ = false ) :
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
283private:
285 const VEC_TYPE& vec;
286 double p0, p1 ;
287 int lower, log;
288
289};
290
291template <int RTYPE, bool NA, typename T>
292class Q3 : public Rcpp::VectorBase< REALSXP, NA, Q3<RTYPE,NA,T> >{
293public:
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
307private:
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__) \
319namespace Rcpp { \
320template <int RTYPE, bool NA, typename T> \
321inline 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} \
326template <int RTYPE, bool NA, typename T> \
327inline 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} \
332template <int RTYPE, bool NA, typename T> \
333inline 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__) \
341namespace Rcpp { \
342template <int RTYPE, bool NA, typename T> \
343inline 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} \
348template <int RTYPE, bool NA, typename T> \
349inline 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} \
354template <int RTYPE, bool NA, typename T> \
355inline 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__) \
364namespace Rcpp { \
365template <int RTYPE, bool NA, typename T> \
366inline 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} \
371template <int RTYPE, bool NA, typename T> \
372inline 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} \
377template <int RTYPE, bool NA, typename T> \
378inline 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__) \
387namespace Rcpp { \
388template <int RTYPE, bool NA, typename T> \
389inline 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} \
394template <int RTYPE, bool NA, typename T> \
395inline 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} \
400template <int RTYPE, bool NA, typename T> \
401inline 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
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
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
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
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
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 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
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
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
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
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 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
T as(SEXP x)
Definition as.h:151