ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Vectorize.hpp
Go to the documentation of this file.
1 // Copyright (C) 2013-2015 Kasper Kristensen
2 // Modified for ADMB by Anders Nielsen
3 // License: GPL-2
4 
8 #ifndef _VFUN
9  #define _VFUN
10 
11 #include <df1b2fun.h>
12 
13 template<class VT>
15 };
16 
17 template<>
19  typedef double scalar;
20 };
21 
22 template<>
24  typedef dvariable scalar;
25 };
26 
27 template<>
30 };
31 
32 //typename getVectorType<dvariable>::vector
33 
34 // Function body type declarations
35 // V=vector, T=scalar, I=integer, N=none
36 //#define declareV(arg) const dvar_vector &arg
37 #define declareV(arg) const VectorType &arg
38 #define declareT(arg) typename getScalarType<VectorType>::scalar arg
39 #define declareI(arg) int arg
40 #define declareN(arg)
41 // How to extract elementwise subset of the four types
42 #define elementV(arg,i) (typename getScalarType<VectorType>::scalar) arg[arg.indexmin()+i]
43 #define elementT(arg,i) arg
44 #define elementI(arg,i) arg
45 #define elementN(arg,i)
46 // How to place comma in front of the types
47 #define commaV ,
48 #define commaT ,
49 #define commaI ,
50 #define commaN
51 // Update output vector size
52 #define outputsizeV(n,arg) n = ((arg.indexmax()-arg.indexmin()+1)>n ? (arg.indexmax()-arg.indexmin()+1) : n)
53 #define outputsizeT(n,arg)
54 #define outputsizeI(n,arg)
55 #define outputsizeN(n,arg)
56 
63 #define GVECTORIZE(FUN,Type1,Type2,Type3,Type4,Type5,Type6) \
64 template<class VectorType> \
65 VectorType FUN( declare##Type1(arg1) comma##Type2 \
66  declare##Type2(arg2) comma##Type3 \
67  declare##Type3(arg3) comma##Type4 \
68  declare##Type4(arg4) comma##Type5 \
69  declare##Type5(arg5) comma##Type6 \
70  declare##Type6(arg6) ) \
71 { \
72  int n = 0; \
73  outputsize##Type1(n,arg1); \
74  outputsize##Type2(n,arg2); \
75  outputsize##Type3(n,arg3); \
76  outputsize##Type4(n,arg4); \
77  outputsize##Type5(n,arg5); \
78  outputsize##Type6(n,arg6); \
79  VectorType res(1,n); \
80  for(int i=0;i<n;i++) res[i+1] = FUN( element##Type1(arg1,i) comma##Type2 \
81  element##Type2(arg2,i) comma##Type3 \
82  element##Type3(arg3,i) comma##Type4 \
83  element##Type4(arg4,i) comma##Type5 \
84  element##Type5(arg5,i) comma##Type6 \
85  element##Type6(arg6,i) ); \
86  return res; \
87 }
88 
90 #define VECTORIZE1_t(FUN) \
91  GVECTORIZE(FUN,V,N,N,N,N,N)
92 
98 #define VECTORIZE2_tt(FUN) \
99  GVECTORIZE(FUN,V,T,N,N,N,N) \
100  GVECTORIZE(FUN,T,V,N,N,N,N) \
101  GVECTORIZE(FUN,V,V,N,N,N,N)
102 
108 #define VECTORIZE3_tti(FUN) \
109  GVECTORIZE(FUN,V,T,I,N,N,N) \
110  GVECTORIZE(FUN,T,V,I,N,N,N) \
111  GVECTORIZE(FUN,V,V,I,N,N,N)
112 
118 #define VECTORIZE3_ttt(FUN) \
119  GVECTORIZE(FUN,V,T,T,N,N,N) \
120  GVECTORIZE(FUN,T,V,T,N,N,N) \
121  GVECTORIZE(FUN,T,T,V,N,N,N) \
122  GVECTORIZE(FUN,V,V,T,N,N,N) \
123  GVECTORIZE(FUN,T,V,V,N,N,N) \
124  GVECTORIZE(FUN,V,T,V,N,N,N) \
125  GVECTORIZE(FUN,V,V,V,N,N,N)
126 
132 #define VECTORIZE4_ttti(FUN) \
133  GVECTORIZE(FUN,V,T,T,I,N,N) \
134  GVECTORIZE(FUN,T,V,T,I,N,N) \
135  GVECTORIZE(FUN,T,T,V,I,N,N) \
136  GVECTORIZE(FUN,V,V,T,I,N,N) \
137  GVECTORIZE(FUN,T,V,V,I,N,N) \
138  GVECTORIZE(FUN,V,T,V,I,N,N) \
139  GVECTORIZE(FUN,V,V,V,I,N,N)
140 
146 #define VECTORIZE6_ttttti(FUN) \
147  GVECTORIZE(FUN,V,T,T,T,T,I) \
148  GVECTORIZE(FUN,T,V,T,T,T,I) \
149  GVECTORIZE(FUN,T,T,V,T,T,I) \
150  GVECTORIZE(FUN,V,V,T,T,T,I) \
151  GVECTORIZE(FUN,T,V,V,T,T,I) \
152  GVECTORIZE(FUN,V,T,V,T,T,I) \
153  GVECTORIZE(FUN,V,V,V,T,T,I)
154 
155 
156 
157 // functions vectorized
160 #endif
161 
162 
163 
double pbeta(const double x, const double a, const double b, int maxit)
beta distribution function for constant objects (alias of ibeta function with same arguments order as...
Definition: cbetai.cpp:47
Vector of double precision numbers.
Definition: dvector.h:50
double qbeta(double x, double a, double b, double eps)
Description not yet available.
Definition: df1b2fun.h:953
ADMB variable vector.
Definition: fvar.hpp:2172
Description not yet available.
Definition: df1b2fun.h:266
Description not yet available.
#define VECTORIZE3_ttt(FUN)
Vectorize 3-argument functions.
Definition: Vectorize.hpp:118
Fundamental data type for reverse mode automatic differentiation.
Definition: fvar.hpp:1518