10 #define declareV(arg) const vector<Type> &arg 11 #define declareT(arg) Type arg 12 #define declareI(arg) int arg 15 #define elementV(arg,i) arg[i] 16 #define elementT(arg,i) arg 17 #define elementI(arg,i) arg 18 #define elementN(arg,i) 25 #define outputsizeV(n,arg) n = (arg.size()>n ? arg.size() : n) 26 #define outputsizeT(n,arg) 27 #define outputsizeI(n,arg) 28 #define outputsizeN(n,arg) 36 #define GVECTORIZE(FUN,Type1,Type2,Type3,Type4,Type5,Type6) \ 37 template <class Type> \ 38 vector<Type> FUN( declare##Type1(arg1) comma##Type2 \ 39 declare##Type2(arg2) comma##Type3 \ 40 declare##Type3(arg3) comma##Type4 \ 41 declare##Type4(arg4) comma##Type5 \ 42 declare##Type5(arg5) comma##Type6 \ 43 declare##Type6(arg6) ) \ 46 outputsize##Type1(n,arg1); \ 47 outputsize##Type2(n,arg2); \ 48 outputsize##Type3(n,arg3); \ 49 outputsize##Type4(n,arg4); \ 50 outputsize##Type5(n,arg5); \ 51 outputsize##Type6(n,arg6); \ 52 vector<Type> res(n); \ 53 for(int i=0;i<n;i++) res[i] = FUN( element##Type1(arg1,i) comma##Type2 \ 54 element##Type2(arg2,i) comma##Type3 \ 55 element##Type3(arg3,i) comma##Type4 \ 56 element##Type4(arg4,i) comma##Type5 \ 57 element##Type5(arg5,i) comma##Type6 \ 58 element##Type6(arg6,i) ); \ 63 #define VECTORIZE1_t(FUN) \ 64 GVECTORIZE(FUN,V,N,N,N,N,N) 71 #define VECTORIZE2_tt(FUN) \ 72 GVECTORIZE(FUN,V,T,N,N,N,N) \ 73 GVECTORIZE(FUN,T,V,N,N,N,N) \ 74 GVECTORIZE(FUN,V,V,N,N,N,N) 81 #define VECTORIZE3_tti(FUN) \ 82 GVECTORIZE(FUN,V,T,I,N,N,N) \ 83 GVECTORIZE(FUN,T,V,I,N,N,N) \ 84 GVECTORIZE(FUN,V,V,I,N,N,N) 91 #define VECTORIZE3_ttt(FUN) \ 92 GVECTORIZE(FUN,V,T,T,N,N,N) \ 93 GVECTORIZE(FUN,T,V,T,N,N,N) \ 94 GVECTORIZE(FUN,T,T,V,N,N,N) \ 95 GVECTORIZE(FUN,V,V,T,N,N,N) \ 96 GVECTORIZE(FUN,T,V,V,N,N,N) \ 97 GVECTORIZE(FUN,V,T,V,N,N,N) \ 98 GVECTORIZE(FUN,V,V,V,N,N,N) 105 #define VECTORIZE4_ttti(FUN) \ 106 GVECTORIZE(FUN,V,T,T,I,N,N) \ 107 GVECTORIZE(FUN,T,V,T,I,N,N) \ 108 GVECTORIZE(FUN,T,T,V,I,N,N) \ 109 GVECTORIZE(FUN,V,V,T,I,N,N) \ 110 GVECTORIZE(FUN,T,V,V,I,N,N) \ 111 GVECTORIZE(FUN,V,T,V,I,N,N) \ 112 GVECTORIZE(FUN,V,V,V,I,N,N) 119 #define VECTORIZE5_tttti(FUN) \ 120 GVECTORIZE(FUN,V,T,T,T,I,N) \ 121 GVECTORIZE(FUN,T,V,T,T,I,N) \ 122 GVECTORIZE(FUN,T,T,V,T,I,N) \ 123 GVECTORIZE(FUN,V,V,T,T,I,N) \ 124 GVECTORIZE(FUN,T,V,V,T,I,N) \ 125 GVECTORIZE(FUN,V,T,V,T,I,N) \ 126 GVECTORIZE(FUN,V,V,V,T,I,N) 133 #define VECTORIZE6_ttttti(FUN) \ 134 GVECTORIZE(FUN,V,T,T,T,T,I) \ 135 GVECTORIZE(FUN,T,V,T,T,T,I) \ 136 GVECTORIZE(FUN,T,T,V,T,T,I) \ 137 GVECTORIZE(FUN,V,V,T,T,T,I) \ 138 GVECTORIZE(FUN,T,V,V,T,T,I) \ 139 GVECTORIZE(FUN,V,T,V,T,T,I) \ 140 GVECTORIZE(FUN,V,V,V,T,T,I) 144 #define VECTORIZE1_n(FUN) \ 145 template<class Type> \ 146 vector<Type> FUN(int n, Type arg1) { \ 147 vector<Type> ans(n); \ 148 for(int i=0; i<n; i++) ans(i) = FUN(arg1); \ 154 #define VECTORIZE2_n(FUN) \ 155 template<class Type> \ 156 vector<Type> FUN(int n, Type arg1, Type arg2) { \ 157 vector<Type> ans(n); \ 158 for(int i=0; i<n; i++) ans(i) = FUN(arg1, arg2); \ 164 #define VECTORIZE3_n(FUN) \ 165 template<class Type> \ 166 vector<Type> FUN(int n, Type arg1, Type arg2, Type arg3) { \ 167 vector<Type> ans(n); \ 168 for(int i=0; i<n; i++) ans(i) = FUN(arg1, arg2, arg3); \ #define VECTORIZE2_tt(FUN)
Vectorize 2-argument functions.
#define VECTORIZE1_t(FUN)
Vectorize 1-argument functions.