1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #include "op_statistical.hxx"
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>
20 #include "opinlinefun_statistical.cxx"
22 using namespace formula
;
24 namespace sc
{ namespace opencl
{
25 void OpVar::GenSlidingWindowFunction(std::stringstream
&ss
,
26 const std::string
&sSymName
, SubArguments
&vSubArguments
)
28 ss
<< "\ndouble " << sSymName
;
29 ss
<< "_" << BinFuncName() << "(";
30 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
34 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
37 ss
<< " int gid0 = get_global_id(0);\n";
38 ss
<< " double fSum = 0.0;\n";
39 ss
<< " double fMean = 0.0;\n";
40 ss
<< " double vSum = 0.0;\n";
41 ss
<< " double fCount = 0.0;\n";
42 ss
<< " double arg = 0.0;\n";
43 unsigned i
= vSubArguments
.size();
46 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
48 if(ocPush
== vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
50 if (pCur
->GetType() == formula::svDoubleVectorRef
)
52 const formula::DoubleVectorRefToken
* pDVR
=
53 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
54 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
55 ss
<< " for (int i = ";
56 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
58 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
59 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
62 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
64 ss
<< "0; i < " << pDVR
->GetArrayLength();
65 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
68 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
70 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
71 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
76 ss
<< "0; i < " << pDVR
->GetArrayLength() << "; i++)\n";
80 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
82 ss
<< " if (isNan(arg))\n";
84 ss
<< " fSum += arg;\n";
85 ss
<< " fCount += 1.0;\n";
88 else if (pCur
->GetType() == formula::svSingleVectorRef
)
90 const formula::SingleVectorRefToken
* pSVR
=
91 static_cast< const formula::SingleVectorRefToken
*>(pCur
);
92 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
95 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
96 ss
<< " if (!isNan(arg))\n";
98 ss
<< " fSum += arg;\n";
99 ss
<< " fCount += 1.0;\n";
105 ss
<< " arg = " << pCur
->GetDouble() << ";\n";
106 ss
<< " fSum += arg;\n";
107 ss
<< " fCount += 1.0;\n";
113 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
114 ss
<< " fSum += arg;\n";
115 ss
<< " fCount += 1.0;\n";
119 ss
<< " fMean = fSum * pow(fCount,-1.0);\n";
122 i
= vSubArguments
.size();
125 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
127 if(ocPush
== vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
129 if (pCur
->GetType() == formula::svDoubleVectorRef
)
131 const formula::DoubleVectorRefToken
* pDVR
=
132 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
133 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
134 ss
<< " for (int i = ";
135 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
137 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
138 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
141 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
143 ss
<< "0; i < " << pDVR
->GetArrayLength();
144 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
147 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
149 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
150 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
155 ss
<< "0; i < " << pDVR
->GetArrayLength() << "; i++)\n";
160 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
162 ss
<< " if (isNan(arg))\n";
163 ss
<< " continue;\n";
164 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
167 else if (pCur
->GetType() == formula::svSingleVectorRef
)
169 const formula::SingleVectorRefToken
* pSVR
=
170 static_cast< const formula::SingleVectorRefToken
*>(pCur
);
171 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
173 ss
<< " if (!isNan(";
174 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
178 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
179 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
185 ss
<< " arg=" << pCur
->GetDouble() << ";\n";
186 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
192 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
193 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
196 ss
<< " if (fCount <= 1.0)\n";
197 ss
<< " return CreateDoubleError(errDivisionByZero);\n";
199 ss
<< " return vSum * pow(fCount - 1.0,-1.0);\n";
202 void OpZTest::BinInlineFun(std::set
<std::string
>& decls
,
203 std::set
<std::string
>& funs
)
205 decls
.insert(phiDecl
);
207 decls
.insert(taylorDecl
);
209 decls
.insert(gaussDecl
);
212 void OpZTest::GenSlidingWindowFunction(std::stringstream
&ss
,
213 const std::string
&sSymName
, SubArguments
&vSubArguments
)
215 ss
<< "\ndouble " << sSymName
;
216 ss
<< "_" << BinFuncName() << "(";
217 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
221 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
224 ss
<< " int gid0 = get_global_id(0);\n";
225 ss
<< " double fSum = 0.0;\n";
226 ss
<< " double fSumSqr = 0.0;\n";
227 ss
<< " double mue = 0.0;\n";
228 ss
<< " double fCount = 0.0;\n";
229 ss
<< " double arg = 0.0;\n";
230 ss
<< " double sigma = 0.0;\n";
231 ss
<< " double mu = 0.0;\n";
232 if(vSubArguments
.size() == 1 || vSubArguments
.size() == 0)
234 ss
<< " return DBL_MAX;\n";
238 else if(vSubArguments
.size() == 2)
240 FormulaToken
*pCur
= vSubArguments
[0]->GetFormulaToken();
241 FormulaToken
*pCur1
= vSubArguments
[1]->GetFormulaToken();
244 if(pCur
->GetType() == formula::svDoubleVectorRef
)
246 const formula::DoubleVectorRefToken
* pDVR
=
247 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
248 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
249 ss
<< " for (int i = ";
250 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
252 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
253 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
256 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
258 ss
<< "0; i < " << pDVR
->GetArrayLength();
259 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
262 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
264 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
265 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
270 ss
<< "0; i < " << pDVR
->GetArrayLength() << "; i++)\n";
275 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
276 ss
<< " if (isNan(arg))\n";
277 ss
<< " continue;\n";
278 ss
<< " fSum += arg;\n";
279 ss
<< " fSumSqr += arg * arg;\n";
280 ss
<< " fCount += 1.0;\n";
282 ss
<< " if(fCount <= 1.0)\n";
283 ss
<< " return DBL_MAX;\n";
284 ss
<< " mue = fSum *pow(fCount,-1.0);\n";
285 ss
<< " sigma = (fSumSqr-fSum*fSum*";
286 ss
<< "pow(fCount,-1.0))*pow(fCount-1.0,-1.0);\n";
290 ss
<< " return DBL_MAX;\n";
294 if(ocPush
== vSubArguments
[1]->GetFormulaToken()->GetOpCode())
296 if(pCur1
->GetType() == formula::svSingleVectorRef
)
298 const formula::SingleVectorRefToken
* pSVR
=
299 static_cast<const formula::SingleVectorRefToken
* >(pCur1
);
300 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
303 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
304 ss
<< " if (isNan(mu))\n";
305 ss
<< " mu = 0.0;\n";
309 else if(pCur1
->GetType() == formula::svDouble
)
311 ss
<< " mu = " << pCur1
->GetDouble() << ";\n";
315 ss
<< " return DBL_MAX;\n";
323 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
325 ss
<< " return 0.5 - gauss((mue-mu)/sqrt(sigma/fCount));\n";
331 FormulaToken
*pCur
= vSubArguments
[0]->GetFormulaToken();
332 FormulaToken
*pCur1
= vSubArguments
[1]->GetFormulaToken();
333 FormulaToken
*pCur2
= vSubArguments
[2]->GetFormulaToken();
337 if(pCur
->GetType() == formula::svDoubleVectorRef
)
339 const formula::DoubleVectorRefToken
* pDVR
=
340 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
341 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
342 ss
<< " for (int i = ";
343 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
345 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
346 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
349 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
351 ss
<< "0; i < " << pDVR
->GetArrayLength();
352 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
355 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
357 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
358 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
363 ss
<< "0; i < " << pDVR
->GetArrayLength() << "; i++)\n";
367 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
368 ss
<< " if (isNan(arg))\n";
369 ss
<< " continue;\n";
370 ss
<< " fSum += arg;\n";
371 ss
<< " fSumSqr += arg * arg;\n";
372 ss
<< " fCount += 1.0;\n";
374 ss
<< " if(fCount <= 1.0)\n";
375 ss
<< " return DBL_MAX;\n";
376 ss
<< " mue = fSum * pow(fCount,-1.0);\n";
380 ss
<< " return DBL_MAX;\n";
384 if(ocPush
== vSubArguments
[1]->GetFormulaToken()->GetOpCode())
386 if(pCur1
->GetType() == formula::svSingleVectorRef
)
388 const formula::SingleVectorRefToken
* pSVR1
=
389 static_cast<const formula::SingleVectorRefToken
* >(pCur1
);
390 ss
<< " if (gid0 < " << pSVR1
->GetArrayLength() << ")\n";
393 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
394 ss
<< " if (isNan(mu))\n";
395 ss
<< " mu = 0.0;\n";
398 else if(pCur1
->GetType() == formula::svDouble
)
400 ss
<< " mu = " << pCur1
->GetDouble() << ";\n";
404 ss
<< " return DBL_MAX;\n";
412 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
414 if(ocPush
== vSubArguments
[2]->GetFormulaToken()->GetOpCode())
416 if(pCur2
->GetType() == formula::svSingleVectorRef
)
418 const formula::SingleVectorRefToken
* pSVR2
=
419 static_cast<const formula::SingleVectorRefToken
* >(pCur2
);
420 ss
<< " if (gid0 < " << pSVR2
->GetArrayLength() << ")\n";
423 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef() << ";\n";
424 ss
<< " if (isNan(sigma))\n";
425 ss
<< " sigma = 0.0;\n";
428 else if(pCur2
->GetType() == formula::svDouble
)
430 ss
<< " sigma = " << pCur2
->GetDouble() << ";\n";
434 ss
<< " return DBL_MAX;\n";
442 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef() << ";\n";
444 ss
<< " return 0.5 - gauss((mue-mu)*sqrt(fCount)/sigma);\n";
449 void OpTTest::BinInlineFun(std::set
<std::string
>& decls
,
450 std::set
<std::string
>& funs
)
452 decls
.insert(fMachEpsDecl
);
454 decls
.insert(fMaxGammaArgumentDecl
);
456 decls
.insert(lcl_getLanczosSumDecl
);
457 funs
.insert(lcl_getLanczosSum
);
458 decls
.insert(GetBetaDecl
);
459 funs
.insert(GetBeta
);
460 decls
.insert(GetLogBetaDecl
);
461 funs
.insert(GetLogBeta
);
462 decls
.insert(GetBetaDistPDFDecl
);
463 funs
.insert(GetBetaDistPDF
);
464 decls
.insert(lcl_GetBetaHelperContFracDecl
);
465 funs
.insert(lcl_GetBetaHelperContFrac
);
466 decls
.insert(GetBetaDistDecl
);
467 funs
.insert(GetBetaDist
);
468 decls
.insert(GetTDistDecl
);
469 funs
.insert(GetTDist
);
472 void OpTTest::GenSlidingWindowFunction(std::stringstream
&ss
,
473 const std::string
&sSymName
, SubArguments
&vSubArguments
)
475 ss
<< "\ndouble " << sSymName
;
476 ss
<< "_" << BinFuncName() << "(";
477 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
481 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
484 ss
<< " int gid0 = get_global_id(0);\n";
485 ss
<< " double fSum1 = 0.0;\n";
486 ss
<< " double fSum2 = 0.0;\n";
487 ss
<< " double fSumSqr1 = 0.0;\n";
488 ss
<< " double fSumSqr2 = 0.0;\n";
489 ss
<< " double fCount1 = 0.0;\n";
490 ss
<< " double fCount2 = 0.0;\n";
491 ss
<< " double arg1 = 0.0;\n";
492 ss
<< " double arg2 = 0.0;\n";
493 ss
<< " double mode = 0.0;\n";
494 ss
<< " double type = 0.0;\n";
495 ss
<< " double fT = 0.0;\n";
496 ss
<< " double fF = 0.0;\n";
497 if(vSubArguments
.size() != 4)
499 ss
<< " return DBL_MAX;\n";
503 if(vSubArguments
.size() == 4)
505 FormulaToken
*pCur
= vSubArguments
[0]->GetFormulaToken();
506 FormulaToken
*pCur1
= vSubArguments
[1]->GetFormulaToken();
507 FormulaToken
*pCur2
= vSubArguments
[2]->GetFormulaToken();
508 FormulaToken
*pCur3
= vSubArguments
[3]->GetFormulaToken();
513 if(ocPush
== vSubArguments
[2]->GetFormulaToken()->GetOpCode())
515 if(pCur2
->GetType() == formula::svSingleVectorRef
)
517 const formula::SingleVectorRefToken
* pSVR
=
518 static_cast< const formula::SingleVectorRefToken
*>(pCur2
);
519 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
522 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef() << ";\n";
523 ss
<< " if (isNan(mode))\n";
524 ss
<< " mode = 0.0;\n";
526 ss
<< " mode = floor(mode);\n";
529 else if(pCur2
->GetType() == formula::svDouble
)
531 ss
<< " mode = floor(convert_double(";
532 ss
<< pCur2
->GetDouble() << "));\n";
536 ss
<< " return DBL_MAX;\n";
543 ss
<< " mode = floor(" ;
544 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef() << ");\n";
546 ss
<< " if(!(mode == 1.0 || mode == 2.0))\n";
547 ss
<< " return DBL_MAX;\n";
548 if(ocPush
==vSubArguments
[3]->GetFormulaToken()->GetOpCode())
550 if(pCur3
->GetType() == formula::svSingleVectorRef
)
552 const formula::SingleVectorRefToken
* pSVR
=
553 static_cast< const formula::SingleVectorRefToken
*>(pCur3
);
555 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
558 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef() << "))\n";
559 ss
<< " type=0.0;\n";
561 ss
<< " type=floor(";
562 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef() << ");\n";
565 else if(pCur3
->GetType() == formula::svDouble
)
567 ss
<< " type = floor(convert_double(" << pCur3
->GetDouble() <<
572 ss
<< " return DBL_MAX;\n";
579 ss
<< " type=floor(";
580 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef() << ");\n";
582 ss
<< " if(!(type == 1.0||type == 2.0||type == 3.0))\n";
583 ss
<< " return DBL_MAX;\n";
585 if(pCur
->GetType() == formula::svDoubleVectorRef
&&
586 pCur1
->GetType() == formula::svDoubleVectorRef
)
588 const formula::DoubleVectorRefToken
* pDVR
=
589 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
590 const formula::DoubleVectorRefToken
* pDVR1
=
591 static_cast<const formula::DoubleVectorRefToken
*>(pCur1
);
593 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
594 size_t nCurWindowSize1
= pDVR1
->GetRefRowSize();
596 if(nCurWindowSize
== nCurWindowSize1
)
598 ss
<< " if(type == 1.0)\n";
600 ss
<< " for (int i = ";
601 if ((!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) &&
602 (!pDVR1
->IsStartFixed() && pDVR1
->IsEndFixed()))
604 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
605 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
608 else if ((pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) &&
609 (pDVR1
->IsStartFixed() && !pDVR1
->IsEndFixed()))
611 ss
<< "0; i < " << pDVR
->GetArrayLength();
612 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++)\n";
615 else if ((!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) &&
616 (!pDVR1
->IsStartFixed() && !pDVR1
->IsEndFixed()))
618 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
619 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
622 else if ((pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) &&
623 (pDVR1
->IsStartFixed() && pDVR1
->IsEndFixed()))
625 ss
<< "0; i < " << nCurWindowSize
<< "; i++)\n";
630 ss
<< "0; i < " << nCurWindowSize
<< "; i++)\n";
634 ss
<< " return DBL_MAX;\n";
641 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef(true) << ";\n";
643 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef(true) << ";\n";
644 ss
<< " if (isNan(arg1)||isNan(arg2))\n";
645 ss
<< " continue;\n";
646 ss
<< " fSum1 += arg1;\n";
647 ss
<< " fSum2 += arg2;\n";
648 ss
<< " fSumSqr1 += (arg1 - arg2)*(arg1 - arg2);\n";
649 ss
<< " fCount1 += 1;\n";
651 ss
<< " if(fCount1 < 1.0)\n";
652 ss
<< " return DBL_MAX;\n";
653 ss
<< " fT = sqrt(fCount1-1.0) * fabs(fSum1 - fSum2)\n";
654 ss
<< " /sqrt(fCount1 * fSumSqr1 - (fSum1-fSum2)\n";
655 ss
<< " *(fSum1-fSum2));\n";
656 ss
<< " fF = fCount1 - 1.0;\n";
660 ss
<< " return DBL_MAX;\n";
667 ss
<< " return DBL_MAX;\n";
672 ss
<< " if(type == 2.0 || type == 3.0)\n";
675 if(pCur
->GetType() == formula::svDoubleVectorRef
&&
676 pCur1
->GetType() == formula::svDoubleVectorRef
)
678 const formula::DoubleVectorRefToken
* pDVR
=
679 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
680 const formula::DoubleVectorRefToken
* pDVR1
=
681 static_cast<const formula::DoubleVectorRefToken
*>(pCur1
);
683 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
684 size_t nCurWindowSize1
= pDVR1
->GetRefRowSize();
685 ss
<< " for (int i = ";
686 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
688 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
689 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
692 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
694 ss
<< "0; i < " << pDVR
->GetArrayLength();
695 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++)\n";
698 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
700 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
701 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
706 ss
<< "0; i < " << nCurWindowSize
<< "; i++)\n";
711 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef(true) << ";\n";
712 ss
<< " if (isNan(arg1))\n";
713 ss
<< " continue;\n";
714 ss
<< " fSum1 += arg1;\n";
715 ss
<< " fSumSqr1 += arg1 * arg1;\n";
716 ss
<< " fCount1 += 1;\n";
719 ss
<< " for (int i = ";
720 if (!pDVR1
->IsStartFixed() && pDVR1
->IsEndFixed())
722 ss
<< "gid0; i < " << pDVR1
->GetArrayLength();
723 ss
<< " && i < " << nCurWindowSize1
<< "; i++)\n";
726 else if (pDVR1
->IsStartFixed() && !pDVR1
->IsEndFixed())
728 ss
<< "0; i < " << pDVR1
->GetArrayLength();
729 ss
<< " && i < gid0+"<< nCurWindowSize1
<< "; i++)\n";
732 else if (!pDVR1
->IsStartFixed() && !pDVR1
->IsEndFixed())
734 ss
<< "0; i + gid0 < " << pDVR1
->GetArrayLength();
735 ss
<< " && i < " << nCurWindowSize1
<< "; i++)\n";
740 ss
<< "0; i < " << nCurWindowSize1
<< "; i++)\n";
744 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef(true) << ";\n";
745 ss
<< " if (isNan(arg2))\n";
746 ss
<< " continue;\n";
747 ss
<< " fSum2 += arg2;\n";
748 ss
<< " fSumSqr2 += arg2 * arg2;\n";
749 ss
<< " fCount2 += 1;\n";
754 ss
<< " return DBL_MAX;\n";
759 ss
<< " if (fCount1 < 2.0 || fCount2 < 2.0)\n";
760 ss
<< " return DBL_MAX;\n";
762 ss
<< " if(type == 3.0)\n";
764 ss
<< " double fS1 = (fSumSqr1-fSum1*fSum1/fCount1)\n";
765 ss
<< " /(fCount1-1.0)/fCount1;\n";
766 ss
<< " double fS2 = (fSumSqr2-fSum2*fSum2/fCount2)\n";
767 ss
<< " /(fCount2-1.0)/fCount2;\n";
768 ss
<< " if (fS1 + fS2 == 0.0)\n";
769 ss
<< " return DBL_MAX;\n";
770 ss
<< " fT = fabs(fSum1/fCount1 - fSum2/fCount2)\n";
771 ss
<< " /sqrt(fS1+fS2);\n";
772 ss
<< " double c = fS1/(fS1+fS2);\n";
773 ss
<< " fF = 1.0/(c*c/(fCount1-1.0)+(1.0-c)*(1.0-c)\n";
774 ss
<< " /(fCount2-1.0));\n";
776 ss
<< " if(type == 2.0)\n";
778 ss
<< " double fS1 = (fSumSqr1 - fSum1*fSum1/fCount1)\n";
779 ss
<< " /(fCount1 - 1.0);\n";
780 ss
<< " double fS2 = (fSumSqr2 - fSum2*fSum2/fCount2)\n";
781 ss
<< " /(fCount2 - 1.0);\n";
782 ss
<< " fT = fabs( fSum1/fCount1 - fSum2/fCount2 )\n";
783 ss
<< " /sqrt( (fCount1-1.0)*fS1 + (fCount2-1.0)*fS2 )\n";
784 ss
<< " *sqrt( fCount1*fCount2*(fCount1+fCount2-2)\n";
785 ss
<< " /(fCount1+fCount2) );\n";
786 ss
<< " fF = fCount1 + fCount2 - 2;\n";
789 ss
<< " double tdist=GetTDist(fT, fF);\n";
790 ss
<< " if (mode==1)\n";
791 ss
<< " return tdist;\n";
793 ss
<< " return 2.0*tdist;\n";
797 void OpVarP::GenSlidingWindowFunction(std::stringstream
&ss
,
798 const std::string
&sSymName
, SubArguments
&vSubArguments
)
800 ss
<< "\ndouble " << sSymName
;
801 ss
<< "_" << BinFuncName() << "(";
802 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
806 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
809 ss
<< " int gid0 = get_global_id(0);\n";
810 ss
<< " double fSum = 0.0;\n";
811 ss
<< " double fMean = 0.0;\n";
812 ss
<< " double vSum = 0.0;\n";
813 ss
<< " double fCount = 0.0;\n";
814 ss
<< " double arg = 0.0;\n";
815 unsigned i
= vSubArguments
.size();
818 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
820 if(ocPush
== vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
822 if (pCur
->GetType() == formula::svDoubleVectorRef
)
824 const formula::DoubleVectorRefToken
* pDVR
=
825 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
826 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
827 ss
<< " for (int i = ";
828 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
830 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
831 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
834 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
836 ss
<< "0; i < " << pDVR
->GetArrayLength();
837 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
840 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
842 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
843 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
848 ss
<< "0; i < " << pDVR
->GetArrayLength() << "; i++)\n";
852 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
854 ss
<< " if (isNan(arg))\n";
855 ss
<< " continue;\n";
856 ss
<< " fSum += arg;\n";
857 ss
<< " fCount += 1.0;\n";
860 else if (pCur
->GetType() == formula::svSingleVectorRef
)
862 const formula::SingleVectorRefToken
* pSVR
=
863 static_cast< const formula::SingleVectorRefToken
*>(pCur
);
864 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
867 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
868 ss
<< " if (!isNan(arg))\n";
870 ss
<< " fSum += arg;\n";
871 ss
<< " fCount += 1.0;\n";
877 ss
<< " arg = " << pCur
->GetDouble() << ";\n";
878 ss
<< " fSum += arg;\n";
879 ss
<< " fCount += 1.0;\n";
885 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
886 ss
<< " fSum += arg;\n";
887 ss
<< " fCount += 1.0;\n";
891 ss
<< " fMean = fSum * pow(fCount,-1.0);\n";
894 i
= vSubArguments
.size();
897 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
899 if(ocPush
== vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
901 if (pCur
->GetType() == formula::svDoubleVectorRef
)
903 const formula::DoubleVectorRefToken
* pDVR
=
904 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
905 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
906 ss
<< " for (int i = ";
907 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
909 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
910 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
913 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
915 ss
<< "0; i < " << pDVR
->GetArrayLength();
916 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
919 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
921 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
922 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
927 ss
<< "0; i < " << pDVR
->GetArrayLength() << "; i++)\n";
932 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
934 ss
<< " if (isNan(arg))\n";
935 ss
<< " continue;\n";
936 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
939 else if (pCur
->GetType() == formula::svSingleVectorRef
)
941 const formula::SingleVectorRefToken
* pSVR
=
942 static_cast< const formula::SingleVectorRefToken
*>(pCur
);
943 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
946 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
947 ss
<< " if (!isNan(arg))\n";
949 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
955 ss
<< " arg = " << pCur
->GetDouble() << ";\n";
956 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
962 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
963 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
966 ss
<< " if (fCount == 0.0)\n";
967 ss
<< " return DBL_MAX;\n";
969 ss
<< " return vSum * pow(fCount,-1.0);\n";
973 void OpTDist::BinInlineFun(std::set
<std::string
>& decls
,
974 std::set
<std::string
>& funs
)
976 decls
.insert(fMachEpsDecl
);
978 decls
.insert(fMaxGammaArgumentDecl
);
980 decls
.insert(lcl_getLanczosSumDecl
);
981 funs
.insert(lcl_getLanczosSum
);
982 decls
.insert(GetBetaDecl
);
983 funs
.insert(GetBeta
);
984 decls
.insert(GetLogBetaDecl
);
985 funs
.insert(GetLogBeta
);
986 decls
.insert(GetBetaDistPDFDecl
);
987 funs
.insert(GetBetaDistPDF
);
988 decls
.insert(lcl_GetBetaHelperContFracDecl
);
989 funs
.insert(lcl_GetBetaHelperContFrac
);
990 decls
.insert(GetBetaDistDecl
);
991 funs
.insert(GetBetaDist
);
992 decls
.insert(GetTDistDecl
);
993 funs
.insert(GetTDist
);
995 void OpTDist::GenSlidingWindowFunction(std::stringstream
&ss
,
996 const std::string
&sSymName
, SubArguments
&vSubArguments
)
998 ss
<< "\ndouble " << sSymName
;
999 ss
<< "_" << BinFuncName() << "(";
1000 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1004 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1007 ss
<< " int gid0 = get_global_id(0);\n";
1008 ss
<< " double x = 0.0;\n";
1009 ss
<< " double fDF = 0.0;\n";
1010 ss
<< " double fFlag = 0.0;\n";
1011 if(vSubArguments
.size() != 3)
1013 ss
<< " return DBL_MAX;\n}\n";
1016 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1018 if(ocPush
== vSubArguments
[0]->GetFormulaToken()->GetOpCode())
1020 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
1022 const formula::SingleVectorRefToken
*tmpCurDVR0
=
1023 static_cast<const formula::SingleVectorRefToken
*>(tmpCur0
);
1024 ss
<< " if(gid0 < ";
1025 ss
<< tmpCurDVR0
->GetArrayLength() << ")\n";
1028 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1029 ss
<< " if(isNan(x))\n";
1030 ss
<< " x = 0.0;\n";
1033 else if(tmpCur0
->GetType() == formula::svDouble
)
1035 ss
<< " x = " << tmpCur0
->GetDouble() << ";\n";
1039 ss
<< " return DBL_MAX;\n}\n";
1046 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1048 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
1050 if(ocPush
== vSubArguments
[1]->GetFormulaToken()->GetOpCode())
1052 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
1054 const formula::SingleVectorRefToken
*tmpCurDVR1
=
1055 static_cast<const formula::SingleVectorRefToken
*>(tmpCur1
);
1056 ss
<< " if(gid0 < ";
1057 ss
<< tmpCurDVR1
->GetArrayLength() << ")\n";
1060 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
1061 ss
<< " if(isNan(fDF))\n";
1062 ss
<< " fDF = 0.0;\n";
1064 ss
<< " fDF = floor(fDF);\n";
1067 else if(tmpCur1
->GetType() == formula::svDouble
)
1069 ss
<< " fDF = floor(convert_double(";
1070 ss
<< tmpCur1
->GetDouble() << "));\n";
1074 ss
<< " return DBL_MAX;\n}\n";
1080 ss
<< " fDF = floor(";
1081 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ");\n";
1084 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
1086 if(ocPush
== vSubArguments
[2]->GetFormulaToken()->GetOpCode())
1088 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
1090 const formula::SingleVectorRefToken
*tmpCurDVR2
=
1091 static_cast<const formula::SingleVectorRefToken
*>(tmpCur2
);
1092 ss
<< " if(gid0 < ";
1093 ss
<< tmpCurDVR2
->GetArrayLength() << ")\n";
1096 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef() << ";\n";
1097 ss
<< " if(isNan(fFlag))\n";
1098 ss
<< " fFlag = 0.0;\n";
1100 ss
<< " fFlag = floor(fFlag);\n";
1104 else if(tmpCur2
->GetType() == formula::svDouble
)
1106 ss
<< " fFlag = floor(convert_double(";
1107 ss
<< tmpCur2
->GetDouble() << "));\n";
1111 ss
<< " return DBL_MAX;\n}\n";
1117 ss
<< " fFlag = floor(";
1118 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef() << ");\n";
1120 ss
<< " if(fDF < 1.0 || x < 0.0 || (fFlag != 1.0 && fFlag != 2.0))\n";
1121 ss
<< " return DBL_MAX;\n";
1122 ss
<< " double R = GetTDist(x, fDF);\n";
1123 ss
<< " if (fFlag == 1.0)\n";
1124 ss
<< " return R;\n";
1126 ss
<< " return 2.0 * R;\n";
1129 void OpExponDist::GenSlidingWindowFunction(std::stringstream
&ss
,
1130 const std::string
&sSymName
, SubArguments
&vSubArguments
)
1132 ss
<< "\ndouble " << sSymName
;
1133 ss
<< "_"<< BinFuncName() <<"(";
1134 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1138 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1141 ss
<< " double tmp = 0,tmp0=0,tmp1=0,tmp2=0;\n";
1142 ss
<< " int gid0 = get_global_id(0);\n";
1143 ss
<< " double rx,rlambda,rkum;\n";
1144 size_t i
= vSubArguments
.size();
1146 for (i
= 0; i
< vSubArguments
.size(); i
++)
1148 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
1150 if (pCur
->GetType() == formula::svSingleVectorRef
)
1152 const formula::SingleVectorRefToken
* pSVR
=
1153 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
1154 ss
<< "if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
1156 else if (pCur
->GetType() == formula::svDouble
)
1163 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
1165 ss
<< " if (isNan(";
1166 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
1168 ss
<< " tmp"<<i
<<"= 0;\n";
1170 ss
<< " tmp"<<i
<<"=\n";
1171 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
1176 ss
<< "tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
1180 ss
<< " rx = tmp0;\n";
1181 ss
<< " rlambda = tmp1;\n";
1182 ss
<< " rkum = tmp2;\n";
1183 ss
<<" if(rlambda <= 0.0)\n";
1185 ss
<<" tmp = -DBL_MAX;\n";
1187 ss
<<" else if(rkum == 0)\n";
1189 ss
<<" if(rx >= 0)\n";
1190 ss
<<" tmp = rlambda*exp(-rlambda*rx);\n";
1192 ss
<<" tmp = 0.0;\n";
1196 ss
<<" if(rx > 0)\n";
1197 ss
<<" tmp = 1.0 - exp(-rlambda*rx);\n";
1199 ss
<<" tmp = 0.0;\n";
1201 ss
<<" return tmp;\n";
1204 void OpFdist::BinInlineFun(std::set
<std::string
>& decls
,
1205 std::set
<std::string
>& funs
)
1207 decls
.insert(GetFDistDecl
);decls
.insert(GetBetaDistDecl
);
1208 decls
.insert(GetBetaDecl
);decls
.insert(fMaxGammaArgumentDecl
);
1209 decls
.insert(lcl_GetBetaHelperContFracDecl
);
1210 decls
.insert(GetBetaDistPDFDecl
);
1211 decls
.insert(GetLogBetaDecl
);decls
.insert(lcl_getLanczosSumDecl
);
1212 decls
.insert(fMachEpsDecl
);
1213 funs
.insert(GetFDist
);funs
.insert(GetBetaDist
);
1214 funs
.insert(GetBeta
);
1215 funs
.insert(lcl_GetBetaHelperContFrac
);funs
.insert(GetBetaDistPDF
);
1216 funs
.insert(GetLogBeta
);
1217 funs
.insert(lcl_getLanczosSum
);
1219 void OpFdist::GenSlidingWindowFunction(std::stringstream
&ss
,
1220 const std::string
&sSymName
, SubArguments
&vSubArguments
)
1222 ss
<< "\ndouble " << sSymName
;
1223 ss
<< "_"<< BinFuncName() <<"(";
1224 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1228 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1231 ss
<< " double tmp = 0,tmp0=0,tmp1=0,tmp2=0;\n";
1232 ss
<< " int gid0 = get_global_id(0);\n";
1233 ss
<< " double rF1,rF2,rX;\n";
1234 size_t i
= vSubArguments
.size();
1236 for (i
= 0; i
< vSubArguments
.size(); i
++)
1238 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
1240 if (pCur
->GetType() == formula::svSingleVectorRef
)
1242 const formula::SingleVectorRefToken
* pSVR
=
1243 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
1244 ss
<< "if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
1246 else if (pCur
->GetType() == formula::svDouble
)
1253 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
1255 ss
<< " if (isNan(";
1256 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
1258 ss
<< " tmp"<<i
<<"= 0;\n";
1260 ss
<< " tmp"<<i
<<"=\n";
1261 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
1266 ss
<< "tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
1270 ss
<< " rX = tmp0;\n";
1271 ss
<< " rF1 = floor(tmp1);\n";
1272 ss
<< " rF2 = floor(tmp2);\n";
1273 ss
<<" if (rX < 0.0 || rF1 < 1.0 || rF2 < 1.0 || rF1 >= 1.0E10 ||";
1274 ss
<<"rF2 >= 1.0E10)\n";
1276 ss
<<" tmp = -DBL_MAX;\n";
1278 ss
<<" tmp = GetFDist(rX, rF1, rF2);\n";
1279 ss
<<" return tmp;\n";
1283 void OpStandard::GenSlidingWindowFunction(std::stringstream
&ss
,
1284 const std::string
&sSymName
, SubArguments
&vSubArguments
)
1286 ss
<< "\ndouble " << sSymName
;
1287 ss
<< "_" << BinFuncName() << "(";
1288 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1292 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1295 ss
<< " int gid0 = get_global_id(0);\n";
1296 ss
<< " double x = 0.0;\n";
1297 ss
<< " double mu = 0.0;\n";
1298 ss
<< " double sigma = 0.0;\n";
1299 if(vSubArguments
.size() != 3)
1301 ss
<< " return DBL_MAX;\n}\n";
1304 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1306 if(ocPush
== vSubArguments
[0]->GetFormulaToken()->GetOpCode())
1308 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
1310 const formula::SingleVectorRefToken
*tmpCurSVR0
=
1311 static_cast<const formula::SingleVectorRefToken
*>(tmpCur0
);
1312 ss
<< " if (gid0 < " << tmpCurSVR0
->GetArrayLength() << ")\n";
1315 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1316 ss
<< " if (isNan(x))\n";
1317 ss
<< " x = 0.0;\n";
1320 else if(tmpCur0
->GetType() == formula::svDouble
)
1322 ss
<< " x = " << tmpCur0
->GetDouble() << ";\n";
1326 ss
<< " return DBL_MAX;\n}\n";
1333 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1336 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
1338 if(ocPush
== vSubArguments
[1]->GetFormulaToken()->GetOpCode())
1340 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
1342 const formula::SingleVectorRefToken
*tmpCurSVR1
=
1343 static_cast<const formula::SingleVectorRefToken
*>(tmpCur1
);
1344 ss
<< " if (gid0 < " << tmpCurSVR1
->GetArrayLength() << ")\n";
1347 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
1348 ss
<< " if (isNan(mu))\n";
1349 ss
<< " mu = 0.0;\n";
1352 else if(tmpCur1
->GetType() == formula::svDouble
)
1354 ss
<< " mu = " << tmpCur1
->GetDouble() << ";\n";
1358 ss
<< " return DBL_MAX;\n}\n";
1365 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
1368 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
1370 if(ocPush
== vSubArguments
[2]->GetFormulaToken()->GetOpCode())
1372 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
1374 const formula::SingleVectorRefToken
*tmpCurSVR2
=
1375 static_cast<const formula::SingleVectorRefToken
*>(tmpCur2
);
1376 ss
<< " if (gid0 < " << tmpCurSVR2
->GetArrayLength() << ")\n";
1379 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef() << ";\n";
1380 ss
<< " if (isNan(sigma))\n";
1381 ss
<< " sigma = 0.0;\n";
1384 else if(tmpCur2
->GetType() == formula::svDouble
)
1386 ss
<< " sigma = " << tmpCur2
->GetDouble() << ";\n";
1390 ss
<< " return DBL_MAX;\n";
1398 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef() << ";\n";
1401 ss
<< " if(sigma <= 0.0)\n";
1402 ss
<< " return DBL_MAX;\n";
1404 ss
<< " return (x - mu)*pow(sigma,-1.0);\n";
1408 void OpWeibull::GenSlidingWindowFunction(std::stringstream
&ss
,
1409 const std::string
&sSymName
, SubArguments
&vSubArguments
)
1411 ss
<< "\ndouble " << sSymName
;
1412 ss
<< "_" << BinFuncName() << "(";
1413 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1417 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1420 ss
<< " int gid0 = get_global_id(0);\n";
1421 ss
<< " double x = 0.0;\n";
1422 ss
<< " double alpha = 0.0;\n";
1423 ss
<< " double beta = 0.0;\n";
1424 ss
<< " double kum = 0.0;\n";
1425 if(vSubArguments
.size() != 4)
1427 ss
<< " return DBL_MAX;\n}\n";
1430 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1432 if(ocPush
== vSubArguments
[0]->GetFormulaToken()->GetOpCode())
1434 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
1436 const formula::SingleVectorRefToken
*tmpCurSVR0
=
1437 static_cast<const formula::SingleVectorRefToken
*>(tmpCur0
);
1438 ss
<< " if (gid0 < " << tmpCurSVR0
->GetArrayLength() << ")\n";
1441 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1442 ss
<< " if (isNan(x))\n";
1443 ss
<< " x = 0.0;\n";
1446 else if(tmpCur0
->GetType() == formula::svDouble
)
1448 ss
<< " x = " << tmpCur0
->GetDouble() << ";\n";
1452 ss
<< " return DBL_MAX;\n}\n";
1459 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1462 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
1464 if(ocPush
== vSubArguments
[1]->GetFormulaToken()->GetOpCode())
1466 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
1468 const formula::SingleVectorRefToken
*tmpCurSVR1
=
1469 static_cast<const formula::SingleVectorRefToken
*>(tmpCur1
);
1470 ss
<< " if (gid0 < " << tmpCurSVR1
->GetArrayLength() << ")\n";
1473 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
1474 ss
<< " if (isNan(alpha))\n";
1475 ss
<< " alpha = 0.0;\n";
1478 else if(tmpCur1
->GetType() == formula::svDouble
)
1480 ss
<< " alpha = " << tmpCur1
->GetDouble() << ";\n";
1484 ss
<< " return DBL_MAX;\n}\n";
1491 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
1494 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
1496 if(ocPush
== vSubArguments
[2]->GetFormulaToken()->GetOpCode())
1498 if(tmpCur2
->GetType() == formula::svSingleVectorRef
)
1500 const formula::SingleVectorRefToken
*tmpCurSVR2
=
1501 static_cast<const formula::SingleVectorRefToken
*>(tmpCur2
);
1502 ss
<< " if (gid0 < " << tmpCurSVR2
->GetArrayLength() << ")\n";
1505 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef() << ";\n";
1506 ss
<< " if (isNan(beta))\n";
1507 ss
<< " beta = 0.0;\n";
1510 else if(tmpCur2
->GetType() == formula::svDouble
)
1512 ss
<< " beta = " << tmpCur2
->GetDouble() << ";\n";
1516 ss
<< " return DBL_MAX;\n}\n";
1523 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef() << ";\n";
1526 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
1528 if(ocPush
== vSubArguments
[3]->GetFormulaToken()->GetOpCode())
1530 if(tmpCur3
->GetType() == formula::svSingleVectorRef
)
1532 const formula::SingleVectorRefToken
*tmpCurSVR3
=
1533 static_cast<const formula::SingleVectorRefToken
*>(tmpCur3
);
1534 ss
<< " if (gid0 < " << tmpCurSVR3
->GetArrayLength() << ")\n";
1537 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef() << ";\n";
1538 ss
<< " if (isNan(kum))\n";
1539 ss
<< " kum = 0.0;\n";
1542 else if(tmpCur3
->GetType() == formula::svDouble
)
1544 ss
<< " kum = " << tmpCur3
->GetDouble() << ";\n";
1548 ss
<< " return DBL_MAX;\n}\n";
1555 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef() << ";\n";
1558 ss
<< " if(alpha <= 0.0 || beta <=0.0 || kum < 0.0)\n";
1559 ss
<< " return DBL_MAX;\n";
1560 ss
<< " else if(kum == 0.0)\n";
1562 ss
<< " return alpha*pow(pow(beta,alpha),-1.0)*pow(x,alpha-1.0)";
1563 ss
<< "*exp(-pow(x*pow(beta,-1.0),alpha));\n";
1566 ss
<< " return 1.0-exp(-pow(x*pow(beta,-1.0),alpha));\n";
1570 void OpSkew::GenSlidingWindowFunction(std::stringstream
&ss
,
1571 const std::string
&sSymName
, SubArguments
&vSubArguments
)
1573 ss
<< "\ndouble " << sSymName
;
1574 ss
<< "_" << BinFuncName() << "(";
1575 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1579 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1582 ss
<< " int gid0 = get_global_id(0);\n";
1583 ss
<< " double fSum = 0.0;\n";
1584 ss
<< " double fMean = 0.0;\n";
1585 ss
<< " double vSum = 0.0;\n";
1586 ss
<< " double fCount = 0.0;\n";
1587 ss
<< " double arg = 0.0;\n";
1588 unsigned i
= vSubArguments
.size();
1591 FormulaToken
* pCur
= vSubArguments
[i
]->GetFormulaToken();
1593 if(ocPush
== vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
1595 if (pCur
->GetType() == formula::svDoubleVectorRef
)
1597 const formula::DoubleVectorRefToken
* pDVR
=
1598 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
1599 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
1600 ss
<< " for (int i = ";
1601 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
1603 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
1604 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
1607 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
1609 ss
<< "0; i < " << pDVR
->GetArrayLength();
1610 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
1613 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
1615 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
1616 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
1621 ss
<< "0; i < " << pDVR
->GetArrayLength() << "; i++)\n";
1626 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
1627 ss
<< " if (isNan(arg))\n";
1628 ss
<< " continue;\n";
1629 ss
<< " fSum += arg;\n";
1630 ss
<< " fCount += 1.0;\n";
1633 else if (pCur
->GetType() == formula::svSingleVectorRef
)
1635 const formula::SingleVectorRefToken
* pSVR
=
1636 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
1637 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
1640 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
1641 ss
<< " if (!isNan(arg))\n";
1643 ss
<< " fSum += arg;\n";
1644 ss
<< " fCount += 1.0;\n";
1650 ss
<< " arg = " << pCur
->GetDouble() << ";\n";
1651 ss
<< " fSum += arg;\n";
1652 ss
<< " fCount += 1.0;\n";
1658 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
1659 ss
<< " fSum += arg;\n";
1660 ss
<< " fCount += 1.0;\n";
1665 ss
<< " if(fCount <= 2.0)\n";
1666 ss
<< " return DBL_MAX;\n";
1668 ss
<< " fMean = fSum * pow(fCount,-1.0);\n";
1671 i
= vSubArguments
.size();
1674 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
1676 if(ocPush
== vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
1678 if (pCur
->GetType() == formula::svDoubleVectorRef
)
1680 const formula::DoubleVectorRefToken
* pDVR
=
1681 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
1682 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
1683 ss
<< " for (int i = ";
1684 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
1686 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
1687 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
1690 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
1692 ss
<< "0; i < " << pDVR
->GetArrayLength();
1693 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
1696 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
1698 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
1699 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
1704 ss
<< "0; i < " << pDVR
->GetArrayLength() << "; i++)\n";
1709 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
1710 ss
<< " if (isNan(arg))\n";
1711 ss
<< " continue;\n";
1712 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
1715 else if (pCur
->GetType() == formula::svSingleVectorRef
)
1717 const formula::SingleVectorRefToken
* pSVR
=
1718 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
1719 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
1722 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
1723 ss
<< " if (!isNan(arg))\n";
1725 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
1731 ss
<< " arg = " << pCur
->GetDouble() << ";\n";
1732 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
1738 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
1739 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
1742 ss
<< " double fStdDev = sqrt(vSum * pow(fCount - 1.0,-1.0));\n";
1743 ss
<< " double dx = 0.0;\n";
1744 ss
<< " double xcube = 0.0;\n";
1745 ss
<< " if(fStdDev == 0.0)\n";
1746 ss
<< " return DBL_MAX;\n";
1747 i
= vSubArguments
.size();
1750 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
1752 if(ocPush
== vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
1754 if (pCur
->GetType() == formula::svDoubleVectorRef
)
1756 const formula::DoubleVectorRefToken
* pDVR
=
1757 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
1758 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
1759 ss
<< " for (int i = ";
1760 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
1762 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
1763 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
1766 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
1768 ss
<< "0; i < " << pDVR
->GetArrayLength();
1769 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
1772 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
1774 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
1775 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
1780 ss
<< "0; i < " << pDVR
->GetArrayLength() << "; i++)\n";
1785 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
1786 ss
<< " if (isNan(arg))\n";
1787 ss
<< " continue;\n";
1788 ss
<< " dx = (arg - fMean) * pow(fStdDev,-1.0);\n";
1789 ss
<< " xcube = xcube + dx * dx * dx;\n";
1792 else if (pCur
->GetType() == formula::svSingleVectorRef
)
1794 const formula::SingleVectorRefToken
* pSVR
=
1795 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
1796 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
1799 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
1800 ss
<< " if (!isNan(arg))\n";
1802 ss
<< " dx = (arg - fMean) * pow(fStdDev,-1.0);\n";
1803 ss
<< " xcube = xcube + dx * dx * dx;\n";
1809 ss
<< " arg = " << pCur
->GetDouble() << ";\n";
1810 ss
<< " dx = (arg - fMean) * pow(fStdDev,-1.0);\n";
1811 ss
<< " xcube = xcube + dx * dx * dx;\n";
1817 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
1818 ss
<< " dx = (arg - fMean) * pow(fStdDev,-1.0);\n";
1819 ss
<< " xcube = xcube + dx * dx * dx;\n";
1822 ss
<< " return ((xcube * fCount) * pow(fCount - 1.0,-1.0))";
1823 ss
<< " * pow(fCount - 2.0,-1.0);\n";
1827 void OpSkewp::GenSlidingWindowFunction(std::stringstream
&ss
,
1828 const std::string
&sSymName
, SubArguments
&vSubArguments
)
1830 ss
<< "\ndouble " << sSymName
;
1831 ss
<< "_" << BinFuncName() << "(";
1832 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1836 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1839 ss
<< " int gid0 = get_global_id(0);\n";
1840 ss
<< " double fSum = 0.0;\n";
1841 ss
<< " double fMean = 0.0;\n";
1842 ss
<< " double vSum = 0.0;\n";
1843 ss
<< " double fCount = 0.0;\n";
1844 ss
<< " double arg = 0.0;\n";
1845 unsigned i
= vSubArguments
.size();
1848 FormulaToken
* pCur
= vSubArguments
[i
]->GetFormulaToken();
1850 if(ocPush
== vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
1852 if (pCur
->GetType() == formula::svDoubleVectorRef
)
1854 const formula::DoubleVectorRefToken
* pDVR
=
1855 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
1856 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
1857 ss
<< " for (int i = ";
1858 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
1860 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
1861 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
1864 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
1866 ss
<< "0; i < " << pDVR
->GetArrayLength();
1867 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
1870 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
1872 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
1873 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
1878 ss
<< "0; i < " << pDVR
->GetArrayLength() << "; i++)\n";
1883 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
1884 ss
<< " if (isNan(arg))\n";
1885 ss
<< " continue;\n";
1886 ss
<< " fSum += arg;\n";
1887 ss
<< " fCount += 1.0;\n";
1890 else if (pCur
->GetType() == formula::svSingleVectorRef
)
1892 const formula::SingleVectorRefToken
* pSVR
=
1893 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
1894 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
1897 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
1898 ss
<< " if (!isNan(arg))\n";
1900 ss
<< " fSum += arg;\n";
1901 ss
<< " fCount += 1.0;\n";
1907 ss
<< " arg = " << pCur
->GetDouble() << ";\n";
1908 ss
<< " fSum += arg;\n";
1909 ss
<< " fCount += 1.0;\n";
1915 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
1916 ss
<< " fSum += arg;\n";
1917 ss
<< " fCount += 1.0;\n";
1922 ss
<< " if(fCount <= 2.0)\n";
1923 ss
<< " return DBL_MAX;\n";
1925 ss
<< " fMean = fSum * pow(fCount,-1.0);\n";
1928 i
= vSubArguments
.size();
1931 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
1933 if(ocPush
== vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
1935 if (pCur
->GetType() == formula::svDoubleVectorRef
)
1937 const formula::DoubleVectorRefToken
* pDVR
=
1938 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
1939 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
1940 ss
<< " for (int i = ";
1941 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
1943 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
1944 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
1947 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
1949 ss
<< "0; i < " << pDVR
->GetArrayLength();
1950 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
1953 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
1955 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
1956 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
1961 ss
<< "0; i < " << pDVR
->GetArrayLength() << "; i++)\n";
1966 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
1967 ss
<< " if (isNan(arg))\n";
1968 ss
<< " continue;\n";
1969 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
1972 else if (pCur
->GetType() == formula::svSingleVectorRef
)
1974 const formula::SingleVectorRefToken
* pSVR
=
1975 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
1976 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
1979 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
1980 ss
<< " if (!isNan(arg))\n";
1982 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
1988 ss
<< " arg = " << pCur
->GetDouble() << ";\n";
1989 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
1995 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
1996 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
1999 ss
<< " double fStdDev = sqrt(vSum * pow(fCount,-1.0));\n";
2000 ss
<< " double dx = 0.0;\n";
2001 ss
<< " double xcube = 0.0;\n";
2002 ss
<< " if(fStdDev == 0.0)\n";
2003 ss
<< " return DBL_MAX;\n";
2004 i
= vSubArguments
.size();
2007 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
2009 if(ocPush
== vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
2011 if (pCur
->GetType() == formula::svDoubleVectorRef
)
2013 const formula::DoubleVectorRefToken
* pDVR
=
2014 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
2015 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
2016 ss
<< " for (int i = ";
2017 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
2019 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
2020 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
2023 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
2025 ss
<< "0; i < " << pDVR
->GetArrayLength();
2026 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
2029 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
2031 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
2032 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
2037 ss
<< "0; i < " << pDVR
->GetArrayLength() << "; i++)\n";
2042 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
2043 ss
<< " if (isNan(arg))\n";
2044 ss
<< " continue;\n";
2045 ss
<< " dx = (arg - fMean) * pow(fStdDev,-1.0);\n";
2046 ss
<< " xcube = xcube + dx * dx * dx;\n";
2049 else if (pCur
->GetType() == formula::svSingleVectorRef
)
2051 const formula::SingleVectorRefToken
* pSVR
=
2052 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
2053 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
2056 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
2057 ss
<< " if (!isNan(arg))\n";
2059 ss
<< " dx = (arg - fMean) * pow(fStdDev,-1.0);\n";
2060 ss
<< " xcube = xcube + dx * dx * dx;\n";
2066 ss
<< " arg = " << pCur
->GetDouble() << ";\n";
2067 ss
<< " dx = (arg - fMean) * pow(fStdDev,-1.0);\n";
2068 ss
<< " xcube = xcube + dx * dx * dx;\n";
2074 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
2075 ss
<< " dx = (arg - fMean) * pow(fStdDev,-1.0);\n";
2076 ss
<< " xcube = xcube + dx * dx * dx;\n";
2079 ss
<< " return xcube * pow(fCount,-1.0);\n";
2083 void OpTInv::BinInlineFun(std::set
<std::string
>& decls
,
2084 std::set
<std::string
>& funs
)
2086 decls
.insert(fMachEpsDecl
);
2088 decls
.insert(fMaxGammaArgumentDecl
);
2090 decls
.insert(lcl_getLanczosSumDecl
);
2091 funs
.insert(lcl_getLanczosSum
);
2092 decls
.insert(GetBetaDecl
);
2093 funs
.insert(GetBeta
);
2094 decls
.insert(GetLogBetaDecl
);
2095 funs
.insert(GetLogBeta
);
2096 decls
.insert(GetBetaDistPDFDecl
);
2097 funs
.insert(GetBetaDistPDF
);
2098 decls
.insert(lcl_GetBetaHelperContFracDecl
);
2099 funs
.insert(lcl_GetBetaHelperContFrac
);
2100 decls
.insert(GetBetaDistDecl
);
2101 funs
.insert(GetBetaDist
);
2102 decls
.insert(GetTDistDecl
);
2103 funs
.insert(GetTDist
);
2104 decls
.insert(GetValueDecl
);
2105 funs
.insert(GetValue
);
2106 decls
.insert(lcl_HasChangeOfSignDecl
);
2107 funs
.insert(lcl_HasChangeOfSign
);
2108 decls
.insert(lcl_IterateInverseDecl
);
2109 funs
.insert(lcl_IterateInverse
);
2112 void OpTInv::GenSlidingWindowFunction(std::stringstream
&ss
,
2113 const std::string
&sSymName
, SubArguments
&vSubArguments
)
2115 ss
<< "\ndouble " << sSymName
;
2116 ss
<< "_" << BinFuncName() << "(";
2117 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2121 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2124 ss
<< " int gid0 = get_global_id(0);\n";
2125 ss
<< " double x = 0.0;\n";
2126 ss
<< " double fDF = 0.0;\n";
2127 if(vSubArguments
.size() != 2)
2129 ss
<< " return DBL_MAX;\n}\n";
2132 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
2134 if(ocPush
== vSubArguments
[0]->GetFormulaToken()->GetOpCode())
2136 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
2138 const formula::SingleVectorRefToken
*tmpCurDVR0
=
2139 static_cast<const formula::SingleVectorRefToken
*>(tmpCur0
);
2140 ss
<< " if(gid0 < ";
2141 ss
<< tmpCurDVR0
->GetArrayLength() << ")\n";
2144 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
2145 ss
<< " if(isNan(x))\n";
2146 ss
<< " x = 0.0;\n";
2149 else if(tmpCur0
->GetType() == formula::svDouble
)
2151 ss
<< " x = " << tmpCur0
->GetDouble() << ";\n";
2155 ss
<< " return DBL_MAX;\n}\n";
2162 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
2164 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
2166 if(ocPush
== vSubArguments
[1]->GetFormulaToken()->GetOpCode())
2168 if(tmpCur1
->GetType() == formula::svSingleVectorRef
)
2170 const formula::SingleVectorRefToken
*tmpCurDVR1
=
2171 static_cast<const formula::SingleVectorRefToken
*>(tmpCur1
);
2172 ss
<< " if(gid0 < ";
2173 ss
<< tmpCurDVR1
->GetArrayLength() << ")\n";
2176 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
2177 ss
<< " if(isNan(fDF))\n";
2178 ss
<< " fDF = 0.0;\n";
2180 ss
<< " fDF = floor(fDF);\n";
2183 else if(tmpCur1
->GetType() == formula::svDouble
)
2185 ss
<< " fDF = floor(convert_double(";
2186 ss
<< tmpCur1
->GetDouble() << "));\n";
2190 ss
<< " return DBL_MAX;\n}\n";
2196 ss
<< " fDF = floor(";
2197 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ");\n";
2199 ss
<< " if (x > 1.0||fDF < 1.0 || fDF > 1.0E10 || x <= 0.0)\n";
2200 ss
<< " return DBL_MAX;\n";
2201 ss
<< " bool bConvError;\n";
2202 ss
<< " double fVal = lcl_IterateInverse(\n";
2203 ss
<< " fDF*0.5, fDF, &bConvError,x,fDF );\n";
2204 ss
<< " if (bConvError)\n";
2205 ss
<< " return DBL_MAX;\n";
2206 ss
<< " return fVal;\n";
2210 void OpStDev::GenSlidingWindowFunction(std::stringstream
&ss
,
2211 const std::string
&sSymName
, SubArguments
&vSubArguments
)
2213 ss
<< "\ndouble " << sSymName
;
2214 ss
<< "_" << BinFuncName() << "(";
2215 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2219 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2222 ss
<< " int gid0 = get_global_id(0);\n";
2223 ss
<< " double fSum = 0.0;\n";
2224 ss
<< " double vSum = 0.0;\n";
2225 ss
<< " double fMean = 0.0;\n";
2226 ss
<< " double fCount = 0.0;\n";
2227 ss
<< " double arg = 0.0;\n";
2228 unsigned i
= vSubArguments
.size();
2231 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
2233 if(ocPush
== vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
2235 if (pCur
->GetType() == formula::svDoubleVectorRef
)
2237 const formula::DoubleVectorRefToken
* pDVR
=
2238 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
2239 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
2240 ss
<< " for (int i = ";
2241 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
2243 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
2244 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
2247 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
2249 ss
<< "0; i < " << pDVR
->GetArrayLength();
2250 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
2253 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
2255 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
2256 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
2261 ss
<< "0; i < " << pDVR
->GetArrayLength() << "; i++)\n";
2266 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
2267 ss
<< " if (isNan(arg))\n";
2268 ss
<< " continue;\n";
2269 ss
<< " fSum += arg;\n";
2270 ss
<< " fCount += 1.0;\n";
2273 else if (pCur
->GetType() == formula::svSingleVectorRef
)
2275 const formula::SingleVectorRefToken
* pSVR
=
2276 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
2277 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
2280 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
2281 ss
<< " if (!isNan(arg))\n";
2283 ss
<< " fSum += arg;\n";
2284 ss
<< " fCount += 1.0;\n";
2290 ss
<< " arg = " << pCur
->GetDouble() << ";\n";
2291 ss
<< " fSum += arg;\n";
2292 ss
<< " fCount += 1.0;\n";
2298 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
2299 ss
<< " fSum += arg;\n";
2300 ss
<< " fCount += 1.0;\n";
2304 ss
<< " fMean = fSum * pow(fCount,-1.0);\n";
2307 i
= vSubArguments
.size();
2310 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
2312 if(ocPush
== vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
2314 if (pCur
->GetType() == formula::svDoubleVectorRef
)
2316 const formula::DoubleVectorRefToken
* pDVR
=
2317 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
2318 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
2319 ss
<< " for (int i = ";
2320 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
2322 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
2323 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
2326 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
2328 ss
<< "0; i < " << pDVR
->GetArrayLength();
2329 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
2332 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
2334 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
2335 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
2340 ss
<< "0; i < " << pDVR
->GetArrayLength() << "; i++)\n";
2344 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
2345 ss
<< " if (isNan(arg))\n";
2346 ss
<< " continue;\n";
2347 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
2350 else if (pCur
->GetType() == formula::svSingleVectorRef
)
2352 const formula::SingleVectorRefToken
* pSVR
=
2353 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
2354 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
2357 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
2358 ss
<< " if (!isNan(arg))\n";
2360 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
2366 ss
<< " arg = " << pCur
->GetDouble() << ";\n";
2367 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
2373 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
2374 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
2377 ss
<< " if (fCount <= 1.0)\n";
2378 ss
<< " return DBL_MAX;\n";
2380 ss
<< " return sqrt(vSum * pow(fCount - 1.0,-1.0));\n";
2384 void OpStDevP::GenSlidingWindowFunction(std::stringstream
&ss
,
2385 const std::string
&sSymName
, SubArguments
&vSubArguments
)
2387 ss
<< "\ndouble " << sSymName
;
2388 ss
<< "_" << BinFuncName() << "(";
2389 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2393 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2396 ss
<< " int gid0 = get_global_id(0);\n";
2397 ss
<< " double fSum = 0.0;\n";
2398 ss
<< " double fMean = 0.0;\n";
2399 ss
<< " double vSum = 0.0;\n";
2400 ss
<< " double fCount = 0.0;\n";
2401 ss
<< " double arg = 0.0;\n";
2402 unsigned i
= vSubArguments
.size();
2405 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
2407 if(ocPush
== vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
2409 if (pCur
->GetType() == formula::svDoubleVectorRef
)
2411 const formula::DoubleVectorRefToken
* pDVR
=
2412 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
2413 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
2414 ss
<< " for (int i = ";
2415 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
2417 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
2418 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
2421 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
2423 ss
<< "0; i < " << pDVR
->GetArrayLength();
2424 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
2427 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
2429 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
2430 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
2435 ss
<< "0; i < " << pDVR
->GetArrayLength() << "; i++)\n";
2440 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
2441 ss
<< " if (isNan(arg))\n";
2442 ss
<< " continue;\n";
2443 ss
<< " fSum += arg;\n";
2444 ss
<< " fCount += 1.0;\n";
2447 else if (pCur
->GetType() == formula::svSingleVectorRef
)
2449 const formula::SingleVectorRefToken
* pSVR
=
2450 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
2451 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
2454 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
2455 ss
<< " if (!isNan(arg))\n";
2457 ss
<< " fSum += arg;\n";
2458 ss
<< " fCount += 1.0;\n";
2464 ss
<< " arg = " << pCur
->GetDouble() << ";\n";
2465 ss
<< " fSum += arg;\n";
2466 ss
<< " fCount += 1.0;\n";
2472 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
2473 ss
<< " fSum += arg;\n";
2474 ss
<< " fCount += 1.0;\n";
2479 ss
<< " fMean = fSum * pow(fCount,-1.0);\n";
2482 i
= vSubArguments
.size();
2485 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
2487 if(ocPush
== vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
2489 if (pCur
->GetType() == formula::svDoubleVectorRef
)
2491 const formula::DoubleVectorRefToken
* pDVR
=
2492 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
2493 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
2494 ss
<< " for (int i = ";
2495 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
2497 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
2498 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
2501 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
2503 ss
<< "0; i < " << pDVR
->GetArrayLength();
2504 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
2507 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
2509 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
2510 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
2515 ss
<< "0; i < " << pDVR
->GetArrayLength() << "; i++)\n";
2520 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
2521 ss
<< " if (isNan(arg))\n";
2522 ss
<< " continue;\n";
2523 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
2526 else if (pCur
->GetType() == formula::svSingleVectorRef
)
2528 const formula::SingleVectorRefToken
* pSVR
=
2529 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
2530 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
2533 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
2534 ss
<< " if (!isNan(arg))\n";
2536 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
2542 ss
<< " arg = " << pCur
->GetDouble() << ";\n";
2543 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
2549 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
2550 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
2553 ss
<< " if (fCount == 0.0)\n";
2554 ss
<< " return DBL_MAX;\n";
2556 ss
<< " return sqrt(vSum * pow(fCount,-1.0));\n";
2560 void OpSlope::GenSlidingWindowFunction(std::stringstream
&ss
,
2561 const std::string
&sSymName
, SubArguments
&vSubArguments
)
2563 ss
<< "\ndouble " << sSymName
;
2564 ss
<< "_" << BinFuncName() << "(";
2565 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2569 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2572 ss
<< " int gid0 = get_global_id(0);\n";
2573 ss
<< " double fSumX = 0.0;\n";
2574 ss
<< " double fSumY = 0.0;\n";
2575 ss
<< " double fMeanX = 0.0;\n";
2576 ss
<< " double fMeanY = 0.0;\n";
2577 ss
<< " double fSumDeltaXDeltaY = 0.0;\n";
2578 ss
<< " double fSumSqrDeltaX = 0.0;\n";
2579 ss
<< " double fCount = 0.0;\n";
2580 ss
<< " double argX = 0.0;\n";
2581 ss
<< " double argY = 0.0;\n";
2582 if(vSubArguments
.size() != 2)
2584 ss
<< " return NAN;\n";
2588 FormulaToken
*pCur
= vSubArguments
[1]->GetFormulaToken();
2589 FormulaToken
*pCur1
= vSubArguments
[0]->GetFormulaToken();
2592 if (pCur
->GetType() == formula::svDoubleVectorRef
&&
2593 pCur1
->GetType() == formula::svDoubleVectorRef
)
2595 const formula::DoubleVectorRefToken
* pDVR
=
2596 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
2597 const formula::DoubleVectorRefToken
* pDVR1
=
2598 static_cast<const formula::DoubleVectorRefToken
*>(pCur1
);
2600 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
2601 size_t nCurWindowSize1
= pDVR1
->GetRefRowSize();
2602 size_t arrayLength
= pDVR
->GetArrayLength()<
2603 pDVR1
->GetArrayLength() ? pDVR
->GetArrayLength():
2604 pDVR1
->GetArrayLength();
2605 if(nCurWindowSize
!= nCurWindowSize1
)
2607 ss
<< " return NAN;\n";
2611 ss
<< " for (int i = ";
2612 if ((!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
2613 &&(!pDVR1
->IsStartFixed() && pDVR1
->IsEndFixed()))
2615 ss
<< "gid0; i < " << arrayLength
;
2616 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
2619 else if ((pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
2620 &&(pDVR1
->IsStartFixed() && !pDVR1
->IsEndFixed()))
2622 ss
<< "0; i < " << arrayLength
;
2623 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
2626 else if ((!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
2627 &&(!pDVR1
->IsStartFixed() && !pDVR1
->IsEndFixed()))
2629 ss
<< "0; i + gid0 < " << arrayLength
;
2630 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
2633 else if ((pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
2634 &&(pDVR1
->IsStartFixed() && pDVR1
->IsEndFixed()))
2636 ss
<< "0; i < " << arrayLength
<< "; i++)\n";
2641 ss
<< "0; i < " << nCurWindowSize
<< "; i++)\n";
2645 ss
<< " return NAN;\n";
2651 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
2653 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
2654 ss
<< " if (isNan(argX) || isNan(argY))\n";
2655 ss
<< " continue;\n";
2656 ss
<< " fSumX += argX;\n";
2657 ss
<< " fSumY += argY;\n";
2658 ss
<< " fCount += 1.0;\n";
2661 ss
<< " if (fCount < 1.0)\n";
2662 ss
<< " return CreateDoubleError(errNoValue);\n";
2665 ss
<< " fMeanX = fSumX * pow(fCount,-1.0);\n";
2666 ss
<< " fMeanY = fSumY * pow(fCount,-1.0);\n";
2668 ss
<< " for (int i = ";
2669 if ((!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
2670 &&(!pDVR1
->IsStartFixed() && pDVR1
->IsEndFixed()))
2672 ss
<< "gid0; i < " << arrayLength
;
2673 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
2676 else if ((pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
2677 &&(pDVR1
->IsStartFixed() && !pDVR1
->IsEndFixed()))
2679 ss
<< "0; i < " << arrayLength
;
2680 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
2683 else if ((!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
2684 &&(!pDVR1
->IsStartFixed() && !pDVR1
->IsEndFixed()))
2686 ss
<< "0; i + gid0 < " << arrayLength
;
2687 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
2692 ss
<< "0; i < " << arrayLength
<< "; i++)\n";
2697 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
2699 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
2700 ss
<< " if (isNan(argX) || isNan(argY))\n";
2701 ss
<< " continue;\n";
2702 ss
<< " fSumDeltaXDeltaY += (argX-fMeanX)*(argY-fMeanY);\n";
2703 ss
<< " fSumSqrDeltaX += (argX-fMeanX) * (argX-fMeanX);\n";
2705 ss
<< " if(fSumSqrDeltaX == 0.0)\n";
2706 ss
<< " return CreateDoubleError(errDivisionByZero);\n";
2709 ss
<< " return fSumDeltaXDeltaY*pow(fSumSqrDeltaX,-1.0);\n";
2716 ss
<< " return NAN;\n";
2720 void OpSTEYX::GenSlidingWindowFunction(std::stringstream
&ss
,
2721 const std::string
&sSymName
, SubArguments
&vSubArguments
)
2723 ss
<< "\ndouble " << sSymName
;
2724 ss
<< "_" << BinFuncName() << "(";
2725 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2729 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2732 ss
<< " int gid0 = get_global_id(0);\n";
2733 ss
<< " double fSumX = 0.0;\n";
2734 ss
<< " double fSumY = 0.0;\n";
2735 ss
<< " double fMeanX = 0.0;\n";
2736 ss
<< " double fMeanY = 0.0;\n";
2737 ss
<< " double fSumDeltaXDeltaY = 0.0;\n";
2738 ss
<< " double fSumSqrDeltaX = 0.0;\n";
2739 ss
<< " double fSumSqrDeltaY = 0.0;\n";
2740 ss
<< " double fCount = 0.0;\n";
2741 ss
<< " double argX = 0.0;\n";
2742 ss
<< " double argY = 0.0;\n";
2743 FormulaToken
*pCur
= vSubArguments
[1]->GetFormulaToken();
2744 FormulaToken
*pCur1
= vSubArguments
[0]->GetFormulaToken();
2747 if (pCur
->GetType() == formula::svDoubleVectorRef
&&
2748 pCur1
->GetType() == formula::svDoubleVectorRef
)
2750 const formula::DoubleVectorRefToken
* pDVR
=
2751 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
2752 const formula::DoubleVectorRefToken
* pDVR1
=
2753 static_cast<const formula::DoubleVectorRefToken
*>(pCur1
);
2754 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
2755 size_t nCurWindowSize1
= pDVR1
->GetRefRowSize();
2756 size_t arrayLength
= pDVR
->GetArrayLength()<
2757 pDVR1
->GetArrayLength() ? pDVR
->GetArrayLength():
2758 pDVR1
->GetArrayLength();
2759 if(nCurWindowSize
!= nCurWindowSize1
)
2761 ss
<< " return DBL_MAX;\n";
2765 ss
<< " for (int i = ";
2766 if ((!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
2767 &&(!pDVR1
->IsStartFixed() && pDVR1
->IsEndFixed()))
2769 ss
<< "gid0; i < " << arrayLength
;
2770 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
2773 else if ((pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
2774 &&(pDVR1
->IsStartFixed() && !pDVR1
->IsEndFixed()))
2776 ss
<< "0; i < " << arrayLength
;
2777 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
2780 else if ((!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
2781 &&(!pDVR1
->IsStartFixed() && !pDVR1
->IsEndFixed()))
2783 ss
<< "0; i + gid0 < " << arrayLength
;
2784 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
2787 else if ((pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
2788 &&(pDVR1
->IsStartFixed() && pDVR1
->IsEndFixed()))
2790 ss
<< "0; i < " << arrayLength
<< "; i++)\n";
2795 ss
<< "0; i < " << nCurWindowSize
<< "; i++)\n";
2799 ss
<< " return DBL_MAX;\n";
2805 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
2807 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
2808 ss
<< " if (isNan(argX) || isNan(argY))\n";
2809 ss
<< " continue;\n";
2810 ss
<< " fSumX += argX;\n";
2811 ss
<< " fSumY += argY;\n";
2812 ss
<< " fCount += 1.0;\n";
2815 ss
<< " if (fCount < 3.0)\n";
2816 ss
<< " return DBL_MAX;\n";
2819 ss
<< " fMeanX = fSumX * pow(fCount,-1.0);\n";
2820 ss
<< " fMeanY = fSumY * pow(fCount,-1.0);\n";
2822 ss
<< " for (int i = ";
2823 if ((!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
2824 &&(!pDVR1
->IsStartFixed() && pDVR1
->IsEndFixed()))
2826 ss
<< "gid0; i < " << arrayLength
;
2827 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
2830 else if ((pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
2831 &&(pDVR1
->IsStartFixed() && !pDVR1
->IsEndFixed()))
2833 ss
<< "0; i < " << arrayLength
;
2834 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
2837 else if ((!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())&&
2838 (!pDVR1
->IsStartFixed() && !pDVR1
->IsEndFixed()))
2840 ss
<< "0; i + gid0 < " << arrayLength
;
2841 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
2846 ss
<< "0; i < " << arrayLength
<< "; i++)\n";
2851 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
2853 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
2854 ss
<< " if (isNan(argX)||isNan(argY))\n";
2855 ss
<< " continue;\n";
2856 ss
<< " fSumDeltaXDeltaY +=(argX-fMeanX)*(argY-fMeanY);\n";
2857 ss
<< " fSumSqrDeltaX += (argX-fMeanX)*(argX-fMeanX);\n";
2858 ss
<< " fSumSqrDeltaY += (argY-fMeanY)*(argY-fMeanY);\n";
2860 ss
<< " if(fSumSqrDeltaX == 0.0)\n";
2861 ss
<< " return DBL_MAX;\n";
2864 ss
<< " return sqrt((fSumSqrDeltaY - fSumDeltaXDeltaY * \n";
2865 ss
<< " fSumDeltaXDeltaY*pow(fSumSqrDeltaX,-1.0))\n";
2866 ss
<< " *pow(fCount - 2.0,-1.0));\n";
2873 ss
<< " return DBL_MAX;\n";
2877 void OpFisher::GenSlidingWindowFunction(
2878 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&
2881 ss
<< "\ndouble " << sSymName
;
2882 ss
<< "_"<< BinFuncName() <<"(";
2883 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2887 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2890 ss
<<" int gid0=get_global_id(0);\n";
2891 ss
<<" double arg0;\n";
2892 if(vSubArguments
.size() != 1)
2894 ss
<< " return DBL_MAX;\n";
2897 FormulaToken
*pCur
= vSubArguments
[0]->GetFormulaToken();
2899 if (pCur
->GetType() == formula::svDoubleVectorRef
)
2901 ss
<< " return DBL_MAX;\n";
2904 else if (pCur
->GetType() == formula::svSingleVectorRef
)
2906 const formula::SingleVectorRefToken
* pSVR
=
2907 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
2908 ss
<< " arg0 = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
2910 ss
<< " if(isNan(arg0)||(gid0>=";
2911 ss
<<pSVR
->GetArrayLength();
2915 else if (pCur
->GetType() == formula::svDouble
)
2917 ss
<< " arg0 = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
2919 ss
<< " if(isNan(arg0))\n";
2920 ss
<< " return DBL_MAX;\n";
2922 ss
<< " if (fabs(arg0) >= 1.0)\n";
2923 ss
<< " return DBL_MAX;\n";
2924 ss
<< " double tmp=0.5*log((1+arg0)*pow((1-arg0),-1));\n";
2925 ss
<< " return tmp;\n";
2929 void OpFisherInv::GenSlidingWindowFunction(
2930 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&vSubArguments
)
2932 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
2933 const formula::SingleVectorRefToken
*tmpCurDVR
= static_cast<const
2934 formula::SingleVectorRefToken
*>(tmpCur
);
2935 ss
<< "\ndouble " << sSymName
;
2936 ss
<< "_"<< BinFuncName() <<"(";
2937 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2941 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2944 ss
<<"int gid0=get_global_id(0);\n\t";
2945 ss
<< "double arg0 = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
2947 ss
<< "if(isNan(arg0)||(gid0>=";
2948 ss
<<tmpCurDVR
->GetArrayLength();
2950 ss
<<"arg0 = 0;\n\t";
2951 ss
<< "double tmp=tanh(arg0);\n\t";
2952 ss
<< "return tmp;\n";
2956 void OpGamma::GenSlidingWindowFunction(
2957 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&vSubArguments
)
2959 ss
<< "\ndouble " << sSymName
;
2960 ss
<< "_"<< BinFuncName() <<"(";
2961 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2965 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2968 ss
<<"int gid0=get_global_id(0);\n\t";
2969 ss
<< "double arg0 = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
2971 ss
<< "double tmp=tgamma(arg0);\n\t";
2972 ss
<< "return tmp;\n";
2976 void OpCorrel::GenSlidingWindowFunction(
2977 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&vSubArguments
)
2979 if( vSubArguments
.size() !=2 ||vSubArguments
[0]->GetFormulaToken()
2980 ->GetType() != formula::svDoubleVectorRef
||vSubArguments
[1]
2981 ->GetFormulaToken()->GetType() != formula::svDoubleVectorRef
)
2982 ///only support DoubleVector in OpCorrelfor GPU calculating.
2984 const formula::DoubleVectorRefToken
* pCurDVRX
=
2985 static_cast<const formula::DoubleVectorRefToken
*>(
2986 vSubArguments
[0]->GetFormulaToken());
2987 const formula::DoubleVectorRefToken
* pCurDVRY
=
2988 static_cast<const formula::DoubleVectorRefToken
*>(
2989 vSubArguments
[1]->GetFormulaToken());
2990 if( pCurDVRX
->GetRefRowSize() != pCurDVRY
->GetRefRowSize() )
2993 ss
<< "\ndouble " << sSymName
;
2994 ss
<< "_"<< BinFuncName() <<"(";
2995 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2999 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3002 ss
<< "double vSum = 0.0;\n\t";
3003 ss
<< "double vXSum = 0.0;\n\t";
3004 ss
<< "double vYSum = 0.0;\n\t";
3005 ss
<< "double vXMean = 0.0;\n\t";
3006 ss
<< "double vYMean = 0.0;\n\t";
3008 ss
<< "int gid0 = get_global_id(0);\n\t";
3009 ss
<< "double arg0 = 0.0;\n\t";
3010 ss
<< "double arg1 = 0.0;\n\t";
3011 ss
<< "int cnt = 0;\n\t";
3013 size_t nCurWindowSizeX
= pCurDVRY
->GetRefRowSize();
3015 ss
<< "for (int i = ";
3016 if (!pCurDVRX
->IsStartFixed() && pCurDVRX
->IsEndFixed()) {
3017 ss
<< "gid0; i < " << nCurWindowSizeX
<< "; i++) {\n\t\t";
3018 ss
<< "arg0 = " << vSubArguments
[0]
3019 ->GenSlidingWindowDeclRef(true) << ";\n\t\t";
3020 ss
<< "arg1 = " << vSubArguments
[1]
3021 ->GenSlidingWindowDeclRef(true) << ";\n\t\t";
3022 ss
<< "if(isNan(arg0) || isNan(arg1) || (i >= ";
3023 ss
<< pCurDVRX
->GetArrayLength() << ") || (i >=";
3024 ss
<< pCurDVRY
->GetArrayLength() << ")) {\n\t\t\t";
3025 ss
<< "arg0 = 0.0;\n\t\t\t";
3026 ss
<< "arg1 = 0.0;\n\t\t\t";
3027 ss
<< "--cnt;\n\t\t";
3029 ss
<< "++cnt;\n\t\t";
3030 ss
<< "vXSum += arg0;\n\t\t";
3031 ss
<< "vYSum += arg1;\n\t";
3033 } else if (pCurDVRX
->IsStartFixed() && !pCurDVRX
->IsEndFixed()) {
3034 ss
<< "0; i < gid0 + " << nCurWindowSizeX
<< "; i++) {\n\t\t";
3035 ss
<< "arg0 = " << vSubArguments
[0]
3036 ->GenSlidingWindowDeclRef(true) << ";\n\t\t";
3037 ss
<< "arg1 = " << vSubArguments
[1]
3038 ->GenSlidingWindowDeclRef(true) << ";\n\t\t";
3039 ss
<< "if(isNan(arg0) || isNan(arg1) || (i >= ";
3040 ss
<< pCurDVRX
->GetArrayLength() << ") || (i >=";
3041 ss
<< pCurDVRY
->GetArrayLength() << ")) {\n\t\t\t";
3042 ss
<< "arg0 = 0.0;\n\t\t\t";
3043 ss
<< "arg1 = 0.0;\n\t\t\t";
3044 ss
<< "--cnt;\n\t\t";
3046 ss
<< "++cnt;\n\t\t";
3047 ss
<< "vXSum += arg0;\n\t\t";
3048 ss
<< "vYSum += arg1;\n\t";
3051 else if (pCurDVRX
->IsStartFixed() && pCurDVRX
->IsEndFixed()) {
3052 ss
<< "0; i < " << nCurWindowSizeX
<< "; i++) {\n\t\t";
3053 ss
<< "arg0 = " << vSubArguments
[0]
3054 ->GenSlidingWindowDeclRef(true) << ";\n\t\t";
3055 ss
<< "arg1 = " << vSubArguments
[1]
3056 ->GenSlidingWindowDeclRef(true) << ";\n\t\t";
3057 ss
<< "if(isNan(arg0) || isNan(arg1) || (i >= ";
3058 ss
<< pCurDVRX
->GetArrayLength() << ") || (i >=";
3059 ss
<< pCurDVRY
->GetArrayLength() << ")) {\n\t\t\t";
3060 ss
<< "arg0 = 0.0;\n\t\t\t";
3061 ss
<< "arg1 = 0.0;\n\t\t\t";
3062 ss
<< "--cnt;\n\t\t";
3064 ss
<< "++cnt;\n\t\t";
3065 ss
<< "vXSum += arg0;\n\t\t";
3066 ss
<< "vYSum += arg1;\n\t";
3069 ss
<< "0; i < " << nCurWindowSizeX
<< "; i++) {\n\t\t";
3070 ss
<< "arg0 = " << vSubArguments
[0]
3071 ->GenSlidingWindowDeclRef(true) << ";\n\t\t";
3072 ss
<< "arg1 = " << vSubArguments
[1]
3073 ->GenSlidingWindowDeclRef(true) << ";\n\t\t";
3074 ss
<< "if(isNan(arg0) || isNan(arg1) || (i + gid0 >= ";
3075 ss
<< pCurDVRX
->GetArrayLength() << ") || (i + gid0 >=";
3076 ss
<< pCurDVRY
->GetArrayLength() << ")) {\n\t\t\t";
3077 ss
<< "arg0 = 0.0;\n\t\t\t";
3078 ss
<< "arg1 = 0.0;\n\t\t\t";
3079 ss
<< "--cnt;\n\t\t";
3081 ss
<< "++cnt;\n\t\t";
3082 ss
<< "vXSum += arg0;\n\t\t";
3083 ss
<< "vYSum += arg1;\n\t";
3087 ss
<< "if(cnt < 1) {\n\t\t";
3088 ss
<< "return DBL_MIN;\n\t";
3090 ss
<< "else {\n\t\t";
3091 ss
<< "vXMean = vXSum/cnt;\n\t\t";
3092 ss
<< "vYMean = vYSum/cnt;\n\t\t";
3093 ss
<< "vXSum = 0.0;\n\t\t";
3094 ss
<< "vYSum = 0.0;\n\t\t";
3096 ss
<< "for (int i = ";
3097 if (!pCurDVRX
->IsStartFixed() && pCurDVRX
->IsEndFixed()) {
3098 ss
<< "gid0; i < " << nCurWindowSizeX
<< "; i++) {\n\t\t\t";
3099 ss
<< "arg0 = " << vSubArguments
[0]
3100 ->GenSlidingWindowDeclRef(true) << ";\n\t\t\t";
3101 ss
<< "arg1 = " << vSubArguments
[1]
3102 ->GenSlidingWindowDeclRef(true) << ";\n\t\t\t";
3103 ss
<< "if(isNan(arg0) || isNan(arg1) || (i >= ";
3104 ss
<< pCurDVRX
->GetArrayLength() << ") || (i >=";
3105 ss
<< pCurDVRY
->GetArrayLength() << ")) {\n\t\t\t\t";
3106 ss
<< "arg0 = vXMean;\n\t\t\t\t";
3107 ss
<< "arg1 = vYMean;\n\t\t\t";
3109 ss
<< "vXSum += pow(arg0 - vXMean, 2);\n\t\t\t";
3110 ss
<< "vYSum += pow(arg1 - vYMean, 2);\n\t\t\t";
3111 ss
<< "vSum += (arg0 - vXMean)*(arg1 - vYMean);\n\t\t";
3113 } else if (pCurDVRX
->IsStartFixed() && !pCurDVRX
->IsEndFixed()) {
3114 ss
<< "0; i < gid0 + " << nCurWindowSizeX
<< "; i++) {\n\t\t\t";
3115 ss
<< "arg0 = " << vSubArguments
[0]
3116 ->GenSlidingWindowDeclRef(true) << ";\n\t\t\t";
3117 ss
<< "arg1 = " << vSubArguments
[1]
3118 ->GenSlidingWindowDeclRef(true) << ";\n\t\t\t";
3119 ss
<< "if(isNan(arg0) || isNan(arg1) || (i >= ";
3120 ss
<< pCurDVRX
->GetArrayLength() << ") || (i >=";
3121 ss
<< pCurDVRY
->GetArrayLength() << ")) {\n\t\t\t\t";
3122 ss
<< "arg0 = vXMean;\n\t\t\t\t";
3123 ss
<< "arg1 = vYMean;\n\t\t\t";
3125 ss
<< "vXSum += pow(arg0 - vXMean, 2);\n\t\t\t";
3126 ss
<< "vYSum += pow(arg1 - vYMean, 2);\n\t\t\t";
3127 ss
<< "vSum += (arg0 - vXMean)*(arg1 - vYMean);\n\t\t";
3129 } else if (pCurDVRX
->IsStartFixed() && pCurDVRX
->IsEndFixed()) {
3130 ss
<< "0; i < " << nCurWindowSizeX
<< "; i++) {\n\t\t\t";
3131 ss
<< "arg0 = " << vSubArguments
[0]
3132 ->GenSlidingWindowDeclRef(true) << ";\n\t\t\t";
3133 ss
<< "arg1 = " << vSubArguments
[1]
3134 ->GenSlidingWindowDeclRef(true) << ";\n\t\t\t";
3135 ss
<< "if(isNan(arg0) || isNan(arg1) || (i >= ";
3136 ss
<< pCurDVRX
->GetArrayLength() << ") || (i >=";
3137 ss
<< pCurDVRY
->GetArrayLength() << ")) {\n\t\t\t\t";
3138 ss
<< "arg0 = vXMean;\n\t\t\t\t";
3139 ss
<< "arg1 = vYMean;\n\t\t\t";
3141 ss
<< "vXSum += pow(arg0 - vXMean, 2);\n\t\t\t";
3142 ss
<< "vYSum += pow(arg1 - vYMean, 2);\n\t\t\t";
3143 ss
<< "vSum += (arg0 - vXMean)*(arg1 - vYMean);\n\t\t";
3146 ss
<< "0; i < " << nCurWindowSizeX
<< "; i++) {\n\t\t\t";
3147 ss
<< "arg0 = " << vSubArguments
[0]
3148 ->GenSlidingWindowDeclRef(true) << ";\n\t\t\t";
3149 ss
<< "arg1 = " << vSubArguments
[1]
3150 ->GenSlidingWindowDeclRef(true) << ";\n\t\t\t";
3151 ss
<< "if(isNan(arg0) || isNan(arg1) || (i + gid0 >= ";
3152 ss
<< pCurDVRX
->GetArrayLength() << ") || (i + gid0 >=";
3153 ss
<< pCurDVRY
->GetArrayLength() << ")) {\n\t\t\t\t";
3154 ss
<< "arg0 = vXMean;\n\t\t\t\t";
3155 ss
<< "arg1 = vYMean;\n\t\t\t";
3157 ss
<< "vXSum += ((arg0 - vXMean)*(arg0 - vXMean));\n\t\t\t";
3158 ss
<< "vYSum += ((arg1 - vYMean)*(arg1 - vYMean));\n\t\t\t";
3159 ss
<< "vSum += (arg0 - vXMean)*(arg1 - vYMean);\n\t\t";
3163 ss
<< "if(vXSum == 0.0 || vYSum == 0.0) {\n\t\t\t";
3164 ss
<< "return NAN;\n\t\t";
3166 ss
<< "else {\n\t\t\t";
3167 ss
<< "return vSum/pow(vXSum*vYSum, 0.5);\n\t\t";
3173 void OpNegbinomdist::GenSlidingWindowFunction(
3174 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&vSubArguments
)
3176 ss
<< "\ndouble " << sSymName
;
3177 ss
<< "_"<< BinFuncName() <<"(";
3178 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3182 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3186 ss
<< "double f,s,p,tmp0,tmp1,tmp2;\n";
3187 ss
<< " int gid0=get_global_id(0);\n";
3188 size_t i
= vSubArguments
.size();
3190 for (i
= 0; i
< vSubArguments
.size(); i
++)
3192 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
3194 if (pCur
->GetType() == formula::svSingleVectorRef
)
3196 const formula::SingleVectorRefToken
* pSVR
=
3197 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
3198 ss
<< "if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
3200 else if (pCur
->GetType() == formula::svDouble
)
3207 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
3209 ss
<< " if (isNan(";
3210 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
3212 ss
<< " tmp"<<i
<<"= 0;\n";
3214 ss
<< " tmp"<<i
<<"=\n";
3215 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
3220 ss
<< "tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
3224 ss
<< " p = tmp2;\n";
3225 ss
<< " s = tmp1;\n";
3226 ss
<< " f = tmp0;\n";
3227 ss
<< " double q = 1.0 - p;\n\t";
3228 ss
<< " double fFactor = pow(p,s);\n\t";
3229 ss
<< " for(int i=0; i<f; i++)\n\t";
3231 ss
<< " fFactor *= ((double)i+s)*pow(((double)i+1.0),-1.0)/pow(q,-1);\n";
3233 ss
<< " double temp=fFactor;\n\t";
3234 ss
<< " return temp;\n";
3238 void OpPearson::GenSlidingWindowFunction(
3239 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&vSubArguments
)
3241 if( vSubArguments
.size() !=2 ||vSubArguments
[0]->GetFormulaToken()
3242 ->GetType() != formula::svDoubleVectorRef
||vSubArguments
[1]
3243 ->GetFormulaToken()->GetType() != formula::svDoubleVectorRef
)
3244 ///only support DoubleVector in OpPearson for GPU calculating.
3246 const formula::DoubleVectorRefToken
* pDVR
=
3247 static_cast<const formula::DoubleVectorRefToken
*>(
3248 vSubArguments
[0]->GetFormulaToken());
3249 const formula::DoubleVectorRefToken
* pCurDVRY
=
3250 static_cast<const formula::DoubleVectorRefToken
*>(
3251 vSubArguments
[1]->GetFormulaToken());
3252 if( pDVR
->GetRefRowSize() != pCurDVRY
->GetRefRowSize() )
3255 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
3257 ss
<< "\ndouble " << sSymName
;
3258 ss
<< "_"<< BinFuncName() <<"(";
3259 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3263 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3267 ss
<< " int gid0=get_global_id(0);\n";
3268 ss
<< " double fCount = 0.0;\n";
3269 ss
<< " double fSumX = 0.0;\n";
3270 ss
<< " double fSumY = 0.0;\n";
3271 ss
<< " double fSumDeltaXDeltaY = 0.0;\n";
3272 ss
<< " double fInx;\n";
3273 ss
<< " double fIny;\n";
3274 ss
<< "for (int i = ";
3275 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) {
3276 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
3277 ss
<< " && i < " << nCurWindowSize
<< "; i++){\n";
3278 } else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) {
3279 ss
<< "0; i < " << pDVR
->GetArrayLength();
3280 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++){\n";
3281 } else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()){
3282 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
3283 ss
<< " && i < "<< nCurWindowSize
<< "; i++){\n";
3286 ss
<< "0; i < "<< nCurWindowSize
<< "; i++){\n";
3288 ss
<< " fInx = "<<vSubArguments
[0]->GenSlidingWindowDeclRef(true);
3290 ss
<< " fIny = "<<vSubArguments
[1]->GenSlidingWindowDeclRef(true);
3292 ss
<< " if(isNan(fInx)||isNan(fIny)){fInx=0.0;fIny=0.0;fCount = fCount-1;}\n";
3293 ss
<< " fSumX += fInx;\n";
3294 ss
<< " fSumY += fIny;\n";
3295 ss
<< " fCount = fCount + 1;\n";
3297 ss
<< " double fMeanX = fSumX / fCount;\n";
3298 ss
<< " double fMeanY = fSumY / fCount;\n";
3299 ss
<< " fSumX = 0.0;\n";
3300 ss
<< " fSumY = 0.0;\n";
3301 ss
<< "for (int i = ";
3302 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) {
3303 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
3304 ss
<< " && i < " << nCurWindowSize
<< "; i++){\n";
3305 } else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) {
3306 ss
<< "0; i < " << pDVR
->GetArrayLength();
3307 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++){\n";
3308 } else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()){
3309 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
3310 ss
<< " && i < "<< nCurWindowSize
<< "; i++){\n";
3313 ss
<< "0; i < "<< nCurWindowSize
<< "; i++){\n";
3315 ss
<< " fInx = "<<vSubArguments
[0]->GenSlidingWindowDeclRef(true);
3317 ss
<< " fIny = "<<vSubArguments
[1]->GenSlidingWindowDeclRef(true);
3319 ss
<< " if(isNan(fInx)||isNan(fIny)){fInx=0.0;fIny=0.0;}\n";
3320 ss
<< " fSumDeltaXDeltaY += (fInx - fMeanX) * (fIny - fMeanY);\n";
3321 ss
<< " fSumX += pow(fInx - fMeanX,2);\n";
3322 ss
<< " fSumY += pow(fIny - fMeanY,2);\n";
3324 ss
<< " double tmp = ( fSumDeltaXDeltaY / ";
3325 ss
<< "sqrt( fSumX * fSumY));\n\t";
3326 ss
<< " if (isnan(tmp))\n";
3327 ss
<< " return CreateDoubleError(errNoValue);\n";
3328 ss
<< " return tmp;\n";
3332 void OpGammaLn::GenSlidingWindowFunction(
3333 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&vSubArguments
)
3335 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
3336 const formula::SingleVectorRefToken
*tmpCurDVR
= static_cast<const
3337 formula::SingleVectorRefToken
*>(tmpCur
);
3338 ss
<< "\ndouble " << sSymName
;
3339 ss
<< "_"<< BinFuncName() <<"(";
3340 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3344 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3347 ss
<<"int gid0=get_global_id(0);\n\t";
3348 ss
<< "double arg0 = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
3350 ss
<< "if(isNan(arg0)||(gid0>=";
3351 ss
<<tmpCurDVR
->GetArrayLength();
3353 ss
<<"arg0 = 0;\n\t";
3354 ss
<< "double tmp=lgamma(arg0);\n\t";
3355 ss
<< "return tmp;\n";
3358 void OpGauss::BinInlineFun(std::set
<std::string
>& decls
,
3359 std::set
<std::string
>& funs
)
3361 decls
.insert(taylorDecl
);decls
.insert(phiDecl
);
3362 decls
.insert(gaussDecl
);
3363 funs
.insert(taylor
);funs
.insert(phi
);
3367 void OpGauss::GenSlidingWindowFunction(
3368 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&
3371 ss
<< "\ndouble " << sSymName
;
3372 ss
<< "_"<< BinFuncName() <<"(";
3373 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3377 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3380 ss
<<" int gid0=get_global_id(0);\n";
3381 ss
<<" double arg0;\n";
3382 if(vSubArguments
.size() != 1)
3384 ss
<< " return DBL_MAX;\n";
3387 FormulaToken
*pCur
= vSubArguments
[0]->GetFormulaToken();
3389 if (pCur
->GetType() == formula::svDoubleVectorRef
)
3391 ss
<< " return DBL_MAX;\n";
3394 else if (pCur
->GetType() == formula::svSingleVectorRef
)
3396 const formula::SingleVectorRefToken
* pSVR
=
3397 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
3398 ss
<< " arg0 = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
3400 ss
<< " if(isNan(arg0)||(gid0>=";
3401 ss
<<pSVR
->GetArrayLength();
3405 else if (pCur
->GetType() == formula::svDouble
)
3407 ss
<< " arg0 = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
3409 ss
<< " if(isNan(arg0))\n";
3410 ss
<< " return DBL_MAX;\n";
3412 ss
<< " double tmp=gauss(arg0);\n";
3413 ss
<< " return tmp;\n";
3417 void OpGeoMean::GenSlidingWindowFunction(
3418 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&vSubArguments
)
3420 ss
<< "__kernel void ";
3421 ss
<< "GeoMean_reduction( ";
3422 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3426 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3428 ss
<< ", __global double *result)\n";
3430 ss
<< " double tmp =0;\n";
3431 ss
<< " int count = 0;\n";
3433 GenTmpVariables(ss
,vSubArguments
);
3434 ss
<< " double current_sum = 0.0;\n";
3435 ss
<< " int windowSize;\n";
3436 ss
<< " int arrayLength;\n";
3437 ss
<< " int current_count = 0;\n";
3438 ss
<< " int writePos = get_group_id(1);\n";
3439 ss
<< " int lidx = get_local_id(0);\n";
3440 ss
<< " __local double shm_buf[256];\n";
3441 ss
<< " __local int count_buf[256];\n";
3442 ss
<< " int loop;\n";
3443 ss
<< " int offset;\n";
3444 ss
<< " barrier(CLK_LOCAL_MEM_FENCE);\n";
3446 for(unsigned i
=0;i
<vSubArguments
.size();i
++)
3448 assert(vSubArguments
[i
]->GetFormulaToken());
3450 if(vSubArguments
[i
]->GetFormulaToken()->GetType() ==
3451 formula::svDoubleVectorRef
)
3453 FormulaToken
*tmpCur
= vSubArguments
[i
]->GetFormulaToken();
3454 const formula::DoubleVectorRefToken
*pCurDVR
= static_cast<const
3455 formula::DoubleVectorRefToken
*>(tmpCur
);
3456 size_t nCurWindowSize
= pCurDVR
->GetArrayLength() <
3457 pCurDVR
->GetRefRowSize() ? pCurDVR
->GetArrayLength():
3458 pCurDVR
->GetRefRowSize() ;
3460 if (pCurDVR
->IsStartFixed() && pCurDVR
->IsEndFixed())
3461 ss
<< " offset = 0;\n";
3462 else if (!pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed())
3463 ss
<< " offset = get_group_id(1);\n";
3466 ss
<< " windowSize = ";
3467 ss
<< nCurWindowSize
;
3469 ss
<< " arrayLength = ";
3470 ss
<< pCurDVR
->GetArrayLength();
3472 ss
<< " loop = arrayLength/512 + 1;\n";
3473 ss
<< " for (int l=0; l<loop; l++){\n";
3474 ss
<< " tmp = 0.0;\n";
3475 ss
<< " count = 0;\n";
3476 ss
<< " int loopOffset = l*512;\n";
3477 ss
<< " int p1 = loopOffset + lidx + offset, p2 = p1 + 256;\n";
3478 ss
<< " if (p2 < min(offset + windowSize, arrayLength)) {\n";
3479 ss
<< " tmp0 = 0.0;\n";
3480 std::string p1
= "p1";
3481 std::string p2
= "p2";
3484 vSubArguments
[i
]->GenDeclRef(ss
);
3485 ss
<< "["<<p1
.c_str()<<"];\n";
3486 ss
<< " if(!isNan(tmp0))\n";
3488 ss
<< " tmp += log(tmp0);\n";
3489 ss
<< " count++;\n";
3493 vSubArguments
[i
]->GenDeclRef(ss
);
3494 ss
<< "["<<p2
.c_str()<<"];\n";
3495 ss
<< " if(!isNan(tmp0))\n";
3497 ss
<< " tmp += log(tmp0);\n";
3498 ss
<< " count++;\n";
3502 ss
<< " else if (p1 < min(arrayLength, offset + windowSize)) {\n";
3505 vSubArguments
[i
]->GenDeclRef(ss
);
3506 ss
<< "["<<p1
.c_str()<<"];\n";
3507 ss
<< " if(!isNan(tmp0))\n";
3509 ss
<< " tmp += log(tmp0);\n";
3510 ss
<< " count++;\n";
3514 ss
<< " shm_buf[lidx] = tmp;\n";
3515 ss
<< " count_buf[lidx] = count;\n";
3516 ss
<< " barrier(CLK_LOCAL_MEM_FENCE);\n";
3518 ss
<< " for (int i = 128; i >0; i/=2) {\n";
3519 ss
<< " if (lidx < i)\n";
3521 ss
<< " shm_buf[lidx] += shm_buf[lidx + i];\n";
3522 ss
<< " count_buf[lidx] += count_buf[lidx + i];\n";
3524 ss
<< " barrier(CLK_LOCAL_MEM_FENCE);\n";
3526 ss
<< " if (lidx == 0)\n";
3528 ss
<< " current_sum += shm_buf[0];\n";
3529 ss
<< " current_count += count_buf[0];\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 ss
<< " barrier(CLK_LOCAL_MEM_FENCE);\n";
3537 ss
<< " if (lidx == 0)\n";
3540 if(vSubArguments
[i
]->GetFormulaToken()->GetType() ==
3541 formula::svSingleVectorRef
)
3543 vSubArguments
[i
]->GenDeclRef(ss
);
3544 ss
<< "[writePos];\n";
3548 vSubArguments
[i
]->GenDeclRef(ss
);
3550 //ss <<"printf(\"\\n********************tmp0 is %f\",tmp0);\n";
3552 ss
<< " if(!isNan(tmp0))\n";
3554 ss
<< " current_sum += log(tmp0);\n";
3555 ss
<< " current_count++;\n";
3561 ss
<< " if (lidx == 0)\n";
3562 ss
<< " result[writePos] = exp(current_sum/current_count);\n";
3565 ss
<< "\ndouble " << sSymName
;
3566 ss
<< "_"<< BinFuncName() <<"(";
3567 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3571 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3574 ss
<<" int gid0=get_global_id(0);\n";
3575 ss
<< " double tmp =0;\n";
3577 vSubArguments
[0]->GenDeclRef(ss
);
3579 ss
<< " return tmp;\n";
3583 void OpHarMean::GenSlidingWindowFunction(
3584 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&
3588 ss
<< "\ndouble " << sSymName
;
3589 ss
<< "_"<< BinFuncName() <<"( ";
3590 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3594 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3598 ss
<< " int gid0 = get_global_id(0);\n";
3599 ss
<< " double nVal=0.0;\n";
3600 ss
<< " double tmp = 0;\n";
3601 ss
<< " int length;\n";
3602 ss
<< " int totallength=0;\n";
3603 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3605 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
3607 if (pCur
->GetType() == formula::svDoubleVectorRef
)
3609 const formula::DoubleVectorRefToken
* pDVR
=
3610 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
3611 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
3612 ss
<< " length="<<nCurWindowSize
;
3614 ss
<< " for (int i = ";
3615 ss
<< "0; i < "<< nCurWindowSize
<< "; i++)\n";
3617 ss
<< " double arg"<<i
<<" = ";
3618 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
3620 ss
<< " if(isNan(arg"<<i
<<")||((gid0+i)>=";
3621 ss
<< pDVR
->GetArrayLength();
3624 ss
<< " length--;\n";
3625 ss
<< " continue;\n";
3627 ss
<< " nVal += (1.0 *pow(";
3628 ss
<< " arg"<<i
<<",-1));\n";
3630 ss
<< " totallength +=length;\n";
3632 else if (pCur
->GetType() == formula::svSingleVectorRef
)
3635 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
3637 ss
<< " if(!isNan(tmp))\n";
3639 ss
<< " nVal += (1.0 * pow( tmp,-1));\n";
3640 ss
<< " totallength +=1;\n";
3643 else if (pCur
->GetType() == formula::svDouble
)
3646 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
3648 ss
<< " nVal += (1.0 *pow( tmp,-1));\n";
3649 ss
<< " totallength +=1;\n";
3653 ss
<< " return DBL_MIN;\n";
3656 ss
<< " tmp = totallength*pow(nVal,-1);\n";
3657 ss
<< " return tmp;\n";
3661 void OpConfidence::BinInlineFun(std::set
<std::string
>& decls
,
3662 std::set
<std::string
>& funs
)
3664 decls
.insert(gaussinvDecl
);
3665 funs
.insert(gaussinv
);
3668 void OpConfidence::GenSlidingWindowFunction(std::stringstream
& ss
,
3669 const std::string
&sSymName
, SubArguments
& vSubArguments
)
3671 ss
<< "\ndouble " << sSymName
;
3672 ss
<< "_"<< BinFuncName() <<"(";
3673 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3677 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3680 ss
<< " double tmp = " << GetBottom() <<";\n";
3681 ss
<< " int gid0 = get_global_id(0);\n";
3682 ss
<< " double alpha = " << GetBottom() <<";\n";
3683 ss
<< " double sigma = " << GetBottom() <<";\n";
3684 ss
<< " double size = " << GetBottom() <<";\n";
3685 ss
<< " double tmp0,tmp1,tmp2;\n";
3686 size_t i
= vSubArguments
.size();
3688 for (i
= 0; i
< vSubArguments
.size(); i
++)
3690 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
3692 if (pCur
->GetType() == formula::svSingleVectorRef
)
3694 const formula::SingleVectorRefToken
* pSVR
=
3695 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
3696 ss
<< "if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
3698 else if (pCur
->GetType() == formula::svDouble
)
3705 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
3707 ss
<< " if (isNan(";
3708 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
3710 ss
<< " tmp"<<i
<<"= 0;\n";
3712 ss
<< " tmp"<<i
<<"=\n";
3713 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
3718 ss
<< "tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
3722 ss
<< " alpha = tmp0;\n";
3723 ss
<< " sigma = tmp1;\n";
3724 ss
<< " size = tmp2;\n";
3725 ss
<< " double rn = floor(size);\n";
3726 ss
<< " if(sigma <= 0.0 || alpha <= 0.0 || alpha >= 1.0";
3727 ss
<< "|| rn < 1.0)\n";
3728 ss
<< " tmp = -DBL_MAX;\n";
3730 ss
<< " tmp = gaussinv(1.0 - alpha * pow(2.0,-1.0)) * sigma ";
3731 ss
<< "* pow(sqrt( rn ),-1);\n";
3732 ss
<< " return tmp;\n";
3736 void OpCritBinom::BinInlineFun(std::set
<std::string
>& decls
,
3737 std::set
<std::string
>& funs
)
3739 decls
.insert(MinDecl
);
3743 void OpCritBinom::GenSlidingWindowFunction(std::stringstream
& ss
,
3744 const std::string
&sSymName
, SubArguments
& vSubArguments
)
3746 ss
<< "\ndouble " << sSymName
;
3747 ss
<< "_"<< BinFuncName() <<"(";
3748 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3752 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3755 ss
<< " double tmp = " << GetBottom() <<";\n";
3756 ss
<< " int gid0 = get_global_id(0);\n";
3757 ss
<< " double n = " << GetBottom() <<";\n";
3758 ss
<< " double p = " << GetBottom() <<";\n";
3759 ss
<< " double alpha = " << GetBottom() <<";\n";
3760 ss
<< " double tmp0 = 0.0,tmp1 = 0.0,tmp2 = 0.0;\n";
3761 size_t i
= vSubArguments
.size();
3763 for (i
= 0; i
< vSubArguments
.size(); i
++)
3765 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
3767 if (pCur
->GetType() == formula::svSingleVectorRef
)
3769 const formula::SingleVectorRefToken
* pSVR
=
3770 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
3771 ss
<< "if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
3773 else if (pCur
->GetType() == formula::svDouble
)
3780 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
3782 ss
<< " if (isNan(";
3783 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
3785 ss
<< " tmp"<<i
<<"= 0;\n";
3787 ss
<< " tmp"<<i
<<"=\n";
3788 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
3793 ss
<< "tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
3797 ss
<< " n = tmp0;\n";
3798 ss
<< " p = tmp1;\n";
3799 ss
<< " alpha = tmp2;\n";
3800 ss
<< " double rn = floor(n);\n";
3801 ss
<< " if (rn < 0.0 || alpha <= 0.0 || alpha >= 1.0 || p < 0.0";
3802 ss
<< " || p > 1.0)\n";
3803 ss
<< " tmp = -DBL_MIN;\n";
3806 ss
<< " double rq = (0.5 - p) + 0.5;\n";
3807 ss
<< " double fFactor = pow(rq, rn);\n";
3808 ss
<< " if (fFactor <= Min)\n";
3810 ss
<< " fFactor = pow(p, rn);\n";
3811 ss
<< " if (fFactor <= Min)\n";
3812 ss
<< " tmp = -DBL_MAX;\n";
3815 ss
<< " double fSum = 1.0 - fFactor;\n";
3816 ss
<< " uint max =(uint)(rn), i;\n";
3817 ss
<< " for (i = 0; i < max && fSum >= alpha; i++)\n";
3819 ss
<< " fFactor *= (rn - i) * pow((double)(i + 1),-1.0) *";
3820 ss
<< " rq * pow(p, -1.0);\n";
3821 ss
<< " fSum -= fFactor;\n";
3823 ss
<< " tmp = (rn - i);\n";
3828 ss
<< " double fSum = fFactor;\n";
3829 ss
<< " uint max = (uint)(rn), i;\n";
3830 ss
<< " for (i = 0; i < max && fSum < alpha; i++)\n";
3832 ss
<< " fFactor *= (rn - i) * pow((double)(i + 1), -1.0) *";
3833 ss
<< " p * pow(rq, -1.0);\n";
3834 ss
<< " fSum += fFactor;\n";
3836 ss
<< " tmp = (i);\n";
3839 ss
<< " return tmp;\n";
3843 void OpRsq::GenSlidingWindowFunction(
3844 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&vSubArguments
)
3846 if( vSubArguments
.size() !=2 ||vSubArguments
[0]->GetFormulaToken()
3847 ->GetType() != formula::svDoubleVectorRef
||vSubArguments
[1]
3848 ->GetFormulaToken()->GetType() != formula::svDoubleVectorRef
)
3849 ///only support DoubleVector in OpRsq for GPU calculating.
3851 const formula::DoubleVectorRefToken
* pCurDVR1
=
3852 static_cast<const formula::DoubleVectorRefToken
*>(
3853 vSubArguments
[0]->GetFormulaToken());
3854 const formula::DoubleVectorRefToken
* pCurDVR2
=
3855 static_cast<const formula::DoubleVectorRefToken
*>(
3856 vSubArguments
[1]->GetFormulaToken());
3857 if( pCurDVR1
->GetRefRowSize() != pCurDVR2
->GetRefRowSize() )
3860 size_t nCurWindowSize
= pCurDVR1
->GetRefRowSize();
3862 ss
<< "\ndouble " << sSymName
;
3863 ss
<< "_"<< BinFuncName() <<"(";
3864 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3868 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3872 ss
<< " int gid0=get_global_id(0);\n";
3873 ss
<< " double fCount = 0.0;\n";
3874 ss
<< " double fSumX = 0.0;\n";
3875 ss
<< " double fSumY = 0.0;\n";
3876 ss
<< " double fSumDeltaXDeltaY = 0.0;\n";
3877 ss
<< " double fInx;\n";
3878 ss
<< " double fIny;\n";
3879 ss
<< " double tmp0,tmp1;\n";
3883 ss
<< " for(int i=0; i<"<<nCurWindowSize
<<"; i++)\n";
3886 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef(true);
3888 ss
<< " fInx = 0;\n";
3890 ss
<< " fInx = "<<vSubArguments
[0]->GenSlidingWindowDeclRef();
3893 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef(true);
3895 ss
<< " fIny = 0;\n";
3897 ss
<< " fIny = "<<vSubArguments
[1]->GenSlidingWindowDeclRef();
3899 ss
<< " fSumX += fInx;\n";
3900 ss
<< " fSumY += fIny;\n";
3901 ss
<< " fCount = fCount + 1;\n";
3903 ss
<< " double fMeanX = fSumX / fCount;\n";
3904 ss
<< " double fMeanY = fSumY / fCount;\n";
3905 ss
<< " fSumX = 0.0;\n";
3906 ss
<< " fSumY = 0.0;\n";
3907 ss
<< " for(int i=0; i<"<<nCurWindowSize
<<"; i++)\n";
3910 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef(true);
3912 ss
<< " fInx = 0;\n";
3914 ss
<< " fInx = "<<vSubArguments
[0]->GenSlidingWindowDeclRef();
3917 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
3919 ss
<< " fIny = 0;\n";
3921 ss
<< " fIny = "<<vSubArguments
[1]->GenSlidingWindowDeclRef();
3923 ss
<< " fSumDeltaXDeltaY += (fInx - fMeanX) * (fIny - fMeanY);\n";
3924 ss
<< " fSumX += pow(fInx - fMeanX,2);\n";
3925 ss
<< " fSumY += pow(fIny - fMeanY,2);\n";
3927 ss
<< " double tmp = pow( fSumDeltaXDeltaY,2) / (fSumX * fSumY);\n";
3928 ss
<< " return tmp ;\n";
3932 void OpChiInv::BinInlineFun(std::set
<std::string
>& decls
,
3933 std::set
<std::string
>& funs
)
3935 decls
.insert(fMachEpsDecl
);
3937 decls
.insert(fBigInvDecl
);
3939 decls
.insert(fHalfMachEpsDecl
);
3941 decls
.insert(lcl_IterateInverseChiInvDecl
);
3942 funs
.insert(lcl_IterateInverseChiInv
);
3943 decls
.insert(GetChiDistDecl
);
3944 funs
.insert(GetChiDist
);
3945 decls
.insert(lcl_HasChangeOfSignDecl
);
3946 funs
.insert(lcl_HasChangeOfSign
);
3947 decls
.insert(GetUpRegIGammaDecl
);
3948 funs
.insert(GetUpRegIGamma
);
3949 decls
.insert(GetGammaContFractionDecl
);
3950 funs
.insert(GetGammaContFraction
);
3951 decls
.insert(GetGammaSeriesDecl
);
3952 funs
.insert(GetGammaSeries
);
3954 void OpChiInv::GenSlidingWindowFunction(
3955 std::stringstream
&ss
,const std::string
&sSymName
,
3956 SubArguments
&vSubArguments
)
3958 ss
<< "\ndouble " << sSymName
;
3959 ss
<< "_"<< BinFuncName() <<"(";
3960 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3964 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3968 ss
<< " double tmp0,tmp1,tmp;\n";
3969 ss
<< " int gid0=get_global_id(0);\n";
3970 size_t i
= vSubArguments
.size();
3972 for (i
= 0; i
< vSubArguments
.size(); i
++)
3974 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
3976 if (pCur
->GetType() == formula::svDoubleVectorRef
)
3978 const formula::DoubleVectorRefToken
* pDVR
=
3979 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
3980 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
3981 ss
<< "for (int i = ";
3982 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) {
3983 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
3984 ss
<< " && i < " << nCurWindowSize
<< "; i++){\n";
3985 } else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) {
3986 ss
<< "0; i < " << pDVR
->GetArrayLength();
3987 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++){\n";
3988 } else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()){
3989 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
3990 ss
<< " && i < "<< nCurWindowSize
<< "; i++){\n";
3993 ss
<< "0; i < "<< nCurWindowSize
<< "; i++){\n";
3996 else if (pCur
->GetType() == formula::svSingleVectorRef
)
3998 const formula::SingleVectorRefToken
* pSVR
=
3999 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
4000 ss
<< "if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
4002 else if (pCur
->GetType() == formula::svDouble
)
4009 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
4012 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
4014 ss
<< " tmp"<<i
<<"= 0;\n";
4016 ss
<<"tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
4021 ss
<< "tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
4025 ss
<< " tmp1 = floor(tmp1);";
4026 ss
<< " if (tmp1 < 1.0 || tmp0 <= 0.0 || tmp0 > 1.0 )\n";
4028 ss
<< " return DBL_MIN;\n";
4030 ss
<< " bool bConvError;\n";
4031 ss
<< " double fVal = lcl_IterateInverseChiInv";
4032 ss
<< "(tmp0, tmp1, tmp1*0.5, tmp1, &bConvError);\n";
4033 ss
<< " if(bConvError)\n";
4034 ss
<< " return DBL_MIN;\n";
4035 ss
<< " return fVal;\n";
4038 void OpNormdist::GenSlidingWindowFunction(
4039 std::stringstream
&ss
, const std::string
&sSymName
,
4040 SubArguments
&vSubArguments
)
4042 ss
<< "\ndouble " << sSymName
;
4043 ss
<< "_"<< BinFuncName() <<"(";
4044 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4048 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4052 ss
<< " double x,mue,sigma,c;\n";
4053 ss
<< " int gid0=get_global_id(0);\n";
4054 ss
<< " double tmp0,tmp1,tmp2,tmp3;\n";
4055 size_t i
= vSubArguments
.size();
4057 for (i
= 0; i
< vSubArguments
.size(); i
++)
4059 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
4061 if (pCur
->GetType() == formula::svSingleVectorRef
)
4063 const formula::SingleVectorRefToken
* pSVR
=
4064 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
4065 ss
<< "if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
4067 else if (pCur
->GetType() == formula::svDouble
)
4071 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
4073 ss
<< " if (isNan(";
4074 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
4076 ss
<< " tmp"<<i
<<"= 0;\n";
4078 ss
<< " tmp"<<i
<<"=\n";
4079 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
4084 ss
<< "tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
4088 ss
<< "x = tmp0;\n";
4089 ss
<< "mue = tmp1;\n";
4090 ss
<< "sigma = tmp2;\n";
4091 ss
<< "c = tmp3;\n";
4092 ss
<< "double mid,tmp;\n";
4093 ss
<< "mid = (x - mue)/sigma;\n";
4095 ss
<< " tmp = 0.5 *erfc(-mid * 0.7071067811865475);\n";
4097 ss
<<" tmp=(0.39894228040143268*exp(-pow(mid,2)/2.0))/sigma;\n";
4098 ss
<< "return tmp;\n";
4101 void OpNormsdist::BinInlineFun(std::set
<std::string
>& decls
,
4102 std::set
<std::string
>& funs
)
4104 decls
.insert(lcl_Erfc0600Decl
);
4105 funs
.insert(lcl_Erfc0600
);
4106 decls
.insert(lcl_Erfc2654Decl
);
4107 funs
.insert(lcl_Erfc2654
);
4108 decls
.insert(lcl_Erf0065Decl
);
4109 funs
.insert(lcl_Erf0065
);
4110 decls
.insert(rtl_math_erf_rdDecl
);
4111 funs
.insert(rtl_math_erf_rd
);
4112 decls
.insert(rtl_math_erfc_rdDecl
);
4113 funs
.insert(rtl_math_erfc_rd
);
4116 void OpNormsdist::GenSlidingWindowFunction(
4117 std::stringstream
&ss
,const std::string
&sSymName
,
4118 SubArguments
&vSubArguments
)
4120 ss
<< "\ndouble " << sSymName
;
4121 ss
<< "_"<< BinFuncName() <<"(";
4122 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4126 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4130 ss
<< " double x = 0,tmp0 = 0;\n";
4131 ss
<< " int gid0=get_global_id(0);\n";
4132 size_t i
= vSubArguments
.size();
4134 for (i
= 0; i
< vSubArguments
.size(); i
++)
4136 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
4138 if (pCur
->GetType() == formula::svSingleVectorRef
)
4140 const formula::SingleVectorRefToken
* pSVR
=
4141 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
4142 ss
<< "if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
4144 else if (pCur
->GetType() == formula::svDouble
)
4151 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
4153 ss
<< " if (isNan(";
4154 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
4156 ss
<< " tmp"<<i
<<"= 0;\n";
4158 ss
<< " tmp"<<i
<<"=\n";
4159 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
4164 ss
<< "tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
4168 ss
<< " x = tmp0;\n";
4169 ss
<< " double tmp = 0.5 * rtl_math_erfc_rd((-1)*x * 0.7071067811865475);\n";
4170 ss
<< " return tmp;\n";
4174 void OpPermut::GenSlidingWindowFunction(
4175 std::stringstream
&ss
,const std::string
&sSymName
,
4176 SubArguments
&vSubArguments
)
4178 ss
<< "\ndouble " << sSymName
;
4179 ss
<< "_"<< BinFuncName() <<"(";
4180 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4184 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4187 ss
<<" int gid0=get_global_id(0);\n";
4188 ss
<<" double inA;\n";
4189 ss
<<" double inB;\n";
4190 ss
<<" double tmp0,tmp1;\n";
4191 ss
<<" double tmp = 1 ;\n";
4192 size_t i
= vSubArguments
.size();
4194 for (i
= 0; i
< vSubArguments
.size(); i
++)
4196 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
4198 if (pCur
->GetType() == formula::svSingleVectorRef
)
4200 const formula::SingleVectorRefToken
* pSVR
=
4201 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
4202 ss
<< "if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
4205 else if (pCur
->GetType() == formula::svDouble
)
4212 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
4214 ss
<< " if (isNan(";
4215 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
4217 ss
<< " tmp"<<i
<<"= 0;\n";
4219 ss
<< " tmp"<<i
<<"=\n";
4220 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
4225 ss
<< "tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
4229 ss
<< " inA = tmp0;\n";
4230 ss
<< " inB = tmp1;\n";
4231 ss
<< " for( int i =0; i<inB; i++)\n";
4233 ss
<< " tmp *= inA ;\n";
4234 ss
<< " inA = inA - 1.0;\n";
4236 ss
<< " return tmp;\n";
4239 void OpPermutationA::GenSlidingWindowFunction(
4240 std::stringstream
&ss
,const std::string
&sSymName
,
4241 SubArguments
&vSubArguments
)
4243 ss
<< "\ndouble " << sSymName
;
4244 ss
<< "_"<< BinFuncName() <<"(";
4245 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4249 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4252 ss
<<" int gid0=get_global_id(0);\n";
4253 ss
<<" double inA;\n";
4254 ss
<<" double inB;\n";
4255 ss
<<" double tmp = 1.0;\n";
4256 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
4257 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
4258 formula::SingleVectorRefToken
*>(tmpCur0
);
4259 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
4260 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
4261 formula::SingleVectorRefToken
*>(tmpCur1
);
4262 ss
<< "int buffer_fIna_len = ";
4263 ss
<< tmpCurDVR0
->GetArrayLength();
4265 ss
<< " int buffer_fInb_len = ";
4266 ss
<< tmpCurDVR1
->GetArrayLength();
4268 ss
<< " if((gid0)>=buffer_fIna_len || isNan(";
4269 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
4271 ss
<< " inA = 0;\nelse \n";
4272 ss
<< " inA = "<<vSubArguments
[0]->GenSlidingWindowDeclRef();
4274 ss
<< "if((gid0)>=buffer_fInb_len || isNan(";
4275 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
4277 ss
<< "inB = 0;\nelse \n";
4278 ss
<< " inB = "<<vSubArguments
[1]->GenSlidingWindowDeclRef();
4280 ss
<< " for(int i=0; i<inB; i++)\n";
4282 ss
<< " tmp *= inA;\n";
4284 ss
<< " return tmp;\n";
4288 void OpPhi::GenSlidingWindowFunction(
4289 std::stringstream
&ss
,const std::string
&sSymName
,
4290 SubArguments
&vSubArguments
)
4292 ss
<< "\ndouble " << sSymName
;
4293 ss
<< "_"<< BinFuncName() <<"(";
4294 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4298 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4302 ss
<< " double x,tmp0;\n";
4303 ss
<< " int gid0=get_global_id(0);\n";
4304 size_t i
= vSubArguments
.size();
4306 for (i
= 0; i
< vSubArguments
.size(); i
++)
4308 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
4310 if (pCur
->GetType() == formula::svSingleVectorRef
)
4312 const formula::SingleVectorRefToken
* pSVR
=
4313 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
4314 ss
<< "if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
4316 else if (pCur
->GetType() == formula::svDouble
)
4323 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
4325 ss
<< " if (isNan(";
4326 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
4328 ss
<< " tmp"<<i
<<"= 0;\n";
4330 ss
<< " tmp"<<i
<<"=\n";
4331 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
4336 ss
<< "tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
4340 ss
<< " x = tmp0;\n";
4341 ss
<< " double tmp = 0.39894228040143268 * exp((-1)*pow(x,2) / 2.0);\n";
4342 ss
<< " return tmp;\n";
4346 void OpNorminv::GenSlidingWindowFunction(
4347 std::stringstream
&ss
,const std::string
&sSymName
,
4348 SubArguments
&vSubArguments
)
4350 ss
<< "\ndouble " << sSymName
;
4351 ss
<< "_"<< BinFuncName() <<"(";
4352 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4356 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4360 ss
<<" double q,t,z;\n";
4361 ss
<<" double x,mue,sigma;\n";
4362 ss
<<" double tmp0,tmp1,tmp2;\n";
4363 ss
<<" int gid0=get_global_id(0);\n";
4364 size_t i
= vSubArguments
.size();
4366 for (i
= 0; i
< vSubArguments
.size(); i
++)
4368 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
4370 if (pCur
->GetType() == formula::svSingleVectorRef
)
4372 const formula::SingleVectorRefToken
* pSVR
=
4373 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
4374 ss
<< "if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
4376 else if (pCur
->GetType() == formula::svDouble
)
4383 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
4385 ss
<< " if (isNan(";
4386 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
4388 ss
<< " tmp"<<i
<<"= 0;\n";
4390 ss
<< " tmp"<<i
<<"=\n";
4391 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
4396 ss
<< "tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
4400 ss
<<" x = tmp0;\n";
4401 ss
<<" mue = tmp1;\n";
4402 ss
<<" sigma = tmp2;\n";
4403 ss
<<" q = x -0.5;\n";
4404 ss
<<" if(fabs(q)<=.425)\n";
4406 ss
<<" t=0.180625-pow(q,2);\n";
4416 "t*2509.0809287301226727";
4417 ss
<<"+33430.575583588128105\n"
4419 "*t+67265.770927008700853\n"
4421 "*t+45921.953931549871457\n"
4423 "*t+13731.693765509461125\n"
4425 "*t+1971.5909503065514427\n"
4427 "*t+133.14166789178437745\n"
4429 "*t+3.387132872796366608\n"
4439 "t*5226.495278852854561";
4440 ss
<<"+28729.085735721942674\n"
4442 "*t+39307.89580009271061\n"
4444 "*t+21213.794301586595867\n"
4446 "*t+5394.1960214247511077\n"
4448 "*t+687.1870074920579083\n"
4450 "*t+42.313330701600911252\n"
4454 ss
<<"}\nelse\n{\n";
4455 ss
<<" if(q>0)\nt=1-x;\n";
4456 ss
<<"else\nt=x;\n";
4457 ss
<<"t=sqrt(-log(t));\n";
4458 ss
<<"if(t<=5.0)\n{\n";
4468 "t*7.7454501427834140764e-4";
4469 ss
<<"+0.0227238449892691845833\n"
4471 "*t+0.24178072517745061177\n"
4473 "*t+1.27045825245236838258\n"
4475 "*t+3.64784832476320460504\n"
4477 "*t+5.7694972214606914055\n"
4479 "*t+4.6303378461565452959\n"
4481 "*t+1.42343711074968357734\n"
4491 "t*1.05075007164441684324e-9";
4492 ss
<<"+5.475938084995344946e-4\n"
4494 "*t+0.0151986665636164571966\n"
4496 "*t+0.14810397642748007459\n"
4498 "*t+0.68976733498510000455\n"
4500 "*t+1.6763848301838038494\n"
4502 "*t+2.05319162663775882187\n"
4516 "t*2.01033439929228813265e-7";
4517 ss
<<"+2.71155556874348757815e-5\n"
4519 "*t+0.0012426609473880784386\n"
4521 "*t+0.026532189526576123093\n"
4523 "*t+0.29656057182850489123\n"
4525 "*t+1.7848265399172913358\n"
4527 "*t+5.4637849111641143699\n"
4529 "*t+6.6579046435011037772\n"
4539 "t*2.04426310338993978564e-15"
4540 "+1.4215117583164458887e-7\n"
4542 "*t+1.8463183175100546818e-5\n"
4544 "*t+7.868691311456132591e-4\n"
4546 "*t+0.0148753612908506148525\n"
4548 "*t+0.13692988092273580531\n"
4550 "*t+0.59983220655588793769\n"
4555 ss
<< "z = q < 0.0 ? (-1)*z : z;\n";
4557 ss
<<"double tmp = z*sigma + mue;\n";
4558 ss
<<"return tmp;\n";
4561 void OpNormsinv:: GenSlidingWindowFunction
4562 (std::stringstream
&ss
,const std::string
&sSymName
,
4563 SubArguments
&vSubArguments
)
4565 ss
<< "\ndouble " << sSymName
;
4566 ss
<< "_"<< BinFuncName() <<"(";
4567 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4571 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4575 ss
<< " double q,t,z,x,tmp0;\n";
4576 ss
<< " int gid0=get_global_id(0);\n";
4577 size_t i
= vSubArguments
.size();
4579 for (i
= 0; i
< vSubArguments
.size(); i
++)
4581 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
4583 if (pCur
->GetType() == formula::svSingleVectorRef
)
4585 const formula::SingleVectorRefToken
* pSVR
=
4586 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
4587 ss
<< "if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
4589 else if (pCur
->GetType() == formula::svDouble
)
4596 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
4598 ss
<< " if (isNan(";
4599 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
4601 ss
<< " tmp"<<i
<<"= 0;\n";
4603 ss
<< " tmp"<<i
<<"=\n";
4604 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
4609 ss
<< "tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
4613 ss
<<" x = tmp0;\n";
4614 ss
<<" q = x -0.5;\n";
4615 ss
<<" if(fabs(q)<=.425)\n";
4617 ss
<<" t=0.180625-pow(q,2);\n";
4627 "t*2509.0809287301226727";
4628 ss
<<"+33430.575583588128105\n"
4630 "*t+67265.770927008700853\n"
4632 "*t+45921.953931549871457\n"
4634 "*t+13731.693765509461125\n"
4636 "*t+1971.5909503065514427\n"
4638 "*t+133.14166789178437745\n"
4640 "*t+3.387132872796366608\n"
4650 "t*5226.495278852854561";
4651 ss
<<"+28729.085735721942674\n"
4653 "*t+39307.89580009271061\n"
4655 "*t+21213.794301586595867\n"
4657 "*t+5394.1960214247511077\n"
4659 "*t+687.1870074920579083\n"
4661 "*t+42.313330701600911252\n"
4665 ss
<<"}\nelse\n{\n";
4666 ss
<<" if(q>0)\nt=1-x;\n";
4667 ss
<<"else\nt=x;\n";
4668 ss
<<"t=sqrt(-log(t));\n";
4669 ss
<<"if(t<=5.0)\n{\n";
4679 "t*7.7454501427834140764e-4";
4680 ss
<<"+0.0227238449892691845833\n"
4682 "*t+0.24178072517745061177\n"
4684 "*t+1.27045825245236838258\n"
4686 "*t+3.64784832476320460504\n"
4688 "*t+5.7694972214606914055\n"
4690 "*t+4.6303378461565452959\n"
4692 "*t+1.42343711074968357734\n"
4702 "t*1.05075007164441684324e-9";
4703 ss
<<"+5.475938084995344946e-4\n"
4705 "*t+0.0151986665636164571966\n"
4707 "*t+0.14810397642748007459\n"
4709 "*t+0.68976733498510000455\n"
4711 "*t+1.6763848301838038494\n"
4713 "*t+2.05319162663775882187\n"
4727 "t*2.01033439929228813265e-7";
4728 ss
<<"+2.71155556874348757815e-5\n"
4730 "*t+0.0012426609473880784386\n"
4732 "*t+0.026532189526576123093\n"
4734 "*t+0.29656057182850489123\n"
4736 "*t+1.7848265399172913358\n"
4738 "*t+5.4637849111641143699\n"
4740 "*t+6.6579046435011037772\n"
4750 "t*2.04426310338993978564e-15"
4751 "+1.4215117583164458887e-7\n"
4753 "*t+1.8463183175100546818e-5\n"
4755 "*t+7.868691311456132591e-4\n"
4757 "*t+0.0148753612908506148525\n"
4759 "*t+0.13692988092273580531\n"
4761 "*t+0.59983220655588793769\n"
4766 ss
<< "z = q < 0.0 ? (-1)*z : z;\n";
4768 ss
<<"if (isnan(z))\n";
4769 ss
<<" return CreateDoubleError(errNoValue);\n";
4773 void OpMedian::GenSlidingWindowFunction(
4774 std::stringstream
&ss
, const std::string
&sSymName
,
4775 SubArguments
&vSubArguments
)
4777 ss
<< "\ndouble " << sSymName
;
4778 ss
<< "_"<< BinFuncName() <<"(";
4779 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4783 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4786 ss
<< " int gid0 = get_global_id(0);\n";
4787 ss
<< " double tmp = 0;\n";
4789 ss
<< " unsigned int startFlag = 0;\n";
4790 ss
<< " unsigned int endFlag = 0;\n";
4791 ss
<< " double dataIna;\n";
4792 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4794 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
4796 if (const formula::DoubleVectorRefToken
* pCurDVR
=
4797 dynamic_cast<const formula::DoubleVectorRefToken
*>(pCur
))
4799 size_t nCurWindowSize
= pCurDVR
->GetRefRowSize();
4800 ss
<< "startFlag = ";
4801 if (!pCurDVR
->IsStartFixed() && pCurDVR
->IsEndFixed())
4803 ss
<< "gid0; endFlag = "<< nCurWindowSize
<<"-gid0;\n";
4805 ss
<< "gid0; endFlag = gid0+"<< nCurWindowSize
<<";\n";
4809 ss
<<"startFlag=gid0;endFlag=gid0;\n";
4812 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
4813 const formula::DoubleVectorRefToken
*tmpCurDVR0
= static_cast<const
4814 formula::DoubleVectorRefToken
*>(tmpCur0
);
4815 ss
<< "int buffer_fIna_len = ";
4816 ss
<< tmpCurDVR0
->GetArrayLength();
4818 ss
<<"if((i+gid0)>=buffer_fIna_len || isNan(";
4819 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
4821 ss
<<" dataIna = 0;\n";
4822 ss
<< " int nSize =endFlag- startFlag ;\n";
4823 ss
<< " if (nSize & 1)\n";
4825 ss
<< " tmp = "<<vSubArguments
[0]->GetName();
4826 ss
<< " [startFlag+nSize/2];\n";
4830 ss
<< " tmp =("<<vSubArguments
[0]->GetName();
4831 ss
<< " [startFlag+nSize/2]+";
4832 ss
<< vSubArguments
[0]->GetName();
4833 ss
<< " [startFlag+nSize/2-1])/2;\n";
4835 ss
<<" return tmp;\n";
4838 void OpKurt:: GenSlidingWindowFunction(std::stringstream
&ss
,
4839 const std::string
&sSymName
, SubArguments
&vSubArguments
)
4841 ss
<< "\ndouble " << sSymName
;
4842 ss
<< "_"<< BinFuncName() <<"( ";
4843 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4847 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
4851 ss
<< " int gid0 = get_global_id(0);\n";
4852 ss
<< " double fSum = 0.0;\n";
4853 ss
<< " double vSum = 0.0;\n";
4854 ss
<< " double length;\n";
4855 ss
<< " double totallength=0;\n";
4856 ss
<< " double tmp = 0;\n";
4857 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4859 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
4861 if (pCur
->GetType() == formula::svDoubleVectorRef
)
4863 const formula::DoubleVectorRefToken
* pDVR
=
4864 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
4865 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
4866 ss
<< " length="<<nCurWindowSize
;
4868 ss
<< " for (int i = ";
4869 ss
<< "0; i < "<< nCurWindowSize
<< "; i++)\n";
4871 ss
<< " double arg"<<i
<<" = ";
4872 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef(true);
4874 ss
<< " if(isNan(arg"<<i
<<")||((gid0+i)>=";
4875 ss
<< pDVR
->GetArrayLength();
4878 ss
<< " length-=1.0;\n";
4879 ss
<< " continue;\n";
4881 ss
<< " fSum += arg"<<i
<<";\n";
4883 ss
<< " totallength +=length;\n";
4885 else if (pCur
->GetType() == formula::svSingleVectorRef
)
4888 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
4890 ss
<< " if(!isNan(tmp))\n";
4892 ss
<< " fSum += tmp;\n";
4893 ss
<< " totallength +=1;\n";
4896 else if (pCur
->GetType() == formula::svDouble
)
4899 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
4901 ss
<< " fSum += tmp;\n";
4902 ss
<< " totallength +=1;\n";
4906 ss
<< " return DBL_MIN;\n";
4909 ss
<< " double fMean = fSum * pow(totallength,-1);\n";
4910 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4912 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
4914 if (pCur
->GetType() == formula::svDoubleVectorRef
)
4916 const formula::DoubleVectorRefToken
* pDVR
=
4917 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
4918 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
4919 ss
<< " for (int i = ";
4920 ss
<< "0; i < "<< nCurWindowSize
<< "; i++)\n";
4922 ss
<< " double arg"<<i
<<" = ";
4923 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef(true);
4925 ss
<< " if(isNan(arg"<<i
<<")||((gid0+i)>=";
4926 ss
<< pDVR
->GetArrayLength();
4929 ss
<< " continue;\n";
4931 ss
<< " vSum += (arg"<<i
<<"-fMean)*(arg"<<i
<<"-fMean);\n";
4934 else if (pCur
->GetType() == formula::svSingleVectorRef
)
4937 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
4939 ss
<< " if(!isNan(tmp))\n";
4941 ss
<< " vSum += (tmp-fMean)*(tmp-fMean);\n";
4944 else if (pCur
->GetType() == formula::svDouble
)
4947 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
4949 ss
<< " vSum += (tmp-fMean)*(tmp-fMean);\n";
4952 ss
<< " double fStdDev = sqrt(vSum / (totallength - 1.0));\n";
4953 ss
<< " double dx = 0.0;\n";
4954 ss
<< " double xpower4 = 0.0;\n";
4955 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
4957 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
4959 if (pCur
->GetType() == formula::svDoubleVectorRef
)
4961 const formula::DoubleVectorRefToken
* pDVR
=
4962 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
4963 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
4964 ss
<< " for (int i = ";
4965 ss
<< "0; i < "<< nCurWindowSize
<< "; i++)\n";
4967 ss
<< " double arg"<<i
<<" = ";
4968 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef(true);
4970 ss
<< " if(isNan(arg"<<i
<<")||((gid0+i)>=";
4971 ss
<< pDVR
->GetArrayLength();
4974 ss
<< " continue;\n";
4976 ss
<< " dx = (arg"<<i
<<" -fMean) / fStdDev;\n";
4977 ss
<< " xpower4 = xpower4 + (dx * dx * dx * dx);\n";
4980 else if (pCur
->GetType() == formula::svSingleVectorRef
)
4983 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
4985 ss
<< " if(!isNan(tmp))\n";
4987 ss
<< " dx = (tmp -fMean) / fStdDev;\n";
4988 ss
<< " xpower4 = xpower4 + (dx * dx * dx * dx);\n";
4991 else if (pCur
->GetType() == formula::svDouble
)
4994 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
4996 ss
<< " dx = (tmp -fMean) / fStdDev;\n";
4997 ss
<< " xpower4 = xpower4 + (dx * dx * dx * dx);\n";
5000 ss
<< " double k_d = (totallength - 2.0) * (totallength - 3.0);\n";
5001 ss
<< " double k_l = totallength * (totallength + 1.0) /";
5002 ss
<< "((totallength - 1.0) * k_d);\n";
5003 ss
<< " double k_t = 3.0 * (totallength - 1.0) * ";
5004 ss
<< "(totallength - 1.0) / k_d;\n";
5005 ss
<< " tmp = xpower4 * k_l - k_t;\n";
5006 ss
<< " return tmp;\n";
5010 void OpIntercept::GenSlidingWindowFunction(std::stringstream
&ss
,
5011 const std::string
&sSymName
, SubArguments
&vSubArguments
)
5013 ss
<< "\ndouble " << sSymName
;
5014 ss
<< "_" << BinFuncName() << "(";
5015 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
5019 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
5022 ss
<< " int gid0 = get_global_id(0);\n";
5023 ss
<< " double fSumX = 0.0;\n";
5024 ss
<< " double fSumY = 0.0;\n";
5025 ss
<< " double fMeanX = 0.0;\n";
5026 ss
<< " double fMeanY = 0.0;\n";
5027 ss
<< " double fSumDeltaXDeltaY = 0.0;\n";
5028 ss
<< " double fSumSqrDeltaX = 0.0;\n";
5029 ss
<< " double fCount = 0.0;\n";
5030 ss
<< " double argX = 0.0;\n";
5031 ss
<< " double argY = 0.0;\n";
5032 if(vSubArguments
.size() != 2)
5034 ss
<< " return NAN;\n";
5038 FormulaToken
*pCur
= vSubArguments
[1]->GetFormulaToken();
5039 FormulaToken
*pCur1
= vSubArguments
[0]->GetFormulaToken();
5042 if (pCur
->GetType() == formula::svDoubleVectorRef
&&
5043 pCur1
->GetType() == formula::svDoubleVectorRef
)
5045 const formula::DoubleVectorRefToken
* pDVR
=
5046 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
5047 const formula::DoubleVectorRefToken
* pDVR1
=
5048 static_cast<const formula::DoubleVectorRefToken
*>(pCur1
);
5050 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
5051 size_t nCurWindowSize1
= pDVR1
->GetRefRowSize();
5052 size_t arrayLength
= pDVR
->GetArrayLength()<
5053 pDVR1
->GetArrayLength() ? pDVR
->GetArrayLength():
5054 pDVR1
->GetArrayLength();
5055 if(nCurWindowSize
!= nCurWindowSize1
)
5057 ss
<< " return NAN;\n";
5061 ss
<< " for (int i = ";
5062 if ((!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
5063 &&(!pDVR1
->IsStartFixed() && pDVR1
->IsEndFixed()))
5065 ss
<< "gid0; i < " << arrayLength
;
5066 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
5069 else if ((pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
5070 &&(pDVR1
->IsStartFixed() && !pDVR1
->IsEndFixed()))
5072 ss
<< "0; i < " << arrayLength
;
5073 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
5076 else if ((!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
5077 &&(!pDVR1
->IsStartFixed() && !pDVR1
->IsEndFixed()))
5079 ss
<< "0; i + gid0 < " << arrayLength
;
5080 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
5083 else if ((pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
5084 &&(pDVR1
->IsStartFixed() && pDVR1
->IsEndFixed()))
5086 ss
<< "0; i < " << arrayLength
<< "; i++)\n";
5091 ss
<< "0; i < " << nCurWindowSize
<< "; i++)\n";
5095 ss
<< " return NAN;\n";
5101 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
5103 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
5104 ss
<< " if (isNan(argX) || isNan(argY))\n";
5105 ss
<< " continue;\n";
5106 ss
<< " fSumX += argX;\n";
5107 ss
<< " fSumY += argY;\n";
5108 ss
<< " fCount += 1.0;\n";
5111 ss
<< " if (fCount < 1.0)\n";
5112 ss
<< " return NAN;\n";
5115 ss
<< " fMeanX = fSumX * pow(fCount,-1.0);\n";
5116 ss
<< " fMeanY = fSumY * pow(fCount,-1.0);\n";
5118 ss
<< " for (int i = ";
5119 if ((!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
5120 &&(!pDVR1
->IsStartFixed() && pDVR1
->IsEndFixed()))
5122 ss
<< "gid0; i < " << arrayLength
;
5123 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
5126 else if ((pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
5127 &&(pDVR1
->IsStartFixed() && !pDVR1
->IsEndFixed()))
5129 ss
<< "0; i < " << arrayLength
;
5130 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
5133 else if ((!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
5134 &&(!pDVR1
->IsStartFixed() && !pDVR1
->IsEndFixed()))
5136 ss
<< "0; i + gid0 < " << arrayLength
;
5137 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
5142 ss
<< "0; i < " << arrayLength
<< "; i++)\n";
5147 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
5149 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
5150 ss
<< " if (isNan(argX) || isNan(argY))\n";
5151 ss
<< " continue;\n";
5152 ss
<< " fSumDeltaXDeltaY += (argX-fMeanX)*(argY-fMeanY);\n";
5153 ss
<< " fSumSqrDeltaX += (argX-fMeanX) * (argX-fMeanX);\n";
5155 ss
<< " if(fSumSqrDeltaX == 0.0)\n";
5156 ss
<< " return NAN;\n";
5159 ss
<< " return fMeanY -";
5160 ss
<< " (fSumDeltaXDeltaY*pow(fSumSqrDeltaX,-1.0))*fMeanX;\n";
5167 ss
<< " return NAN;\n";
5171 void OpLogInv:: GenSlidingWindowFunction(std::stringstream
&ss
,
5172 const std::string
&sSymName
, SubArguments
&vSubArguments
)
5174 ss
<< "\ndouble " << sSymName
;
5175 ss
<< "_"<< BinFuncName() <<"(";
5176 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
5180 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
5183 ss
<< " int gid0=get_global_id(0);\n";
5184 ss
<< " double tmp;\n";
5185 ss
<< " double arg0,arg1,arg2,arg3;\n";
5186 size_t i
= vSubArguments
.size();
5187 for (i
= 0; i
< vSubArguments
.size(); i
++)
5189 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
5191 if (pCur
->GetType() == formula::svDoubleVectorRef
)
5193 const formula::DoubleVectorRefToken
* pDVR
=
5194 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
5195 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
5196 ss
<< "for (int i = ";
5197 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) {
5198 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
5199 ss
<< " && i < " << nCurWindowSize
<< "; i++){\n";
5200 } else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) {
5201 ss
<< "0; i < " << pDVR
->GetArrayLength();
5202 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++){\n";
5203 } else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()){
5204 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
5205 ss
<< " && i < "<< nCurWindowSize
<< "; i++){\n ";
5208 ss
<< "0; i < "<< nCurWindowSize
<< "; i++){\n";
5211 else if (pCur
->GetType() == formula::svSingleVectorRef
)
5213 const formula::SingleVectorRefToken
* pSVR
=
5214 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
5215 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
5217 ss
<< " if (isNan(";
5218 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
5220 ss
<< " arg"<<i
<<"= 0;\n";
5222 ss
<< " arg"<<i
<<"=";
5223 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
5227 ss
<< " arg"<<i
<<"= 0;\n";
5229 else if (pCur
->GetType() == formula::svDouble
)
5231 ss
<< " if (isNan(";
5232 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
5234 ss
<< " arg"<<i
<<"= 0;\n";
5236 ss
<< " arg"<<i
<<"=";
5237 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
5241 ss
<< " double q,t,z;\n";
5242 ss
<< " q = arg0 -0.5;\n";
5243 ss
<< " if(fabs(q)<=.425)\n";
5245 ss
<< " t=0.180625-pow(q, 2);\n";
5255 " t*2509.0809287301226727";
5256 ss
<<"+33430.575583588128105\n"
5258 " *t+67265.770927008700853\n"
5260 " *t+45921.953931549871457\n"
5262 " *t+13731.693765509461125\n"
5264 " *t+1971.5909503065514427\n"
5266 " *t+133.14166789178437745\n"
5268 " *t+3.387132872796366608\n"
5278 " t*5226.495278852854561";
5279 ss
<<"+28729.085735721942674\n"
5281 " *t+39307.89580009271061\n"
5283 " *t+21213.794301586595867\n"
5285 " *t+5394.1960214247511077\n"
5287 " *t+687.1870074920579083\n"
5289 " *t+42.313330701600911252\n"
5296 ss
<<" t = q > 0 ? 1 - arg0 : arg0;\n";
5297 ss
<<" t=sqrt(-log(t));\n";
5298 ss
<<" if(t<=5.0)\n";
5309 " t*7.7454501427834140764e-4";
5310 ss
<<"+0.0227238449892691845833\n"
5312 " *t+0.24178072517745061177\n"
5314 " *t+1.27045825245236838258\n"
5316 " *t+3.64784832476320460504\n"
5318 " *t+5.7694972214606914055\n"
5320 " *t+4.6303378461565452959\n"
5322 " *t+1.42343711074968357734\n"
5332 " t*1.05075007164441684324e-9";
5333 ss
<<"+5.475938084995344946e-4\n"
5335 " *t+0.0151986665636164571966\n"
5337 " *t+0.14810397642748007459\n"
5339 " *t+0.68976733498510000455\n"
5341 " *t+1.6763848301838038494\n"
5343 " *t+2.05319162663775882187\n"
5359 " t*2.01033439929228813265e-7";
5360 ss
<<"+2.71155556874348757815e-5\n"
5362 " *t+0.0012426609473880784386\n"
5364 " *t+0.026532189526576123093\n"
5366 " *t+0.29656057182850489123\n"
5368 " *t+1.7848265399172913358\n"
5370 " *t+5.4637849111641143699\n"
5372 " *t+6.6579046435011037772\n"
5382 " t*2.04426310338993978564e-15"
5383 " +1.4215117583164458887e-7\n"
5385 " *t+1.8463183175100546818e-5\n"
5387 " *t+7.868691311456132591e-4\n"
5389 " *t+0.0148753612908506148525\n"
5391 " *t+0.13692988092273580531\n"
5393 " *t+0.59983220655588793769\n"
5398 ss
<< " z = q < 0.0 ? (-1)*z : z;\n";
5400 ss
<< " tmp = exp(arg1+arg2*z);\n";
5401 ss
<< " return tmp;\n";
5405 void OpForecast::GenSlidingWindowFunction(std::stringstream
&ss
,
5406 const std::string
&sSymName
, SubArguments
&vSubArguments
)
5408 FormulaToken
*pCur0
= vSubArguments
[0]->GetFormulaToken();
5410 const formula::SingleVectorRefToken
*pCurDVR0
= static_cast<const
5411 formula::SingleVectorRefToken
*>(pCur0
);
5412 FormulaToken
*pCur1
= vSubArguments
[1]->GetFormulaToken();
5414 const formula::DoubleVectorRefToken
* pCurDVR1
=
5415 static_cast<const formula::DoubleVectorRefToken
*>(pCur1
);
5416 size_t nCurWindowSize
= pCurDVR1
->GetRefRowSize();
5417 FormulaToken
*pCur2
= vSubArguments
[2]->GetFormulaToken();
5419 const formula::DoubleVectorRefToken
* pCurDVR2
=
5420 static_cast<const formula::DoubleVectorRefToken
*>(pCur2
);
5421 size_t nCurWindowSize1
= pCurDVR2
->GetRefRowSize();
5422 ss
<< "\ndouble " << sSymName
;
5423 ss
<< "_"<< BinFuncName() <<"( ";
5424 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
5428 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
5431 ss
<< " int gid0 = get_global_id(0);\n";
5432 ss
<< " double fSumX = 0.0;\n";
5433 ss
<< " double fSumY = 0.0;\n";
5434 ss
<< " double fSumDeltaXDeltaY = 0.0;\n";
5435 ss
<< " double fSumSqrDeltaX = 0.0;\n";
5436 if(pCur0
->GetType()== formula::svDouble
||
5437 pCur0
->GetType() == formula::svSingleVectorRef
)
5439 ss
<< " double arg0 = ";
5440 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
5444 ss
<< "return HUGE_VAL";
5445 if(pCur1
->GetType() != formula::svDoubleVectorRef
||
5446 pCur2
->GetType() != formula::svDoubleVectorRef
)
5447 ss
<< "return HUGE_VAL";
5450 ss
<< " if(isNan(arg0)||(gid0>=";
5451 ss
<<pCurDVR0
->GetArrayLength();
5454 ss
<< " int length="<<nCurWindowSize
;
5456 ss
<< " int length1= "<<nCurWindowSize1
;
5458 ss
<< " if(length!=length1)\n";
5459 ss
<< " return 0;\n";
5460 ss
<< " double tmp = 0;\n";
5461 ss
<< " for (int i = 0; i <" << nCurWindowSize
<< "; i++)\n";
5463 ss
<< " double arg1 = ";
5464 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef(true);
5466 ss
<< " double arg2 = ";
5467 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef(true);
5469 ss
<< " if(isNan(arg1)||((gid0+i)>=";
5470 ss
<< pCurDVR1
->GetArrayLength();
5473 ss
<< " length--;\n";
5474 ss
<< " continue;\n";
5476 ss
<< " if(isNan(arg2)||((gid0+i)>=";
5477 ss
<< pCurDVR2
->GetArrayLength();
5480 ss
<< " length--;\n";
5481 ss
<< " continue;\n";
5483 ss
<< " fSumY+=arg1;\n";
5484 ss
<< " fSumX+=arg2;\n";
5486 ss
<< " double fMeanX = fSumX / length;\n";
5487 ss
<< " double fMeanY = fSumY / length;\n";
5488 ss
<< " for (int i = 0; i <" << nCurWindowSize
<< "; i++)\n";
5490 ss
<< " double arg1 = ";
5491 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef(true);
5493 ss
<< " double arg2 = ";
5494 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef(true);
5496 ss
<< " if(isNan(arg1)||((gid0+i)>=";
5497 ss
<<pCurDVR1
->GetArrayLength();
5500 ss
<<" continue;\n";
5502 ss
<< " if(isNan(arg2)||((gid0+i)>=";
5503 ss
<<pCurDVR2
->GetArrayLength();
5506 ss
<<" continue;\n";
5508 ss
<<" fSumDeltaXDeltaY+=(arg2 - fMeanX) * (arg1 - fMeanY);\n";
5509 ss
<<" fSumSqrDeltaX+=pow(arg2 - fMeanX, 2);\n";
5511 ss
<<" tmp =fMeanY + fSumDeltaXDeltaY / fSumSqrDeltaX *";
5512 ss
<<" (arg0 - fMeanX);\n";
5513 ss
<<" return tmp;\n";
5517 void OpLogNormDist::GenSlidingWindowFunction(std::stringstream
&ss
,
5518 const std::string
&sSymName
, SubArguments
&vSubArguments
)
5520 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
5521 const formula::SingleVectorRefToken
*tmpCurDVR0
= static_cast<const
5522 formula::SingleVectorRefToken
*>(tmpCur0
);
5523 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
5524 const formula::SingleVectorRefToken
*tmpCurDVR1
= static_cast<const
5525 formula::SingleVectorRefToken
*>(tmpCur1
);
5526 FormulaToken
*tmpCur2
= vSubArguments
[2]->GetFormulaToken();
5527 const formula::SingleVectorRefToken
*tmpCurDVR2
= static_cast<const
5528 formula::SingleVectorRefToken
*>(tmpCur2
);
5529 FormulaToken
*tmpCur3
= vSubArguments
[3]->GetFormulaToken();
5530 const formula::SingleVectorRefToken
*tmpCurDVR3
= static_cast<const
5531 formula::SingleVectorRefToken
*>(tmpCur3
);
5532 ss
<< "\ndouble " << sSymName
;
5533 ss
<< "_"<< BinFuncName() <<"(";
5534 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
5538 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
5541 ss
<< " int gid0=get_global_id(0);\n";
5542 ss
<< " double arg0,arg1,arg2,arg3;\n";
5543 size_t i
= vSubArguments
.size();
5544 for (i
= 0; i
< vSubArguments
.size(); i
++)
5546 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
5548 if (pCur
->GetType() == formula::svDoubleVectorRef
)
5550 const formula::DoubleVectorRefToken
* pDVR
=
5551 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
5552 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
5553 ss
<< "for (int i = ";
5554 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) {
5555 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
5556 ss
<< " && i < " << nCurWindowSize
<< "; i++){\n";
5557 } else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) {
5558 ss
<< "0; i < " << pDVR
->GetArrayLength();
5559 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++){\n";
5560 } else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()){
5561 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
5562 ss
<< " && i < "<< nCurWindowSize
<< "; i++){\n ";
5565 ss
<< "0; i < "<< nCurWindowSize
<< "; i++){\n";
5568 else if (pCur
->GetType() == formula::svSingleVectorRef
)
5570 const formula::SingleVectorRefToken
* pSVR
=
5571 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
5572 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
5574 ss
<< " if (isNan(";
5575 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
5577 ss
<< " arg"<<i
<<"= 0;\n";
5579 ss
<< " arg"<<i
<<"=";
5580 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
5584 ss
<< " arg"<<i
<<"= 0;\n";
5586 else if (pCur
->GetType() == formula::svDouble
)
5588 ss
<< " if (isNan(";
5589 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
5591 ss
<< " arg"<<i
<<"= 0;\n";
5593 ss
<< " arg"<<i
<<"=";
5594 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
5598 ss
<< " double tmp;\n";
5599 ss
<< " if(isNan(arg0)||(gid0>=";
5600 ss
<< tmpCurDVR0
->GetArrayLength();
5602 ss
<< " arg0 = 0;\n";
5603 ss
<< " if(isNan(arg1)||(gid0>=";
5604 ss
<< tmpCurDVR1
->GetArrayLength();
5606 ss
<< " arg1 = 0;\n";
5607 ss
<< " if(isNan(arg2)||(gid0>=";
5608 ss
<< tmpCurDVR2
->GetArrayLength();
5610 ss
<< " arg2 = 0;\n";
5611 ss
<< " if(isNan(arg3)||(gid0>=";
5612 ss
<< tmpCurDVR3
->GetArrayLength();
5614 ss
<< " arg3 = 0;\n";
5615 ss
<< " double temp = (log(arg0)-arg1)/arg2;\n";
5616 ss
<< " if(arg3)\n";
5618 ss
<< " if(arg0<=0)\n";
5619 ss
<< " tmp = 0.0;\n";
5621 ss
<< " tmp = 0.5 * erfc(-temp * 0.7071067811865475);\n";
5624 ss
<< " tmp = (0.39894228040143268 * exp((-1)*pow(temp, 2)";
5625 ss
<< " / 2.0))/(arg2*arg0);\n";
5626 ss
<< " return tmp;\n";
5630 void OpGammaDist::BinInlineFun(std::set
<std::string
>& decls
,
5631 std::set
<std::string
>& funs
)
5633 decls
.insert(fBigInvDecl
);decls
.insert(fLogDblMaxDecl
);
5634 decls
.insert(fHalfMachEpsDecl
);decls
.insert(fMaxGammaArgumentDecl
);
5635 decls
.insert(GetGammaSeriesDecl
);decls
.insert(GetGammaContFractionDecl
);
5636 decls
.insert(GetLowRegIGammaDecl
);decls
.insert(GetGammaDistDecl
);
5637 decls
.insert(GetGammaDistPDFDecl
);
5638 funs
.insert(GetGammaSeries
);funs
.insert(GetGammaContFraction
);
5639 funs
.insert(GetLowRegIGamma
);funs
.insert(GetGammaDist
);
5640 funs
.insert(GetGammaDistPDF
);
5643 void OpGammaDist::GenSlidingWindowFunction(std::stringstream
&ss
,
5644 const std::string
&sSymName
, SubArguments
&vSubArguments
)
5646 ss
<< "\ndouble " << sSymName
;
5647 ss
<< "_"<< BinFuncName() <<"(";
5648 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
5652 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
5655 ss
<< " int gid0=get_global_id(0);\n";
5656 ss
<< " double tmp;\n";
5657 ss
<< " double arg0,arg1,arg2,arg3;\n";
5658 size_t i
= vSubArguments
.size();
5660 for (i
= 0; i
< vSubArguments
.size(); i
++)
5662 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
5664 if (pCur
->GetType() == formula::svDoubleVectorRef
)
5666 const formula::DoubleVectorRefToken
* pDVR
=
5667 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
5668 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
5669 ss
<< "for (int i = ";
5670 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) {
5671 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
5672 ss
<< " && i < " << nCurWindowSize
<< "; i++){\n";
5673 } else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) {
5674 ss
<< "0; i < " << pDVR
->GetArrayLength();
5675 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++){\n";
5676 } else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()){
5677 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
5678 ss
<< " && i < "<< nCurWindowSize
<< "; i++){\n ";
5681 ss
<< "0; i < "<< nCurWindowSize
<< "; i++){\n";
5684 else if (pCur
->GetType() == formula::svSingleVectorRef
)
5686 const formula::SingleVectorRefToken
* pSVR
=
5687 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
5688 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
5690 ss
<< " if (isNan(";
5691 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
5693 ss
<< " arg"<<i
<<"= 0;\n";
5695 ss
<< " arg"<<i
<<"=";
5696 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
5700 ss
<< " arg"<<i
<<"= 0;\n";
5702 else if (pCur
->GetType() == formula::svDouble
)
5704 ss
<< " if (isNan(";
5705 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
5707 ss
<< " arg"<<i
<<"= 0;\n";
5709 ss
<< " arg"<<i
<<"=";
5710 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
5714 ss
<< " if (arg3)\n";
5715 ss
<< " tmp=GetGammaDist( arg0, arg1, arg2);\n";
5717 ss
<< " tmp=GetGammaDistPDF( arg0, arg1, arg2);\n";
5718 ss
<< " return tmp;\n";
5721 void OpChiDist::BinInlineFun(std::set
<std::string
>& decls
,
5722 std::set
<std::string
>& funs
)
5724 decls
.insert(fBigInvDecl
);
5726 decls
.insert(fHalfMachEpsDecl
);
5728 decls
.insert(GetUpRegIGammaDecl
);
5729 funs
.insert(GetUpRegIGamma
);
5730 decls
.insert(GetGammaSeriesDecl
);
5731 funs
.insert(GetGammaSeries
);
5732 decls
.insert(GetGammaContFractionDecl
);
5733 funs
.insert(GetGammaContFraction
);
5734 decls
.insert(GetChiDistDecl
);
5735 funs
.insert(GetChiDist
);
5737 void OpChiDist::GenSlidingWindowFunction(
5738 std::stringstream
&ss
,const std::string
&sSymName
,
5739 SubArguments
&vSubArguments
)
5741 ss
<< "\ndouble " << sSymName
;
5742 ss
<< "_"<< BinFuncName() <<"(";
5743 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
5747 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
5751 ss
<< " double fx,fDF,tmp=0,tmp0=0,tmp1=0;\n";
5752 ss
<< " int gid0=get_global_id(0);\n";
5754 size_t i
= vSubArguments
.size();
5756 for (i
= 0; i
< vSubArguments
.size(); i
++)
5758 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
5760 if (pCur
->GetType() == formula::svDoubleVectorRef
)
5762 const formula::DoubleVectorRefToken
* pDVR
=
5763 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
5764 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
5765 ss
<< "for (int i = ";
5766 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
5768 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
5769 ss
<< " && i < " << nCurWindowSize
<< "; i++){\n";
5771 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
5773 ss
<< "0; i < " << pDVR
->GetArrayLength();
5774 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++){\n";
5776 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
5778 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
5779 ss
<< " && i < "<< nCurWindowSize
<< "; i++){\n";
5783 ss
<< "0; i < "<< nCurWindowSize
<< "; i++){\n";
5786 else if (pCur
->GetType() == formula::svSingleVectorRef
)
5788 const formula::SingleVectorRefToken
* pSVR
=
5789 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
5790 ss
<< "if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
5792 else if (pCur
->GetType() == formula::svDouble
)
5799 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
5801 ss
<< " if (isNan(";
5802 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
5804 ss
<< " tmp"<<i
<<"= 0;\n";
5806 ss
<< " tmp"<<i
<<"=\n";
5807 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
5811 ss
<< " fx = tmp0;\n";
5812 ss
<< " fDF = floor(tmp1);\n";
5813 ss
<< " if(fDF < 1.0)\n";
5815 ss
<< " return DBL_MIN;\n";
5817 ss
<< " tmp = GetChiDist( fx, fDF);\n";
5818 ss
<< " return tmp;\n";
5821 void OpBinomdist::BinInlineFun(std::set
<std::string
>& decls
,
5822 std::set
<std::string
>& funs
)
5824 decls
.insert(fMachEpsDecl
);
5826 decls
.insert(MinDecl
);
5828 decls
.insert(fMaxGammaArgumentDecl
);
5830 decls
.insert(GetBinomDistPMFDecl
);
5831 funs
.insert(GetBinomDistPMF
);
5832 decls
.insert(GetBetaDistDecl
);
5833 funs
.insert(GetBetaDist
);
5834 decls
.insert(lcl_GetBinomDistRangeDecl
);
5835 funs
.insert(lcl_GetBinomDistRange
);
5836 decls
.insert(lcl_GetBetaHelperContFracDecl
);
5837 funs
.insert(lcl_GetBetaHelperContFrac
);
5838 decls
.insert(GetBetaDistPDFDecl
);
5839 funs
.insert(GetBetaDistPDF
);
5840 decls
.insert(GetLogBetaDecl
);
5841 funs
.insert(GetLogBeta
);
5842 decls
.insert(GetBetaDecl
);
5843 funs
.insert(GetBeta
);
5844 decls
.insert(lcl_getLanczosSumDecl
);
5845 funs
.insert(lcl_getLanczosSum
);
5847 void OpBinomdist::GenSlidingWindowFunction(
5848 std::stringstream
&ss
,const std::string
&sSymName
,
5849 SubArguments
&vSubArguments
)
5851 ss
<< "\ndouble " << sSymName
;
5852 ss
<< "_"<< BinFuncName() <<"(";
5853 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
5857 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
5861 ss
<< " double tmp0,tmp1,tmp2,tmp3;\n";
5862 ss
<< " int gid0=get_global_id(0);\n";
5863 size_t i
= vSubArguments
.size();
5867 for (i
= 0; i
< vSubArguments
.size(); i
++)
5869 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
5871 if (pCur
->GetType() == formula::svDoubleVectorRef
)
5873 const formula::DoubleVectorRefToken
* pDVR
=
5874 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
5875 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
5876 ss
<< "for (int i = ";
5877 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
5879 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
5880 ss
<< " && i < " << nCurWindowSize
<< "; i++){\n";
5882 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
5884 ss
<< "0; i < " << pDVR
->GetArrayLength();
5885 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++){\n";
5887 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
5889 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
5890 ss
<< " && i < "<< nCurWindowSize
<< "; i++){\n";
5894 ss
<< "0; i < "<< nCurWindowSize
<< "; i++){\n";
5897 else if (pCur
->GetType() == formula::svSingleVectorRef
)
5899 const formula::SingleVectorRefToken
* pSVR
=
5900 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
5901 ss
<< "if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
5903 else if (pCur
->GetType() == formula::svDouble
)
5910 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
5912 ss
<< " if (isNan(";
5913 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
5915 ss
<< " tmp"<<i
<<"= 0;\n";
5917 ss
<< " tmp"<<i
<<"=\n";
5918 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
5923 ss
<< "tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
5927 ss
<< " tmp0 = floor(tmp0);\n";
5928 ss
<< " tmp1 = floor(tmp1);\n";
5929 ss
<< " double rq = (0.5 - tmp2) + 0.5;\n";
5930 ss
<< " if (tmp1 < 0.0 || tmp0 < 0.0 || tmp0 > tmp1 ||";
5931 ss
<< "tmp2 < 0.0 || tmp2 > 1.0)\n";
5933 ss
<< " return DBL_MIN;\n";
5935 ss
<< " if(tmp2 == 0.0)\n";
5936 ss
<< " return ( (tmp0 == 0.0 || tmp3) ? 1.0 : 0.0 );\n";
5937 ss
<< " if(tmp2 == 1.0)\n";
5938 ss
<< " return ( (tmp0 == tmp1) ? 1.0 : 0.0);\n";
5939 ss
<< " if(!tmp3)\n";
5940 ss
<< " return ( GetBinomDistPMF(tmp0, tmp1, tmp2));\n";
5943 ss
<< " if(tmp0 == tmp1)\n";
5944 ss
<< " return 1.0;\n";
5947 ss
<< " double fFactor = pow(rq,tmp1);\n";
5948 ss
<< " if(tmp0 == 0.0)\n";
5949 ss
<< " return (fFactor);\n";
5950 ss
<< " else if(fFactor <= Min)\n";
5952 ss
<< " fFactor = pow(tmp2,tmp1);\n";
5953 ss
<< " if(fFactor <= Min)\n";
5954 ss
<< " return GetBetaDist";
5955 ss
<< "(rq, tmp1 - tmp0, tmp0 + 1.0);\n";
5958 ss
<< " if(fFactor > fMachEps)\n";
5960 ss
<< " double fSum = 1.0 - fFactor;\n";
5961 ss
<< " unsigned int max = ";
5962 ss
<< "(unsigned int)((tmp1 - tmp0)-1);\n";
5963 ss
<< " for (uint i = 0; i < max && fFactor > 0.0;";
5966 ss
<< " fFactor *= (tmp1 - i)*pow((i + 1),-1.0)*";
5967 ss
<< "rq*pow(tmp2,-1.0);\n";
5968 ss
<< " fSum -= fFactor;\n";
5970 ss
<< " return ( (fSum < 0.0) ? 0.0 : fSum );\n";
5973 ss
<< " return (lcl_GetBinomDistRange";
5974 ss
<< "(tmp1, tmp1 - tmp0, tmp1, fFactor, rq, tmp2));\n";
5979 ss
<< " double rtmp = ( lcl_GetBinomDistRange";
5980 ss
<< "(tmp1, 0.0, tmp0, fFactor, tmp2, rq));\n";
5981 ss
<< " return rtmp;\n";
5988 void OpChiSqDist::BinInlineFun(std::set
<std::string
>& decls
,
5989 std::set
<std::string
>& funs
)
5991 decls
.insert(fMaxGammaArgumentDecl
);decls
.insert(GetChiSqDistCDFDecl
);
5992 decls
.insert(GetChiSqDistPDFDecl
);decls
.insert(GetLowRegIGammaDecl
);
5993 decls
.insert(GetGammaContFractionDecl
);decls
.insert(GetGammaSeriesDecl
);
5994 decls
.insert(fHalfMachEpsDecl
);decls
.insert(F_PIDecl
);
5995 decls
.insert(fBigInvDecl
);
5997 funs
.insert(GetGammaContFraction
);funs
.insert(GetChiSqDistCDF
);
5998 funs
.insert(GetChiSqDistPDF
);funs
.insert(GetLowRegIGamma
);
5999 funs
.insert(GetGammaSeries
);
6002 void OpChiSqDist::GenSlidingWindowFunction(
6003 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&
6006 ss
<< "\ndouble " << sSymName
;
6007 ss
<< "_"<< BinFuncName() <<"(";
6008 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
6012 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
6015 ss
<< " int gid0 = get_global_id(0);\n";
6016 ss
<< " int singleIndex = gid0;\n";
6017 ss
<< " double result = 0;\n";
6018 if(vSubArguments
.size()<2)
6020 ss
<< " result = -DBL_MAX;\n";
6021 ss
<< " return result;\n";
6024 GenTmpVariables(ss
,vSubArguments
);
6025 CheckAllSubArgumentIsNan(ss
,vSubArguments
);
6026 if(vSubArguments
.size() == 2)
6028 ss
<< " int tmp2 = 1;\n";
6031 size_t i
= vSubArguments
.size();
6033 for (i
= 0; i
< vSubArguments
.size(); i
++)
6035 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
6037 if (pCur
->GetType() == formula::svSingleVectorRef
)
6039 const formula::SingleVectorRefToken
* pSVR
=
6040 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
6041 ss
<< "if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
6043 else if (pCur
->GetType() == formula::svDouble
)
6048 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
6050 ss
<< " if (isNan(";
6051 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
6053 ss
<< " tmp"<<i
<<"= 0;\n";
6055 ss
<< " tmp"<<i
<<"=\n";
6056 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
6061 ss
<< "tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
6065 ss
<< " tmp1 = floor(tmp1);\n";
6066 ss
<< " if(tmp1 < 1.0)\n";
6067 ss
<< " result = -DBL_MAX;\n";
6070 ss
<< " if(tmp2)\n";
6071 ss
<< " result =GetChiSqDistCDF(tmp0,tmp1);\n";
6073 ss
<< " result =GetChiSqDistPDF(tmp0,tmp1);\n";
6075 ss
<< " return result;\n";
6079 void OpChiSqInv::BinInlineFun(std::set
<std::string
>& decls
,
6080 std::set
<std::string
>& funs
)
6082 decls
.insert(fMaxGammaArgumentDecl
);decls
.insert(GetChiSqDistCDFDecl
);
6083 decls
.insert(GetLowRegIGammaDecl
);decls
.insert(lcl_IterateInverseChiSQInvDecl
);
6084 decls
.insert(GetGammaContFractionDecl
);decls
.insert(GetGammaSeriesDecl
);
6085 decls
.insert(fHalfMachEpsDecl
);decls
.insert(F_PIDecl
);
6086 decls
.insert(fBigInvDecl
);decls
.insert(lcl_HasChangeOfSignDecl
);
6087 decls
.insert(fMachEpsDecl
);
6089 funs
.insert(GetGammaContFraction
);funs
.insert(GetChiSqDistCDF
);
6090 funs
.insert(GetLowRegIGamma
);funs
.insert(lcl_HasChangeOfSign
);
6091 funs
.insert(GetGammaSeries
);funs
.insert(lcl_IterateInverseChiSQInv
);
6094 void OpChiSqInv::GenSlidingWindowFunction(
6095 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&
6098 ss
<< "\ndouble " << sSymName
;
6099 ss
<< "_"<< BinFuncName() <<"(";
6100 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
6104 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
6107 ss
<< " int gid0 = get_global_id(0);\n";
6108 ss
<< " int singleIndex = gid0;\n";
6109 ss
<< " double result = 0;\n";
6110 if(vSubArguments
.size()!=2)
6112 ss
<< " result = -DBL_MAX;\n";
6113 ss
<< " return result;\n";
6117 GenTmpVariables(ss
,vSubArguments
);
6118 CheckAllSubArgumentIsNan(ss
,vSubArguments
);
6119 size_t i
= vSubArguments
.size();
6121 for (i
= 0; i
< vSubArguments
.size(); i
++)
6123 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
6125 if (pCur
->GetType() == formula::svSingleVectorRef
)
6127 const formula::SingleVectorRefToken
* pSVR
=
6128 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
6129 ss
<< "if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
6131 else if (pCur
->GetType() == formula::svDouble
)
6136 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
6138 ss
<< " if (isNan(";
6139 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
6141 ss
<< " tmp"<<i
<<"= 0;\n";
6143 ss
<< " tmp"<<i
<<"=\n";
6144 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
6149 ss
<< "tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
6153 ss
<< " tmp1 = floor(tmp1);\n";
6154 ss
<< " bool bConvError;\n";
6155 ss
<< " if(tmp1 < 1.0 || tmp0 < 0 || tmp0>=1.0)\n";
6156 ss
<< " result = -DBL_MAX;\n";
6159 ss
<< " result =lcl_IterateInverseChiSQInv( tmp0, tmp1,";
6160 ss
<< "tmp1*0.5, tmp1, &bConvError );\n";
6162 ss
<< " if(bConvError)\n";
6163 ss
<< " result = -DBL_MAX;\n";
6164 ss
<< " return result;\n";
6169 void OpGammaInv::BinInlineFun(std::set
<std::string
>& decls
,
6170 std::set
<std::string
>& funs
)
6172 decls
.insert(fBigInvDecl
);decls
.insert(fHalfMachEpsDecl
);
6173 decls
.insert(GetGammaSeriesDecl
);decls
.insert(GetGammaContFractionDecl
);
6174 decls
.insert(GetGammaInvValueDecl
);
6175 funs
.insert(GetGammaSeries
);funs
.insert(GetGammaContFraction
);
6176 funs
.insert(GetGammaInvValue
);
6179 void OpGammaInv::GenSlidingWindowFunction(std::stringstream
&ss
,
6180 const std::string
&sSymName
, SubArguments
&vSubArguments
)
6182 ss
<< "\ndouble " << sSymName
;
6183 ss
<< "_"<< BinFuncName() <<"(";
6184 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
6188 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
6191 ss
<< " int gid0=get_global_id(0);\n";
6192 ss
<< " double tmp;\n";
6193 ss
<< " double arg0,arg1,arg2;\n";
6194 size_t i
= vSubArguments
.size();
6196 for (i
= 0; i
< vSubArguments
.size(); i
++)
6198 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
6200 if (pCur
->GetType() == formula::svDoubleVectorRef
)
6202 const formula::DoubleVectorRefToken
* pDVR
=
6203 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
6204 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
6205 ss
<< "for (int i = ";
6206 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) {
6207 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
6208 ss
<< " && i < " << nCurWindowSize
<< "; i++){\n";
6209 } else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) {
6210 ss
<< "0; i < " << pDVR
->GetArrayLength();
6211 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++){\n";
6212 } else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()){
6213 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
6214 ss
<< " && i < "<< nCurWindowSize
<< "; i++){\n ";
6217 ss
<< "0; i < "<< nCurWindowSize
<< "; i++){\n";
6220 else if (pCur
->GetType() == formula::svSingleVectorRef
)
6222 const formula::SingleVectorRefToken
* pSVR
=
6223 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
6224 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
6226 ss
<< " if (isNan(";
6227 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
6229 ss
<< " arg"<<i
<<"= 0;\n";
6231 ss
<< " arg"<<i
<<"=";
6232 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
6236 ss
<< " arg"<<i
<<"= 0;\n";
6238 else if (pCur
->GetType() == formula::svDouble
)
6240 ss
<< " if (isNan(";
6241 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
6243 ss
<< " arg"<<i
<<"= 0;\n";
6245 ss
<< " arg"<<i
<<"=";
6246 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
6250 ss
<< " if (arg0 == 0.0)\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"
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"
6271 " if (fabs(fAy) <= fabs(fBy))\n"
6274 " fAx += 2.0 * (fAx - fBx);\n"
6279 " fAy = arg0-GetGammaInvValue(arg1,arg2,fAx);\n"
6284 " fBx += 2.0 * (fBx - fAx);\n"
6287 " fBy = arg0-GetGammaInvValue(arg1,arg2,fBx);\n"
6290 " if (fAy == 0.0)\n"
6295 " if (fBy == 0.0)\n"
6300 " if (!((fAy < 0.0 && fBy > 0.0) || (fAy > 0.0 && fBy < 0.0)))\n"
6302 " bConvError = true;\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"
6315 " while ( nCount < 500 && fabs(fRy) > fYEps &&"
6316 "(fBx-fAx) > fmax( fabs(fAx), fabs(fBx)) * fXEps )\n"
6318 " if (bHasToInterpolate)\n"
6320 " if (fPy!=fQy && fQy!=fRy && fRy!=fPy)\n"
6322 " fSx = fPx * fRy * fQy *pow( (fRy-fPy),-1) *pow"
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"
6329 " bHasToInterpolate = false;\n"
6331 " if(!bHasToInterpolate)\n"
6333 " fSx = 0.5 * (fAx + fBx);\n"
6334 " fPx = fAx; fPy = fAy;\n"
6335 " fQx = fBx; fQy = fBy;\n"
6336 " bHasToInterpolate = true;\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"
6351 " bHasToInterpolate = bHasToInterpolate && (fabs(fRy)"
6352 " * 2.0 <= fabs(fQy));\n"
6360 void OpFInv::BinInlineFun(std::set
<std::string
>& decls
,
6361 std::set
<std::string
>& funs
)
6363 decls
.insert(fMachEpsDecl
);decls
.insert(fMaxGammaArgumentDecl
);
6364 decls
.insert(lcl_getLanczosSumDecl
);decls
.insert(GetBetaDecl
);
6365 decls
.insert(GetLogBetaDecl
);decls
.insert(GetBetaDistPDFDecl
);
6366 decls
.insert(lcl_GetBetaHelperContFracDecl
);decls
.insert(GetFInvValueDecl
);
6367 funs
.insert(lcl_getLanczosSum
);funs
.insert(GetBeta
);
6368 funs
.insert(GetLogBeta
);funs
.insert(GetBetaDistPDF
);
6369 funs
.insert(lcl_GetBetaHelperContFrac
);funs
.insert(GetFInvValue
);
6372 void OpFInv::GenSlidingWindowFunction(std::stringstream
&ss
,
6373 const std::string
&sSymName
, SubArguments
&vSubArguments
)
6375 ss
<< "\ndouble " << sSymName
;
6376 ss
<< "_"<< BinFuncName() <<"(";
6377 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
6381 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
6384 ss
<< " int gid0=get_global_id(0);\n";
6385 ss
<< " double tmp;\n";
6386 ss
<< " double arg0,arg1,arg2;\n";
6387 size_t i
= vSubArguments
.size();
6389 for (i
= 0; i
< vSubArguments
.size(); i
++)
6391 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
6393 if (pCur
->GetType() == formula::svDoubleVectorRef
)
6395 const formula::DoubleVectorRefToken
* pDVR
=
6396 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
6397 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
6398 ss
<< "for (int i = ";
6399 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) {
6400 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
6401 ss
<< " && i < " << nCurWindowSize
<< "; i++){\n";
6402 } else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) {
6403 ss
<< "0; i < " << pDVR
->GetArrayLength();
6404 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++){\n";
6405 } else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()){
6406 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
6407 ss
<< " && i < "<< nCurWindowSize
<< "; i++){\n ";
6410 ss
<< "0; i < "<< nCurWindowSize
<< "; i++){\n";
6413 else if (pCur
->GetType() == formula::svSingleVectorRef
)
6415 const formula::SingleVectorRefToken
* pSVR
=
6416 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
6417 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
6419 ss
<< " if (isNan(";
6420 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
6422 ss
<< " arg"<<i
<<"= 0;\n";
6424 ss
<< " arg"<<i
<<"="<<vSubArguments
[i
]->
6425 GenSlidingWindowDeclRef();
6429 ss
<< " arg"<<i
<<"= 0;\n";
6431 else if (pCur
->GetType() == formula::svDouble
)
6433 ss
<< " if (isNan(";
6434 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
6436 ss
<< " arg"<<i
<<"= 0;\n";
6438 ss
<< " arg"<<i
<<"="<<vSubArguments
[i
]->
6439 GenSlidingWindowDeclRef();
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"
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"
6458 " if (fabs(fAy) <= fabs(fBy))\n"
6461 " fAx += 2.0 * (fAx - fBx);\n"
6466 " fAy = arg0-GetFInvValue(fF1,fF2,fAx);\n"
6471 " fBx += 2.0 * (fBx - fAx);\n"
6474 " fBy = arg0-GetFInvValue(fF1,fF2,fBx);\n"
6477 " if (fAy == 0.0)\n"
6482 " if (fBy == 0.0)\n"
6487 " if (!((fAy < 0.0 && fBy > 0.0) || (fAy > 0.0 && fBy < 0.0)))\n"
6489 " bConvError = true;\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"
6502 " while ( nCount < 500 && fabs(fRy) > fYEps &&"
6503 "(fBx-fAx) > fmax( fabs(fAx), fabs(fBx)) * fXEps )\n"
6505 " if (bHasToInterpolate)\n"
6507 " if (fPy!=fQy && fQy!=fRy && fRy!=fPy)\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"
6516 " bHasToInterpolate = false;\n"
6518 " if(!bHasToInterpolate)\n"
6520 " fSx = 0.5 * (fAx + fBx);\n"
6521 " fPx = fAx; fPy = fAy;\n"
6522 " fQx = fBx; fQy = fBy;\n"
6523 " bHasToInterpolate = true;\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"
6530 " fBx = fRx; fBy = fRy;\n"
6534 " fAx = fRx; fAy = fRy;\n"
6536 " bHasToInterpolate = bHasToInterpolate && (fabs(fRy)"
6537 " * 2.0 <= fabs(fQy));\n"
6544 void OpFTest::BinInlineFun(std::set
<std::string
>& decls
,
6545 std::set
<std::string
>& funs
)
6547 decls
.insert(fMachEpsDecl
);decls
.insert(fMaxGammaArgumentDecl
);
6548 decls
.insert(lcl_getLanczosSumDecl
);decls
.insert(GetBetaDecl
);
6549 decls
.insert(GetLogBetaDecl
);decls
.insert(GetBetaDistPDFDecl
);
6550 decls
.insert(lcl_GetBetaHelperContFracDecl
);decls
.insert(GetBetaDistDecl
);
6551 decls
.insert(GetFDistDecl
);
6552 funs
.insert(lcl_getLanczosSum
);funs
.insert(GetBeta
);
6553 funs
.insert(GetLogBeta
);funs
.insert(GetBetaDistPDF
);
6554 funs
.insert(lcl_GetBetaHelperContFrac
);funs
.insert(GetBetaDist
);
6555 funs
.insert(GetFDist
);
6557 void OpFTest::GenSlidingWindowFunction(std::stringstream
&ss
,
6558 const std::string
&sSymName
, SubArguments
&vSubArguments
)
6560 FormulaToken
*pCur
= vSubArguments
[0]->GetFormulaToken();
6562 const formula::DoubleVectorRefToken
* pCurDVR
=
6563 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
6564 size_t nCurWindowSize
= pCurDVR
->GetRefRowSize();
6565 FormulaToken
*pCur1
= vSubArguments
[1]->GetFormulaToken();
6567 const formula::DoubleVectorRefToken
* pCurDVR1
=
6568 static_cast<const formula::DoubleVectorRefToken
*>(pCur1
);
6569 size_t nCurWindowSize1
= pCurDVR1
->GetRefRowSize();
6570 ss
<< "\ndouble " << sSymName
;
6571 ss
<< "_"<< BinFuncName() <<"( ";
6572 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
6576 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
6579 ss
<< " int gid0 = get_global_id(0);\n";
6580 ss
<< " double fSum1 = 0.0;\n";
6581 ss
<< " double fSumSqr1 = 0.0;\n";
6582 ss
<< " double fSum2 = 0.0;\n";
6583 ss
<< " double fSumSqr2 = 0.0;\n";
6584 ss
<< " int length0="<<nCurWindowSize
;
6586 ss
<< " int length1= "<<nCurWindowSize1
;
6588 ss
<< " double tmp = 0;\n";
6589 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
6591 FormulaToken
*pCurSub
= vSubArguments
[i
]->GetFormulaToken();
6593 if (pCurSub
->GetType() == formula::svDoubleVectorRef
)
6595 const formula::DoubleVectorRefToken
* pDVR
=
6596 static_cast<const formula::DoubleVectorRefToken
*>(pCurSub
);
6597 ss
<< " for (int i = ";
6598 ss
<< "0; i < "<< pDVR
->GetRefRowSize() << "; i++){\n";
6599 ss
<< " double arg"<<i
<<" = ";
6600 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef(true);
6602 ss
<< " if(isNan(arg"<<i
<<")||((gid0+i)>=";
6603 ss
<< pDVR
->GetArrayLength();
6606 ss
<< " length"<<i
<<"--;\n";
6607 ss
<< " continue;\n";
6609 ss
<< " fSum"<<i
+1<<" += arg"<<i
<<";\n";
6610 ss
<< " fSumSqr"<<i
+1<<" += arg"<<i
;
6611 ss
<< " * arg"<<i
<<";\n";
6614 else if (pCurSub
->GetType() == formula::svSingleVectorRef
)
6616 ss
<< "return HUGE_VAL";
6618 else if (pCurSub
->GetType() == formula::svDouble
)
6620 ss
<< "return HUGE_VAL";
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"
6629 " fF1 = length0-1.0;\n"
6630 " fF2 = length1-1.0;\n"
6635 " fF1 = length1-1.0;\n"
6636 " fF2 = length0-1.0;\n"
6638 " tmp = 2.0*GetFDist(fF, fF1, fF2);\n";
6639 ss
<< " return tmp;\n";
6642 void OpB::BinInlineFun(std::set
<std::string
>& decls
,
6643 std::set
<std::string
>& funs
)
6645 //decls.insert(fBigInvDecl);decls.insert(fLogDblMaxDecl);
6646 decls
.insert(GetBinomDistPMFDecl
);decls
.insert(MinDecl
);
6647 decls
.insert(fMachEpsDecl
);decls
.insert(fMaxGammaArgumentDecl
);
6648 decls
.insert(GetBetaDistDecl
);decls
.insert(GetBetaDistPDFDecl
);
6649 decls
.insert(lcl_GetBetaHelperContFracDecl
);decls
.insert(GetLogBetaDecl
);
6650 decls
.insert(lcl_getLanczosSumDecl
); decls
.insert(GetBetaDecl
);
6651 funs
.insert(GetBinomDistPMF
);funs
.insert(lcl_GetBinomDistRange
);
6652 funs
.insert(GetBetaDist
);funs
.insert(GetBetaDistPDF
);
6653 funs
.insert(lcl_GetBetaHelperContFrac
);funs
.insert(GetLogBeta
);
6654 funs
.insert(lcl_getLanczosSum
);funs
.insert(GetBeta
);
6657 void OpB::GenSlidingWindowFunction(std::stringstream
&ss
,
6658 const std::string
&sSymName
, SubArguments
&vSubArguments
)
6660 ss
<< "\ndouble " << sSymName
;
6661 ss
<< "_"<< BinFuncName() <<"(";
6662 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
6666 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
6669 ss
<< " int gid0=get_global_id(0);\n";
6670 ss
<< " double min = 2.22507e-308;\n";
6671 ss
<< " double tmp;\n";
6672 ss
<< " double arg0,arg1,arg2,arg3;\n";
6673 size_t i
= vSubArguments
.size();
6674 for (i
= 0; i
< vSubArguments
.size(); i
++)
6676 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
6678 if (pCur
->GetType() == formula::svDoubleVectorRef
)
6680 const formula::DoubleVectorRefToken
* pDVR
=
6681 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
6682 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
6683 ss
<< "for (int i = ";
6684 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) {
6685 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
6686 ss
<< " && i < " << nCurWindowSize
<< "; i++){\n";
6687 } else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) {
6688 ss
<< "0; i < " << pDVR
->GetArrayLength();
6689 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++){\n";
6690 } else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()){
6691 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
6692 ss
<< " && i < "<< nCurWindowSize
<< "; i++){\n ";
6695 ss
<< "0; i < "<< nCurWindowSize
<< "; i++){\n";
6698 else if (pCur
->GetType() == formula::svSingleVectorRef
)
6700 const formula::SingleVectorRefToken
* pSVR
=
6701 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
6702 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
6704 ss
<< " if (isNan(";
6705 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
6707 ss
<< " arg"<<i
<<"= 0;\n";
6709 ss
<< " arg"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
6713 ss
<< " arg"<<i
<<"= 0;\n";
6715 else if (pCur
->GetType() == formula::svDouble
)
6717 ss
<< " if (isNan(";
6718 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
6720 ss
<< " arg"<<i
<<"= 0;\n";
6722 ss
<< " arg"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
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"
6733 " if (rxs == rxe)\n"
6734 " tmp = GetBinomDistPMF(rxs, rn, arg1);\n"
6737 " double fFactor = pow(rq, rn);\n"
6738 " if (fFactor > min)\n"
6740 " lcl_GetBinomDistRange(rn, rxs, rxe, fFactor, arg1, rq);\n"
6743 " fFactor = pow(arg1, rn);\n"
6744 " if (fFactor > min)\n"
6747 "lcl_GetBinomDistRange(rn, rn - rxe, rn - rxs, fFactor, rq, arg1);\n"
6751 "GetBetaDist(rq, rn - rxe, rxe + 1.0)"
6752 "- GetBetaDist(rq, rn - rxs + 1, rxs);\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"
6777 void OpBetaDist::BinInlineFun(std::set
<std::string
>& decls
,
6778 std::set
<std::string
>& funs
)
6780 decls
.insert(fMachEpsDecl
);decls
.insert(fMaxGammaArgumentDecl
);
6781 decls
.insert(GetBetaDistDecl
);decls
.insert(GetBetaDistPDFDecl
);
6782 decls
.insert(lcl_GetBetaHelperContFracDecl
);decls
.insert(GetLogBetaDecl
);
6783 decls
.insert(GetBetaDecl
);decls
.insert(lcl_getLanczosSumDecl
);
6784 funs
.insert(GetBetaDist
);funs
.insert(GetBetaDistPDF
);
6785 funs
.insert(lcl_GetBetaHelperContFrac
);funs
.insert(GetLogBeta
);
6786 funs
.insert(GetBeta
);funs
.insert(lcl_getLanczosSum
);
6788 void OpPoisson::BinInlineFun(std::set
<std::string
>& decls
,
6789 std::set
<std::string
>& funs
)
6791 decls
.insert(fHalfMachEpsDecl
);
6793 decls
.insert(fMaxGammaArgumentDecl
);
6795 decls
.insert(fBigInvDecl
);
6797 decls
.insert(GetLogGammaDecl
);
6798 funs
.insert(GetLogGamma
);
6799 decls
.insert(lcl_GetLogGammaHelperDecl
);
6800 funs
.insert(lcl_GetLogGammaHelper
);
6801 decls
.insert(lcl_GetGammaHelperDecl
);
6802 funs
.insert(lcl_GetGammaHelper
);
6803 decls
.insert(lcl_getLanczosSumDecl
);
6804 funs
.insert(lcl_getLanczosSum
);
6805 decls
.insert(GetUpRegIGammaDecl
);
6806 funs
.insert(GetUpRegIGamma
);
6807 decls
.insert(GetGammaContFractionDecl
);
6808 funs
.insert(GetGammaContFraction
);
6809 decls
.insert(GetGammaSeriesDecl
);
6810 funs
.insert(GetGammaSeries
);
6812 void OpPoisson::GenSlidingWindowFunction(
6813 std::stringstream
&ss
,const std::string
&sSymName
,
6814 SubArguments
&vSubArguments
)
6816 ss
<< "\ndouble " << sSymName
;
6817 ss
<< "_"<< BinFuncName() <<"(";
6818 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
6822 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
6826 ss
<< " double x,lambda,tmp,tmp0,tmp1,tmp2;\n";
6827 ss
<< " int bCumulative;\n";
6828 ss
<< " int gid0=get_global_id(0);\n";
6829 size_t i
= vSubArguments
.size();
6831 for (i
= 0; i
< vSubArguments
.size(); i
++)
6833 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
6835 if (pCur
->GetType() == formula::svSingleVectorRef
)
6837 const formula::SingleVectorRefToken
* pSVR
=
6838 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
6839 ss
<< "if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
6841 else if (pCur
->GetType() == formula::svDouble
)
6848 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
6850 ss
<< " if (isNan(";
6851 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
6853 ss
<< " tmp"<<i
<<"= 0;\n";
6855 ss
<< " tmp"<<i
<<"=\n";
6856 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
6861 ss
<< "tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
6865 ss
<< " x = floor(tmp0);\n";
6866 ss
<< " lambda = tmp1;\n";
6867 ss
<< " bCumulative = tmp2;\n ";
6868 ss
<< " if (!bCumulative)\n";
6870 ss
<< " if(lambda == 0.0)\n";
6872 ss
<< " return 0;\n";
6876 ss
<< " if (lambda >712)\n";
6878 ss
<< " tmp = (exp(x*log(lambda)-lambda-GetLogGamma(x+1.0)));\n";
6879 ss
<< " return tmp;\n";
6883 ss
<< " double fPoissonVar = 1.0;\n";
6884 ss
<< " for ( int f = 0; f < x; ++f )\n";
6885 ss
<< " fPoissonVar *= lambda * pow(( (double)f + 1.0 ),-1);\n";
6886 ss
<< " tmp = ( fPoissonVar * exp( -lambda ) );\n";
6887 ss
<< " return tmp;\n";
6893 ss
<< " if (lambda == 0.0)\n";
6895 ss
<< " return 1;\n";
6899 ss
<< " if (lambda > 712 )\n";
6901 ss
<< " tmp = (GetUpRegIGamma(x+1.0,lambda));\n";
6902 ss
<< " return tmp;\n";
6906 ss
<< " if (x >= 936.0)\n";
6908 ss
<< " return 1;\n";
6912 ss
<< " double fSummand = exp(-lambda);\n";
6913 ss
<< " double fSum = fSummand;\n";
6914 ss
<< " int nEnd = (int) (x + 0.5);\n";
6915 ss
<< " for (int i = 1; i <= nEnd; i++)\n";
6917 ss
<< " fSummand = (fSummand*lambda)*pow((double)i,-1);\n";
6918 ss
<< " fSum += fSummand;\n";
6920 ss
<< " tmp = fSum;\n";
6921 ss
<< " return tmp;\n";
6928 void OpCovar::GenSlidingWindowFunction(std::stringstream
& ss
,
6929 const std::string
&sSymName
, SubArguments
& vSubArguments
)
6931 ss
<< "\ndouble " << sSymName
;
6932 ss
<< "_"<< BinFuncName() <<"(";
6933 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
6937 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
6940 ss
<< " int gid0 = get_global_id(0);\n";
6941 ss
<< " double vSum = 0.0;\n";
6942 ss
<< " double vSum0 = 0.0;\n";
6943 ss
<< " double vSum1 = 0.0;\n";
6944 ss
<< " double vMean0 = 0.0;\n";
6945 ss
<< " double vMean1 = 0.0;\n";
6946 ss
<< " double arg0 = 0.0;\n";
6947 ss
<< " double arg1 = 0.0;\n";
6948 FormulaToken
* pCurX
= vSubArguments
[0]->GetFormulaToken();
6949 FormulaToken
* pCurY
= vSubArguments
[1]->GetFormulaToken();
6950 if ((pCurX
->GetType() == formula::svDoubleVectorRef
)&&
6951 (pCurY
->GetType() == formula::svDoubleVectorRef
)){
6952 ss
<< " int cnt = 0;\n";
6953 const formula::DoubleVectorRefToken
* pCurDVRX
=
6954 static_cast<const formula::DoubleVectorRefToken
* >(pCurX
);
6955 const formula::DoubleVectorRefToken
* pCurDVRY
=
6956 static_cast<const formula::DoubleVectorRefToken
* >(pCurY
);
6957 size_t nCurWindowSizeX
= pCurDVRX
->GetRefRowSize();
6958 size_t nCurWindowSizeY
= pCurDVRY
->GetRefRowSize();
6959 if(nCurWindowSizeX
== nCurWindowSizeY
)
6962 if (!pCurDVRX
->IsStartFixed() && pCurDVRX
->IsEndFixed()) {
6963 ss
<< "int i = gid0; i < " << nCurWindowSizeX
;
6964 ss
<< " && i < " << pCurDVRX
->GetArrayLength() << " && i < ";
6965 ss
<< pCurDVRY
->GetArrayLength() << "; i++){\n";
6967 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ") ||";
6968 ss
<< " isNan("<< vSubArguments
[1]->GenSlidingWindowDeclRef();
6970 ss
<< " arg0 = 0.0;\n";
6971 ss
<< " arg1 = 0.0;\n";
6976 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
6978 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
6981 ss
<< " vSum0 += arg0;\n";
6982 ss
<< " vSum1 += arg1;\n";
6985 else if (pCurDVRX
->IsStartFixed() && !pCurDVRX
->IsEndFixed()) {
6986 ss
<< "int i = 0; i < gid0 + " << nCurWindowSizeX
<< " && ";
6987 ss
<< " i < " << pCurDVRX
->GetArrayLength() << " && ";
6988 ss
<< " i < " << pCurDVRY
->GetArrayLength() << "; i++) {\n";
6990 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ") ||";
6991 ss
<< " isNan(" << vSubArguments
[1]->GenSlidingWindowDeclRef();
6993 ss
<< " arg0 = 0.0;\n";
6994 ss
<< " arg1 = 0.0;\n";
6999 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
7001 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";}\n";
7003 ss
<< " vSum0 += arg0;\n";
7004 ss
<< " vSum1 += arg1;\n";
7007 else if (pCurDVRX
->IsStartFixed() && pCurDVRX
->IsEndFixed()) {
7008 ss
<< "int i = 0; i < " << nCurWindowSizeX
<< " && i < ";
7009 ss
<< pCurDVRX
->GetArrayLength() << " && i < ";
7010 ss
<< pCurDVRY
->GetArrayLength() << "; i++) {\n";
7012 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ") ||";
7013 ss
<< " isNan(" << vSubArguments
[1]->GenSlidingWindowDeclRef();
7015 ss
<< " arg0 = 0.0;\n";
7016 ss
<< " arg1 = 0.0;\n";
7021 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
7023 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";}\n";
7025 ss
<< " vSum0 += arg0;\n";
7026 ss
<< " vSum1 += arg1;\n";
7030 ss
<< "int i = 0; i < " << nCurWindowSizeX
<< " && ";
7031 ss
<< " i + gid0 < " << pCurDVRX
->GetArrayLength();
7032 ss
<< " && i + gid0 < " << pCurDVRX
->GetArrayLength();
7034 ss
<< "if ((isNan(";
7035 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ")) || ";
7036 ss
<< "(isNan("<< vSubArguments
[1]->GenSlidingWindowDeclRef();
7038 ss
<< " arg0 = 0.0;\n";
7039 ss
<< " arg1 = 0.0;\n";
7044 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
7046 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
7049 ss
<< " vSum0 += arg0;\n";
7050 ss
<< " vSum1 += arg1;\n";
7053 ss
<< " if(cnt < 1) {\n";
7054 ss
<< " return CreateDoubleError(errNoValue);\n";
7057 ss
<< " vMean0 = vSum0 / cnt;\n";
7058 ss
<< " vMean1 = vSum1 / cnt;\n";
7060 if (!pCurDVRX
->IsStartFixed() && pCurDVRX
->IsEndFixed()) {
7061 ss
<< "int i = gid0; i < " << nCurWindowSizeX
;
7062 ss
<< " && i < " << pCurDVRX
->GetArrayLength() << " && i < ";
7063 ss
<< pCurDVRY
->GetArrayLength() << "; i++){\n";
7065 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ") ||";
7066 ss
<< " isNan(" << vSubArguments
[1]->GenSlidingWindowDeclRef();
7068 ss
<< " arg0 = vMean0;\n";
7069 ss
<< " arg1 = vMean1;\n";
7073 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
7075 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";}\n";
7076 ss
<< " vSum += (arg0 - vMean0) * (arg1 - vMean1);\n";
7079 else if (pCurDVRX
->IsStartFixed() && !pCurDVRX
->IsEndFixed()) {
7080 ss
<< "int i = 0; i < gid0 + " << nCurWindowSizeX
<< " && ";
7081 ss
<< " i < " << pCurDVRX
->GetArrayLength() << " && ";
7082 ss
<< " i < " << pCurDVRY
->GetArrayLength() << "; i++) {\n";
7084 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ") || ";
7085 ss
<< "isNan(" << vSubArguments
[1]->GenSlidingWindowDeclRef();
7087 ss
<< " arg0 = vMean0;\n";
7088 ss
<< " arg1 = vMean1;\n";
7092 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
7094 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";}\n";
7095 ss
<< " vSum += (arg0 - vMean0) * (arg1 - vMean1);\n";
7098 else if (pCurDVRX
->IsStartFixed() && pCurDVRX
->IsEndFixed()) {
7099 ss
<< "int i = 0; i < " << nCurWindowSizeX
<< " && i < ";
7100 ss
<< pCurDVRX
->GetArrayLength() << " && i < ";
7101 ss
<< pCurDVRY
->GetArrayLength() << "; i++) {\n";
7103 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ") || ";
7104 ss
<< "isNan(" << vSubArguments
[1]->GenSlidingWindowDeclRef();
7106 ss
<< " arg0 = vMean0;\n";
7107 ss
<< " arg1 = vMean1;\n";
7111 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
7113 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";}\n";
7114 ss
<< " vSum += (arg0 - vMean0) * (arg1 - vMean1);\n";
7118 ss
<< "int i = 0; i < " << nCurWindowSizeX
<< " && ";
7119 ss
<< " i + gid0 < " << pCurDVRX
->GetArrayLength();
7120 ss
<< " && i + gid0 < " << pCurDVRX
->GetArrayLength();
7123 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ")) || ";
7124 ss
<< "(isNan(" << vSubArguments
[1]->GenSlidingWindowDeclRef();
7126 ss
<< " arg0 = vMean0;\n";
7127 ss
<< " arg1 = vMean1;\n";
7131 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
7133 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
7135 ss
<< " vSum += (arg0 - vMean0) * (arg1 - vMean1);\n";
7138 ss
<< " return vSum / cnt;\n";
7144 ss
<< " int cnt0 = 0,cnt1 = 0;\n";
7145 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
7147 FormulaToken
* pCur
= vSubArguments
[i
]->GetFormulaToken();
7148 if (pCur
->GetType() == formula::svSingleVectorRef
){
7149 const formula::SingleVectorRefToken
* pTVR
=
7150 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
7152 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
7153 ss
<< ") || gid0 >= " << pTVR
->GetArrayLength() << ")\n";
7154 ss
<< " arg" << i
<< " = 0;\n else\n";
7155 ss
<< " arg" << i
<< " = ";
7156 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
7157 ss
<< " cnt" << i
<< "++;\n";
7158 ss
<< " vSum" << i
<< " += arg" << i
<< ";\n";
7160 else if (pCur
->GetType() == formula::svDouble
){
7161 ss
<< " if(isNan ( ";
7162 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << "))\n";
7163 ss
<< " arg" << i
<< " = 0;\n else\n";
7164 ss
<< " arg" << i
<< " = ";
7165 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
7166 ss
<< " cnt" << i
<< "++;\n";
7167 ss
<< " vSum" << i
<< " += arg" << i
<< ";\n";
7170 ss
<< " arg" << i
<< " = ";
7171 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
7172 ss
<< " cnt" << i
<< "++;\n";
7173 ss
<< " vSum" << i
<< " += arg" << i
<< ";\n";
7176 ss
<< " vMean0 = vSum0 / cnt0;\n";
7177 ss
<< " vMean1 = vSum0 / cnt1;\n";
7178 for(unsigned i
= 0; i
< vSubArguments
.size(); i
++ ) {
7179 FormulaToken
* pCur
= vSubArguments
[i
]->GetFormulaToken();
7180 if (pCur
->GetType() == formula::svSingleVectorRef
) {
7181 const formula::SingleVectorRefToken
* pTVR
=
7182 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
7184 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
7185 ss
<< ") || gid0 >= " << pTVR
->GetArrayLength() << ")\n";
7186 ss
<< " arg" << i
<< " = vMean" << i
<< ";\n";
7188 ss
<< " arg" << i
<< " = ";
7189 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
7191 else if (pCur
->GetType() == formula::svDouble
) {
7192 ss
<< " arg" << i
<< " = ";
7193 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
7194 ss
<< " if(isNan(arg" << i
<< "))\n";
7195 ss
<< " arg" << i
<< " = vMean" << i
<< ";\n";
7198 ss
<< " arg" << i
<< " = ";
7199 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
7202 ss
<< " vSum += (arg0 - vMean0) * ( arg1 - vMean1 );\n";
7203 ss
<< " return vSum / cnt0;\n";
7207 void OpBetaDist::GenSlidingWindowFunction(std::stringstream
&ss
,
7208 const std::string
&sSymName
, SubArguments
&vSubArguments
)
7210 ss
<< "\ndouble " << sSymName
;
7211 ss
<< "_"<< BinFuncName() <<"(";
7212 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
7216 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
7219 ss
<< " int gid0=get_global_id(0);\n";
7220 ss
<< " double tmp;\n";
7221 ss
<< " double arg0,arg1,arg2,arg3,arg4,arg5;\n";
7222 size_t i
= vSubArguments
.size();
7224 for (i
= 0; i
< vSubArguments
.size(); i
++)
7226 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
7228 if (pCur
->GetType() == formula::svDoubleVectorRef
)
7230 const formula::DoubleVectorRefToken
* pDVR
=
7231 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
7232 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
7233 ss
<< "for (int i = ";
7234 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) {
7235 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
7236 ss
<< " && i < " << nCurWindowSize
<< "; i++){\n";
7237 } else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) {
7238 ss
<< "0; i < " << pDVR
->GetArrayLength();
7239 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++){\n";
7240 } else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()){
7241 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
7242 ss
<< " && i < "<< nCurWindowSize
<< "; i++){\n ";
7245 ss
<< "0; i < "<< nCurWindowSize
<< "; i++){\n";
7249 else if (pCur
->GetType() == formula::svSingleVectorRef
)
7251 const formula::SingleVectorRefToken
* pSVR
=
7252 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
7253 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
7255 ss
<< " if (isNan(";
7256 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
7258 ss
<< " arg"<<i
<<"= 0;\n";
7260 ss
<< " arg"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
7264 ss
<< " arg"<<i
<<"= 0;\n";
7266 else if (pCur
->GetType() == formula::svDouble
)
7268 ss
<< " if (isNan(";
7269 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
7271 ss
<< " arg"<<i
<<"= 0;\n";
7273 ss
<< " arg"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
7277 ss
<< " double fScale = arg4 - arg3;\n"
7278 " if (fScale <= 0.0 || arg1 <= 0.0 || arg2 <= 0.0)\n"
7285 " if (arg0< arg3)\n"
7290 " if (arg0 > arg4)\n"
7295 " arg0 = (arg0-arg3)*pow(fScale,-1);\n"
7296 " tmp = GetBetaDist(arg0, arg1, arg2);\n"
7300 " if (arg0 < arg3 || arg0 > arg4 )\n"
7305 " arg0 = (arg0 - arg3)*pow(fScale,-1);\n"
7306 " tmp = GetBetaDistPDF(arg0, arg1, arg2)*pow(fScale,-1);\n"
7308 ss
<< " return tmp;\n";
7311 void OpBetainv::BinInlineFun(std::set
<std::string
>& decls
,
7312 std::set
<std::string
>& funs
)
7314 decls
.insert(fMachEpsDecl
);
7316 decls
.insert(fMaxGammaArgumentDecl
);
7318 decls
.insert(lcl_IterateInverseBetaInvDecl
);
7319 funs
.insert(lcl_IterateInverseBetaInv
);
7320 decls
.insert(GetBetaDistDecl
);
7321 funs
.insert(GetBetaDist
);
7322 decls
.insert(lcl_HasChangeOfSignDecl
);
7323 funs
.insert(lcl_HasChangeOfSign
);
7324 decls
.insert(lcl_HasChangeOfSignDecl
);
7325 funs
.insert(lcl_HasChangeOfSign
);
7326 decls
.insert(lcl_HasChangeOfSignDecl
);
7327 funs
.insert(lcl_HasChangeOfSign
);
7328 decls
.insert(lcl_GetBetaHelperContFracDecl
);
7329 funs
.insert(lcl_GetBetaHelperContFrac
);
7330 decls
.insert(GetBetaDistPDFDecl
);
7331 funs
.insert(GetBetaDistPDF
);
7332 decls
.insert(GetLogBetaDecl
);
7333 funs
.insert(GetLogBeta
);
7334 decls
.insert(GetBetaDecl
);
7335 funs
.insert(GetBeta
);
7336 decls
.insert(lcl_getLanczosSumDecl
);
7337 funs
.insert(lcl_getLanczosSum
);
7339 void OpBetainv::GenSlidingWindowFunction(
7340 std::stringstream
&ss
,const std::string
&sSymName
,
7341 SubArguments
&vSubArguments
)
7343 ss
<< "\ndouble " << sSymName
;
7344 ss
<< "_"<< BinFuncName() <<"(";
7345 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
7349 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
7353 ss
<< " double tmp0,tmp1,tmp2,tmp3,tmp4;\n";
7354 ss
<< " int gid0=get_global_id(0);\n";
7355 size_t i
= vSubArguments
.size();
7358 for (i
= 0; i
< vSubArguments
.size(); i
++)
7360 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
7362 if (pCur
->GetType() == formula::svDoubleVectorRef
)
7364 const formula::DoubleVectorRefToken
* pDVR
=
7365 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
7366 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
7367 ss
<< "for (int i = ";
7368 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) {
7369 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
7370 ss
<< " && i < " << nCurWindowSize
<< "; i++){\n";
7371 } else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) {
7372 ss
<< "0; i < " << pDVR
->GetArrayLength();
7373 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++){\n";
7374 } else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()){
7375 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
7376 ss
<< " && i < "<< nCurWindowSize
<< "; i++){\n";
7379 ss
<< "0; i < "<< nCurWindowSize
<< "; i++){\n";
7382 else if (pCur
->GetType() == formula::svSingleVectorRef
)
7384 const formula::SingleVectorRefToken
* pSVR
=
7385 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
7386 ss
<< "if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
7388 else if (pCur
->GetType() == formula::svDouble
)
7396 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
7398 ss
<< " if (isNan(";
7399 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
7401 ss
<< " tmp"<<i
<<"= 0;\n";
7403 ss
<< " tmp"<<i
<<"=\n";
7404 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
7409 ss
<< "tmp"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
7413 ss
<< " if (tmp0 < 0.0 || tmp0 >= 1.0 ||";
7414 ss
<< "tmp3 == tmp4 || tmp1 <= 0.0 || tmp2 <= 0.0)\n";
7416 ss
<< " return DBL_MIN;\n";
7418 ss
<< " if (tmp0 == 0.0)\n";
7419 ss
<< " return 0.0;\n";
7422 ss
<< " bool bConvError;";
7423 ss
<< " double fVal = lcl_IterateInverseBetaInv";
7424 ss
<< "(tmp0, tmp1, tmp2, 0.0, 1.0, &bConvError);\n";
7425 ss
<< " if(bConvError)\n";
7426 ss
<< " return DBL_MIN;\n";
7428 ss
<< " return (tmp3 + fVal*(tmp4 - tmp3));\n";
7432 void OpDevSq::GenSlidingWindowFunction(std::stringstream
& ss
,
7433 const std::string
&sSymName
, SubArguments
& vSubArguments
)
7435 ss
<< "\ndouble " << sSymName
;
7436 ss
<< "_"<< BinFuncName() <<"(";
7437 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
7441 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
7444 ss
<< " int gid0 = get_global_id(0);\n";
7445 ss
<< " double vSum = 0.0;\n";
7446 ss
<< " double vMean = 0.0;\n";
7447 ss
<< " int cnt = 0;\n";
7448 for(unsigned i
= 0; i
< vSubArguments
.size(); i
++ )
7450 ss
<< " double arg" << i
<< " = 0.0;\n";
7451 FormulaToken
* pCur
= vSubArguments
[i
]->GetFormulaToken();
7452 if (pCur
->GetType() == formula::svDoubleVectorRef
)
7454 const formula::DoubleVectorRefToken
* pCurDVR
=
7455 static_cast<const formula::DoubleVectorRefToken
* >(pCur
);
7456 size_t nCurWindowSize
= pCurDVR
->GetRefRowSize();
7457 ss
<< " for(int i = ";
7458 if (!pCurDVR
->IsStartFixed() && pCurDVR
->IsEndFixed()) {
7459 ss
<< "gid0; i < " << nCurWindowSize
<< "; i++) {\n";
7460 ss
<< " arg" << i
<< " = ";
7461 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
7462 ss
<< " if(isNan(arg" << i
<< ") || (i >= ";
7463 ss
<< pCurDVR
->GetArrayLength() << ")) {\n";
7464 ss
<< " arg" << i
<< " = 0.0;\n";
7468 ss
<< " vSum += arg" << i
<< ";\n";
7470 } else if (pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed()) {
7471 ss
<< "0; i < gid0 + " << nCurWindowSize
<< "; i++) {\n";
7472 ss
<< " arg" << i
<< " = ";
7473 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
7474 ss
<< " if(isNan(arg" << i
<< ") || (i >= ";
7475 ss
<< pCurDVR
->GetArrayLength() << ")) {\n";
7476 ss
<< " arg" << i
<< " = 0.0;\n";
7480 ss
<< " vSum += arg" << i
<< ";\n";
7482 } else if (pCurDVR
->IsStartFixed() && pCurDVR
->IsEndFixed()) {
7483 ss
<< "0; i < " << nCurWindowSize
<< "; i++) {\n";
7484 ss
<< " arg" << i
<< " = ";
7485 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
7486 ss
<< " if(isNan(arg" << i
<< ") || (i >= ";
7487 ss
<< pCurDVR
->GetArrayLength() << ")) {\n";
7488 ss
<< " arg" << i
<< " = 0.0;\n";
7492 ss
<< " vSum += arg" << i
<< ";\n";
7495 ss
<< "0; i < " << nCurWindowSize
<< "; i++) {\n";
7496 ss
<< " arg" << i
<< " = ";
7497 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
7498 ss
<< " if(isNan(arg" << i
<< ") || (i + gid0 >= ";
7499 ss
<< pCurDVR
->GetArrayLength() << ")) {\n";
7500 ss
<< " arg" << i
<< " = 0.0;\n";
7504 ss
<< " vSum += arg" << i
<< ";\n";
7508 else if (pCur
->GetType() == formula::svSingleVectorRef
)
7510 const formula::SingleVectorRefToken
* pTVR
=
7511 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
7513 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
7514 ss
<< ") || gid0 >= " << pTVR
->GetArrayLength() << ")\n";
7515 ss
<< " arg" << i
<< " = 0;\n else\n";
7516 ss
<< " arg" << i
<< " = ";
7517 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
7519 ss
<< " vSum += arg" << i
<< ";\n";
7521 else if (pCur
->GetType() == formula::svDouble
)
7523 ss
<< " if(isNan ( ";
7524 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << "))\n";
7525 ss
<< " arg" << i
<< " = 0;\n else\n";
7526 ss
<< " arg" << i
<< " = ";
7527 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
7529 ss
<< " vSum += arg" << i
<< ";\n";
7533 ss
<< " arg" << i
<< " = ";
7534 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
7536 ss
<< " vSum += arg" << i
<< ";\n";
7539 ss
<< " vMean = vSum / cnt;\n";
7540 ss
<< " vSum = 0.0;\n";
7541 for(unsigned k
= 0; k
< vSubArguments
.size(); k
++ )
7543 FormulaToken
* pCur
= vSubArguments
[k
]->GetFormulaToken();
7544 if (pCur
->GetType() == formula::svDoubleVectorRef
)
7546 const formula::DoubleVectorRefToken
* pCurDVR
=
7547 static_cast<const formula::DoubleVectorRefToken
* >(pCur
);
7548 size_t nCurWindowSize
= pCurDVR
->GetRefRowSize();
7549 ss
<< " for(int i = ";
7550 if (!pCurDVR
->IsStartFixed() && pCurDVR
->IsEndFixed()) {
7551 ss
<< "gid0; i < " << nCurWindowSize
<< "; i++) {\n";
7552 ss
<< " arg" << k
<< " = ";
7553 ss
<< vSubArguments
[k
]->GenSlidingWindowDeclRef() << ";\n";
7554 ss
<< " if(isNan( arg" << k
<< " ) || (i >= ";
7555 ss
<< pCurDVR
->GetArrayLength() << ")) {\n";
7556 ss
<< " arg" << k
<< " = vXMean;\n";
7558 ss
<< " vSum += pow( arg" << k
<< " - vMean, 2 );\n";
7560 } else if (pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed()) {
7561 ss
<< "0; i < gid0 + " << nCurWindowSize
<< "; i++) {\n";
7562 ss
<< " arg" << k
<< " = ";
7563 ss
<< vSubArguments
[k
]->GenSlidingWindowDeclRef() << ";\n";
7564 ss
<< " if(isNan( arg" << k
<< ") || (i >= ";
7565 ss
<< pCurDVR
->GetArrayLength() << ")) {\n";
7566 ss
<< " arg" << k
<< " = vMean;\n";
7568 ss
<< " vSum += pow( arg" << k
<< " - vMean, 2 );\n";
7570 } else if (pCurDVR
->IsStartFixed() && pCurDVR
->IsEndFixed()) {
7571 ss
<< "0; i < " << nCurWindowSize
<< "; i++) {\n";
7572 ss
<< " arg" << k
<< " = ";
7573 ss
<< vSubArguments
[k
]->GenSlidingWindowDeclRef() << ";\n";
7574 ss
<< " if(isNan(arg" << k
<< ") || (i >= ";
7575 ss
<< pCurDVR
->GetArrayLength() << ")) {\n";
7576 ss
<< " arg" << k
<< " = vMean;\n";
7578 ss
<< " vSum += pow( arg" << k
<< " - vMean, 2 );\n";
7581 ss
<< "0; i < " << nCurWindowSize
<< "; i++) {\n";
7582 ss
<< " arg" << k
<< " = ";
7583 ss
<< vSubArguments
[k
]->GenSlidingWindowDeclRef() << ";\n";
7584 ss
<< " if(isNan(arg" << k
<< ") || (i + gid0 >= ";
7585 ss
<< pCurDVR
->GetArrayLength() << ")) {\n";
7586 ss
<< " arg" << k
<< " = vMean;\n";
7588 ss
<< " vSum += pow( arg" << k
<< " - vMean, 2 );\n";
7592 else if (pCur
->GetType() == formula::svSingleVectorRef
)
7594 const formula::SingleVectorRefToken
* pTVR
=
7595 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
7597 ss
<< vSubArguments
[k
]->GenSlidingWindowDeclRef();
7598 ss
<< ") || gid0 >= " << pTVR
->GetArrayLength() << ")\n";
7599 ss
<< " arg" << k
<< " = vMean;\n else\n";
7600 ss
<< " arg" << k
<< " = ";
7601 ss
<< vSubArguments
[k
]->GenSlidingWindowDeclRef()<<";\n";
7602 ss
<< " vSum += pow( arg" << k
<< " - vMean, 2 );\n";
7604 else if (pCur
->GetType() == formula::svDouble
)
7606 ss
<< " arg" << k
<< " = ";
7607 ss
<< vSubArguments
[k
]->GenSlidingWindowDeclRef() << ";\n";
7608 ss
<< " if(isNan(arg" << k
<< "))\n";
7609 ss
<< " arg" << k
<< " = vMean;\n";
7610 ss
<< " vSum += pow( arg" << k
<< " - vMean, 2 );\n";
7614 ss
<< " arg" << k
<< " = ";
7615 ss
<< vSubArguments
[k
]->GenSlidingWindowDeclRef() << ";\n";
7616 ss
<< " vSum += pow( arg" << k
<< " - vMean, 2 );\n";
7619 ss
<< " return vSum;\n";
7622 void OpHypGeomDist::GenSlidingWindowFunction(std::stringstream
&ss
,
7623 const std::string
&sSymName
, SubArguments
&vSubArguments
)
7625 ss
<< "\ndouble " << sSymName
;
7626 ss
<< "_"<< BinFuncName() <<"(";
7627 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
7631 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
7634 ss
<< " int gid0=get_global_id(0);\n";
7635 ss
<< " double arg0,arg1,arg2,arg3;\n";
7636 size_t i
= vSubArguments
.size();
7638 for (i
= 0; i
< vSubArguments
.size(); i
++)
7640 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
7642 if (pCur
->GetType() == formula::svDoubleVectorRef
)
7644 const formula::DoubleVectorRefToken
* pDVR
=
7645 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
7646 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
7647 ss
<< "for (int i = ";
7648 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) {
7649 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
7650 ss
<< " && i < " << nCurWindowSize
<< "; i++){\n";
7651 } else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) {
7652 ss
<< "0; i < " << pDVR
->GetArrayLength();
7653 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++){\n";
7654 } else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()){
7655 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
7656 ss
<< " && i < "<< nCurWindowSize
<< "; i++){\n ";
7659 ss
<< "0; i < "<< nCurWindowSize
<< "; i++){\n";
7662 else if (pCur
->GetType() == formula::svSingleVectorRef
)
7664 const formula::SingleVectorRefToken
* pSVR
=
7665 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
7666 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
7668 ss
<< " if (isNan(";
7669 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
7671 ss
<< " arg"<<i
<<"= 0;\n";
7673 ss
<< " arg"<<i
<<"=";
7674 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
7678 ss
<< " arg"<<i
<<"= 0;\n";
7680 else if (pCur
->GetType() == formula::svDouble
)
7682 ss
<< " if (isNan(";
7683 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
7685 ss
<< " arg"<<i
<<"= 0;\n";
7687 ss
<< " arg"<<i
<<"=";
7688 ss
<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
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"
7697 " double PI = 3.1415926535897932384626433832795;\n"
7699 " if( (x1 < 0.0) || (n1 < x1) || (M1 < x1) || (N1 < n1) ||"
7700 "(N1 < M1) || (x1 < n1 - N1 + M1) )\n"
7710 " num[5]=N1-M1-n1+x1;\n"
7714 " for(int i=0;i<9;i++)\n"
7721 " num[i]=log(tgamma(num[i])*num[i]);\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"
7727 ss
<< " tmp=pow(M_E,(num[0]+num[3]+num[7]+num[8]";
7728 ss
<< "-num[1]-num[2]-num[4]-num[5]-num[6]));\n";
7729 ss
<< " return tmp;\n";
7733 enum MixDoubleString
7735 svDoubleVectorRefDoubleString
,
7736 svDoubleVectorRefDouble
,
7737 svDoubleVectorRefString
,
7738 svDoubleVectorRefNULL
,
7739 svSingleVectorRefDoubleString
,
7740 svSingleVectorRefDouble
,
7741 svSingleVectorRefString
,
7742 svSingleVectorRefNULL
,
7746 void OpMinA::GenSlidingWindowFunction(
7747 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&vSubArguments
)
7750 ss
<< "\ndouble " << sSymName
;
7751 ss
<< "_"<< BinFuncName() <<"(";
7752 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
7756 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
7760 ss
<< " int gid0=get_global_id(0);\n";
7761 ss
<< " double tmp0 = 1.79769e+308;\n";
7762 size_t i
= vSubArguments
.size();
7764 for (i
= 0; i
< vSubArguments
.size(); i
++)
7766 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
7768 if (pCur
->GetType() == formula::svDoubleVectorRef
)
7770 const formula::DoubleVectorRefToken
* pDVR
=
7771 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
7772 if(pDVR
->GetArrays()[0].mpNumericArray
7773 && pDVR
->GetArrays()[0].mpStringArray
)
7774 isMixed
= svDoubleVectorRefDoubleString
;
7775 else if(pDVR
->GetArrays()[0].mpNumericArray
)
7776 isMixed
= svDoubleVectorRefDouble
;
7777 else if(pDVR
->GetArrays()[0].mpStringArray
)
7778 isMixed
= svDoubleVectorRefString
;
7780 isMixed
= svDoubleVectorRefNULL
;
7781 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
7782 ss
<< " for (int i = ";
7783 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) {
7784 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
7785 ss
<< " && i < " << nCurWindowSize
<< "; i++){\n";
7786 } else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) {
7787 ss
<< "0; i < " << pDVR
->GetArrayLength();
7788 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++){\n";
7789 } else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()){
7790 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
7791 ss
<< " && i < "<< nCurWindowSize
<< "; i++){\n";
7794 ss
<< "0; i < "<< nCurWindowSize
<< "; i++){\n";
7797 else if (pCur
->GetType() == formula::svSingleVectorRef
)
7799 const formula::SingleVectorRefToken
* pSVR
=
7800 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
7802 if(pSVR
->GetArray().mpNumericArray
7803 && pSVR
->GetArray().mpStringArray
)
7804 isMixed
= svSingleVectorRefDoubleString
;
7805 else if(pSVR
->GetArray().mpNumericArray
)
7806 isMixed
= svSingleVectorRefDouble
;
7807 else if(pSVR
->GetArray().mpStringArray
)
7808 isMixed
= svSingleVectorRefString
;
7810 isMixed
= svSingleVectorRefNULL
;
7811 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
7813 else if (pCur
->GetType() == formula::svDouble
)
7816 isMixed
= svDoubleDouble
;
7822 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
7824 if(isMixed
== svDoubleVectorRefDoubleString
7825 || isMixed
== svSingleVectorRefDoubleString
)
7827 ss
<< " if (!isNan(";
7828 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
7830 ss
<< " tmp0 = tmp0 > ";
7831 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
7833 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
7835 ss
<< " else if(isNan(";
7836 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
7838 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
7840 ss
<< " tmp0 = tmp0 > 0.0 ? 0.0 : tmp0;\n";
7843 else if(isMixed
== svDoubleVectorRefDouble
7844 || isMixed
== svSingleVectorRefDouble
)
7846 ss
<< " if (!isNan(";
7847 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
7849 ss
<< " tmp0 = tmp0 > ";
7850 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
7851 ss
<< " ? " << vSubArguments
[i
]->GenSlidingWindowDeclRef();
7855 else if(isMixed
== svDoubleVectorRefString
)
7858 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
7859 ss
<< " == 0)\n continue;\n";
7860 ss
<< " tmp0 = tmp0 > 0.0 ? 0.0 : tmp0;\n";
7863 else if(isMixed
== svSingleVectorRefString
)
7866 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
7868 ss
<< " tmp0 = tmp0 > 0.0 ? 0.0 : tmp0;\n";
7871 else if(isMixed
== svDoubleDouble
)
7873 ss
<< " tmp0 = tmp0 > ";
7874 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
7875 ss
<< " ? " << vSubArguments
[i
]->GenSlidingWindowDeclRef();
7876 ss
<< " : tmp0;\n }\n";
7885 ss
<< " tmp0 = tmp0 > ";
7886 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
7887 ss
<< " ? " << vSubArguments
[i
]->GenSlidingWindowDeclRef();
7892 ss
<< " return tmp0 == 1.79769e+308 ? 0.0 : tmp0;\n";
7895 void OpCountA::GenSlidingWindowFunction(
7896 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&
7900 ss
<< "\ndouble " << sSymName
;
7901 ss
<< "_"<< BinFuncName() <<"(";
7902 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
7906 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
7910 ss
<< " int gid0=get_global_id(0);\n";
7911 ss
<< " double nCount = 0.0;\n";
7912 size_t i
= vSubArguments
.size();
7915 for (i
= 0; i
< vSubArguments
.size(); i
++)
7917 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
7919 if (pCur
->GetType() == formula::svDoubleVectorRef
)
7921 const formula::DoubleVectorRefToken
* pDVR
=
7922 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
7923 if(pDVR
->GetArrays()[0].mpNumericArray
7924 && pDVR
->GetArrays()[0].mpStringArray
)
7925 isMixed
= svDoubleVectorRefDoubleString
;
7926 else if(pDVR
->GetArrays()[0].mpNumericArray
)
7927 isMixed
= svDoubleVectorRefDouble
;
7928 else if(pDVR
->GetArrays()[0].mpStringArray
)
7929 isMixed
= svDoubleVectorRefString
;
7931 isMixed
= svDoubleVectorRefNULL
;
7932 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
7933 ss
<< " for (int i = ";
7934 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) {
7935 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
7936 ss
<< " && i < " << nCurWindowSize
<< "; i++){\n";
7937 } else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) {
7938 ss
<< "0; i < " << pDVR
->GetArrayLength();
7939 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++){\n";
7940 } else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()){
7941 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
7942 ss
<< " && i < "<< nCurWindowSize
<< "; i++){\n";
7945 ss
<< "0; i < "<< nCurWindowSize
<< "; i++){\n";
7948 else if (pCur
->GetType() == formula::svSingleVectorRef
)
7950 const formula::SingleVectorRefToken
* pSVR
=
7951 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
7953 if(pSVR
->GetArray().mpNumericArray
7954 && pSVR
->GetArray().mpStringArray
)
7955 isMixed
= svSingleVectorRefDoubleString
;
7956 else if(pSVR
->GetArray().mpNumericArray
)
7957 isMixed
= svSingleVectorRefDouble
;
7958 else if(pSVR
->GetArray().mpStringArray
)
7959 isMixed
= svSingleVectorRefString
;
7961 isMixed
= svSingleVectorRefNULL
;
7962 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
7964 else if (pCur
->GetType() == formula::svDouble
)
7967 isMixed
= svDoubleDouble
;
7973 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
7975 if(isMixed
== svDoubleVectorRefDoubleString
7976 || isMixed
== svSingleVectorRefDoubleString
)
7978 ss
<< " if (!isNan(";
7979 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
7981 ss
<< " nCount+=1.0;\n";
7983 ss
<< " else if(isNan(";
7984 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
7986 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
7988 ss
<< " nCount+=1.0;\n";
7991 else if(isMixed
== svDoubleVectorRefDouble
7992 || isMixed
== svSingleVectorRefDouble
)
7994 ss
<< " if (!isNan(";
7995 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
7997 ss
<< " nCount+=1.0;\n";
8000 else if(isMixed
== svDoubleVectorRefString
)
8002 ss
<< " if (!isNan(";
8003 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
8005 ss
<< " nCount+=1.0;\n";
8008 else if(isMixed
== svSingleVectorRefString
)
8011 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
8013 ss
<< " nCount+=1.0;\n";
8016 else if(isMixed
== svDoubleDouble
)
8018 ss
<< " nCount+=1.0;\n";
8028 ss
<< " nCount+=1.0;\n";
8032 ss
<< " return nCount;\n";
8035 void OpMaxA::GenSlidingWindowFunction(
8036 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&
8040 ss
<< "\ndouble " << sSymName
;
8041 ss
<< "_"<< BinFuncName() <<"(";
8042 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
8046 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
8050 ss
<< " int gid0=get_global_id(0);\n";
8051 ss
<< " double tmp0 = 2.22507e-308;\n";
8052 size_t i
= vSubArguments
.size();
8055 for (i
= 0; i
< vSubArguments
.size(); i
++)
8057 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
8059 if (pCur
->GetType() == formula::svDoubleVectorRef
)
8061 const formula::DoubleVectorRefToken
* pDVR
=
8062 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
8063 if(pDVR
->GetArrays()[0].mpNumericArray
8064 && pDVR
->GetArrays()[0].mpStringArray
)
8065 isMixed
= svDoubleVectorRefDoubleString
;
8066 else if(pDVR
->GetArrays()[0].mpNumericArray
)
8067 isMixed
= svDoubleVectorRefDouble
;
8068 else if(pDVR
->GetArrays()[0].mpStringArray
)
8069 isMixed
= svDoubleVectorRefString
;
8071 isMixed
= svDoubleVectorRefNULL
;
8072 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
8073 ss
<< " for (int i = ";
8074 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) {
8075 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
8076 ss
<< " && i < " << nCurWindowSize
<< "; i++){\n";
8077 } else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) {
8078 ss
<< "0; i < " << pDVR
->GetArrayLength();
8079 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++){\n";
8080 } else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()){
8081 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
8082 ss
<< " && i < "<< nCurWindowSize
<< "; i++){\n";
8085 ss
<< "0; i < "<< nCurWindowSize
<< "; i++){\n";
8088 else if (pCur
->GetType() == formula::svSingleVectorRef
)
8090 const formula::SingleVectorRefToken
* pSVR
=
8091 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
8093 if(pSVR
->GetArray().mpNumericArray
8094 && pSVR
->GetArray().mpStringArray
)
8095 isMixed
= svSingleVectorRefDoubleString
;
8096 else if(pSVR
->GetArray().mpNumericArray
)
8097 isMixed
= svSingleVectorRefDouble
;
8098 else if(pSVR
->GetArray().mpStringArray
)
8099 isMixed
= svSingleVectorRefString
;
8101 isMixed
= svSingleVectorRefNULL
;
8102 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
8104 else if (pCur
->GetType() == formula::svDouble
)
8107 isMixed
= svDoubleDouble
;
8113 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
8115 if(isMixed
== svDoubleVectorRefDoubleString
8116 || isMixed
== svSingleVectorRefDoubleString
)
8118 ss
<< " if (!isNan(";
8119 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
8121 ss
<< " tmp0 = tmp0 < ";
8122 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
8124 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
8126 ss
<< " else if(isNan(";
8127 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
8129 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
8131 ss
<< " tmp0 = tmp0 < 0.0 ? 0.0 : tmp0;\n";
8134 else if(isMixed
== svDoubleVectorRefDouble
8135 || isMixed
== svSingleVectorRefDouble
)
8137 ss
<< " if (!isNan(";
8138 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
8140 ss
<< " tmp0 = tmp0 < ";
8141 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
8142 ss
<< " ? " << vSubArguments
[i
]->GenSlidingWindowDeclRef();
8146 else if(isMixed
== svDoubleVectorRefString
)
8149 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
8150 ss
<< " == 0)\n continue;\n";
8151 ss
<< " tmp0 = tmp0 < 0.0 ? 0.0 : tmp0;\n";
8154 else if(isMixed
== svSingleVectorRefString
)
8157 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
8159 ss
<< " tmp0 = tmp0 < 0.0 ? 0.0 : tmp0;\n";
8162 else if(isMixed
== svDoubleDouble
)
8164 ss
<< " tmp0 = tmp0 < ";
8165 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
8166 ss
<< " ? " << vSubArguments
[i
]->GenSlidingWindowDeclRef();
8167 ss
<< " : tmp0;\n }\n";
8176 ss
<< " tmp0 = tmp0 < ";
8177 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
8178 ss
<< " ? " << vSubArguments
[i
]->GenSlidingWindowDeclRef();
8183 ss
<< " return tmp0 == 2.22507e-308 ? 0.0 : tmp0;\n";
8186 void OpAverageA::GenSlidingWindowFunction(
8187 std::stringstream
&ss
, const std::string
&sSymName
, SubArguments
&
8191 ss
<< "\ndouble " << sSymName
;
8192 ss
<< "_"<< BinFuncName() <<"(";
8193 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
8197 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
8201 ss
<< " int gid0=get_global_id(0);\n";
8202 ss
<< " double tmp0 = 0.0;\n";
8203 ss
<< " double nCount = 0.0;\n";
8204 size_t i
= vSubArguments
.size();
8206 for (i
= 0; i
< vSubArguments
.size(); i
++)
8208 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
8210 if (pCur
->GetType() == formula::svDoubleVectorRef
)
8212 const formula::DoubleVectorRefToken
* pDVR
=
8213 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
8214 if(pDVR
->GetArrays()[0].mpNumericArray
8215 && pDVR
->GetArrays()[0].mpStringArray
)
8216 isMixed
= svDoubleVectorRefDoubleString
;
8217 else if(pDVR
->GetArrays()[0].mpNumericArray
)
8218 isMixed
= svDoubleVectorRefDouble
;
8219 else if(pDVR
->GetArrays()[0].mpStringArray
)
8220 isMixed
= svDoubleVectorRefString
;
8222 isMixed
= svDoubleVectorRefNULL
;
8223 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
8224 ss
<< " for (int i = ";
8225 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed()) {
8226 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
8227 ss
<< " && i < " << nCurWindowSize
<< "; i++){\n";
8228 } else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()) {
8229 ss
<< "0; i < " << pDVR
->GetArrayLength();
8230 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; i++){\n";
8231 } else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed()){
8232 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
8233 ss
<< " && i < "<< nCurWindowSize
<< "; i++){\n";
8236 ss
<< "0; i < "<< nCurWindowSize
<< "; i++){\n";
8239 else if (pCur
->GetType() == formula::svSingleVectorRef
)
8241 const formula::SingleVectorRefToken
* pSVR
=
8242 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
8244 if(pSVR
->GetArray().mpNumericArray
8245 && pSVR
->GetArray().mpStringArray
)
8246 isMixed
= svSingleVectorRefDoubleString
;
8247 else if(pSVR
->GetArray().mpNumericArray
)
8248 isMixed
= svSingleVectorRefDouble
;
8249 else if(pSVR
->GetArray().mpStringArray
)
8250 isMixed
= svSingleVectorRefString
;
8252 isMixed
= svSingleVectorRefNULL
;
8253 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
8255 else if (pCur
->GetType() == formula::svDouble
)
8258 isMixed
= svDoubleDouble
;
8264 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
8266 if(isMixed
== svDoubleVectorRefDoubleString
8267 || isMixed
== svSingleVectorRefDoubleString
)
8269 ss
<< " if (!isNan(";
8270 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
8273 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
8275 ss
<< " nCount+=1.0;\n";
8277 ss
<< " else if(isNan(";
8278 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
8280 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
8282 ss
<< " nCount+=1.0;\n";
8285 else if(isMixed
== svDoubleVectorRefDouble
8286 || isMixed
== svSingleVectorRefDouble
)
8288 ss
<< " if (!isNan(";
8289 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
8292 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
8294 ss
<< " nCount+=1.0;\n";
8297 else if(isMixed
== svDoubleVectorRefString
)
8299 ss
<< " if (!isNan(";
8300 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
8302 ss
<< " nCount+=1.0;\n";
8305 else if(isMixed
== svSingleVectorRefString
)
8308 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
8310 ss
<< " nCount+=1.0;\n";
8313 else if(isMixed
== svDoubleDouble
)
8316 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
8318 ss
<< " nCount+=1.0;\n";
8329 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
8331 ss
<< " nCount+=1.0;\n";
8335 ss
<< " return tmp0*pow(nCount,-1);\n";
8338 void OpVarA::GenSlidingWindowFunction(std::stringstream
&ss
,
8339 const std::string
&sSymName
, SubArguments
&vSubArguments
)
8343 ss
<< "\ndouble " << sSymName
;
8344 ss
<< "_" << BinFuncName() << "(";
8345 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
8349 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
8352 ss
<< " int gid0 = get_global_id(0);\n";
8353 ss
<< " double fSum = 0.0;\n";
8354 ss
<< " double fMean = 0.0;\n";
8355 ss
<< " double vSum = 0.0;\n";
8356 ss
<< " double fCount = 0.0;\n";
8357 ss
<< " double arg = 0.0;\n";
8358 unsigned i
= vSubArguments
.size();
8361 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
8364 if(ocPush
== vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
8366 if (pCur
->GetType() == formula::svDoubleVectorRef
)
8368 const formula::DoubleVectorRefToken
* pDVR
=
8369 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
8371 if(pDVR
->GetArrays()[0].mpNumericArray
8372 && pDVR
->GetArrays()[0].mpStringArray
)
8373 isMixedDV
= svDoubleVectorRefDoubleString
;
8374 else if(pDVR
->GetArrays()[0].mpNumericArray
)
8375 isMixedDV
= svDoubleVectorRefDouble
;
8376 else if(pDVR
->GetArrays()[0].mpStringArray
)
8377 isMixedDV
= svDoubleVectorRefString
;
8379 isMixedDV
= svDoubleVectorRefNULL
;
8381 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
8382 ss
<< " for (int i = ";
8383 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
8385 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
8386 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
8389 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
8391 ss
<< "0; i < " << pDVR
->GetArrayLength();
8392 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
8395 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
8397 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
8398 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
8403 ss
<< "0; i < " << pDVR
->GetArrayLength() << "; i++)\n";
8407 if(isMixedDV
== svDoubleVectorRefDoubleString
)
8410 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
8412 ss
<< " if (isNan(arg) && ";
8413 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
8415 ss
<< " continue;\n";
8416 ss
<< " if(isNan(arg) && ";
8417 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
8420 ss
<< " fCount = fCount + 1.0;\n";
8421 ss
<< " continue;\n";
8423 ss
<< " fSum += arg;\n";
8424 ss
<< " fCount = fCount + 1.0;\n";
8427 else if(isMixedDV
== svDoubleVectorRefDouble
)
8430 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
8432 ss
<< " if (isNan(arg))\n";
8433 ss
<< " continue;\n";
8434 ss
<< " fSum += arg;\n";
8435 ss
<< " fCount = fCount + 1.0;\n";
8438 else if(isMixedDV
== svDoubleVectorRefString
)
8441 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
8443 ss
<< " continue;\n";
8444 ss
<< " fCount = fCount + 1.0;\n";
8449 ss
<< " continue;\n";
8454 else if (pCur
->GetType() == formula::svSingleVectorRef
)
8456 const formula::SingleVectorRefToken
* pSVR
=
8457 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
8459 if(pSVR
->GetArray().mpNumericArray
8460 && pSVR
->GetArray().mpStringArray
)
8461 isMixedSV
= svSingleVectorRefDoubleString
;
8462 else if(pSVR
->GetArray().mpNumericArray
)
8463 isMixedSV
= svSingleVectorRefDouble
;
8464 else if(pSVR
->GetArray().mpStringArray
)
8465 isMixedSV
= svSingleVectorRefString
;
8467 isMixedSV
= svSingleVectorRefNULL
;
8469 if(isMixedSV
== svSingleVectorRefDoubleString
)
8471 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
8474 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
8476 ss
<< " if (!isNan(arg))\n";
8478 ss
<< " fSum += arg;\n";
8479 ss
<< " fCount = fCount + 1.0;\n";
8481 ss
<< " if (isNan(arg) && ";
8482 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
8484 ss
<< " fCount = fCount + 1.0;\n";
8487 else if(isMixedSV
== svSingleVectorRefDouble
)
8489 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
8492 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
8493 ss
<< " if (!isNan(arg))\n";
8495 ss
<< " fSum += arg;\n";
8496 ss
<< " fCount += 1.0;\n";
8500 else if(isMixedSV
== svSingleVectorRefString
)
8503 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
8506 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
8508 ss
<< " fCount = fCount + 1.0;\n";
8513 ss
<< " arg =0.0;\n";
8518 ss
<< " arg = " << pCur
->GetDouble() << ";\n";
8519 ss
<< " fSum += arg;\n";
8520 ss
<< " fCount = fCount + 1.0;\n";
8526 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
8527 ss
<< " fSum += arg;\n";
8528 ss
<< " fCount = fCount + 1.0;\n";
8532 ss
<< " fMean = fSum * pow(fCount,-1.0);\n";
8535 i
= vSubArguments
.size();
8538 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
8541 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
8543 if (pCur
->GetType() == formula::svDoubleVectorRef
)
8545 const formula::DoubleVectorRefToken
* pDVR
=
8546 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
8547 if(pDVR
->GetArrays()[0].mpNumericArray
8548 && pDVR
->GetArrays()[0].mpStringArray
)
8549 isMixedDV
= svDoubleVectorRefDoubleString
;
8550 else if(pDVR
->GetArrays()[0].mpNumericArray
)
8551 isMixedDV
= svDoubleVectorRefDouble
;
8552 else if(pDVR
->GetArrays()[0].mpStringArray
)
8553 isMixedDV
= svDoubleVectorRefString
;
8555 isMixedDV
= svDoubleVectorRefNULL
;
8557 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
8558 ss
<< " for (int i = ";
8559 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
8561 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
8562 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
8565 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
8567 ss
<< "0; i < " << pDVR
->GetArrayLength();
8568 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
8571 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
8573 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
8574 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
8579 ss
<< "0; i < " << pDVR
->GetArrayLength() << "; i++)\n";
8582 if(isMixedDV
== svDoubleVectorRefDoubleString
)
8585 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
8587 ss
<< " if (isNan(arg) && ";
8588 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
8590 ss
<< " continue;\n";
8591 ss
<< " if(isNan(arg) && ";
8592 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
8594 ss
<< " arg = 0.0;\n";
8595 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
8599 else if(isMixedDV
== svDoubleVectorRefDouble
)
8602 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
8604 ss
<< " if (isNan(arg))\n";
8605 ss
<< " continue;\n";
8606 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
8610 else if(isMixedDV
== svDoubleVectorRefString
)
8613 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
8615 ss
<< " continue;\n";
8616 ss
<< " arg = 0.0;\n";
8617 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
8622 ss
<< " continue;\n";
8626 else if (pCur
->GetType() == formula::svSingleVectorRef
)
8628 const formula::SingleVectorRefToken
* pSVR
=
8629 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
8630 if(pSVR
->GetArray().mpNumericArray
8631 && pSVR
->GetArray().mpStringArray
)
8632 isMixedSV
= svSingleVectorRefDoubleString
;
8633 else if(pSVR
->GetArray().mpNumericArray
)
8634 isMixedSV
= svSingleVectorRefDouble
;
8635 else if(pSVR
->GetArray().mpStringArray
)
8636 isMixedSV
= svSingleVectorRefString
;
8638 isMixedSV
= svSingleVectorRefNULL
;
8640 if(isMixedSV
== svSingleVectorRefDoubleString
)
8642 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
8645 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
8647 ss
<< " if (!isNan(arg))\n";
8648 ss
<< " vSum += (arg - fMean)*(arg - fMean);\n";
8649 ss
<< " if (isNan(arg) && ";
8650 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
8653 ss
<< " arg = 0.0;\n";
8654 ss
<< " vSum += (arg - fMean)*(arg - fMean);\n";
8658 else if(isMixedSV
== svSingleVectorRefDouble
)
8660 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
8663 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
8664 ss
<< " if (!isNan(arg))\n";
8666 ss
<< " vSum += (arg - fMean)*(arg - fMean);\n";
8670 else if(isMixedSV
== svSingleVectorRefString
)
8672 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
8675 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
8678 ss
<< " arg = 0.0;\n";
8679 ss
<< " vSum += (arg - fMean)*(arg - fMean);\n";
8685 ss
<< " arg = 0.0;\n";
8690 ss
<< " arg = " << pCur
->GetDouble() << ";\n";
8691 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
8697 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
8698 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
8701 ss
<< " if (fCount <= 1.0)\n";
8702 ss
<< " return DBL_MAX;\n";
8704 ss
<< " return vSum * pow(fCount - 1.0,-1.0);\n";
8708 void OpVarPA::GenSlidingWindowFunction(std::stringstream
&ss
,
8709 const std::string
&sSymName
, SubArguments
&vSubArguments
)
8713 ss
<< "\ndouble " << sSymName
;
8714 ss
<< "_" << BinFuncName() << "(";
8715 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
8719 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
8722 ss
<< " int gid0 = get_global_id(0);\n";
8723 ss
<< " double fSum = 0.0;\n";
8724 ss
<< " double fMean = 0.0;\n";
8725 ss
<< " double vSum = 0.0;\n";
8726 ss
<< " double fCount = 0.0;\n";
8727 ss
<< " double arg = 0.0;\n";
8728 unsigned i
= vSubArguments
.size();
8731 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
8734 if(ocPush
== vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
8736 if (pCur
->GetType() == formula::svDoubleVectorRef
)
8738 const formula::DoubleVectorRefToken
* pDVR
=
8739 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
8740 if(pDVR
->GetArrays()[0].mpNumericArray
8741 && pDVR
->GetArrays()[0].mpStringArray
)
8742 isMixedDV
= svDoubleVectorRefDoubleString
;
8743 else if(pDVR
->GetArrays()[0].mpNumericArray
)
8744 isMixedDV
= svDoubleVectorRefDouble
;
8745 else if(pDVR
->GetArrays()[0].mpStringArray
)
8746 isMixedDV
= svDoubleVectorRefString
;
8748 isMixedDV
= svDoubleVectorRefNULL
;
8750 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
8751 ss
<< " for (int i = ";
8752 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
8754 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
8755 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
8758 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
8760 ss
<< "0; i < " << pDVR
->GetArrayLength();
8761 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
8764 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
8766 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
8767 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
8772 ss
<< "0; i < " << pDVR
->GetArrayLength() << "; i++)\n";
8776 if(isMixedDV
== svDoubleVectorRefDoubleString
)
8779 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
8781 ss
<< " if (isNan(arg) && ";
8782 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
8784 ss
<< " continue;\n";
8785 ss
<< " if(isNan(arg) && ";
8786 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
8789 ss
<< " fCount = fCount + 1.0;\n";
8790 ss
<< " continue;\n";
8792 ss
<< " fSum += arg;\n";
8793 ss
<< " fCount = fCount + 1.0;\n";
8796 else if(isMixedDV
== svDoubleVectorRefDouble
)
8799 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
8801 ss
<< " if (isNan(arg))\n";
8802 ss
<< " continue;\n";
8803 ss
<< " fSum += arg;\n";
8804 ss
<< " fCount = fCount + 1.0;\n";
8807 else if(isMixedDV
== svDoubleVectorRefString
)
8810 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
8812 ss
<< " continue;\n";
8813 ss
<< " fCount = fCount + 1.0;\n";
8818 ss
<< " continue;\n";
8823 else if (pCur
->GetType() == formula::svSingleVectorRef
)
8825 const formula::SingleVectorRefToken
* pSVR
=
8826 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
8827 if(pSVR
->GetArray().mpNumericArray
8828 && pSVR
->GetArray().mpStringArray
)
8829 isMixedSV
= svSingleVectorRefDoubleString
;
8830 else if(pSVR
->GetArray().mpNumericArray
)
8831 isMixedSV
= svSingleVectorRefDouble
;
8832 else if(pSVR
->GetArray().mpStringArray
)
8833 isMixedSV
= svSingleVectorRefString
;
8835 isMixedSV
= svSingleVectorRefNULL
;
8837 if(isMixedSV
== svSingleVectorRefDoubleString
)
8839 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
8842 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
8844 ss
<< " if (!isNan(arg))\n";
8846 ss
<< " fSum += arg;\n";
8847 ss
<< " fCount = fCount + 1.0;\n";
8849 ss
<< " if (isNan(arg) && ";
8850 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
8852 ss
<< " fCount = fCount + 1.0;\n";
8855 else if(isMixedSV
== svSingleVectorRefDouble
)
8857 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
8860 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
8861 ss
<< " if (!isNan(arg))\n";
8863 ss
<< " fSum += arg;\n";
8864 ss
<< " fCount += 1.0;\n";
8868 else if(isMixedSV
== svSingleVectorRefString
)
8871 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
8874 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
8876 ss
<< " fCount = fCount + 1.0;\n";
8881 ss
<< " arg =0.0;\n";
8886 ss
<< " arg = " << pCur
->GetDouble() << ";\n";
8887 ss
<< " fSum += arg;\n";
8888 ss
<< " fCount = fCount + 1.0;\n";
8894 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
8895 ss
<< " fSum += arg;\n";
8896 ss
<< " fCount = fCount + 1.0;\n";
8900 ss
<< " fMean = fSum * pow(fCount,-1.0);\n";
8903 i
= vSubArguments
.size();
8906 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
8909 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
8911 if (pCur
->GetType() == formula::svDoubleVectorRef
)
8913 const formula::DoubleVectorRefToken
* pDVR
=
8914 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
8915 if(pDVR
->GetArrays()[0].mpNumericArray
8916 && pDVR
->GetArrays()[0].mpStringArray
)
8917 isMixedDV
= svDoubleVectorRefDoubleString
;
8918 else if(pDVR
->GetArrays()[0].mpNumericArray
)
8919 isMixedDV
= svDoubleVectorRefDouble
;
8920 else if(pDVR
->GetArrays()[0].mpStringArray
)
8921 isMixedDV
= svDoubleVectorRefString
;
8923 isMixedDV
= svDoubleVectorRefNULL
;
8925 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
8926 ss
<< " for (int i = ";
8927 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
8929 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
8930 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
8933 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
8935 ss
<< "0; i < " << pDVR
->GetArrayLength();
8936 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
8939 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
8941 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
8942 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
8947 ss
<< "0; i < " << pDVR
->GetArrayLength() << "; i++)\n";
8950 if(isMixedDV
== svDoubleVectorRefDoubleString
)
8953 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
8955 ss
<< " if (isNan(arg) && ";
8956 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
8958 ss
<< " continue;\n";
8959 ss
<< " if(isNan(arg) && ";
8960 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
8962 ss
<< " arg = 0.0;\n";
8963 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
8967 else if(isMixedDV
== svDoubleVectorRefDouble
)
8970 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
8972 ss
<< " if (isNan(arg))\n";
8973 ss
<< " continue;\n";
8974 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
8978 else if(isMixedDV
== svDoubleVectorRefString
)
8981 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
8983 ss
<< " continue;\n";
8984 ss
<< " arg = 0.0;\n";
8985 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
8990 ss
<< " continue;\n";
8994 else if (pCur
->GetType() == formula::svSingleVectorRef
)
8996 const formula::SingleVectorRefToken
* pSVR
=
8997 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
8998 if(pSVR
->GetArray().mpNumericArray
8999 && pSVR
->GetArray().mpStringArray
)
9000 isMixedSV
= svSingleVectorRefDoubleString
;
9001 else if(pSVR
->GetArray().mpNumericArray
)
9002 isMixedSV
= svSingleVectorRefDouble
;
9003 else if(pSVR
->GetArray().mpStringArray
)
9004 isMixedSV
= svSingleVectorRefString
;
9006 isMixedSV
= svSingleVectorRefNULL
;
9008 if(isMixedSV
== svSingleVectorRefDoubleString
)
9010 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
9013 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
9015 ss
<< " if (!isNan(arg))\n";
9016 ss
<< " vSum += (arg - fMean)*(arg - fMean);\n";
9017 ss
<< " if (isNan(arg) && ";
9018 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
9021 ss
<< " arg = 0.0;\n";
9022 ss
<< " vSum += (arg - fMean)*(arg - fMean);\n";
9026 else if(isMixedSV
== svSingleVectorRefDouble
)
9028 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
9031 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
9032 ss
<< " if (!isNan(arg))\n";
9034 ss
<< " vSum += (arg - fMean)*(arg - fMean);\n";
9038 else if(isMixedSV
== svSingleVectorRefString
)
9040 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
9043 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
9046 ss
<< " arg = 0.0;\n";
9047 ss
<< " vSum += (arg - fMean)*(arg - fMean);\n";
9053 ss
<< " arg = 0.0;\n";
9058 ss
<< " arg = " << pCur
->GetDouble() << ";\n";
9059 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
9065 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
9066 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
9069 ss
<< " if (fCount == 0.0)\n";
9070 ss
<< " return DBL_MAX;\n";
9072 ss
<< " return vSum * pow(fCount,-1.0);\n";
9075 void OpStDevA::GenSlidingWindowFunction(std::stringstream
&ss
,
9076 const std::string
&sSymName
, SubArguments
&vSubArguments
)
9080 ss
<< "\ndouble " << sSymName
;
9081 ss
<< "_" << BinFuncName() << "(";
9082 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
9086 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
9089 ss
<< " int gid0 = get_global_id(0);\n";
9090 ss
<< " double fSum = 0.0;\n";
9091 ss
<< " double fMean = 0.0;\n";
9092 ss
<< " double vSum = 0.0;\n";
9093 ss
<< " double fCount = 0.0;\n";
9094 ss
<< " double arg = 0.0;\n";
9095 unsigned i
= vSubArguments
.size();
9098 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
9101 if(ocPush
== vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
9103 if (pCur
->GetType() == formula::svDoubleVectorRef
)
9105 const formula::DoubleVectorRefToken
* pDVR
=
9106 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
9107 if(pDVR
->GetArrays()[0].mpNumericArray
9108 && pDVR
->GetArrays()[0].mpStringArray
)
9109 isMixedDV
= svDoubleVectorRefDoubleString
;
9110 else if(pDVR
->GetArrays()[0].mpNumericArray
)
9111 isMixedDV
= svDoubleVectorRefDouble
;
9112 else if(pDVR
->GetArrays()[0].mpStringArray
)
9113 isMixedDV
= svDoubleVectorRefString
;
9115 isMixedDV
= svDoubleVectorRefNULL
;
9117 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
9118 ss
<< " for (int i = ";
9119 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
9121 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
9122 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
9125 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
9127 ss
<< "0; i < " << pDVR
->GetArrayLength();
9128 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
9131 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
9133 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
9134 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
9139 ss
<< "0; i < " << pDVR
->GetArrayLength() << "; i++)\n";
9143 if(isMixedDV
== svDoubleVectorRefDoubleString
)
9146 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
9148 ss
<< " if (isNan(arg) && ";
9149 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
9151 ss
<< " continue;\n";
9152 ss
<< " if(isNan(arg) && ";
9153 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
9156 ss
<< " fCount = fCount + 1.0;\n";
9157 ss
<< " continue;\n";
9159 ss
<< " fSum += arg;\n";
9160 ss
<< " fCount = fCount + 1.0;\n";
9163 else if(isMixedDV
== svDoubleVectorRefDouble
)
9166 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
9168 ss
<< " if (isNan(arg))\n";
9169 ss
<< " continue;\n";
9170 ss
<< " fSum += arg;\n";
9171 ss
<< " fCount = fCount + 1.0;\n";
9174 else if(isMixedDV
== svDoubleVectorRefString
)
9177 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
9179 ss
<< " continue;\n";
9180 ss
<< " fCount = fCount + 1.0;\n";
9185 ss
<< " continue;\n";
9190 else if (pCur
->GetType() == formula::svSingleVectorRef
)
9192 const formula::SingleVectorRefToken
* pSVR
=
9193 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
9194 if(pSVR
->GetArray().mpNumericArray
9195 && pSVR
->GetArray().mpStringArray
)
9196 isMixedSV
= svSingleVectorRefDoubleString
;
9197 else if(pSVR
->GetArray().mpNumericArray
)
9198 isMixedSV
= svSingleVectorRefDouble
;
9199 else if(pSVR
->GetArray().mpStringArray
)
9200 isMixedSV
= svSingleVectorRefString
;
9202 isMixedSV
= svSingleVectorRefNULL
;
9204 if(isMixedSV
== svSingleVectorRefDoubleString
)
9206 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
9209 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
9211 ss
<< " if (!isNan(arg))\n";
9213 ss
<< " fSum += arg;\n";
9214 ss
<< " fCount = fCount + 1.0;\n";
9216 ss
<< " if (isNan(arg) && ";
9217 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
9219 ss
<< " fCount = fCount + 1.0;\n";
9222 else if(isMixedSV
== svSingleVectorRefDouble
)
9224 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
9227 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
9228 ss
<< " if (!isNan(arg))\n";
9230 ss
<< " fSum += arg;\n";
9231 ss
<< " fCount += 1.0;\n";
9235 else if(isMixedSV
== svSingleVectorRefString
)
9238 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
9241 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
9243 ss
<< " fCount = fCount + 1.0;\n";
9248 ss
<< " arg =0.0;\n";
9253 ss
<< " arg = " << pCur
->GetDouble() << ";\n";
9254 ss
<< " fSum += arg;\n";
9255 ss
<< " fCount = fCount + 1.0;\n";
9261 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
9262 ss
<< " fSum += arg;\n";
9263 ss
<< " fCount = fCount + 1.0;\n";
9267 ss
<< " fMean = fSum * pow(fCount,-1.0);\n";
9270 i
= vSubArguments
.size();
9273 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
9276 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
9278 if (pCur
->GetType() == formula::svDoubleVectorRef
)
9280 const formula::DoubleVectorRefToken
* pDVR
=
9281 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
9282 if(pDVR
->GetArrays()[0].mpNumericArray
9283 && pDVR
->GetArrays()[0].mpStringArray
)
9284 isMixedDV
= svDoubleVectorRefDoubleString
;
9285 else if(pDVR
->GetArrays()[0].mpNumericArray
)
9286 isMixedDV
= svDoubleVectorRefDouble
;
9287 else if(pDVR
->GetArrays()[0].mpStringArray
)
9288 isMixedDV
= svDoubleVectorRefString
;
9290 isMixedDV
= svDoubleVectorRefNULL
;
9292 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
9293 ss
<< " for (int i = ";
9294 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
9296 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
9297 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
9300 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
9302 ss
<< "0; i < " << pDVR
->GetArrayLength();
9303 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
9306 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
9308 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
9309 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
9314 ss
<< "0; i < " << pDVR
->GetArrayLength() << "; i++)\n";
9317 if(isMixedDV
== svDoubleVectorRefDoubleString
)
9320 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
9322 ss
<< " if (isNan(arg) && ";
9323 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
9325 ss
<< " continue;\n";
9326 ss
<< " if(isNan(arg) && ";
9327 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
9329 ss
<< " arg = 0.0;\n";
9330 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
9334 else if(isMixedDV
== svDoubleVectorRefDouble
)
9337 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
9339 ss
<< " if (isNan(arg))\n";
9340 ss
<< " continue;\n";
9341 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
9345 else if(isMixedDV
== svDoubleVectorRefString
)
9348 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
9350 ss
<< " continue;\n";
9351 ss
<< " arg = 0.0;\n";
9352 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
9357 ss
<< " continue;\n";
9361 else if (pCur
->GetType() == formula::svSingleVectorRef
)
9363 const formula::SingleVectorRefToken
* pSVR
=
9364 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
9365 if(pSVR
->GetArray().mpNumericArray
9366 && pSVR
->GetArray().mpStringArray
)
9367 isMixedSV
= svSingleVectorRefDoubleString
;
9368 else if(pSVR
->GetArray().mpNumericArray
)
9369 isMixedSV
= svSingleVectorRefDouble
;
9370 else if(pSVR
->GetArray().mpStringArray
)
9371 isMixedSV
= svSingleVectorRefString
;
9373 isMixedSV
= svSingleVectorRefNULL
;
9375 if(isMixedSV
== svSingleVectorRefDoubleString
)
9377 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
9380 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
9382 ss
<< " if (!isNan(arg))\n";
9383 ss
<< " vSum += (arg - fMean)*(arg - fMean);\n";
9384 ss
<< " if (isNan(arg) && ";
9385 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
9388 ss
<< " arg = 0.0;\n";
9389 ss
<< " vSum += (arg - fMean)*(arg - fMean);\n";
9393 else if(isMixedSV
== svSingleVectorRefDouble
)
9395 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
9398 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
9399 ss
<< " if (!isNan(arg))\n";
9401 ss
<< " vSum += (arg - fMean)*(arg - fMean);\n";
9405 else if(isMixedSV
== svSingleVectorRefString
)
9407 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
9410 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
9413 ss
<< " arg = 0.0;\n";
9414 ss
<< " vSum += (arg - fMean)*(arg - fMean);\n";
9420 ss
<< " arg = 0.0;\n";
9425 ss
<< " arg = " << pCur
->GetDouble() << ";\n";
9426 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
9432 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
9433 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
9436 ss
<< " if (fCount <= 1.0)\n";
9437 ss
<< " return DBL_MAX;\n";
9439 ss
<< " return sqrt(vSum * pow(fCount - 1.0,-1.0));\n";
9443 void OpStDevPA::GenSlidingWindowFunction(std::stringstream
&ss
,
9444 const std::string
&sSymName
, SubArguments
&vSubArguments
)
9448 ss
<< "\ndouble " << sSymName
;
9449 ss
<< "_" << BinFuncName() << "(";
9450 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
9454 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
9457 ss
<< " int gid0 = get_global_id(0);\n";
9458 ss
<< " double fSum = 0.0;\n";
9459 ss
<< " double fMean = 0.0;\n";
9460 ss
<< " double vSum = 0.0;\n";
9461 ss
<< " double fCount = 0.0;\n";
9462 ss
<< " double arg = 0.0;\n";
9463 unsigned i
= vSubArguments
.size();
9466 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
9469 if(ocPush
== vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
9471 if (pCur
->GetType() == formula::svDoubleVectorRef
)
9473 const formula::DoubleVectorRefToken
* pDVR
=
9474 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
9475 if(pDVR
->GetArrays()[0].mpNumericArray
9476 && pDVR
->GetArrays()[0].mpStringArray
)
9477 isMixedDV
= svDoubleVectorRefDoubleString
;
9478 else if(pDVR
->GetArrays()[0].mpNumericArray
)
9479 isMixedDV
= svDoubleVectorRefDouble
;
9480 else if(pDVR
->GetArrays()[0].mpStringArray
)
9481 isMixedDV
= svDoubleVectorRefString
;
9483 isMixedDV
= svDoubleVectorRefNULL
;
9485 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
9486 ss
<< " for (int i = ";
9487 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
9489 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
9490 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
9493 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
9495 ss
<< "0; i < " << pDVR
->GetArrayLength();
9496 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
9499 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
9501 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
9502 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
9507 ss
<< "0; i < " << pDVR
->GetArrayLength() << "; i++)\n";
9511 if(isMixedDV
== svDoubleVectorRefDoubleString
)
9514 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
9516 ss
<< " if (isNan(arg) && ";
9517 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
9519 ss
<< " continue;\n";
9520 ss
<< " if(isNan(arg) && ";
9521 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
9524 ss
<< " fCount = fCount + 1.0;\n";
9525 ss
<< " continue;\n";
9527 ss
<< " fSum += arg;\n";
9528 ss
<< " fCount = fCount + 1.0;\n";
9531 else if(isMixedDV
== svDoubleVectorRefDouble
)
9534 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
9536 ss
<< " if (isNan(arg))\n";
9537 ss
<< " continue;\n";
9538 ss
<< " fSum += arg;\n";
9539 ss
<< " fCount = fCount + 1.0;\n";
9542 else if(isMixedDV
== svDoubleVectorRefString
)
9545 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
9547 ss
<< " continue;\n";
9548 ss
<< " fCount = fCount + 1.0;\n";
9553 ss
<< " continue;\n";
9558 else if (pCur
->GetType() == formula::svSingleVectorRef
)
9560 const formula::SingleVectorRefToken
* pSVR
=
9561 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
9562 if(pSVR
->GetArray().mpNumericArray
9563 && pSVR
->GetArray().mpStringArray
)
9564 isMixedSV
= svSingleVectorRefDoubleString
;
9565 else if(pSVR
->GetArray().mpNumericArray
)
9566 isMixedSV
= svSingleVectorRefDouble
;
9567 else if(pSVR
->GetArray().mpStringArray
)
9568 isMixedSV
= svSingleVectorRefString
;
9570 isMixedSV
= svSingleVectorRefNULL
;
9572 if(isMixedSV
== svSingleVectorRefDoubleString
)
9574 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
9577 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
9579 ss
<< " if (!isNan(arg))\n";
9581 ss
<< " fSum += arg;\n";
9582 ss
<< " fCount = fCount + 1.0;\n";
9584 ss
<< " if (isNan(arg) && ";
9585 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
9587 ss
<< " fCount = fCount + 1.0;\n";
9590 else if(isMixedSV
== svSingleVectorRefDouble
)
9592 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
9595 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
9596 ss
<< " if (!isNan(arg))\n";
9598 ss
<< " fSum += arg;\n";
9599 ss
<< " fCount += 1.0;\n";
9603 else if(isMixedSV
== svSingleVectorRefString
)
9606 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
9609 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
9611 ss
<< " fCount = fCount + 1.0;\n";
9616 ss
<< " arg =0.0;\n";
9621 ss
<< " arg = " << pCur
->GetDouble() << ";\n";
9622 ss
<< " fSum += arg;\n";
9623 ss
<< " fCount = fCount + 1.0;\n";
9629 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
9630 ss
<< " fSum += arg;\n";
9631 ss
<< " fCount = fCount + 1.0;\n";
9635 ss
<< " fMean = fSum * pow(fCount,-1.0);\n";
9638 i
= vSubArguments
.size();
9641 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
9644 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
9646 if (pCur
->GetType() == formula::svDoubleVectorRef
)
9648 const formula::DoubleVectorRefToken
* pDVR
=
9649 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
9650 if(pDVR
->GetArrays()[0].mpNumericArray
9651 && pDVR
->GetArrays()[0].mpStringArray
)
9652 isMixedDV
= svDoubleVectorRefDoubleString
;
9653 else if(pDVR
->GetArrays()[0].mpNumericArray
)
9654 isMixedDV
= svDoubleVectorRefDouble
;
9655 else if(pDVR
->GetArrays()[0].mpStringArray
)
9656 isMixedDV
= svDoubleVectorRefString
;
9658 isMixedDV
= svDoubleVectorRefNULL
;
9660 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
9661 ss
<< " for (int i = ";
9662 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
9664 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
9665 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
9668 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
9670 ss
<< "0; i < " << pDVR
->GetArrayLength();
9671 ss
<< " && i < gid0+" << nCurWindowSize
<< "; i++)\n";
9674 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
9676 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
9677 ss
<< " && i < " << nCurWindowSize
<< "; i++)\n";
9682 ss
<< "0; i < " << pDVR
->GetArrayLength() << "; i++)\n";
9685 if(isMixedDV
== svDoubleVectorRefDoubleString
)
9688 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
9690 ss
<< " if (isNan(arg) && ";
9691 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
9693 ss
<< " continue;\n";
9694 ss
<< " if(isNan(arg) && ";
9695 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
9697 ss
<< " arg = 0.0;\n";
9698 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
9702 else if(isMixedDV
== svDoubleVectorRefDouble
)
9705 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
9707 ss
<< " if (isNan(arg))\n";
9708 ss
<< " continue;\n";
9709 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
9713 else if(isMixedDV
== svDoubleVectorRefString
)
9716 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
9718 ss
<< " continue;\n";
9719 ss
<< " arg = 0.0;\n";
9720 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
9725 ss
<< " continue;\n";
9729 else if (pCur
->GetType() == formula::svSingleVectorRef
)
9731 const formula::SingleVectorRefToken
* pSVR
=
9732 static_cast< const formula::SingleVectorRefToken
* >(pCur
);
9733 if(pSVR
->GetArray().mpNumericArray
9734 && pSVR
->GetArray().mpStringArray
)
9735 isMixedSV
= svSingleVectorRefDoubleString
;
9736 else if(pSVR
->GetArray().mpNumericArray
)
9737 isMixedSV
= svSingleVectorRefDouble
;
9738 else if(pSVR
->GetArray().mpStringArray
)
9739 isMixedSV
= svSingleVectorRefString
;
9741 isMixedSV
= svSingleVectorRefNULL
;
9743 if(isMixedSV
== svSingleVectorRefDoubleString
)
9745 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
9748 ss
<< vSubArguments
[i
]->GenDoubleSlidingWindowDeclRef();
9750 ss
<< " if (!isNan(arg))\n";
9751 ss
<< " vSum += (arg - fMean)*(arg - fMean);\n";
9752 ss
<< " if (isNan(arg) && ";
9753 ss
<< vSubArguments
[i
]->GenStringSlidingWindowDeclRef();
9756 ss
<< " arg = 0.0;\n";
9757 ss
<< " vSum += (arg - fMean)*(arg - fMean);\n";
9761 else if(isMixedSV
== svSingleVectorRefDouble
)
9763 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
9766 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
9767 ss
<< " if (!isNan(arg))\n";
9769 ss
<< " vSum += (arg - fMean)*(arg - fMean);\n";
9773 else if(isMixedSV
== svSingleVectorRefString
)
9775 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << ")\n";
9778 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
9781 ss
<< " arg = 0.0;\n";
9782 ss
<< " vSum += (arg - fMean)*(arg - fMean);\n";
9788 ss
<< " arg = 0.0;\n";
9793 ss
<< " arg = " << pCur
->GetDouble() << ";\n";
9794 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
9800 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef() << ";\n";
9801 ss
<< " vSum += (arg - fMean) * (arg - fMean);\n";
9804 ss
<< " if (fCount == 1.0)\n";
9805 ss
<< " return DBL_MAX;\n";
9807 ss
<< " return sqrt(vSum * pow(fCount,-1.0));\n";
9811 void OpAveDev:: GenSlidingWindowFunction(std::stringstream
&ss
,
9812 const std::string
&sSymName
, SubArguments
&vSubArguments
)
9814 ss
<< "\ndouble " << sSymName
;
9815 ss
<< "_"<< BinFuncName() <<"( ";
9816 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
9820 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
9824 ss
<< " int gid0 = get_global_id(0);\n";
9825 ss
<< " double sum=0.0;\n";
9826 ss
<< " double length;\n";
9827 ss
<< " double totallength=0;\n";
9828 ss
<< " double tmp = 0;\n";
9829 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
9831 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
9833 if (pCur
->GetType() == formula::svDoubleVectorRef
)
9835 const formula::DoubleVectorRefToken
* pDVR
=
9836 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
9837 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
9838 ss
<< " length="<<nCurWindowSize
;
9840 ss
<< " for (int i = ";
9841 ss
<< "0; i < "<< nCurWindowSize
<< "; i++)\n";
9843 ss
<< " double arg"<<i
<<" = ";
9844 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
9846 ss
<< " if(isNan(arg"<<i
<<")||((gid0+i)>=";
9847 ss
<< pDVR
->GetArrayLength();
9850 ss
<< " length-=1.0;\n";
9851 ss
<< " continue;\n";
9853 ss
<< " sum += arg"<<i
<<";\n";
9855 ss
<< " totallength +=length;\n";
9857 else if (pCur
->GetType() == formula::svSingleVectorRef
)
9860 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
9862 ss
<< " if(!isNan(tmp))\n";
9864 ss
<< " sum += tmp;\n";
9865 ss
<< " totallength +=1;\n";
9868 else if (pCur
->GetType() == formula::svDouble
)
9871 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
9873 ss
<< " sum += tmp;\n";
9874 ss
<< " totallength +=1;\n";
9877 ss
<< " double mean = sum * pow(totallength,-1);\n";
9878 ss
<< " sum = 0.0;\n";
9879 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
9881 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
9883 if (pCur
->GetType() == formula::svDoubleVectorRef
)
9885 const formula::DoubleVectorRefToken
* pDVR
=
9886 static_cast<const formula::DoubleVectorRefToken
*>(pCur
);
9887 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
9888 ss
<< " for (int i = ";
9889 ss
<< "0; i < "<< nCurWindowSize
<< "; i++)\n";
9891 ss
<< " double arg"<<i
<<" = ";
9892 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
9894 ss
<< " if(isNan(arg"<<i
<<")||((gid0+i)>=";
9895 ss
<< pDVR
->GetArrayLength();
9898 ss
<< " continue;\n";
9900 ss
<< " sum += fabs(arg"<<i
<<"-mean);\n";
9903 else if (pCur
->GetType() == formula::svSingleVectorRef
)
9906 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
9908 ss
<< " if(!isNan(tmp))\n";
9910 ss
<< " sum += fabs(tmp-mean);\n";
9913 else if (pCur
->GetType() == formula::svDouble
)
9916 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
9918 ss
<< " sum += fabs(tmp-mean);\n";
9921 ss
<< " tmp=sum*pow(totallength,-1);\n";
9922 ss
<< " return tmp;\n";
9927 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */