Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : */
9 :
10 : #include "op_statistical.hxx"
11 :
12 : #include "formulagroup.hxx"
13 : #include "document.hxx"
14 : #include "formulacell.hxx"
15 : #include "tokenarray.hxx"
16 : #include "compiler.hxx"
17 : #include "interpre.hxx"
18 : #include <formula/vectortoken.hxx>
19 : #include <sstream>
20 : #include "opinlinefun_statistical.cxx"
21 :
22 : using namespace formula;
23 :
24 : namespace sc { namespace opencl {
25 0 : void OpVar::GenSlidingWindowFunction(std::stringstream &ss,
26 : const std::string &sSymName, SubArguments &vSubArguments)
27 : {
28 0 : ss << "\ndouble " << sSymName;
29 0 : ss << "_" << BinFuncName() << "(";
30 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
31 : {
32 0 : if (i)
33 0 : ss << ",";
34 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
35 : }
36 0 : ss << "){\n";
37 0 : ss << " int gid0 = get_global_id(0);\n";
38 0 : ss << " double fSum = 0.0;\n";
39 0 : ss << " double fMean = 0.0;\n";
40 0 : ss << " double vSum = 0.0;\n";
41 0 : ss << " double fCount = 0.0;\n";
42 0 : ss << " double arg = 0.0;\n";
43 0 : unsigned i = vSubArguments.size();
44 0 : while (i--)
45 : {
46 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
47 : assert(pCur);
48 0 : if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
49 : {
50 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
51 : {
52 : const formula::DoubleVectorRefToken* pDVR =
53 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
54 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
55 0 : ss << " for (int i = ";
56 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
57 : {
58 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
59 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
60 0 : ss << " {\n";
61 : }
62 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
63 : {
64 0 : ss << "0; i < " << pDVR->GetArrayLength();
65 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
66 0 : ss << " {\n";
67 : }
68 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
69 : {
70 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
71 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
72 0 : ss << " {\n";
73 : }
74 : else
75 : {
76 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
77 0 : ss << " {\n";
78 : }
79 0 : ss << " arg = ";
80 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
81 0 : ss << ";\n";
82 0 : ss << " if (isNan(arg))\n";
83 0 : ss << " continue;\n";
84 0 : ss << " fSum += arg;\n";
85 0 : ss << " fCount += 1.0;\n";
86 0 : ss << " }\n";
87 : }
88 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
89 : {
90 : const formula::SingleVectorRefToken* pSVR =
91 0 : static_cast< const formula::SingleVectorRefToken*>(pCur);
92 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
93 0 : ss << " {\n";
94 0 : ss << " arg = ";
95 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
96 0 : ss << " if (!isNan(arg))\n";
97 0 : ss << " {\n";
98 0 : ss << " fSum += arg;\n";
99 0 : ss << " fCount += 1.0;\n";
100 0 : ss << " }\n";
101 0 : ss << " }\n";
102 : }
103 : else
104 : {
105 0 : ss << " arg = " << pCur->GetDouble() << ";\n";
106 0 : ss << " fSum += arg;\n";
107 0 : ss << " fCount += 1.0;\n";
108 : }
109 : }
110 : else
111 : {
112 0 : ss << " arg = ";
113 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
114 0 : ss << " fSum += arg;\n";
115 0 : ss << " fCount += 1.0;\n";
116 : }
117 0 : if (i == 0)
118 : {
119 0 : ss << " fMean = fSum * pow(fCount,-1.0);\n";
120 : }
121 : }
122 0 : i = vSubArguments.size();
123 0 : while (i--)
124 : {
125 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
126 : assert(pCur);
127 0 : if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
128 : {
129 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
130 : {
131 : const formula::DoubleVectorRefToken* pDVR =
132 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
133 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
134 0 : ss << " for (int i = ";
135 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
136 : {
137 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
138 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
139 0 : ss << " {\n";
140 : }
141 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
142 : {
143 0 : ss << "0; i < " << pDVR->GetArrayLength();
144 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
145 0 : ss << " {\n";
146 : }
147 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
148 : {
149 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
150 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
151 0 : ss << " {\n";
152 : }
153 : else
154 : {
155 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
156 0 : ss << " {\n";
157 : }
158 :
159 0 : ss << " arg = ";
160 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
161 0 : ss << ";\n";
162 0 : ss << " if (isNan(arg))\n";
163 0 : ss << " continue;\n";
164 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
165 0 : ss << " }\n";
166 : }
167 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
168 : {
169 : const formula::SingleVectorRefToken* pSVR =
170 0 : static_cast< const formula::SingleVectorRefToken*>(pCur);
171 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
172 0 : ss << " {\n";
173 0 : ss << " if (!isNan(";
174 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
175 0 : ss << "))\n";
176 0 : ss << " {\n";
177 0 : ss << " arg = ";
178 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
179 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
180 0 : ss << " }\n";
181 0 : ss << " }\n";
182 : }
183 : else
184 : {
185 0 : ss << " arg=" << pCur->GetDouble() << ";\n";
186 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
187 : }
188 : }
189 : else
190 : {
191 0 : ss << " arg = ";
192 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
193 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
194 : }
195 : }
196 0 : ss << " if (fCount <= 1.0)\n";
197 0 : ss << " return CreateDoubleError(errDivisionByZero);\n";
198 0 : ss << " else\n";
199 0 : ss << " return vSum * pow(fCount - 1.0,-1.0);\n";
200 0 : ss << "}\n";
201 0 : }
202 0 : void OpZTest::BinInlineFun(std::set<std::string>& decls,
203 : std::set<std::string>& funs)
204 : {
205 0 : decls.insert(phiDecl);
206 0 : funs.insert(phi);
207 0 : decls.insert(taylorDecl);
208 0 : funs.insert(taylor);
209 0 : decls.insert(gaussDecl);
210 0 : funs.insert(gauss);
211 0 : }
212 0 : void OpZTest::GenSlidingWindowFunction(std::stringstream &ss,
213 : const std::string &sSymName, SubArguments &vSubArguments)
214 : {
215 0 : ss << "\ndouble " << sSymName;
216 0 : ss << "_" << BinFuncName() << "(";
217 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
218 : {
219 0 : if (i)
220 0 : ss << ",";
221 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
222 : }
223 0 : ss << "){\n";
224 0 : ss << " int gid0 = get_global_id(0);\n";
225 0 : ss << " double fSum = 0.0;\n";
226 0 : ss << " double fSumSqr = 0.0;\n";
227 0 : ss << " double mue = 0.0;\n";
228 0 : ss << " double fCount = 0.0;\n";
229 0 : ss << " double arg = 0.0;\n";
230 0 : ss << " double sigma = 0.0;\n";
231 0 : ss << " double mu = 0.0;\n";
232 0 : if(vSubArguments.size() == 1 || vSubArguments.size() == 0)
233 : {
234 0 : ss << " return DBL_MAX;\n";
235 0 : ss << "}\n";
236 0 : return ;
237 : }
238 0 : else if(vSubArguments.size() == 2)
239 : {
240 0 : FormulaToken *pCur = vSubArguments[0]->GetFormulaToken();
241 0 : FormulaToken *pCur1 = vSubArguments[1]->GetFormulaToken();
242 : assert(pCur);
243 : assert(pCur1);
244 0 : if(pCur->GetType() == formula::svDoubleVectorRef)
245 : {
246 : const formula::DoubleVectorRefToken* pDVR =
247 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
248 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
249 0 : ss << " for (int i = ";
250 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
251 : {
252 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
253 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
254 0 : ss << " {\n";
255 : }
256 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
257 : {
258 0 : ss << "0; i < " << pDVR->GetArrayLength();
259 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
260 0 : ss << " {\n";
261 : }
262 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
263 : {
264 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
265 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
266 0 : ss << " {\n";
267 : }
268 : else
269 : {
270 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
271 0 : ss << " {\n";
272 : }
273 :
274 0 : ss << " arg = ";
275 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
276 0 : ss << " if (isNan(arg))\n";
277 0 : ss << " continue;\n";
278 0 : ss << " fSum += arg;\n";
279 0 : ss << " fSumSqr += arg * arg;\n";
280 0 : ss << " fCount += 1.0;\n";
281 0 : ss << " }\n";
282 0 : ss << " if(fCount <= 1.0)\n";
283 0 : ss << " return DBL_MAX;\n";
284 0 : ss << " mue = fSum *pow(fCount,-1.0);\n";
285 0 : ss << " sigma = (fSumSqr-fSum*fSum*";
286 0 : ss << "pow(fCount,-1.0))*pow(fCount-1.0,-1.0);\n";
287 : }
288 : else
289 : {
290 0 : ss << " return DBL_MAX;\n";
291 0 : ss << "}\n";
292 0 : return ;
293 : }
294 0 : if(ocPush == vSubArguments[1]->GetFormulaToken()->GetOpCode())
295 : {
296 0 : if(pCur1->GetType() == formula::svSingleVectorRef)
297 : {
298 : const formula::SingleVectorRefToken* pSVR =
299 0 : static_cast<const formula::SingleVectorRefToken* >(pCur1);
300 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
301 0 : ss << " {\n";
302 0 : ss << " mu = " ;
303 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
304 0 : ss << " if (isNan(mu))\n";
305 0 : ss << " mu = 0.0;\n";
306 0 : ss << " }\n";
307 :
308 : }
309 0 : else if(pCur1->GetType() == formula::svDouble)
310 : {
311 0 : ss << " mu = " << pCur1->GetDouble() << ";\n";
312 : }
313 : else
314 : {
315 0 : ss << " return DBL_MAX;\n";
316 0 : ss << "}\n";
317 0 : return ;
318 : }
319 : }
320 : else
321 : {
322 0 : ss << " mu = " ;
323 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
324 : }
325 0 : ss << " return 0.5 - gauss((mue-mu)/sqrt(sigma/fCount));\n";
326 0 : ss << "}\n";
327 0 : return ;
328 : }
329 : else
330 : {
331 0 : FormulaToken *pCur = vSubArguments[0]->GetFormulaToken();
332 0 : FormulaToken *pCur1 = vSubArguments[1]->GetFormulaToken();
333 0 : FormulaToken *pCur2 = vSubArguments[2]->GetFormulaToken();
334 : assert(pCur);
335 : assert(pCur1);
336 : assert(pCur2);
337 0 : if(pCur->GetType() == formula::svDoubleVectorRef)
338 : {
339 : const formula::DoubleVectorRefToken* pDVR =
340 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
341 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
342 0 : ss << " for (int i = ";
343 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
344 : {
345 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
346 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
347 0 : ss << " {\n";
348 : }
349 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
350 : {
351 0 : ss << "0; i < " << pDVR->GetArrayLength();
352 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
353 0 : ss << " {\n";
354 : }
355 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
356 : {
357 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
358 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
359 0 : ss << " {\n";
360 : }
361 : else
362 : {
363 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
364 0 : ss << " {\n";
365 : }
366 0 : ss << " arg = ";
367 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
368 0 : ss << " if (isNan(arg))\n";
369 0 : ss << " continue;\n";
370 0 : ss << " fSum += arg;\n";
371 0 : ss << " fSumSqr += arg * arg;\n";
372 0 : ss << " fCount += 1.0;\n";
373 0 : ss << " }\n";
374 0 : ss << " if(fCount <= 1.0)\n";
375 0 : ss << " return DBL_MAX;\n";
376 0 : ss << " mue = fSum * pow(fCount,-1.0);\n";
377 : }
378 : else
379 : {
380 0 : ss << " return DBL_MAX;\n";
381 0 : ss << "}\n";
382 0 : return ;
383 : }
384 0 : if(ocPush == vSubArguments[1]->GetFormulaToken()->GetOpCode())
385 : {
386 0 : if(pCur1->GetType() == formula::svSingleVectorRef)
387 : {
388 : const formula::SingleVectorRefToken* pSVR1 =
389 0 : static_cast<const formula::SingleVectorRefToken* >(pCur1);
390 0 : ss << " if (gid0 < " << pSVR1->GetArrayLength() << ")\n";
391 0 : ss << " {\n";
392 0 : ss << " mu = " ;
393 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
394 0 : ss << " if (isNan(mu))\n";
395 0 : ss << " mu = 0.0;\n";
396 0 : ss << " }\n";
397 : }
398 0 : else if(pCur1->GetType() == formula::svDouble)
399 : {
400 0 : ss << " mu = " << pCur1->GetDouble() << ";\n";
401 : }
402 : else
403 : {
404 0 : ss << " return DBL_MAX;\n";
405 0 : ss << "}\n";
406 0 : return ;
407 : }
408 : }
409 : else
410 : {
411 0 : ss << " mu=" ;
412 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
413 : }
414 0 : if(ocPush == vSubArguments[2]->GetFormulaToken()->GetOpCode())
415 : {
416 0 : if(pCur2->GetType() == formula::svSingleVectorRef)
417 : {
418 : const formula::SingleVectorRefToken* pSVR2 =
419 0 : static_cast<const formula::SingleVectorRefToken* >(pCur2);
420 0 : ss << " if (gid0 < " << pSVR2->GetArrayLength() << ")\n";
421 0 : ss << " {\n";
422 0 : ss << " sigma = " ;
423 0 : ss << vSubArguments[2]->GenSlidingWindowDeclRef() << ";\n";
424 0 : ss << " if (isNan(sigma))\n";
425 0 : ss << " sigma = 0.0;\n";
426 0 : ss << " }\n";
427 : }
428 0 : else if(pCur2->GetType() == formula::svDouble)
429 : {
430 0 : ss << " sigma = " << pCur2->GetDouble() << ";\n";
431 : }
432 : else
433 : {
434 0 : ss << " return DBL_MAX;\n";
435 0 : ss << "}\n";
436 0 : return ;
437 : }
438 : }
439 : else
440 : {
441 0 : ss << " sigma = " ;
442 0 : ss << vSubArguments[2]->GenSlidingWindowDeclRef() << ";\n";
443 : }
444 0 : ss << " return 0.5 - gauss((mue-mu)*sqrt(fCount)/sigma);\n";
445 0 : ss << "}\n";
446 : }
447 : }
448 :
449 0 : void OpTTest::BinInlineFun(std::set<std::string>& decls,
450 : std::set<std::string>& funs)
451 : {
452 0 : decls.insert(fMachEpsDecl);
453 0 : funs.insert("");
454 0 : decls.insert(fMaxGammaArgumentDecl);
455 0 : funs.insert("");
456 0 : decls.insert(lcl_getLanczosSumDecl);
457 0 : funs.insert(lcl_getLanczosSum);
458 0 : decls.insert(GetBetaDecl);
459 0 : funs.insert(GetBeta);
460 0 : decls.insert(GetLogBetaDecl);
461 0 : funs.insert(GetLogBeta);
462 0 : decls.insert(GetBetaDistPDFDecl);
463 0 : funs.insert(GetBetaDistPDF);
464 0 : decls.insert(lcl_GetBetaHelperContFracDecl);
465 0 : funs.insert(lcl_GetBetaHelperContFrac);
466 0 : decls.insert(GetBetaDistDecl);
467 0 : funs.insert(GetBetaDist);
468 0 : decls.insert(GetTDistDecl);
469 0 : funs.insert(GetTDist);
470 0 : }
471 :
472 0 : void OpTTest::GenSlidingWindowFunction(std::stringstream &ss,
473 : const std::string &sSymName, SubArguments &vSubArguments)
474 : {
475 0 : ss << "\ndouble " << sSymName;
476 0 : ss << "_" << BinFuncName() << "(";
477 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
478 : {
479 0 : if (i)
480 0 : ss << ",";
481 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
482 : }
483 0 : ss << "){\n";
484 0 : ss << " int gid0 = get_global_id(0);\n";
485 0 : ss << " double fSum1 = 0.0;\n";
486 0 : ss << " double fSum2 = 0.0;\n";
487 0 : ss << " double fSumSqr1 = 0.0;\n";
488 0 : ss << " double fSumSqr2 = 0.0;\n";
489 0 : ss << " double fCount1 = 0.0;\n";
490 0 : ss << " double fCount2 = 0.0;\n";
491 0 : ss << " double arg1 = 0.0;\n";
492 0 : ss << " double arg2 = 0.0;\n";
493 0 : ss << " double mode = 0.0;\n";
494 0 : ss << " double type = 0.0;\n";
495 0 : ss << " double fT = 0.0;\n";
496 0 : ss << " double fF = 0.0;\n";
497 0 : if(vSubArguments.size() != 4)
498 : {
499 0 : ss << " return DBL_MAX;\n";
500 0 : ss << "}\n";
501 0 : return ;
502 : }
503 0 : if(vSubArguments.size() == 4)
504 : {
505 0 : FormulaToken *pCur = vSubArguments[0]->GetFormulaToken();
506 0 : FormulaToken *pCur1 = vSubArguments[1]->GetFormulaToken();
507 0 : FormulaToken *pCur2 = vSubArguments[2]->GetFormulaToken();
508 0 : FormulaToken *pCur3 = vSubArguments[3]->GetFormulaToken();
509 : assert(pCur);
510 : assert(pCur1);
511 : assert(pCur2);
512 : assert(pCur3);
513 0 : if(ocPush == vSubArguments[2]->GetFormulaToken()->GetOpCode())
514 : {
515 0 : if(pCur2->GetType() == formula::svSingleVectorRef)
516 : {
517 : const formula::SingleVectorRefToken* pSVR =
518 0 : static_cast< const formula::SingleVectorRefToken*>(pCur2);
519 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
520 0 : ss << " {\n";
521 0 : ss << " mode = " ;
522 0 : ss << vSubArguments[2]->GenSlidingWindowDeclRef() << ";\n";
523 0 : ss << " if (isNan(mode))\n";
524 0 : ss << " mode = 0.0;\n";
525 0 : ss << " else\n";
526 0 : ss << " mode = floor(mode);\n";
527 0 : ss << " }\n";
528 : }
529 0 : else if(pCur2->GetType() == formula::svDouble)
530 : {
531 0 : ss << " mode = floor(convert_double(";
532 0 : ss << pCur2->GetDouble() << "));\n";
533 : }
534 : else
535 : {
536 0 : ss << " return DBL_MAX;\n";
537 0 : ss << "}\n";
538 0 : return ;
539 : }
540 : }
541 : else
542 : {
543 0 : ss << " mode = floor(" ;
544 0 : ss << vSubArguments[2]->GenSlidingWindowDeclRef() << ");\n";
545 : }
546 0 : ss << " if(!(mode == 1.0 || mode == 2.0))\n";
547 0 : ss << " return DBL_MAX;\n";
548 0 : if(ocPush==vSubArguments[3]->GetFormulaToken()->GetOpCode())
549 : {
550 0 : if(pCur3->GetType() == formula::svSingleVectorRef)
551 : {
552 : const formula::SingleVectorRefToken* pSVR =
553 0 : static_cast< const formula::SingleVectorRefToken*>(pCur3);
554 : assert(pSVR);
555 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
556 0 : ss << " {\n";
557 0 : ss << " if (isNan(";
558 0 : ss << vSubArguments[3]->GenSlidingWindowDeclRef() << "))\n";
559 0 : ss << " type=0.0;\n";
560 0 : ss << " else\n";
561 0 : ss << " type=floor(";
562 0 : ss << vSubArguments[3]->GenSlidingWindowDeclRef() << ");\n";
563 0 : ss << " }\n";
564 : }
565 0 : else if(pCur3->GetType() == formula::svDouble)
566 : {
567 0 : ss << " type = floor(convert_double(" << pCur3->GetDouble() <<
568 0 : "));\n";
569 : }
570 : else
571 : {
572 0 : ss << " return DBL_MAX;\n";
573 0 : ss << "}\n";
574 0 : return ;
575 : }
576 : }
577 : else
578 : {
579 0 : ss << " type=floor(";
580 0 : ss << vSubArguments[3]->GenSlidingWindowDeclRef() << ");\n";
581 : }
582 0 : ss << " if(!(type == 1.0||type == 2.0||type == 3.0))\n";
583 0 : ss << " return DBL_MAX;\n";
584 :
585 0 : if(pCur->GetType() == formula::svDoubleVectorRef &&
586 0 : pCur1->GetType() == formula::svDoubleVectorRef)
587 : {
588 : const formula::DoubleVectorRefToken* pDVR =
589 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
590 : const formula::DoubleVectorRefToken* pDVR1 =
591 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur1);
592 :
593 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
594 0 : size_t nCurWindowSize1 = pDVR1->GetRefRowSize();
595 :
596 0 : if(nCurWindowSize == nCurWindowSize1)
597 : {
598 0 : ss << " if(type == 1.0)\n";
599 0 : ss << " {\n";
600 0 : ss << " for (int i = ";
601 0 : if ((!pDVR->IsStartFixed() && pDVR->IsEndFixed()) &&
602 0 : (!pDVR1->IsStartFixed() && pDVR1->IsEndFixed()))
603 : {
604 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
605 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
606 0 : ss << " {\n";
607 : }
608 0 : else if ((pDVR->IsStartFixed() && !pDVR->IsEndFixed()) &&
609 0 : (pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
610 : {
611 0 : ss << "0; i < " << pDVR->GetArrayLength();
612 0 : ss << " && i < gid0+"<< nCurWindowSize << "; i++)\n";
613 0 : ss << " {\n";
614 : }
615 0 : else if ((!pDVR->IsStartFixed() && !pDVR->IsEndFixed()) &&
616 0 : (!pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
617 : {
618 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
619 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
620 0 : ss << " {\n";
621 : }
622 0 : else if ((pDVR->IsStartFixed() && pDVR->IsEndFixed()) &&
623 0 : (pDVR1->IsStartFixed() && pDVR1->IsEndFixed()))
624 : {
625 0 : ss << "0; i < " << nCurWindowSize << "; i++)\n";
626 0 : ss << " {\n";
627 : }
628 : else
629 : {
630 0 : ss << "0; i < " << nCurWindowSize << "; i++)\n";
631 0 : ss << " {\n";
632 0 : ss << " break;\n";
633 0 : ss << " }";
634 0 : ss << " return DBL_MAX;\n";
635 0 : ss << " }\n";
636 0 : ss << "}\n";
637 0 : return ;
638 : }
639 :
640 0 : ss << " arg1 = ";
641 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef(true) << ";\n";
642 0 : ss << " arg2 = ";
643 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef(true) << ";\n";
644 0 : ss << " if (isNan(arg1)||isNan(arg2))\n";
645 0 : ss << " continue;\n";
646 0 : ss << " fSum1 += arg1;\n";
647 0 : ss << " fSum2 += arg2;\n";
648 0 : ss << " fSumSqr1 += (arg1 - arg2)*(arg1 - arg2);\n";
649 0 : ss << " fCount1 += 1;\n";
650 0 : ss << " }\n";
651 0 : ss << " if(fCount1 < 1.0)\n";
652 0 : ss << " return DBL_MAX;\n";
653 0 : ss << " fT = sqrt(fCount1-1.0) * fabs(fSum1 - fSum2)\n";
654 0 : ss << " /sqrt(fCount1 * fSumSqr1 - (fSum1-fSum2)\n";
655 0 : ss << " *(fSum1-fSum2));\n";
656 0 : ss << " fF = fCount1 - 1.0;\n";
657 : }
658 : else
659 : {
660 0 : ss << " return DBL_MAX;\n";
661 0 : ss << "}\n";
662 0 : return ;
663 : }
664 : }
665 : else
666 : {
667 0 : ss << " return DBL_MAX;\n";
668 0 : ss << "}\n";
669 0 : return ;
670 : }
671 0 : ss << " }\n";
672 0 : ss << " if(type == 2.0 || type == 3.0)\n";
673 0 : ss << " {\n";
674 :
675 0 : if(pCur->GetType() == formula::svDoubleVectorRef &&
676 0 : pCur1->GetType() == formula::svDoubleVectorRef)
677 : {
678 : const formula::DoubleVectorRefToken* pDVR =
679 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
680 : const formula::DoubleVectorRefToken* pDVR1 =
681 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur1);
682 :
683 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
684 0 : size_t nCurWindowSize1 = pDVR1->GetRefRowSize();
685 0 : ss << " for (int i = ";
686 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
687 : {
688 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
689 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
690 0 : ss << " {\n";
691 : }
692 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
693 : {
694 0 : ss << "0; i < " << pDVR->GetArrayLength();
695 0 : ss << " && i < gid0+"<< nCurWindowSize << "; i++)\n";
696 0 : ss << " {\n";
697 : }
698 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
699 : {
700 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
701 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
702 0 : ss << " {\n";
703 : }
704 : else
705 : {
706 0 : ss << "0; i < " << nCurWindowSize << "; i++)\n";
707 0 : ss << " {\n";
708 : }
709 :
710 0 : ss << " arg1 = ";
711 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef(true) << ";\n";
712 0 : ss << " if (isNan(arg1))\n";
713 0 : ss << " continue;\n";
714 0 : ss << " fSum1 += arg1;\n";
715 0 : ss << " fSumSqr1 += arg1 * arg1;\n";
716 0 : ss << " fCount1 += 1;\n";
717 0 : ss << " }\n";
718 :
719 0 : ss << " for (int i = ";
720 0 : if (!pDVR1->IsStartFixed() && pDVR1->IsEndFixed())
721 : {
722 0 : ss << "gid0; i < " << pDVR1->GetArrayLength();
723 0 : ss << " && i < " << nCurWindowSize1 << "; i++)\n";
724 0 : ss << " {\n";
725 : }
726 0 : else if (pDVR1->IsStartFixed() && !pDVR1->IsEndFixed())
727 : {
728 0 : ss << "0; i < " << pDVR1->GetArrayLength();
729 0 : ss << " && i < gid0+"<< nCurWindowSize1 << "; i++)\n";
730 0 : ss << " {\n";
731 : }
732 0 : else if (!pDVR1->IsStartFixed() && !pDVR1->IsEndFixed())
733 : {
734 0 : ss << "0; i + gid0 < " << pDVR1->GetArrayLength();
735 0 : ss << " && i < " << nCurWindowSize1 << "; i++)\n";
736 0 : ss << " {\n";
737 : }
738 : else
739 : {
740 0 : ss << "0; i < " << nCurWindowSize1 << "; i++)\n";
741 0 : ss << " {\n";
742 : }
743 0 : ss << " arg2 = ";
744 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef(true) << ";\n";
745 0 : ss << " if (isNan(arg2))\n";
746 0 : ss << " continue;\n";
747 0 : ss << " fSum2 += arg2;\n";
748 0 : ss << " fSumSqr2 += arg2 * arg2;\n";
749 0 : ss << " fCount2 += 1;\n";
750 0 : ss << " }\n";
751 : }
752 : else
753 : {
754 0 : ss << " return DBL_MAX;\n";
755 0 : ss << " }\n";
756 0 : ss << "}\n";
757 0 : return ;
758 : }
759 0 : ss << " if (fCount1 < 2.0 || fCount2 < 2.0)\n";
760 0 : ss << " return DBL_MAX;\n";
761 0 : ss << " }\n";
762 0 : ss << " if(type == 3.0)\n";
763 0 : ss << " {\n";
764 0 : ss << " double fS1 = (fSumSqr1-fSum1*fSum1/fCount1)\n";
765 0 : ss << " /(fCount1-1.0)/fCount1;\n";
766 0 : ss << " double fS2 = (fSumSqr2-fSum2*fSum2/fCount2)\n";
767 0 : ss << " /(fCount2-1.0)/fCount2;\n";
768 0 : ss << " if (fS1 + fS2 == 0.0)\n";
769 0 : ss << " return DBL_MAX;\n";
770 0 : ss << " fT = fabs(fSum1/fCount1 - fSum2/fCount2)\n";
771 0 : ss << " /sqrt(fS1+fS2);\n";
772 0 : ss << " double c = fS1/(fS1+fS2);\n";
773 0 : ss << " fF = 1.0/(c*c/(fCount1-1.0)+(1.0-c)*(1.0-c)\n";
774 0 : ss << " /(fCount2-1.0));\n";
775 0 : ss << " }\n";
776 0 : ss << " if(type == 2.0)\n";
777 0 : ss << " {\n";
778 0 : ss << " double fS1 = (fSumSqr1 - fSum1*fSum1/fCount1)\n";
779 0 : ss << " /(fCount1 - 1.0);\n";
780 0 : ss << " double fS2 = (fSumSqr2 - fSum2*fSum2/fCount2)\n";
781 0 : ss << " /(fCount2 - 1.0);\n";
782 0 : ss << " fT = fabs( fSum1/fCount1 - fSum2/fCount2 )\n";
783 0 : ss << " /sqrt( (fCount1-1.0)*fS1 + (fCount2-1.0)*fS2 )\n";
784 0 : ss << " *sqrt( fCount1*fCount2*(fCount1+fCount2-2)\n";
785 0 : ss << " /(fCount1+fCount2) );\n";
786 0 : ss << " fF = fCount1 + fCount2 - 2;\n";
787 0 : ss << " }\n";
788 :
789 0 : ss << " double tdist=GetTDist(fT, fF);\n";
790 0 : ss << " if (mode==1)\n";
791 0 : ss << " return tdist;\n";
792 0 : ss << " else\n";
793 0 : ss << " return 2.0*tdist;\n";
794 0 : ss << "}\n";
795 : }
796 : }
797 0 : void OpVarP::GenSlidingWindowFunction(std::stringstream &ss,
798 : const std::string &sSymName, SubArguments &vSubArguments)
799 : {
800 0 : ss << "\ndouble " << sSymName;
801 0 : ss << "_" << BinFuncName() << "(";
802 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
803 : {
804 0 : if (i)
805 0 : ss << ",";
806 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
807 : }
808 0 : ss << "){\n";
809 0 : ss << " int gid0 = get_global_id(0);\n";
810 0 : ss << " double fSum = 0.0;\n";
811 0 : ss << " double fMean = 0.0;\n";
812 0 : ss << " double vSum = 0.0;\n";
813 0 : ss << " double fCount = 0.0;\n";
814 0 : ss << " double arg = 0.0;\n";
815 0 : unsigned i = vSubArguments.size();
816 0 : while (i--)
817 : {
818 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
819 : assert(pCur);
820 0 : if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
821 : {
822 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
823 : {
824 : const formula::DoubleVectorRefToken* pDVR =
825 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
826 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
827 0 : ss << " for (int i = ";
828 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
829 : {
830 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
831 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
832 0 : ss << " {\n";
833 : }
834 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
835 : {
836 0 : ss << "0; i < " << pDVR->GetArrayLength();
837 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
838 0 : ss << " {\n";
839 : }
840 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
841 : {
842 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
843 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
844 0 : ss << " {\n";
845 : }
846 : else
847 : {
848 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
849 0 : ss << " {\n";
850 : }
851 0 : ss << " arg = ";
852 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
853 0 : ss << ";\n";
854 0 : ss << " if (isNan(arg))\n";
855 0 : ss << " continue;\n";
856 0 : ss << " fSum += arg;\n";
857 0 : ss << " fCount += 1.0;\n";
858 0 : ss << " }\n";
859 : }
860 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
861 : {
862 : const formula::SingleVectorRefToken* pSVR =
863 0 : static_cast< const formula::SingleVectorRefToken*>(pCur);
864 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
865 0 : ss << " {\n";
866 0 : ss << " arg = ";
867 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
868 0 : ss << " if (!isNan(arg))\n";
869 0 : ss << " {\n";
870 0 : ss << " fSum += arg;\n";
871 0 : ss << " fCount += 1.0;\n";
872 0 : ss << " }\n";
873 0 : ss << " }\n";
874 : }
875 : else
876 : {
877 0 : ss << " arg = " << pCur->GetDouble() << ";\n";
878 0 : ss << " fSum += arg;\n";
879 0 : ss << " fCount += 1.0;\n";
880 : }
881 : }
882 : else
883 : {
884 0 : ss << " arg = ";
885 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
886 0 : ss << " fSum += arg;\n";
887 0 : ss << " fCount += 1.0;\n";
888 : }
889 0 : if (i == 0)
890 : {
891 0 : ss << " fMean = fSum * pow(fCount,-1.0);\n";
892 : }
893 : }
894 0 : i = vSubArguments.size();
895 0 : while (i--)
896 : {
897 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
898 : assert(pCur);
899 0 : if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
900 : {
901 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
902 : {
903 : const formula::DoubleVectorRefToken* pDVR =
904 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
905 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
906 0 : ss << " for (int i = ";
907 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
908 : {
909 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
910 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
911 0 : ss << " {\n";
912 : }
913 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
914 : {
915 0 : ss << "0; i < " << pDVR->GetArrayLength();
916 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
917 0 : ss << " {\n";
918 : }
919 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
920 : {
921 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
922 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
923 0 : ss << " {\n";
924 : }
925 : else
926 : {
927 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
928 0 : ss << " {\n";
929 : }
930 :
931 0 : ss << " arg = ";
932 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
933 0 : ss << ";\n";
934 0 : ss << " if (isNan(arg))\n";
935 0 : ss << " continue;\n";
936 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
937 0 : ss << " }\n";
938 : }
939 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
940 : {
941 : const formula::SingleVectorRefToken* pSVR =
942 0 : static_cast< const formula::SingleVectorRefToken*>(pCur);
943 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
944 0 : ss << " {\n";
945 0 : ss << " arg = ";
946 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
947 0 : ss << " if (!isNan(arg))\n";
948 0 : ss << " {\n";
949 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
950 0 : ss << " }\n";
951 0 : ss << " }\n";
952 : }
953 : else
954 : {
955 0 : ss << " arg = " << pCur->GetDouble() << ";\n";
956 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
957 : }
958 : }
959 : else
960 : {
961 0 : ss << " arg = ";
962 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
963 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
964 : }
965 : }
966 0 : ss << " if (fCount == 0.0)\n";
967 0 : ss << " return DBL_MAX;\n";
968 0 : ss << " else\n";
969 0 : ss << " return vSum * pow(fCount,-1.0);\n";
970 0 : ss << "}\n";
971 0 : }
972 :
973 0 : void OpTDist::BinInlineFun(std::set<std::string>& decls,
974 : std::set<std::string>& funs)
975 : {
976 0 : decls.insert(fMachEpsDecl);
977 0 : funs.insert("");
978 0 : decls.insert(fMaxGammaArgumentDecl);
979 0 : funs.insert("");
980 0 : decls.insert(lcl_getLanczosSumDecl);
981 0 : funs.insert(lcl_getLanczosSum);
982 0 : decls.insert(GetBetaDecl);
983 0 : funs.insert(GetBeta);
984 0 : decls.insert(GetLogBetaDecl);
985 0 : funs.insert(GetLogBeta);
986 0 : decls.insert(GetBetaDistPDFDecl);
987 0 : funs.insert(GetBetaDistPDF);
988 0 : decls.insert(lcl_GetBetaHelperContFracDecl);
989 0 : funs.insert(lcl_GetBetaHelperContFrac);
990 0 : decls.insert(GetBetaDistDecl);
991 0 : funs.insert(GetBetaDist);
992 0 : decls.insert(GetTDistDecl);
993 0 : funs.insert(GetTDist);
994 0 : }
995 0 : void OpTDist::GenSlidingWindowFunction(std::stringstream &ss,
996 : const std::string &sSymName, SubArguments &vSubArguments)
997 : {
998 0 : ss << "\ndouble " << sSymName;
999 0 : ss << "_" << BinFuncName() << "(";
1000 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1001 : {
1002 0 : if (i)
1003 0 : ss << ",";
1004 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1005 : }
1006 0 : ss << ") {\n";
1007 0 : ss << " int gid0 = get_global_id(0);\n";
1008 0 : ss << " double x = 0.0;\n";
1009 0 : ss << " double fDF = 0.0;\n";
1010 0 : ss << " double fFlag = 0.0;\n";
1011 0 : if(vSubArguments.size() != 3)
1012 : {
1013 0 : ss << " return DBL_MAX;\n}\n";
1014 0 : return ;
1015 : }
1016 0 : FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
1017 : assert(tmpCur0);
1018 0 : if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
1019 : {
1020 0 : if(tmpCur0->GetType() == formula::svSingleVectorRef)
1021 : {
1022 : const formula::SingleVectorRefToken*tmpCurDVR0 =
1023 0 : static_cast<const formula::SingleVectorRefToken *>(tmpCur0);
1024 0 : ss << " if(gid0 < ";
1025 0 : ss << tmpCurDVR0->GetArrayLength() << ")\n";
1026 0 : ss << " {\n";
1027 0 : ss << " x = ";
1028 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
1029 0 : ss << " if(isNan(x))\n";
1030 0 : ss << " x = 0.0;\n";
1031 0 : ss << " }\n";
1032 : }
1033 0 : else if(tmpCur0->GetType() == formula::svDouble)
1034 : {
1035 0 : ss << " x = " << tmpCur0->GetDouble() << ";\n";
1036 : }
1037 : else
1038 : {
1039 0 : ss << " return DBL_MAX;\n}\n";
1040 0 : return ;
1041 : }
1042 : }
1043 : else
1044 : {
1045 0 : ss << " x = ";
1046 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
1047 : }
1048 0 : FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
1049 : assert(tmpCur1);
1050 0 : if(ocPush == vSubArguments[1]->GetFormulaToken()->GetOpCode())
1051 : {
1052 0 : if(tmpCur1->GetType() == formula::svSingleVectorRef)
1053 : {
1054 : const formula::SingleVectorRefToken*tmpCurDVR1 =
1055 0 : static_cast<const formula::SingleVectorRefToken *>(tmpCur1);
1056 0 : ss << " if(gid0 < ";
1057 0 : ss << tmpCurDVR1->GetArrayLength() << ")\n";
1058 0 : ss << " {\n";
1059 0 : ss << " fDF = ";
1060 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
1061 0 : ss << " if(isNan(fDF))\n";
1062 0 : ss << " fDF = 0.0;\n";
1063 0 : ss << " else\n";
1064 0 : ss << " fDF = floor(fDF);\n";
1065 0 : ss << " }\n";
1066 : }
1067 0 : else if(tmpCur1->GetType() == formula::svDouble)
1068 : {
1069 0 : ss << " fDF = floor(convert_double(";
1070 0 : ss << tmpCur1->GetDouble() << "));\n";
1071 : }
1072 : else
1073 : {
1074 0 : ss << " return DBL_MAX;\n}\n";
1075 0 : return ;
1076 : }
1077 : }
1078 : else
1079 : {
1080 0 : ss << " fDF = floor(";
1081 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ");\n";
1082 : }
1083 :
1084 0 : FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
1085 : assert(tmpCur2);
1086 0 : if(ocPush == vSubArguments[2]->GetFormulaToken()->GetOpCode())
1087 : {
1088 0 : if(tmpCur2->GetType() == formula::svSingleVectorRef)
1089 : {
1090 : const formula::SingleVectorRefToken*tmpCurDVR2 =
1091 0 : static_cast<const formula::SingleVectorRefToken *>(tmpCur2);
1092 0 : ss << " if(gid0 < ";
1093 0 : ss << tmpCurDVR2->GetArrayLength() << ")\n";
1094 0 : ss << " {\n";
1095 0 : ss << " fFlag = ";
1096 0 : ss << vSubArguments[2]->GenSlidingWindowDeclRef() << ";\n";
1097 0 : ss << " if(isNan(fFlag))\n";
1098 0 : ss << " fFlag = 0.0;\n";
1099 0 : ss << " else\n";
1100 0 : ss << " fFlag = floor(fFlag);\n";
1101 0 : ss << " }\n";
1102 :
1103 : }
1104 0 : else if(tmpCur2->GetType() == formula::svDouble)
1105 : {
1106 0 : ss << " fFlag = floor(convert_double(";
1107 0 : ss << tmpCur2->GetDouble() << "));\n";
1108 : }
1109 : else
1110 : {
1111 0 : ss << " return DBL_MAX;\n}\n";
1112 0 : return ;
1113 : }
1114 : }
1115 : else
1116 : {
1117 0 : ss << " fFlag = floor(";
1118 0 : ss << vSubArguments[2]->GenSlidingWindowDeclRef() << ");\n";
1119 : }
1120 0 : ss << " if(fDF < 1.0 || x < 0.0 || (fFlag != 1.0 && fFlag != 2.0))\n";
1121 0 : ss << " return DBL_MAX;\n";
1122 0 : ss << " double R = GetTDist(x, fDF);\n";
1123 0 : ss << " if (fFlag == 1.0)\n";
1124 0 : ss << " return R;\n";
1125 0 : ss << " else\n";
1126 0 : ss << " return 2.0 * R;\n";
1127 0 : ss << "}\n";
1128 : }
1129 0 : void OpExponDist::GenSlidingWindowFunction(std::stringstream &ss,
1130 : const std::string &sSymName, SubArguments &vSubArguments)
1131 : {
1132 0 : ss << "\ndouble " << sSymName;
1133 0 : ss << "_"<< BinFuncName() <<"(";
1134 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1135 : {
1136 0 : if (i)
1137 0 : ss << ",";
1138 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1139 : }
1140 0 : ss << ") {\n";
1141 0 : ss << " double tmp = 0,tmp0=0,tmp1=0,tmp2=0;\n";
1142 0 : ss << " int gid0 = get_global_id(0);\n";
1143 0 : ss << " double rx,rlambda,rkum;\n";
1144 0 : size_t i = vSubArguments.size();
1145 0 : ss <<"\n";
1146 0 : for (i = 0; i < vSubArguments.size(); i++)
1147 : {
1148 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
1149 : assert(pCur);
1150 0 : if (pCur->GetType() == formula::svSingleVectorRef)
1151 : {
1152 : const formula::SingleVectorRefToken* pSVR =
1153 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
1154 0 : ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
1155 : }
1156 0 : else if (pCur->GetType() == formula::svDouble)
1157 : {
1158 0 : ss << "{\n";
1159 : }
1160 : else
1161 : {
1162 : }
1163 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
1164 : {
1165 0 : ss << " if (isNan(";
1166 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
1167 0 : ss << "))\n";
1168 0 : ss << " tmp"<<i<<"= 0;\n";
1169 0 : ss << " else\n";
1170 0 : ss << " tmp"<<i<<"=\n";
1171 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
1172 0 : ss << ";\n}\n";
1173 : }
1174 : else
1175 : {
1176 0 : ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
1177 0 : ss <<";\n";
1178 : }
1179 : }
1180 0 : ss << " rx = tmp0;\n";
1181 0 : ss << " rlambda = tmp1;\n";
1182 0 : ss << " rkum = tmp2;\n";
1183 0 : ss <<" if(rlambda <= 0.0)\n";
1184 0 : ss <<" {\n";
1185 0 : ss <<" tmp = -DBL_MAX;\n";
1186 0 : ss <<" }\n";
1187 0 : ss <<" else if(rkum == 0)\n";
1188 0 : ss <<" {\n";
1189 0 : ss <<" if(rx >= 0)\n";
1190 0 : ss <<" tmp = rlambda*exp(-rlambda*rx);\n";
1191 0 : ss <<" else\n";
1192 0 : ss <<" tmp = 0.0;\n";
1193 0 : ss <<" }\n";
1194 0 : ss <<" else\n";
1195 0 : ss <<" {\n";
1196 0 : ss <<" if(rx > 0)\n";
1197 0 : ss <<" tmp = 1.0 - exp(-rlambda*rx);\n";
1198 0 : ss <<" else\n";
1199 0 : ss <<" tmp = 0.0;\n";
1200 0 : ss <<" }\n";
1201 0 : ss <<" return tmp;\n";
1202 0 : ss <<"}";
1203 0 : }
1204 0 : void OpFdist::BinInlineFun(std::set<std::string>& decls,
1205 : std::set<std::string>& funs)
1206 : {
1207 0 : decls.insert(GetFDistDecl);decls.insert(GetBetaDistDecl);
1208 0 : decls.insert(GetBetaDecl);decls.insert(fMaxGammaArgumentDecl);
1209 0 : decls.insert(lcl_GetBetaHelperContFracDecl);
1210 0 : decls.insert(GetBetaDistPDFDecl);
1211 0 : decls.insert(GetLogBetaDecl);decls.insert(lcl_getLanczosSumDecl);
1212 0 : decls.insert(fMachEpsDecl);
1213 0 : funs.insert(GetFDist);funs.insert(GetBetaDist);
1214 0 : funs.insert(GetBeta);
1215 0 : funs.insert(lcl_GetBetaHelperContFrac);funs.insert(GetBetaDistPDF);
1216 0 : funs.insert(GetLogBeta);
1217 0 : funs.insert(lcl_getLanczosSum);
1218 0 : }
1219 0 : void OpFdist::GenSlidingWindowFunction(std::stringstream &ss,
1220 : const std::string &sSymName, SubArguments &vSubArguments)
1221 : {
1222 0 : ss << "\ndouble " << sSymName;
1223 0 : ss << "_"<< BinFuncName() <<"(";
1224 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1225 : {
1226 0 : if (i)
1227 0 : ss << ",";
1228 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1229 : }
1230 0 : ss << ") {\n";
1231 0 : ss << " double tmp = 0,tmp0=0,tmp1=0,tmp2=0;\n";
1232 0 : ss << " int gid0 = get_global_id(0);\n";
1233 0 : ss << " double rF1,rF2,rX;\n";
1234 0 : size_t i = vSubArguments.size();
1235 0 : ss <<"\n";
1236 0 : for (i = 0; i < vSubArguments.size(); i++)
1237 : {
1238 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
1239 : assert(pCur);
1240 0 : if (pCur->GetType() == formula::svSingleVectorRef)
1241 : {
1242 : const formula::SingleVectorRefToken* pSVR =
1243 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
1244 0 : ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
1245 : }
1246 0 : else if (pCur->GetType() == formula::svDouble)
1247 : {
1248 0 : ss << "{\n";
1249 : }
1250 : else
1251 : {
1252 : }
1253 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
1254 : {
1255 0 : ss << " if (isNan(";
1256 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
1257 0 : ss << "))\n";
1258 0 : ss << " tmp"<<i<<"= 0;\n";
1259 0 : ss << " else\n";
1260 0 : ss << " tmp"<<i<<"=\n";
1261 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
1262 0 : ss << ";\n}\n";
1263 : }
1264 : else
1265 : {
1266 0 : ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
1267 0 : ss <<";\n";
1268 : }
1269 : }
1270 0 : ss << " rX = tmp0;\n";
1271 0 : ss << " rF1 = floor(tmp1);\n";
1272 0 : ss << " rF2 = floor(tmp2);\n";
1273 0 : ss <<" if (rX < 0.0 || rF1 < 1.0 || rF2 < 1.0 || rF1 >= 1.0E10 ||";
1274 0 : ss <<"rF2 >= 1.0E10)\n";
1275 0 : ss <<" {\n";
1276 0 : ss <<" tmp = -DBL_MAX;\n";
1277 0 : ss <<" }\n";
1278 0 : ss <<" tmp = GetFDist(rX, rF1, rF2);\n";
1279 0 : ss <<" return tmp;\n";
1280 0 : ss <<"}";
1281 0 : }
1282 :
1283 0 : void OpStandard::GenSlidingWindowFunction(std::stringstream &ss,
1284 : const std::string &sSymName, SubArguments &vSubArguments)
1285 : {
1286 0 : ss << "\ndouble " << sSymName;
1287 0 : ss << "_" << BinFuncName() << "(";
1288 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1289 : {
1290 0 : if (i)
1291 0 : ss << ",";
1292 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1293 : }
1294 0 : ss << ") {\n";
1295 0 : ss << " int gid0 = get_global_id(0);\n";
1296 0 : ss << " double x = 0.0;\n";
1297 0 : ss << " double mu = 0.0;\n";
1298 0 : ss << " double sigma = 0.0;\n";
1299 0 : if(vSubArguments.size() != 3)
1300 : {
1301 0 : ss << " return DBL_MAX;\n}\n";
1302 0 : return ;
1303 : }
1304 0 : FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
1305 : assert(tmpCur0);
1306 0 : if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
1307 : {
1308 0 : if(tmpCur0->GetType() == formula::svSingleVectorRef)
1309 : {
1310 : const formula::SingleVectorRefToken*tmpCurSVR0 =
1311 0 : static_cast<const formula::SingleVectorRefToken *>(tmpCur0);
1312 0 : ss << " if (gid0 < " << tmpCurSVR0->GetArrayLength() << ")\n";
1313 0 : ss << " {\n";
1314 0 : ss << " x = ";
1315 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
1316 0 : ss << " if (isNan(x))\n";
1317 0 : ss << " x = 0.0;\n";
1318 0 : ss << " }\n";
1319 : }
1320 0 : else if(tmpCur0->GetType() == formula::svDouble)
1321 : {
1322 0 : ss << " x = " << tmpCur0->GetDouble() << ";\n";
1323 : }
1324 : else
1325 : {
1326 0 : ss << " return DBL_MAX;\n}\n";
1327 0 : return ;
1328 : }
1329 : }
1330 : else
1331 : {
1332 0 : ss << " x = ";
1333 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
1334 : }
1335 :
1336 0 : FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
1337 : assert(tmpCur1);
1338 0 : if(ocPush == vSubArguments[1]->GetFormulaToken()->GetOpCode())
1339 : {
1340 0 : if(tmpCur1->GetType() == formula::svSingleVectorRef)
1341 : {
1342 : const formula::SingleVectorRefToken*tmpCurSVR1 =
1343 0 : static_cast<const formula::SingleVectorRefToken *>(tmpCur1);
1344 0 : ss << " if (gid0 < " << tmpCurSVR1->GetArrayLength() << ")\n";
1345 0 : ss << " {\n";
1346 0 : ss << " mu = ";
1347 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
1348 0 : ss << " if (isNan(mu))\n";
1349 0 : ss << " mu = 0.0;\n";
1350 0 : ss << " }\n";
1351 : }
1352 0 : else if(tmpCur1->GetType() == formula::svDouble)
1353 : {
1354 0 : ss << " mu = " << tmpCur1->GetDouble() << ";\n";
1355 : }
1356 : else
1357 : {
1358 0 : ss << " return DBL_MAX;\n}\n";
1359 0 : return ;
1360 : }
1361 : }
1362 : else
1363 : {
1364 0 : ss << " mu = ";
1365 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
1366 : }
1367 :
1368 0 : FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
1369 : assert(tmpCur2);
1370 0 : if(ocPush == vSubArguments[2]->GetFormulaToken()->GetOpCode())
1371 : {
1372 0 : if(tmpCur2->GetType() == formula::svSingleVectorRef)
1373 : {
1374 : const formula::SingleVectorRefToken*tmpCurSVR2 =
1375 0 : static_cast<const formula::SingleVectorRefToken *>(tmpCur2);
1376 0 : ss << " if (gid0 < " << tmpCurSVR2->GetArrayLength() << ")\n";
1377 0 : ss << " {\n";
1378 0 : ss << " sigma = ";
1379 0 : ss << vSubArguments[2]->GenSlidingWindowDeclRef() << ";\n";
1380 0 : ss << " if (isNan(sigma))\n";
1381 0 : ss << " sigma = 0.0;\n";
1382 0 : ss << " }\n";
1383 : }
1384 0 : else if(tmpCur2->GetType() == formula::svDouble)
1385 : {
1386 0 : ss << " sigma = " << tmpCur2->GetDouble() << ";\n";
1387 : }
1388 : else
1389 : {
1390 0 : ss << " return DBL_MAX;\n";
1391 0 : ss << "}\n";
1392 0 : return ;
1393 : }
1394 : }
1395 : else
1396 : {
1397 0 : ss << " sigma = ";
1398 0 : ss << vSubArguments[2]->GenSlidingWindowDeclRef() << ";\n";
1399 : }
1400 :
1401 0 : ss << " if(sigma <= 0.0)\n";
1402 0 : ss << " return DBL_MAX;\n";
1403 0 : ss << " else\n";
1404 0 : ss << " return (x - mu)*pow(sigma,-1.0);\n";
1405 0 : ss << "}";
1406 : }
1407 :
1408 0 : void OpWeibull::GenSlidingWindowFunction(std::stringstream &ss,
1409 : const std::string &sSymName, SubArguments &vSubArguments)
1410 : {
1411 0 : ss << "\ndouble " << sSymName;
1412 0 : ss << "_" << BinFuncName() << "(";
1413 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1414 : {
1415 0 : if (i)
1416 0 : ss << ",";
1417 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1418 : }
1419 0 : ss << ") {\n";
1420 0 : ss << " int gid0 = get_global_id(0);\n";
1421 0 : ss << " double x = 0.0;\n";
1422 0 : ss << " double alpha = 0.0;\n";
1423 0 : ss << " double beta = 0.0;\n";
1424 0 : ss << " double kum = 0.0;\n";
1425 0 : if(vSubArguments.size() != 4)
1426 : {
1427 0 : ss << " return DBL_MAX;\n}\n";
1428 0 : return ;
1429 : }
1430 0 : FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
1431 : assert(tmpCur0);
1432 0 : if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
1433 : {
1434 0 : if(tmpCur0->GetType() == formula::svSingleVectorRef)
1435 : {
1436 : const formula::SingleVectorRefToken*tmpCurSVR0 =
1437 0 : static_cast<const formula::SingleVectorRefToken *>(tmpCur0);
1438 0 : ss << " if (gid0 < " << tmpCurSVR0->GetArrayLength() << ")\n";
1439 0 : ss << " {\n";
1440 0 : ss << " x = ";
1441 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
1442 0 : ss << " if (isNan(x))\n";
1443 0 : ss << " x = 0.0;\n";
1444 0 : ss << " }\n";
1445 : }
1446 0 : else if(tmpCur0->GetType() == formula::svDouble)
1447 : {
1448 0 : ss << " x = " << tmpCur0->GetDouble() << ";\n";
1449 : }
1450 : else
1451 : {
1452 0 : ss << " return DBL_MAX;\n}\n";
1453 0 : return ;
1454 : }
1455 : }
1456 : else
1457 : {
1458 0 : ss << " x = ";
1459 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
1460 : }
1461 :
1462 0 : FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
1463 : assert(tmpCur1);
1464 0 : if(ocPush == vSubArguments[1]->GetFormulaToken()->GetOpCode())
1465 : {
1466 0 : if(tmpCur1->GetType() == formula::svSingleVectorRef)
1467 : {
1468 : const formula::SingleVectorRefToken*tmpCurSVR1 =
1469 0 : static_cast<const formula::SingleVectorRefToken *>(tmpCur1);
1470 0 : ss << " if (gid0 < " << tmpCurSVR1->GetArrayLength() << ")\n";
1471 0 : ss << " {\n";
1472 0 : ss << " alpha = ";
1473 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
1474 0 : ss << " if (isNan(alpha))\n";
1475 0 : ss << " alpha = 0.0;\n";
1476 0 : ss << " }\n";
1477 : }
1478 0 : else if(tmpCur1->GetType() == formula::svDouble)
1479 : {
1480 0 : ss << " alpha = " << tmpCur1->GetDouble() << ";\n";
1481 : }
1482 : else
1483 : {
1484 0 : ss << " return DBL_MAX;\n}\n";
1485 0 : return ;
1486 : }
1487 : }
1488 : else
1489 : {
1490 0 : ss << " alpha = ";
1491 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
1492 : }
1493 :
1494 0 : FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
1495 : assert(tmpCur2);
1496 0 : if(ocPush == vSubArguments[2]->GetFormulaToken()->GetOpCode())
1497 : {
1498 0 : if(tmpCur2->GetType() == formula::svSingleVectorRef)
1499 : {
1500 : const formula::SingleVectorRefToken*tmpCurSVR2 =
1501 0 : static_cast<const formula::SingleVectorRefToken *>(tmpCur2);
1502 0 : ss << " if (gid0 < " << tmpCurSVR2->GetArrayLength() << ")\n";
1503 0 : ss << " {\n";
1504 0 : ss << " beta = ";
1505 0 : ss << vSubArguments[2]->GenSlidingWindowDeclRef() << ";\n";
1506 0 : ss << " if (isNan(beta))\n";
1507 0 : ss << " beta = 0.0;\n";
1508 0 : ss << " }\n";
1509 : }
1510 0 : else if(tmpCur2->GetType() == formula::svDouble)
1511 : {
1512 0 : ss << " beta = " << tmpCur2->GetDouble() << ";\n";
1513 : }
1514 : else
1515 : {
1516 0 : ss << " return DBL_MAX;\n}\n";
1517 0 : return ;
1518 : }
1519 : }
1520 : else
1521 : {
1522 0 : ss << " beta = ";
1523 0 : ss << vSubArguments[2]->GenSlidingWindowDeclRef() << ";\n";
1524 : }
1525 :
1526 0 : FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
1527 : assert(tmpCur3);
1528 0 : if(ocPush == vSubArguments[3]->GetFormulaToken()->GetOpCode())
1529 : {
1530 0 : if(tmpCur3->GetType() == formula::svSingleVectorRef)
1531 : {
1532 : const formula::SingleVectorRefToken*tmpCurSVR3 =
1533 0 : static_cast<const formula::SingleVectorRefToken *>(tmpCur3);
1534 0 : ss << " if (gid0 < " << tmpCurSVR3->GetArrayLength() << ")\n";
1535 0 : ss << " {\n";
1536 0 : ss << " kum = ";
1537 0 : ss << vSubArguments[3]->GenSlidingWindowDeclRef() << ";\n";
1538 0 : ss << " if (isNan(kum))\n";
1539 0 : ss << " kum = 0.0;\n";
1540 0 : ss << " }\n";
1541 : }
1542 0 : else if(tmpCur3->GetType() == formula::svDouble)
1543 : {
1544 0 : ss << " kum = " << tmpCur3->GetDouble() << ";\n";
1545 : }
1546 : else
1547 : {
1548 0 : ss << " return DBL_MAX;\n}\n";
1549 0 : return ;
1550 : }
1551 : }
1552 : else
1553 : {
1554 0 : ss << " kum = ";
1555 0 : ss << vSubArguments[3]->GenSlidingWindowDeclRef() << ";\n";
1556 : }
1557 :
1558 0 : ss << " if(alpha <= 0.0 || beta <=0.0 || kum < 0.0)\n";
1559 0 : ss << " return DBL_MAX;\n";
1560 0 : ss << " else if(kum == 0.0)\n";
1561 0 : ss << " {\n";
1562 0 : ss << " return alpha*pow(pow(beta,alpha),-1.0)*pow(x,alpha-1.0)";
1563 0 : ss << "*exp(-pow(x*pow(beta,-1.0),alpha));\n";
1564 0 : ss << " }\n";
1565 0 : ss << " else\n";
1566 0 : ss << " return 1.0-exp(-pow(x*pow(beta,-1.0),alpha));\n";
1567 0 : ss << "}\n";
1568 : }
1569 :
1570 0 : void OpSkew::GenSlidingWindowFunction(std::stringstream &ss,
1571 : const std::string &sSymName, SubArguments &vSubArguments)
1572 : {
1573 0 : ss << "\ndouble " << sSymName;
1574 0 : ss << "_" << BinFuncName() << "(";
1575 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1576 : {
1577 0 : if (i)
1578 0 : ss << ",";
1579 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1580 : }
1581 0 : ss << "){\n";
1582 0 : ss << " int gid0 = get_global_id(0);\n";
1583 0 : ss << " double fSum = 0.0;\n";
1584 0 : ss << " double fMean = 0.0;\n";
1585 0 : ss << " double vSum = 0.0;\n";
1586 0 : ss << " double fCount = 0.0;\n";
1587 0 : ss << " double arg = 0.0;\n";
1588 0 : unsigned i = vSubArguments.size();
1589 0 : while (i--)
1590 : {
1591 0 : FormulaToken* pCur = vSubArguments[i]->GetFormulaToken();
1592 : assert(pCur);
1593 0 : if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
1594 : {
1595 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
1596 : {
1597 : const formula::DoubleVectorRefToken* pDVR =
1598 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
1599 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
1600 0 : ss << " for (int i = ";
1601 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
1602 : {
1603 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
1604 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
1605 0 : ss << " {\n";
1606 : }
1607 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
1608 : {
1609 0 : ss << "0; i < " << pDVR->GetArrayLength();
1610 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
1611 0 : ss << " {\n";
1612 : }
1613 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
1614 : {
1615 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
1616 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
1617 0 : ss << " {\n";
1618 : }
1619 : else
1620 : {
1621 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
1622 0 : ss << " {\n";
1623 : }
1624 :
1625 0 : ss << " arg = ";
1626 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
1627 0 : ss << " if (isNan(arg))\n";
1628 0 : ss << " continue;\n";
1629 0 : ss << " fSum += arg;\n";
1630 0 : ss << " fCount += 1.0;\n";
1631 0 : ss << " }\n";
1632 : }
1633 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
1634 : {
1635 : const formula::SingleVectorRefToken* pSVR =
1636 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
1637 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
1638 0 : ss << " {\n";
1639 0 : ss << " arg = ";
1640 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
1641 0 : ss << " if (!isNan(arg))\n";
1642 0 : ss << " {\n";
1643 0 : ss << " fSum += arg;\n";
1644 0 : ss << " fCount += 1.0;\n";
1645 0 : ss << " }\n";
1646 0 : ss << " }\n";
1647 : }
1648 : else
1649 : {
1650 0 : ss << " arg = " << pCur->GetDouble() << ";\n";
1651 0 : ss << " fSum += arg;\n";
1652 0 : ss << " fCount += 1.0;\n";
1653 : }
1654 : }
1655 : else
1656 : {
1657 0 : ss << " arg = ";
1658 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
1659 0 : ss << " fSum += arg;\n";
1660 0 : ss << " fCount += 1.0;\n";
1661 : }
1662 :
1663 0 : if(i == 0)
1664 : {
1665 0 : ss << " if(fCount <= 2.0)\n";
1666 0 : ss << " return DBL_MAX;\n";
1667 0 : ss << " else\n";
1668 0 : ss << " fMean = fSum * pow(fCount,-1.0);\n";
1669 : }
1670 : }
1671 0 : i = vSubArguments.size();
1672 0 : while (i--)
1673 : {
1674 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
1675 : assert(pCur);
1676 0 : if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
1677 : {
1678 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
1679 : {
1680 : const formula::DoubleVectorRefToken* pDVR =
1681 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
1682 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
1683 0 : ss << " for (int i = ";
1684 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
1685 : {
1686 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
1687 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
1688 0 : ss << " {\n";
1689 : }
1690 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
1691 : {
1692 0 : ss << "0; i < " << pDVR->GetArrayLength();
1693 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
1694 0 : ss << " {\n";
1695 : }
1696 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
1697 : {
1698 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
1699 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
1700 0 : ss << " {\n";
1701 : }
1702 : else
1703 : {
1704 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
1705 0 : ss << " {\n";
1706 : }
1707 :
1708 0 : ss << " arg = ";
1709 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
1710 0 : ss << " if (isNan(arg))\n";
1711 0 : ss << " continue;\n";
1712 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
1713 0 : ss << " }\n";
1714 : }
1715 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
1716 : {
1717 : const formula::SingleVectorRefToken* pSVR =
1718 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
1719 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
1720 0 : ss << " {\n";
1721 0 : ss << " arg = ";
1722 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
1723 0 : ss << " if (!isNan(arg))\n";
1724 0 : ss << " {\n";
1725 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
1726 0 : ss << " }\n";
1727 0 : ss << " }\n";
1728 : }
1729 : else
1730 : {
1731 0 : ss << " arg = " << pCur->GetDouble() << ";\n";
1732 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
1733 : }
1734 : }
1735 : else
1736 : {
1737 0 : ss << " arg = ";
1738 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
1739 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
1740 : }
1741 : }
1742 0 : ss << " double fStdDev = sqrt(vSum * pow(fCount - 1.0,-1.0));\n";
1743 0 : ss << " double dx = 0.0;\n";
1744 0 : ss << " double xcube = 0.0;\n";
1745 0 : ss << " if(fStdDev == 0.0)\n";
1746 0 : ss << " return DBL_MAX;\n";
1747 0 : i = vSubArguments.size();
1748 0 : while (i--)
1749 : {
1750 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
1751 : assert(pCur);
1752 0 : if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
1753 : {
1754 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
1755 : {
1756 : const formula::DoubleVectorRefToken* pDVR =
1757 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
1758 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
1759 0 : ss << " for (int i = ";
1760 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
1761 : {
1762 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
1763 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
1764 0 : ss << " {\n";
1765 : }
1766 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
1767 : {
1768 0 : ss << "0; i < " << pDVR->GetArrayLength();
1769 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
1770 0 : ss << " {\n";
1771 : }
1772 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
1773 : {
1774 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
1775 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
1776 0 : ss << " {\n";
1777 : }
1778 : else
1779 : {
1780 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
1781 0 : ss << " {\n";
1782 : }
1783 :
1784 0 : ss << " arg = ";
1785 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
1786 0 : ss << " if (isNan(arg))\n";
1787 0 : ss << " continue;\n";
1788 0 : ss << " dx = (arg - fMean) * pow(fStdDev,-1.0);\n";
1789 0 : ss << " xcube = xcube + dx * dx * dx;\n";
1790 0 : ss << " }\n";
1791 : }
1792 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
1793 : {
1794 : const formula::SingleVectorRefToken* pSVR =
1795 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
1796 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
1797 0 : ss << " {\n";
1798 0 : ss << " arg = ";
1799 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
1800 0 : ss << " if (!isNan(arg))\n";
1801 0 : ss << " {\n";
1802 0 : ss << " dx = (arg - fMean) * pow(fStdDev,-1.0);\n";
1803 0 : ss << " xcube = xcube + dx * dx * dx;\n";
1804 0 : ss << " }\n";
1805 0 : ss << " }\n";
1806 : }
1807 : else
1808 : {
1809 0 : ss << " arg = " << pCur->GetDouble() << ";\n";
1810 0 : ss << " dx = (arg - fMean) * pow(fStdDev,-1.0);\n";
1811 0 : ss << " xcube = xcube + dx * dx * dx;\n";
1812 : }
1813 : }
1814 : else
1815 : {
1816 0 : ss << " arg = ";
1817 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
1818 0 : ss << " dx = (arg - fMean) * pow(fStdDev,-1.0);\n";
1819 0 : ss << " xcube = xcube + dx * dx * dx;\n";
1820 : }
1821 : }
1822 0 : ss << " return ((xcube * fCount) * pow(fCount - 1.0,-1.0))";
1823 0 : ss << " * pow(fCount - 2.0,-1.0);\n";
1824 0 : ss << "}\n";
1825 0 : }
1826 :
1827 0 : void OpSkewp::GenSlidingWindowFunction(std::stringstream &ss,
1828 : const std::string &sSymName, SubArguments &vSubArguments)
1829 : {
1830 0 : ss << "\ndouble " << sSymName;
1831 0 : ss << "_" << BinFuncName() << "(";
1832 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1833 : {
1834 0 : if (i)
1835 0 : ss << ",";
1836 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1837 : }
1838 0 : ss << "){\n";
1839 0 : ss << " int gid0 = get_global_id(0);\n";
1840 0 : ss << " double fSum = 0.0;\n";
1841 0 : ss << " double fMean = 0.0;\n";
1842 0 : ss << " double vSum = 0.0;\n";
1843 0 : ss << " double fCount = 0.0;\n";
1844 0 : ss << " double arg = 0.0;\n";
1845 0 : unsigned i = vSubArguments.size();
1846 0 : while (i--)
1847 : {
1848 0 : FormulaToken* pCur = vSubArguments[i]->GetFormulaToken();
1849 : assert(pCur);
1850 0 : if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
1851 : {
1852 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
1853 : {
1854 : const formula::DoubleVectorRefToken* pDVR =
1855 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
1856 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
1857 0 : ss << " for (int i = ";
1858 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
1859 : {
1860 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
1861 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
1862 0 : ss << " {\n";
1863 : }
1864 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
1865 : {
1866 0 : ss << "0; i < " << pDVR->GetArrayLength();
1867 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
1868 0 : ss << " {\n";
1869 : }
1870 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
1871 : {
1872 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
1873 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
1874 0 : ss << " {\n";
1875 : }
1876 : else
1877 : {
1878 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
1879 0 : ss << " {\n";
1880 : }
1881 :
1882 0 : ss << " arg = ";
1883 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
1884 0 : ss << " if (isNan(arg))\n";
1885 0 : ss << " continue;\n";
1886 0 : ss << " fSum += arg;\n";
1887 0 : ss << " fCount += 1.0;\n";
1888 0 : ss << " }\n";
1889 : }
1890 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
1891 : {
1892 : const formula::SingleVectorRefToken* pSVR =
1893 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
1894 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
1895 0 : ss << " {\n";
1896 0 : ss << " arg = ";
1897 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
1898 0 : ss << " if (!isNan(arg))\n";
1899 0 : ss << " {\n";
1900 0 : ss << " fSum += arg;\n";
1901 0 : ss << " fCount += 1.0;\n";
1902 0 : ss << " }\n";
1903 0 : ss << " }\n";
1904 : }
1905 : else
1906 : {
1907 0 : ss << " arg = " << pCur->GetDouble() << ";\n";
1908 0 : ss << " fSum += arg;\n";
1909 0 : ss << " fCount += 1.0;\n";
1910 : }
1911 : }
1912 : else
1913 : {
1914 0 : ss << " arg = ";
1915 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
1916 0 : ss << " fSum += arg;\n";
1917 0 : ss << " fCount += 1.0;\n";
1918 : }
1919 :
1920 0 : if(i == 0)
1921 : {
1922 0 : ss << " if(fCount <= 2.0)\n";
1923 0 : ss << " return DBL_MAX;\n";
1924 0 : ss << " else\n";
1925 0 : ss << " fMean = fSum * pow(fCount,-1.0);\n";
1926 : }
1927 : }
1928 0 : i = vSubArguments.size();
1929 0 : while (i--)
1930 : {
1931 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
1932 : assert(pCur);
1933 0 : if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
1934 : {
1935 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
1936 : {
1937 : const formula::DoubleVectorRefToken* pDVR =
1938 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
1939 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
1940 0 : ss << " for (int i = ";
1941 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
1942 : {
1943 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
1944 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
1945 0 : ss << " {\n";
1946 : }
1947 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
1948 : {
1949 0 : ss << "0; i < " << pDVR->GetArrayLength();
1950 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
1951 0 : ss << " {\n";
1952 : }
1953 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
1954 : {
1955 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
1956 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
1957 0 : ss << " {\n";
1958 : }
1959 : else
1960 : {
1961 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
1962 0 : ss << " {\n";
1963 : }
1964 :
1965 0 : ss << " arg = ";
1966 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
1967 0 : ss << " if (isNan(arg))\n";
1968 0 : ss << " continue;\n";
1969 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
1970 0 : ss << " }\n";
1971 : }
1972 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
1973 : {
1974 : const formula::SingleVectorRefToken* pSVR =
1975 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
1976 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
1977 0 : ss << " {\n";
1978 0 : ss << " arg = ";
1979 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
1980 0 : ss << " if (!isNan(arg))\n";
1981 0 : ss << " {\n";
1982 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
1983 0 : ss << " }\n";
1984 0 : ss << " }\n";
1985 : }
1986 : else
1987 : {
1988 0 : ss << " arg = " << pCur->GetDouble() << ";\n";
1989 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
1990 : }
1991 : }
1992 : else
1993 : {
1994 0 : ss << " arg = ";
1995 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
1996 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
1997 : }
1998 : }
1999 0 : ss << " double fStdDev = sqrt(vSum * pow(fCount,-1.0));\n";
2000 0 : ss << " double dx = 0.0;\n";
2001 0 : ss << " double xcube = 0.0;\n";
2002 0 : ss << " if(fStdDev == 0.0)\n";
2003 0 : ss << " return DBL_MAX;\n";
2004 0 : i = vSubArguments.size();
2005 0 : while (i--)
2006 : {
2007 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
2008 : assert(pCur);
2009 0 : if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
2010 : {
2011 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
2012 : {
2013 : const formula::DoubleVectorRefToken* pDVR =
2014 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
2015 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
2016 0 : ss << " for (int i = ";
2017 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
2018 : {
2019 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
2020 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
2021 0 : ss << " {\n";
2022 : }
2023 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
2024 : {
2025 0 : ss << "0; i < " << pDVR->GetArrayLength();
2026 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
2027 0 : ss << " {\n";
2028 : }
2029 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
2030 : {
2031 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
2032 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
2033 0 : ss << " {\n";
2034 : }
2035 : else
2036 : {
2037 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
2038 0 : ss << " {\n";
2039 : }
2040 :
2041 0 : ss << " arg = ";
2042 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
2043 0 : ss << " if (isNan(arg))\n";
2044 0 : ss << " continue;\n";
2045 0 : ss << " dx = (arg - fMean) * pow(fStdDev,-1.0);\n";
2046 0 : ss << " xcube = xcube + dx * dx * dx;\n";
2047 0 : ss << " }\n";
2048 : }
2049 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
2050 : {
2051 : const formula::SingleVectorRefToken* pSVR =
2052 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
2053 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
2054 0 : ss << " {\n";
2055 0 : ss << " arg = ";
2056 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
2057 0 : ss << " if (!isNan(arg))\n";
2058 0 : ss << " {\n";
2059 0 : ss << " dx = (arg - fMean) * pow(fStdDev,-1.0);\n";
2060 0 : ss << " xcube = xcube + dx * dx * dx;\n";
2061 0 : ss << " }\n";
2062 0 : ss << " }\n";
2063 : }
2064 : else
2065 : {
2066 0 : ss << " arg = " << pCur->GetDouble() << ";\n";
2067 0 : ss << " dx = (arg - fMean) * pow(fStdDev,-1.0);\n";
2068 0 : ss << " xcube = xcube + dx * dx * dx;\n";
2069 : }
2070 : }
2071 : else
2072 : {
2073 0 : ss << " arg = ";
2074 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
2075 0 : ss << " dx = (arg - fMean) * pow(fStdDev,-1.0);\n";
2076 0 : ss << " xcube = xcube + dx * dx * dx;\n";
2077 : }
2078 : }
2079 0 : ss << " return xcube * pow(fCount,-1.0);\n";
2080 0 : ss << "}\n";
2081 0 : }
2082 :
2083 0 : void OpTInv::BinInlineFun(std::set<std::string>& decls,
2084 : std::set<std::string>& funs)
2085 : {
2086 0 : decls.insert(fMachEpsDecl);
2087 0 : funs.insert("");
2088 0 : decls.insert(fMaxGammaArgumentDecl);
2089 0 : funs.insert("");
2090 0 : decls.insert(lcl_getLanczosSumDecl);
2091 0 : funs.insert(lcl_getLanczosSum);
2092 0 : decls.insert(GetBetaDecl);
2093 0 : funs.insert(GetBeta);
2094 0 : decls.insert(GetLogBetaDecl);
2095 0 : funs.insert(GetLogBeta);
2096 0 : decls.insert(GetBetaDistPDFDecl);
2097 0 : funs.insert(GetBetaDistPDF);
2098 0 : decls.insert(lcl_GetBetaHelperContFracDecl);
2099 0 : funs.insert(lcl_GetBetaHelperContFrac);
2100 0 : decls.insert(GetBetaDistDecl);
2101 0 : funs.insert(GetBetaDist);
2102 0 : decls.insert(GetTDistDecl);
2103 0 : funs.insert(GetTDist);
2104 0 : decls.insert(GetValueDecl);
2105 0 : funs.insert(GetValue);
2106 0 : decls.insert(lcl_HasChangeOfSignDecl);
2107 0 : funs.insert(lcl_HasChangeOfSign);
2108 0 : decls.insert(lcl_IterateInverseDecl);
2109 0 : funs.insert(lcl_IterateInverse);
2110 0 : }
2111 :
2112 0 : void OpTInv::GenSlidingWindowFunction(std::stringstream &ss,
2113 : const std::string &sSymName, SubArguments &vSubArguments)
2114 : {
2115 0 : ss << "\ndouble " << sSymName;
2116 0 : ss << "_" << BinFuncName() << "(";
2117 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
2118 : {
2119 0 : if (i)
2120 0 : ss << ",";
2121 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
2122 : }
2123 0 : ss << ") {\n";
2124 0 : ss << " int gid0 = get_global_id(0);\n";
2125 0 : ss << " double x = 0.0;\n";
2126 0 : ss << " double fDF = 0.0;\n";
2127 0 : if(vSubArguments.size() != 2)
2128 : {
2129 0 : ss << " return DBL_MAX;\n}\n";
2130 0 : return ;
2131 : }
2132 0 : FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
2133 : assert(tmpCur0);
2134 0 : if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
2135 : {
2136 0 : if(tmpCur0->GetType() == formula::svSingleVectorRef)
2137 : {
2138 : const formula::SingleVectorRefToken*tmpCurDVR0 =
2139 0 : static_cast<const formula::SingleVectorRefToken *>(tmpCur0);
2140 0 : ss << " if(gid0 < ";
2141 0 : ss << tmpCurDVR0->GetArrayLength() << ")\n";
2142 0 : ss << " {\n";
2143 0 : ss << " x = ";
2144 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
2145 0 : ss << " if(isNan(x))\n";
2146 0 : ss << " x = 0.0;\n";
2147 0 : ss << " }\n";
2148 : }
2149 0 : else if(tmpCur0->GetType() == formula::svDouble)
2150 : {
2151 0 : ss << " x = " << tmpCur0->GetDouble() << ";\n";
2152 : }
2153 : else
2154 : {
2155 0 : ss << " return DBL_MAX;\n}\n";
2156 0 : return ;
2157 : }
2158 : }
2159 : else
2160 : {
2161 0 : ss << " x = ";
2162 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
2163 : }
2164 0 : FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
2165 : assert(tmpCur1);
2166 0 : if(ocPush == vSubArguments[1]->GetFormulaToken()->GetOpCode())
2167 : {
2168 0 : if(tmpCur1->GetType() == formula::svSingleVectorRef)
2169 : {
2170 : const formula::SingleVectorRefToken*tmpCurDVR1 =
2171 0 : static_cast<const formula::SingleVectorRefToken *>(tmpCur1);
2172 0 : ss << " if(gid0 < ";
2173 0 : ss << tmpCurDVR1->GetArrayLength() << ")\n";
2174 0 : ss << " {\n";
2175 0 : ss << " fDF = ";
2176 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
2177 0 : ss << " if(isNan(fDF))\n";
2178 0 : ss << " fDF = 0.0;\n";
2179 0 : ss << " else\n";
2180 0 : ss << " fDF = floor(fDF);\n";
2181 0 : ss << " }\n";
2182 : }
2183 0 : else if(tmpCur1->GetType() == formula::svDouble)
2184 : {
2185 0 : ss << " fDF = floor(convert_double(";
2186 0 : ss << tmpCur1->GetDouble() << "));\n";
2187 : }
2188 : else
2189 : {
2190 0 : ss << " return DBL_MAX;\n}\n";
2191 0 : return ;
2192 : }
2193 : }
2194 : else
2195 : {
2196 0 : ss << " fDF = floor(";
2197 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ");\n";
2198 : }
2199 0 : ss << " if (x > 1.0||fDF < 1.0 || fDF > 1.0E10 || x <= 0.0)\n";
2200 0 : ss << " return DBL_MAX;\n";
2201 0 : ss << " bool bConvError;\n";
2202 0 : ss << " double fVal = lcl_IterateInverse(\n";
2203 0 : ss << " fDF*0.5, fDF, &bConvError,x,fDF );\n";
2204 0 : ss << " if (bConvError)\n";
2205 0 : ss << " return DBL_MAX;\n";
2206 0 : ss << " return fVal;\n";
2207 0 : ss << "}\n";
2208 : }
2209 :
2210 0 : void OpStDev::GenSlidingWindowFunction(std::stringstream &ss,
2211 : const std::string &sSymName, SubArguments &vSubArguments)
2212 : {
2213 0 : ss << "\ndouble " << sSymName;
2214 0 : ss << "_" << BinFuncName() << "(";
2215 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
2216 : {
2217 0 : if (i)
2218 0 : ss << ",";
2219 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
2220 : }
2221 0 : ss << "){\n";
2222 0 : ss << " int gid0 = get_global_id(0);\n";
2223 0 : ss << " double fSum = 0.0;\n";
2224 0 : ss << " double vSum = 0.0;\n";
2225 0 : ss << " double fMean = 0.0;\n";
2226 0 : ss << " double fCount = 0.0;\n";
2227 0 : ss << " double arg = 0.0;\n";
2228 0 : unsigned i = vSubArguments.size();
2229 0 : while (i--)
2230 : {
2231 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
2232 : assert(pCur);
2233 0 : if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
2234 : {
2235 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
2236 : {
2237 : const formula::DoubleVectorRefToken* pDVR =
2238 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
2239 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
2240 0 : ss << " for (int i = ";
2241 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
2242 : {
2243 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
2244 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
2245 0 : ss << " {\n";
2246 : }
2247 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
2248 : {
2249 0 : ss << "0; i < " << pDVR->GetArrayLength();
2250 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
2251 0 : ss << " {\n";
2252 : }
2253 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
2254 : {
2255 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
2256 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
2257 0 : ss << " {\n";
2258 : }
2259 : else
2260 : {
2261 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
2262 0 : ss << " {\n";
2263 : }
2264 :
2265 0 : ss << " arg = ";
2266 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
2267 0 : ss << " if (isNan(arg))\n";
2268 0 : ss << " continue;\n";
2269 0 : ss << " fSum += arg;\n";
2270 0 : ss << " fCount += 1.0;\n";
2271 0 : ss << " }\n";
2272 : }
2273 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
2274 : {
2275 : const formula::SingleVectorRefToken* pSVR =
2276 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
2277 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
2278 0 : ss << " {\n";
2279 0 : ss << " arg = ";
2280 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
2281 0 : ss << " if (!isNan(arg))\n";
2282 0 : ss << " {\n";
2283 0 : ss << " fSum += arg;\n";
2284 0 : ss << " fCount += 1.0;\n";
2285 0 : ss << " }\n";
2286 0 : ss << " }\n";
2287 : }
2288 : else
2289 : {
2290 0 : ss << " arg = " << pCur->GetDouble() << ";\n";
2291 0 : ss << " fSum += arg;\n";
2292 0 : ss << " fCount += 1.0;\n";
2293 : }
2294 : }
2295 : else
2296 : {
2297 0 : ss << " arg = ";
2298 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
2299 0 : ss << " fSum += arg;\n";
2300 0 : ss << " fCount += 1.0;\n";
2301 : }
2302 0 : if (i == 0)
2303 : {
2304 0 : ss << " fMean = fSum * pow(fCount,-1.0);\n";
2305 : }
2306 : }
2307 0 : i = vSubArguments.size();
2308 0 : while (i--)
2309 : {
2310 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
2311 : assert(pCur);
2312 0 : if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
2313 : {
2314 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
2315 : {
2316 : const formula::DoubleVectorRefToken* pDVR =
2317 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
2318 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
2319 0 : ss << " for (int i = ";
2320 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
2321 : {
2322 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
2323 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
2324 0 : ss << " {\n";
2325 : }
2326 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
2327 : {
2328 0 : ss << "0; i < " << pDVR->GetArrayLength();
2329 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
2330 0 : ss << " {\n";
2331 : }
2332 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
2333 : {
2334 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
2335 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
2336 0 : ss << " {\n";
2337 : }
2338 : else
2339 : {
2340 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
2341 0 : ss << " {\n";
2342 : }
2343 0 : ss << " arg = ";
2344 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
2345 0 : ss << " if (isNan(arg))\n";
2346 0 : ss << " continue;\n";
2347 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
2348 0 : ss << " }\n";
2349 : }
2350 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
2351 : {
2352 : const formula::SingleVectorRefToken* pSVR =
2353 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
2354 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
2355 0 : ss << " {\n";
2356 0 : ss << " arg = ";
2357 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
2358 0 : ss << " if (!isNan(arg))\n";
2359 0 : ss << " {\n";
2360 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
2361 0 : ss << " }\n";
2362 0 : ss << " }\n";
2363 : }
2364 : else
2365 : {
2366 0 : ss << " arg = " << pCur->GetDouble() << ";\n";
2367 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
2368 : }
2369 : }
2370 : else
2371 : {
2372 0 : ss << " arg = ";
2373 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
2374 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
2375 : }
2376 : }
2377 0 : ss << " if (fCount <= 1.0)\n";
2378 0 : ss << " return DBL_MAX;\n";
2379 0 : ss << " else\n";
2380 0 : ss << " return sqrt(vSum * pow(fCount - 1.0,-1.0));\n";
2381 0 : ss << "}\n";
2382 0 : }
2383 :
2384 0 : void OpStDevP::GenSlidingWindowFunction(std::stringstream &ss,
2385 : const std::string &sSymName, SubArguments &vSubArguments)
2386 : {
2387 0 : ss << "\ndouble " << sSymName;
2388 0 : ss << "_" << BinFuncName() << "(";
2389 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
2390 : {
2391 0 : if (i)
2392 0 : ss << ",";
2393 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
2394 : }
2395 0 : ss << "){\n";
2396 0 : ss << " int gid0 = get_global_id(0);\n";
2397 0 : ss << " double fSum = 0.0;\n";
2398 0 : ss << " double fMean = 0.0;\n";
2399 0 : ss << " double vSum = 0.0;\n";
2400 0 : ss << " double fCount = 0.0;\n";
2401 0 : ss << " double arg = 0.0;\n";
2402 0 : unsigned i = vSubArguments.size();
2403 0 : while (i--)
2404 : {
2405 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
2406 : assert(pCur);
2407 0 : if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
2408 : {
2409 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
2410 : {
2411 : const formula::DoubleVectorRefToken* pDVR =
2412 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
2413 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
2414 0 : ss << " for (int i = ";
2415 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
2416 : {
2417 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
2418 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
2419 0 : ss << " {\n";
2420 : }
2421 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
2422 : {
2423 0 : ss << "0; i < " << pDVR->GetArrayLength();
2424 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
2425 0 : ss << " {\n";
2426 : }
2427 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
2428 : {
2429 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
2430 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
2431 0 : ss << " {\n";
2432 : }
2433 : else
2434 : {
2435 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
2436 0 : ss << " {\n";
2437 : }
2438 :
2439 0 : ss << " arg = ";
2440 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
2441 0 : ss << " if (isNan(arg))\n";
2442 0 : ss << " continue;\n";
2443 0 : ss << " fSum += arg;\n";
2444 0 : ss << " fCount += 1.0;\n";
2445 0 : ss << " }\n";
2446 : }
2447 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
2448 : {
2449 : const formula::SingleVectorRefToken* pSVR =
2450 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
2451 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
2452 0 : ss << " {\n";
2453 0 : ss << " arg = ";
2454 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
2455 0 : ss << " if (!isNan(arg))\n";
2456 0 : ss << " {\n";
2457 0 : ss << " fSum += arg;\n";
2458 0 : ss << " fCount += 1.0;\n";
2459 0 : ss << " }\n";
2460 0 : ss << " }\n";
2461 : }
2462 : else
2463 : {
2464 0 : ss << " arg = " << pCur->GetDouble() << ";\n";
2465 0 : ss << " fSum += arg;\n";
2466 0 : ss << " fCount += 1.0;\n";
2467 : }
2468 : }
2469 : else
2470 : {
2471 0 : ss << " arg = ";
2472 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
2473 0 : ss << " fSum += arg;\n";
2474 0 : ss << " fCount += 1.0;\n";
2475 :
2476 : }
2477 0 : if (i == 0)
2478 : {
2479 0 : ss << " fMean = fSum * pow(fCount,-1.0);\n";
2480 : }
2481 : }
2482 0 : i = vSubArguments.size();
2483 0 : while (i--)
2484 : {
2485 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
2486 : assert(pCur);
2487 0 : if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
2488 : {
2489 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
2490 : {
2491 : const formula::DoubleVectorRefToken* pDVR =
2492 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
2493 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
2494 0 : ss << " for (int i = ";
2495 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
2496 : {
2497 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
2498 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
2499 0 : ss << " {\n";
2500 : }
2501 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
2502 : {
2503 0 : ss << "0; i < " << pDVR->GetArrayLength();
2504 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
2505 0 : ss << " {\n";
2506 : }
2507 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
2508 : {
2509 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
2510 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
2511 0 : ss << " {\n";
2512 : }
2513 : else
2514 : {
2515 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
2516 0 : ss << " {\n";
2517 : }
2518 :
2519 0 : ss << " arg = ";
2520 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
2521 0 : ss << " if (isNan(arg))\n";
2522 0 : ss << " continue;\n";
2523 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
2524 0 : ss << " }\n";
2525 : }
2526 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
2527 : {
2528 : const formula::SingleVectorRefToken* pSVR =
2529 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
2530 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
2531 0 : ss << " {\n";
2532 0 : ss << " arg = ";
2533 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
2534 0 : ss << " if (!isNan(arg))\n";
2535 0 : ss << " {\n";
2536 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
2537 0 : ss << " }\n";
2538 0 : ss << " }\n";
2539 : }
2540 : else
2541 : {
2542 0 : ss << " arg = " << pCur->GetDouble() << ";\n";
2543 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
2544 : }
2545 : }
2546 : else
2547 : {
2548 0 : ss << " arg = ";
2549 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
2550 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
2551 : }
2552 : }
2553 0 : ss << " if (fCount == 0.0)\n";
2554 0 : ss << " return DBL_MAX;\n";
2555 0 : ss << " else\n";
2556 0 : ss << " return sqrt(vSum * pow(fCount,-1.0));\n";
2557 0 : ss << "}\n";
2558 0 : }
2559 :
2560 0 : void OpSlope::GenSlidingWindowFunction(std::stringstream &ss,
2561 : const std::string &sSymName, SubArguments &vSubArguments)
2562 : {
2563 0 : ss << "\ndouble " << sSymName;
2564 0 : ss << "_" << BinFuncName() << "(";
2565 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
2566 : {
2567 0 : if (i)
2568 0 : ss << ",";
2569 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
2570 : }
2571 0 : ss << "){\n";
2572 0 : ss << " int gid0 = get_global_id(0);\n";
2573 0 : ss << " double fSumX = 0.0;\n";
2574 0 : ss << " double fSumY = 0.0;\n";
2575 0 : ss << " double fMeanX = 0.0;\n";
2576 0 : ss << " double fMeanY = 0.0;\n";
2577 0 : ss << " double fSumDeltaXDeltaY = 0.0;\n";
2578 0 : ss << " double fSumSqrDeltaX = 0.0;\n";
2579 0 : ss << " double fCount = 0.0;\n";
2580 0 : ss << " double argX = 0.0;\n";
2581 0 : ss << " double argY = 0.0;\n";
2582 0 : if(vSubArguments.size() != 2)
2583 : {
2584 0 : ss << " return NAN;\n";
2585 0 : ss << "}\n";
2586 0 : return ;
2587 : }
2588 0 : FormulaToken *pCur = vSubArguments[1]->GetFormulaToken();
2589 0 : FormulaToken *pCur1 = vSubArguments[0]->GetFormulaToken();
2590 : assert(pCur);
2591 : assert(pCur1);
2592 0 : if (pCur->GetType() == formula::svDoubleVectorRef&&
2593 0 : pCur1->GetType() == formula::svDoubleVectorRef)
2594 : {
2595 : const formula::DoubleVectorRefToken* pDVR =
2596 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
2597 : const formula::DoubleVectorRefToken* pDVR1 =
2598 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur1);
2599 :
2600 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
2601 0 : size_t nCurWindowSize1 = pDVR1->GetRefRowSize();
2602 0 : size_t arrayLength = pDVR->GetArrayLength()<
2603 0 : pDVR1->GetArrayLength() ? pDVR->GetArrayLength():
2604 0 : pDVR1->GetArrayLength();
2605 0 : if(nCurWindowSize != nCurWindowSize1)
2606 : {
2607 0 : ss << " return NAN;\n";
2608 0 : ss << "}\n";
2609 0 : return ;
2610 : }
2611 0 : ss << " for (int i = ";
2612 0 : if ((!pDVR->IsStartFixed() && pDVR->IsEndFixed())
2613 0 : &&(!pDVR1->IsStartFixed() && pDVR1->IsEndFixed()))
2614 : {
2615 0 : ss << "gid0; i < " << arrayLength;
2616 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
2617 0 : ss << " {\n";
2618 : }
2619 0 : else if ((pDVR->IsStartFixed() && !pDVR->IsEndFixed())
2620 0 : &&(pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
2621 : {
2622 0 : ss << "0; i < " << arrayLength ;
2623 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
2624 0 : ss << " {\n";
2625 : }
2626 0 : else if ((!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
2627 0 : &&(!pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
2628 : {
2629 0 : ss << "0; i + gid0 < " << arrayLength;
2630 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
2631 0 : ss << " {\n";
2632 : }
2633 0 : else if ((pDVR->IsStartFixed() && pDVR->IsEndFixed())
2634 0 : &&(pDVR1->IsStartFixed() && pDVR1->IsEndFixed()))
2635 : {
2636 0 : ss << "0; i < " << arrayLength << "; i++)\n";
2637 0 : ss << " {\n";
2638 : }
2639 : else
2640 : {
2641 0 : ss << "0; i < " << nCurWindowSize << "; i++)\n";
2642 0 : ss << " {\n";
2643 0 : ss << " break;\n";
2644 0 : ss << " }";
2645 0 : ss << " return NAN;\n";
2646 0 : ss << "}\n";
2647 0 : return ;
2648 : }
2649 :
2650 0 : ss << " argX = ";
2651 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
2652 0 : ss << " argY = ";
2653 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
2654 0 : ss << " if (isNan(argX) || isNan(argY))\n";
2655 0 : ss << " continue;\n";
2656 0 : ss << " fSumX += argX;\n";
2657 0 : ss << " fSumY += argY;\n";
2658 0 : ss << " fCount += 1.0;\n";
2659 0 : ss << " }\n";
2660 :
2661 0 : ss << " if (fCount < 1.0)\n";
2662 0 : ss << " return CreateDoubleError(errNoValue);\n";
2663 0 : ss << " else\n";
2664 0 : ss << " {\n";
2665 0 : ss << " fMeanX = fSumX * pow(fCount,-1.0);\n";
2666 0 : ss << " fMeanY = fSumY * pow(fCount,-1.0);\n";
2667 :
2668 0 : ss << " for (int i = ";
2669 0 : if ((!pDVR->IsStartFixed() && pDVR->IsEndFixed())
2670 0 : &&(!pDVR1->IsStartFixed() && pDVR1->IsEndFixed()))
2671 : {
2672 0 : ss << "gid0; i < " << arrayLength;
2673 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
2674 0 : ss << " {\n";
2675 : }
2676 0 : else if ((pDVR->IsStartFixed() && !pDVR->IsEndFixed())
2677 0 : &&(pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
2678 : {
2679 0 : ss << "0; i < " << arrayLength ;
2680 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
2681 0 : ss << " {\n";
2682 : }
2683 0 : else if ((!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
2684 0 : &&(!pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
2685 : {
2686 0 : ss << "0; i + gid0 < " << arrayLength;
2687 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
2688 0 : ss << " {\n";
2689 : }
2690 : else
2691 : {
2692 0 : ss << "0; i < " << arrayLength << "; i++)\n";
2693 0 : ss << " {\n";
2694 : }
2695 :
2696 0 : ss << " argX = ";
2697 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
2698 0 : ss << " argY = ";
2699 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
2700 0 : ss << " if (isNan(argX) || isNan(argY))\n";
2701 0 : ss << " continue;\n";
2702 0 : ss << " fSumDeltaXDeltaY += (argX-fMeanX)*(argY-fMeanY);\n";
2703 0 : ss << " fSumSqrDeltaX += (argX-fMeanX) * (argX-fMeanX);\n";
2704 0 : ss << " }\n";
2705 0 : ss << " if(fSumSqrDeltaX == 0.0)\n";
2706 0 : ss << " return CreateDoubleError(errDivisionByZero);\n";
2707 0 : ss << " else\n";
2708 0 : ss << " {\n";
2709 0 : ss << " return fSumDeltaXDeltaY*pow(fSumSqrDeltaX,-1.0);\n";
2710 0 : ss << " }\n";
2711 0 : ss << " }\n";
2712 0 : ss << "}\n";
2713 : }
2714 : else
2715 : {
2716 0 : ss << " return NAN;\n";
2717 0 : ss << "}\n";
2718 : }
2719 : }
2720 0 : void OpSTEYX::GenSlidingWindowFunction(std::stringstream &ss,
2721 : const std::string &sSymName, SubArguments &vSubArguments)
2722 : {
2723 0 : ss << "\ndouble " << sSymName;
2724 0 : ss << "_" << BinFuncName() << "(";
2725 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
2726 : {
2727 0 : if (i)
2728 0 : ss << ",";
2729 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
2730 : }
2731 0 : ss << "){\n";
2732 0 : ss << " int gid0 = get_global_id(0);\n";
2733 0 : ss << " double fSumX = 0.0;\n";
2734 0 : ss << " double fSumY = 0.0;\n";
2735 0 : ss << " double fMeanX = 0.0;\n";
2736 0 : ss << " double fMeanY = 0.0;\n";
2737 0 : ss << " double fSumDeltaXDeltaY = 0.0;\n";
2738 0 : ss << " double fSumSqrDeltaX = 0.0;\n";
2739 0 : ss << " double fSumSqrDeltaY = 0.0;\n";
2740 0 : ss << " double fCount = 0.0;\n";
2741 0 : ss << " double argX = 0.0;\n";
2742 0 : ss << " double argY = 0.0;\n";
2743 0 : FormulaToken *pCur = vSubArguments[1]->GetFormulaToken();
2744 0 : FormulaToken *pCur1 = vSubArguments[0]->GetFormulaToken();
2745 : assert(pCur);
2746 : assert(pCur1);
2747 0 : if (pCur->GetType() == formula::svDoubleVectorRef&&
2748 0 : pCur1->GetType() == formula::svDoubleVectorRef)
2749 : {
2750 : const formula::DoubleVectorRefToken* pDVR =
2751 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
2752 : const formula::DoubleVectorRefToken* pDVR1 =
2753 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur1);
2754 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
2755 0 : size_t nCurWindowSize1 = pDVR1->GetRefRowSize();
2756 0 : size_t arrayLength = pDVR->GetArrayLength()<
2757 0 : pDVR1->GetArrayLength() ? pDVR->GetArrayLength():
2758 0 : pDVR1->GetArrayLength();
2759 0 : if(nCurWindowSize != nCurWindowSize1)
2760 : {
2761 0 : ss << " return DBL_MAX;\n";
2762 0 : ss << "}\n";
2763 0 : return ;
2764 : }
2765 0 : ss << " for (int i = ";
2766 0 : if ((!pDVR->IsStartFixed() && pDVR->IsEndFixed())
2767 0 : &&(!pDVR1->IsStartFixed() && pDVR1->IsEndFixed()))
2768 : {
2769 0 : ss << "gid0; i < " << arrayLength;
2770 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
2771 0 : ss << " {\n";
2772 : }
2773 0 : else if ((pDVR->IsStartFixed() && !pDVR->IsEndFixed())
2774 0 : &&(pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
2775 : {
2776 0 : ss << "0; i < " << arrayLength;
2777 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
2778 0 : ss << " {\n";
2779 : }
2780 0 : else if ((!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
2781 0 : &&(!pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
2782 : {
2783 0 : ss << "0; i + gid0 < " << arrayLength;
2784 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
2785 0 : ss << " {\n";
2786 : }
2787 0 : else if ((pDVR->IsStartFixed() && pDVR->IsEndFixed())
2788 0 : &&(pDVR1->IsStartFixed() && pDVR1->IsEndFixed()))
2789 : {
2790 0 : ss << "0; i < " << arrayLength << "; i++)\n";
2791 0 : ss << " {\n";
2792 : }
2793 : else
2794 : {
2795 0 : ss << "0; i < " << nCurWindowSize << "; i++)\n";
2796 0 : ss << " {\n";
2797 0 : ss << " break;\n";
2798 0 : ss << " }";
2799 0 : ss << " return DBL_MAX;\n";
2800 0 : ss << "}\n";
2801 0 : return ;
2802 : }
2803 :
2804 0 : ss << " argX = ";
2805 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
2806 0 : ss << " argY = ";
2807 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
2808 0 : ss << " if (isNan(argX) || isNan(argY))\n";
2809 0 : ss << " continue;\n";
2810 0 : ss << " fSumX += argX;\n";
2811 0 : ss << " fSumY += argY;\n";
2812 0 : ss << " fCount += 1.0;\n";
2813 0 : ss << " }\n";
2814 :
2815 0 : ss << " if (fCount < 3.0)\n";
2816 0 : ss << " return DBL_MAX;\n";
2817 0 : ss << " else\n";
2818 0 : ss << " {\n";
2819 0 : ss << " fMeanX = fSumX * pow(fCount,-1.0);\n";
2820 0 : ss << " fMeanY = fSumY * pow(fCount,-1.0);\n";
2821 :
2822 0 : ss << " for (int i = ";
2823 0 : if ((!pDVR->IsStartFixed() && pDVR->IsEndFixed())
2824 0 : &&(!pDVR1->IsStartFixed() && pDVR1->IsEndFixed()))
2825 : {
2826 0 : ss << "gid0; i < " << arrayLength;
2827 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
2828 0 : ss << " {\n";
2829 : }
2830 0 : else if ((pDVR->IsStartFixed() && !pDVR->IsEndFixed())
2831 0 : &&(pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
2832 : {
2833 0 : ss << "0; i < " << arrayLength ;
2834 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
2835 0 : ss << " {\n";
2836 : }
2837 0 : else if ((!pDVR->IsStartFixed() && !pDVR->IsEndFixed())&&
2838 0 : (!pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
2839 : {
2840 0 : ss << "0; i + gid0 < " << arrayLength;
2841 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
2842 0 : ss << " {\n";
2843 : }
2844 : else
2845 : {
2846 0 : ss << "0; i < " << arrayLength << "; i++)\n";
2847 0 : ss << " {\n";
2848 : }
2849 :
2850 0 : ss << " argX = ";
2851 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
2852 0 : ss << " argY = ";
2853 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
2854 0 : ss << " if (isNan(argX)||isNan(argY))\n";
2855 0 : ss << " continue;\n";
2856 0 : ss << " fSumDeltaXDeltaY +=(argX-fMeanX)*(argY-fMeanY);\n";
2857 0 : ss << " fSumSqrDeltaX += (argX-fMeanX)*(argX-fMeanX);\n";
2858 0 : ss << " fSumSqrDeltaY += (argY-fMeanY)*(argY-fMeanY);\n";
2859 0 : ss << " }\n";
2860 0 : ss << " if(fSumSqrDeltaX == 0.0)\n";
2861 0 : ss << " return DBL_MAX;\n";
2862 0 : ss << " else\n";
2863 0 : ss << " {\n";
2864 0 : ss << " return sqrt((fSumSqrDeltaY - fSumDeltaXDeltaY * \n";
2865 0 : ss << " fSumDeltaXDeltaY*pow(fSumSqrDeltaX,-1.0))\n";
2866 0 : ss << " *pow(fCount - 2.0,-1.0));\n";
2867 0 : ss << " }\n";
2868 0 : ss << " }\n";
2869 0 : ss << "}\n";
2870 : }
2871 : else
2872 : {
2873 0 : ss << " return DBL_MAX;\n";
2874 0 : ss << "}\n";
2875 : }
2876 : }
2877 0 : void OpFisher::GenSlidingWindowFunction(
2878 : std::stringstream &ss, const std::string &sSymName, SubArguments &
2879 : vSubArguments)
2880 : {
2881 0 : ss << "\ndouble " << sSymName;
2882 0 : ss << "_"<< BinFuncName() <<"(";
2883 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
2884 : {
2885 0 : if (i)
2886 0 : ss << ",";
2887 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
2888 : }
2889 0 : ss << ") {\n";
2890 0 : ss <<" int gid0=get_global_id(0);\n";
2891 0 : ss <<" double arg0;\n";
2892 0 : if(vSubArguments.size() != 1)
2893 : {
2894 0 : ss << " return DBL_MAX;\n";
2895 0 : return ;
2896 : }
2897 0 : FormulaToken *pCur = vSubArguments[0]->GetFormulaToken();
2898 : assert(pCur);
2899 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
2900 : {
2901 0 : ss << " return DBL_MAX;\n";
2902 0 : return ;
2903 : }
2904 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
2905 : {
2906 : const formula::SingleVectorRefToken* pSVR =
2907 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
2908 0 : ss << " arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
2909 0 : ss << ";\n";
2910 0 : ss<< " if(isNan(arg0)||(gid0>=";
2911 0 : ss<<pSVR->GetArrayLength();
2912 0 : ss<<"))\n";
2913 0 : ss<<" arg0 = 0;\n";
2914 : }
2915 0 : else if (pCur->GetType() == formula::svDouble)
2916 : {
2917 0 : ss << " arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
2918 0 : ss << ";\n";
2919 0 : ss << " if(isNan(arg0))\n";
2920 0 : ss << " return DBL_MAX;\n";
2921 : }
2922 0 : ss << " if (fabs(arg0) >= 1.0)\n";
2923 0 : ss << " return DBL_MAX;\n";
2924 0 : ss << " double tmp=0.5*log((1+arg0)*pow((1-arg0),-1));\n";
2925 0 : ss << " return tmp;\n";
2926 0 : ss << "}\n";
2927 : }
2928 :
2929 0 : void OpFisherInv::GenSlidingWindowFunction(
2930 : std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
2931 : {
2932 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
2933 : const formula::SingleVectorRefToken*tmpCurDVR = static_cast<const
2934 0 : formula::SingleVectorRefToken *>(tmpCur);
2935 0 : ss << "\ndouble " << sSymName;
2936 0 : ss << "_"<< BinFuncName() <<"(";
2937 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
2938 : {
2939 0 : if (i)
2940 0 : ss << ",";
2941 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
2942 : }
2943 0 : ss << ") {\n\t";
2944 0 : ss <<"int gid0=get_global_id(0);\n\t";
2945 0 : ss << "double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
2946 0 : ss << ";\n\t";
2947 0 : ss<< "if(isNan(arg0)||(gid0>=";
2948 0 : ss<<tmpCurDVR->GetArrayLength();
2949 0 : ss<<"))\n\t\t";
2950 0 : ss<<"arg0 = 0;\n\t";
2951 0 : ss << "double tmp=tanh(arg0);\n\t";
2952 0 : ss << "return tmp;\n";
2953 0 : ss << "}\n";
2954 0 : }
2955 :
2956 0 : void OpGamma::GenSlidingWindowFunction(
2957 : std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
2958 : {
2959 0 : ss << "\ndouble " << sSymName;
2960 0 : ss << "_"<< BinFuncName() <<"(";
2961 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
2962 : {
2963 0 : if (i)
2964 0 : ss << ",";
2965 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
2966 : }
2967 0 : ss << ") {\n\t";
2968 0 : ss <<"int gid0=get_global_id(0);\n\t";
2969 0 : ss << "double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
2970 0 : ss << ";\n\t";
2971 0 : ss << "double tmp=tgamma(arg0);\n\t";
2972 0 : ss << "return tmp;\n";
2973 0 : ss << "}\n";
2974 0 : }
2975 :
2976 0 : void OpCorrel::GenSlidingWindowFunction(
2977 : std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
2978 : {
2979 0 : if( vSubArguments.size() !=2 ||vSubArguments[0]->GetFormulaToken()
2980 0 : ->GetType() != formula::svDoubleVectorRef||vSubArguments[1]
2981 0 : ->GetFormulaToken()->GetType() != formula::svDoubleVectorRef )
2982 : ///only support DoubleVector in OpCorrelfor GPU calculating.
2983 0 : throw Unhandled();
2984 : const formula::DoubleVectorRefToken* pCurDVRX =
2985 : static_cast<const formula::DoubleVectorRefToken *>(
2986 0 : vSubArguments[0]->GetFormulaToken());
2987 : const formula::DoubleVectorRefToken* pCurDVRY =
2988 : static_cast<const formula::DoubleVectorRefToken *>(
2989 0 : vSubArguments[1]->GetFormulaToken());
2990 0 : if( pCurDVRX->GetRefRowSize() != pCurDVRY->GetRefRowSize() )
2991 0 : throw Unhandled();
2992 :
2993 0 : ss << "\ndouble " << sSymName;
2994 0 : ss << "_"<< BinFuncName() <<"(";
2995 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
2996 : {
2997 0 : if (i)
2998 0 : ss << ",";
2999 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
3000 : }
3001 0 : ss << ") {\n\t";
3002 0 : ss << "double vSum = 0.0;\n\t";
3003 0 : ss << "double vXSum = 0.0;\n\t";
3004 0 : ss << "double vYSum = 0.0;\n\t";
3005 0 : ss << "double vXMean = 0.0;\n\t";
3006 0 : ss << "double vYMean = 0.0;\n\t";
3007 :
3008 0 : ss << "int gid0 = get_global_id(0);\n\t";
3009 0 : ss << "double arg0 = 0.0;\n\t";
3010 0 : ss << "double arg1 = 0.0;\n\t";
3011 0 : ss << "int cnt = 0;\n\t";
3012 :
3013 0 : size_t nCurWindowSizeX = pCurDVRY->GetRefRowSize();
3014 :
3015 0 : ss << "for (int i = ";
3016 0 : if (!pCurDVRX->IsStartFixed() && pCurDVRX->IsEndFixed()) {
3017 0 : ss << "gid0; i < " << nCurWindowSizeX << "; i++) {\n\t\t";
3018 0 : ss << "arg0 = " << vSubArguments[0]
3019 0 : ->GenSlidingWindowDeclRef(true) << ";\n\t\t";
3020 0 : ss << "arg1 = " << vSubArguments[1]
3021 0 : ->GenSlidingWindowDeclRef(true) << ";\n\t\t";
3022 0 : ss << "if(isNan(arg0) || isNan(arg1) || (i >= ";
3023 0 : ss << pCurDVRX->GetArrayLength() << ") || (i >=";
3024 0 : ss << pCurDVRY->GetArrayLength() << ")) {\n\t\t\t";
3025 0 : ss << "arg0 = 0.0;\n\t\t\t";
3026 0 : ss << "arg1 = 0.0;\n\t\t\t";
3027 0 : ss << "--cnt;\n\t\t";
3028 0 : ss << "}\n\t\t";
3029 0 : ss << "++cnt;\n\t\t";
3030 0 : ss << "vXSum += arg0;\n\t\t";
3031 0 : ss << "vYSum += arg1;\n\t";
3032 0 : ss << "}\n\t";
3033 0 : } else if (pCurDVRX->IsStartFixed() && !pCurDVRX->IsEndFixed()) {
3034 0 : ss << "0; i < gid0 + " << nCurWindowSizeX << "; i++) {\n\t\t";
3035 0 : ss << "arg0 = " << vSubArguments[0]
3036 0 : ->GenSlidingWindowDeclRef(true) << ";\n\t\t";
3037 0 : ss << "arg1 = " << vSubArguments[1]
3038 0 : ->GenSlidingWindowDeclRef(true) << ";\n\t\t";
3039 0 : ss << "if(isNan(arg0) || isNan(arg1) || (i >= ";
3040 0 : ss << pCurDVRX->GetArrayLength() << ") || (i >=";
3041 0 : ss << pCurDVRY->GetArrayLength() << ")) {\n\t\t\t";
3042 0 : ss << "arg0 = 0.0;\n\t\t\t";
3043 0 : ss << "arg1 = 0.0;\n\t\t\t";
3044 0 : ss << "--cnt;\n\t\t";
3045 0 : ss << "}\n\t\t";
3046 0 : ss << "++cnt;\n\t\t";
3047 0 : ss << "vXSum += arg0;\n\t\t";
3048 0 : ss << "vYSum += arg1;\n\t";
3049 0 : ss << "}\n\t";
3050 : }
3051 0 : else if (pCurDVRX->IsStartFixed() && pCurDVRX->IsEndFixed()) {
3052 0 : ss << "0; i < " << nCurWindowSizeX << "; i++) {\n\t\t";
3053 0 : ss << "arg0 = " << vSubArguments[0]
3054 0 : ->GenSlidingWindowDeclRef(true) << ";\n\t\t";
3055 0 : ss << "arg1 = " << vSubArguments[1]
3056 0 : ->GenSlidingWindowDeclRef(true) << ";\n\t\t";
3057 0 : ss << "if(isNan(arg0) || isNan(arg1) || (i >= ";
3058 0 : ss << pCurDVRX->GetArrayLength() << ") || (i >=";
3059 0 : ss << pCurDVRY->GetArrayLength() << ")) {\n\t\t\t";
3060 0 : ss << "arg0 = 0.0;\n\t\t\t";
3061 0 : ss << "arg1 = 0.0;\n\t\t\t";
3062 0 : ss << "--cnt;\n\t\t";
3063 0 : ss << "}\n\t\t";
3064 0 : ss << "++cnt;\n\t\t";
3065 0 : ss << "vXSum += arg0;\n\t\t";
3066 0 : ss << "vYSum += arg1;\n\t";
3067 0 : ss << "}\n\t";
3068 : } else {
3069 0 : ss << "0; i < " << nCurWindowSizeX << "; i++) {\n\t\t";
3070 0 : ss << "arg0 = " << vSubArguments[0]
3071 0 : ->GenSlidingWindowDeclRef(true) << ";\n\t\t";
3072 0 : ss << "arg1 = " << vSubArguments[1]
3073 0 : ->GenSlidingWindowDeclRef(true) << ";\n\t\t";
3074 0 : ss << "if(isNan(arg0) || isNan(arg1) || (i + gid0 >= ";
3075 0 : ss << pCurDVRX->GetArrayLength() << ") || (i + gid0 >=";
3076 0 : ss << pCurDVRY->GetArrayLength() << ")) {\n\t\t\t";
3077 0 : ss << "arg0 = 0.0;\n\t\t\t";
3078 0 : ss << "arg1 = 0.0;\n\t\t\t";
3079 0 : ss << "--cnt;\n\t\t";
3080 0 : ss << "}\n\t\t";
3081 0 : ss << "++cnt;\n\t\t";
3082 0 : ss << "vXSum += arg0;\n\t\t";
3083 0 : ss << "vYSum += arg1;\n\t";
3084 0 : ss << "}\n\t";
3085 : }
3086 :
3087 0 : ss << "if(cnt < 1) {\n\t\t";
3088 0 : ss << "return DBL_MIN;\n\t";
3089 0 : ss << "}\n\t";
3090 0 : ss << "else {\n\t\t";
3091 0 : ss << "vXMean = vXSum/cnt;\n\t\t";
3092 0 : ss << "vYMean = vYSum/cnt;\n\t\t";
3093 0 : ss << "vXSum = 0.0;\n\t\t";
3094 0 : ss << "vYSum = 0.0;\n\t\t";
3095 :
3096 0 : ss << "for (int i = ";
3097 0 : if (!pCurDVRX->IsStartFixed() && pCurDVRX->IsEndFixed()) {
3098 0 : ss << "gid0; i < " << nCurWindowSizeX << "; i++) {\n\t\t\t";
3099 0 : ss << "arg0 = " << vSubArguments[0]
3100 0 : ->GenSlidingWindowDeclRef(true) << ";\n\t\t\t";
3101 0 : ss << "arg1 = " << vSubArguments[1]
3102 0 : ->GenSlidingWindowDeclRef(true) << ";\n\t\t\t";
3103 0 : ss << "if(isNan(arg0) || isNan(arg1) || (i >= ";
3104 0 : ss << pCurDVRX->GetArrayLength() << ") || (i >=";
3105 0 : ss << pCurDVRY->GetArrayLength() << ")) {\n\t\t\t\t";
3106 0 : ss << "arg0 = vXMean;\n\t\t\t\t";
3107 0 : ss << "arg1 = vYMean;\n\t\t\t";
3108 0 : ss << "}\n\t\t\t";
3109 0 : ss << "vXSum += pow(arg0 - vXMean, 2);\n\t\t\t";
3110 0 : ss << "vYSum += pow(arg1 - vYMean, 2);\n\t\t\t";
3111 0 : ss << "vSum += (arg0 - vXMean)*(arg1 - vYMean);\n\t\t";
3112 0 : ss << "}\n\t\t";
3113 0 : } else if (pCurDVRX->IsStartFixed() && !pCurDVRX->IsEndFixed()) {
3114 0 : ss << "0; i < gid0 + " << nCurWindowSizeX << "; i++) {\n\t\t\t";
3115 0 : ss << "arg0 = " << vSubArguments[0]
3116 0 : ->GenSlidingWindowDeclRef(true) << ";\n\t\t\t";
3117 0 : ss << "arg1 = " << vSubArguments[1]
3118 0 : ->GenSlidingWindowDeclRef(true) << ";\n\t\t\t";
3119 0 : ss << "if(isNan(arg0) || isNan(arg1) || (i >= ";
3120 0 : ss << pCurDVRX->GetArrayLength() << ") || (i >=";
3121 0 : ss << pCurDVRY->GetArrayLength() << ")) {\n\t\t\t\t";
3122 0 : ss << "arg0 = vXMean;\n\t\t\t\t";
3123 0 : ss << "arg1 = vYMean;\n\t\t\t";
3124 0 : ss << "}\n\t\t\t";
3125 0 : ss << "vXSum += pow(arg0 - vXMean, 2);\n\t\t\t";
3126 0 : ss << "vYSum += pow(arg1 - vYMean, 2);\n\t\t\t";
3127 0 : ss << "vSum += (arg0 - vXMean)*(arg1 - vYMean);\n\t\t";
3128 0 : ss << "}\n\t\t";
3129 0 : } else if (pCurDVRX->IsStartFixed() && pCurDVRX->IsEndFixed()) {
3130 0 : ss << "0; i < " << nCurWindowSizeX << "; i++) {\n\t\t\t";
3131 0 : ss << "arg0 = " << vSubArguments[0]
3132 0 : ->GenSlidingWindowDeclRef(true) << ";\n\t\t\t";
3133 0 : ss << "arg1 = " << vSubArguments[1]
3134 0 : ->GenSlidingWindowDeclRef(true) << ";\n\t\t\t";
3135 0 : ss << "if(isNan(arg0) || isNan(arg1) || (i >= ";
3136 0 : ss << pCurDVRX->GetArrayLength() << ") || (i >=";
3137 0 : ss << pCurDVRY->GetArrayLength() << ")) {\n\t\t\t\t";
3138 0 : ss << "arg0 = vXMean;\n\t\t\t\t";
3139 0 : ss << "arg1 = vYMean;\n\t\t\t";
3140 0 : ss << "}\n\t\t\t";
3141 0 : ss << "vXSum += pow(arg0 - vXMean, 2);\n\t\t\t";
3142 0 : ss << "vYSum += pow(arg1 - vYMean, 2);\n\t\t\t";
3143 0 : ss << "vSum += (arg0 - vXMean)*(arg1 - vYMean);\n\t\t";
3144 0 : ss << "}\n\t\t";
3145 : } else {
3146 0 : ss << "0; i < " << nCurWindowSizeX << "; i++) {\n\t\t\t";
3147 0 : ss << "arg0 = " << vSubArguments[0]
3148 0 : ->GenSlidingWindowDeclRef(true) << ";\n\t\t\t";
3149 0 : ss << "arg1 = " << vSubArguments[1]
3150 0 : ->GenSlidingWindowDeclRef(true) << ";\n\t\t\t";
3151 0 : ss << "if(isNan(arg0) || isNan(arg1) || (i + gid0 >= ";
3152 0 : ss << pCurDVRX->GetArrayLength() << ") || (i + gid0 >=";
3153 0 : ss << pCurDVRY->GetArrayLength() << ")) {\n\t\t\t\t";
3154 0 : ss << "arg0 = vXMean;\n\t\t\t\t";
3155 0 : ss << "arg1 = vYMean;\n\t\t\t";
3156 0 : ss << "}\n\t\t\t";
3157 0 : ss << "vXSum += ((arg0 - vXMean)*(arg0 - vXMean));\n\t\t\t";
3158 0 : ss << "vYSum += ((arg1 - vYMean)*(arg1 - vYMean));\n\t\t\t";
3159 0 : ss << "vSum += (arg0 - vXMean)*(arg1 - vYMean);\n\t\t";
3160 0 : ss << "}\n\t\t";
3161 : }
3162 :
3163 0 : ss << "if(vXSum == 0.0 || vYSum == 0.0) {\n\t\t\t";
3164 0 : ss << "return NAN;\n\t\t";
3165 0 : ss << "}\n\t\t";
3166 0 : ss << "else {\n\t\t\t";
3167 0 : ss << "return vSum/pow(vXSum*vYSum, 0.5);\n\t\t";
3168 0 : ss << "}\n\t";
3169 0 : ss << "}\n";
3170 0 : ss << "}";
3171 0 : }
3172 :
3173 0 : void OpNegbinomdist::GenSlidingWindowFunction(
3174 : std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
3175 : {
3176 0 : ss << "\ndouble " << sSymName;
3177 0 : ss << "_"<< BinFuncName() <<"(";
3178 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
3179 : {
3180 0 : if (i)
3181 0 : ss << ",";
3182 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
3183 : }
3184 0 : ss << ")\n";
3185 0 : ss << "{\n\t";
3186 0 : ss << "double f,s,p,tmp0,tmp1,tmp2;\n";
3187 0 : ss << " int gid0=get_global_id(0);\n";
3188 0 : size_t i = vSubArguments.size();
3189 0 : ss <<"\n";
3190 0 : for (i = 0; i < vSubArguments.size(); i++)
3191 : {
3192 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
3193 : assert(pCur);
3194 0 : if (pCur->GetType() == formula::svSingleVectorRef)
3195 : {
3196 : const formula::SingleVectorRefToken* pSVR =
3197 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
3198 0 : ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
3199 : }
3200 0 : else if (pCur->GetType() == formula::svDouble)
3201 : {
3202 0 : ss << "{\n";
3203 : }
3204 : else
3205 : {
3206 : }
3207 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
3208 : {
3209 0 : ss << " if (isNan(";
3210 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
3211 0 : ss << "))\n";
3212 0 : ss << " tmp"<<i<<"= 0;\n";
3213 0 : ss << " else\n";
3214 0 : ss << " tmp"<<i<<"=\n";
3215 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
3216 0 : ss << ";\n}\n";
3217 : }
3218 : else
3219 : {
3220 0 : ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
3221 0 : ss <<";\n";
3222 : }
3223 : }
3224 0 : ss << " p = tmp2;\n";
3225 0 : ss << " s = tmp1;\n";
3226 0 : ss << " f = tmp0;\n";
3227 0 : ss << " double q = 1.0 - p;\n\t";
3228 0 : ss << " double fFactor = pow(p,s);\n\t";
3229 0 : ss << " for(int i=0; i<f; i++)\n\t";
3230 0 : ss << " {\n\t";
3231 0 : ss << " fFactor *= ((double)i+s)*pow(((double)i+1.0),-1.0)/pow(q,-1);\n";
3232 0 : ss << " }\n\t";
3233 0 : ss << " double temp=fFactor;\n\t";
3234 0 : ss << " return temp;\n";
3235 0 : ss << "}\n";
3236 0 : }
3237 :
3238 0 : void OpPearson::GenSlidingWindowFunction(
3239 : std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
3240 : {
3241 0 : if( vSubArguments.size() !=2 ||vSubArguments[0]->GetFormulaToken()
3242 0 : ->GetType() != formula::svDoubleVectorRef||vSubArguments[1]
3243 0 : ->GetFormulaToken()->GetType() != formula::svDoubleVectorRef )
3244 : ///only support DoubleVector in OpPearson for GPU calculating.
3245 0 : throw Unhandled();
3246 : const formula::DoubleVectorRefToken* pDVR =
3247 : static_cast<const formula::DoubleVectorRefToken *>(
3248 0 : vSubArguments[0]->GetFormulaToken());
3249 : const formula::DoubleVectorRefToken* pCurDVRY =
3250 : static_cast<const formula::DoubleVectorRefToken *>(
3251 0 : vSubArguments[1]->GetFormulaToken());
3252 0 : if( pDVR->GetRefRowSize() != pCurDVRY->GetRefRowSize() )
3253 0 : throw Unhandled();
3254 :
3255 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
3256 :
3257 0 : ss << "\ndouble " << sSymName;
3258 0 : ss << "_"<< BinFuncName() <<"(";
3259 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
3260 : {
3261 0 : if (i)
3262 0 : ss << ",";
3263 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
3264 : }
3265 0 : ss << ")\n";
3266 0 : ss << "{\n";
3267 0 : ss << " int gid0=get_global_id(0);\n";
3268 0 : ss << " double fCount = 0.0;\n";
3269 0 : ss << " double fSumX = 0.0;\n";
3270 0 : ss << " double fSumY = 0.0;\n";
3271 0 : ss << " double fSumDeltaXDeltaY = 0.0;\n";
3272 0 : ss << " double fInx;\n";
3273 0 : ss << " double fIny;\n";
3274 0 : ss << "for (int i = ";
3275 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
3276 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
3277 0 : ss << " && i < " << nCurWindowSize << "; i++){\n";
3278 0 : } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
3279 0 : ss << "0; i < " << pDVR->GetArrayLength();
3280 0 : ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
3281 0 : } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
3282 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
3283 0 : ss << " && i < "<< nCurWindowSize << "; i++){\n";
3284 : }
3285 : else {
3286 0 : ss << "0; i < "<< nCurWindowSize << "; i++){\n";
3287 : }
3288 0 : ss << " fInx = "<<vSubArguments[0]->GenSlidingWindowDeclRef(true);
3289 0 : ss << ";\n";
3290 0 : ss << " fIny = "<<vSubArguments[1]->GenSlidingWindowDeclRef(true);
3291 0 : ss << " ;\n";
3292 0 : ss << " if(isNan(fInx)||isNan(fIny)){fInx=0.0;fIny=0.0;fCount = fCount-1;}\n";
3293 0 : ss << " fSumX += fInx;\n";
3294 0 : ss << " fSumY += fIny;\n";
3295 0 : ss << " fCount = fCount + 1;\n";
3296 0 : ss << " }\n";
3297 0 : ss << " double fMeanX = fSumX / fCount;\n";
3298 0 : ss << " double fMeanY = fSumY / fCount;\n";
3299 0 : ss << " fSumX = 0.0;\n";
3300 0 : ss << " fSumY = 0.0;\n";
3301 0 : ss << "for (int i = ";
3302 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
3303 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
3304 0 : ss << " && i < " << nCurWindowSize << "; i++){\n";
3305 0 : } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
3306 0 : ss << "0; i < " << pDVR->GetArrayLength();
3307 0 : ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
3308 0 : } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
3309 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
3310 0 : ss << " && i < "<< nCurWindowSize << "; i++){\n";
3311 : }
3312 : else {
3313 0 : ss << "0; i < "<< nCurWindowSize << "; i++){\n";
3314 : }
3315 0 : ss << " fInx = "<<vSubArguments[0]->GenSlidingWindowDeclRef(true);
3316 0 : ss << " ;\n";
3317 0 : ss << " fIny = "<<vSubArguments[1]->GenSlidingWindowDeclRef(true);
3318 0 : ss << " ;\n";
3319 0 : ss << " if(isNan(fInx)||isNan(fIny)){fInx=0.0;fIny=0.0;}\n";
3320 0 : ss << " fSumDeltaXDeltaY += (fInx - fMeanX) * (fIny - fMeanY);\n";
3321 0 : ss << " fSumX += pow(fInx - fMeanX,2);\n";
3322 0 : ss << " fSumY += pow(fIny - fMeanY,2);\n";
3323 0 : ss << " }\n";
3324 0 : ss << " double tmp = ( fSumDeltaXDeltaY / ";
3325 0 : ss << "sqrt( fSumX * fSumY));\n\t";
3326 0 : ss << " if (isnan(tmp))\n";
3327 0 : ss << " return CreateDoubleError(errNoValue);\n";
3328 0 : ss << " return tmp;\n";
3329 0 : ss << "}\n";
3330 0 : }
3331 :
3332 0 : void OpGammaLn::GenSlidingWindowFunction(
3333 : std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
3334 : {
3335 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
3336 : const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const
3337 0 : formula::SingleVectorRefToken *>(tmpCur);
3338 0 : ss << "\ndouble " << sSymName;
3339 0 : ss << "_"<< BinFuncName() <<"(";
3340 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
3341 : {
3342 0 : if (i)
3343 0 : ss << ",";
3344 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
3345 : }
3346 0 : ss << ") {\n\t";
3347 0 : ss <<"int gid0=get_global_id(0);\n\t";
3348 0 : ss << "double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
3349 0 : ss << ";\n\t";
3350 0 : ss<< "if(isNan(arg0)||(gid0>=";
3351 0 : ss<<tmpCurDVR->GetArrayLength();
3352 0 : ss<<"))\n\t\t";
3353 0 : ss<<"arg0 = 0;\n\t";
3354 0 : ss << "double tmp=lgamma(arg0);\n\t";
3355 0 : ss << "return tmp;\n";
3356 0 : ss << "}\n";
3357 0 : }
3358 0 : void OpGauss::BinInlineFun(std::set<std::string>& decls,
3359 : std::set<std::string>& funs)
3360 : {
3361 0 : decls.insert(taylorDecl);decls.insert(phiDecl);
3362 0 : decls.insert(gaussDecl);
3363 0 : funs.insert(taylor);funs.insert(phi);
3364 0 : funs.insert(gauss);
3365 0 : }
3366 :
3367 0 : void OpGauss::GenSlidingWindowFunction(
3368 : std::stringstream &ss, const std::string &sSymName, SubArguments &
3369 : vSubArguments)
3370 : {
3371 0 : ss << "\ndouble " << sSymName;
3372 0 : ss << "_"<< BinFuncName() <<"(";
3373 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
3374 : {
3375 0 : if (i)
3376 0 : ss << ",";
3377 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
3378 : }
3379 0 : ss << ") {\n";
3380 0 : ss <<" int gid0=get_global_id(0);\n";
3381 0 : ss <<" double arg0;\n";
3382 0 : if(vSubArguments.size() != 1)
3383 : {
3384 0 : ss << " return DBL_MAX;\n";
3385 0 : return ;
3386 : }
3387 0 : FormulaToken *pCur = vSubArguments[0]->GetFormulaToken();
3388 : assert(pCur);
3389 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
3390 : {
3391 0 : ss << " return DBL_MAX;\n";
3392 0 : return ;
3393 : }
3394 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
3395 : {
3396 : const formula::SingleVectorRefToken* pSVR =
3397 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
3398 0 : ss << " arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
3399 0 : ss << ";\n";
3400 0 : ss<< " if(isNan(arg0)||(gid0>=";
3401 0 : ss<<pSVR->GetArrayLength();
3402 0 : ss<<"))\n";
3403 0 : ss<<" arg0 = 0;\n";
3404 : }
3405 0 : else if (pCur->GetType() == formula::svDouble)
3406 : {
3407 0 : ss << " arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
3408 0 : ss << ";\n";
3409 0 : ss << " if(isNan(arg0))\n";
3410 0 : ss << " return DBL_MAX;\n";
3411 : }
3412 0 : ss << " double tmp=gauss(arg0);\n";
3413 0 : ss << " return tmp;\n";
3414 0 : ss << "}\n";
3415 : }
3416 :
3417 0 : void OpGeoMean::GenSlidingWindowFunction(
3418 : std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
3419 : {
3420 0 : ss << "__kernel void ";
3421 0 : ss << "GeoMean_reduction( ";
3422 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
3423 : {
3424 0 : if (i)
3425 0 : ss << ",";
3426 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
3427 : }
3428 0 : ss << ", __global double *result)\n";
3429 0 : ss << "{\n";
3430 0 : ss << " double tmp =0;\n";
3431 0 : ss << " int count = 0;\n";
3432 0 : ss << " int i ;\n";
3433 0 : GenTmpVariables(ss,vSubArguments);
3434 0 : ss << " double current_sum = 0.0;\n";
3435 0 : ss << " int windowSize;\n";
3436 0 : ss << " int arrayLength;\n";
3437 0 : ss << " int current_count = 0;\n";
3438 0 : ss << " int writePos = get_group_id(1);\n";
3439 0 : ss << " int lidx = get_local_id(0);\n";
3440 0 : ss << " __local double shm_buf[256];\n";
3441 0 : ss << " __local int count_buf[256];\n";
3442 0 : ss << " int loop;\n";
3443 0 : ss << " int offset;\n";
3444 0 : ss << " barrier(CLK_LOCAL_MEM_FENCE);\n";
3445 :
3446 0 : for(size_t i=0;i<vSubArguments.size();i++)
3447 : {
3448 : assert(vSubArguments[i]->GetFormulaToken());
3449 :
3450 0 : if(vSubArguments[i]->GetFormulaToken()->GetType() ==
3451 : formula::svDoubleVectorRef)
3452 : {
3453 0 : FormulaToken *tmpCur = vSubArguments[i]->GetFormulaToken();
3454 : const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
3455 0 : formula::DoubleVectorRefToken *>(tmpCur);
3456 0 : size_t nCurWindowSize = pCurDVR->GetArrayLength() <
3457 0 : pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
3458 0 : pCurDVR->GetRefRowSize() ;
3459 :
3460 0 : if (pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed())
3461 0 : ss << " offset = 0;\n";
3462 0 : else if (!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
3463 0 : ss << " offset = get_group_id(1);\n";
3464 : else
3465 0 : throw Unhandled();
3466 0 : ss << " windowSize = ";
3467 0 : ss << nCurWindowSize;
3468 0 : ss << ";\n";
3469 0 : ss << " arrayLength = ";
3470 0 : ss << pCurDVR->GetArrayLength();
3471 0 : ss << ";\n";
3472 0 : ss << " loop = arrayLength/512 + 1;\n";
3473 0 : ss << " for (int l=0; l<loop; l++){\n";
3474 0 : ss << " tmp = 0.0;\n";
3475 0 : ss << " count = 0;\n";
3476 0 : ss << " int loopOffset = l*512;\n";
3477 0 : ss << " int p1 = loopOffset + lidx + offset, p2 = p1 + 256;\n";
3478 0 : ss << " if (p2 < min(offset + windowSize, arrayLength)) {\n";
3479 0 : ss << " tmp0 = 0.0;\n";
3480 0 : std::string p1 = "p1";
3481 0 : std::string p2 = "p2";
3482 :
3483 0 : ss << " tmp0 =";
3484 0 : vSubArguments[i]->GenDeclRef(ss);
3485 0 : ss << "["<<p1.c_str()<<"];\n";
3486 0 : ss << " if(!isNan(tmp0))\n";
3487 0 : ss << " {\n";
3488 0 : ss << " tmp += log(tmp0);\n";
3489 0 : ss << " count++;\n";
3490 0 : ss << " }\n";
3491 :
3492 0 : ss << " tmp0 =";
3493 0 : vSubArguments[i]->GenDeclRef(ss);
3494 0 : ss << "["<<p2.c_str()<<"];\n";
3495 0 : ss << " if(!isNan(tmp0))\n";
3496 0 : ss << " {\n";
3497 0 : ss << " tmp += log(tmp0);\n";
3498 0 : ss << " count++;\n";
3499 0 : ss << " }\n";
3500 :
3501 0 : ss << " }\n";
3502 0 : ss << " else if (p1 < min(arrayLength, offset + windowSize)) {\n";
3503 :
3504 0 : ss << " tmp0 =";
3505 0 : vSubArguments[i]->GenDeclRef(ss);
3506 0 : ss << "["<<p1.c_str()<<"];\n";
3507 0 : ss << " if(!isNan(tmp0))\n";
3508 0 : ss << " {\n";
3509 0 : ss << " tmp += log(tmp0);\n";
3510 0 : ss << " count++;\n";
3511 0 : ss << " }\n";
3512 :
3513 0 : ss << " }\n";
3514 0 : ss << " shm_buf[lidx] = tmp;\n";
3515 0 : ss << " count_buf[lidx] = count;\n";
3516 0 : ss << " barrier(CLK_LOCAL_MEM_FENCE);\n";
3517 :
3518 0 : ss << " for (int i = 128; i >0; i/=2) {\n";
3519 0 : ss << " if (lidx < i)\n";
3520 0 : ss << " {\n";
3521 0 : ss << " shm_buf[lidx] += shm_buf[lidx + i];\n";
3522 0 : ss << " count_buf[lidx] += count_buf[lidx + i];\n";
3523 0 : ss << " }\n";
3524 0 : ss << " barrier(CLK_LOCAL_MEM_FENCE);\n";
3525 0 : ss << " }\n";
3526 0 : ss << " if (lidx == 0)\n";
3527 0 : ss << " {\n";
3528 0 : ss << " current_sum += shm_buf[0];\n";
3529 0 : ss << " current_count += count_buf[0];\n";
3530 0 : ss << " }\n";
3531 : // ss << "if(writePos == 14 && lidx ==0)\n";
3532 : //ss <<"printf(\"\\n********************sum is is %f, count is%d\",current_sum,current_count);\n";
3533 0 : ss << " barrier(CLK_LOCAL_MEM_FENCE);\n";
3534 0 : ss << " }\n";
3535 : }else
3536 : {
3537 0 : ss << " if (lidx == 0)\n";
3538 0 : ss << " {\n";
3539 0 : ss << " tmp0 =";
3540 0 : if(vSubArguments[i]->GetFormulaToken()->GetType() ==
3541 : formula::svSingleVectorRef)
3542 : {
3543 0 : vSubArguments[i]->GenDeclRef(ss);
3544 0 : ss << "[writePos];\n";
3545 : }
3546 : else
3547 : {
3548 0 : vSubArguments[i]->GenDeclRef(ss);
3549 0 : ss <<";\n";
3550 : //ss <<"printf(\"\\n********************tmp0 is %f\",tmp0);\n";
3551 : }
3552 0 : ss << " if(!isNan(tmp0))\n";
3553 0 : ss << " {\n";
3554 0 : ss << " current_sum += log(tmp0);\n";
3555 0 : ss << " current_count++;\n";
3556 0 : ss << " }\n";
3557 0 : ss << " }\n";
3558 : }
3559 : }
3560 :
3561 0 : ss << " if (lidx == 0)\n";
3562 0 : ss << " result[writePos] = exp(current_sum/current_count);\n";
3563 0 : ss << "}\n";
3564 :
3565 0 : ss << "\ndouble " << sSymName;
3566 0 : ss << "_"<< BinFuncName() <<"(";
3567 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
3568 : {
3569 0 : if (i)
3570 0 : ss << ",";
3571 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
3572 : }
3573 0 : ss << ")\n {\n";
3574 0 : ss <<" int gid0=get_global_id(0);\n";
3575 0 : ss << " double tmp =0;\n";
3576 0 : ss << " tmp =";
3577 0 : vSubArguments[0]->GenDeclRef(ss);
3578 0 : ss << "[gid0];\n";
3579 0 : ss << " return tmp;\n";
3580 0 : ss << "}";
3581 0 : }
3582 :
3583 0 : void OpHarMean::GenSlidingWindowFunction(
3584 : std::stringstream &ss, const std::string &sSymName, SubArguments &
3585 : vSubArguments)
3586 : {
3587 :
3588 0 : ss << "\ndouble " << sSymName;
3589 0 : ss << "_"<< BinFuncName() <<"( ";
3590 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
3591 : {
3592 0 : if (i)
3593 0 : ss << ",";
3594 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
3595 : }
3596 0 : ss << ")\n";
3597 0 : ss <<"{\n";
3598 0 : ss << " int gid0 = get_global_id(0);\n";
3599 0 : ss << " double nVal=0.0;\n";
3600 0 : ss << " double tmp = 0;\n";
3601 0 : ss << " int length;\n";
3602 0 : ss << " int totallength=0;\n";
3603 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
3604 : {
3605 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
3606 : assert(pCur);
3607 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
3608 : {
3609 : const formula::DoubleVectorRefToken* pDVR =
3610 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
3611 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
3612 0 : ss << " length="<<nCurWindowSize;
3613 0 : ss << ";\n";
3614 0 : ss << " for (int i = ";
3615 0 : ss << "0; i < "<< nCurWindowSize << "; i++)\n";
3616 0 : ss << " {\n";
3617 0 : ss << " double arg"<<i<<" = ";
3618 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
3619 0 : ss << ";\n";
3620 0 : ss << " if(isNan(arg"<<i<<")||((gid0+i)>=";
3621 0 : ss << pDVR->GetArrayLength();
3622 0 : ss << "))\n";
3623 0 : ss << " {\n";
3624 0 : ss << " length--;\n";
3625 0 : ss << " continue;\n";
3626 0 : ss << " }\n";
3627 0 : ss << " nVal += (1.0 *pow(";
3628 0 : ss << " arg"<<i<<",-1));\n";
3629 0 : ss << " }\n";
3630 0 : ss << " totallength +=length;\n";
3631 : }
3632 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
3633 : {
3634 0 : ss << " tmp = ";
3635 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
3636 0 : ss << ";\n";
3637 0 : ss << " if(!isNan(tmp))\n";
3638 0 : ss << " {\n";
3639 0 : ss << " nVal += (1.0 * pow( tmp,-1));\n";
3640 0 : ss << " totallength +=1;\n";
3641 0 : ss << " }\n";
3642 : }
3643 0 : else if (pCur->GetType() == formula::svDouble)
3644 : {
3645 0 : ss << " tmp = ";
3646 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
3647 0 : ss << ";\n";
3648 0 : ss << " nVal += (1.0 *pow( tmp,-1));\n";
3649 0 : ss << " totallength +=1;\n";
3650 : }
3651 : else
3652 : {
3653 0 : ss << " return DBL_MIN;\n";
3654 : }
3655 : }
3656 0 : ss << " tmp = totallength*pow(nVal,-1);\n";
3657 0 : ss << " return tmp;\n";
3658 0 : ss << "}";
3659 0 : }
3660 :
3661 0 : void OpConfidence::BinInlineFun(std::set<std::string>& decls,
3662 : std::set<std::string>& funs)
3663 : {
3664 0 : decls.insert(gaussinvDecl);
3665 0 : funs.insert(gaussinv);
3666 0 : }
3667 :
3668 0 : void OpConfidence::GenSlidingWindowFunction(std::stringstream& ss,
3669 : const std::string &sSymName, SubArguments& vSubArguments)
3670 : {
3671 0 : ss << "\ndouble " << sSymName;
3672 0 : ss << "_"<< BinFuncName() <<"(";
3673 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
3674 : {
3675 0 : if (i)
3676 0 : ss << ",";
3677 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
3678 : }
3679 0 : ss << ") {\n";
3680 0 : ss << " double tmp = " << GetBottom() <<";\n";
3681 0 : ss << " int gid0 = get_global_id(0);\n";
3682 0 : ss << " double alpha = " << GetBottom() <<";\n";
3683 0 : ss << " double sigma = " << GetBottom() <<";\n";
3684 0 : ss << " double size = " << GetBottom() <<";\n";
3685 0 : ss << " double tmp0,tmp1,tmp2;\n";
3686 0 : size_t i = vSubArguments.size();
3687 0 : ss <<"\n";
3688 0 : for (i = 0; i < vSubArguments.size(); i++)
3689 : {
3690 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
3691 : assert(pCur);
3692 0 : if (pCur->GetType() == formula::svSingleVectorRef)
3693 : {
3694 : const formula::SingleVectorRefToken* pSVR =
3695 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
3696 0 : ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
3697 : }
3698 0 : else if (pCur->GetType() == formula::svDouble)
3699 : {
3700 0 : ss << "{\n";
3701 : }
3702 : else
3703 : {
3704 : }
3705 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
3706 : {
3707 0 : ss << " if (isNan(";
3708 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
3709 0 : ss << "))\n";
3710 0 : ss << " tmp"<<i<<"= 0;\n";
3711 0 : ss << " else\n";
3712 0 : ss << " tmp"<<i<<"=\n";
3713 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
3714 0 : ss << ";\n}\n";
3715 : }
3716 : else
3717 : {
3718 0 : ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
3719 0 : ss <<";\n";
3720 : }
3721 : }
3722 0 : ss << " alpha = tmp0;\n";
3723 0 : ss << " sigma = tmp1;\n";
3724 0 : ss << " size = tmp2;\n";
3725 0 : ss << " double rn = floor(size);\n";
3726 0 : ss << " if(sigma <= 0.0 || alpha <= 0.0 || alpha >= 1.0";
3727 0 : ss << "|| rn < 1.0)\n";
3728 0 : ss << " tmp = -DBL_MAX;\n";
3729 0 : ss << " else\n";
3730 0 : ss << " tmp = gaussinv(1.0 - alpha * pow(2.0,-1.0)) * sigma ";
3731 0 : ss << "* pow(sqrt( rn ),-1);\n";
3732 0 : ss << " return tmp;\n";
3733 0 : ss << "}";
3734 0 : }
3735 :
3736 0 : void OpCritBinom::BinInlineFun(std::set<std::string>& decls,
3737 : std::set<std::string>& funs)
3738 : {
3739 0 : decls.insert(MinDecl);
3740 0 : funs.insert("");
3741 0 : }
3742 :
3743 0 : void OpCritBinom::GenSlidingWindowFunction(std::stringstream& ss,
3744 : const std::string &sSymName, SubArguments& vSubArguments)
3745 : {
3746 0 : ss << "\ndouble " << sSymName;
3747 0 : ss << "_"<< BinFuncName() <<"(";
3748 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
3749 : {
3750 0 : if (i)
3751 0 : ss << ",";
3752 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
3753 : }
3754 0 : ss << ") {\n";
3755 0 : ss << " double tmp = " << GetBottom() <<";\n";
3756 0 : ss << " int gid0 = get_global_id(0);\n";
3757 0 : ss << " double n = " << GetBottom() <<";\n";
3758 0 : ss << " double p = " << GetBottom() <<";\n";
3759 0 : ss << " double alpha = " << GetBottom() <<";\n";
3760 0 : ss << " double tmp0 = 0.0,tmp1 = 0.0,tmp2 = 0.0;\n";
3761 0 : size_t i = vSubArguments.size();
3762 0 : ss <<"\n";
3763 0 : for (i = 0; i < vSubArguments.size(); i++)
3764 : {
3765 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
3766 : assert(pCur);
3767 0 : if (pCur->GetType() == formula::svSingleVectorRef)
3768 : {
3769 : const formula::SingleVectorRefToken* pSVR =
3770 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
3771 0 : ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
3772 : }
3773 0 : else if (pCur->GetType() == formula::svDouble)
3774 : {
3775 0 : ss << "{\n";
3776 : }
3777 : else
3778 : {
3779 : }
3780 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
3781 : {
3782 0 : ss << " if (isNan(";
3783 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
3784 0 : ss << "))\n";
3785 0 : ss << " tmp"<<i<<"= 0;\n";
3786 0 : ss << " else\n";
3787 0 : ss << " tmp"<<i<<"=\n";
3788 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
3789 0 : ss << ";\n}\n";
3790 : }
3791 : else
3792 : {
3793 0 : ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
3794 0 : ss <<";\n";
3795 : }
3796 : }
3797 0 : ss << " n = tmp0;\n";
3798 0 : ss << " p = tmp1;\n";
3799 0 : ss << " alpha = tmp2;\n";
3800 0 : ss << " double rn = floor(n);\n";
3801 0 : ss << " if (rn < 0.0 || alpha <= 0.0 || alpha >= 1.0 || p < 0.0";
3802 0 : ss << " || p > 1.0)\n";
3803 0 : ss << " tmp = -DBL_MIN;\n";
3804 0 : ss << " else\n";
3805 0 : ss << " {\n";
3806 0 : ss << " double rq = (0.5 - p) + 0.5;\n";
3807 0 : ss << " double fFactor = pow(rq, rn);\n";
3808 0 : ss << " if (fFactor <= Min)\n";
3809 0 : ss << " {\n";
3810 0 : ss << " fFactor = pow(p, rn);\n";
3811 0 : ss << " if (fFactor <= Min)\n";
3812 0 : ss << " tmp = -DBL_MAX;\n";
3813 0 : ss << " else\n";
3814 0 : ss << " {\n";
3815 0 : ss << " double fSum = 1.0 - fFactor;\n";
3816 0 : ss << " uint max =(uint)(rn), i;\n";
3817 0 : ss << " for (i = 0; i < max && fSum >= alpha; i++)\n";
3818 0 : ss << " {\n";
3819 0 : ss << " fFactor *= (rn - i) * pow((double)(i + 1),-1.0) *";
3820 0 : ss << " rq * pow(p, -1.0);\n";
3821 0 : ss << " fSum -= fFactor;\n";
3822 0 : ss << " }\n";
3823 0 : ss << " tmp = (rn - i);\n";
3824 0 : ss << " }\n";
3825 0 : ss << " }\n";
3826 0 : ss << " else\n";
3827 0 : ss << " {\n";
3828 0 : ss << " double fSum = fFactor;\n";
3829 0 : ss << " uint max = (uint)(rn), i;\n";
3830 0 : ss << " for (i = 0; i < max && fSum < alpha; i++)\n";
3831 0 : ss << " {\n";
3832 0 : ss << " fFactor *= (rn - i) * pow((double)(i + 1), -1.0) *";
3833 0 : ss << " p * pow(rq, -1.0);\n";
3834 0 : ss << " fSum += fFactor;\n";
3835 0 : ss << " }\n";
3836 0 : ss << " tmp = (i);\n";
3837 0 : ss << " }\n";
3838 0 : ss << " }\n";
3839 0 : ss << " return tmp;\n";
3840 0 : ss << "}";
3841 0 : }
3842 :
3843 0 : void OpRsq::GenSlidingWindowFunction(
3844 : std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
3845 : {
3846 0 : if( vSubArguments.size() !=2 ||vSubArguments[0]->GetFormulaToken()
3847 0 : ->GetType() != formula::svDoubleVectorRef||vSubArguments[1]
3848 0 : ->GetFormulaToken()->GetType() != formula::svDoubleVectorRef )
3849 : ///only support DoubleVector in OpRsq for GPU calculating.
3850 0 : throw Unhandled();
3851 : const formula::DoubleVectorRefToken* pCurDVR1 =
3852 : static_cast<const formula::DoubleVectorRefToken *>(
3853 0 : vSubArguments[0]->GetFormulaToken());
3854 : const formula::DoubleVectorRefToken* pCurDVR2 =
3855 : static_cast<const formula::DoubleVectorRefToken *>(
3856 0 : vSubArguments[1]->GetFormulaToken());
3857 0 : if( pCurDVR1->GetRefRowSize() != pCurDVR2->GetRefRowSize() )
3858 0 : throw Unhandled();
3859 :
3860 0 : size_t nCurWindowSize = pCurDVR1->GetRefRowSize();
3861 :
3862 0 : ss << "\ndouble " << sSymName;
3863 0 : ss << "_"<< BinFuncName() <<"(";
3864 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
3865 : {
3866 0 : if (i)
3867 0 : ss << ",";
3868 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
3869 : }
3870 0 : ss << ")\n";
3871 0 : ss << "{\n";
3872 0 : ss << " int gid0=get_global_id(0);\n";
3873 0 : ss << " double fCount = 0.0;\n";
3874 0 : ss << " double fSumX = 0.0;\n";
3875 0 : ss << " double fSumY = 0.0;\n";
3876 0 : ss << " double fSumDeltaXDeltaY = 0.0;\n";
3877 0 : ss << " double fInx;\n";
3878 0 : ss << " double fIny;\n";
3879 0 : ss << " double tmp0,tmp1;\n";
3880 :
3881 0 : ss <<"\n";
3882 :
3883 0 : ss << " for(int i=0; i<"<<nCurWindowSize<<"; i++)\n";
3884 0 : ss << " {\n";
3885 0 : ss << " if(isNan(";
3886 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef(true);
3887 0 : ss << "))\n";
3888 0 : ss << " fInx = 0;\n";
3889 0 : ss << " else\n";
3890 0 : ss << " fInx = "<<vSubArguments[0]->GenSlidingWindowDeclRef();
3891 0 : ss << ";\n";
3892 0 : ss << " if(isNan(";
3893 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef(true);
3894 0 : ss << "))\n";
3895 0 : ss << " fIny = 0;\n";
3896 0 : ss << " else\n";
3897 0 : ss << " fIny = "<<vSubArguments[1]->GenSlidingWindowDeclRef();
3898 0 : ss << " ;\n";
3899 0 : ss << " fSumX += fInx;\n";
3900 0 : ss << " fSumY += fIny;\n";
3901 0 : ss << " fCount = fCount + 1;\n";
3902 0 : ss << " }\n";
3903 0 : ss << " double fMeanX = fSumX / fCount;\n";
3904 0 : ss << " double fMeanY = fSumY / fCount;\n";
3905 0 : ss << " fSumX = 0.0;\n";
3906 0 : ss << " fSumY = 0.0;\n";
3907 0 : ss << " for(int i=0; i<"<<nCurWindowSize<<"; i++)\n";
3908 0 : ss << " {\n";
3909 0 : ss << " if(isNan(";
3910 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef(true);
3911 0 : ss << "))\n";
3912 0 : ss << " fInx = 0;\n";
3913 0 : ss << " else\n";
3914 0 : ss << " fInx = "<<vSubArguments[0]->GenSlidingWindowDeclRef();
3915 0 : ss << ";\n";
3916 0 : ss << " if(isNan(";
3917 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef();
3918 0 : ss << "))\n";
3919 0 : ss << " fIny = 0;\n";
3920 0 : ss << " else\n";
3921 0 : ss << " fIny = "<<vSubArguments[1]->GenSlidingWindowDeclRef();
3922 0 : ss << " ;\n";
3923 0 : ss << " fSumDeltaXDeltaY += (fInx - fMeanX) * (fIny - fMeanY);\n";
3924 0 : ss << " fSumX += pow(fInx - fMeanX,2);\n";
3925 0 : ss << " fSumY += pow(fIny - fMeanY,2);\n";
3926 0 : ss << " }\n";
3927 0 : ss << " double tmp = pow( fSumDeltaXDeltaY,2) / (fSumX * fSumY);\n";
3928 0 : ss << " return tmp ;\n";
3929 0 : ss << "}\n";
3930 0 : }
3931 :
3932 0 : void OpChiInv::BinInlineFun(std::set<std::string>& decls,
3933 : std::set<std::string>& funs)
3934 : {
3935 0 : decls.insert(fMachEpsDecl);
3936 0 : funs.insert("");
3937 0 : decls.insert(fBigInvDecl);
3938 0 : funs.insert("");
3939 0 : decls.insert(fHalfMachEpsDecl);
3940 0 : funs.insert("");
3941 0 : decls.insert(lcl_IterateInverseChiInvDecl);
3942 0 : funs.insert(lcl_IterateInverseChiInv);
3943 0 : decls.insert(GetChiDistDecl);
3944 0 : funs.insert(GetChiDist);
3945 0 : decls.insert(lcl_HasChangeOfSignDecl);
3946 0 : funs.insert(lcl_HasChangeOfSign);
3947 0 : decls.insert(GetUpRegIGammaDecl);
3948 0 : funs.insert(GetUpRegIGamma);
3949 0 : decls.insert(GetGammaContFractionDecl);
3950 0 : funs.insert(GetGammaContFraction);
3951 0 : decls.insert(GetGammaSeriesDecl);
3952 0 : funs.insert(GetGammaSeries);
3953 0 : }
3954 0 : void OpChiInv::GenSlidingWindowFunction(
3955 : std::stringstream &ss,const std::string &sSymName,
3956 : SubArguments &vSubArguments)
3957 : {
3958 0 : ss << "\ndouble " << sSymName;
3959 0 : ss << "_"<< BinFuncName() <<"(";
3960 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
3961 : {
3962 0 : if (i)
3963 0 : ss << ",";
3964 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
3965 : }
3966 0 : ss << ")\n";
3967 0 : ss << "{\n";
3968 0 : ss << " double tmp0,tmp1,tmp;\n";
3969 0 : ss << " int gid0=get_global_id(0);\n";
3970 0 : size_t i = vSubArguments.size();
3971 0 : ss <<"\n ";
3972 0 : for (i = 0; i < vSubArguments.size(); i++)
3973 : {
3974 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
3975 : assert(pCur);
3976 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
3977 : {
3978 : const formula::DoubleVectorRefToken* pDVR =
3979 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
3980 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
3981 0 : ss << "for (int i = ";
3982 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
3983 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
3984 0 : ss << " && i < " << nCurWindowSize << "; i++){\n";
3985 0 : } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
3986 0 : ss << "0; i < " << pDVR->GetArrayLength();
3987 0 : ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
3988 0 : } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
3989 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
3990 0 : ss << " && i < "<< nCurWindowSize << "; i++){\n";
3991 : }
3992 : else {
3993 0 : ss << "0; i < "<< nCurWindowSize << "; i++){\n";
3994 : }
3995 : }
3996 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
3997 : {
3998 : const formula::SingleVectorRefToken* pSVR =
3999 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
4000 0 : ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
4001 : }
4002 0 : else if (pCur->GetType() == formula::svDouble)
4003 : {
4004 0 : ss << "{\n";
4005 : }
4006 : else
4007 : {
4008 : }
4009 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
4010 : {
4011 0 : ss << "if (isNan(";
4012 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
4013 0 : ss << "))\n";
4014 0 : ss << " tmp"<<i<<"= 0;\n";
4015 0 : ss << "else\n";
4016 0 : ss <<"tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
4017 0 : ss << ";\n}\n";
4018 : }
4019 : else
4020 : {
4021 0 : ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
4022 0 : ss << ";\n";
4023 : }
4024 : }
4025 0 : ss << " tmp1 = floor(tmp1);";
4026 0 : ss << " if (tmp1 < 1.0 || tmp0 <= 0.0 || tmp0 > 1.0 )\n";
4027 0 : ss << " {\n";
4028 0 : ss << " return DBL_MIN;\n";
4029 0 : ss << " }\n";
4030 0 : ss << " bool bConvError;\n";
4031 0 : ss << " double fVal = lcl_IterateInverseChiInv";
4032 0 : ss << "(tmp0, tmp1, tmp1*0.5, tmp1, &bConvError);\n";
4033 0 : ss << " if(bConvError)\n";
4034 0 : ss << " return DBL_MIN;\n";
4035 0 : ss << " return fVal;\n";
4036 0 : ss << "}\n";
4037 0 : }
4038 0 : void OpNormdist::GenSlidingWindowFunction(
4039 : std::stringstream &ss, const std::string &sSymName,
4040 : SubArguments &vSubArguments)
4041 : {
4042 0 : ss << "\ndouble " << sSymName;
4043 0 : ss << "_"<< BinFuncName() <<"(";
4044 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
4045 : {
4046 0 : if (i)
4047 0 : ss << ",";
4048 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
4049 : }
4050 0 : ss << ")\n";
4051 0 : ss << "{\n";
4052 0 : ss << " double x,mue,sigma,c;\n";
4053 0 : ss << " int gid0=get_global_id(0);\n";
4054 0 : ss << " double tmp0,tmp1,tmp2,tmp3;\n";
4055 0 : size_t i = vSubArguments.size();
4056 0 : ss <<"\n ";
4057 0 : for (i = 0; i < vSubArguments.size(); i++)
4058 : {
4059 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
4060 : assert(pCur);
4061 0 : if (pCur->GetType() == formula::svSingleVectorRef)
4062 : {
4063 : const formula::SingleVectorRefToken* pSVR =
4064 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
4065 0 : ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
4066 : }
4067 0 : else if (pCur->GetType() == formula::svDouble)
4068 : {
4069 0 : ss << "{\n";
4070 : }
4071 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
4072 : {
4073 0 : ss << " if (isNan(";
4074 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
4075 0 : ss << "))\n";
4076 0 : ss << " tmp"<<i<<"= 0;\n";
4077 0 : ss << " else\n";
4078 0 : ss << " tmp"<<i<<"=\n";
4079 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
4080 0 : ss << ";\n}\n";
4081 : }
4082 : else
4083 : {
4084 0 : ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
4085 0 : ss <<";\n";
4086 : }
4087 : }
4088 0 : ss << "x = tmp0;\n";
4089 0 : ss << "mue = tmp1;\n";
4090 0 : ss << "sigma = tmp2;\n";
4091 0 : ss << "c = tmp3;\n";
4092 0 : ss << "double mid,tmp;\n";
4093 0 : ss << "mid = (x - mue)/sigma;\n";
4094 0 : ss << "if(c)\n";
4095 0 : ss << " tmp = 0.5 *erfc(-mid * 0.7071067811865475);\n";
4096 0 : ss << "else \n";
4097 0 : ss <<" tmp=(0.39894228040143268*exp(-pow(mid,2)/2.0))/sigma;\n";
4098 0 : ss << "return tmp;\n";
4099 0 : ss << "}\n";
4100 0 : }
4101 0 : void OpNormsdist::BinInlineFun(std::set<std::string>& decls,
4102 : std::set<std::string>& funs)
4103 : {
4104 0 : decls.insert(lcl_Erfc0600Decl);
4105 0 : funs.insert(lcl_Erfc0600);
4106 0 : decls.insert(lcl_Erfc2654Decl);
4107 0 : funs.insert(lcl_Erfc2654);
4108 0 : decls.insert(lcl_Erf0065Decl);
4109 0 : funs.insert(lcl_Erf0065);
4110 0 : decls.insert(rtl_math_erf_rdDecl);
4111 0 : funs.insert(rtl_math_erf_rd);
4112 0 : decls.insert(rtl_math_erfc_rdDecl);
4113 0 : funs.insert(rtl_math_erfc_rd);
4114 0 : }
4115 :
4116 0 : void OpNormsdist::GenSlidingWindowFunction(
4117 : std::stringstream &ss,const std::string &sSymName,
4118 : SubArguments &vSubArguments)
4119 : {
4120 0 : ss << "\ndouble " << sSymName;
4121 0 : ss << "_"<< BinFuncName() <<"(";
4122 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
4123 : {
4124 0 : if (i)
4125 0 : ss << ",";
4126 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
4127 : }
4128 0 : ss << ")\n";
4129 0 : ss << "{\n";
4130 0 : ss << " double x = 0,tmp0 = 0;\n";
4131 0 : ss << " int gid0=get_global_id(0);\n";
4132 0 : size_t i = vSubArguments.size();
4133 0 : ss <<"\n ";
4134 0 : for (i = 0; i < vSubArguments.size(); i++)
4135 : {
4136 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
4137 : assert(pCur);
4138 0 : if (pCur->GetType() == formula::svSingleVectorRef)
4139 : {
4140 : const formula::SingleVectorRefToken* pSVR =
4141 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
4142 0 : ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
4143 : }
4144 0 : else if (pCur->GetType() == formula::svDouble)
4145 : {
4146 0 : ss << "{\n";
4147 : }
4148 : else
4149 : {
4150 : }
4151 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
4152 : {
4153 0 : ss << " if (isNan(";
4154 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
4155 0 : ss << "))\n";
4156 0 : ss << " tmp"<<i<<"= 0;\n";
4157 0 : ss << " else\n";
4158 0 : ss << " tmp"<<i<<"=\n";
4159 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
4160 0 : ss << ";\n}\n";
4161 : }
4162 : else
4163 : {
4164 0 : ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
4165 0 : ss <<";\n";
4166 : }
4167 : }
4168 0 : ss << " x = tmp0;\n";
4169 0 : ss << " double tmp = 0.5 * rtl_math_erfc_rd((-1)*x * 0.7071067811865475);\n";
4170 0 : ss << " return tmp;\n";
4171 0 : ss << "}\n";
4172 0 : }
4173 :
4174 0 : void OpPermut::GenSlidingWindowFunction(
4175 : std::stringstream &ss,const std::string &sSymName,
4176 : SubArguments &vSubArguments)
4177 : {
4178 0 : ss << "\ndouble " << sSymName;
4179 0 : ss << "_"<< BinFuncName() <<"(";
4180 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
4181 : {
4182 0 : if (i)
4183 0 : ss << ",";
4184 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
4185 : }
4186 0 : ss << ") {\n";
4187 0 : ss <<" int gid0=get_global_id(0);\n";
4188 0 : ss <<" double inA;\n";
4189 0 : ss <<" double inB;\n";
4190 0 : ss <<" double tmp0,tmp1;\n";
4191 0 : ss <<" double tmp = 1 ;\n";
4192 0 : size_t i = vSubArguments.size();
4193 0 : ss <<"\n";
4194 0 : for (i = 0; i < vSubArguments.size(); i++)
4195 : {
4196 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
4197 : assert(pCur);
4198 0 : if (pCur->GetType() == formula::svSingleVectorRef)
4199 : {
4200 : const formula::SingleVectorRefToken* pSVR =
4201 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
4202 0 : ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
4203 :
4204 : }
4205 0 : else if (pCur->GetType() == formula::svDouble)
4206 : {
4207 0 : ss << "{\n";
4208 : }
4209 : else
4210 : {
4211 : }
4212 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
4213 : {
4214 0 : ss << " if (isNan(";
4215 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
4216 0 : ss << "))\n";
4217 0 : ss << " tmp"<<i<<"= 0;\n";
4218 0 : ss << " else\n";
4219 0 : ss << " tmp"<<i<<"=\n";
4220 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
4221 0 : ss << ";\n}\n";
4222 : }
4223 : else
4224 : {
4225 0 : ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
4226 0 : ss <<";\n";
4227 : }
4228 : }
4229 0 : ss << " inA = tmp0;\n";
4230 0 : ss << " inB = tmp1;\n";
4231 0 : ss << " for( int i =0; i<inB; i++)\n";
4232 0 : ss << " {\n";
4233 0 : ss << " tmp *= inA ;\n";
4234 0 : ss << " inA = inA - 1.0;\n";
4235 0 : ss << " }\n";
4236 0 : ss << " return tmp;\n";
4237 0 : ss << "}\n";
4238 0 : }
4239 0 : void OpPermutationA::GenSlidingWindowFunction(
4240 : std::stringstream &ss,const std::string &sSymName,
4241 : SubArguments &vSubArguments)
4242 : {
4243 0 : ss << "\ndouble " << sSymName;
4244 0 : ss << "_"<< BinFuncName() <<"(";
4245 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
4246 : {
4247 0 : if (i)
4248 0 : ss << ",";
4249 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
4250 : }
4251 0 : ss << ") {\n";
4252 0 : ss <<" int gid0=get_global_id(0);\n";
4253 0 : ss <<" double inA;\n";
4254 0 : ss <<" double inB;\n";
4255 0 : ss <<" double tmp = 1.0;\n";
4256 0 : FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
4257 : const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
4258 0 : formula::SingleVectorRefToken *>(tmpCur0);
4259 0 : FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
4260 : const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
4261 0 : formula::SingleVectorRefToken *>(tmpCur1);
4262 0 : ss << "int buffer_fIna_len = ";
4263 0 : ss << tmpCurDVR0->GetArrayLength();
4264 0 : ss << ";\n";
4265 0 : ss << " int buffer_fInb_len = ";
4266 0 : ss << tmpCurDVR1->GetArrayLength();
4267 0 : ss << ";\n";
4268 0 : ss << " if((gid0)>=buffer_fIna_len || isNan(";
4269 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
4270 0 : ss << "))\n";
4271 0 : ss << " inA = 0;\nelse \n";
4272 0 : ss << " inA = "<<vSubArguments[0]->GenSlidingWindowDeclRef();
4273 0 : ss << ";\n";
4274 0 : ss << "if((gid0)>=buffer_fInb_len || isNan(";
4275 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef();
4276 0 : ss << "))\n";
4277 0 : ss << "inB = 0;\nelse \n";
4278 0 : ss << " inB = "<<vSubArguments[1]->GenSlidingWindowDeclRef();
4279 0 : ss << ";\n";
4280 0 : ss << " for(int i=0; i<inB; i++)\n";
4281 0 : ss << " {\n";
4282 0 : ss << " tmp *= inA;\n";
4283 0 : ss << " }\n";
4284 0 : ss << " return tmp;\n";
4285 0 : ss << "}\n";
4286 0 : }
4287 :
4288 0 : void OpPhi::GenSlidingWindowFunction(
4289 : std::stringstream &ss,const std::string &sSymName,
4290 : SubArguments &vSubArguments)
4291 : {
4292 0 : ss << "\ndouble " << sSymName;
4293 0 : ss << "_"<< BinFuncName() <<"(";
4294 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
4295 : {
4296 0 : if (i)
4297 0 : ss << ",";
4298 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
4299 : }
4300 0 : ss << ")\n";
4301 0 : ss << "{\n";
4302 0 : ss << " double x,tmp0;\n";
4303 0 : ss << " int gid0=get_global_id(0);\n";
4304 0 : size_t i = vSubArguments.size();
4305 0 : ss <<"\n";
4306 0 : for (i = 0; i < vSubArguments.size(); i++)
4307 : {
4308 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
4309 : assert(pCur);
4310 0 : if (pCur->GetType() == formula::svSingleVectorRef)
4311 : {
4312 : const formula::SingleVectorRefToken* pSVR =
4313 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
4314 0 : ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
4315 : }
4316 0 : else if (pCur->GetType() == formula::svDouble)
4317 : {
4318 0 : ss << "{\n";
4319 : }
4320 : else
4321 : {
4322 : }
4323 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
4324 : {
4325 0 : ss << " if (isNan(";
4326 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
4327 0 : ss << "))\n";
4328 0 : ss << " tmp"<<i<<"= 0;\n";
4329 0 : ss << " else\n";
4330 0 : ss << " tmp"<<i<<"=\n";
4331 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
4332 0 : ss << ";\n}\n";
4333 : }
4334 : else
4335 : {
4336 0 : ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
4337 0 : ss <<";\n";
4338 : }
4339 : }
4340 0 : ss << " x = tmp0;\n";
4341 0 : ss << " double tmp = 0.39894228040143268 * exp((-1)*pow(x,2) / 2.0);\n";
4342 0 : ss << " return tmp;\n";
4343 0 : ss << "}\n";
4344 0 : }
4345 :
4346 0 : void OpNorminv::GenSlidingWindowFunction(
4347 : std::stringstream &ss,const std::string &sSymName,
4348 : SubArguments &vSubArguments)
4349 : {
4350 0 : ss << "\ndouble " << sSymName;
4351 0 : ss << "_"<< BinFuncName() <<"(";
4352 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
4353 : {
4354 0 : if (i)
4355 0 : ss << ",";
4356 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
4357 : }
4358 0 : ss << ")\n";
4359 0 : ss << "{\n";
4360 0 : ss <<" double q,t,z;\n";
4361 0 : ss <<" double x,mue,sigma;\n";
4362 0 : ss <<" double tmp0,tmp1,tmp2;\n";
4363 0 : ss <<" int gid0=get_global_id(0);\n";
4364 0 : size_t i = vSubArguments.size();
4365 0 : ss <<"\n";
4366 0 : for (i = 0; i < vSubArguments.size(); i++)
4367 : {
4368 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
4369 : assert(pCur);
4370 0 : if (pCur->GetType() == formula::svSingleVectorRef)
4371 : {
4372 : const formula::SingleVectorRefToken* pSVR =
4373 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
4374 0 : ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
4375 : }
4376 0 : else if (pCur->GetType() == formula::svDouble)
4377 : {
4378 0 : ss << "{\n";
4379 : }
4380 : else
4381 : {
4382 : }
4383 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
4384 : {
4385 0 : ss << " if (isNan(";
4386 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
4387 0 : ss << "))\n";
4388 0 : ss << " tmp"<<i<<"= 0;\n";
4389 0 : ss << " else\n";
4390 0 : ss << " tmp"<<i<<"=\n";
4391 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
4392 0 : ss << ";\n}\n";
4393 : }
4394 : else
4395 : {
4396 0 : ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
4397 0 : ss <<";\n";
4398 : }
4399 : }
4400 0 : ss <<" x = tmp0;\n";
4401 0 : ss <<" mue = tmp1;\n";
4402 0 : ss <<" sigma = tmp2;\n";
4403 0 : ss <<" q = x -0.5;\n";
4404 0 : ss <<" if(fabs(q)<=.425)\n";
4405 0 : ss <<" {\n";
4406 0 : ss <<" t=0.180625-pow(q,2);\n";
4407 : ss <<" z=\n"
4408 : "q*\n"
4409 : "(\n"
4410 : "(\n"
4411 : "(\n"
4412 : "(\n"
4413 : "(\n"
4414 : "(\n"
4415 : "(\n"
4416 0 : "t*2509.0809287301226727";
4417 : ss <<"+33430.575583588128105\n"
4418 : ")\n"
4419 : "*t+67265.770927008700853\n"
4420 : ")\n"
4421 : "*t+45921.953931549871457\n"
4422 : ")\n"
4423 : "*t+13731.693765509461125\n"
4424 : ")\n"
4425 : "*t+1971.5909503065514427\n"
4426 : ")\n"
4427 : "*t+133.14166789178437745\n"
4428 : ")\n"
4429 : "*t+3.387132872796366608\n"
4430 : ")\n"
4431 : "/\n"
4432 : "(\n"
4433 : "(\n"
4434 : "(\n"
4435 : "(\n"
4436 : "(\n"
4437 : "(\n"
4438 : "(\n"
4439 0 : "t*5226.495278852854561";
4440 : ss <<"+28729.085735721942674\n"
4441 : ")\n"
4442 : "*t+39307.89580009271061\n"
4443 : ")\n"
4444 : "*t+21213.794301586595867\n"
4445 : ")\n"
4446 : "*t+5394.1960214247511077\n"
4447 : ")\n"
4448 : "*t+687.1870074920579083\n"
4449 : ")\n"
4450 : "*t+42.313330701600911252\n"
4451 : ")\n"
4452 : "*t+1.0\n"
4453 0 : ");\n";
4454 0 : ss <<"}\nelse\n{\n";
4455 0 : ss <<" if(q>0)\nt=1-x;\n";
4456 0 : ss <<"else\nt=x;\n";
4457 0 : ss <<"t=sqrt(-log(t));\n";
4458 0 : ss <<"if(t<=5.0)\n{\n";
4459 0 : ss <<"t+=-1.6;\n";
4460 : ss <<"z=\n"
4461 : "(\n"
4462 : "(\n"
4463 : "(\n"
4464 : "(\n"
4465 : "(\n"
4466 : "(\n"
4467 : "(\n"
4468 0 : "t*7.7454501427834140764e-4";
4469 : ss <<"+0.0227238449892691845833\n"
4470 : ")\n"
4471 : "*t+0.24178072517745061177\n"
4472 : ")\n"
4473 : "*t+1.27045825245236838258\n"
4474 : ")\n"
4475 : "*t+3.64784832476320460504\n"
4476 : ")\n"
4477 : "*t+5.7694972214606914055\n"
4478 : ")\n"
4479 : "*t+4.6303378461565452959\n"
4480 : ")\n"
4481 : "*t+1.42343711074968357734\n"
4482 : ")\n"
4483 : "/\n"
4484 : "(\n"
4485 : "(\n"
4486 : "(\n"
4487 : "(\n"
4488 : "(\n"
4489 : "(\n"
4490 : "(\n"
4491 0 : "t*1.05075007164441684324e-9";
4492 : ss <<"+5.475938084995344946e-4\n"
4493 : ")\n"
4494 : "*t+0.0151986665636164571966\n"
4495 : ")\n"
4496 : "*t+0.14810397642748007459\n"
4497 : ")\n"
4498 : "*t+0.68976733498510000455\n"
4499 : ")\n"
4500 : "*t+1.6763848301838038494\n"
4501 : ")\n"
4502 : "*t+2.05319162663775882187\n"
4503 : ")\n"
4504 : "*t+1.0\n"
4505 0 : ");\n}\n";
4506 0 : ss <<"else\n{\n";
4507 0 : ss <<"t+=-5.0;\n";
4508 : ss <<"z=\n"
4509 : "(\n"
4510 : "(\n"
4511 : "(\n"
4512 : "(\n"
4513 : "(\n"
4514 : "(\n"
4515 : "(\n"
4516 0 : "t*2.01033439929228813265e-7";
4517 : ss<<"+2.71155556874348757815e-5\n"
4518 : ")\n"
4519 : "*t+0.0012426609473880784386\n"
4520 : ")\n"
4521 : "*t+0.026532189526576123093\n"
4522 : ")\n"
4523 : "*t+0.29656057182850489123\n"
4524 : ")\n"
4525 : "*t+1.7848265399172913358\n"
4526 : ")\n"
4527 : "*t+5.4637849111641143699\n"
4528 : ")\n"
4529 : "*t+6.6579046435011037772\n"
4530 : ")\n"
4531 : "/\n"
4532 : "(\n"
4533 : "(\n"
4534 : "(\n"
4535 : "(\n"
4536 : "(\n"
4537 : "(\n"
4538 : "(\n"
4539 : "t*2.04426310338993978564e-15"
4540 : "+1.4215117583164458887e-7\n"
4541 : ")\n"
4542 : "*t+1.8463183175100546818e-5\n"
4543 : ")\n"
4544 : "*t+7.868691311456132591e-4\n"
4545 : ")\n"
4546 : "*t+0.0148753612908506148525\n"
4547 : ")\n"
4548 : "*t+0.13692988092273580531\n"
4549 : ")\n"
4550 : "*t+0.59983220655588793769\n"
4551 : ")\n"
4552 : "*t+1.0\n"
4553 0 : ");\n";
4554 0 : ss<<"}\n";
4555 0 : ss << "z = q < 0.0 ? (-1)*z : z;\n";
4556 0 : ss<<"}\n";
4557 0 : ss<<"double tmp = z*sigma + mue;\n";
4558 0 : ss<<"return tmp;\n";
4559 0 : ss<<"}\n";
4560 0 : }
4561 0 : void OpNormsinv:: GenSlidingWindowFunction
4562 : (std::stringstream &ss,const std::string &sSymName,
4563 : SubArguments &vSubArguments)
4564 : {
4565 0 : ss << "\ndouble " << sSymName;
4566 0 : ss << "_"<< BinFuncName() <<"(";
4567 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
4568 : {
4569 0 : if (i)
4570 0 : ss << ",";
4571 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
4572 : }
4573 0 : ss << ")\n";
4574 0 : ss << "{\n";
4575 0 : ss << " double q,t,z,x,tmp0;\n";
4576 0 : ss << " int gid0=get_global_id(0);\n";
4577 0 : size_t i = vSubArguments.size();
4578 0 : ss <<"\n";
4579 0 : for (i = 0; i < vSubArguments.size(); i++)
4580 : {
4581 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
4582 : assert(pCur);
4583 0 : if (pCur->GetType() == formula::svSingleVectorRef)
4584 : {
4585 : const formula::SingleVectorRefToken* pSVR =
4586 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
4587 0 : ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
4588 : }
4589 0 : else if (pCur->GetType() == formula::svDouble)
4590 : {
4591 0 : ss << "{\n";
4592 : }
4593 : else
4594 : {
4595 : }
4596 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
4597 : {
4598 0 : ss << " if (isNan(";
4599 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
4600 0 : ss << "))\n";
4601 0 : ss << " tmp"<<i<<"= 0;\n";
4602 0 : ss << " else\n";
4603 0 : ss << " tmp"<<i<<"=\n";
4604 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
4605 0 : ss << ";\n}\n";
4606 : }
4607 : else
4608 : {
4609 0 : ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
4610 0 : ss <<";\n";
4611 : }
4612 : }
4613 0 : ss <<" x = tmp0;\n";
4614 0 : ss <<" q = x -0.5;\n";
4615 0 : ss <<" if(fabs(q)<=.425)\n";
4616 0 : ss <<" {\n";
4617 0 : ss <<" t=0.180625-pow(q,2);\n";
4618 : ss <<" z=\n"
4619 : "q*\n"
4620 : "(\n"
4621 : "(\n"
4622 : "(\n"
4623 : "(\n"
4624 : "(\n"
4625 : "(\n"
4626 : "(\n"
4627 0 : "t*2509.0809287301226727";
4628 : ss <<"+33430.575583588128105\n"
4629 : ")\n"
4630 : "*t+67265.770927008700853\n"
4631 : ")\n"
4632 : "*t+45921.953931549871457\n"
4633 : ")\n"
4634 : "*t+13731.693765509461125\n"
4635 : ")\n"
4636 : "*t+1971.5909503065514427\n"
4637 : ")\n"
4638 : "*t+133.14166789178437745\n"
4639 : ")\n"
4640 : "*t+3.387132872796366608\n"
4641 : ")\n"
4642 : "/\n"
4643 : "(\n"
4644 : "(\n"
4645 : "(\n"
4646 : "(\n"
4647 : "(\n"
4648 : "(\n"
4649 : "(\n"
4650 0 : "t*5226.495278852854561";
4651 : ss <<"+28729.085735721942674\n"
4652 : ")\n"
4653 : "*t+39307.89580009271061\n"
4654 : ")\n"
4655 : "*t+21213.794301586595867\n"
4656 : ")\n"
4657 : "*t+5394.1960214247511077\n"
4658 : ")\n"
4659 : "*t+687.1870074920579083\n"
4660 : ")\n"
4661 : "*t+42.313330701600911252\n"
4662 : ")\n"
4663 : "*t+1.0\n"
4664 0 : ");\n";
4665 0 : ss <<"}\nelse\n{\n";
4666 0 : ss <<" if(q>0)\nt=1-x;\n";
4667 0 : ss <<"else\nt=x;\n";
4668 0 : ss <<"t=sqrt(-log(t));\n";
4669 0 : ss <<"if(t<=5.0)\n{\n";
4670 0 : ss <<"t+=-1.6;\n";
4671 : ss <<"z=\n"
4672 : "(\n"
4673 : "(\n"
4674 : "(\n"
4675 : "(\n"
4676 : "(\n"
4677 : "(\n"
4678 : "(\n"
4679 0 : "t*7.7454501427834140764e-4";
4680 : ss <<"+0.0227238449892691845833\n"
4681 : ")\n"
4682 : "*t+0.24178072517745061177\n"
4683 : ")\n"
4684 : "*t+1.27045825245236838258\n"
4685 : ")\n"
4686 : "*t+3.64784832476320460504\n"
4687 : ")\n"
4688 : "*t+5.7694972214606914055\n"
4689 : ")\n"
4690 : "*t+4.6303378461565452959\n"
4691 : ")\n"
4692 : "*t+1.42343711074968357734\n"
4693 : ")\n"
4694 : "/\n"
4695 : "(\n"
4696 : "(\n"
4697 : "(\n"
4698 : "(\n"
4699 : "(\n"
4700 : "(\n"
4701 : "(\n"
4702 0 : "t*1.05075007164441684324e-9";
4703 : ss <<"+5.475938084995344946e-4\n"
4704 : ")\n"
4705 : "*t+0.0151986665636164571966\n"
4706 : ")\n"
4707 : "*t+0.14810397642748007459\n"
4708 : ")\n"
4709 : "*t+0.68976733498510000455\n"
4710 : ")\n"
4711 : "*t+1.6763848301838038494\n"
4712 : ")\n"
4713 : "*t+2.05319162663775882187\n"
4714 : ")\n"
4715 : "*t+1.0\n"
4716 0 : ");\n}\n";
4717 0 : ss <<"else\n{\n";
4718 0 : ss <<"t+=-5.0;\n";
4719 : ss <<"z=\n"
4720 : "(\n"
4721 : "(\n"
4722 : "(\n"
4723 : "(\n"
4724 : "(\n"
4725 : "(\n"
4726 : "(\n"
4727 0 : "t*2.01033439929228813265e-7";
4728 : ss <<"+2.71155556874348757815e-5\n"
4729 : ")\n"
4730 : "*t+0.0012426609473880784386\n"
4731 : ")\n"
4732 : "*t+0.026532189526576123093\n"
4733 : ")\n"
4734 : "*t+0.29656057182850489123\n"
4735 : ")\n"
4736 : "*t+1.7848265399172913358\n"
4737 : ")\n"
4738 : "*t+5.4637849111641143699\n"
4739 : ")\n"
4740 : "*t+6.6579046435011037772\n"
4741 : ")\n"
4742 : "/\n"
4743 : "(\n"
4744 : "(\n"
4745 : "(\n"
4746 : "(\n"
4747 : "(\n"
4748 : "(\n"
4749 : "(\n"
4750 : "t*2.04426310338993978564e-15"
4751 : "+1.4215117583164458887e-7\n"
4752 : ")\n"
4753 : "*t+1.8463183175100546818e-5\n"
4754 : ")\n"
4755 : "*t+7.868691311456132591e-4\n"
4756 : ")\n"
4757 : "*t+0.0148753612908506148525\n"
4758 : ")\n"
4759 : "*t+0.13692988092273580531\n"
4760 : ")\n"
4761 : "*t+0.59983220655588793769\n"
4762 : ")\n"
4763 : "*t+1.0\n"
4764 0 : ");\n";
4765 0 : ss <<"}\n";
4766 0 : ss << "z = q < 0.0 ? (-1)*z : z;\n";
4767 0 : ss <<"}\n";
4768 0 : ss <<"if (isnan(z))\n";
4769 0 : ss <<" return CreateDoubleError(errNoValue);\n";
4770 0 : ss <<"return z;\n";
4771 0 : ss <<"}\n";
4772 0 : }
4773 0 : void OpMedian::GenSlidingWindowFunction(
4774 : std::stringstream &ss, const std::string &sSymName,
4775 : SubArguments &vSubArguments)
4776 : {
4777 0 : ss << "\ndouble " << sSymName;
4778 0 : ss << "_"<< BinFuncName() <<"(";
4779 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
4780 : {
4781 0 : if (i)
4782 0 : ss << ",";
4783 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
4784 : }
4785 0 : ss << ") {\n";
4786 0 : ss << " int gid0 = get_global_id(0);\n";
4787 0 : ss << " double tmp = 0;\n";
4788 0 : ss << " int i;\n";
4789 0 : ss << " unsigned int startFlag = 0;\n";
4790 0 : ss << " unsigned int endFlag = 0;\n";
4791 0 : ss << " double dataIna;\n";
4792 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
4793 : {
4794 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
4795 : assert(pCur);
4796 0 : if (const formula::DoubleVectorRefToken* pCurDVR =
4797 0 : dynamic_cast<const formula::DoubleVectorRefToken *>(pCur))
4798 : {
4799 0 : size_t nCurWindowSize = pCurDVR->GetRefRowSize();
4800 0 : ss << "startFlag = ";
4801 0 : if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed())
4802 : {
4803 0 : ss << "gid0; endFlag = "<< nCurWindowSize <<"-gid0;\n";
4804 : }
4805 0 : ss << "gid0; endFlag = gid0+"<< nCurWindowSize <<";\n";
4806 : }
4807 : else
4808 : {
4809 0 : ss<<"startFlag=gid0;endFlag=gid0;\n";
4810 : }
4811 : }
4812 0 : FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
4813 : const formula::DoubleVectorRefToken*tmpCurDVR0= static_cast<const
4814 0 : formula::DoubleVectorRefToken *>(tmpCur0);
4815 0 : ss << "int buffer_fIna_len = ";
4816 0 : ss << tmpCurDVR0->GetArrayLength();
4817 0 : ss << ";\n";
4818 0 : ss<<"if((i+gid0)>=buffer_fIna_len || isNan(";
4819 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
4820 0 : ss<<"))\n";
4821 0 : ss<<" dataIna = 0;\n";
4822 0 : ss << " int nSize =endFlag- startFlag ;\n";
4823 0 : ss << " if (nSize & 1)\n";
4824 0 : ss << " {\n";
4825 0 : ss << " tmp = "<<vSubArguments[0]->GetName();
4826 0 : ss << " [startFlag+nSize/2];\n";
4827 0 : ss << " }\n";
4828 0 : ss << " else\n";
4829 0 : ss << " {\n";
4830 0 : ss << " tmp =("<<vSubArguments[0]->GetName();
4831 0 : ss << " [startFlag+nSize/2]+";
4832 0 : ss << vSubArguments[0]->GetName();
4833 0 : ss << " [startFlag+nSize/2-1])/2;\n";
4834 0 : ss << " }\n";
4835 0 : ss <<" return tmp;\n";
4836 0 : ss << "}\n";
4837 0 : }
4838 0 : void OpKurt:: GenSlidingWindowFunction(std::stringstream &ss,
4839 : const std::string &sSymName, SubArguments &vSubArguments)
4840 : {
4841 0 : ss << "\ndouble " << sSymName;
4842 0 : ss << "_"<< BinFuncName() <<"( ";
4843 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
4844 : {
4845 0 : if (i)
4846 0 : ss << ",";
4847 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
4848 : }
4849 0 : ss << ")\n";
4850 0 : ss <<"{\n";
4851 0 : ss << " int gid0 = get_global_id(0);\n";
4852 0 : ss << " double fSum = 0.0;\n";
4853 0 : ss << " double vSum = 0.0;\n";
4854 0 : ss << " double length;\n";
4855 0 : ss << " double totallength=0;\n";
4856 0 : ss << " double tmp = 0;\n";
4857 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
4858 : {
4859 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
4860 : assert(pCur);
4861 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
4862 : {
4863 : const formula::DoubleVectorRefToken* pDVR =
4864 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
4865 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
4866 0 : ss << " length="<<nCurWindowSize;
4867 0 : ss << ";\n";
4868 0 : ss << " for (int i = ";
4869 0 : ss << "0; i < "<< nCurWindowSize << "; i++)\n";
4870 0 : ss << " {\n";
4871 0 : ss << " double arg"<<i<<" = ";
4872 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef(true);
4873 0 : ss << ";\n";
4874 0 : ss << " if(isNan(arg"<<i<<")||((gid0+i)>=";
4875 0 : ss << pDVR->GetArrayLength();
4876 0 : ss << "))\n";
4877 0 : ss << " {\n";
4878 0 : ss << " length-=1.0;\n";
4879 0 : ss << " continue;\n";
4880 0 : ss << " }\n";
4881 0 : ss << " fSum += arg"<<i<<";\n";
4882 0 : ss << " }\n";
4883 0 : ss << " totallength +=length;\n";
4884 : }
4885 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
4886 : {
4887 0 : ss << " tmp = ";
4888 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
4889 0 : ss << ";\n";
4890 0 : ss << " if(!isNan(tmp))\n";
4891 0 : ss << " {\n";
4892 0 : ss << " fSum += tmp;\n";
4893 0 : ss << " totallength +=1;\n";
4894 0 : ss << " }\n";
4895 : }
4896 0 : else if (pCur->GetType() == formula::svDouble)
4897 : {
4898 0 : ss << " tmp = ";
4899 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
4900 0 : ss << ";\n";
4901 0 : ss << " fSum += tmp;\n";
4902 0 : ss << " totallength +=1;\n";
4903 : }
4904 : else
4905 : {
4906 0 : ss << " return DBL_MIN;\n";
4907 : }
4908 : }
4909 0 : ss << " double fMean = fSum * pow(totallength,-1);\n";
4910 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
4911 : {
4912 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
4913 : assert(pCur);
4914 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
4915 : {
4916 : const formula::DoubleVectorRefToken* pDVR =
4917 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
4918 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
4919 0 : ss << " for (int i = ";
4920 0 : ss << "0; i < "<< nCurWindowSize << "; i++)\n";
4921 0 : ss << " {\n";
4922 0 : ss << " double arg"<<i<<" = ";
4923 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef(true);
4924 0 : ss << ";\n";
4925 0 : ss << " if(isNan(arg"<<i<<")||((gid0+i)>=";
4926 0 : ss << pDVR->GetArrayLength();
4927 0 : ss << "))\n";
4928 0 : ss << " {\n";
4929 0 : ss << " continue;\n";
4930 0 : ss << " }\n";
4931 0 : ss << " vSum += (arg"<<i<<"-fMean)*(arg"<<i<<"-fMean);\n";
4932 0 : ss << " }\n";
4933 : }
4934 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
4935 : {
4936 0 : ss << " tmp = ";
4937 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
4938 0 : ss << ";\n";
4939 0 : ss << " if(!isNan(tmp))\n";
4940 0 : ss << " {\n";
4941 0 : ss << " vSum += (tmp-fMean)*(tmp-fMean);\n";
4942 0 : ss << " }\n";
4943 : }
4944 0 : else if (pCur->GetType() == formula::svDouble)
4945 : {
4946 0 : ss << " tmp = ";
4947 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
4948 0 : ss << ";\n";
4949 0 : ss << " vSum += (tmp-fMean)*(tmp-fMean);\n";
4950 : }
4951 : }
4952 0 : ss << " double fStdDev = sqrt(vSum / (totallength - 1.0));\n";
4953 0 : ss << " double dx = 0.0;\n";
4954 0 : ss << " double xpower4 = 0.0;\n";
4955 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
4956 : {
4957 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
4958 : assert(pCur);
4959 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
4960 : {
4961 : const formula::DoubleVectorRefToken* pDVR =
4962 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
4963 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
4964 0 : ss << " for (int i = ";
4965 0 : ss << "0; i < "<< nCurWindowSize << "; i++)\n";
4966 0 : ss << " {\n";
4967 0 : ss << " double arg"<<i<<" = ";
4968 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef(true);
4969 0 : ss << ";\n";
4970 0 : ss << " if(isNan(arg"<<i<<")||((gid0+i)>=";
4971 0 : ss << pDVR->GetArrayLength();
4972 0 : ss << "))\n";
4973 0 : ss << " {\n";
4974 0 : ss << " continue;\n";
4975 0 : ss << " }\n";
4976 0 : ss<< " dx = (arg"<<i<<" -fMean) / fStdDev;\n";
4977 0 : ss<< " xpower4 = xpower4 + (dx * dx * dx * dx);\n";
4978 0 : ss << " }\n";
4979 : }
4980 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
4981 : {
4982 0 : ss << " tmp = ";
4983 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
4984 0 : ss << ";\n";
4985 0 : ss << " if(!isNan(tmp))\n";
4986 0 : ss << " {\n";
4987 0 : ss<< " dx = (tmp -fMean) / fStdDev;\n";
4988 0 : ss<< " xpower4 = xpower4 + (dx * dx * dx * dx);\n";
4989 0 : ss << " }\n";
4990 : }
4991 0 : else if (pCur->GetType() == formula::svDouble)
4992 : {
4993 0 : ss << " tmp = ";
4994 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
4995 0 : ss << ";\n";
4996 0 : ss<< " dx = (tmp -fMean) / fStdDev;\n";
4997 0 : ss<< " xpower4 = xpower4 + (dx * dx * dx * dx);\n";
4998 : }
4999 : }
5000 0 : ss<< " double k_d = (totallength - 2.0) * (totallength - 3.0);\n";
5001 0 : ss<< " double k_l = totallength * (totallength + 1.0) /";
5002 0 : ss<< "((totallength - 1.0) * k_d);\n";
5003 0 : ss<< " double k_t = 3.0 * (totallength - 1.0) * ";
5004 0 : ss<< "(totallength - 1.0) / k_d;\n";
5005 0 : ss<< " tmp = xpower4 * k_l - k_t;\n";
5006 0 : ss<< " return tmp;\n";
5007 0 : ss << "}";
5008 0 : }
5009 :
5010 0 : void OpIntercept::GenSlidingWindowFunction(std::stringstream &ss,
5011 : const std::string &sSymName, SubArguments &vSubArguments)
5012 : {
5013 0 : ss << "\ndouble " << sSymName;
5014 0 : ss << "_" << BinFuncName() << "(";
5015 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
5016 : {
5017 0 : if (i)
5018 0 : ss << ",";
5019 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
5020 : }
5021 0 : ss << "){\n";
5022 0 : ss << " int gid0 = get_global_id(0);\n";
5023 0 : ss << " double fSumX = 0.0;\n";
5024 0 : ss << " double fSumY = 0.0;\n";
5025 0 : ss << " double fMeanX = 0.0;\n";
5026 0 : ss << " double fMeanY = 0.0;\n";
5027 0 : ss << " double fSumDeltaXDeltaY = 0.0;\n";
5028 0 : ss << " double fSumSqrDeltaX = 0.0;\n";
5029 0 : ss << " double fCount = 0.0;\n";
5030 0 : ss << " double argX = 0.0;\n";
5031 0 : ss << " double argY = 0.0;\n";
5032 0 : if(vSubArguments.size() != 2)
5033 : {
5034 0 : ss << " return NAN;\n";
5035 0 : ss << "}\n";
5036 0 : return ;
5037 : }
5038 0 : FormulaToken *pCur = vSubArguments[1]->GetFormulaToken();
5039 0 : FormulaToken *pCur1 = vSubArguments[0]->GetFormulaToken();
5040 : assert(pCur);
5041 : assert(pCur1);
5042 0 : if (pCur->GetType() == formula::svDoubleVectorRef&&
5043 0 : pCur1->GetType() == formula::svDoubleVectorRef)
5044 : {
5045 : const formula::DoubleVectorRefToken* pDVR =
5046 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
5047 : const formula::DoubleVectorRefToken* pDVR1 =
5048 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur1);
5049 :
5050 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
5051 0 : size_t nCurWindowSize1 = pDVR1->GetRefRowSize();
5052 0 : size_t arrayLength = pDVR->GetArrayLength()<
5053 0 : pDVR1->GetArrayLength() ? pDVR->GetArrayLength():
5054 0 : pDVR1->GetArrayLength();
5055 0 : if(nCurWindowSize != nCurWindowSize1)
5056 : {
5057 0 : ss << " return NAN;\n";
5058 0 : ss << "}\n";
5059 0 : return ;
5060 : }
5061 0 : ss << " for (int i = ";
5062 0 : if ((!pDVR->IsStartFixed() && pDVR->IsEndFixed())
5063 0 : &&(!pDVR1->IsStartFixed() && pDVR1->IsEndFixed()))
5064 : {
5065 0 : ss << "gid0; i < " << arrayLength;
5066 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
5067 0 : ss << " {\n";
5068 : }
5069 0 : else if ((pDVR->IsStartFixed() && !pDVR->IsEndFixed())
5070 0 : &&(pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
5071 : {
5072 0 : ss << "0; i < " << arrayLength ;
5073 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
5074 0 : ss << " {\n";
5075 : }
5076 0 : else if ((!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
5077 0 : &&(!pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
5078 : {
5079 0 : ss << "0; i + gid0 < " << arrayLength;
5080 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
5081 0 : ss << " {\n";
5082 : }
5083 0 : else if ((pDVR->IsStartFixed() && pDVR->IsEndFixed())
5084 0 : &&(pDVR1->IsStartFixed() && pDVR1->IsEndFixed()))
5085 : {
5086 0 : ss << "0; i < " << arrayLength << "; i++)\n";
5087 0 : ss << " {\n";
5088 : }
5089 : else
5090 : {
5091 0 : ss << "0; i < " << nCurWindowSize << "; i++)\n";
5092 0 : ss << " {\n";
5093 0 : ss << " break;\n";
5094 0 : ss << " }";
5095 0 : ss << " return NAN;\n";
5096 0 : ss << "}\n";
5097 0 : return ;
5098 : }
5099 :
5100 0 : ss << " argX = ";
5101 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
5102 0 : ss << " argY = ";
5103 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
5104 0 : ss << " if (isNan(argX) || isNan(argY))\n";
5105 0 : ss << " continue;\n";
5106 0 : ss << " fSumX += argX;\n";
5107 0 : ss << " fSumY += argY;\n";
5108 0 : ss << " fCount += 1.0;\n";
5109 0 : ss << " }\n";
5110 :
5111 0 : ss << " if (fCount < 1.0)\n";
5112 0 : ss << " return NAN;\n";
5113 0 : ss << " else\n";
5114 0 : ss << " {\n";
5115 0 : ss << " fMeanX = fSumX * pow(fCount,-1.0);\n";
5116 0 : ss << " fMeanY = fSumY * pow(fCount,-1.0);\n";
5117 :
5118 0 : ss << " for (int i = ";
5119 0 : if ((!pDVR->IsStartFixed() && pDVR->IsEndFixed())
5120 0 : &&(!pDVR1->IsStartFixed() && pDVR1->IsEndFixed()))
5121 : {
5122 0 : ss << "gid0; i < " << arrayLength;
5123 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
5124 0 : ss << " {\n";
5125 : }
5126 0 : else if ((pDVR->IsStartFixed() && !pDVR->IsEndFixed())
5127 0 : &&(pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
5128 : {
5129 0 : ss << "0; i < " << arrayLength ;
5130 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
5131 0 : ss << " {\n";
5132 : }
5133 0 : else if ((!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
5134 0 : &&(!pDVR1->IsStartFixed() && !pDVR1->IsEndFixed()))
5135 : {
5136 0 : ss << "0; i + gid0 < " << arrayLength;
5137 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
5138 0 : ss << " {\n";
5139 : }
5140 : else
5141 : {
5142 0 : ss << "0; i < " << arrayLength << "; i++)\n";
5143 0 : ss << " {\n";
5144 : }
5145 :
5146 0 : ss << " argX = ";
5147 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
5148 0 : ss << " argY = ";
5149 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
5150 0 : ss << " if (isNan(argX) || isNan(argY))\n";
5151 0 : ss << " continue;\n";
5152 0 : ss << " fSumDeltaXDeltaY += (argX-fMeanX)*(argY-fMeanY);\n";
5153 0 : ss << " fSumSqrDeltaX += (argX-fMeanX) * (argX-fMeanX);\n";
5154 0 : ss << " }\n";
5155 0 : ss << " if(fSumSqrDeltaX == 0.0)\n";
5156 0 : ss << " return NAN;\n";
5157 0 : ss << " else\n";
5158 0 : ss << " {\n";
5159 0 : ss << " return fMeanY -";
5160 0 : ss << " (fSumDeltaXDeltaY*pow(fSumSqrDeltaX,-1.0))*fMeanX;\n";
5161 0 : ss << " }\n";
5162 0 : ss << " }\n";
5163 0 : ss << "}\n";
5164 : }
5165 : else
5166 : {
5167 0 : ss << " return NAN;\n";
5168 0 : ss << "}\n";
5169 : }
5170 : }
5171 0 : void OpLogInv:: GenSlidingWindowFunction(std::stringstream &ss,
5172 : const std::string &sSymName, SubArguments &vSubArguments)
5173 : {
5174 0 : ss << "\ndouble " << sSymName;
5175 0 : ss << "_"<< BinFuncName() <<"(";
5176 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
5177 : {
5178 0 : if (i)
5179 0 : ss << ",";
5180 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
5181 : }
5182 0 : ss << ") {\n";
5183 0 : ss << " int gid0=get_global_id(0);\n";
5184 0 : ss << " double tmp;\n";
5185 0 : ss << " double arg0,arg1,arg2,arg3;\n";
5186 0 : size_t i = vSubArguments.size();
5187 0 : for (i = 0; i < vSubArguments.size(); i++)
5188 : {
5189 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
5190 : assert(pCur);
5191 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
5192 : {
5193 : const formula::DoubleVectorRefToken* pDVR =
5194 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
5195 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
5196 0 : ss << "for (int i = ";
5197 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
5198 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
5199 0 : ss << " && i < " << nCurWindowSize << "; i++){\n";
5200 0 : } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
5201 0 : ss << "0; i < " << pDVR->GetArrayLength();
5202 0 : ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
5203 0 : } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
5204 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
5205 0 : ss << " && i < "<< nCurWindowSize << "; i++){\n ";
5206 : }
5207 : else {
5208 0 : ss << "0; i < "<< nCurWindowSize << "; i++){\n";
5209 : }
5210 : }
5211 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
5212 : {
5213 : const formula::SingleVectorRefToken* pSVR =
5214 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
5215 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
5216 0 : ss << " {\n";
5217 0 : ss << " if (isNan(";
5218 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
5219 0 : ss << "))\n";
5220 0 : ss << " arg"<<i<<"= 0;\n";
5221 0 : ss << " else\n";
5222 0 : ss << " arg"<<i<<"=";
5223 0 : ss<<vSubArguments[i]->GenSlidingWindowDeclRef();
5224 0 : ss << ";\n";
5225 0 : ss << " }\n";
5226 0 : ss << " else\n";
5227 0 : ss << " arg"<<i<<"= 0;\n";
5228 : }
5229 0 : else if (pCur->GetType() == formula::svDouble)
5230 : {
5231 0 : ss << " if (isNan(";
5232 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
5233 0 : ss << "))\n";
5234 0 : ss << " arg"<<i<<"= 0;\n";
5235 0 : ss << " else\n";
5236 0 : ss << " arg"<<i<<"=";
5237 0 : ss<<vSubArguments[i]->GenSlidingWindowDeclRef();
5238 0 : ss << ";\n";
5239 : }
5240 : }
5241 0 : ss<< " double q,t,z;\n";
5242 0 : ss<< " q = arg0 -0.5;\n";
5243 0 : ss<< " if(fabs(q)<=.425)\n";
5244 0 : ss<< " {\n";
5245 0 : ss<< " t=0.180625-pow(q, 2);\n";
5246 : ss<< " z=\n"
5247 : " q*\n"
5248 : " (\n"
5249 : " (\n"
5250 : " (\n"
5251 : " (\n"
5252 : " (\n"
5253 : " (\n"
5254 : " (\n"
5255 0 : " t*2509.0809287301226727";
5256 : ss<<"+33430.575583588128105\n"
5257 : " )\n"
5258 : " *t+67265.770927008700853\n"
5259 : " )\n"
5260 : " *t+45921.953931549871457\n"
5261 : " )\n"
5262 : " *t+13731.693765509461125\n"
5263 : " )\n"
5264 : " *t+1971.5909503065514427\n"
5265 : " )\n"
5266 : " *t+133.14166789178437745\n"
5267 : " )\n"
5268 : " *t+3.387132872796366608\n"
5269 : " )\n"
5270 : " /\n"
5271 : " (\n"
5272 : " (\n"
5273 : " (\n"
5274 : " (\n"
5275 : " (\n"
5276 : " (\n"
5277 : " (\n"
5278 0 : " t*5226.495278852854561";
5279 : ss<<"+28729.085735721942674\n"
5280 : " )\n"
5281 : " *t+39307.89580009271061\n"
5282 : " )\n"
5283 : " *t+21213.794301586595867\n"
5284 : " )\n"
5285 : " *t+5394.1960214247511077\n"
5286 : " )\n"
5287 : " *t+687.1870074920579083\n"
5288 : " )\n"
5289 : " *t+42.313330701600911252\n"
5290 : " )\n"
5291 : " *t+1.0\n"
5292 0 : " );\n";
5293 0 : ss<<" }\n";
5294 0 : ss<<" else\n";
5295 0 : ss<<" {\n";
5296 0 : ss<<" t = q > 0 ? 1 - arg0 : arg0;\n";
5297 0 : ss<<" t=sqrt(-log(t));\n";
5298 0 : ss<<" if(t<=5.0)\n";
5299 0 : ss<<" {\n";
5300 0 : ss<<" t+=-1.6;\n";
5301 : ss<<" z=\n"
5302 : " (\n"
5303 : " (\n"
5304 : " (\n"
5305 : " (\n"
5306 : " (\n"
5307 : " (\n"
5308 : " (\n"
5309 0 : " t*7.7454501427834140764e-4";
5310 : ss<<"+0.0227238449892691845833\n"
5311 : " )\n"
5312 : " *t+0.24178072517745061177\n"
5313 : " )\n"
5314 : " *t+1.27045825245236838258\n"
5315 : " )\n"
5316 : " *t+3.64784832476320460504\n"
5317 : " )\n"
5318 : " *t+5.7694972214606914055\n"
5319 : " )\n"
5320 : " *t+4.6303378461565452959\n"
5321 : " )\n"
5322 : " *t+1.42343711074968357734\n"
5323 : " )\n"
5324 : " /\n"
5325 : " (\n"
5326 : " (\n"
5327 : " (\n"
5328 : " (\n"
5329 : " (\n"
5330 : " (\n"
5331 : " (\n"
5332 0 : " t*1.05075007164441684324e-9";
5333 : ss<<"+5.475938084995344946e-4\n"
5334 : " )\n"
5335 : " *t+0.0151986665636164571966\n"
5336 : " )\n"
5337 : " *t+0.14810397642748007459\n"
5338 : " )\n"
5339 : " *t+0.68976733498510000455\n"
5340 : " )\n"
5341 : " *t+1.6763848301838038494\n"
5342 : " )\n"
5343 : " *t+2.05319162663775882187\n"
5344 : " )\n"
5345 : " *t+1.0\n"
5346 0 : " );\n";
5347 0 : ss<<" }\n";
5348 0 : ss<<" else\n";
5349 0 : ss<<" {\n";
5350 0 : ss<<" t+=-5.0;\n";
5351 : ss<<" z=\n"
5352 : " (\n"
5353 : " (\n"
5354 : " (\n"
5355 : " (\n"
5356 : " (\n"
5357 : " (\n"
5358 : " (\n"
5359 0 : " t*2.01033439929228813265e-7";
5360 : ss<<"+2.71155556874348757815e-5\n"
5361 : " )\n"
5362 : " *t+0.0012426609473880784386\n"
5363 : " )\n"
5364 : " *t+0.026532189526576123093\n"
5365 : " )\n"
5366 : " *t+0.29656057182850489123\n"
5367 : " )\n"
5368 : " *t+1.7848265399172913358\n"
5369 : " )\n"
5370 : " *t+5.4637849111641143699\n"
5371 : " )\n"
5372 : " *t+6.6579046435011037772\n"
5373 : " )\n"
5374 : " /\n"
5375 : " (\n"
5376 : " (\n"
5377 : " (\n"
5378 : " (\n"
5379 : " (\n"
5380 : " (\n"
5381 : " (\n"
5382 : " t*2.04426310338993978564e-15"
5383 : " +1.4215117583164458887e-7\n"
5384 : " )\n"
5385 : " *t+1.8463183175100546818e-5\n"
5386 : " )\n"
5387 : " *t+7.868691311456132591e-4\n"
5388 : " )\n"
5389 : " *t+0.0148753612908506148525\n"
5390 : " )\n"
5391 : " *t+0.13692988092273580531\n"
5392 : " )\n"
5393 : " *t+0.59983220655588793769\n"
5394 : " )\n"
5395 : " *t+1.0\n"
5396 0 : " );\n";
5397 0 : ss << " }\n";
5398 0 : ss << " z = q < 0.0 ? (-1)*z : z;\n";
5399 0 : ss << " }\n";
5400 0 : ss << " tmp = exp(arg1+arg2*z);\n";
5401 0 : ss << " return tmp;\n";
5402 0 : ss << "}\n";
5403 0 : }
5404 :
5405 0 : void OpForecast::GenSlidingWindowFunction(std::stringstream &ss,
5406 : const std::string &sSymName, SubArguments &vSubArguments)
5407 : {
5408 0 : FormulaToken *pCur0 = vSubArguments[0]->GetFormulaToken();
5409 : assert(pCur0);
5410 : const formula::SingleVectorRefToken*pCurDVR0= static_cast<const
5411 0 : formula::SingleVectorRefToken *>(pCur0);
5412 0 : FormulaToken *pCur1 = vSubArguments[1]->GetFormulaToken();
5413 : assert(pCur1);
5414 : const formula::DoubleVectorRefToken* pCurDVR1 =
5415 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur1);
5416 0 : size_t nCurWindowSize = pCurDVR1->GetRefRowSize();
5417 0 : FormulaToken *pCur2 = vSubArguments[2]->GetFormulaToken();
5418 : assert(pCur2);
5419 : const formula::DoubleVectorRefToken* pCurDVR2 =
5420 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur2);
5421 0 : size_t nCurWindowSize1 = pCurDVR2->GetRefRowSize();
5422 0 : ss << "\ndouble " << sSymName;
5423 0 : ss << "_"<< BinFuncName() <<"( ";
5424 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
5425 : {
5426 0 : if (i)
5427 0 : ss << ",";
5428 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
5429 : }
5430 0 : ss << ") {\n";
5431 0 : ss << " int gid0 = get_global_id(0);\n";
5432 0 : ss << " double fSumX = 0.0;\n";
5433 0 : ss << " double fSumY = 0.0;\n";
5434 0 : ss << " double fSumDeltaXDeltaY = 0.0;\n";
5435 0 : ss << " double fSumSqrDeltaX = 0.0;\n";
5436 0 : if(pCur0->GetType()== formula::svDouble ||
5437 0 : pCur0->GetType() == formula::svSingleVectorRef)
5438 : {
5439 0 : ss << " double arg0 = ";
5440 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
5441 0 : ss << ";\n";
5442 : }
5443 : else
5444 0 : ss << "return HUGE_VAL";
5445 0 : if(pCur1->GetType() != formula::svDoubleVectorRef ||
5446 0 : pCur2->GetType() != formula::svDoubleVectorRef)
5447 0 : ss << "return HUGE_VAL";
5448 : else
5449 : {
5450 0 : ss<< " if(isNan(arg0)||(gid0>=";
5451 0 : ss<<pCurDVR0->GetArrayLength();
5452 0 : ss<<"))\n";
5453 0 : ss<<" arg0 = 0;\n";
5454 0 : ss << " int length="<<nCurWindowSize;
5455 0 : ss << ";\n";
5456 0 : ss << " int length1= "<<nCurWindowSize1;
5457 0 : ss << ";\n";
5458 0 : ss << " if(length!=length1)\n";
5459 0 : ss << " return 0;\n";
5460 0 : ss << " double tmp = 0;\n";
5461 0 : ss << " for (int i = 0; i <" << nCurWindowSize << "; i++)\n";
5462 0 : ss << " {\n";
5463 0 : ss << " double arg1 = ";
5464 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef(true);
5465 0 : ss << ";\n";
5466 0 : ss << " double arg2 = ";
5467 0 : ss << vSubArguments[2]->GenSlidingWindowDeclRef(true);
5468 0 : ss << ";\n";
5469 0 : ss << " if(isNan(arg1)||((gid0+i)>=";
5470 0 : ss << pCurDVR1->GetArrayLength();
5471 0 : ss << "))\n";
5472 0 : ss << " {\n";
5473 0 : ss << " length--;\n";
5474 0 : ss << " continue;\n";
5475 0 : ss << " }\n";
5476 0 : ss << " if(isNan(arg2)||((gid0+i)>=";
5477 0 : ss << pCurDVR2->GetArrayLength();
5478 0 : ss << "))\n";
5479 0 : ss << " {\n";
5480 0 : ss << " length--;\n";
5481 0 : ss << " continue;\n";
5482 0 : ss << " }\n";
5483 0 : ss << " fSumY+=arg1;\n";
5484 0 : ss << " fSumX+=arg2;\n";
5485 0 : ss << " }\n";
5486 0 : ss << " double fMeanX = fSumX / length;\n";
5487 0 : ss << " double fMeanY = fSumY / length;\n";
5488 0 : ss << " for (int i = 0; i <" << nCurWindowSize << "; i++)\n";
5489 0 : ss << " {\n";
5490 0 : ss << " double arg1 = ";
5491 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef(true);
5492 0 : ss << ";\n";
5493 0 : ss << " double arg2 = ";
5494 0 : ss << vSubArguments[2]->GenSlidingWindowDeclRef(true);
5495 0 : ss << ";\n";
5496 0 : ss << " if(isNan(arg1)||((gid0+i)>=";
5497 0 : ss <<pCurDVR1->GetArrayLength();
5498 0 : ss <<"))\n";
5499 0 : ss <<" {\n";
5500 0 : ss <<" continue;\n";
5501 0 : ss <<" }\n";
5502 0 : ss << " if(isNan(arg2)||((gid0+i)>=";
5503 0 : ss <<pCurDVR2->GetArrayLength();
5504 0 : ss <<"))\n";
5505 0 : ss <<" {\n";
5506 0 : ss <<" continue;\n";
5507 0 : ss <<" }\n";
5508 0 : ss <<" fSumDeltaXDeltaY+=(arg2 - fMeanX) * (arg1 - fMeanY);\n";
5509 0 : ss <<" fSumSqrDeltaX+=pow(arg2 - fMeanX, 2);\n";
5510 0 : ss <<" }\n";
5511 0 : ss <<" tmp =fMeanY + fSumDeltaXDeltaY / fSumSqrDeltaX *";
5512 0 : ss <<" (arg0 - fMeanX);\n";
5513 0 : ss <<" return tmp;\n";
5514 0 : ss << "}";
5515 : }
5516 0 : }
5517 0 : void OpLogNormDist::GenSlidingWindowFunction(std::stringstream &ss,
5518 : const std::string &sSymName, SubArguments &vSubArguments)
5519 : {
5520 0 : FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
5521 : const formula::SingleVectorRefToken*tmpCurDVR0= static_cast<const
5522 0 : formula::SingleVectorRefToken *>(tmpCur0);
5523 0 : FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
5524 : const formula::SingleVectorRefToken*tmpCurDVR1= static_cast<const
5525 0 : formula::SingleVectorRefToken *>(tmpCur1);
5526 0 : FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
5527 : const formula::SingleVectorRefToken*tmpCurDVR2= static_cast<const
5528 0 : formula::SingleVectorRefToken *>(tmpCur2);
5529 0 : FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
5530 : const formula::SingleVectorRefToken*tmpCurDVR3= static_cast<const
5531 0 : formula::SingleVectorRefToken *>(tmpCur3);
5532 0 : ss << "\ndouble " << sSymName;
5533 0 : ss << "_"<< BinFuncName() <<"(";
5534 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
5535 : {
5536 0 : if (i)
5537 0 : ss << ",";
5538 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
5539 : }
5540 0 : ss << ") {\n";
5541 0 : ss << " int gid0=get_global_id(0);\n";
5542 0 : ss << " double arg0,arg1,arg2,arg3;\n";
5543 0 : size_t i = vSubArguments.size();
5544 0 : for (i = 0; i < vSubArguments.size(); i++)
5545 : {
5546 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
5547 : assert(pCur);
5548 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
5549 : {
5550 : const formula::DoubleVectorRefToken* pDVR =
5551 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
5552 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
5553 0 : ss << "for (int i = ";
5554 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
5555 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
5556 0 : ss << " && i < " << nCurWindowSize << "; i++){\n";
5557 0 : } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
5558 0 : ss << "0; i < " << pDVR->GetArrayLength();
5559 0 : ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
5560 0 : } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
5561 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
5562 0 : ss << " && i < "<< nCurWindowSize << "; i++){\n ";
5563 : }
5564 : else {
5565 0 : ss << "0; i < "<< nCurWindowSize << "; i++){\n";
5566 : }
5567 : }
5568 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
5569 : {
5570 : const formula::SingleVectorRefToken* pSVR =
5571 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
5572 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
5573 0 : ss << " {\n";
5574 0 : ss << " if (isNan(";
5575 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
5576 0 : ss << "))\n";
5577 0 : ss << " arg"<<i<<"= 0;\n";
5578 0 : ss << " else\n";
5579 0 : ss << " arg"<<i<<"=";
5580 0 : ss<<vSubArguments[i]->GenSlidingWindowDeclRef();
5581 0 : ss << ";\n";
5582 0 : ss << " }\n";
5583 0 : ss << " else\n";
5584 0 : ss << " arg"<<i<<"= 0;\n";
5585 : }
5586 0 : else if (pCur->GetType() == formula::svDouble)
5587 : {
5588 0 : ss << " if (isNan(";
5589 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
5590 0 : ss << "))\n";
5591 0 : ss << " arg"<<i<<"= 0;\n";
5592 0 : ss << " else\n";
5593 0 : ss << " arg"<<i<<"=";
5594 0 : ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
5595 0 : ss << ";\n";
5596 : }
5597 : }
5598 0 : ss << " double tmp;\n";
5599 0 : ss << " if(isNan(arg0)||(gid0>=";
5600 0 : ss << tmpCurDVR0->GetArrayLength();
5601 0 : ss << "))\n";
5602 0 : ss << " arg0 = 0;\n";
5603 0 : ss << " if(isNan(arg1)||(gid0>=";
5604 0 : ss << tmpCurDVR1->GetArrayLength();
5605 0 : ss << "))\n";
5606 0 : ss << " arg1 = 0;\n";
5607 0 : ss << " if(isNan(arg2)||(gid0>=";
5608 0 : ss << tmpCurDVR2->GetArrayLength();
5609 0 : ss << "))\n";
5610 0 : ss << " arg2 = 0;\n";
5611 0 : ss << " if(isNan(arg3)||(gid0>=";
5612 0 : ss << tmpCurDVR3->GetArrayLength();
5613 0 : ss << "))\n";
5614 0 : ss << " arg3 = 0;\n";
5615 0 : ss << " double temp = (log(arg0)-arg1)/arg2;\n";
5616 0 : ss << " if(arg3)\n";
5617 0 : ss << " {\n";
5618 0 : ss << " if(arg0<=0)\n";
5619 0 : ss << " tmp = 0.0;\n";
5620 0 : ss << " else\n";
5621 0 : ss << " tmp = 0.5 * erfc(-temp * 0.7071067811865475);\n";
5622 0 : ss << " }\n";
5623 0 : ss << " else\n";
5624 0 : ss << " tmp = (0.39894228040143268 * exp((-1)*pow(temp, 2)";
5625 0 : ss << " / 2.0))/(arg2*arg0);\n";
5626 0 : ss << " return tmp;\n";
5627 0 : ss << "}\n";
5628 0 : }
5629 :
5630 0 : void OpGammaDist::BinInlineFun(std::set<std::string>& decls,
5631 : std::set<std::string>& funs)
5632 : {
5633 0 : decls.insert(fBigInvDecl);decls.insert(fLogDblMaxDecl);
5634 0 : decls.insert(fHalfMachEpsDecl);decls.insert(fMaxGammaArgumentDecl);
5635 0 : decls.insert(GetGammaSeriesDecl);decls.insert(GetGammaContFractionDecl);
5636 0 : decls.insert(GetLowRegIGammaDecl);decls.insert(GetGammaDistDecl);
5637 0 : decls.insert(GetGammaDistPDFDecl);
5638 0 : funs.insert(GetGammaSeries);funs.insert(GetGammaContFraction);
5639 0 : funs.insert(GetLowRegIGamma);funs.insert(GetGammaDist);
5640 0 : funs.insert(GetGammaDistPDF);
5641 0 : }
5642 :
5643 0 : void OpGammaDist::GenSlidingWindowFunction(std::stringstream &ss,
5644 : const std::string &sSymName, SubArguments &vSubArguments)
5645 : {
5646 0 : ss << "\ndouble " << sSymName;
5647 0 : ss << "_"<< BinFuncName() <<"(";
5648 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
5649 : {
5650 0 : if (i)
5651 0 : ss << ",";
5652 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
5653 : }
5654 0 : ss << ") {\n";
5655 0 : ss << " int gid0=get_global_id(0);\n";
5656 0 : ss << " double tmp;\n";
5657 0 : ss << " double arg0,arg1,arg2,arg3;\n";
5658 0 : size_t i = vSubArguments.size();
5659 :
5660 0 : for (i = 0; i < vSubArguments.size(); i++)
5661 : {
5662 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
5663 : assert(pCur);
5664 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
5665 : {
5666 : const formula::DoubleVectorRefToken* pDVR =
5667 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
5668 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
5669 0 : ss << "for (int i = ";
5670 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
5671 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
5672 0 : ss << " && i < " << nCurWindowSize << "; i++){\n";
5673 0 : } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
5674 0 : ss << "0; i < " << pDVR->GetArrayLength();
5675 0 : ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
5676 0 : } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
5677 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
5678 0 : ss << " && i < "<< nCurWindowSize << "; i++){\n ";
5679 : }
5680 : else {
5681 0 : ss << "0; i < "<< nCurWindowSize << "; i++){\n";
5682 : }
5683 : }
5684 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
5685 : {
5686 : const formula::SingleVectorRefToken* pSVR =
5687 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
5688 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
5689 0 : ss << " {\n";
5690 0 : ss << " if (isNan(";
5691 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
5692 0 : ss << "))\n";
5693 0 : ss << " arg"<<i<<"= 0;\n";
5694 0 : ss << " else\n";
5695 0 : ss << " arg"<<i<<"=";
5696 0 : ss<<vSubArguments[i]->GenSlidingWindowDeclRef();
5697 0 : ss << ";\n";
5698 0 : ss << " }\n";
5699 0 : ss << " else\n";
5700 0 : ss << " arg"<<i<<"= 0;\n";
5701 : }
5702 0 : else if (pCur->GetType() == formula::svDouble)
5703 : {
5704 0 : ss << " if (isNan(";
5705 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
5706 0 : ss << "))\n";
5707 0 : ss << " arg"<<i<<"= 0;\n";
5708 0 : ss << " else\n";
5709 0 : ss << " arg"<<i<<"=";
5710 0 : ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
5711 0 : ss << ";\n";
5712 : }
5713 : }
5714 0 : ss << " if (arg3)\n";
5715 0 : ss << " tmp=GetGammaDist( arg0, arg1, arg2);\n";
5716 0 : ss << " else\n";
5717 0 : ss << " tmp=GetGammaDistPDF( arg0, arg1, arg2);\n";
5718 0 : ss << " return tmp;\n";
5719 0 : ss << "}\n";
5720 0 : }
5721 0 : void OpChiDist::BinInlineFun(std::set<std::string>& decls,
5722 : std::set<std::string>& funs)
5723 : {
5724 0 : decls.insert(fBigInvDecl);
5725 0 : funs.insert("");
5726 0 : decls.insert(fHalfMachEpsDecl);
5727 0 : funs.insert("");
5728 0 : decls.insert(GetUpRegIGammaDecl);
5729 0 : funs.insert(GetUpRegIGamma);
5730 0 : decls.insert(GetGammaSeriesDecl);
5731 0 : funs.insert(GetGammaSeries);
5732 0 : decls.insert(GetGammaContFractionDecl);
5733 0 : funs.insert(GetGammaContFraction);
5734 0 : decls.insert(GetChiDistDecl);
5735 0 : funs.insert(GetChiDist);
5736 0 : }
5737 0 : void OpChiDist::GenSlidingWindowFunction(
5738 : std::stringstream &ss,const std::string &sSymName,
5739 : SubArguments &vSubArguments)
5740 : {
5741 0 : ss << "\ndouble " << sSymName;
5742 0 : ss << "_"<< BinFuncName() <<"(";
5743 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
5744 : {
5745 0 : if (i)
5746 0 : ss << ",";
5747 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
5748 : }
5749 0 : ss << ")\n";
5750 0 : ss << "{\n";
5751 0 : ss << " double fx,fDF,tmp=0,tmp0=0,tmp1=0;\n";
5752 0 : ss << " int gid0=get_global_id(0);\n";
5753 :
5754 0 : size_t i = vSubArguments.size();
5755 0 : ss <<"\n";
5756 0 : for (i = 0; i < vSubArguments.size(); i++)
5757 : {
5758 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
5759 : assert(pCur);
5760 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
5761 : {
5762 : const formula::DoubleVectorRefToken* pDVR =
5763 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
5764 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
5765 0 : ss << "for (int i = ";
5766 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
5767 : {
5768 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
5769 0 : ss << " && i < " << nCurWindowSize << "; i++){\n";
5770 : }
5771 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
5772 : {
5773 0 : ss << "0; i < " << pDVR->GetArrayLength();
5774 0 : ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
5775 : }
5776 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
5777 : {
5778 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
5779 0 : ss << " && i < "<< nCurWindowSize << "; i++){\n";
5780 : }
5781 : else
5782 : {
5783 0 : ss << "0; i < "<< nCurWindowSize << "; i++){\n";
5784 : }
5785 : }
5786 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
5787 : {
5788 : const formula::SingleVectorRefToken* pSVR =
5789 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
5790 0 : ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
5791 : }
5792 0 : else if (pCur->GetType() == formula::svDouble)
5793 : {
5794 0 : ss << "{\n";
5795 : }
5796 : else
5797 : {
5798 : }
5799 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
5800 : {
5801 0 : ss << " if (isNan(";
5802 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
5803 0 : ss << "))\n";
5804 0 : ss << " tmp"<<i<<"= 0;\n";
5805 0 : ss << " else\n";
5806 0 : ss << " tmp"<<i<<"=\n";
5807 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
5808 0 : ss << ";\n}\n";
5809 : }
5810 : }
5811 0 : ss << " fx = tmp0;\n";
5812 0 : ss << " fDF = floor(tmp1);\n";
5813 0 : ss << " if(fDF < 1.0)\n";
5814 0 : ss << " {\n";
5815 0 : ss << " return DBL_MIN;\n";
5816 0 : ss << " }\n";
5817 0 : ss << " tmp = GetChiDist( fx, fDF);\n";
5818 0 : ss << " return tmp;\n";
5819 0 : ss << "}\n";
5820 0 : }
5821 0 : void OpBinomdist::BinInlineFun(std::set<std::string>& decls,
5822 : std::set<std::string>& funs)
5823 : {
5824 0 : decls.insert(fMachEpsDecl);
5825 0 : funs.insert("");
5826 0 : decls.insert(MinDecl);
5827 0 : funs.insert("");
5828 0 : decls.insert(fMaxGammaArgumentDecl);
5829 0 : funs.insert("");
5830 0 : decls.insert(GetBinomDistPMFDecl);
5831 0 : funs.insert(GetBinomDistPMF);
5832 0 : decls.insert(GetBetaDistDecl);
5833 0 : funs.insert(GetBetaDist);
5834 0 : decls.insert(lcl_GetBinomDistRangeDecl);
5835 0 : funs.insert(lcl_GetBinomDistRange);
5836 0 : decls.insert(lcl_GetBetaHelperContFracDecl);
5837 0 : funs.insert(lcl_GetBetaHelperContFrac);
5838 0 : decls.insert(GetBetaDistPDFDecl);
5839 0 : funs.insert(GetBetaDistPDF);
5840 0 : decls.insert(GetLogBetaDecl);
5841 0 : funs.insert(GetLogBeta);
5842 0 : decls.insert(GetBetaDecl);
5843 0 : funs.insert(GetBeta);
5844 0 : decls.insert(lcl_getLanczosSumDecl);
5845 0 : funs.insert(lcl_getLanczosSum);
5846 0 : }
5847 0 : void OpBinomdist::GenSlidingWindowFunction(
5848 : std::stringstream &ss,const std::string &sSymName,
5849 : SubArguments &vSubArguments)
5850 : {
5851 0 : ss << "\ndouble " << sSymName;
5852 0 : ss << "_"<< BinFuncName() <<"(";
5853 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
5854 : {
5855 0 : if (i)
5856 0 : ss << ",";
5857 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
5858 : }
5859 0 : ss << ")\n";
5860 0 : ss << "{\n";
5861 0 : ss << " double tmp0,tmp1,tmp2,tmp3;\n";
5862 0 : ss << " int gid0=get_global_id(0);\n";
5863 0 : size_t i = vSubArguments.size();
5864 :
5865 0 : ss <<"\n ";
5866 : //while (i-- > 1)
5867 0 : for (i = 0; i < vSubArguments.size(); i++)
5868 : {
5869 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
5870 : assert(pCur);
5871 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
5872 : {
5873 : const formula::DoubleVectorRefToken* pDVR =
5874 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
5875 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
5876 0 : ss << "for (int i = ";
5877 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
5878 : {
5879 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
5880 0 : ss << " && i < " << nCurWindowSize << "; i++){\n";
5881 : }
5882 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
5883 : {
5884 0 : ss << "0; i < " << pDVR->GetArrayLength();
5885 0 : ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
5886 : }
5887 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
5888 : {
5889 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
5890 0 : ss << " && i < "<< nCurWindowSize << "; i++){\n";
5891 : }
5892 : else
5893 : {
5894 0 : ss << "0; i < "<< nCurWindowSize << "; i++){\n";
5895 : }
5896 : }
5897 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
5898 : {
5899 : const formula::SingleVectorRefToken* pSVR =
5900 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
5901 0 : ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
5902 : }
5903 0 : else if (pCur->GetType() == formula::svDouble)
5904 : {
5905 0 : ss << "{\n";
5906 : }
5907 : else
5908 : {
5909 : }
5910 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
5911 : {
5912 0 : ss << " if (isNan(";
5913 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
5914 0 : ss << "))\n";
5915 0 : ss << " tmp"<<i<<"= 0;\n";
5916 0 : ss << " else\n";
5917 0 : ss << " tmp"<<i<<"=\n";
5918 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
5919 0 : ss << ";\n}\n";
5920 : }
5921 : else
5922 : {
5923 0 : ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
5924 0 : ss <<";\n";
5925 : }
5926 : }
5927 0 : ss << " tmp0 = floor(tmp0);\n";
5928 0 : ss << " tmp1 = floor(tmp1);\n";
5929 0 : ss << " double rq = (0.5 - tmp2) + 0.5;\n";
5930 0 : ss << " if (tmp1 < 0.0 || tmp0 < 0.0 || tmp0 > tmp1 ||";
5931 0 : ss << "tmp2 < 0.0 || tmp2 > 1.0)\n";
5932 0 : ss << " {\n";
5933 0 : ss << " return DBL_MIN;\n";
5934 0 : ss << " }\n";
5935 0 : ss << " if(tmp2 == 0.0)\n";
5936 0 : ss << " return ( (tmp0 == 0.0 || tmp3) ? 1.0 : 0.0 );\n";
5937 0 : ss << " if(tmp2 == 1.0)\n";
5938 0 : ss << " return ( (tmp0 == tmp1) ? 1.0 : 0.0);\n";
5939 0 : ss << " if(!tmp3)\n";
5940 0 : ss << " return ( GetBinomDistPMF(tmp0, tmp1, tmp2));\n";
5941 0 : ss << " else \n";
5942 0 : ss << " {\n";
5943 0 : ss << " if(tmp0 == tmp1)\n";
5944 0 : ss << " return 1.0;\n";
5945 0 : ss << " else\n";
5946 0 : ss << " {\n";
5947 0 : ss << " double fFactor = pow(rq,tmp1);\n";
5948 0 : ss << " if(tmp0 == 0.0)\n";
5949 0 : ss << " return (fFactor);\n";
5950 0 : ss << " else if(fFactor <= Min)\n";
5951 0 : ss << " {\n";
5952 0 : ss << " fFactor = pow(tmp2,tmp1);\n";
5953 0 : ss << " if(fFactor <= Min)\n";
5954 0 : ss << " return GetBetaDist";
5955 0 : ss << "(rq, tmp1 - tmp0, tmp0 + 1.0);\n";
5956 0 : ss << " else\n";
5957 0 : ss << " {\n";
5958 0 : ss << " if(fFactor > fMachEps)\n";
5959 0 : ss << " {\n";
5960 0 : ss << " double fSum = 1.0 - fFactor;\n";
5961 0 : ss << " unsigned int max = ";
5962 0 : ss << "(unsigned int)((tmp1 - tmp0)-1);\n";
5963 0 : ss << " for (uint i = 0; i < max && fFactor > 0.0;";
5964 0 : ss << " i++)\n";
5965 0 : ss << " {\n";
5966 0 : ss << " fFactor *= (tmp1 - i)*pow((i + 1),-1.0)*";
5967 0 : ss << "rq*pow(tmp2,-1.0);\n";
5968 0 : ss << " fSum -= fFactor;\n";
5969 0 : ss << " }\n";
5970 0 : ss << " return ( (fSum < 0.0) ? 0.0 : fSum );\n";
5971 0 : ss << " }\n";
5972 0 : ss << " else \n";
5973 0 : ss << " return (lcl_GetBinomDistRange";
5974 0 : ss << "(tmp1, tmp1 - tmp0, tmp1, fFactor, rq, tmp2));\n";
5975 0 : ss << " }\n";
5976 0 : ss << " }\n";
5977 0 : ss << " else\n";
5978 0 : ss << " {\n";
5979 0 : ss << " double rtmp = ( lcl_GetBinomDistRange";
5980 0 : ss << "(tmp1, 0.0, tmp0, fFactor, tmp2, rq));\n";
5981 0 : ss << " return rtmp;\n";
5982 0 : ss << " }\n";
5983 0 : ss << " }\n";
5984 0 : ss << " }\n";
5985 0 : ss << "}\n";
5986 0 : }
5987 :
5988 0 : void OpChiSqDist::BinInlineFun(std::set<std::string>& decls,
5989 : std::set<std::string>& funs)
5990 : {
5991 0 : decls.insert(fMaxGammaArgumentDecl);decls.insert(GetChiSqDistCDFDecl);
5992 0 : decls.insert(GetChiSqDistPDFDecl);decls.insert(GetLowRegIGammaDecl);
5993 0 : decls.insert(GetGammaContFractionDecl);decls.insert(GetGammaSeriesDecl);
5994 0 : decls.insert(fHalfMachEpsDecl);decls.insert(F_PIDecl);
5995 0 : decls.insert(fBigInvDecl);
5996 :
5997 0 : funs.insert(GetGammaContFraction);funs.insert(GetChiSqDistCDF);
5998 0 : funs.insert(GetChiSqDistPDF);funs.insert(GetLowRegIGamma);
5999 0 : funs.insert(GetGammaSeries);
6000 0 : }
6001 :
6002 0 : void OpChiSqDist::GenSlidingWindowFunction(
6003 : std::stringstream &ss, const std::string &sSymName, SubArguments &
6004 : vSubArguments)
6005 : {
6006 0 : ss << "\ndouble " << sSymName;
6007 0 : ss << "_"<< BinFuncName() <<"(";
6008 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
6009 : {
6010 0 : if (i)
6011 0 : ss << ",";
6012 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
6013 : }
6014 0 : ss << ") {\n";
6015 0 : ss << " int gid0 = get_global_id(0);\n";
6016 0 : ss << " int singleIndex = gid0;\n";
6017 0 : ss << " double result = 0;\n";
6018 0 : if(vSubArguments.size()<2)
6019 : {
6020 0 : ss << " result = -DBL_MAX;\n";
6021 0 : ss << " return result;\n";
6022 : }else
6023 : {
6024 0 : GenTmpVariables(ss,vSubArguments);
6025 0 : CheckAllSubArgumentIsNan(ss,vSubArguments);
6026 0 : if(vSubArguments.size() == 2)
6027 : {
6028 0 : ss << " int tmp2 = 1;\n";
6029 : }
6030 : }
6031 0 : size_t i = vSubArguments.size();
6032 0 : ss <<"\n";
6033 0 : for (i = 0; i < vSubArguments.size(); i++)
6034 : {
6035 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
6036 : assert(pCur);
6037 0 : if (pCur->GetType() == formula::svSingleVectorRef)
6038 : {
6039 : const formula::SingleVectorRefToken* pSVR =
6040 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
6041 0 : ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
6042 : }
6043 0 : else if (pCur->GetType() == formula::svDouble)
6044 : {
6045 0 : ss << "{\n";
6046 : }
6047 :
6048 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
6049 : {
6050 0 : ss << " if (isNan(";
6051 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
6052 0 : ss << "))\n";
6053 0 : ss << " tmp"<<i<<"= 0;\n";
6054 0 : ss << " else\n";
6055 0 : ss << " tmp"<<i<<"=\n";
6056 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
6057 0 : ss << ";\n}\n";
6058 : }
6059 : else
6060 : {
6061 0 : ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
6062 0 : ss <<";\n";
6063 : }
6064 : }
6065 0 : ss << " tmp1 = floor(tmp1);\n";
6066 0 : ss << " if(tmp1 < 1.0)\n";
6067 0 : ss << " result = -DBL_MAX;\n";
6068 0 : ss << " else\n";
6069 0 : ss << " {\n";
6070 0 : ss << " if(tmp2)\n";
6071 0 : ss << " result =GetChiSqDistCDF(tmp0,tmp1);\n";
6072 0 : ss << " else\n";
6073 0 : ss << " result =GetChiSqDistPDF(tmp0,tmp1);\n";
6074 0 : ss << " }\n";
6075 0 : ss << " return result;\n";
6076 0 : ss << "}";
6077 0 : }
6078 :
6079 0 : void OpChiSqInv::BinInlineFun(std::set<std::string>& decls,
6080 : std::set<std::string>& funs)
6081 : {
6082 0 : decls.insert(fMaxGammaArgumentDecl);decls.insert(GetChiSqDistCDFDecl);
6083 0 : decls.insert(GetLowRegIGammaDecl);decls.insert(lcl_IterateInverseChiSQInvDecl);
6084 0 : decls.insert(GetGammaContFractionDecl);decls.insert(GetGammaSeriesDecl);
6085 0 : decls.insert(fHalfMachEpsDecl);decls.insert(F_PIDecl);
6086 0 : decls.insert(fBigInvDecl);decls.insert(lcl_HasChangeOfSignDecl);
6087 0 : decls.insert(fMachEpsDecl);
6088 :
6089 0 : funs.insert(GetGammaContFraction);funs.insert(GetChiSqDistCDF);
6090 0 : funs.insert(GetLowRegIGamma);funs.insert(lcl_HasChangeOfSign);
6091 0 : funs.insert(GetGammaSeries);funs.insert(lcl_IterateInverseChiSQInv);
6092 0 : }
6093 :
6094 0 : void OpChiSqInv::GenSlidingWindowFunction(
6095 : std::stringstream &ss, const std::string &sSymName, SubArguments &
6096 : vSubArguments)
6097 : {
6098 0 : ss << "\ndouble " << sSymName;
6099 0 : ss << "_"<< BinFuncName() <<"(";
6100 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
6101 : {
6102 0 : if (i)
6103 0 : ss << ",";
6104 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
6105 : }
6106 0 : ss << ") {\n";
6107 0 : ss << " int gid0 = get_global_id(0);\n";
6108 0 : ss << " int singleIndex = gid0;\n";
6109 0 : ss << " double result = 0;\n";
6110 0 : if(vSubArguments.size()!=2)
6111 : {
6112 0 : ss << " result = -DBL_MAX;\n";
6113 0 : ss << " return result;\n";
6114 : }
6115 : else
6116 : {
6117 0 : GenTmpVariables(ss,vSubArguments);
6118 0 : CheckAllSubArgumentIsNan(ss,vSubArguments);
6119 0 : size_t i = vSubArguments.size();
6120 0 : ss <<"\n";
6121 0 : for (i = 0; i < vSubArguments.size(); i++)
6122 : {
6123 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
6124 : assert(pCur);
6125 0 : if (pCur->GetType() == formula::svSingleVectorRef)
6126 : {
6127 : const formula::SingleVectorRefToken* pSVR =
6128 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
6129 0 : ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
6130 : }
6131 0 : else if (pCur->GetType() == formula::svDouble)
6132 : {
6133 0 : ss << "{\n";
6134 : }
6135 :
6136 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
6137 : {
6138 0 : ss << " if (isNan(";
6139 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
6140 0 : ss << "))\n";
6141 0 : ss << " tmp"<<i<<"= 0;\n";
6142 0 : ss << " else\n";
6143 0 : ss << " tmp"<<i<<"=\n";
6144 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
6145 0 : ss << ";\n}\n";
6146 : }
6147 : else
6148 : {
6149 0 : ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
6150 0 : ss <<";\n";
6151 : }
6152 : }
6153 0 : ss << " tmp1 = floor(tmp1);\n";
6154 0 : ss << " bool bConvError;\n";
6155 0 : ss << " if(tmp1 < 1.0 || tmp0 < 0 || tmp0>=1.0)\n";
6156 0 : ss << " result = -DBL_MAX;\n";
6157 0 : ss << " else\n";
6158 0 : ss << " {\n";
6159 0 : ss << " result =lcl_IterateInverseChiSQInv( tmp0, tmp1,";
6160 0 : ss << "tmp1*0.5, tmp1, &bConvError );\n";
6161 0 : ss << " }\n";
6162 0 : ss << " if(bConvError)\n";
6163 0 : ss << " result = -DBL_MAX;\n";
6164 0 : ss << " return result;\n";
6165 0 : ss << "}";
6166 : }
6167 :
6168 0 : }
6169 0 : void OpGammaInv::BinInlineFun(std::set<std::string>& decls,
6170 : std::set<std::string>& funs)
6171 : {
6172 0 : decls.insert(fBigInvDecl);decls.insert(fHalfMachEpsDecl);
6173 0 : decls.insert(GetGammaSeriesDecl);decls.insert(GetGammaContFractionDecl);
6174 0 : decls.insert(GetGammaInvValueDecl);
6175 0 : funs.insert(GetGammaSeries);funs.insert(GetGammaContFraction);
6176 0 : funs.insert(GetGammaInvValue);
6177 0 : }
6178 :
6179 0 : void OpGammaInv::GenSlidingWindowFunction(std::stringstream &ss,
6180 : const std::string &sSymName, SubArguments &vSubArguments)
6181 : {
6182 0 : ss << "\ndouble " << sSymName;
6183 0 : ss << "_"<< BinFuncName() <<"(";
6184 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
6185 : {
6186 0 : if (i)
6187 0 : ss << ",";
6188 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
6189 : }
6190 0 : ss << ") {\n";
6191 0 : ss << " int gid0=get_global_id(0);\n";
6192 0 : ss << " double tmp;\n";
6193 0 : ss << " double arg0,arg1,arg2;\n";
6194 0 : size_t i = vSubArguments.size();
6195 :
6196 0 : for (i = 0; i < vSubArguments.size(); i++)
6197 : {
6198 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
6199 : assert(pCur);
6200 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
6201 : {
6202 : const formula::DoubleVectorRefToken* pDVR =
6203 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
6204 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
6205 0 : ss << "for (int i = ";
6206 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
6207 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
6208 0 : ss << " && i < " << nCurWindowSize << "; i++){\n";
6209 0 : } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
6210 0 : ss << "0; i < " << pDVR->GetArrayLength();
6211 0 : ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
6212 0 : } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
6213 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
6214 0 : ss << " && i < "<< nCurWindowSize << "; i++){\n ";
6215 : }
6216 : else {
6217 0 : ss << "0; i < "<< nCurWindowSize << "; i++){\n";
6218 : }
6219 : }
6220 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
6221 : {
6222 : const formula::SingleVectorRefToken* pSVR =
6223 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
6224 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
6225 0 : ss << " {\n";
6226 0 : ss << " if (isNan(";
6227 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
6228 0 : ss << "))\n";
6229 0 : ss << " arg"<<i<<"= 0;\n";
6230 0 : ss << " else\n";
6231 0 : ss << " arg"<<i<<"=";
6232 0 : ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
6233 0 : ss << ";\n";
6234 0 : ss << " }\n";
6235 0 : ss << " else\n";
6236 0 : ss << " arg"<<i<<"= 0;\n";
6237 : }
6238 0 : else if (pCur->GetType() == formula::svDouble)
6239 : {
6240 0 : ss << " if (isNan(";
6241 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
6242 0 : ss << "))\n";
6243 0 : ss << " arg"<<i<<"= 0;\n";
6244 0 : ss << " else\n";
6245 0 : ss << " arg"<<i<<"=";
6246 0 : ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
6247 0 : ss << ";\n";
6248 : }
6249 : }
6250 : ss << " if (arg0 == 0.0)\n"
6251 : " {\n"
6252 : " tmp=0.0;\n"
6253 : " return tmp;\n"
6254 : " }\n"
6255 : " else\n"
6256 : " {\n"
6257 : " bool bConvError;\n"
6258 : " double fStart = arg1 * arg2;\n"
6259 : " double fAx=fStart*0.5;\n"
6260 : " double fBx=fStart;\n"
6261 : " bConvError = false;\n"
6262 : " double fYEps = 1.0E-307;\n"
6263 : " double fXEps = 2.22045e-016;\n"
6264 : " double fAy = arg0-GetGammaInvValue(arg1,arg2,fAx);\n"
6265 : " double fBy = arg0-GetGammaInvValue(arg1,arg2,fBx);\n"
6266 : " double fTemp;\n"
6267 : " unsigned short nCount;\n"
6268 : " for (nCount = 0; nCount < 1000 && !((fAy < 0.0 && fBy > 0.0)"
6269 : " || (fAy > 0.0 && fBy < 0.0)); nCount++)\n"
6270 : " {\n"
6271 : " if (fabs(fAy) <= fabs(fBy))\n"
6272 : " {\n"
6273 : " fTemp = fAx;\n"
6274 : " fAx += 2.0 * (fAx - fBx);\n"
6275 : " if (fAx < 0.0)\n"
6276 : " fAx = 0.0;\n"
6277 : " fBx = fTemp;\n"
6278 : " fBy = fAy;\n"
6279 : " fAy = arg0-GetGammaInvValue(arg1,arg2,fAx);\n"
6280 : " }\n"
6281 : " else\n"
6282 : " {\n"
6283 : " fTemp = fBx;\n"
6284 : " fBx += 2.0 * (fBx - fAx);\n"
6285 : " fAx = fTemp;\n"
6286 : " fAy = fBy;\n"
6287 : " fBy = arg0-GetGammaInvValue(arg1,arg2,fBx);\n"
6288 : " }\n"
6289 : " }\n"
6290 : " if (fAy == 0.0)\n"
6291 : " {\n"
6292 : " tmp = fAx;\n"
6293 : " return tmp;\n"
6294 : " }\n"
6295 : " if (fBy == 0.0)\n"
6296 : " {\n"
6297 : " tmp = fBx;\n"
6298 : " return tmp;\n"
6299 : " }\n"
6300 : " if (!((fAy < 0.0 && fBy > 0.0) || (fAy > 0.0 && fBy < 0.0)))\n"
6301 : " {\n"
6302 : " bConvError = true;\n"
6303 : " tmp = 0.0;\n"
6304 : " return tmp;\n"
6305 : " }\n"
6306 : " double fPx = fAx;\n"
6307 : " double fPy = fAy;\n"
6308 : " double fQx = fBx;\n"
6309 : " double fQy = fBy;\n"
6310 : " double fRx = fAx;\n"
6311 : " double fRy = fAy;\n"
6312 : " double fSx = 0.5 * (fAx + fBx);\n"
6313 : " bool bHasToInterpolate = true;\n"
6314 : " nCount = 0;\n"
6315 : " while ( nCount < 500 && fabs(fRy) > fYEps &&"
6316 : "(fBx-fAx) > fmax( fabs(fAx), fabs(fBx)) * fXEps )\n"
6317 : " {\n"
6318 : " if (bHasToInterpolate)\n"
6319 : " {\n"
6320 : " if (fPy!=fQy && fQy!=fRy && fRy!=fPy)\n"
6321 : " {\n"
6322 : " fSx = fPx * fRy * fQy *pow( (fRy-fPy),-1) *pow"
6323 : "( (fQy-fPy),-1)"
6324 : "+ fRx * fQy * fPy *pow( (fQy-fRy),-1) *pow( (fPy-fRy),-1)"
6325 : "+ fQx * fPy * fRy *pow( (fPy-fQy),-1) *pow( (fRy-fQy),-1);\n"
6326 : " bHasToInterpolate = (fAx < fSx) && (fSx < fBx);\n"
6327 : " }\n"
6328 : " else\n"
6329 : " bHasToInterpolate = false;\n"
6330 : " }\n"
6331 : " if(!bHasToInterpolate)\n"
6332 : " {\n"
6333 : " fSx = 0.5 * (fAx + fBx);\n"
6334 : " fPx = fAx; fPy = fAy;\n"
6335 : " fQx = fBx; fQy = fBy;\n"
6336 : " bHasToInterpolate = true;\n"
6337 : " }\n"
6338 : " fPx = fQx; fQx = fRx; fRx = fSx;\n"
6339 : " fPy = fQy; fQy = fRy;\n"
6340 : " fRy = arg0-GetGammaInvValue(arg1,arg2,fSx);\n"
6341 : " if ((fAy < 0.0 && fRy > 0.0) || (fAy > 0.0 && fRy < 0.0))\n"
6342 : " {\n"
6343 : " fBx = fRx;\n"
6344 : " fBy = fRy;\n"
6345 : " }\n"
6346 : " else\n"
6347 : " {\n"
6348 : " fAx = fRx;\n"
6349 : " fAy = fRy;\n"
6350 : " }\n"
6351 : " bHasToInterpolate = bHasToInterpolate && (fabs(fRy)"
6352 : " * 2.0 <= fabs(fQy));\n"
6353 : " ++nCount;\n"
6354 : " }\n"
6355 : " tmp = fRx;\n"
6356 : " return tmp;\n"
6357 : " }\n"
6358 0 : "}\n";
6359 0 : }
6360 0 : void OpFInv::BinInlineFun(std::set<std::string>& decls,
6361 : std::set<std::string>& funs)
6362 : {
6363 0 : decls.insert(fMachEpsDecl);decls.insert(fMaxGammaArgumentDecl);
6364 0 : decls.insert(lcl_getLanczosSumDecl);decls.insert(GetBetaDecl);
6365 0 : decls.insert(GetLogBetaDecl);decls.insert(GetBetaDistPDFDecl);
6366 0 : decls.insert(lcl_GetBetaHelperContFracDecl);decls.insert(GetFInvValueDecl);
6367 0 : funs.insert(lcl_getLanczosSum);funs.insert(GetBeta);
6368 0 : funs.insert(GetLogBeta);funs.insert(GetBetaDistPDF);
6369 0 : funs.insert(lcl_GetBetaHelperContFrac);funs.insert(GetFInvValue);
6370 0 : }
6371 :
6372 0 : void OpFInv::GenSlidingWindowFunction(std::stringstream &ss,
6373 : const std::string &sSymName, SubArguments &vSubArguments)
6374 : {
6375 0 : ss << "\ndouble " << sSymName;
6376 0 : ss << "_"<< BinFuncName() <<"(";
6377 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
6378 : {
6379 0 : if (i)
6380 0 : ss << ",";
6381 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
6382 : }
6383 0 : ss << ") {\n";
6384 0 : ss << " int gid0=get_global_id(0);\n";
6385 0 : ss << " double tmp;\n";
6386 0 : ss << " double arg0,arg1,arg2;\n";
6387 0 : size_t i = vSubArguments.size();
6388 :
6389 0 : for (i = 0; i < vSubArguments.size(); i++)
6390 : {
6391 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
6392 : assert(pCur);
6393 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
6394 : {
6395 : const formula::DoubleVectorRefToken* pDVR =
6396 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
6397 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
6398 0 : ss << "for (int i = ";
6399 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
6400 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
6401 0 : ss << " && i < " << nCurWindowSize << "; i++){\n";
6402 0 : } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
6403 0 : ss << "0; i < " << pDVR->GetArrayLength();
6404 0 : ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
6405 0 : } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
6406 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
6407 0 : ss << " && i < "<< nCurWindowSize << "; i++){\n ";
6408 : }
6409 : else {
6410 0 : ss << "0; i < "<< nCurWindowSize << "; i++){\n";
6411 : }
6412 : }
6413 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
6414 : {
6415 : const formula::SingleVectorRefToken* pSVR =
6416 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
6417 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
6418 0 : ss << " {\n";
6419 0 : ss << " if (isNan(";
6420 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
6421 0 : ss << "))\n";
6422 0 : ss << " arg"<<i<<"= 0;\n";
6423 0 : ss << " else\n";
6424 0 : ss << " arg"<<i<<"="<<vSubArguments[i]->
6425 0 : GenSlidingWindowDeclRef();
6426 0 : ss << ";\n";
6427 0 : ss << " }\n";
6428 0 : ss << " else\n";
6429 0 : ss << " arg"<<i<<"= 0;\n";
6430 : }
6431 0 : else if (pCur->GetType() == formula::svDouble)
6432 : {
6433 0 : ss << " if (isNan(";
6434 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
6435 0 : ss << "))\n";
6436 0 : ss << " arg"<<i<<"= 0;\n";
6437 0 : ss << " else\n";
6438 0 : ss << " arg"<<i<<"="<<vSubArguments[i]->
6439 0 : GenSlidingWindowDeclRef();
6440 0 : ss << ";\n";
6441 : }
6442 : }
6443 : ss << " double fF2=floor(arg2);\n"
6444 : " double fF1=floor(arg1);\n"
6445 : " bool bConvError;\n"
6446 : " double fAx=fF1*0.5;\n"
6447 : " double fBx=fF1;\n"
6448 : " bConvError = false;\n"
6449 : " const double fYEps = 1.0E-307;\n"
6450 : " const double fXEps = 2.22045e-016;\n"
6451 : " double fAy = arg0-GetFInvValue(fF1,fF2,fAx);\n"
6452 : " double fBy = arg0-GetFInvValue(fF1,fF2,fBx);\n"
6453 : " double fTemp;\n"
6454 : " unsigned short nCount;\n"
6455 : " for (nCount = 0; nCount < 1000 && !((fAy < 0.0 && fBy > 0.0)"
6456 : " || (fAy > 0.0 && fBy < 0.0)); nCount++)\n"
6457 : " {\n"
6458 : " if (fabs(fAy) <= fabs(fBy))\n"
6459 : " {\n"
6460 : " fTemp = fAx;\n"
6461 : " fAx += 2.0 * (fAx - fBx);\n"
6462 : " if (fAx < 0.0)\n"
6463 : " fAx = 0.0;\n"
6464 : " fBx = fTemp;\n"
6465 : " fBy = fAy;\n"
6466 : " fAy = arg0-GetFInvValue(fF1,fF2,fAx);\n"
6467 : " }\n"
6468 : " else\n"
6469 : " {\n"
6470 : " fTemp = fBx;\n"
6471 : " fBx += 2.0 * (fBx - fAx);\n"
6472 : " fAx = fTemp;\n"
6473 : " fAy = fBy;\n"
6474 : " fBy = arg0-GetFInvValue(fF1,fF2,fBx);\n"
6475 : " }\n"
6476 : " }\n"
6477 : " if (fAy == 0.0)\n"
6478 : " {\n"
6479 : " tmp = fAx;\n"
6480 : " return tmp;\n"
6481 : " }\n"
6482 : " if (fBy == 0.0)\n"
6483 : " {\n"
6484 : " tmp = fBx;\n"
6485 : " return tmp;\n"
6486 : " }\n"
6487 : " if (!((fAy < 0.0 && fBy > 0.0) || (fAy > 0.0 && fBy < 0.0)))\n"
6488 : " {\n"
6489 : " bConvError = true;\n"
6490 : " tmp = 0.0;\n"
6491 : " return tmp;\n"
6492 : " }\n"
6493 : " double fPx = fAx;\n"
6494 : " double fPy = fAy;\n"
6495 : " double fQx = fBx;\n"
6496 : " double fQy = fBy;\n"
6497 : " double fRx = fAx;\n"
6498 : " double fRy = fAy;\n"
6499 : " double fSx = 0.5 * (fAx + fBx);\n"
6500 : " bool bHasToInterpolate = true;\n"
6501 : " nCount = 0;\n"
6502 : " while ( nCount < 500 && fabs(fRy) > fYEps &&"
6503 : "(fBx-fAx) > fmax( fabs(fAx), fabs(fBx)) * fXEps )\n"
6504 : " {\n"
6505 : " if (bHasToInterpolate)\n"
6506 : " {\n"
6507 : " if (fPy!=fQy && fQy!=fRy && fRy!=fPy)\n"
6508 : " {\n"
6509 : " fSx = fPx * fRy * fQy *pow( (fRy-fPy),-1)"
6510 : " *pow( (fQy-fPy),-1)+fRx * fQy * fPy*pow( (fQy-fRy),-1) *"
6511 : "pow( (fPy-fRy),-1)+ fQx * fPy * fRy *pow( (fPy-fQy),-1)"
6512 : " *pow((fRy-fQy),-1);\n"
6513 : " bHasToInterpolate = (fAx < fSx) && (fSx < fBx);\n"
6514 : " }\n"
6515 : " else\n"
6516 : " bHasToInterpolate = false;\n"
6517 : " }\n"
6518 : " if(!bHasToInterpolate)\n"
6519 : " {\n"
6520 : " fSx = 0.5 * (fAx + fBx);\n"
6521 : " fPx = fAx; fPy = fAy;\n"
6522 : " fQx = fBx; fQy = fBy;\n"
6523 : " bHasToInterpolate = true;\n"
6524 : " }\n"
6525 : " fPx = fQx; fQx = fRx; fRx = fSx;\n"
6526 : " fPy = fQy; fQy = fRy;\n"
6527 : " fRy = arg0-GetFInvValue(fF1,fF2,fSx);\n"
6528 : " if ((fAy < 0.0 && fRy > 0.0) || (fAy > 0.0 && fRy < 0.0))\n"
6529 : " {\n"
6530 : " fBx = fRx; fBy = fRy;\n"
6531 : " }\n"
6532 : " else\n"
6533 : " {\n"
6534 : " fAx = fRx; fAy = fRy;\n"
6535 : " }\n"
6536 : " bHasToInterpolate = bHasToInterpolate && (fabs(fRy)"
6537 : " * 2.0 <= fabs(fQy));\n"
6538 : " ++nCount;\n"
6539 : " }\n"
6540 : " tmp = fRx;\n"
6541 : " return tmp;"
6542 0 : "}";
6543 0 : }
6544 0 : void OpFTest::BinInlineFun(std::set<std::string>& decls,
6545 : std::set<std::string>& funs)
6546 : {
6547 0 : decls.insert(fMachEpsDecl);decls.insert(fMaxGammaArgumentDecl);
6548 0 : decls.insert(lcl_getLanczosSumDecl);decls.insert(GetBetaDecl);
6549 0 : decls.insert(GetLogBetaDecl);decls.insert(GetBetaDistPDFDecl);
6550 0 : decls.insert(lcl_GetBetaHelperContFracDecl);decls.insert(GetBetaDistDecl);
6551 0 : decls.insert(GetFDistDecl);
6552 0 : funs.insert(lcl_getLanczosSum);funs.insert(GetBeta);
6553 0 : funs.insert(GetLogBeta);funs.insert(GetBetaDistPDF);
6554 0 : funs.insert(lcl_GetBetaHelperContFrac);funs.insert(GetBetaDist);
6555 0 : funs.insert(GetFDist);
6556 0 : }
6557 0 : void OpFTest::GenSlidingWindowFunction(std::stringstream &ss,
6558 : const std::string &sSymName, SubArguments &vSubArguments)
6559 : {
6560 0 : FormulaToken *pCur = vSubArguments[0]->GetFormulaToken();
6561 : assert(pCur);
6562 : const formula::DoubleVectorRefToken* pCurDVR =
6563 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
6564 0 : size_t nCurWindowSize = pCurDVR->GetRefRowSize();
6565 0 : FormulaToken *pCur1 = vSubArguments[1]->GetFormulaToken();
6566 : assert(pCur1);
6567 : const formula::DoubleVectorRefToken* pCurDVR1 =
6568 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur1);
6569 0 : size_t nCurWindowSize1 = pCurDVR1->GetRefRowSize();
6570 0 : ss << "\ndouble " << sSymName;
6571 0 : ss << "_"<< BinFuncName() <<"( ";
6572 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
6573 : {
6574 0 : if (i)
6575 0 : ss << ",";
6576 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
6577 : }
6578 0 : ss << ") {\n";
6579 0 : ss << " int gid0 = get_global_id(0);\n";
6580 0 : ss << " double fSum1 = 0.0;\n";
6581 0 : ss << " double fSumSqr1 = 0.0;\n";
6582 0 : ss << " double fSum2 = 0.0;\n";
6583 0 : ss << " double fSumSqr2 = 0.0;\n";
6584 0 : ss << " int length0="<<nCurWindowSize;
6585 0 : ss << ";\n";
6586 0 : ss << " int length1= "<<nCurWindowSize1;
6587 0 : ss << ";\n";
6588 0 : ss << " double tmp = 0;\n";
6589 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
6590 : {
6591 0 : FormulaToken *pCurSub = vSubArguments[i]->GetFormulaToken();
6592 : assert(pCurSub);
6593 0 : if (pCurSub->GetType() == formula::svDoubleVectorRef)
6594 : {
6595 : const formula::DoubleVectorRefToken* pDVR =
6596 0 : static_cast<const formula::DoubleVectorRefToken *>(pCurSub);
6597 0 : ss << " for (int i = ";
6598 0 : ss << "0; i < "<< pDVR->GetRefRowSize() << "; i++){\n";
6599 0 : ss << " double arg"<<i<<" = ";
6600 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef(true);
6601 0 : ss << ";\n";
6602 0 : ss << " if(isNan(arg"<<i<<")||((gid0+i)>=";
6603 0 : ss << pDVR->GetArrayLength();
6604 0 : ss << "))\n";
6605 0 : ss << " {\n";
6606 0 : ss << " length"<<i<<"--;\n";
6607 0 : ss << " continue;\n";
6608 0 : ss << " }\n";
6609 0 : ss << " fSum"<<i+1<<" += arg"<<i<<";\n";
6610 0 : ss << " fSumSqr"<<i+1<<" += arg"<<i;
6611 0 : ss << " * arg"<<i<<";\n";
6612 0 : ss << " }\n";
6613 : }
6614 0 : else if (pCurSub->GetType() == formula::svSingleVectorRef)
6615 : {
6616 0 : ss << "return HUGE_VAL";
6617 : }
6618 0 : else if (pCurSub->GetType() == formula::svDouble)
6619 : {
6620 0 : ss << "return HUGE_VAL";
6621 : }
6622 : }
6623 : ss << " double fS1 = (fSumSqr1-fSum1*fSum1/length0)/(length0-1.0);\n"
6624 : " double fS2 = (fSumSqr2-fSum2*fSum2/length1)/(length1-1.0);\n"
6625 : " double fF, fF1, fF2;\n"
6626 : " if (fS1 > fS2)\n"
6627 : " {\n"
6628 : " fF = fS1/fS2;\n"
6629 : " fF1 = length0-1.0;\n"
6630 : " fF2 = length1-1.0;\n"
6631 : " }\n"
6632 : " else\n"
6633 : " {\n"
6634 : " fF = fS2/fS1;\n"
6635 : " fF1 = length1-1.0;\n"
6636 : " fF2 = length0-1.0;\n"
6637 : " }\n"
6638 0 : " tmp = 2.0*GetFDist(fF, fF1, fF2);\n";
6639 0 : ss << " return tmp;\n";
6640 0 : ss << "}";
6641 0 : }
6642 0 : void OpB::BinInlineFun(std::set<std::string>& decls,
6643 : std::set<std::string>& funs)
6644 : {
6645 : //decls.insert(fBigInvDecl);decls.insert(fLogDblMaxDecl);
6646 0 : decls.insert(GetBinomDistPMFDecl);decls.insert(MinDecl);
6647 0 : decls.insert(fMachEpsDecl);decls.insert(fMaxGammaArgumentDecl);
6648 0 : decls.insert(GetBetaDistDecl);decls.insert(GetBetaDistPDFDecl);
6649 0 : decls.insert(lcl_GetBetaHelperContFracDecl);decls.insert(GetLogBetaDecl);
6650 0 : decls.insert(lcl_getLanczosSumDecl); decls.insert(GetBetaDecl);
6651 0 : funs.insert(GetBinomDistPMF);funs.insert(lcl_GetBinomDistRange);
6652 0 : funs.insert(GetBetaDist);funs.insert(GetBetaDistPDF);
6653 0 : funs.insert(lcl_GetBetaHelperContFrac);funs.insert(GetLogBeta);
6654 0 : funs.insert(lcl_getLanczosSum);funs.insert(GetBeta);
6655 0 : }
6656 :
6657 0 : void OpB::GenSlidingWindowFunction(std::stringstream &ss,
6658 : const std::string &sSymName, SubArguments &vSubArguments)
6659 : {
6660 0 : ss << "\ndouble " << sSymName;
6661 0 : ss << "_"<< BinFuncName() <<"(";
6662 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
6663 : {
6664 0 : if (i)
6665 0 : ss << ",";
6666 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
6667 : }
6668 0 : ss << ") {\n";
6669 0 : ss << " int gid0=get_global_id(0);\n";
6670 0 : ss << " double min = 2.22507e-308;\n";
6671 0 : ss << " double tmp;\n";
6672 0 : ss << " double arg0,arg1,arg2,arg3;\n";
6673 0 : size_t i = vSubArguments.size();
6674 0 : for (i = 0; i < vSubArguments.size(); i++)
6675 : {
6676 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
6677 : assert(pCur);
6678 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
6679 : {
6680 : const formula::DoubleVectorRefToken* pDVR =
6681 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
6682 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
6683 0 : ss << "for (int i = ";
6684 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
6685 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
6686 0 : ss << " && i < " << nCurWindowSize << "; i++){\n";
6687 0 : } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
6688 0 : ss << "0; i < " << pDVR->GetArrayLength();
6689 0 : ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
6690 0 : } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
6691 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
6692 0 : ss << " && i < "<< nCurWindowSize << "; i++){\n ";
6693 : }
6694 : else {
6695 0 : ss << "0; i < "<< nCurWindowSize << "; i++){\n";
6696 : }
6697 : }
6698 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
6699 : {
6700 : const formula::SingleVectorRefToken* pSVR =
6701 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
6702 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
6703 0 : ss << " {\n";
6704 0 : ss << " if (isNan(";
6705 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
6706 0 : ss << "))\n";
6707 0 : ss << " arg"<<i<<"= 0;\n";
6708 0 : ss << " else\n";
6709 0 : ss << " arg"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
6710 0 : ss << ";\n";
6711 0 : ss << " }\n";
6712 0 : ss << " else\n";
6713 0 : ss << " arg"<<i<<"= 0;\n";
6714 : }
6715 0 : else if (pCur->GetType() == formula::svDouble)
6716 : {
6717 0 : ss << " if (isNan(";
6718 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
6719 0 : ss << "))\n";
6720 0 : ss << " arg"<<i<<"= 0;\n";
6721 0 : ss << " else\n";
6722 0 : ss << " arg"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
6723 0 : ss << ";\n";
6724 : }
6725 : }
6726 : ss << " double rxs = floor(arg2);\n"
6727 : " double rxe = floor(arg3);\n"
6728 : " double rn = floor(arg0);\n"
6729 : " double rq = (0.5 - arg1) + 0.5;\n"
6730 : " bool bIsValidX = (0.0 <= rxs && rxs <= rxe && rxe <= rn);\n"
6731 : " if (bIsValidX && 0.0 < arg1 && arg1 < 1.0)\n"
6732 : " {\n"
6733 : " if (rxs == rxe)\n"
6734 : " tmp = GetBinomDistPMF(rxs, rn, arg1);\n"
6735 : " else\n"
6736 : " {\n"
6737 : " double fFactor = pow(rq, rn);\n"
6738 : " if (fFactor > min)\n"
6739 : " tmp ="
6740 : " lcl_GetBinomDistRange(rn, rxs, rxe, fFactor, arg1, rq);\n"
6741 : " else\n"
6742 : " {\n"
6743 : " fFactor = pow(arg1, rn);\n"
6744 : " if (fFactor > min)\n"
6745 : " {\n"
6746 : " tmp ="
6747 : "lcl_GetBinomDistRange(rn, rn - rxe, rn - rxs, fFactor, rq, arg1);\n"
6748 : " }\n"
6749 : " else\n"
6750 : " tmp ="
6751 : "GetBetaDist(rq, rn - rxe, rxe + 1.0)"
6752 : "- GetBetaDist(rq, rn - rxs + 1, rxs);\n"
6753 : " }\n"
6754 : " }\n"
6755 : " }\n"
6756 : " else\n"
6757 : " {\n"
6758 : " if (bIsValidX)\n"
6759 : " {\n"
6760 : " if (arg1 == 0.0)\n"
6761 : " tmp = (rxs == 0.0 ? 1.0 : 0.0);\n"
6762 : " else if (arg1 == 1.0)\n"
6763 : " tmp = (rxe == rn ? 1.0 : 0.0);\n"
6764 : " else\n"
6765 : " {\n"
6766 : " tmp = DBL_MIN;\n"
6767 : " }\n"
6768 : " }\n"
6769 : " else\n"
6770 : " {\n"
6771 : " tmp = DBL_MIN;\n"
6772 : " }\n"
6773 : " }\n"
6774 : " return tmp;"
6775 0 : "}\n";
6776 0 : }
6777 0 : void OpBetaDist::BinInlineFun(std::set<std::string>& decls,
6778 : std::set<std::string>& funs)
6779 : {
6780 0 : decls.insert(fMachEpsDecl);decls.insert(fMaxGammaArgumentDecl);
6781 0 : decls.insert(GetBetaDistDecl);decls.insert(GetBetaDistPDFDecl);
6782 0 : decls.insert(lcl_GetBetaHelperContFracDecl);decls.insert(GetLogBetaDecl);
6783 0 : decls.insert(GetBetaDecl);decls.insert(lcl_getLanczosSumDecl);
6784 0 : funs.insert(GetBetaDist);funs.insert(GetBetaDistPDF);
6785 0 : funs.insert(lcl_GetBetaHelperContFrac);funs.insert(GetLogBeta);
6786 0 : funs.insert(GetBeta);funs.insert(lcl_getLanczosSum);
6787 0 : }
6788 0 : void OpPoisson::BinInlineFun(std::set<std::string>& decls,
6789 : std::set<std::string>& funs)
6790 : {
6791 0 : decls.insert(fHalfMachEpsDecl);
6792 0 : funs.insert("");
6793 0 : decls.insert(fMaxGammaArgumentDecl);
6794 0 : funs.insert("");
6795 0 : decls.insert(fBigInvDecl);
6796 0 : funs.insert("");
6797 0 : decls.insert(GetLogGammaDecl);
6798 0 : funs.insert(GetLogGamma);
6799 0 : decls.insert(lcl_GetLogGammaHelperDecl);
6800 0 : funs.insert(lcl_GetLogGammaHelper);
6801 0 : decls.insert(lcl_GetGammaHelperDecl);
6802 0 : funs.insert(lcl_GetGammaHelper);
6803 0 : decls.insert(lcl_getLanczosSumDecl);
6804 0 : funs.insert(lcl_getLanczosSum);
6805 0 : decls.insert(GetUpRegIGammaDecl);
6806 0 : funs.insert(GetUpRegIGamma);
6807 0 : decls.insert(GetGammaContFractionDecl);
6808 0 : funs.insert(GetGammaContFraction);
6809 0 : decls.insert(GetGammaSeriesDecl);
6810 0 : funs.insert(GetGammaSeries);
6811 0 : }
6812 0 : void OpPoisson::GenSlidingWindowFunction(
6813 : std::stringstream &ss,const std::string &sSymName,
6814 : SubArguments &vSubArguments)
6815 : {
6816 0 : ss << "\ndouble " << sSymName;
6817 0 : ss << "_"<< BinFuncName() <<"(";
6818 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
6819 : {
6820 0 : if (i)
6821 0 : ss << ",";
6822 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
6823 : }
6824 0 : ss << ")\n";
6825 0 : ss << "{\n";
6826 0 : ss << " double x,lambda,tmp,tmp0,tmp1,tmp2;\n";
6827 0 : ss << " int bCumulative;\n";
6828 0 : ss << " int gid0=get_global_id(0);\n";
6829 0 : size_t i = vSubArguments.size();
6830 0 : ss <<"\n ";
6831 0 : for (i = 0; i < vSubArguments.size(); i++)
6832 : {
6833 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
6834 : assert(pCur);
6835 0 : if (pCur->GetType() == formula::svSingleVectorRef)
6836 : {
6837 : const formula::SingleVectorRefToken* pSVR =
6838 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
6839 0 : ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
6840 : }
6841 0 : else if (pCur->GetType() == formula::svDouble)
6842 : {
6843 0 : ss << "{\n";
6844 : }
6845 : else
6846 : {
6847 : }
6848 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
6849 : {
6850 0 : ss << " if (isNan(";
6851 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
6852 0 : ss << "))\n";
6853 0 : ss << " tmp"<<i<<"= 0;\n";
6854 0 : ss << " else\n";
6855 0 : ss << " tmp"<<i<<"=\n";
6856 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
6857 0 : ss << ";\n}\n";
6858 : }
6859 : else
6860 : {
6861 0 : ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
6862 0 : ss <<";\n";
6863 : }
6864 : }
6865 0 : ss << " x = floor(tmp0);\n";
6866 0 : ss << " lambda = tmp1;\n";
6867 0 : ss << " bCumulative = tmp2;\n ";
6868 0 : ss << " if (!bCumulative)\n";
6869 0 : ss << " {\n";
6870 0 : ss << " if(lambda == 0.0)\n";
6871 0 : ss << " {\n";
6872 0 : ss << " return 0;\n";
6873 0 : ss << " }\n";
6874 0 : ss << " else\n";
6875 0 : ss << " {\n";
6876 0 : ss << " if (lambda >712)\n";
6877 0 : ss << " {\n";
6878 0 : ss << " tmp = (exp(x*log(lambda)-lambda-GetLogGamma(x+1.0)));\n";
6879 0 : ss << " return tmp;\n";
6880 0 : ss << " }\n";
6881 0 : ss << " else\n";
6882 0 : ss << " {\n";
6883 0 : ss << " double fPoissonVar = 1.0;\n";
6884 0 : ss << " for ( int f = 0; f < x; ++f )\n";
6885 0 : ss << " fPoissonVar *= lambda * pow(( (double)f + 1.0 ),-1);\n";
6886 0 : ss << " tmp = ( fPoissonVar * exp( -lambda ) );\n";
6887 0 : ss << " return tmp;\n";
6888 0 : ss << " }\n";
6889 0 : ss << " }\n";
6890 0 : ss << " } \n";
6891 0 : ss << " else\n";
6892 0 : ss << " {\n";
6893 0 : ss << " if (lambda == 0.0)\n";
6894 0 : ss << " {\n";
6895 0 : ss << " return 1;\n";
6896 0 : ss << " }\n";
6897 0 : ss << " else\n";
6898 0 : ss << " {\n";
6899 0 : ss << " if (lambda > 712 )\n";
6900 0 : ss << " {\n";
6901 0 : ss << " tmp = (GetUpRegIGamma(x+1.0,lambda));\n";
6902 0 : ss << " return tmp;\n";
6903 0 : ss << " }\n";
6904 0 : ss << " else\n";
6905 0 : ss << " {\n";
6906 0 : ss << " if (x >= 936.0)\n";
6907 0 : ss << " {\n";
6908 0 : ss << " return 1;\n";
6909 0 : ss << " }\n";
6910 0 : ss << " else\n";
6911 0 : ss << " {\n";
6912 0 : ss << " double fSummand = exp(-lambda);\n";
6913 0 : ss << " double fSum = fSummand;\n";
6914 0 : ss << " int nEnd = (int) (x + 0.5);\n";
6915 0 : ss << " for (int i = 1; i <= nEnd; i++)\n";
6916 0 : ss << " {\n";
6917 0 : ss << " fSummand = (fSummand*lambda)*pow((double)i,-1);\n";
6918 0 : ss << " fSum += fSummand;\n";
6919 0 : ss << " }\n";
6920 0 : ss << " tmp = fSum;\n";
6921 0 : ss << " return tmp;\n";
6922 0 : ss << " }\n";
6923 0 : ss << " }\n";
6924 0 : ss << " }\n";
6925 0 : ss << " }\n";
6926 0 : ss << "}\n";
6927 0 : }
6928 0 : void OpCovar::GenSlidingWindowFunction(std::stringstream& ss,
6929 : const std::string &sSymName, SubArguments& vSubArguments)
6930 : {
6931 0 : ss << "\ndouble " << sSymName;
6932 0 : ss << "_"<< BinFuncName() <<"(";
6933 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
6934 : {
6935 0 : if (i)
6936 0 : ss << ",";
6937 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
6938 : }
6939 0 : ss << ") {\n";
6940 0 : ss << " int gid0 = get_global_id(0);\n";
6941 0 : ss << " double vSum = 0.0;\n";
6942 0 : ss << " double vSum0 = 0.0;\n";
6943 0 : ss << " double vSum1 = 0.0;\n";
6944 0 : ss << " double vMean0 = 0.0;\n";
6945 0 : ss << " double vMean1 = 0.0;\n";
6946 0 : ss << " double arg0 = 0.0;\n";
6947 0 : ss << " double arg1 = 0.0;\n";
6948 0 : FormulaToken* pCurX = vSubArguments[0]->GetFormulaToken();
6949 0 : FormulaToken* pCurY = vSubArguments[1]->GetFormulaToken();
6950 0 : if ((pCurX->GetType() == formula::svDoubleVectorRef)&&
6951 0 : (pCurY->GetType() == formula::svDoubleVectorRef)){
6952 0 : ss << " int cnt = 0;\n";
6953 : const formula::DoubleVectorRefToken* pCurDVRX =
6954 0 : static_cast<const formula::DoubleVectorRefToken* >(pCurX);
6955 : const formula::DoubleVectorRefToken* pCurDVRY =
6956 0 : static_cast<const formula::DoubleVectorRefToken* >(pCurY);
6957 0 : size_t nCurWindowSizeX = pCurDVRX->GetRefRowSize();
6958 0 : size_t nCurWindowSizeY = pCurDVRY->GetRefRowSize();
6959 0 : if(nCurWindowSizeX == nCurWindowSizeY)
6960 : {
6961 0 : ss << " for( ";
6962 0 : if (!pCurDVRX->IsStartFixed() && pCurDVRX->IsEndFixed()) {
6963 0 : ss << "int i = gid0; i < " << nCurWindowSizeX;
6964 0 : ss << " && i < " << pCurDVRX->GetArrayLength() << " && i < ";
6965 0 : ss << pCurDVRY->GetArrayLength() << "; i++){\n";
6966 0 : ss << " if(isNan(";
6967 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ") ||";
6968 0 : ss << " isNan("<< vSubArguments[1]->GenSlidingWindowDeclRef();
6969 0 : ss << ")) {\n";
6970 0 : ss << " arg0 = 0.0;\n";
6971 0 : ss << " arg1 = 0.0;\n";
6972 0 : ss << " --cnt;\n";
6973 0 : ss << " }\n";
6974 0 : ss << "else{\n";
6975 0 : ss << " arg0 = ";
6976 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
6977 0 : ss << " arg1 = ";
6978 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
6979 0 : ss << "}\n";
6980 0 : ss << " ++cnt;\n";
6981 0 : ss << " vSum0 += arg0;\n";
6982 0 : ss << " vSum1 += arg1;\n";
6983 0 : ss << " }\n";
6984 : }
6985 0 : else if (pCurDVRX->IsStartFixed() && !pCurDVRX->IsEndFixed()) {
6986 0 : ss << "int i = 0; i < gid0 + " << nCurWindowSizeX << " && ";
6987 0 : ss << " i < " << pCurDVRX->GetArrayLength() << " && ";
6988 0 : ss << " i < " << pCurDVRY->GetArrayLength() << "; i++) {\n";
6989 0 : ss << " if(isNan(";
6990 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ") ||";
6991 0 : ss << " isNan(" << vSubArguments[1]->GenSlidingWindowDeclRef();
6992 0 : ss << ")) {\n";
6993 0 : ss << " arg0 = 0.0;\n";
6994 0 : ss << " arg1 = 0.0;\n";
6995 0 : ss << " --cnt;\n";
6996 0 : ss << " }\n";
6997 0 : ss << "else{\n";
6998 0 : ss << " arg0 = ";
6999 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
7000 0 : ss << " arg1 = ";
7001 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";}\n";
7002 0 : ss << " ++cnt;\n";
7003 0 : ss << " vSum0 += arg0;\n";
7004 0 : ss << " vSum1 += arg1;\n";
7005 0 : ss << " }\n";
7006 : }
7007 0 : else if (pCurDVRX->IsStartFixed() && pCurDVRX->IsEndFixed()) {
7008 0 : ss << "int i = 0; i < " << nCurWindowSizeX << " && i < ";
7009 0 : ss << pCurDVRX->GetArrayLength() << " && i < ";
7010 0 : ss << pCurDVRY->GetArrayLength() << "; i++) {\n";
7011 0 : ss << " if(isNan(";
7012 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ") ||";
7013 0 : ss << " isNan(" << vSubArguments[1]->GenSlidingWindowDeclRef();
7014 0 : ss << ")) {\n";
7015 0 : ss << " arg0 = 0.0;\n";
7016 0 : ss << " arg1 = 0.0;\n";
7017 0 : ss << " --cnt;\n";
7018 0 : ss << " }\n";
7019 0 : ss << "else{\n";
7020 0 : ss << " arg0 = ";
7021 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
7022 0 : ss << " arg1 = ";
7023 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";}\n";
7024 0 : ss << " ++cnt;\n";
7025 0 : ss << " vSum0 += arg0;\n";
7026 0 : ss << " vSum1 += arg1;\n";
7027 0 : ss << " }\n";
7028 : }
7029 : else {
7030 0 : ss << "int i = 0; i < " << nCurWindowSizeX << " && ";
7031 0 : ss << " i + gid0 < " << pCurDVRX->GetArrayLength();
7032 0 : ss << " && i + gid0 < " << pCurDVRX->GetArrayLength();
7033 0 : ss << "; i++) {\n";
7034 0 : ss << "if ((isNan(";
7035 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ")) || ";
7036 0 : ss << "(isNan("<< vSubArguments[1]->GenSlidingWindowDeclRef();
7037 0 : ss << "))) {\n";
7038 0 : ss << " arg0 = 0.0;\n";
7039 0 : ss << " arg1 = 0.0;\n";
7040 0 : ss << " --cnt;\n";
7041 0 : ss << " }\n";
7042 0 : ss << " else {\n";
7043 0 : ss << " arg0 = ";
7044 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
7045 0 : ss << " arg1 = ";
7046 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
7047 0 : ss << " }\n";
7048 0 : ss << " ++cnt;\n";
7049 0 : ss << " vSum0 += arg0;\n";
7050 0 : ss << " vSum1 += arg1;\n";
7051 0 : ss << " }\n";
7052 : }
7053 0 : ss << " if(cnt < 1) {\n";
7054 0 : ss << " return CreateDoubleError(errNoValue);\n";
7055 0 : ss << " }\n";
7056 0 : ss << " else {\n";
7057 0 : ss << " vMean0 = vSum0 / cnt;\n";
7058 0 : ss << " vMean1 = vSum1 / cnt;\n";
7059 0 : ss << " for(";
7060 0 : if (!pCurDVRX->IsStartFixed() && pCurDVRX->IsEndFixed()) {
7061 0 : ss << "int i = gid0; i < " << nCurWindowSizeX;
7062 0 : ss << " && i < " << pCurDVRX->GetArrayLength() << " && i < ";
7063 0 : ss << pCurDVRY->GetArrayLength() << "; i++){\n";
7064 0 : ss << " if(isNan(";
7065 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ") ||";
7066 0 : ss << " isNan(" << vSubArguments[1]->GenSlidingWindowDeclRef();
7067 0 : ss << ")){\n";
7068 0 : ss << " arg0 = vMean0;\n";
7069 0 : ss << " arg1 = vMean1;\n";
7070 0 : ss << " }\n";
7071 0 : ss << " else{\n";
7072 0 : ss << " arg0 = ";
7073 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
7074 0 : ss << " arg1 = ";
7075 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";}\n";
7076 0 : ss << " vSum += (arg0 - vMean0) * (arg1 - vMean1);\n";
7077 0 : ss << " }\n";
7078 : }
7079 0 : else if (pCurDVRX->IsStartFixed() && !pCurDVRX->IsEndFixed()) {
7080 0 : ss << "int i = 0; i < gid0 + " << nCurWindowSizeX << " && ";
7081 0 : ss << " i < " << pCurDVRX->GetArrayLength() << " && ";
7082 0 : ss << " i < " << pCurDVRY->GetArrayLength() << "; i++) {\n";
7083 0 : ss << " if(isNan(";
7084 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ") || ";
7085 0 : ss << "isNan(" << vSubArguments[1]->GenSlidingWindowDeclRef();
7086 0 : ss << ")) {\n";
7087 0 : ss << " arg0 = vMean0;\n";
7088 0 : ss << " arg1 = vMean1;\n";
7089 0 : ss << " }\n";
7090 0 : ss << "else{\n";
7091 0 : ss << " arg0 = ";
7092 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
7093 0 : ss << " arg1 = ";
7094 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";}\n";
7095 0 : ss << " vSum += (arg0 - vMean0) * (arg1 - vMean1);\n";
7096 0 : ss << " }\n";
7097 : }
7098 0 : else if (pCurDVRX->IsStartFixed() && pCurDVRX->IsEndFixed()) {
7099 0 : ss << "int i = 0; i < " << nCurWindowSizeX << " && i < ";
7100 0 : ss << pCurDVRX->GetArrayLength() << " && i < ";
7101 0 : ss << pCurDVRY->GetArrayLength() << "; i++) {\n";
7102 0 : ss << " if(isNan(";
7103 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ") || ";
7104 0 : ss << "isNan(" << vSubArguments[1]->GenSlidingWindowDeclRef();
7105 0 : ss << ")) {\n";
7106 0 : ss << " arg0 = vMean0;\n";
7107 0 : ss << " arg1 = vMean1;\n";
7108 0 : ss << " }\n";
7109 0 : ss << "else{\n";
7110 0 : ss << " arg0 = ";
7111 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
7112 0 : ss << " arg1 = ";
7113 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";}\n";
7114 0 : ss << " vSum += (arg0 - vMean0) * (arg1 - vMean1);\n";
7115 0 : ss << " }\n";
7116 : }
7117 : else {
7118 0 : ss << "int i = 0; i < " << nCurWindowSizeX << " && ";
7119 0 : ss << " i + gid0 < " << pCurDVRX->GetArrayLength();
7120 0 : ss << " && i + gid0 < " << pCurDVRX->GetArrayLength();
7121 0 : ss << "; i++) {\n";
7122 0 : ss << "if((isNan(";
7123 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ")) || ";
7124 0 : ss << "(isNan(" << vSubArguments[1]->GenSlidingWindowDeclRef();
7125 0 : ss << "))) {\n";
7126 0 : ss << " arg0 = vMean0;\n";
7127 0 : ss << " arg1 = vMean1;\n";
7128 0 : ss << " }\n";
7129 0 : ss << " else{\n";
7130 0 : ss << " arg0 = ";
7131 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
7132 0 : ss << " arg1 = ";
7133 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
7134 0 : ss << " }\n";
7135 0 : ss << " vSum += (arg0 - vMean0) * (arg1 - vMean1);\n";
7136 0 : ss << " }\n";
7137 : }
7138 0 : ss << " return vSum / cnt;\n";
7139 0 : ss << " }\n";
7140 0 : ss << "}";
7141 : }
7142 : }
7143 : else {
7144 0 : ss << " int cnt0 = 0,cnt1 = 0;\n";
7145 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
7146 : {
7147 0 : FormulaToken* pCur = vSubArguments[i]->GetFormulaToken();
7148 0 : if (pCur->GetType() == formula::svSingleVectorRef){
7149 : const formula::SingleVectorRefToken* pTVR =
7150 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
7151 0 : ss << " if(isNan(";
7152 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
7153 0 : ss << ") || gid0 >= " << pTVR->GetArrayLength() << ")\n";
7154 0 : ss << " arg" << i << " = 0;\n else\n";
7155 0 : ss << " arg" << i << " = ";
7156 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
7157 0 : ss << " cnt" << i << "++;\n";
7158 0 : ss << " vSum" << i << " += arg" << i << ";\n";
7159 : }
7160 0 : else if (pCur->GetType() == formula::svDouble){
7161 0 : ss << " if(isNan ( ";
7162 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << "))\n";
7163 0 : ss << " arg" << i << " = 0;\n else\n";
7164 0 : ss << " arg" << i << " = ";
7165 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
7166 0 : ss << " cnt" << i << "++;\n";
7167 0 : ss << " vSum" << i << " += arg" << i << ";\n";
7168 : }
7169 : else {
7170 0 : ss << " arg" << i << " = ";
7171 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
7172 0 : ss << " cnt" << i << "++;\n";
7173 0 : ss << " vSum" << i << " += arg" << i << ";\n";
7174 : }
7175 : }
7176 0 : ss << " vMean0 = vSum0 / cnt0;\n";
7177 0 : ss << " vMean1 = vSum0 / cnt1;\n";
7178 0 : for(size_t i = 0; i < vSubArguments.size(); i++ ) {
7179 0 : FormulaToken* pCur = vSubArguments[i]->GetFormulaToken();
7180 0 : if (pCur->GetType() == formula::svSingleVectorRef) {
7181 : const formula::SingleVectorRefToken* pTVR =
7182 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
7183 0 : ss << " if(isNan(";
7184 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
7185 0 : ss << ") || gid0 >= " << pTVR->GetArrayLength() << ")\n";
7186 0 : ss << " arg" << i << " = vMean" << i << ";\n";
7187 0 : ss << " else\n";
7188 0 : ss << " arg" << i << " = ";
7189 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
7190 : }
7191 0 : else if (pCur->GetType() == formula::svDouble) {
7192 0 : ss << " arg" << i << " = ";
7193 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
7194 0 : ss << " if(isNan(arg" << i << "))\n";
7195 0 : ss << " arg" << i << " = vMean" << i << ";\n";
7196 : }
7197 : else {
7198 0 : ss << " arg" << i << " = ";
7199 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
7200 : }
7201 : }
7202 0 : ss << " vSum += (arg0 - vMean0) * ( arg1 - vMean1 );\n";
7203 0 : ss << " return vSum / cnt0;\n";
7204 0 : ss << "}";
7205 : }
7206 0 : }
7207 0 : void OpBetaDist::GenSlidingWindowFunction(std::stringstream &ss,
7208 : const std::string &sSymName, SubArguments &vSubArguments)
7209 : {
7210 0 : ss << "\ndouble " << sSymName;
7211 0 : ss << "_"<< BinFuncName() <<"(";
7212 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
7213 : {
7214 0 : if (i)
7215 0 : ss << ",";
7216 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
7217 : }
7218 0 : ss << ") {\n";
7219 0 : ss << " int gid0=get_global_id(0);\n";
7220 0 : ss << " double tmp;\n";
7221 0 : ss << " double arg0,arg1,arg2,arg3,arg4,arg5;\n";
7222 0 : size_t i = vSubArguments.size();
7223 :
7224 0 : for (i = 0; i < vSubArguments.size(); i++)
7225 : {
7226 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
7227 : assert(pCur);
7228 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
7229 : {
7230 : const formula::DoubleVectorRefToken* pDVR =
7231 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
7232 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
7233 0 : ss << "for (int i = ";
7234 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
7235 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
7236 0 : ss << " && i < " << nCurWindowSize << "; i++){\n";
7237 0 : } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
7238 0 : ss << "0; i < " << pDVR->GetArrayLength();
7239 0 : ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
7240 0 : } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
7241 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
7242 0 : ss << " && i < "<< nCurWindowSize << "; i++){\n ";
7243 : }
7244 : else {
7245 0 : ss << "0; i < "<< nCurWindowSize << "; i++){\n";
7246 : }
7247 :
7248 : }
7249 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
7250 : {
7251 : const formula::SingleVectorRefToken* pSVR =
7252 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
7253 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
7254 0 : ss << " {\n";
7255 0 : ss << " if (isNan(";
7256 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
7257 0 : ss << "))\n";
7258 0 : ss << " arg"<<i<<"= 0;\n";
7259 0 : ss << " else\n";
7260 0 : ss << " arg"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
7261 0 : ss << ";\n";
7262 0 : ss << " }\n";
7263 0 : ss << " else\n";
7264 0 : ss << " arg"<<i<<"= 0;\n";
7265 : }
7266 0 : else if (pCur->GetType() == formula::svDouble)
7267 : {
7268 0 : ss << " if (isNan(";
7269 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
7270 0 : ss << "))\n";
7271 0 : ss << " arg"<<i<<"= 0;\n";
7272 0 : ss << " else\n";
7273 0 : ss << " arg"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
7274 0 : ss << ";\n";
7275 : }
7276 : }
7277 : ss << " double fScale = arg4 - arg3;\n"
7278 : " if (fScale <= 0.0 || arg1 <= 0.0 || arg2 <= 0.0)\n"
7279 : " {\n"
7280 : " tmp = DBL_MIN;\n"
7281 : " return tmp;\n"
7282 : " }\n"
7283 : " if (arg5)\n"
7284 : " {\n"
7285 : " if (arg0< arg3)\n"
7286 : " {\n"
7287 : " tmp = 0.0;\n"
7288 : " return tmp;\n"
7289 : " }\n"
7290 : " if (arg0 > arg4)\n"
7291 : " {\n"
7292 : " tmp = 1.0;\n"
7293 : " return tmp;\n"
7294 : " }\n"
7295 : " arg0 = (arg0-arg3)*pow(fScale,-1);\n"
7296 : " tmp = GetBetaDist(arg0, arg1, arg2);\n"
7297 : " }\n"
7298 : " else\n"
7299 : " {\n"
7300 : " if (arg0 < arg3 || arg0 > arg4 )\n"
7301 : " {\n"
7302 : " tmp = 0.0;\n"
7303 : " return tmp;\n"
7304 : " }\n"
7305 : " arg0 = (arg0 - arg3)*pow(fScale,-1);\n"
7306 : " tmp = GetBetaDistPDF(arg0, arg1, arg2)*pow(fScale,-1);\n"
7307 0 : " }\n";
7308 0 : ss << " return tmp;\n";
7309 0 : ss << "}\n";
7310 0 : }
7311 0 : void OpBetainv::BinInlineFun(std::set<std::string>& decls,
7312 : std::set<std::string>& funs)
7313 : {
7314 0 : decls.insert(fMachEpsDecl);
7315 0 : funs.insert("");
7316 0 : decls.insert(fMaxGammaArgumentDecl);
7317 0 : funs.insert("");
7318 0 : decls.insert(lcl_IterateInverseBetaInvDecl);
7319 0 : funs.insert(lcl_IterateInverseBetaInv);
7320 0 : decls.insert(GetBetaDistDecl);
7321 0 : funs.insert(GetBetaDist);
7322 0 : decls.insert(lcl_HasChangeOfSignDecl);
7323 0 : funs.insert(lcl_HasChangeOfSign);
7324 0 : decls.insert(lcl_HasChangeOfSignDecl);
7325 0 : funs.insert(lcl_HasChangeOfSign);
7326 0 : decls.insert(lcl_HasChangeOfSignDecl);
7327 0 : funs.insert(lcl_HasChangeOfSign);
7328 0 : decls.insert(lcl_GetBetaHelperContFracDecl);
7329 0 : funs.insert(lcl_GetBetaHelperContFrac);
7330 0 : decls.insert(GetBetaDistPDFDecl);
7331 0 : funs.insert(GetBetaDistPDF);
7332 0 : decls.insert(GetLogBetaDecl);
7333 0 : funs.insert(GetLogBeta);
7334 0 : decls.insert(GetBetaDecl);
7335 0 : funs.insert(GetBeta);
7336 0 : decls.insert(lcl_getLanczosSumDecl);
7337 0 : funs.insert(lcl_getLanczosSum);
7338 0 : }
7339 0 : void OpBetainv::GenSlidingWindowFunction(
7340 : std::stringstream &ss,const std::string &sSymName,
7341 : SubArguments &vSubArguments)
7342 : {
7343 0 : ss << "\ndouble " << sSymName;
7344 0 : ss << "_"<< BinFuncName() <<"(";
7345 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
7346 : {
7347 0 : if (i)
7348 0 : ss << ",";
7349 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
7350 : }
7351 0 : ss << ")\n";
7352 0 : ss << "{\n";
7353 0 : ss << " double tmp0,tmp1,tmp2,tmp3,tmp4;\n";
7354 0 : ss << " int gid0=get_global_id(0);\n";
7355 0 : size_t i = vSubArguments.size();
7356 0 : ss <<"\n ";
7357 : //while (i-- > 1)
7358 0 : for (i = 0; i < vSubArguments.size(); i++)
7359 : {
7360 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
7361 : assert(pCur);
7362 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
7363 : {
7364 : const formula::DoubleVectorRefToken* pDVR =
7365 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
7366 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
7367 0 : ss << "for (int i = ";
7368 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
7369 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
7370 0 : ss << " && i < " << nCurWindowSize << "; i++){\n";
7371 0 : } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
7372 0 : ss << "0; i < " << pDVR->GetArrayLength();
7373 0 : ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
7374 0 : } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
7375 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
7376 0 : ss << " && i < "<< nCurWindowSize << "; i++){\n";
7377 : }
7378 : else {
7379 0 : ss << "0; i < "<< nCurWindowSize << "; i++){\n";
7380 : }
7381 : }
7382 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
7383 : {
7384 : const formula::SingleVectorRefToken* pSVR =
7385 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
7386 0 : ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
7387 : }
7388 0 : else if (pCur->GetType() == formula::svDouble)
7389 : {
7390 0 : ss << "{\n";
7391 : }
7392 : else
7393 : {
7394 :
7395 : }
7396 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
7397 : {
7398 0 : ss << " if (isNan(";
7399 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
7400 0 : ss << "))\n";
7401 0 : ss << " tmp"<<i<<"= 0;\n";
7402 0 : ss << " else\n";
7403 0 : ss << " tmp"<<i<<"=\n";
7404 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
7405 0 : ss << ";\n}\n";
7406 : }
7407 : else
7408 : {
7409 0 : ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
7410 0 : ss <<";\n";
7411 : }
7412 : }
7413 0 : ss << " if (tmp0 < 0.0 || tmp0 >= 1.0 ||";
7414 0 : ss << "tmp3 == tmp4 || tmp1 <= 0.0 || tmp2 <= 0.0)\n";
7415 0 : ss << " {\n";
7416 0 : ss << " return DBL_MIN;\n";
7417 0 : ss << " }\n";
7418 0 : ss << " if (tmp0 == 0.0)\n";
7419 0 : ss << " return 0.0;\n";
7420 0 : ss << " else\n";
7421 0 : ss << " {";
7422 0 : ss << " bool bConvError;";
7423 0 : ss << " double fVal = lcl_IterateInverseBetaInv";
7424 0 : ss << "(tmp0, tmp1, tmp2, 0.0, 1.0, &bConvError);\n";
7425 0 : ss << " if(bConvError)\n";
7426 0 : ss << " return DBL_MIN;\n";
7427 0 : ss << " else\n";
7428 0 : ss << " return (tmp3 + fVal*(tmp4 - tmp3));\n";
7429 0 : ss << " }";
7430 0 : ss << "}\n";
7431 0 : }
7432 0 : void OpDevSq::GenSlidingWindowFunction(std::stringstream& ss,
7433 : const std::string &sSymName, SubArguments& vSubArguments)
7434 : {
7435 0 : ss << "\ndouble " << sSymName;
7436 0 : ss << "_"<< BinFuncName() <<"(";
7437 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
7438 : {
7439 0 : if (i)
7440 0 : ss << ",";
7441 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
7442 : }
7443 0 : ss << ") {\n";
7444 0 : ss << " int gid0 = get_global_id(0);\n";
7445 0 : ss << " double vSum = 0.0;\n";
7446 0 : ss << " double vMean = 0.0;\n";
7447 0 : ss << " int cnt = 0;\n";
7448 0 : for(size_t i = 0; i < vSubArguments.size(); i++ )
7449 : {
7450 0 : ss << " double arg" << i << " = 0.0;\n";
7451 0 : FormulaToken* pCur = vSubArguments[i]->GetFormulaToken();
7452 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
7453 : {
7454 : const formula::DoubleVectorRefToken* pCurDVR =
7455 0 : static_cast<const formula::DoubleVectorRefToken* >(pCur);
7456 0 : size_t nCurWindowSize = pCurDVR->GetRefRowSize();
7457 0 : ss << " for(int i = ";
7458 0 : if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
7459 0 : ss << "gid0; i < " << nCurWindowSize << "; i++) {\n";
7460 0 : ss << " arg" << i << " = ";
7461 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
7462 0 : ss << " if(isNan(arg" << i << ") || (i >= ";
7463 0 : ss << pCurDVR->GetArrayLength() << ")) {\n";
7464 0 : ss << " arg" << i << " = 0.0;\n";
7465 0 : ss << " --cnt;\n";
7466 0 : ss << " }\n";
7467 0 : ss << " ++cnt;\n";
7468 0 : ss << " vSum += arg" << i << ";\n";
7469 0 : ss << " }\n";
7470 0 : } else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) {
7471 0 : ss << "0; i < gid0 + " << nCurWindowSize << "; i++) {\n";
7472 0 : ss << " arg" << i << " = ";
7473 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
7474 0 : ss << " if(isNan(arg" << i << ") || (i >= ";
7475 0 : ss << pCurDVR->GetArrayLength() << ")) {\n";
7476 0 : ss << " arg" << i << " = 0.0;\n";
7477 0 : ss << " --cnt;\n";
7478 0 : ss << " }\n";
7479 0 : ss << " ++cnt;\n";
7480 0 : ss << " vSum += arg" << i << ";\n";
7481 0 : ss << " }\n";
7482 0 : } else if (pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
7483 0 : ss << "0; i < " << nCurWindowSize << "; i++) {\n";
7484 0 : ss << " arg" << i << " = ";
7485 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
7486 0 : ss << " if(isNan(arg" << i << ") || (i >= ";
7487 0 : ss << pCurDVR->GetArrayLength() << ")) {\n";
7488 0 : ss << " arg" << i << " = 0.0;\n";
7489 0 : ss << " --cnt;\n";
7490 0 : ss << " }\n";
7491 0 : ss << " ++cnt;\n";
7492 0 : ss << " vSum += arg" << i << ";\n";
7493 0 : ss << " }\n";
7494 : } else {
7495 0 : ss << "0; i < " << nCurWindowSize << "; i++) {\n";
7496 0 : ss << " arg" << i << " = ";
7497 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
7498 0 : ss << " if(isNan(arg" << i << ") || (i + gid0 >= ";
7499 0 : ss << pCurDVR->GetArrayLength() << ")) {\n";
7500 0 : ss << " arg" << i << " = 0.0;\n";
7501 0 : ss << " --cnt;\n";
7502 0 : ss << " }\n";
7503 0 : ss << " ++cnt;\n";
7504 0 : ss << " vSum += arg" << i << ";\n";
7505 0 : ss << " }\n";
7506 : }
7507 : }
7508 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
7509 : {
7510 : const formula::SingleVectorRefToken* pTVR =
7511 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
7512 0 : ss << " if(isNan(";
7513 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
7514 0 : ss << ") || gid0 >= " << pTVR->GetArrayLength() << ")\n";
7515 0 : ss << " arg" << i << " = 0;\n else\n";
7516 0 : ss << " arg" << i << " = ";
7517 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
7518 0 : ss << " cnt++;\n";
7519 0 : ss << " vSum += arg" << i << ";\n";
7520 : }
7521 0 : else if (pCur->GetType() == formula::svDouble)
7522 : {
7523 0 : ss << " if(isNan ( ";
7524 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << "))\n";
7525 0 : ss << " arg" << i << " = 0;\n else\n";
7526 0 : ss << " arg" << i << " = ";
7527 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
7528 0 : ss << " cnt++;\n";
7529 0 : ss << " vSum += arg" << i << ";\n";
7530 : }
7531 : else
7532 : {
7533 0 : ss << " arg" << i << " = ";
7534 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
7535 0 : ss << " cnt++;\n";
7536 0 : ss << " vSum += arg" << i << ";\n";
7537 : }
7538 : }
7539 0 : ss << " vMean = vSum / cnt;\n";
7540 0 : ss << " vSum = 0.0;\n";
7541 0 : for(size_t k = 0; k < vSubArguments.size(); k++ )
7542 : {
7543 0 : FormulaToken* pCur = vSubArguments[k]->GetFormulaToken();
7544 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
7545 : {
7546 : const formula::DoubleVectorRefToken* pCurDVR =
7547 0 : static_cast<const formula::DoubleVectorRefToken* >(pCur);
7548 0 : size_t nCurWindowSize = pCurDVR->GetRefRowSize();
7549 0 : ss << " for(int i = ";
7550 0 : if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
7551 0 : ss << "gid0; i < " << nCurWindowSize << "; i++) {\n";
7552 0 : ss << " arg" << k << " = ";
7553 0 : ss << vSubArguments[k]->GenSlidingWindowDeclRef() << ";\n";
7554 0 : ss << " if(isNan( arg" << k << " ) || (i >= ";
7555 0 : ss << pCurDVR->GetArrayLength() << ")) {\n";
7556 0 : ss << " arg" << k << " = vXMean;\n";
7557 0 : ss << " }\n";
7558 0 : ss << " vSum += pow( arg" << k << " - vMean, 2 );\n";
7559 0 : ss << " }\n";
7560 0 : } else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) {
7561 0 : ss << "0; i < gid0 + " << nCurWindowSize << "; i++) {\n";
7562 0 : ss << " arg" << k << " = ";
7563 0 : ss << vSubArguments[k]->GenSlidingWindowDeclRef() << ";\n";
7564 0 : ss << " if(isNan( arg" << k << ") || (i >= ";
7565 0 : ss << pCurDVR->GetArrayLength() << ")) {\n";
7566 0 : ss << " arg" << k << " = vMean;\n";
7567 0 : ss << " }\n";
7568 0 : ss << " vSum += pow( arg" << k << " - vMean, 2 );\n";
7569 0 : ss << " }\n";
7570 0 : } else if (pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
7571 0 : ss << "0; i < " << nCurWindowSize << "; i++) {\n";
7572 0 : ss << " arg" << k << " = ";
7573 0 : ss << vSubArguments[k]->GenSlidingWindowDeclRef() << ";\n";
7574 0 : ss << " if(isNan(arg" << k << ") || (i >= ";
7575 0 : ss << pCurDVR->GetArrayLength() << ")) {\n";
7576 0 : ss << " arg" << k << " = vMean;\n";
7577 0 : ss << " }\n";
7578 0 : ss << " vSum += pow( arg" << k << " - vMean, 2 );\n";
7579 0 : ss << " }\n";
7580 : } else {
7581 0 : ss << "0; i < " << nCurWindowSize << "; i++) {\n";
7582 0 : ss << " arg" << k << " = ";
7583 0 : ss << vSubArguments[k]->GenSlidingWindowDeclRef() << ";\n";
7584 0 : ss << " if(isNan(arg" << k << ") || (i + gid0 >= ";
7585 0 : ss << pCurDVR->GetArrayLength() << ")) {\n";
7586 0 : ss << " arg" << k << " = vMean;\n";
7587 0 : ss << " }\n";
7588 0 : ss << " vSum += pow( arg" << k << " - vMean, 2 );\n";
7589 0 : ss << " }\n";
7590 : }
7591 : }
7592 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
7593 : {
7594 : const formula::SingleVectorRefToken* pTVR =
7595 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
7596 0 : ss << " if(isNan(";
7597 0 : ss << vSubArguments[k]->GenSlidingWindowDeclRef();
7598 0 : ss << ") || gid0 >= " << pTVR->GetArrayLength() << ")\n";
7599 0 : ss << " arg" << k << " = vMean;\n else\n";
7600 0 : ss << " arg" << k << " = ";
7601 0 : ss << vSubArguments[k]->GenSlidingWindowDeclRef()<<";\n";
7602 0 : ss << " vSum += pow( arg" << k << " - vMean, 2 );\n";
7603 : }
7604 0 : else if (pCur->GetType() == formula::svDouble)
7605 : {
7606 0 : ss << " arg" << k << " = ";
7607 0 : ss << vSubArguments[k]->GenSlidingWindowDeclRef() << ";\n";
7608 0 : ss << " if(isNan(arg" << k << "))\n";
7609 0 : ss << " arg" << k << " = vMean;\n";
7610 0 : ss << " vSum += pow( arg" << k << " - vMean, 2 );\n";
7611 : }
7612 : else
7613 : {
7614 0 : ss << " arg" << k << " = ";
7615 0 : ss << vSubArguments[k]->GenSlidingWindowDeclRef() << ";\n";
7616 0 : ss << " vSum += pow( arg" << k << " - vMean, 2 );\n";
7617 : }
7618 : }
7619 0 : ss << " return vSum;\n";
7620 0 : ss << "}";
7621 0 : }
7622 0 : void OpHypGeomDist::GenSlidingWindowFunction(std::stringstream &ss,
7623 : const std::string &sSymName, SubArguments &vSubArguments)
7624 : {
7625 0 : ss << "\ndouble " << sSymName;
7626 0 : ss << "_"<< BinFuncName() <<"(";
7627 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
7628 : {
7629 0 : if (i)
7630 0 : ss << ",";
7631 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
7632 : }
7633 0 : ss << ") {\n";
7634 0 : ss << " int gid0=get_global_id(0);\n";
7635 0 : ss << " double arg0,arg1,arg2,arg3;\n";
7636 0 : size_t i = vSubArguments.size();
7637 :
7638 0 : for (i = 0; i < vSubArguments.size(); i++)
7639 : {
7640 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
7641 : assert(pCur);
7642 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
7643 : {
7644 : const formula::DoubleVectorRefToken* pDVR =
7645 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
7646 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
7647 0 : ss << "for (int i = ";
7648 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
7649 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
7650 0 : ss << " && i < " << nCurWindowSize << "; i++){\n";
7651 0 : } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
7652 0 : ss << "0; i < " << pDVR->GetArrayLength();
7653 0 : ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
7654 0 : } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
7655 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
7656 0 : ss << " && i < "<< nCurWindowSize << "; i++){\n ";
7657 : }
7658 : else {
7659 0 : ss << "0; i < "<< nCurWindowSize << "; i++){\n";
7660 : }
7661 : }
7662 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
7663 : {
7664 : const formula::SingleVectorRefToken* pSVR =
7665 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
7666 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
7667 0 : ss << " {\n";
7668 0 : ss << " if (isNan(";
7669 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
7670 0 : ss << "))\n";
7671 0 : ss << " arg"<<i<<"= 0;\n";
7672 0 : ss << " else\n";
7673 0 : ss << " arg"<<i<<"=";
7674 0 : ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
7675 0 : ss << ";\n";
7676 0 : ss << " }\n";
7677 0 : ss << " else\n";
7678 0 : ss << " arg"<<i<<"= 0;\n";
7679 : }
7680 0 : else if (pCur->GetType() == formula::svDouble)
7681 : {
7682 0 : ss << " if (isNan(";
7683 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
7684 0 : ss << "))\n";
7685 0 : ss << " arg"<<i<<"= 0;\n";
7686 0 : ss << " else\n";
7687 0 : ss << " arg"<<i<<"=";
7688 0 : ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
7689 0 : ss << ";\n";
7690 : }
7691 : }
7692 : ss << " double N1=floor(arg3);\n"
7693 : " double M1=floor(arg2);\n"
7694 : " double n1=floor(arg1);\n"
7695 : " double x1=floor(arg0);\n"
7696 : " double num[9];\n"
7697 : " double PI = 3.1415926535897932384626433832795;\n"
7698 : " double tmp;\n"
7699 : " if( (x1 < 0.0) || (n1 < x1) || (M1 < x1) || (N1 < n1) ||"
7700 : "(N1 < M1) || (x1 < n1 - N1 + M1) )\n"
7701 : " {\n"
7702 : " tmp = DBL_MIN;\n"
7703 : " return tmp;\n"
7704 : " }\n"
7705 : " num[0]=M1;\n"
7706 : " num[1]=x1;\n"
7707 : " num[2]=M1-x1;\n"
7708 : " num[3]=N1-M1;\n"
7709 : " num[4]=n1-x1;\n"
7710 : " num[5]=N1-M1-n1+x1;\n"
7711 : " num[6]=N1;\n"
7712 : " num[7]=n1;\n"
7713 : " num[8]=N1-n1;\n"
7714 : " for(int i=0;i<9;i++)\n"
7715 : " {\n"
7716 : " if(num[i]<171)\n"
7717 : " {\n"
7718 : " if(num[i]==0)\n"
7719 : " num[i]=0;\n"
7720 : " else\n"
7721 : " num[i]=log(tgamma(num[i])*num[i]);\n"
7722 : " }\n"
7723 : " else\n"
7724 : " num[i]=0.5*log(2.0*PI)+(num[i]+0.5)*log(num[i])-num[i]+"
7725 : "(1.0*pow(12.0*num[i],-1)-1.0*pow(360*pow(num[i],3),-1));\n"
7726 0 : " }\n";
7727 0 : ss << " tmp=pow(M_E,(num[0]+num[3]+num[7]+num[8]";
7728 0 : ss << "-num[1]-num[2]-num[4]-num[5]-num[6]));\n";
7729 0 : ss << " return tmp;\n";
7730 0 : ss << "}\n";
7731 0 : }
7732 :
7733 : enum MixDoubleString
7734 : {
7735 : svDoubleVectorRefDoubleString,
7736 : svDoubleVectorRefDouble,
7737 : svDoubleVectorRefString,
7738 : svDoubleVectorRefNULL,
7739 : svSingleVectorRefDoubleString,
7740 : svSingleVectorRefDouble,
7741 : svSingleVectorRefString,
7742 : svSingleVectorRefNULL,
7743 : svDoubleDouble
7744 : };
7745 :
7746 0 : void OpMinA::GenSlidingWindowFunction(
7747 : std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
7748 : {
7749 0 : int isMixed = 0;
7750 0 : ss << "\ndouble " << sSymName;
7751 0 : ss << "_"<< BinFuncName() <<"(";
7752 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
7753 : {
7754 0 : if (i)
7755 0 : ss << ",";
7756 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
7757 : }
7758 0 : ss << ")\n";
7759 0 : ss << "{\n";
7760 0 : ss << " int gid0=get_global_id(0);\n";
7761 0 : ss << " double tmp0 = 1.79769e+308;\n";
7762 0 : size_t i = vSubArguments.size();
7763 0 : ss <<"\n";
7764 0 : for (i = 0; i < vSubArguments.size(); i++)
7765 : {
7766 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
7767 : assert(pCur);
7768 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
7769 : {
7770 : const formula::DoubleVectorRefToken* pDVR =
7771 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
7772 0 : if(pDVR->GetArrays()[0].mpNumericArray
7773 0 : && pDVR->GetArrays()[0].mpStringArray)
7774 0 : isMixed = svDoubleVectorRefDoubleString;
7775 0 : else if(pDVR->GetArrays()[0].mpNumericArray)
7776 0 : isMixed = svDoubleVectorRefDouble;
7777 0 : else if(pDVR->GetArrays()[0].mpStringArray)
7778 0 : isMixed = svDoubleVectorRefString;
7779 : else
7780 0 : isMixed = svDoubleVectorRefNULL;
7781 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
7782 0 : ss << " for (int i = ";
7783 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
7784 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
7785 0 : ss << " && i < " << nCurWindowSize << "; i++){\n";
7786 0 : } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
7787 0 : ss << "0; i < " << pDVR->GetArrayLength();
7788 0 : ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
7789 0 : } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
7790 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
7791 0 : ss << " && i < "<< nCurWindowSize << "; i++){\n";
7792 : }
7793 : else {
7794 0 : ss << "0; i < "<< nCurWindowSize << "; i++){\n";
7795 : }
7796 : }
7797 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
7798 : {
7799 : const formula::SingleVectorRefToken* pSVR =
7800 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
7801 :
7802 0 : if(pSVR->GetArray().mpNumericArray
7803 0 : && pSVR->GetArray().mpStringArray)
7804 0 : isMixed = svSingleVectorRefDoubleString;
7805 0 : else if(pSVR->GetArray().mpNumericArray)
7806 0 : isMixed = svSingleVectorRefDouble;
7807 0 : else if(pSVR->GetArray().mpStringArray)
7808 0 : isMixed = svSingleVectorRefString;
7809 : else
7810 0 : isMixed = svSingleVectorRefNULL;
7811 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << "){\n";
7812 : }
7813 0 : else if (pCur->GetType() == formula::svDouble)
7814 : {
7815 0 : ss << " {\n";
7816 0 : isMixed = svDoubleDouble;
7817 : }
7818 : else
7819 : {
7820 : }
7821 :
7822 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
7823 : {
7824 0 : if(isMixed == svDoubleVectorRefDoubleString
7825 0 : || isMixed == svSingleVectorRefDoubleString)
7826 : {
7827 0 : ss << " if (!isNan(";
7828 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
7829 0 : ss << "))\n";
7830 0 : ss << " tmp0 = tmp0 > ";
7831 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
7832 0 : ss << " ? ";
7833 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
7834 0 : ss << " : tmp0;\n";
7835 0 : ss << " else if(isNan(";
7836 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
7837 0 : ss << ") && ";
7838 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
7839 0 : ss << " != 0)\n";
7840 0 : ss << " tmp0 = tmp0 > 0.0 ? 0.0 : tmp0;\n";
7841 0 : ss << " }\n";
7842 : }
7843 0 : else if(isMixed == svDoubleVectorRefDouble
7844 0 : || isMixed == svSingleVectorRefDouble)
7845 : {
7846 0 : ss << " if (!isNan(";
7847 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
7848 0 : ss << "))\n";
7849 0 : ss << " tmp0 = tmp0 > ";
7850 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
7851 0 : ss << " ? " << vSubArguments[i]->GenSlidingWindowDeclRef();
7852 0 : ss << " : tmp0;";
7853 0 : ss <<"\n }\n";
7854 : }
7855 0 : else if(isMixed == svDoubleVectorRefString)
7856 : {
7857 0 : ss << " if(";
7858 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
7859 0 : ss << " == 0)\n continue;\n";
7860 0 : ss << " tmp0 = tmp0 > 0.0 ? 0.0 : tmp0;\n";
7861 0 : ss << " }\n";
7862 : }
7863 0 : else if(isMixed == svSingleVectorRefString)
7864 : {
7865 0 : ss << " if(";
7866 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
7867 0 : ss << " != 0)\n";
7868 0 : ss << " tmp0 = tmp0 > 0.0 ? 0.0 : tmp0;\n";
7869 0 : ss << " }\n";
7870 : }
7871 0 : else if(isMixed == svDoubleDouble)
7872 : {
7873 0 : ss << " tmp0 = tmp0 > ";
7874 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
7875 0 : ss << " ? " << vSubArguments[i]->GenSlidingWindowDeclRef();
7876 0 : ss << " : tmp0;\n }\n";
7877 : }
7878 : else
7879 : {
7880 0 : ss << " }\n";
7881 : }
7882 : }
7883 : else
7884 : {
7885 0 : ss << " tmp0 = tmp0 > ";
7886 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
7887 0 : ss << " ? " << vSubArguments[i]->GenSlidingWindowDeclRef();
7888 0 : ss << " : tmp0;";
7889 0 : ss <<"\n }\n";
7890 : }
7891 : }
7892 0 : ss << " return tmp0 == 1.79769e+308 ? 0.0 : tmp0;\n";
7893 0 : ss << "}\n";
7894 0 : }
7895 0 : void OpCountA::GenSlidingWindowFunction(
7896 : std::stringstream &ss, const std::string &sSymName, SubArguments &
7897 : vSubArguments)
7898 : {
7899 0 : int isMixed = 0;
7900 0 : ss << "\ndouble " << sSymName;
7901 0 : ss << "_"<< BinFuncName() <<"(";
7902 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
7903 : {
7904 0 : if (i)
7905 0 : ss << ",";
7906 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
7907 : }
7908 0 : ss << ")\n";
7909 0 : ss << "{\n";
7910 0 : ss << " int gid0=get_global_id(0);\n";
7911 0 : ss << " double nCount = 0.0;\n";
7912 0 : size_t i = vSubArguments.size();
7913 :
7914 0 : ss <<"\n";
7915 0 : for (i = 0; i < vSubArguments.size(); i++)
7916 : {
7917 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
7918 : assert(pCur);
7919 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
7920 : {
7921 : const formula::DoubleVectorRefToken* pDVR =
7922 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
7923 0 : if(pDVR->GetArrays()[0].mpNumericArray
7924 0 : && pDVR->GetArrays()[0].mpStringArray)
7925 0 : isMixed = svDoubleVectorRefDoubleString;
7926 0 : else if(pDVR->GetArrays()[0].mpNumericArray)
7927 0 : isMixed = svDoubleVectorRefDouble;
7928 0 : else if(pDVR->GetArrays()[0].mpStringArray)
7929 0 : isMixed = svDoubleVectorRefString;
7930 : else
7931 0 : isMixed = svDoubleVectorRefNULL;
7932 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
7933 0 : ss << " for (int i = ";
7934 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
7935 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
7936 0 : ss << " && i < " << nCurWindowSize << "; i++){\n";
7937 0 : } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
7938 0 : ss << "0; i < " << pDVR->GetArrayLength();
7939 0 : ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
7940 0 : } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
7941 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
7942 0 : ss << " && i < "<< nCurWindowSize << "; i++){\n";
7943 : }
7944 : else {
7945 0 : ss << "0; i < "<< nCurWindowSize << "; i++){\n";
7946 : }
7947 : }
7948 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
7949 : {
7950 : const formula::SingleVectorRefToken* pSVR =
7951 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
7952 :
7953 0 : if(pSVR->GetArray().mpNumericArray
7954 0 : && pSVR->GetArray().mpStringArray)
7955 0 : isMixed = svSingleVectorRefDoubleString;
7956 0 : else if(pSVR->GetArray().mpNumericArray)
7957 0 : isMixed = svSingleVectorRefDouble;
7958 0 : else if(pSVR->GetArray().mpStringArray)
7959 0 : isMixed = svSingleVectorRefString;
7960 : else
7961 0 : isMixed = svSingleVectorRefNULL;
7962 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << "){\n";
7963 : }
7964 0 : else if (pCur->GetType() == formula::svDouble)
7965 : {
7966 0 : ss << " {\n";
7967 0 : isMixed = svDoubleDouble;
7968 : }
7969 : else
7970 : {
7971 : }
7972 :
7973 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
7974 : {
7975 0 : if(isMixed == svDoubleVectorRefDoubleString
7976 0 : || isMixed == svSingleVectorRefDoubleString)
7977 : {
7978 0 : ss << " if (!isNan(";
7979 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
7980 0 : ss << ")){\n";
7981 0 : ss << " nCount+=1.0;\n";
7982 0 : ss << " }\n";
7983 0 : ss << " else if(isNan(";
7984 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
7985 0 : ss << ") && ";
7986 0 : ss<< vSubArguments[i]->GenStringSlidingWindowDeclRef();
7987 0 : ss << " != 0)\n";
7988 0 : ss << " nCount+=1.0;\n";
7989 0 : ss << " }\n";
7990 : }
7991 0 : else if(isMixed == svDoubleVectorRefDouble
7992 0 : || isMixed == svSingleVectorRefDouble)
7993 : {
7994 0 : ss << " if (!isNan(";
7995 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
7996 0 : ss << ")){\n";
7997 0 : ss << " nCount+=1.0;\n";
7998 0 : ss <<"}\n }\n";
7999 : }
8000 0 : else if(isMixed == svDoubleVectorRefString)
8001 : {
8002 0 : ss << " if (!isNan(";
8003 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
8004 0 : ss << "))\n";
8005 0 : ss << " nCount+=1.0;\n";
8006 0 : ss <<"\n }\n";
8007 : }
8008 0 : else if(isMixed == svSingleVectorRefString)
8009 : {
8010 0 : ss << " if(";
8011 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
8012 0 : ss << " != 0)\n";
8013 0 : ss << " nCount+=1.0;\n";
8014 0 : ss << " }\n";
8015 : }
8016 0 : else if(isMixed == svDoubleDouble)
8017 : {
8018 0 : ss << " nCount+=1.0;\n";
8019 0 : ss << " }\n";
8020 : }
8021 : else
8022 : {
8023 0 : ss << " }\n";
8024 : }
8025 : }
8026 : else
8027 : {
8028 0 : ss << " nCount+=1.0;\n";
8029 0 : ss << " }\n";
8030 : }
8031 : }
8032 0 : ss << " return nCount;\n";
8033 0 : ss << "}\n";
8034 0 : }
8035 0 : void OpMaxA::GenSlidingWindowFunction(
8036 : std::stringstream &ss, const std::string &sSymName, SubArguments &
8037 : vSubArguments)
8038 : {
8039 0 : int isMixed = 0;
8040 0 : ss << "\ndouble " << sSymName;
8041 0 : ss << "_"<< BinFuncName() <<"(";
8042 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
8043 : {
8044 0 : if (i)
8045 0 : ss << ",";
8046 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
8047 : }
8048 0 : ss << ")\n";
8049 0 : ss << "{\n";
8050 0 : ss << " int gid0=get_global_id(0);\n";
8051 0 : ss << " double tmp0 = 2.22507e-308;\n";
8052 0 : size_t i = vSubArguments.size();
8053 :
8054 0 : ss <<"\n";
8055 0 : for (i = 0; i < vSubArguments.size(); i++)
8056 : {
8057 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
8058 : assert(pCur);
8059 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
8060 : {
8061 : const formula::DoubleVectorRefToken* pDVR =
8062 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
8063 0 : if(pDVR->GetArrays()[0].mpNumericArray
8064 0 : && pDVR->GetArrays()[0].mpStringArray)
8065 0 : isMixed = svDoubleVectorRefDoubleString;
8066 0 : else if(pDVR->GetArrays()[0].mpNumericArray)
8067 0 : isMixed = svDoubleVectorRefDouble;
8068 0 : else if(pDVR->GetArrays()[0].mpStringArray)
8069 0 : isMixed = svDoubleVectorRefString;
8070 : else
8071 0 : isMixed = svDoubleVectorRefNULL;
8072 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
8073 0 : ss << " for (int i = ";
8074 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
8075 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
8076 0 : ss << " && i < " << nCurWindowSize << "; i++){\n";
8077 0 : } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
8078 0 : ss << "0; i < " << pDVR->GetArrayLength();
8079 0 : ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
8080 0 : } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
8081 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
8082 0 : ss << " && i < "<< nCurWindowSize << "; i++){\n";
8083 : }
8084 : else {
8085 0 : ss << "0; i < "<< nCurWindowSize << "; i++){\n";
8086 : }
8087 : }
8088 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
8089 : {
8090 : const formula::SingleVectorRefToken* pSVR =
8091 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
8092 :
8093 0 : if(pSVR->GetArray().mpNumericArray
8094 0 : && pSVR->GetArray().mpStringArray)
8095 0 : isMixed = svSingleVectorRefDoubleString;
8096 0 : else if(pSVR->GetArray().mpNumericArray)
8097 0 : isMixed = svSingleVectorRefDouble;
8098 0 : else if(pSVR->GetArray().mpStringArray)
8099 0 : isMixed = svSingleVectorRefString;
8100 : else
8101 0 : isMixed = svSingleVectorRefNULL;
8102 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << "){\n";
8103 : }
8104 0 : else if (pCur->GetType() == formula::svDouble)
8105 : {
8106 0 : ss << " {\n";
8107 0 : isMixed = svDoubleDouble;
8108 : }
8109 : else
8110 : {
8111 : }
8112 :
8113 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
8114 : {
8115 0 : if(isMixed == svDoubleVectorRefDoubleString
8116 0 : || isMixed == svSingleVectorRefDoubleString)
8117 : {
8118 0 : ss << " if (!isNan(";
8119 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
8120 0 : ss << "))\n";
8121 0 : ss << " tmp0 = tmp0 < ";
8122 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
8123 0 : ss << " ? ";
8124 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
8125 0 : ss << " : tmp0;\n";
8126 0 : ss << " else if(isNan(";
8127 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
8128 0 : ss << ") && ";
8129 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
8130 0 : ss << " != 0)\n";
8131 0 : ss << " tmp0 = tmp0 < 0.0 ? 0.0 : tmp0;\n";
8132 0 : ss << " }\n";
8133 : }
8134 0 : else if(isMixed == svDoubleVectorRefDouble
8135 0 : || isMixed == svSingleVectorRefDouble)
8136 : {
8137 0 : ss << " if (!isNan(";
8138 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
8139 0 : ss << "))\n";
8140 0 : ss << " tmp0 = tmp0 < ";
8141 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
8142 0 : ss << " ? " << vSubArguments[i]->GenSlidingWindowDeclRef();
8143 0 : ss << " : tmp0;";
8144 0 : ss <<"\n }\n";
8145 : }
8146 0 : else if(isMixed == svDoubleVectorRefString)
8147 : {
8148 0 : ss << " if(";
8149 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
8150 0 : ss << " == 0)\n continue;\n";
8151 0 : ss << " tmp0 = tmp0 < 0.0 ? 0.0 : tmp0;\n";
8152 0 : ss << " }\n";
8153 : }
8154 0 : else if(isMixed == svSingleVectorRefString)
8155 : {
8156 0 : ss << " if(";
8157 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
8158 0 : ss << " != 0)\n";
8159 0 : ss << " tmp0 = tmp0 < 0.0 ? 0.0 : tmp0;\n";
8160 0 : ss << " }\n";
8161 : }
8162 0 : else if(isMixed == svDoubleDouble)
8163 : {
8164 0 : ss << " tmp0 = tmp0 < ";
8165 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
8166 0 : ss << " ? " << vSubArguments[i]->GenSlidingWindowDeclRef();
8167 0 : ss << " : tmp0;\n }\n";
8168 : }
8169 : else
8170 : {
8171 0 : ss << " }\n";
8172 : }
8173 : }
8174 : else
8175 : {
8176 0 : ss << " tmp0 = tmp0 < ";
8177 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
8178 0 : ss << " ? " << vSubArguments[i]->GenSlidingWindowDeclRef();
8179 0 : ss << " : tmp0;";
8180 0 : ss <<"\n }\n";
8181 : }
8182 : }
8183 0 : ss << " return tmp0 == 2.22507e-308 ? 0.0 : tmp0;\n";
8184 0 : ss << "}\n";
8185 0 : }
8186 0 : void OpAverageA::GenSlidingWindowFunction(
8187 : std::stringstream &ss, const std::string &sSymName, SubArguments &
8188 : vSubArguments)
8189 : {
8190 0 : int isMixed = 0;
8191 0 : ss << "\ndouble " << sSymName;
8192 0 : ss << "_"<< BinFuncName() <<"(";
8193 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
8194 : {
8195 0 : if (i)
8196 0 : ss << ",";
8197 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
8198 : }
8199 0 : ss << ")\n";
8200 0 : ss << "{\n";
8201 0 : ss << " int gid0=get_global_id(0);\n";
8202 0 : ss << " double tmp0 = 0.0;\n";
8203 0 : ss << " double nCount = 0.0;\n";
8204 0 : size_t i = vSubArguments.size();
8205 0 : ss <<"\n";
8206 0 : for (i = 0; i < vSubArguments.size(); i++)
8207 : {
8208 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
8209 : assert(pCur);
8210 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
8211 : {
8212 : const formula::DoubleVectorRefToken* pDVR =
8213 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
8214 0 : if(pDVR->GetArrays()[0].mpNumericArray
8215 0 : && pDVR->GetArrays()[0].mpStringArray)
8216 0 : isMixed = svDoubleVectorRefDoubleString;
8217 0 : else if(pDVR->GetArrays()[0].mpNumericArray)
8218 0 : isMixed = svDoubleVectorRefDouble;
8219 0 : else if(pDVR->GetArrays()[0].mpStringArray)
8220 0 : isMixed = svDoubleVectorRefString;
8221 : else
8222 0 : isMixed = svDoubleVectorRefNULL;
8223 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
8224 0 : ss << " for (int i = ";
8225 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
8226 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
8227 0 : ss << " && i < " << nCurWindowSize << "; i++){\n";
8228 0 : } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
8229 0 : ss << "0; i < " << pDVR->GetArrayLength();
8230 0 : ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
8231 0 : } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
8232 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
8233 0 : ss << " && i < "<< nCurWindowSize << "; i++){\n";
8234 : }
8235 : else {
8236 0 : ss << "0; i < "<< nCurWindowSize << "; i++){\n";
8237 : }
8238 : }
8239 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
8240 : {
8241 : const formula::SingleVectorRefToken* pSVR =
8242 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
8243 :
8244 0 : if(pSVR->GetArray().mpNumericArray
8245 0 : && pSVR->GetArray().mpStringArray)
8246 0 : isMixed = svSingleVectorRefDoubleString;
8247 0 : else if(pSVR->GetArray().mpNumericArray)
8248 0 : isMixed = svSingleVectorRefDouble;
8249 0 : else if(pSVR->GetArray().mpStringArray)
8250 0 : isMixed = svSingleVectorRefString;
8251 : else
8252 0 : isMixed = svSingleVectorRefNULL;
8253 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << "){\n";
8254 : }
8255 0 : else if (pCur->GetType() == formula::svDouble)
8256 : {
8257 0 : ss << " {\n";
8258 0 : isMixed = svDoubleDouble;
8259 : }
8260 : else
8261 : {
8262 : }
8263 :
8264 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
8265 : {
8266 0 : if(isMixed == svDoubleVectorRefDoubleString
8267 0 : || isMixed == svSingleVectorRefDoubleString)
8268 : {
8269 0 : ss << " if (!isNan(";
8270 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
8271 0 : ss << ")){\n";
8272 0 : ss << " tmp0 +=";
8273 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
8274 0 : ss << ";\n";
8275 0 : ss << " nCount+=1.0;\n";
8276 0 : ss << " }\n";
8277 0 : ss << " else if(isNan(";
8278 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
8279 0 : ss << ") && ";
8280 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
8281 0 : ss << " != 0)\n";
8282 0 : ss << " nCount+=1.0;\n";
8283 0 : ss << " }\n";
8284 : }
8285 0 : else if(isMixed == svDoubleVectorRefDouble
8286 0 : || isMixed == svSingleVectorRefDouble)
8287 : {
8288 0 : ss << " if (!isNan(";
8289 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
8290 0 : ss << ")){\n";
8291 0 : ss << " tmp0 +=";
8292 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
8293 0 : ss << ";\n";
8294 0 : ss << " nCount+=1.0;\n";
8295 0 : ss <<"}\n }\n";
8296 : }
8297 0 : else if(isMixed == svDoubleVectorRefString)
8298 : {
8299 0 : ss << " if (!isNan(";
8300 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
8301 0 : ss << "))\n";
8302 0 : ss << " nCount+=1.0;\n";
8303 0 : ss <<"\n }\n";
8304 : }
8305 0 : else if(isMixed == svSingleVectorRefString)
8306 : {
8307 0 : ss << " if(";
8308 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
8309 0 : ss << " != 0)\n";
8310 0 : ss << " nCount+=1.0;\n";
8311 0 : ss << " }\n";
8312 : }
8313 0 : else if(isMixed == svDoubleDouble)
8314 : {
8315 0 : ss << " tmp0 +=";
8316 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
8317 0 : ss << ";\n";
8318 0 : ss << " nCount+=1.0;\n";
8319 0 : ss << " }\n";
8320 : }
8321 : else
8322 : {
8323 0 : ss << " }\n";
8324 : }
8325 : }
8326 : else
8327 : {
8328 0 : ss << " tmp0 +=";
8329 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
8330 0 : ss << ";\n";
8331 0 : ss << " nCount+=1.0;\n";
8332 0 : ss << " }\n";
8333 : }
8334 : }
8335 0 : ss << " return tmp0*pow(nCount,-1);\n";
8336 0 : ss << "}\n";
8337 0 : }
8338 0 : void OpVarA::GenSlidingWindowFunction(std::stringstream &ss,
8339 : const std::string &sSymName, SubArguments &vSubArguments)
8340 : {
8341 0 : int isMixedDV = 0;
8342 0 : int isMixedSV = 0;
8343 0 : ss << "\ndouble " << sSymName;
8344 0 : ss << "_" << BinFuncName() << "(";
8345 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
8346 : {
8347 0 : if (i)
8348 0 : ss << ",";
8349 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
8350 : }
8351 0 : ss << "){\n";
8352 0 : ss << " int gid0 = get_global_id(0);\n";
8353 0 : ss << " double fSum = 0.0;\n";
8354 0 : ss << " double fMean = 0.0;\n";
8355 0 : ss << " double vSum = 0.0;\n";
8356 0 : ss << " double fCount = 0.0;\n";
8357 0 : ss << " double arg = 0.0;\n";
8358 0 : unsigned i = vSubArguments.size();
8359 0 : while (i--)
8360 : {
8361 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
8362 : assert(pCur);
8363 :
8364 0 : if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
8365 : {
8366 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
8367 : {
8368 : const formula::DoubleVectorRefToken* pDVR =
8369 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
8370 : assert(pDVR);
8371 0 : if(pDVR->GetArrays()[0].mpNumericArray
8372 0 : && pDVR->GetArrays()[0].mpStringArray)
8373 0 : isMixedDV = svDoubleVectorRefDoubleString;
8374 0 : else if(pDVR->GetArrays()[0].mpNumericArray)
8375 0 : isMixedDV = svDoubleVectorRefDouble;
8376 0 : else if(pDVR->GetArrays()[0].mpStringArray)
8377 0 : isMixedDV = svDoubleVectorRefString;
8378 : else
8379 0 : isMixedDV = svDoubleVectorRefNULL;
8380 :
8381 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
8382 0 : ss << " for (int i = ";
8383 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
8384 : {
8385 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
8386 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
8387 0 : ss << " {\n";
8388 : }
8389 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
8390 : {
8391 0 : ss << "0; i < " << pDVR->GetArrayLength();
8392 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
8393 0 : ss << " {\n";
8394 : }
8395 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
8396 : {
8397 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
8398 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
8399 0 : ss << " {\n";
8400 : }
8401 : else
8402 : {
8403 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
8404 0 : ss << " {\n";
8405 : }
8406 :
8407 0 : if(isMixedDV == svDoubleVectorRefDoubleString)
8408 : {
8409 0 : ss << " arg = ";
8410 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
8411 0 : ss << ";\n";
8412 0 : ss << " if (isNan(arg) && ";
8413 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
8414 0 : ss << " == 0)\n";
8415 0 : ss << " continue;\n";
8416 0 : ss << " if(isNan(arg) && ";
8417 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
8418 0 : ss << " != 0)\n";
8419 0 : ss << " {\n";
8420 0 : ss << " fCount = fCount + 1.0;\n";
8421 0 : ss << " continue;\n";
8422 0 : ss << " }\n";
8423 0 : ss << " fSum += arg;\n";
8424 0 : ss << " fCount = fCount + 1.0;\n";
8425 0 : ss << " }\n";
8426 : }
8427 0 : else if(isMixedDV == svDoubleVectorRefDouble)
8428 : {
8429 0 : ss << " arg = ";
8430 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
8431 0 : ss << ";\n";
8432 0 : ss << " if (isNan(arg))\n";
8433 0 : ss << " continue;\n";
8434 0 : ss << " fSum += arg;\n";
8435 0 : ss << " fCount = fCount + 1.0;\n";
8436 0 : ss << " }\n";
8437 : }
8438 0 : else if(isMixedDV == svDoubleVectorRefString)
8439 : {
8440 0 : ss << " if (";
8441 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
8442 0 : ss << " == 0)\n";
8443 0 : ss << " continue;\n";
8444 0 : ss << " fCount = fCount + 1.0;\n";
8445 0 : ss << " }\n";
8446 : }
8447 : else
8448 : {
8449 0 : ss << " continue;\n";
8450 0 : ss << " }\n";
8451 : }
8452 :
8453 : }
8454 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
8455 : {
8456 : const formula::SingleVectorRefToken* pSVR =
8457 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
8458 : assert(pSVR);
8459 0 : if(pSVR->GetArray().mpNumericArray
8460 0 : && pSVR->GetArray().mpStringArray)
8461 0 : isMixedSV = svSingleVectorRefDoubleString;
8462 0 : else if(pSVR->GetArray().mpNumericArray)
8463 0 : isMixedSV = svSingleVectorRefDouble;
8464 0 : else if(pSVR->GetArray().mpStringArray)
8465 0 : isMixedSV = svSingleVectorRefString;
8466 : else
8467 0 : isMixedSV = svSingleVectorRefNULL;
8468 :
8469 0 : if(isMixedSV == svSingleVectorRefDoubleString)
8470 : {
8471 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
8472 0 : ss << " {\n";
8473 0 : ss << " arg = ";
8474 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
8475 0 : ss << ";\n";
8476 0 : ss << " if (!isNan(arg))\n";
8477 0 : ss << " {\n";
8478 0 : ss << " fSum += arg;\n";
8479 0 : ss << " fCount = fCount + 1.0;\n";
8480 0 : ss << " }\n";
8481 0 : ss << " if (isNan(arg) && ";
8482 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
8483 0 : ss << " != 0)\n";
8484 0 : ss << " fCount = fCount + 1.0;\n";
8485 0 : ss << " }\n";
8486 : }
8487 0 : else if(isMixedSV == svSingleVectorRefDouble)
8488 : {
8489 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
8490 0 : ss << " {\n";
8491 0 : ss << " arg = ";
8492 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
8493 0 : ss << " if (!isNan(arg))\n";
8494 0 : ss << " {\n";
8495 0 : ss << " fSum += arg;\n";
8496 0 : ss << " fCount += 1.0;\n";
8497 0 : ss << " }\n";
8498 0 : ss << " }\n";
8499 : }
8500 0 : else if(isMixedSV == svSingleVectorRefString)
8501 : {
8502 :
8503 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
8504 0 : ss << " {\n";
8505 0 : ss << " if (";
8506 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
8507 0 : ss << " != 0)\n";
8508 0 : ss << " fCount = fCount + 1.0;\n";
8509 0 : ss << " }\n";
8510 : }
8511 : else
8512 : {
8513 0 : ss << " arg =0.0;\n";
8514 : }
8515 : }
8516 : else
8517 : {
8518 0 : ss << " arg = " << pCur->GetDouble() << ";\n";
8519 0 : ss << " fSum += arg;\n";
8520 0 : ss << " fCount = fCount + 1.0;\n";
8521 : }
8522 : }
8523 : else
8524 : {
8525 0 : ss << " arg = ";
8526 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
8527 0 : ss << " fSum += arg;\n";
8528 0 : ss << " fCount = fCount + 1.0;\n";
8529 : }
8530 0 : if (i == 0)
8531 : {
8532 0 : ss << " fMean = fSum * pow(fCount,-1.0);\n";
8533 : }
8534 : }
8535 0 : i = vSubArguments.size();
8536 0 : while (i--)
8537 : {
8538 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
8539 : assert(pCur);
8540 :
8541 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
8542 : {
8543 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
8544 : {
8545 : const formula::DoubleVectorRefToken* pDVR =
8546 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
8547 0 : if(pDVR->GetArrays()[0].mpNumericArray
8548 0 : && pDVR->GetArrays()[0].mpStringArray)
8549 0 : isMixedDV = svDoubleVectorRefDoubleString;
8550 0 : else if(pDVR->GetArrays()[0].mpNumericArray)
8551 0 : isMixedDV = svDoubleVectorRefDouble;
8552 0 : else if(pDVR->GetArrays()[0].mpStringArray)
8553 0 : isMixedDV = svDoubleVectorRefString;
8554 : else
8555 0 : isMixedDV = svDoubleVectorRefNULL;
8556 :
8557 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
8558 0 : ss << " for (int i = ";
8559 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
8560 : {
8561 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
8562 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
8563 0 : ss << " {\n";
8564 : }
8565 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
8566 : {
8567 0 : ss << "0; i < " << pDVR->GetArrayLength();
8568 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
8569 0 : ss << " {\n";
8570 : }
8571 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
8572 : {
8573 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
8574 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
8575 0 : ss << " {\n";
8576 : }
8577 : else
8578 : {
8579 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
8580 0 : ss << " {\n";
8581 : }
8582 0 : if(isMixedDV == svDoubleVectorRefDoubleString)
8583 : {
8584 0 : ss << " arg = ";
8585 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
8586 0 : ss << ";\n";
8587 0 : ss << " if (isNan(arg) && ";
8588 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
8589 0 : ss << " == 0)\n";
8590 0 : ss << " continue;\n";
8591 0 : ss << " if(isNan(arg) && ";
8592 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
8593 0 : ss << " != 0)\n";
8594 0 : ss << " arg = 0.0;\n";
8595 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
8596 0 : ss << " }\n";
8597 :
8598 : }
8599 0 : else if(isMixedDV == svDoubleVectorRefDouble)
8600 : {
8601 0 : ss << " arg = ";
8602 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
8603 0 : ss << ";\n";
8604 0 : ss << " if (isNan(arg))\n";
8605 0 : ss << " continue;\n";
8606 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
8607 0 : ss << " }\n";
8608 :
8609 : }
8610 0 : else if(isMixedDV == svDoubleVectorRefString)
8611 : {
8612 0 : ss << " if (";
8613 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
8614 0 : ss << " == 0)\n";
8615 0 : ss << " continue;\n";
8616 0 : ss << " arg = 0.0;\n";
8617 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
8618 0 : ss << " }\n";
8619 : }
8620 : else
8621 : {
8622 0 : ss << " continue;\n";
8623 0 : ss << " }\n";
8624 : }
8625 : }
8626 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
8627 : {
8628 : const formula::SingleVectorRefToken* pSVR =
8629 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
8630 0 : if(pSVR->GetArray().mpNumericArray
8631 0 : && pSVR->GetArray().mpStringArray)
8632 0 : isMixedSV = svSingleVectorRefDoubleString;
8633 0 : else if(pSVR->GetArray().mpNumericArray)
8634 0 : isMixedSV = svSingleVectorRefDouble;
8635 0 : else if(pSVR->GetArray().mpStringArray)
8636 0 : isMixedSV = svSingleVectorRefString;
8637 : else
8638 0 : isMixedSV = svSingleVectorRefNULL;
8639 :
8640 0 : if(isMixedSV == svSingleVectorRefDoubleString)
8641 : {
8642 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
8643 0 : ss << " {\n";
8644 0 : ss << " arg = ";
8645 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
8646 0 : ss << ";\n";
8647 0 : ss << " if (!isNan(arg))\n";
8648 0 : ss << " vSum += (arg - fMean)*(arg - fMean);\n";
8649 0 : ss << " if (isNan(arg) && ";
8650 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
8651 0 : ss << " != 0)\n";
8652 0 : ss << " {\n";
8653 0 : ss << " arg = 0.0;\n";
8654 0 : ss << " vSum += (arg - fMean)*(arg - fMean);\n";
8655 0 : ss << " }\n";
8656 0 : ss << " }\n";
8657 : }
8658 0 : else if(isMixedSV == svSingleVectorRefDouble)
8659 : {
8660 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
8661 0 : ss << " {\n";
8662 0 : ss << " arg = ";
8663 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
8664 0 : ss << " if (!isNan(arg))\n";
8665 0 : ss << " {\n";
8666 0 : ss << " vSum += (arg - fMean)*(arg - fMean);\n";
8667 0 : ss << " }\n";
8668 0 : ss << " }\n";
8669 : }
8670 0 : else if(isMixedSV == svSingleVectorRefString)
8671 : {
8672 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
8673 0 : ss << " {\n";
8674 0 : ss << " if (";
8675 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
8676 0 : ss << " != 0)\n";
8677 0 : ss << " {\n";
8678 0 : ss << " arg = 0.0;\n";
8679 0 : ss << " vSum += (arg - fMean)*(arg - fMean);\n";
8680 0 : ss << " }\n";
8681 0 : ss << " }\n";
8682 : }
8683 : else
8684 : {
8685 0 : ss << " arg = 0.0;\n";
8686 : }
8687 : }
8688 : else
8689 : {
8690 0 : ss << " arg = " << pCur->GetDouble() << ";\n";
8691 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
8692 : }
8693 : }
8694 : else
8695 : {
8696 0 : ss << " arg = ";
8697 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
8698 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
8699 : }
8700 : }
8701 0 : ss << " if (fCount <= 1.0)\n";
8702 0 : ss << " return DBL_MAX;\n";
8703 0 : ss << " else\n";
8704 0 : ss << " return vSum * pow(fCount - 1.0,-1.0);\n";
8705 0 : ss << "}\n";
8706 0 : }
8707 :
8708 0 : void OpVarPA::GenSlidingWindowFunction(std::stringstream &ss,
8709 : const std::string &sSymName, SubArguments &vSubArguments)
8710 : {
8711 0 : int isMixedDV = 0;
8712 0 : int isMixedSV = 0;
8713 0 : ss << "\ndouble " << sSymName;
8714 0 : ss << "_" << BinFuncName() << "(";
8715 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
8716 : {
8717 0 : if (i)
8718 0 : ss << ",";
8719 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
8720 : }
8721 0 : ss << "){\n";
8722 0 : ss << " int gid0 = get_global_id(0);\n";
8723 0 : ss << " double fSum = 0.0;\n";
8724 0 : ss << " double fMean = 0.0;\n";
8725 0 : ss << " double vSum = 0.0;\n";
8726 0 : ss << " double fCount = 0.0;\n";
8727 0 : ss << " double arg = 0.0;\n";
8728 0 : unsigned i = vSubArguments.size();
8729 0 : while (i--)
8730 : {
8731 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
8732 : assert(pCur);
8733 :
8734 0 : if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
8735 : {
8736 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
8737 : {
8738 : const formula::DoubleVectorRefToken* pDVR =
8739 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
8740 0 : if(pDVR->GetArrays()[0].mpNumericArray
8741 0 : && pDVR->GetArrays()[0].mpStringArray)
8742 0 : isMixedDV = svDoubleVectorRefDoubleString;
8743 0 : else if(pDVR->GetArrays()[0].mpNumericArray)
8744 0 : isMixedDV = svDoubleVectorRefDouble;
8745 0 : else if(pDVR->GetArrays()[0].mpStringArray)
8746 0 : isMixedDV = svDoubleVectorRefString;
8747 : else
8748 0 : isMixedDV = svDoubleVectorRefNULL;
8749 :
8750 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
8751 0 : ss << " for (int i = ";
8752 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
8753 : {
8754 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
8755 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
8756 0 : ss << " {\n";
8757 : }
8758 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
8759 : {
8760 0 : ss << "0; i < " << pDVR->GetArrayLength();
8761 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
8762 0 : ss << " {\n";
8763 : }
8764 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
8765 : {
8766 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
8767 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
8768 0 : ss << " {\n";
8769 : }
8770 : else
8771 : {
8772 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
8773 0 : ss << " {\n";
8774 : }
8775 :
8776 0 : if(isMixedDV == svDoubleVectorRefDoubleString)
8777 : {
8778 0 : ss << " arg = ";
8779 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
8780 0 : ss << ";\n";
8781 0 : ss << " if (isNan(arg) && ";
8782 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
8783 0 : ss << " == 0)\n";
8784 0 : ss << " continue;\n";
8785 0 : ss << " if(isNan(arg) && ";
8786 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
8787 0 : ss << " != 0)\n";
8788 0 : ss << " {\n";
8789 0 : ss << " fCount = fCount + 1.0;\n";
8790 0 : ss << " continue;\n";
8791 0 : ss << " }\n";
8792 0 : ss << " fSum += arg;\n";
8793 0 : ss << " fCount = fCount + 1.0;\n";
8794 0 : ss << " }\n";
8795 : }
8796 0 : else if(isMixedDV == svDoubleVectorRefDouble)
8797 : {
8798 0 : ss << " arg = ";
8799 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
8800 0 : ss << ";\n";
8801 0 : ss << " if (isNan(arg))\n";
8802 0 : ss << " continue;\n";
8803 0 : ss << " fSum += arg;\n";
8804 0 : ss << " fCount = fCount + 1.0;\n";
8805 0 : ss << " }\n";
8806 : }
8807 0 : else if(isMixedDV == svDoubleVectorRefString)
8808 : {
8809 0 : ss << " if (";
8810 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
8811 0 : ss << " == 0)\n";
8812 0 : ss << " continue;\n";
8813 0 : ss << " fCount = fCount + 1.0;\n";
8814 0 : ss << " }\n";
8815 : }
8816 : else
8817 : {
8818 0 : ss << " continue;\n";
8819 0 : ss << " }\n";
8820 : }
8821 :
8822 : }
8823 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
8824 : {
8825 : const formula::SingleVectorRefToken* pSVR =
8826 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
8827 0 : if(pSVR->GetArray().mpNumericArray
8828 0 : && pSVR->GetArray().mpStringArray)
8829 0 : isMixedSV = svSingleVectorRefDoubleString;
8830 0 : else if(pSVR->GetArray().mpNumericArray)
8831 0 : isMixedSV = svSingleVectorRefDouble;
8832 0 : else if(pSVR->GetArray().mpStringArray)
8833 0 : isMixedSV = svSingleVectorRefString;
8834 : else
8835 0 : isMixedSV = svSingleVectorRefNULL;
8836 :
8837 0 : if(isMixedSV == svSingleVectorRefDoubleString)
8838 : {
8839 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
8840 0 : ss << " {\n";
8841 0 : ss << " arg = ";
8842 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
8843 0 : ss << ";\n";
8844 0 : ss << " if (!isNan(arg))\n";
8845 0 : ss << " {\n";
8846 0 : ss << " fSum += arg;\n";
8847 0 : ss << " fCount = fCount + 1.0;\n";
8848 0 : ss << " }\n";
8849 0 : ss << " if (isNan(arg) && ";
8850 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
8851 0 : ss << " != 0)\n";
8852 0 : ss << " fCount = fCount + 1.0;\n";
8853 0 : ss << " }\n";
8854 : }
8855 0 : else if(isMixedSV == svSingleVectorRefDouble)
8856 : {
8857 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
8858 0 : ss << " {\n";
8859 0 : ss << " arg = ";
8860 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
8861 0 : ss << " if (!isNan(arg))\n";
8862 0 : ss << " {\n";
8863 0 : ss << " fSum += arg;\n";
8864 0 : ss << " fCount += 1.0;\n";
8865 0 : ss << " }\n";
8866 0 : ss << " }\n";
8867 : }
8868 0 : else if(isMixedSV == svSingleVectorRefString)
8869 : {
8870 :
8871 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
8872 0 : ss << " {\n";
8873 0 : ss << " if (";
8874 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
8875 0 : ss << " != 0)\n";
8876 0 : ss << " fCount = fCount + 1.0;\n";
8877 0 : ss << " }\n";
8878 : }
8879 : else
8880 : {
8881 0 : ss << " arg =0.0;\n";
8882 : }
8883 : }
8884 : else
8885 : {
8886 0 : ss << " arg = " << pCur->GetDouble() << ";\n";
8887 0 : ss << " fSum += arg;\n";
8888 0 : ss << " fCount = fCount + 1.0;\n";
8889 : }
8890 : }
8891 : else
8892 : {
8893 0 : ss << " arg = ";
8894 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
8895 0 : ss << " fSum += arg;\n";
8896 0 : ss << " fCount = fCount + 1.0;\n";
8897 : }
8898 0 : if (i == 0)
8899 : {
8900 0 : ss << " fMean = fSum * pow(fCount,-1.0);\n";
8901 : }
8902 : }
8903 0 : i = vSubArguments.size();
8904 0 : while (i--)
8905 : {
8906 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
8907 : assert(pCur);
8908 :
8909 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
8910 : {
8911 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
8912 : {
8913 : const formula::DoubleVectorRefToken* pDVR =
8914 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
8915 0 : if(pDVR->GetArrays()[0].mpNumericArray
8916 0 : && pDVR->GetArrays()[0].mpStringArray)
8917 0 : isMixedDV = svDoubleVectorRefDoubleString;
8918 0 : else if(pDVR->GetArrays()[0].mpNumericArray)
8919 0 : isMixedDV = svDoubleVectorRefDouble;
8920 0 : else if(pDVR->GetArrays()[0].mpStringArray)
8921 0 : isMixedDV = svDoubleVectorRefString;
8922 : else
8923 0 : isMixedDV = svDoubleVectorRefNULL;
8924 :
8925 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
8926 0 : ss << " for (int i = ";
8927 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
8928 : {
8929 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
8930 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
8931 0 : ss << " {\n";
8932 : }
8933 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
8934 : {
8935 0 : ss << "0; i < " << pDVR->GetArrayLength();
8936 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
8937 0 : ss << " {\n";
8938 : }
8939 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
8940 : {
8941 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
8942 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
8943 0 : ss << " {\n";
8944 : }
8945 : else
8946 : {
8947 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
8948 0 : ss << " {\n";
8949 : }
8950 0 : if(isMixedDV == svDoubleVectorRefDoubleString)
8951 : {
8952 0 : ss << " arg = ";
8953 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
8954 0 : ss << ";\n";
8955 0 : ss << " if (isNan(arg) && ";
8956 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
8957 0 : ss << " == 0)\n";
8958 0 : ss << " continue;\n";
8959 0 : ss << " if(isNan(arg) && ";
8960 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
8961 0 : ss << " != 0)\n";
8962 0 : ss << " arg = 0.0;\n";
8963 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
8964 0 : ss << " }\n";
8965 :
8966 : }
8967 0 : else if(isMixedDV == svDoubleVectorRefDouble)
8968 : {
8969 0 : ss << " arg = ";
8970 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
8971 0 : ss << ";\n";
8972 0 : ss << " if (isNan(arg))\n";
8973 0 : ss << " continue;\n";
8974 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
8975 0 : ss << " }\n";
8976 :
8977 : }
8978 0 : else if(isMixedDV == svDoubleVectorRefString)
8979 : {
8980 0 : ss << " if (";
8981 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
8982 0 : ss << " == 0)\n";
8983 0 : ss << " continue;\n";
8984 0 : ss << " arg = 0.0;\n";
8985 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
8986 0 : ss << " }\n";
8987 : }
8988 : else
8989 : {
8990 0 : ss << " continue;\n";
8991 0 : ss << " }\n";
8992 : }
8993 : }
8994 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
8995 : {
8996 : const formula::SingleVectorRefToken* pSVR =
8997 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
8998 0 : if(pSVR->GetArray().mpNumericArray
8999 0 : && pSVR->GetArray().mpStringArray)
9000 0 : isMixedSV = svSingleVectorRefDoubleString;
9001 0 : else if(pSVR->GetArray().mpNumericArray)
9002 0 : isMixedSV = svSingleVectorRefDouble;
9003 0 : else if(pSVR->GetArray().mpStringArray)
9004 0 : isMixedSV = svSingleVectorRefString;
9005 : else
9006 0 : isMixedSV = svSingleVectorRefNULL;
9007 :
9008 0 : if(isMixedSV == svSingleVectorRefDoubleString)
9009 : {
9010 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
9011 0 : ss << " {\n";
9012 0 : ss << " arg = ";
9013 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
9014 0 : ss << ";\n";
9015 0 : ss << " if (!isNan(arg))\n";
9016 0 : ss << " vSum += (arg - fMean)*(arg - fMean);\n";
9017 0 : ss << " if (isNan(arg) && ";
9018 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
9019 0 : ss << " != 0)\n";
9020 0 : ss << " {\n";
9021 0 : ss << " arg = 0.0;\n";
9022 0 : ss << " vSum += (arg - fMean)*(arg - fMean);\n";
9023 0 : ss << " }\n";
9024 0 : ss << " }\n";
9025 : }
9026 0 : else if(isMixedSV == svSingleVectorRefDouble)
9027 : {
9028 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
9029 0 : ss << " {\n";
9030 0 : ss << " arg = ";
9031 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
9032 0 : ss << " if (!isNan(arg))\n";
9033 0 : ss << " {\n";
9034 0 : ss << " vSum += (arg - fMean)*(arg - fMean);\n";
9035 0 : ss << " }\n";
9036 0 : ss << " }\n";
9037 : }
9038 0 : else if(isMixedSV == svSingleVectorRefString)
9039 : {
9040 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
9041 0 : ss << " {\n";
9042 0 : ss << " if (";
9043 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
9044 0 : ss << " != 0)\n";
9045 0 : ss << " {\n";
9046 0 : ss << " arg = 0.0;\n";
9047 0 : ss << " vSum += (arg - fMean)*(arg - fMean);\n";
9048 0 : ss << " }\n";
9049 0 : ss << " }\n";
9050 : }
9051 : else
9052 : {
9053 0 : ss << " arg = 0.0;\n";
9054 : }
9055 : }
9056 : else
9057 : {
9058 0 : ss << " arg = " << pCur->GetDouble() << ";\n";
9059 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
9060 : }
9061 : }
9062 : else
9063 : {
9064 0 : ss << " arg = ";
9065 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
9066 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
9067 : }
9068 : }
9069 0 : ss << " if (fCount == 0.0)\n";
9070 0 : ss << " return DBL_MAX;\n";
9071 0 : ss << " else\n";
9072 0 : ss << " return vSum * pow(fCount,-1.0);\n";
9073 0 : ss << "}\n";
9074 0 : }
9075 0 : void OpStDevA::GenSlidingWindowFunction(std::stringstream &ss,
9076 : const std::string &sSymName, SubArguments &vSubArguments)
9077 : {
9078 0 : int isMixedDV = 0;
9079 0 : int isMixedSV = 0;
9080 0 : ss << "\ndouble " << sSymName;
9081 0 : ss << "_" << BinFuncName() << "(";
9082 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
9083 : {
9084 0 : if (i)
9085 0 : ss << ",";
9086 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
9087 : }
9088 0 : ss << "){\n";
9089 0 : ss << " int gid0 = get_global_id(0);\n";
9090 0 : ss << " double fSum = 0.0;\n";
9091 0 : ss << " double fMean = 0.0;\n";
9092 0 : ss << " double vSum = 0.0;\n";
9093 0 : ss << " double fCount = 0.0;\n";
9094 0 : ss << " double arg = 0.0;\n";
9095 0 : unsigned i = vSubArguments.size();
9096 0 : while (i--)
9097 : {
9098 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
9099 : assert(pCur);
9100 :
9101 0 : if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
9102 : {
9103 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
9104 : {
9105 : const formula::DoubleVectorRefToken* pDVR =
9106 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
9107 0 : if(pDVR->GetArrays()[0].mpNumericArray
9108 0 : && pDVR->GetArrays()[0].mpStringArray)
9109 0 : isMixedDV = svDoubleVectorRefDoubleString;
9110 0 : else if(pDVR->GetArrays()[0].mpNumericArray)
9111 0 : isMixedDV = svDoubleVectorRefDouble;
9112 0 : else if(pDVR->GetArrays()[0].mpStringArray)
9113 0 : isMixedDV = svDoubleVectorRefString;
9114 : else
9115 0 : isMixedDV = svDoubleVectorRefNULL;
9116 :
9117 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
9118 0 : ss << " for (int i = ";
9119 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
9120 : {
9121 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
9122 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
9123 0 : ss << " {\n";
9124 : }
9125 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
9126 : {
9127 0 : ss << "0; i < " << pDVR->GetArrayLength();
9128 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
9129 0 : ss << " {\n";
9130 : }
9131 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
9132 : {
9133 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
9134 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
9135 0 : ss << " {\n";
9136 : }
9137 : else
9138 : {
9139 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
9140 0 : ss << " {\n";
9141 : }
9142 :
9143 0 : if(isMixedDV == svDoubleVectorRefDoubleString)
9144 : {
9145 0 : ss << " arg = ";
9146 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
9147 0 : ss << ";\n";
9148 0 : ss << " if (isNan(arg) && ";
9149 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
9150 0 : ss << " == 0)\n";
9151 0 : ss << " continue;\n";
9152 0 : ss << " if(isNan(arg) && ";
9153 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
9154 0 : ss << " != 0)\n";
9155 0 : ss << " {\n";
9156 0 : ss << " fCount = fCount + 1.0;\n";
9157 0 : ss << " continue;\n";
9158 0 : ss << " }\n";
9159 0 : ss << " fSum += arg;\n";
9160 0 : ss << " fCount = fCount + 1.0;\n";
9161 0 : ss << " }\n";
9162 : }
9163 0 : else if(isMixedDV == svDoubleVectorRefDouble)
9164 : {
9165 0 : ss << " arg = ";
9166 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
9167 0 : ss << ";\n";
9168 0 : ss << " if (isNan(arg))\n";
9169 0 : ss << " continue;\n";
9170 0 : ss << " fSum += arg;\n";
9171 0 : ss << " fCount = fCount + 1.0;\n";
9172 0 : ss << " }\n";
9173 : }
9174 0 : else if(isMixedDV == svDoubleVectorRefString)
9175 : {
9176 0 : ss << " if (";
9177 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
9178 0 : ss << " == 0)\n";
9179 0 : ss << " continue;\n";
9180 0 : ss << " fCount = fCount + 1.0;\n";
9181 0 : ss << " }\n";
9182 : }
9183 : else
9184 : {
9185 0 : ss << " continue;\n";
9186 0 : ss << " }\n";
9187 : }
9188 :
9189 : }
9190 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
9191 : {
9192 : const formula::SingleVectorRefToken* pSVR =
9193 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
9194 0 : if(pSVR->GetArray().mpNumericArray
9195 0 : && pSVR->GetArray().mpStringArray)
9196 0 : isMixedSV = svSingleVectorRefDoubleString;
9197 0 : else if(pSVR->GetArray().mpNumericArray)
9198 0 : isMixedSV = svSingleVectorRefDouble;
9199 0 : else if(pSVR->GetArray().mpStringArray)
9200 0 : isMixedSV = svSingleVectorRefString;
9201 : else
9202 0 : isMixedSV = svSingleVectorRefNULL;
9203 :
9204 0 : if(isMixedSV == svSingleVectorRefDoubleString)
9205 : {
9206 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
9207 0 : ss << " {\n";
9208 0 : ss << " arg = ";
9209 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
9210 0 : ss << ";\n";
9211 0 : ss << " if (!isNan(arg))\n";
9212 0 : ss << " {\n";
9213 0 : ss << " fSum += arg;\n";
9214 0 : ss << " fCount = fCount + 1.0;\n";
9215 0 : ss << " }\n";
9216 0 : ss << " if (isNan(arg) && ";
9217 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
9218 0 : ss << " != 0)\n";
9219 0 : ss << " fCount = fCount + 1.0;\n";
9220 0 : ss << " }\n";
9221 : }
9222 0 : else if(isMixedSV == svSingleVectorRefDouble)
9223 : {
9224 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
9225 0 : ss << " {\n";
9226 0 : ss << " arg = ";
9227 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
9228 0 : ss << " if (!isNan(arg))\n";
9229 0 : ss << " {\n";
9230 0 : ss << " fSum += arg;\n";
9231 0 : ss << " fCount += 1.0;\n";
9232 0 : ss << " }\n";
9233 0 : ss << " }\n";
9234 : }
9235 0 : else if(isMixedSV == svSingleVectorRefString)
9236 : {
9237 :
9238 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
9239 0 : ss << " {\n";
9240 0 : ss << " if (";
9241 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
9242 0 : ss << " != 0)\n";
9243 0 : ss << " fCount = fCount + 1.0;\n";
9244 0 : ss << " }\n";
9245 : }
9246 : else
9247 : {
9248 0 : ss << " arg =0.0;\n";
9249 : }
9250 : }
9251 : else
9252 : {
9253 0 : ss << " arg = " << pCur->GetDouble() << ";\n";
9254 0 : ss << " fSum += arg;\n";
9255 0 : ss << " fCount = fCount + 1.0;\n";
9256 : }
9257 : }
9258 : else
9259 : {
9260 0 : ss << " arg = ";
9261 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
9262 0 : ss << " fSum += arg;\n";
9263 0 : ss << " fCount = fCount + 1.0;\n";
9264 : }
9265 0 : if (i == 0)
9266 : {
9267 0 : ss << " fMean = fSum * pow(fCount,-1.0);\n";
9268 : }
9269 : }
9270 0 : i = vSubArguments.size();
9271 0 : while (i--)
9272 : {
9273 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
9274 : assert(pCur);
9275 :
9276 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
9277 : {
9278 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
9279 : {
9280 : const formula::DoubleVectorRefToken* pDVR =
9281 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
9282 0 : if(pDVR->GetArrays()[0].mpNumericArray
9283 0 : && pDVR->GetArrays()[0].mpStringArray)
9284 0 : isMixedDV = svDoubleVectorRefDoubleString;
9285 0 : else if(pDVR->GetArrays()[0].mpNumericArray)
9286 0 : isMixedDV = svDoubleVectorRefDouble;
9287 0 : else if(pDVR->GetArrays()[0].mpStringArray)
9288 0 : isMixedDV = svDoubleVectorRefString;
9289 : else
9290 0 : isMixedDV = svDoubleVectorRefNULL;
9291 :
9292 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
9293 0 : ss << " for (int i = ";
9294 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
9295 : {
9296 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
9297 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
9298 0 : ss << " {\n";
9299 : }
9300 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
9301 : {
9302 0 : ss << "0; i < " << pDVR->GetArrayLength();
9303 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
9304 0 : ss << " {\n";
9305 : }
9306 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
9307 : {
9308 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
9309 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
9310 0 : ss << " {\n";
9311 : }
9312 : else
9313 : {
9314 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
9315 0 : ss << " {\n";
9316 : }
9317 0 : if(isMixedDV == svDoubleVectorRefDoubleString)
9318 : {
9319 0 : ss << " arg = ";
9320 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
9321 0 : ss << ";\n";
9322 0 : ss << " if (isNan(arg) && ";
9323 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
9324 0 : ss << " == 0)\n";
9325 0 : ss << " continue;\n";
9326 0 : ss << " if(isNan(arg) && ";
9327 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
9328 0 : ss << " != 0)\n";
9329 0 : ss << " arg = 0.0;\n";
9330 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
9331 0 : ss << " }\n";
9332 :
9333 : }
9334 0 : else if(isMixedDV == svDoubleVectorRefDouble)
9335 : {
9336 0 : ss << " arg = ";
9337 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
9338 0 : ss << ";\n";
9339 0 : ss << " if (isNan(arg))\n";
9340 0 : ss << " continue;\n";
9341 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
9342 0 : ss << " }\n";
9343 :
9344 : }
9345 0 : else if(isMixedDV == svDoubleVectorRefString)
9346 : {
9347 0 : ss << " if (";
9348 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
9349 0 : ss << " == 0)\n";
9350 0 : ss << " continue;\n";
9351 0 : ss << " arg = 0.0;\n";
9352 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
9353 0 : ss << " }\n";
9354 : }
9355 : else
9356 : {
9357 0 : ss << " continue;\n";
9358 0 : ss << " }\n";
9359 : }
9360 : }
9361 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
9362 : {
9363 : const formula::SingleVectorRefToken* pSVR =
9364 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
9365 0 : if(pSVR->GetArray().mpNumericArray
9366 0 : && pSVR->GetArray().mpStringArray)
9367 0 : isMixedSV = svSingleVectorRefDoubleString;
9368 0 : else if(pSVR->GetArray().mpNumericArray)
9369 0 : isMixedSV = svSingleVectorRefDouble;
9370 0 : else if(pSVR->GetArray().mpStringArray)
9371 0 : isMixedSV = svSingleVectorRefString;
9372 : else
9373 0 : isMixedSV = svSingleVectorRefNULL;
9374 :
9375 0 : if(isMixedSV == svSingleVectorRefDoubleString)
9376 : {
9377 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
9378 0 : ss << " {\n";
9379 0 : ss << " arg = ";
9380 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
9381 0 : ss << ";\n";
9382 0 : ss << " if (!isNan(arg))\n";
9383 0 : ss << " vSum += (arg - fMean)*(arg - fMean);\n";
9384 0 : ss << " if (isNan(arg) && ";
9385 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
9386 0 : ss << " != 0)\n";
9387 0 : ss << " {\n";
9388 0 : ss << " arg = 0.0;\n";
9389 0 : ss << " vSum += (arg - fMean)*(arg - fMean);\n";
9390 0 : ss << " }\n";
9391 0 : ss << " }\n";
9392 : }
9393 0 : else if(isMixedSV == svSingleVectorRefDouble)
9394 : {
9395 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
9396 0 : ss << " {\n";
9397 0 : ss << " arg = ";
9398 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
9399 0 : ss << " if (!isNan(arg))\n";
9400 0 : ss << " {\n";
9401 0 : ss << " vSum += (arg - fMean)*(arg - fMean);\n";
9402 0 : ss << " }\n";
9403 0 : ss << " }\n";
9404 : }
9405 0 : else if(isMixedSV == svSingleVectorRefString)
9406 : {
9407 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
9408 0 : ss << " {\n";
9409 0 : ss << " if (";
9410 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
9411 0 : ss << " != 0)\n";
9412 0 : ss << " {\n";
9413 0 : ss << " arg = 0.0;\n";
9414 0 : ss << " vSum += (arg - fMean)*(arg - fMean);\n";
9415 0 : ss << " }\n";
9416 0 : ss << " }\n";
9417 : }
9418 : else
9419 : {
9420 0 : ss << " arg = 0.0;\n";
9421 : }
9422 : }
9423 : else
9424 : {
9425 0 : ss << " arg = " << pCur->GetDouble() << ";\n";
9426 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
9427 : }
9428 : }
9429 : else
9430 : {
9431 0 : ss << " arg = ";
9432 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
9433 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
9434 : }
9435 : }
9436 0 : ss << " if (fCount <= 1.0)\n";
9437 0 : ss << " return DBL_MAX;\n";
9438 0 : ss << " else\n";
9439 0 : ss << " return sqrt(vSum * pow(fCount - 1.0,-1.0));\n";
9440 0 : ss << "}\n";
9441 0 : }
9442 :
9443 0 : void OpStDevPA::GenSlidingWindowFunction(std::stringstream &ss,
9444 : const std::string &sSymName, SubArguments &vSubArguments)
9445 : {
9446 0 : int isMixedDV = 0;
9447 0 : int isMixedSV = 0;
9448 0 : ss << "\ndouble " << sSymName;
9449 0 : ss << "_" << BinFuncName() << "(";
9450 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
9451 : {
9452 0 : if (i)
9453 0 : ss << ",";
9454 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
9455 : }
9456 0 : ss << "){\n";
9457 0 : ss << " int gid0 = get_global_id(0);\n";
9458 0 : ss << " double fSum = 0.0;\n";
9459 0 : ss << " double fMean = 0.0;\n";
9460 0 : ss << " double vSum = 0.0;\n";
9461 0 : ss << " double fCount = 0.0;\n";
9462 0 : ss << " double arg = 0.0;\n";
9463 0 : unsigned i = vSubArguments.size();
9464 0 : while (i--)
9465 : {
9466 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
9467 : assert(pCur);
9468 :
9469 0 : if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
9470 : {
9471 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
9472 : {
9473 : const formula::DoubleVectorRefToken* pDVR =
9474 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
9475 0 : if(pDVR->GetArrays()[0].mpNumericArray
9476 0 : && pDVR->GetArrays()[0].mpStringArray)
9477 0 : isMixedDV = svDoubleVectorRefDoubleString;
9478 0 : else if(pDVR->GetArrays()[0].mpNumericArray)
9479 0 : isMixedDV = svDoubleVectorRefDouble;
9480 0 : else if(pDVR->GetArrays()[0].mpStringArray)
9481 0 : isMixedDV = svDoubleVectorRefString;
9482 : else
9483 0 : isMixedDV = svDoubleVectorRefNULL;
9484 :
9485 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
9486 0 : ss << " for (int i = ";
9487 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
9488 : {
9489 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
9490 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
9491 0 : ss << " {\n";
9492 : }
9493 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
9494 : {
9495 0 : ss << "0; i < " << pDVR->GetArrayLength();
9496 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
9497 0 : ss << " {\n";
9498 : }
9499 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
9500 : {
9501 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
9502 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
9503 0 : ss << " {\n";
9504 : }
9505 : else
9506 : {
9507 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
9508 0 : ss << " {\n";
9509 : }
9510 :
9511 0 : if(isMixedDV == svDoubleVectorRefDoubleString)
9512 : {
9513 0 : ss << " arg = ";
9514 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
9515 0 : ss << ";\n";
9516 0 : ss << " if (isNan(arg) && ";
9517 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
9518 0 : ss << " == 0)\n";
9519 0 : ss << " continue;\n";
9520 0 : ss << " if(isNan(arg) && ";
9521 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
9522 0 : ss << " != 0)\n";
9523 0 : ss << " {\n";
9524 0 : ss << " fCount = fCount + 1.0;\n";
9525 0 : ss << " continue;\n";
9526 0 : ss << " }\n";
9527 0 : ss << " fSum += arg;\n";
9528 0 : ss << " fCount = fCount + 1.0;\n";
9529 0 : ss << " }\n";
9530 : }
9531 0 : else if(isMixedDV == svDoubleVectorRefDouble)
9532 : {
9533 0 : ss << " arg = ";
9534 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
9535 0 : ss << ";\n";
9536 0 : ss << " if (isNan(arg))\n";
9537 0 : ss << " continue;\n";
9538 0 : ss << " fSum += arg;\n";
9539 0 : ss << " fCount = fCount + 1.0;\n";
9540 0 : ss << " }\n";
9541 : }
9542 0 : else if(isMixedDV == svDoubleVectorRefString)
9543 : {
9544 0 : ss << " if (";
9545 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
9546 0 : ss << " == 0)\n";
9547 0 : ss << " continue;\n";
9548 0 : ss << " fCount = fCount + 1.0;\n";
9549 0 : ss << " }\n";
9550 : }
9551 : else
9552 : {
9553 0 : ss << " continue;\n";
9554 0 : ss << " }\n";
9555 : }
9556 :
9557 : }
9558 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
9559 : {
9560 : const formula::SingleVectorRefToken* pSVR =
9561 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
9562 0 : if(pSVR->GetArray().mpNumericArray
9563 0 : && pSVR->GetArray().mpStringArray)
9564 0 : isMixedSV = svSingleVectorRefDoubleString;
9565 0 : else if(pSVR->GetArray().mpNumericArray)
9566 0 : isMixedSV = svSingleVectorRefDouble;
9567 0 : else if(pSVR->GetArray().mpStringArray)
9568 0 : isMixedSV = svSingleVectorRefString;
9569 : else
9570 0 : isMixedSV = svSingleVectorRefNULL;
9571 :
9572 0 : if(isMixedSV == svSingleVectorRefDoubleString)
9573 : {
9574 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
9575 0 : ss << " {\n";
9576 0 : ss << " arg = ";
9577 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
9578 0 : ss << ";\n";
9579 0 : ss << " if (!isNan(arg))\n";
9580 0 : ss << " {\n";
9581 0 : ss << " fSum += arg;\n";
9582 0 : ss << " fCount = fCount + 1.0;\n";
9583 0 : ss << " }\n";
9584 0 : ss << " if (isNan(arg) && ";
9585 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
9586 0 : ss << " != 0)\n";
9587 0 : ss << " fCount = fCount + 1.0;\n";
9588 0 : ss << " }\n";
9589 : }
9590 0 : else if(isMixedSV == svSingleVectorRefDouble)
9591 : {
9592 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
9593 0 : ss << " {\n";
9594 0 : ss << " arg = ";
9595 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
9596 0 : ss << " if (!isNan(arg))\n";
9597 0 : ss << " {\n";
9598 0 : ss << " fSum += arg;\n";
9599 0 : ss << " fCount += 1.0;\n";
9600 0 : ss << " }\n";
9601 0 : ss << " }\n";
9602 : }
9603 0 : else if(isMixedSV == svSingleVectorRefString)
9604 : {
9605 :
9606 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
9607 0 : ss << " {\n";
9608 0 : ss << " if (";
9609 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
9610 0 : ss << " != 0)\n";
9611 0 : ss << " fCount = fCount + 1.0;\n";
9612 0 : ss << " }\n";
9613 : }
9614 : else
9615 : {
9616 0 : ss << " arg =0.0;\n";
9617 : }
9618 : }
9619 : else
9620 : {
9621 0 : ss << " arg = " << pCur->GetDouble() << ";\n";
9622 0 : ss << " fSum += arg;\n";
9623 0 : ss << " fCount = fCount + 1.0;\n";
9624 : }
9625 : }
9626 : else
9627 : {
9628 0 : ss << " arg = ";
9629 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
9630 0 : ss << " fSum += arg;\n";
9631 0 : ss << " fCount = fCount + 1.0;\n";
9632 : }
9633 0 : if (i == 0)
9634 : {
9635 0 : ss << " fMean = fSum * pow(fCount,-1.0);\n";
9636 : }
9637 : }
9638 0 : i = vSubArguments.size();
9639 0 : while (i--)
9640 : {
9641 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
9642 : assert(pCur);
9643 :
9644 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
9645 : {
9646 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
9647 : {
9648 : const formula::DoubleVectorRefToken* pDVR =
9649 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
9650 0 : if(pDVR->GetArrays()[0].mpNumericArray
9651 0 : && pDVR->GetArrays()[0].mpStringArray)
9652 0 : isMixedDV = svDoubleVectorRefDoubleString;
9653 0 : else if(pDVR->GetArrays()[0].mpNumericArray)
9654 0 : isMixedDV = svDoubleVectorRefDouble;
9655 0 : else if(pDVR->GetArrays()[0].mpStringArray)
9656 0 : isMixedDV = svDoubleVectorRefString;
9657 : else
9658 0 : isMixedDV = svDoubleVectorRefNULL;
9659 :
9660 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
9661 0 : ss << " for (int i = ";
9662 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
9663 : {
9664 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
9665 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
9666 0 : ss << " {\n";
9667 : }
9668 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
9669 : {
9670 0 : ss << "0; i < " << pDVR->GetArrayLength();
9671 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
9672 0 : ss << " {\n";
9673 : }
9674 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
9675 : {
9676 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
9677 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
9678 0 : ss << " {\n";
9679 : }
9680 : else
9681 : {
9682 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
9683 0 : ss << " {\n";
9684 : }
9685 0 : if(isMixedDV == svDoubleVectorRefDoubleString)
9686 : {
9687 0 : ss << " arg = ";
9688 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
9689 0 : ss << ";\n";
9690 0 : ss << " if (isNan(arg) && ";
9691 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
9692 0 : ss << " == 0)\n";
9693 0 : ss << " continue;\n";
9694 0 : ss << " if(isNan(arg) && ";
9695 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
9696 0 : ss << " != 0)\n";
9697 0 : ss << " arg = 0.0;\n";
9698 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
9699 0 : ss << " }\n";
9700 :
9701 : }
9702 0 : else if(isMixedDV == svDoubleVectorRefDouble)
9703 : {
9704 0 : ss << " arg = ";
9705 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
9706 0 : ss << ";\n";
9707 0 : ss << " if (isNan(arg))\n";
9708 0 : ss << " continue;\n";
9709 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
9710 0 : ss << " }\n";
9711 :
9712 : }
9713 0 : else if(isMixedDV == svDoubleVectorRefString)
9714 : {
9715 0 : ss << " if (";
9716 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
9717 0 : ss << " == 0)\n";
9718 0 : ss << " continue;\n";
9719 0 : ss << " arg = 0.0;\n";
9720 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
9721 0 : ss << " }\n";
9722 : }
9723 : else
9724 : {
9725 0 : ss << " continue;\n";
9726 0 : ss << " }\n";
9727 : }
9728 : }
9729 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
9730 : {
9731 : const formula::SingleVectorRefToken* pSVR =
9732 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
9733 0 : if(pSVR->GetArray().mpNumericArray
9734 0 : && pSVR->GetArray().mpStringArray)
9735 0 : isMixedSV = svSingleVectorRefDoubleString;
9736 0 : else if(pSVR->GetArray().mpNumericArray)
9737 0 : isMixedSV = svSingleVectorRefDouble;
9738 0 : else if(pSVR->GetArray().mpStringArray)
9739 0 : isMixedSV = svSingleVectorRefString;
9740 : else
9741 0 : isMixedSV = svSingleVectorRefNULL;
9742 :
9743 0 : if(isMixedSV == svSingleVectorRefDoubleString)
9744 : {
9745 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
9746 0 : ss << " {\n";
9747 0 : ss << " arg = ";
9748 0 : ss << vSubArguments[i]->GenDoubleSlidingWindowDeclRef();
9749 0 : ss << ";\n";
9750 0 : ss << " if (!isNan(arg))\n";
9751 0 : ss << " vSum += (arg - fMean)*(arg - fMean);\n";
9752 0 : ss << " if (isNan(arg) && ";
9753 0 : ss << vSubArguments[i]->GenStringSlidingWindowDeclRef();
9754 0 : ss << " != 0)\n";
9755 0 : ss << " {\n";
9756 0 : ss << " arg = 0.0;\n";
9757 0 : ss << " vSum += (arg - fMean)*(arg - fMean);\n";
9758 0 : ss << " }\n";
9759 0 : ss << " }\n";
9760 : }
9761 0 : else if(isMixedSV == svSingleVectorRefDouble)
9762 : {
9763 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
9764 0 : ss << " {\n";
9765 0 : ss << " arg = ";
9766 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
9767 0 : ss << " if (!isNan(arg))\n";
9768 0 : ss << " {\n";
9769 0 : ss << " vSum += (arg - fMean)*(arg - fMean);\n";
9770 0 : ss << " }\n";
9771 0 : ss << " }\n";
9772 : }
9773 0 : else if(isMixedSV == svSingleVectorRefString)
9774 : {
9775 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << ")\n";
9776 0 : ss << " {\n";
9777 0 : ss << " if (";
9778 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
9779 0 : ss << " != 0)\n";
9780 0 : ss << " {\n";
9781 0 : ss << " arg = 0.0;\n";
9782 0 : ss << " vSum += (arg - fMean)*(arg - fMean);\n";
9783 0 : ss << " }\n";
9784 0 : ss << " }\n";
9785 : }
9786 : else
9787 : {
9788 0 : ss << " arg = 0.0;\n";
9789 : }
9790 : }
9791 : else
9792 : {
9793 0 : ss << " arg = " << pCur->GetDouble() << ";\n";
9794 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
9795 : }
9796 : }
9797 : else
9798 : {
9799 0 : ss << " arg = ";
9800 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
9801 0 : ss << " vSum += (arg - fMean) * (arg - fMean);\n";
9802 : }
9803 : }
9804 0 : ss << " if (fCount == 1.0)\n";
9805 0 : ss << " return DBL_MAX;\n";
9806 0 : ss << " else\n";
9807 0 : ss << " return sqrt(vSum * pow(fCount,-1.0));\n";
9808 0 : ss << "}\n";
9809 0 : }
9810 :
9811 0 : void OpAveDev:: GenSlidingWindowFunction(std::stringstream &ss,
9812 : const std::string &sSymName, SubArguments &vSubArguments)
9813 : {
9814 0 : ss << "\ndouble " << sSymName;
9815 0 : ss << "_"<< BinFuncName() <<"( ";
9816 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
9817 : {
9818 0 : if (i)
9819 0 : ss << ",";
9820 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
9821 : }
9822 0 : ss << ")\n";
9823 0 : ss <<"{\n";
9824 0 : ss << " int gid0 = get_global_id(0);\n";
9825 0 : ss << " double sum=0.0;\n";
9826 0 : ss << " double length;\n";
9827 0 : ss << " double totallength=0;\n";
9828 0 : ss << " double tmp = 0;\n";
9829 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
9830 : {
9831 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
9832 : assert(pCur);
9833 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
9834 : {
9835 : const formula::DoubleVectorRefToken* pDVR =
9836 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
9837 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
9838 0 : ss << " length="<<nCurWindowSize;
9839 0 : ss << ";\n";
9840 0 : ss << " for (int i = ";
9841 0 : ss << "0; i < "<< nCurWindowSize << "; i++)\n";
9842 0 : ss << " {\n";
9843 0 : ss << " double arg"<<i<<" = ";
9844 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
9845 0 : ss << ";\n";
9846 0 : ss << " if(isNan(arg"<<i<<")||((gid0+i)>=";
9847 0 : ss << pDVR->GetArrayLength();
9848 0 : ss << "))\n";
9849 0 : ss << " {\n";
9850 0 : ss << " length-=1.0;\n";
9851 0 : ss << " continue;\n";
9852 0 : ss << " }\n";
9853 0 : ss << " sum += arg"<<i<<";\n";
9854 0 : ss << " }\n";
9855 0 : ss << " totallength +=length;\n";
9856 : }
9857 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
9858 : {
9859 0 : ss << " tmp = ";
9860 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
9861 0 : ss << ";\n";
9862 0 : ss << " if(!isNan(tmp))\n";
9863 0 : ss << " {\n";
9864 0 : ss << " sum += tmp;\n";
9865 0 : ss << " totallength +=1;\n";
9866 0 : ss << " }\n";
9867 : }
9868 0 : else if (pCur->GetType() == formula::svDouble)
9869 : {
9870 0 : ss << " tmp = ";
9871 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
9872 0 : ss << ";\n";
9873 0 : ss << " sum += tmp;\n";
9874 0 : ss << " totallength +=1;\n";
9875 : }
9876 : }
9877 0 : ss << " double mean = sum * pow(totallength,-1);\n";
9878 0 : ss << " sum = 0.0;\n";
9879 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
9880 : {
9881 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
9882 : assert(pCur);
9883 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
9884 : {
9885 : const formula::DoubleVectorRefToken* pDVR =
9886 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
9887 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
9888 0 : ss << " for (int i = ";
9889 0 : ss << "0; i < "<< nCurWindowSize << "; i++)\n";
9890 0 : ss << " {\n";
9891 0 : ss << " double arg"<<i<<" = ";
9892 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
9893 0 : ss << ";\n";
9894 0 : ss << " if(isNan(arg"<<i<<")||((gid0+i)>=";
9895 0 : ss << pDVR->GetArrayLength();
9896 0 : ss << "))\n";
9897 0 : ss << " {\n";
9898 0 : ss << " continue;\n";
9899 0 : ss << " }\n";
9900 0 : ss << " sum += fabs(arg"<<i<<"-mean);\n";
9901 0 : ss << " }\n";
9902 : }
9903 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
9904 : {
9905 0 : ss << " tmp = ";
9906 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
9907 0 : ss << ";\n";
9908 0 : ss << " if(!isNan(tmp))\n";
9909 0 : ss << " {\n";
9910 0 : ss << " sum += fabs(tmp-mean);\n";
9911 0 : ss << " }\n";
9912 : }
9913 0 : else if (pCur->GetType() == formula::svDouble)
9914 : {
9915 0 : ss << " tmp = ";
9916 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
9917 0 : ss << ";\n";
9918 0 : ss << " sum += fabs(tmp-mean);\n";
9919 : }
9920 : }
9921 0 : ss << " tmp=sum*pow(totallength,-1);\n";
9922 0 : ss << " return tmp;\n";
9923 0 : ss << "}";
9924 0 : }
9925 156 : }}
9926 :
9927 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|