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_math.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"
19 #include "opinlinefun_math.hxx"
22 using namespace formula
;
24 namespace sc
{ namespace opencl
{
26 void OpCos::GenSlidingWindowFunction(std::stringstream
&ss
,
27 const std::string sSymName
, SubArguments
&vSubArguments
)
29 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
30 const formula::SingleVectorRefToken
*tmpCurDVR
= dynamic_cast<const
31 formula::SingleVectorRefToken
*>(tmpCur
);
32 ss
<< "\ndouble " << sSymName
;
33 ss
<< "_"<< BinFuncName() <<"(";
34 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
38 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
41 ss
<<"int gid0=get_global_id(0);\n\t";
42 ss
<< "double arg0 = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
45 ss
<< "if(isNan(arg0)||(gid0>=";
46 ss
<<tmpCurDVR
->GetArrayLength();
50 ss
<< "double tmp=cos(arg0);\n\t";
51 ss
<< "return tmp;\n";
54 void OpSec::GenSlidingWindowFunction(std::stringstream
&ss
,
55 const std::string sSymName
, SubArguments
&vSubArguments
)
57 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
58 const formula::SingleVectorRefToken
*tmpCurDVR
= dynamic_cast<const
59 formula::SingleVectorRefToken
*>(tmpCur
);
60 ss
<< "\ndouble " << sSymName
;
61 ss
<< "_"<< BinFuncName() <<"(";
62 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
66 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
69 ss
<<" int gid0=get_global_id(0);\n";
70 ss
<<" double arg0 = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
73 ss
<<" if(isNan(arg0)||(gid0>=";
74 ss
<<tmpCurDVR
->GetArrayLength();
78 ss
<< " return pow(cos(arg0),-1 );\n";
81 void OpCosh::BinInlineFun(std::set
<std::string
>& decls
,
82 std::set
<std::string
>& funs
)
84 decls
.insert(local_coshDecl
);
85 funs
.insert(local_cosh
);
87 void OpSecH::GenSlidingWindowFunction(std::stringstream
&ss
,
88 const std::string sSymName
, SubArguments
&vSubArguments
)
90 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
91 const formula::SingleVectorRefToken
*tmpCurDVR
= dynamic_cast<const
92 formula::SingleVectorRefToken
*>(tmpCur
);
93 ss
<< "\ndouble " << sSymName
;
94 ss
<< "_"<< BinFuncName() <<"(";
95 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
99 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
102 ss
<<" int gid0=get_global_id(0);\n";
103 ss
<<" double arg0 = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
106 ss
<<" if(isNan(arg0)||(gid0>=";
107 ss
<<tmpCurDVR
->GetArrayLength();
111 ss
<< " return pow(cosh(arg0),-1 );\n";
114 void OpMROUND::GenSlidingWindowFunction(std::stringstream
&ss
,
115 const std::string sSymName
, SubArguments
&vSubArguments
)
117 ss
<< "\ndouble " << sSymName
;
118 ss
<< "_"<< BinFuncName() <<"(";
119 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
123 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
126 ss
<<" double tmp = 0;\n";
127 ss
<<" int gid0 = get_global_id(0);\n";
128 ss
<<" double arg0=0;\n";
129 ss
<<" double arg1=0;\n";
132 for (size_t i
= 0; i
< vSubArguments
.size(); i
++)
134 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
136 if (pCur
->GetType() == formula::svSingleVectorRef
)
139 const formula::SingleVectorRefToken
* pSVR
=
140 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur
);
141 ss
<< "if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
145 else if (pCur
->GetType() == formula::svDouble
)
157 if(ocPush
==vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
160 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
162 ss
<< " if (isNan(tmp))\n";
163 ss
<< " arg"<<i
<<"= 0;\n";
165 ss
<< " arg"<<i
<<"=tmp;\n";
170 ss
<<" arg"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
174 ss
<<"arg"<<i
<<"="<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
178 ss
<<" if(arg1==0)\n";
179 ss
<<" return arg1;\n";
180 ss
<<" tmp=arg1 * round(arg0 * pow(arg1,-1));\n";
181 ss
<<" return tmp;\n";
184 void OpCosh::GenSlidingWindowFunction(std::stringstream
&ss
,
185 const std::string sSymName
, SubArguments
&vSubArguments
)
187 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
188 const formula::SingleVectorRefToken
*tmpCurDVR
= dynamic_cast<const
189 formula::SingleVectorRefToken
*>(tmpCur
);
190 ss
<< "\ndouble " << sSymName
;
191 ss
<< "_"<< BinFuncName() <<"(";
192 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
196 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
199 ss
<<" int gid0=get_global_id(0);\n";
200 ss
<< " double arg0 = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
203 ss
<< " if(isNan(arg0)||(gid0>=";
204 ss
<<tmpCurDVR
->GetArrayLength();
208 ss
<< " double tmp=local_cosh(arg0);\n";
209 ss
<< " return tmp;\n";
213 void OpCot::GenSlidingWindowFunction(std::stringstream
&ss
,
214 const std::string sSymName
, SubArguments
&vSubArguments
)
216 ss
<< "\ndouble " << sSymName
;
217 ss
<< "_"<< BinFuncName() <<"(";
218 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
222 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
226 ss
<< " int gid0=get_global_id(0);\n";
227 ss
<< " double arg0 = 0.0f;\n";
228 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
230 if(ocPush
== vSubArguments
[0]->GetFormulaToken()->GetOpCode())
232 if(tmpCur
->GetType() == formula::svSingleVectorRef
)
234 const formula::SingleVectorRefToken
*tmpCurDVR
=
236 <const formula::SingleVectorRefToken
*>(tmpCur
);
238 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
242 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
244 ss
<< tmpCurDVR
->GetArrayLength();
246 ss
<< " { arg0 = 0.0f; }\n";
249 else if(tmpCur
->GetType() == formula::svDouble
)
252 ss
<< tmpCur
->GetDouble() << ";\n";
258 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
261 ss
<< " arg0 = arg0 * M_1_PI;\n";
262 ss
<< " return cospi(arg0) * pow(sinpi(arg0), -1);\n";
267 void OpCoth::BinInlineFun(std::set
<std::string
>& decls
,
268 std::set
<std::string
>& funs
)
270 decls
.insert(local_cothDecl
);
271 funs
.insert(local_coth
);
274 void OpCoth::GenSlidingWindowFunction(std::stringstream
&ss
,
275 const std::string sSymName
, SubArguments
&vSubArguments
)
277 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
278 const formula::SingleVectorRefToken
*tmpCurDVR
= dynamic_cast<const
279 formula::SingleVectorRefToken
*>(tmpCur
);
280 ss
<< "\ndouble " << sSymName
;
281 ss
<< "_"<< BinFuncName() <<"(";
282 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
286 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
289 ss
<<" int gid0=get_global_id(0);\n";
290 ss
<< " double arg0 = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
293 ss
<< " if(isNan(arg0)||(gid0>=";
294 ss
<<tmpCurDVR
->GetArrayLength();
298 ss
<< " double tmp=local_coth(arg0);\n";
299 ss
<< " return tmp;\n";
303 void OpCombina::BinInlineFun(std::set
<std::string
>& decls
,
304 std::set
<std::string
>& funs
)
306 decls
.insert(bikDecl
);
310 void OpCombina::GenSlidingWindowFunction(std::stringstream
&ss
,
311 const std::string sSymName
, SubArguments
&vSubArguments
)
313 ss
<< "\ndouble " << sSymName
;
314 ss
<< "_"<< BinFuncName() <<"(";
315 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
319 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
322 ss
<< " int gid0 = get_global_id(0);\n";
323 ss
<< " double tem;\n";
324 ss
<< " double arg0,arg1;\n";
325 for (unsigned int i
= 0; i
< vSubArguments
.size(); i
++)
327 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
329 ss
<< " arg"<<i
<<" = "<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
331 if(pCur
->GetType() == formula::svSingleVectorRef
)
334 const formula::SingleVectorRefToken
* pSVR
=
335 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur
);
336 ss
<< " if(isNan(arg" << i
<<")||(gid0 >= ";
337 ss
<< pSVR
->GetArrayLength();
339 ss
<< " arg" << i
<< " = 0;\n";
341 else if (pCur
->GetType() == formula::svDouble
)
343 ss
<< " if(isNan(arg" << i
<<"))\n";
344 ss
<< " arg" << i
<< " = 0;\n";
348 ss
<< " arg0 = trunc(arg0);\n";
349 ss
<< " arg1 = trunc(arg1);\n";
350 ss
<< " if(arg0 >= arg1 && arg0 > 0 && arg1 > 0)\n";
351 ss
<< " tem = bik(arg0+arg1-1,arg1);\n";
352 ss
<< " else if(arg0 == 0 && arg1 == 0)\n";
354 ss
<< " else if(arg0 > 0 && arg1 == 0)\n";
357 ss
<< " tem = -1;\n";
358 ss
<< " double i = tem - trunc(tem);\n";
359 ss
<< " if(i < 0.5)\n";
360 ss
<< " tem = trunc(tem);\n";
362 ss
<< " tem = trunc(tem) + 1;\n";
363 ss
<< " return tem;\n";
366 void OpEven::GenSlidingWindowFunction(std::stringstream
&ss
,
367 const std::string sSymName
, SubArguments
&vSubArguments
)
369 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
370 const formula::SingleVectorRefToken
*tmpCurDVR
= dynamic_cast<const
371 formula::SingleVectorRefToken
*>(tmpCur
);
372 ss
<< "\ndouble " << sSymName
;
373 ss
<< "_"<< BinFuncName() <<"(";
374 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
378 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
381 ss
<<" int gid0=get_global_id(0);\n";
382 ss
<< " double arg0 = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
385 ss
<< " if(isNan(arg0)||(gid0>=";
386 ss
<<tmpCurDVR
->GetArrayLength();
390 ss
<< " double tmp;\n";
391 ss
<< " tmp = fabs(arg0 / 2);\n";
392 ss
<< " if ( trunc(tmp) == tmp )\n";
393 ss
<< " tmp = tmp * 2;\n";
395 ss
<< " tmp = (trunc(tmp) + 1) * 2;\n";
396 ss
<< " if (arg0 < 0)\n";
397 ss
<< " tmp = tmp * -1.0;\n";
398 ss
<< " return tmp;\n";
402 void OpMod::GenSlidingWindowFunction(std::stringstream
&ss
,
403 const std::string sSymName
, SubArguments
&vSubArguments
)
406 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
407 const formula::SingleVectorRefToken
*tmpCurDVR0
= dynamic_cast<const
408 formula::SingleVectorRefToken
*>(tmpCur0
);
409 FormulaToken
*tmpCur1
= vSubArguments
[0]->GetFormulaToken();
410 const formula::SingleVectorRefToken
*tmpCurDVR1
= dynamic_cast<const
411 formula::SingleVectorRefToken
*>(tmpCur1
);
413 ss
<< "\ndouble " << sSymName
;
414 ss
<< "_"<< BinFuncName() <<"(";
415 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
419 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
422 ss
<<" int gid0=get_global_id(0);\n";
423 ss
<< " double arg0 = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
425 ss
<<" double arg1 =" << vSubArguments
[1]->GenSlidingWindowDeclRef();
428 ss
<< " if(isNan(arg0)||(gid0>=";
429 ss
<<tmpCurDVR0
->GetArrayLength();
434 ss
<< " if(isNan(arg1)||(gid0>=";
435 ss
<<tmpCurDVR1
->GetArrayLength();
439 ss
<< " double tem;\n";
440 ss
<< " if(arg1 != 0) {\n";
441 ss
<< " if(arg0 < 0 && arg1 > 0)\n";
442 ss
<< " while(arg0 < 0)\n";
443 ss
<< " arg0 += arg1;\n";
444 ss
<< " else if (arg0 > 0 && arg1 < 0)\n";
445 ss
<< " while(arg0 > 0)\n";
446 ss
<< " arg0 += arg1;\n";
447 ss
<< " tem = fmod(arg0,arg1);\n";
451 ss
<< " if(arg1 < 0 && tem > 0)\n";
452 ss
<< " tem = -tem;\n";
453 ss
<< " return tem;\n";
456 void OpLog::GenSlidingWindowFunction(std::stringstream
&ss
,
457 const std::string sSymName
, SubArguments
&vSubArguments
)
459 ss
<< "\ndouble " << sSymName
;
460 ss
<< "_"<< BinFuncName() <<"(";
461 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
465 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
468 ss
<< " int gid0 = get_global_id(0);\n";
469 ss
<< " double tem;\n";
470 ss
<< " double arg0,arg1;\n";
471 for (unsigned int i
= 0; i
< vSubArguments
.size(); i
++)
473 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
475 ss
<< " arg"<<i
<<" = "<<vSubArguments
[i
]->GenSlidingWindowDeclRef();
477 if(pCur
->GetType() == formula::svSingleVectorRef
)
480 const formula::SingleVectorRefToken
* pSVR
=
481 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur
);
482 ss
<< " if(isNan(arg" << i
<<")||(gid0 >= ";
483 ss
<< pSVR
->GetArrayLength();
486 ss
<< " arg0 = 0;\n";
488 ss
<< " arg1 = 10;\n";
490 else if (pCur
->GetType() == formula::svDouble
)
492 ss
<< " if(isNan(arg" << i
<<"))\n";
494 ss
<< " arg0 = 0;\n";
496 ss
<< " arg1 = 10;\n";
500 if (vSubArguments
.size() < 2)
501 ss
<< " arg1 = 10;\n";
502 ss
<< " tem = log10(arg0)/log10(arg1);;\n";
503 ss
<< " return tem;\n";
506 void OpCsc::GenSlidingWindowFunction(
507 std::stringstream
&ss
, const std::string sSymName
, SubArguments
&vSubArguments
)
509 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
510 const formula::SingleVectorRefToken
*tmpCurDVR
= dynamic_cast<const
511 formula::SingleVectorRefToken
*>(tmpCur
);
512 ss
<< "\ndouble " << sSymName
;
513 ss
<< "_"<< BinFuncName() <<"(";
514 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
518 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
521 ss
<<"int gid0=get_global_id(0);\n\t";
522 ss
<< "double arg0 = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
525 ss
<< "if(isNan(arg0)||(gid0>=";
526 ss
<<tmpCurDVR
->GetArrayLength();
530 ss
<< "double tmp=1/sin(arg0);\n\t";
531 ss
<< "return tmp;\n";
534 void OpCountIfs::GenSlidingWindowFunction(std::stringstream
&ss
,
535 const std::string sSymName
, SubArguments
&vSubArguments
)
537 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
538 const formula::DoubleVectorRefToken
*pCurDVR
= dynamic_cast<const
539 formula::DoubleVectorRefToken
*>(tmpCur
);
540 size_t nCurWindowSize
= pCurDVR
->GetArrayLength() <
541 pCurDVR
->GetRefRowSize() ? pCurDVR
->GetArrayLength():
542 pCurDVR
->GetRefRowSize() ;
543 ss
<< "\ndouble " << sSymName
;
544 ss
<< "_"<< BinFuncName() <<"(";
545 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
549 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
552 ss
<<" int gid0=get_global_id(0);\n";
553 ss
<< " int tmp =0;\n";
554 ss
<< " int loop;\n";
555 GenTmpVariables(ss
,vSubArguments
);
557 ss
<< " int singleIndex =gid0;\n";
560 std::stringstream tmpss
;
562 for(unsigned j
=0;j
<vSubArguments
.size();j
+=2,m
++)
564 CheckSubArgumentIsNan(tmpss
,vSubArguments
,j
);
565 CheckSubArgumentIsNan(ss
,vSubArguments
,j
+1);
566 tmpss
<<" if(isequal(";
574 tmpss
<< " tmp ++;\n";
575 for(unsigned j
=0;j
<vSubArguments
.size();j
+=2,m
--)
577 for(int n
= 0;n
<m
+1;n
++)
583 UnrollDoubleVector(ss
,tmpss
,pCurDVR
,nCurWindowSize
);
585 ss
<< "return tmp;\n";
588 void OpSumIfs::GenSlidingWindowFunction(std::stringstream
&ss
,
589 const std::string sSymName
, SubArguments
&vSubArguments
)
591 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
592 const formula::DoubleVectorRefToken
*pCurDVR
= dynamic_cast<const
593 formula::DoubleVectorRefToken
*>(tmpCur
);
594 size_t nCurWindowSize
= pCurDVR
->GetArrayLength() <
595 pCurDVR
->GetRefRowSize() ? pCurDVR
->GetArrayLength():
596 pCurDVR
->GetRefRowSize() ;
598 mNeedReductionKernel
= vSubArguments
[0]->NeedParallelReduction();
599 if (mNeedReductionKernel
)
601 // generate reduction functions
603 ss
<< "__kernel void ";
604 ss
<< vSubArguments
[0]->GetName();
605 ss
<< "_SumIfs_reduction( ";
606 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
610 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
612 ss
<< ", __global double *result,int arrayLength,int windowSize";
615 ss
<< " double tmp =0;\n";
618 GenTmpVariables(ss
,vSubArguments
);
619 ss
<< " double current_result = 0.0;\n";
620 ss
<< " int writePos = get_group_id(1);\n";
621 if (pCurDVR
->IsStartFixed() && pCurDVR
->IsEndFixed())
622 ss
<< " int offset = 0;\n";
623 else if (!pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed())
624 ss
<< " int offset = get_group_id(1);\n";
627 // actually unreachable
628 ss
<< " int lidx = get_local_id(0);\n";
629 ss
<< " __local double shm_buf[256];\n";
630 ss
<< " barrier(CLK_LOCAL_MEM_FENCE);\n";
631 ss
<< " int loop = arrayLength/512 + 1;\n";
632 ss
<< " for (int l=0; l<loop; l++){\n";
633 ss
<< " tmp = 0.0;\n";
634 ss
<< " int loopOffset = l*512;\n";
636 ss
<< " int p1 = loopOffset + lidx + offset, p2 = p1 + 256;\n";
637 ss
<< " if (p2 < min(offset + windowSize, arrayLength)) {\n";
638 ss
<< " tmp0 = 0.0;\n";
640 std::string p1
= "p1";
641 std::string p2
= "p2";
642 for(unsigned j
=1;j
<vSubArguments
.size();j
+=2,mm
++)
644 CheckSubArgumentIsNan2(ss
,vSubArguments
,j
,p1
);
645 CheckSubArgumentIsNan2(ss
,vSubArguments
,j
+1,p1
);
656 CheckSubArgumentIsNan2(ss
,vSubArguments
,0,p1
);
657 ss
<< " tmp += tmp0;\n";
658 for(unsigned j
=1;j
<vSubArguments
.size();j
+=2,mm
--)
660 for(int n
= 0;n
<mm
+1;n
++)
667 for(unsigned j
=1;j
<vSubArguments
.size();j
+=2,mm
++)
669 CheckSubArgumentIsNan2(ss
,vSubArguments
,j
,p2
);
670 CheckSubArgumentIsNan2(ss
,vSubArguments
,j
+1,p2
);
679 CheckSubArgumentIsNan2(ss
,vSubArguments
,0,p2
);
680 ss
<< " tmp += tmp0;\n";
681 for(unsigned j
=1;j
< vSubArguments
.size();j
+=2,mm
--)
683 for(int n
= 0;n
<mm
+1;n
++)
691 ss
<< " else if (p1 < min(arrayLength, offset + windowSize)) {\n";
693 for(unsigned j
=1;j
<vSubArguments
.size();j
+=2,mm
++)
695 CheckSubArgumentIsNan2(ss
,vSubArguments
,j
,p1
);
696 CheckSubArgumentIsNan2(ss
,vSubArguments
,j
+1,p1
);
706 CheckSubArgumentIsNan2(ss
,vSubArguments
,0,p1
);
707 ss
<< " tmp += tmp0;\n";
708 for(unsigned j
=1;j
<vSubArguments
.size();j
+=2,mm
--)
710 for(int n
= 0;n
<mm
+1;n
++)
718 ss
<< " shm_buf[lidx] = tmp;\n";
719 ss
<< " barrier(CLK_LOCAL_MEM_FENCE);\n";
720 ss
<< " for (int i = 128; i >0; i/=2) {\n";
721 ss
<< " if (lidx < i)\n";
722 ss
<< " shm_buf[lidx] += shm_buf[lidx + i];\n";
723 ss
<< " barrier(CLK_LOCAL_MEM_FENCE);\n";
725 ss
<< " if (lidx == 0)\n";
726 ss
<< " current_result += shm_buf[0];\n";
727 ss
<< " barrier(CLK_LOCAL_MEM_FENCE);\n";
730 ss
<< " if (lidx == 0)\n";
731 ss
<< " result[writePos] = current_result;\n";
733 }// finish generate reduction code
734 // generate functions as usual
735 ss
<< "\ndouble " << sSymName
;
736 ss
<< "_"<< BinFuncName() <<"(";
737 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
741 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
744 ss
<<" int gid0=get_global_id(0);\n";
745 ss
<< " double tmp =0;\n";
746 if (!mNeedReductionKernel
)
749 GenTmpVariables(ss
,vSubArguments
);
751 if (!pCurDVR
->IsStartFixed() && pCurDVR
->IsEndFixed()) {
752 ss
<< "gid0; i < "<< nCurWindowSize
<<"; i++)\n";
753 } else if (pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed()) {
754 ss
<< "0; i < gid0+"<< nCurWindowSize
<<"; i++)\n";
756 ss
<< "0; i < "<< nCurWindowSize
<<"; i++)\n";
759 if(!pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed())
761 ss
<< " int doubleIndex =i+gid0;\n";
764 ss
<< " int doubleIndex =i;\n";
766 ss
<< " int singleIndex =gid0;\n";
768 for(unsigned j
=1;j
<vSubArguments
.size();j
+=2,m
++)
770 CheckSubArgumentIsNan(ss
,vSubArguments
,j
);
771 CheckSubArgumentIsNan(ss
,vSubArguments
,j
+1);
780 CheckSubArgumentIsNan(ss
,vSubArguments
,0);
781 ss
<< " tmp += tmp0;\n";
782 for(unsigned j
=1;j
<=vSubArguments
.size();j
+=2,m
--)
784 for(int n
= 0;n
<m
+1;n
++)
791 if (mNeedReductionKernel
)
794 vSubArguments
[0]->GenDeclRef(ss
);
797 ss
<< "return tmp;\n";
800 void OpCscH::GenSlidingWindowFunction(
801 std::stringstream
&ss
, const std::string sSymName
, SubArguments
&vSubArguments
)
803 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
804 const formula::SingleVectorRefToken
*tmpCurDVR
= dynamic_cast<const
805 formula::SingleVectorRefToken
*>(tmpCur
);
806 ss
<< "\ndouble " << sSymName
;
807 ss
<< "_"<< BinFuncName() <<"(";
808 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
812 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
815 ss
<<"int gid0=get_global_id(0);\n\t";
816 ss
<< "double arg0 = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
819 ss
<< "if(isNan(arg0)||(gid0>=";
820 ss
<<tmpCurDVR
->GetArrayLength();
824 ss
<< "double tmp=1/sinh(arg0);\n\t";
825 ss
<< "return tmp;\n";
828 void OpExp::GenSlidingWindowFunction(std::stringstream
&ss
,
829 const std::string sSymName
, SubArguments
&vSubArguments
)
831 ss
<< "\ndouble " << sSymName
;
832 ss
<< "_"<< BinFuncName() <<"(";
833 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
836 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
840 ss
<< " int gid0=get_global_id(0);\n";
841 ss
<< " double arg0 = 0.0f;\n";
842 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
844 if(ocPush
== vSubArguments
[0]->GetFormulaToken()->GetOpCode())
846 if(tmpCur
->GetType() == formula::svSingleVectorRef
)
848 const formula::SingleVectorRefToken
*tmpCurDVR
=
850 <const formula::SingleVectorRefToken
*>(tmpCur
);
852 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
856 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
858 ss
<< tmpCurDVR
->GetArrayLength();
860 ss
<< " { arg0 = 0.0f; }\n";
863 else if(tmpCur
->GetType() == formula::svDouble
)
865 ss
<< " arg0=" << tmpCur
->GetDouble() << ";\n";
871 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
874 ss
<< " return pow(M_E, arg0);\n";
878 void OpAverageIfs::GenSlidingWindowFunction(std::stringstream
&ss
,
879 const std::string sSymName
, SubArguments
&vSubArguments
)
881 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
882 const formula::DoubleVectorRefToken
*pCurDVR
= dynamic_cast<const
883 formula::DoubleVectorRefToken
*>(tmpCur
);
884 size_t nCurWindowSize
= pCurDVR
->GetArrayLength() <
885 pCurDVR
->GetRefRowSize() ? pCurDVR
->GetArrayLength():
886 pCurDVR
->GetRefRowSize() ;
887 ss
<< "\ndouble " << sSymName
;
888 ss
<< "_"<< BinFuncName() <<"(";
889 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
893 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
896 ss
<<" int gid0=get_global_id(0);\n";
897 ss
<< " double tmp =0;\n";
898 ss
<< " int count=0;\n";
900 GenTmpVariables(ss
,vSubArguments
);
901 ss
<< " int singleIndex =gid0;\n";
903 std::stringstream tmpss
;
904 for(unsigned j
=1;j
<vSubArguments
.size();j
+=2,m
++)
906 CheckSubArgumentIsNan(tmpss
,vSubArguments
,j
);
907 CheckSubArgumentIsNan(ss
,vSubArguments
,j
+1);
908 tmpss
<<" if(isequal(";
916 CheckSubArgumentIsNan(tmpss
,vSubArguments
,0);
917 tmpss
<< " tmp += tmp0;\n";
918 tmpss
<< " count++;\n";
919 for(unsigned j
=1;j
<vSubArguments
.size();j
+=2,m
--)
921 for(int n
= 0;n
<m
+1;n
++)
928 UnrollDoubleVector(ss
,tmpss
,pCurDVR
,nCurWindowSize
);
930 ss
<< " if(count!=0)\n";
931 ss
<< " tmp=tmp/count;\n";
934 ss
<< "return tmp;\n";
938 void OpLog10::GenSlidingWindowFunction(std::stringstream
&ss
,
939 const std::string sSymName
, SubArguments
&vSubArguments
)
941 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
942 const formula::SingleVectorRefToken
*tmpCurDVR
= dynamic_cast<const
943 formula::SingleVectorRefToken
*>(tmpCur
);
944 ss
<< "\ndouble " << sSymName
;
945 ss
<< "_"<< BinFuncName() <<"(";
946 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
950 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
953 ss
<<"int gid0=get_global_id(0);\n\t";
954 ss
<< "double arg0 = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
957 ss
<< "if(isNan(arg0)||(gid0>=";
958 ss
<<tmpCurDVR
->GetArrayLength();
962 ss
<< "double tmp=log10(arg0);\n\t";
963 ss
<< "return tmp;\n";
967 void OpSinh::GenSlidingWindowFunction(std::stringstream
&ss
,
968 const std::string sSymName
, SubArguments
&vSubArguments
)
970 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
971 const formula::SingleVectorRefToken
*tmpCurDVR
= dynamic_cast<const
972 formula::SingleVectorRefToken
*>(tmpCur
);
973 ss
<< "\ndouble " << sSymName
;
974 ss
<< "_"<< BinFuncName() <<"(";
975 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
979 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
982 ss
<<" int gid0=get_global_id(0);\n";
983 ss
<<" double arg0 = " <<
984 vSubArguments
[0]->GenSlidingWindowDeclRef();
987 ss
<< " if(isNan(arg0)||(gid0>=";
988 ss
<<tmpCurDVR
->GetArrayLength();
992 ss
<< " double tmp=( exp(arg0)-exp(-arg0) )/2;\n";
993 ss
<< " return tmp;\n";
996 void OpSin::GenSlidingWindowFunction(std::stringstream
&ss
,
997 const std::string sSymName
, SubArguments
&vSubArguments
)
999 ss
<< "\ndouble " << sSymName
;
1000 ss
<< "_"<< BinFuncName() <<"(";
1001 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1004 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1008 ss
<< " int gid0=get_global_id(0);\n";
1009 ss
<< " double arg0 = 0.0f;\n";
1010 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
1012 if(ocPush
== vSubArguments
[0]->GetFormulaToken()->GetOpCode())
1014 if(tmpCur
->GetType() == formula::svSingleVectorRef
)
1016 const formula::SingleVectorRefToken
*tmpCurDVR
=
1018 <const formula::SingleVectorRefToken
*>(tmpCur
);
1020 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1024 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1026 ss
<< tmpCurDVR
->GetArrayLength();
1028 ss
<< " { arg0 = 0.0f; }\n";
1031 else if(tmpCur
->GetType() == formula::svDouble
)
1033 ss
<< " arg0=" << tmpCur
->GetDouble() << ";\n";
1039 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1042 ss
<< " arg0 = arg0 * M_1_PI;\n";
1043 ss
<< " return sinpi(arg0);\n";
1047 void OpAbs::GenSlidingWindowFunction(std::stringstream
&ss
,
1048 const std::string sSymName
, SubArguments
&vSubArguments
)
1050 ss
<< "\ndouble " << sSymName
;
1051 ss
<< "_"<< BinFuncName() <<"(";
1052 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1056 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1059 ss
<< " int gid0 = get_global_id(0);\n";
1060 ss
<< " double tmp = " << GetBottom() << ";\n";
1062 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1063 const formula::SingleVectorRefToken
*tmpCurDVR0
=
1064 dynamic_cast<const formula::SingleVectorRefToken
*>(tmpCur0
);
1065 ss
<< " int buffer_len = ";
1066 ss
<< tmpCurDVR0
->GetArrayLength();
1068 ss
<< " if((gid0)>=buffer_len || isNan(";
1069 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1071 ss
<< " tmp = " << GetBottom() << ";\n else \n";
1074 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1076 ss
<< " return fabs(tmp);\n";
1079 void OpArcCos::BinInlineFun(std::set
<std::string
>& decls
,
1080 std::set
<std::string
>& funs
)
1082 decls
.insert(atan2Decl
);
1083 funs
.insert(atan2Content
);
1085 void OpArcCos::GenSlidingWindowFunction(std::stringstream
&ss
,
1086 const std::string sSymName
, SubArguments
&vSubArguments
)
1088 ss
<< "\ndouble " << sSymName
;
1089 ss
<< "_"<< BinFuncName() <<"(";
1090 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1093 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1096 ss
<< " int gid0 = get_global_id(0);\n";
1097 ss
<< " double tmp = " << GetBottom() << ";\n";
1099 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1100 const formula::SingleVectorRefToken
*tmpCurDVR0
=
1101 dynamic_cast<const formula::SingleVectorRefToken
*>(tmpCur0
);
1102 ss
<< " int buffer_len = "<< tmpCurDVR0
->GetArrayLength()<< ";\n";
1103 ss
<< " if((gid0)>=buffer_len || isNan(";
1104 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef()<< "))\n";
1105 ss
<< " tmp = " << GetBottom() << ";\n";
1109 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef()<< ";\n";
1110 ss
<< " return arctan2(sqrt(1.0 - pow(tmp, 2)), tmp);\n";
1113 void OpArcCosHyp::GenSlidingWindowFunction(std::stringstream
&ss
,
1114 const std::string sSymName
, SubArguments
&vSubArguments
)
1116 ss
<< "\ndouble " << sSymName
;
1117 ss
<< "_"<< BinFuncName() <<"(";
1118 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1121 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1124 ss
<< " int gid0 = get_global_id(0);\n";
1125 ss
<< " double tmp = " << GetBottom() << ";\n";
1126 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1128 if(ocPush
== vSubArguments
[0]->GetFormulaToken()->GetOpCode())
1130 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
1132 const formula::SingleVectorRefToken
*tmpCurDVR0
=
1133 dynamic_cast<const formula::SingleVectorRefToken
*>(tmpCur0
);
1135 ss
<< " int buffer_len = "<<tmpCurDVR0
->GetArrayLength()<<";\n";
1136 ss
<< " if((gid0)>=buffer_len || isNan(";
1137 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << "))\n";
1138 ss
<< " tmp = " << GetBottom() << ";\n";
1141 ss
<< " tmp = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
1144 else if(tmpCur0
->GetType() == formula::svDouble
)
1146 ss
<< " tmp = " << tmpCur0
->GetDouble() << ";\n";
1151 ss
<< " tmp = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
1155 ss
<< " return log( tmp + pow( (pown(tmp, 2) - 1.0), 0.5));\n";
1158 void OpTan::GenSlidingWindowFunction(std::stringstream
&ss
,
1159 const std::string sSymName
, SubArguments
&vSubArguments
)
1161 ss
<< "\ndouble " << sSymName
;
1162 ss
<< "_"<< BinFuncName() <<"(";
1163 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1166 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1170 ss
<< " int gid0=get_global_id(0);\n";
1171 ss
<< " double arg0 = 0.0f;\n";
1172 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
1174 if(ocPush
== vSubArguments
[0]->GetFormulaToken()->GetOpCode())
1176 if(tmpCur
->GetType() == formula::svSingleVectorRef
)
1178 const formula::SingleVectorRefToken
*tmpCurDVR
=
1180 <const formula::SingleVectorRefToken
*>(tmpCur
);
1182 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1186 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1188 ss
<< tmpCurDVR
->GetArrayLength();
1190 ss
<< " { arg0 = 0.0f; }\n";
1193 else if(tmpCur
->GetType() == formula::svDouble
)
1195 ss
<< " arg0=" << tmpCur
->GetDouble() << ";\n";
1201 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1204 ss
<< " arg0 = arg0 * M_1_PI;\n";
1205 ss
<< " return sinpi(arg0) * pow(cospi(arg0), -1);\n";
1208 void OpTanH::GenSlidingWindowFunction(std::stringstream
&ss
,
1209 const std::string sSymName
, SubArguments
&vSubArguments
)
1211 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
1212 const formula::SingleVectorRefToken
*tmpCurDVR
= dynamic_cast<const
1213 formula::SingleVectorRefToken
*>(tmpCur
);
1214 ss
<< "\ndouble " << sSymName
;
1215 ss
<< "_"<< BinFuncName() <<"(";
1216 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1220 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1224 ss
<< " int gid0=get_global_id(0);\n";
1225 ss
<< " double arg0 = "<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1228 ss
<< " if(isNan(arg0)||(gid0>=";
1229 ss
<< tmpCurDVR
->GetArrayLength();
1231 ss
<< " arg0 = 0;\n";
1233 ss
<< " double tmp=tanh(arg0);\n";
1234 ss
<< " return tmp;\n";
1237 void OpPower::GenSlidingWindowFunction(std::stringstream
&ss
,
1238 const std::string sSymName
, SubArguments
&vSubArguments
)
1240 ss
<< "\ndouble " << sSymName
;
1241 ss
<< "_"<< BinFuncName() <<"(";
1242 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1246 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1250 ss
<< " int gid0=get_global_id(0);\n";
1251 ss
<< " double arg[2];\n";
1252 for( unsigned i
=0; i
< vSubArguments
.size(); ++i
)
1254 FormulaToken
*tmpCur
= vSubArguments
[i
]->GetFormulaToken();
1256 if(ocPush
== vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
1258 if(tmpCur
->GetType() == formula::svDoubleVectorRef
)
1260 const formula::DoubleVectorRefToken
* tmpCurDVR
=
1262 const formula::DoubleVectorRefToken
*>(tmpCur
);
1263 ss
<< " int i = 0;\n";
1264 ss
<< " arg["<<i
<<"] = ";
1265 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
1268 ss
<< " if(isNan(arg["<<i
;
1269 ss
<< "])||(gid0>=";
1270 ss
<< tmpCurDVR
->GetArrayLength();
1276 else if(tmpCur
->GetType() == formula::svSingleVectorRef
)
1278 const formula::SingleVectorRefToken
* tmpCurDVR
=
1280 const formula::SingleVectorRefToken
*>(tmpCur
);
1281 ss
<< " arg["<<i
<<"] = ";
1282 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
1285 ss
<< " if(isNan(arg["<<i
;
1286 ss
<< "])||(gid0>=";
1287 ss
<< tmpCurDVR
->GetArrayLength();
1293 else if(tmpCur
->GetType() == formula::svDouble
)
1295 ss
<< " arg["<<i
<<"] = ";
1296 ss
<< tmpCur
->GetDouble() << ";\n";
1301 ss
<< " arg["<<i
<<"] = ";
1302 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
1306 ss
<< " return pow(arg[0],arg[1]);\n";
1309 void OpSqrt::GenSlidingWindowFunction(std::stringstream
&ss
,
1310 const std::string sSymName
, SubArguments
&vSubArguments
)
1312 ss
<< "\ndouble " << sSymName
;
1313 ss
<< "_"<< BinFuncName() <<"(";
1314 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1318 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1322 ss
<< " int gid0=get_global_id(0);\n";
1323 ss
<< " double arg0 = 0.0f;\n";
1324 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
1326 if(ocPush
== vSubArguments
[0]->GetFormulaToken()->GetOpCode())
1328 if(tmpCur
->GetType() == formula::svSingleVectorRef
)
1330 const formula::SingleVectorRefToken
*tmpCurDVR
=
1332 <const formula::SingleVectorRefToken
*>(tmpCur
);
1334 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1338 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1340 ss
<< tmpCurDVR
->GetArrayLength();
1342 ss
<< " { arg0 = 0; }\n";
1345 else if(tmpCur
->GetType() == formula::svDouble
)
1348 ss
<< tmpCur
->GetDouble() << ";\n";
1354 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1357 ss
<< " return sqrt(arg0);\n";
1360 void OpArcCot::GenSlidingWindowFunction(std::stringstream
&ss
,
1361 const std::string sSymName
, SubArguments
&vSubArguments
)
1363 ss
<< "\ndouble " << sSymName
;
1364 ss
<< "_"<< BinFuncName() <<"(";
1365 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1368 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1371 ss
<< " int gid0 = get_global_id(0);\n";
1372 ss
<< " double tmp = " << GetBottom() << ";\n";
1374 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1375 const formula::SingleVectorRefToken
*tmpCurDVR0
=
1376 dynamic_cast<const formula::SingleVectorRefToken
*>(tmpCur0
);
1377 ss
<< " int buffer_len = " << tmpCurDVR0
->GetArrayLength()<< ";\n";
1378 ss
<< " if((gid0)>=buffer_len || isNan(";
1379 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << "))\n";
1380 ss
<< " tmp = " << GetBottom() << ";\n";
1383 ss
<< " tmp = " << vSubArguments
[0]->GenSlidingWindowDeclRef() <<";\n";
1384 ss
<< " return M_PI_2 - atan(tmp);\n";
1387 void OpArcCotHyp::GenSlidingWindowFunction(std::stringstream
&ss
,
1388 const std::string sSymName
, SubArguments
&vSubArguments
)
1390 ss
<< "\ndouble " << sSymName
;
1391 ss
<< "_"<< BinFuncName() <<"(";
1392 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1395 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1399 ss
<< " int gid0=get_global_id(0);\n";
1400 ss
<< " double arg0 = 0.0f;\n";
1401 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
1403 if(ocPush
== vSubArguments
[0]->GetFormulaToken()->GetOpCode())
1405 if(tmpCur
->GetType() == formula::svSingleVectorRef
)
1407 const formula::SingleVectorRefToken
*tmpCurDVR
=
1409 <const formula::SingleVectorRefToken
*>(tmpCur
);
1411 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1415 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1417 ss
<< tmpCurDVR
->GetArrayLength();
1419 ss
<< " { arg0 = 0.0f; }\n";
1422 else if(tmpCur
->GetType() == formula::svDouble
)
1425 ss
<< tmpCur
->GetDouble() << ";\n";
1431 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
1434 ss
<< " return 0.5 * log(1 + 2 * pown(arg0 - 1.0, -1));\n";
1437 void OpArcSin::BinInlineFun(std::set
<std::string
>& decls
,
1438 std::set
<std::string
>& funs
)
1440 decls
.insert(atan2Decl
);
1441 funs
.insert(atan2Content
);
1443 void OpArcSin::GenSlidingWindowFunction(std::stringstream
&ss
,
1444 const std::string sSymName
, SubArguments
&vSubArguments
)
1446 ss
<< "\ndouble " << sSymName
;
1447 ss
<< "_"<< BinFuncName() <<"(";
1448 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1451 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1454 ss
<< " int gid0 = get_global_id(0);\n";
1455 ss
<< " double tmp = " << GetBottom() << ";\n";
1457 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1458 const formula::SingleVectorRefToken
*tmpCurDVR0
=
1459 dynamic_cast<const formula::SingleVectorRefToken
*>(tmpCur0
);
1460 ss
<< " int buffer_len = " << tmpCurDVR0
->GetArrayLength() << ";\n";
1461 ss
<< " if((gid0)>=buffer_len || isNan(";
1462 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << "))\n";
1463 ss
<< " tmp = " << GetBottom() << ";\n";
1466 ss
<< " tmp = " << vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1467 ss
<< " return arctan2(tmp, sqrt(1.0 - pow(tmp, 2)));\n";
1470 void OpArcSinHyp::GenSlidingWindowFunction(std::stringstream
&ss
,
1471 const std::string sSymName
, SubArguments
&vSubArguments
)
1473 ss
<< "\ndouble " << sSymName
;
1474 ss
<< "_"<< BinFuncName() <<"(";
1475 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1478 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1481 ss
<< " int gid0 = get_global_id(0);\n";
1482 ss
<< " double tmp = " << GetBottom() << ";\n";
1483 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1485 if(ocPush
== vSubArguments
[0]->GetFormulaToken()->GetOpCode())
1487 if(tmpCur0
->GetType() == formula::svSingleVectorRef
)
1489 const formula::SingleVectorRefToken
*tmpCurDVR0
=
1490 dynamic_cast<const formula::SingleVectorRefToken
*>(tmpCur0
);
1492 ss
<< " int buffer_len = "<<tmpCurDVR0
->GetArrayLength()<<";\n";
1493 ss
<< " if((gid0)>=buffer_len || isNan(";
1494 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << "))\n";
1495 ss
<< " tmp = " << GetBottom() << ";\n";
1498 ss
<< " tmp = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
1501 else if(tmpCur0
->GetType() == formula::svDouble
)
1503 ss
<< " tmp = " << tmpCur0
->GetDouble() << ";\n";
1508 ss
<< " tmp = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
1511 ss
<< " return log( tmp + pow((pown(tmp, 2) + 1.0), 0.5));\n";
1514 void OpArcTan2::BinInlineFun(std::set
<std::string
>& decls
,
1515 std::set
<std::string
>& funs
)
1517 decls
.insert(atan2Decl
);
1518 funs
.insert(atan2Content
);
1520 void OpArcTan2::GenSlidingWindowFunction(std::stringstream
&ss
,
1521 const std::string sSymName
, SubArguments
&vSubArguments
)
1523 ss
<< "\ndouble " << sSymName
;
1524 ss
<< "_"<< BinFuncName() <<"(";
1525 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1528 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1531 ss
<< " int gid0 = get_global_id(0);\n";
1532 ss
<< " double x_num = " << GetBottom() << ";\n";
1533 ss
<< " double y_num = " << GetBottom() << ";\n";
1535 FormulaToken
*iXNum
= vSubArguments
[0]->GetFormulaToken();
1536 const formula::SingleVectorRefToken
*tmpCurDVRX
=
1537 dynamic_cast<const formula::SingleVectorRefToken
*>(iXNum
);
1538 FormulaToken
*iYNum
= vSubArguments
[1]->GetFormulaToken();
1539 const formula::SingleVectorRefToken
*tmpCurDVRY
=
1540 dynamic_cast<const formula::SingleVectorRefToken
*>(iYNum
);
1541 ss
<< " int buffer_x_len = " << tmpCurDVRX
->GetArrayLength() << ";\n";
1542 ss
<< " int buffer_y_len = " << tmpCurDVRY
->GetArrayLength() << ";\n";
1543 ss
<< " if((gid0)>=buffer_x_len || isNan(";
1544 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << "))\n";
1545 ss
<< " x_num = " << GetBottom() << ";\n";
1548 ss
<< " x_num = "<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1550 ss
<< " if((gid0)>=buffer_y_len || isNan(";
1551 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << "))\n";
1552 ss
<< " y_num = " << GetBottom() << ";\n";
1555 ss
<< " y_num = "<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
1556 ss
<< " return arctan2(y_num, x_num);\n";
1559 void OpArcTan::GenSlidingWindowFunction(std::stringstream
&ss
,
1560 const std::string sSymName
, SubArguments
&vSubArguments
)
1562 ss
<< "\ndouble " << sSymName
;
1563 ss
<< "_"<< BinFuncName() <<"(";
1564 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1567 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1570 ss
<< " int gid0 = get_global_id(0);\n";
1571 ss
<< " double tmp = " << GetBottom() << ";\n";
1573 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1574 const formula::SingleVectorRefToken
*tmpCurDVR0
=
1575 dynamic_cast<const formula::SingleVectorRefToken
*>(tmpCur0
);
1576 ss
<< " int buffer_len = " << tmpCurDVR0
->GetArrayLength() << ";\n";
1577 ss
<< " if((gid0)>=buffer_len || isNan(";
1578 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << "))\n";
1579 ss
<< " tmp = " << GetBottom() << ";\n";
1582 ss
<< " tmp = " << vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1583 ss
<< " return atan(tmp);\n";
1586 void OpArcTanH::GenSlidingWindowFunction(std::stringstream
&ss
,
1587 const std::string sSymName
, SubArguments
&vSubArguments
)
1589 ss
<< "\ndouble " << sSymName
;
1590 ss
<< "_"<< BinFuncName() <<"(";
1591 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1594 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1597 ss
<< " int gid0 = get_global_id(0);\n";
1598 ss
<< " double tmp = " << GetBottom() << ";\n";
1600 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
1601 const formula::SingleVectorRefToken
*tmpCurDVR0
=
1602 dynamic_cast<const formula::SingleVectorRefToken
*>(tmpCur0
);
1603 ss
<< " int buffer_len = " << tmpCurDVR0
->GetArrayLength() << ";\n";
1604 ss
<< " if((gid0)>=buffer_len || isNan(";
1605 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << "))\n";
1606 ss
<< " tmp = " << GetBottom() << ";\n";
1609 ss
<< " tmp = " << vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1610 ss
<< " double a = 1.0 + tmp;\n";
1611 ss
<< " double b = 1.0 - tmp;\n";
1612 ss
<< " return log(pow(a/b, 0.5));\n";
1615 void OpBitAnd::GenSlidingWindowFunction(std::stringstream
&ss
,
1616 const std::string sSymName
, SubArguments
&vSubArguments
)
1618 ss
<< "\ndouble " << sSymName
;
1619 ss
<< "_"<< BinFuncName() <<"(";
1620 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1623 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1626 ss
<< " int gid0 = get_global_id(0);\n";
1627 ss
<< " double num1 = " << GetBottom() << ";\n";
1628 ss
<< " double num2 = " << GetBottom() << ";\n";
1630 FormulaToken
*iNum1
= vSubArguments
[0]->GetFormulaToken();
1631 const formula::SingleVectorRefToken
* tmpCurDVRNum1
=
1632 dynamic_cast<const formula::SingleVectorRefToken
*>(iNum1
);
1633 FormulaToken
*iNum2
= vSubArguments
[1]->GetFormulaToken();
1634 const formula::SingleVectorRefToken
* tmpCurDVRNum2
=
1635 dynamic_cast<const formula::SingleVectorRefToken
*>(iNum2
);
1636 ss
<< " int buffer_num1_len = "<<tmpCurDVRNum1
->GetArrayLength()<<";\n";
1637 ss
<< " int buffer_num2_len = "<<tmpCurDVRNum2
->GetArrayLength()<<";\n";
1638 ss
<< " if((gid0)>=buffer_num1_len || isNan(";
1639 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << "))\n";
1640 ss
<< " num1 = " << GetBottom() << ";\n";
1643 ss
<< " num1 = " << vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
1645 ss
<< " if((gid0)>=buffer_num2_len || isNan(";
1646 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << "))\n";
1647 ss
<< " num2 = " << GetBottom() << ";\n";
1650 ss
<< " num2 = " << vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
1651 ss
<< " return (long)num1 & (long)num2;\n";
1654 void OpLn::GenSlidingWindowFunction(
1655 std::stringstream
&ss
, const std::string sSymName
, SubArguments
&vSubArguments
)
1657 ss
<< "\ndouble " << sSymName
;
1658 ss
<< "_"<< BinFuncName() <<"(";
1659 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1663 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1666 ss
<< " int gid0=get_global_id(0);\n";
1667 ss
<< " int singleIndex = gid0;\n";
1669 GenTmpVariables(ss
,vSubArguments
);
1670 CheckAllSubArgumentIsNan(ss
,vSubArguments
);
1672 ss
<< " double tmp=log1p(tmp0-1);\n";
1673 ss
<< " return tmp;\n";
1677 void OpRound::GenSlidingWindowFunction(std::stringstream
&ss
,
1678 const std::string sSymName
, SubArguments
&vSubArguments
)
1680 ss
<< "\ndouble " << sSymName
;
1681 ss
<< "_"<< BinFuncName() <<"(";
1682 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1686 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1689 ss
<< " int gid0=get_global_id(0);\n";
1690 ss
<< " int singleIndex = gid0;\n";
1691 GenTmpVariables(ss
,vSubArguments
);
1692 CheckAllSubArgumentIsNan(ss
,vSubArguments
);
1693 ss
<< " for(int i=0;i<tmp1;i++)\n";
1694 ss
<< " tmp0 = tmp0 * 10;\n";
1695 ss
<< " double tmp=round(tmp0);\n";
1696 ss
<< " for(int i=0;i<tmp1;i++)\n";
1697 ss
<< " tmp = tmp / 10;\n";
1698 ss
<< " return tmp;\n";
1701 void OpRoundUp::GenSlidingWindowFunction(std::stringstream
&ss
,
1702 const std::string sSymName
, SubArguments
&vSubArguments
)
1704 ss
<< "\ndouble " << sSymName
;
1705 ss
<< "_"<< BinFuncName() <<"(";
1706 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1710 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1713 ss
<< " int gid0=get_global_id(0);\n";
1714 ss
<< " int singleIndex = gid0;\n";
1715 ss
<< " int intTmp;\n";
1716 ss
<< " double doubleTmp;\n";
1717 ss
<< " double tmp;\n";
1718 GenTmpVariables(ss
,vSubArguments
);
1719 CheckAllSubArgumentIsNan(ss
,vSubArguments
);
1720 ss
<< " if(tmp1 >20 || tmp1 < -20)";
1722 ss
<< " tmp = NAN;\n";
1725 ss
<< " for(int i=0;i<tmp1;i++)\n";
1726 ss
<< " tmp0 = tmp0 * 10;\n";
1727 ss
<< " intTmp = (int)tmp0;\n";
1728 ss
<< " doubleTmp = intTmp;\n";
1729 ss
<< " if(isequal(doubleTmp,tmp0))\n";
1730 ss
<< " tmp = doubleTmp;\n";
1732 ss
<< " tmp = doubleTmp + 1;\n";
1733 ss
<< " for(int i=0;i<tmp1;i++)\n";
1734 ss
<< " tmp = tmp / 10;\n";
1736 ss
<< " return tmp;\n";
1739 void OpRoundDown::GenSlidingWindowFunction(std::stringstream
&ss
,
1740 const std::string sSymName
, SubArguments
&vSubArguments
)
1742 ss
<< "\ndouble " << sSymName
;
1743 ss
<< "_"<< BinFuncName() <<"(";
1744 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1748 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1751 ss
<< " int gid0=get_global_id(0);\n";
1752 ss
<< " int singleIndex = gid0;\n";
1753 ss
<< " int intTmp;\n";
1754 ss
<< " double tmp;\n";
1755 GenTmpVariables(ss
,vSubArguments
);
1756 CheckAllSubArgumentIsNan(ss
,vSubArguments
);
1757 ss
<< " if(tmp1 >20 || tmp1 < -20)";
1759 ss
<< " tmp = NAN;\n";
1762 ss
<< " for(int i=0;i<tmp1;i++)\n";
1763 ss
<< " tmp0 = tmp0 * 10;\n";
1764 ss
<< " intTmp = (int)tmp0;\n";
1765 ss
<< " tmp = intTmp;\n";
1766 ss
<< " for(int i=0;i<tmp1;i++)\n";
1767 ss
<< " tmp = tmp / 10;\n";
1769 ss
<< " return tmp;\n";
1772 void OpInt::GenSlidingWindowFunction(std::stringstream
&ss
,
1773 const std::string sSymName
, SubArguments
&vSubArguments
)
1775 ss
<< "\ndouble " << sSymName
;
1776 ss
<< "_"<< BinFuncName() <<"(";
1777 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1781 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1784 ss
<< " int gid0=get_global_id(0);\n";
1785 ss
<< " int singleIndex = gid0;\n";
1786 ss
<< " int intTmp;\n";
1787 ss
<< " double tmp;\n";
1788 GenTmpVariables(ss
,vSubArguments
);
1789 CheckAllSubArgumentIsNan(ss
,vSubArguments
);
1790 ss
<< " intTmp = (int)tmp0;\n";
1791 ss
<< " tmp = intTmp;\n";
1792 ss
<< " return tmp;\n";
1795 void OpNegSub::GenSlidingWindowFunction(std::stringstream
&ss
,
1796 const std::string sSymName
, SubArguments
&vSubArguments
)
1798 ss
<< "\ndouble " << sSymName
;
1799 ss
<< "_"<< BinFuncName() <<"(";
1800 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1804 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1807 ss
<< " int gid0=get_global_id(0);\n";
1808 ss
<< " int singleIndex = gid0;\n";
1809 GenTmpVariables(ss
,vSubArguments
);
1810 CheckAllSubArgumentIsNan(ss
,vSubArguments
);
1811 ss
<< " return -tmp0;\n";
1815 void OpRadians::GenSlidingWindowFunction(std::stringstream
&ss
,
1816 const std::string sSymName
, SubArguments
&vSubArguments
)
1818 ss
<< "\ndouble " << sSymName
;
1819 ss
<< "_"<< BinFuncName() <<"(";
1820 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1824 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1827 ss
<< " int gid0=get_global_id(0);\n";
1828 ss
<< " int singleIndex = gid0;\n";
1829 ss
<< " double tmp;\n";
1830 GenTmpVariables(ss
,vSubArguments
);
1831 CheckAllSubArgumentIsNan(ss
,vSubArguments
);
1832 ss
<< " tmp = tmp0 * 3.141592657 * pow(180.0,-1);\n";
1833 ss
<< " return tmp;\n";
1836 void OpIsEven::GenSlidingWindowFunction(std::stringstream
&ss
,
1837 const std::string sSymName
, SubArguments
&vSubArguments
)
1839 ss
<< "\ndouble " << sSymName
;
1840 ss
<< "_"<< BinFuncName() <<"(";
1841 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1845 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1848 ss
<< " int gid0=get_global_id(0);\n";
1849 ss
<< " int singleIndex = gid0;\n";
1850 ss
<< " double tmp;\n";
1851 GenTmpVariables(ss
,vSubArguments
);
1852 CheckAllSubArgumentIsNan(ss
,vSubArguments
);
1853 ss
<< " tmp = (fmod(floor(fabs(tmp0)), 2.0)<0.5);\n";
1854 ss
<< " return tmp;\n";
1857 void OpIsOdd::GenSlidingWindowFunction(std::stringstream
&ss
,
1858 const std::string sSymName
, SubArguments
&vSubArguments
)
1860 ss
<< "\ndouble " << sSymName
;
1861 ss
<< "_"<< BinFuncName() <<"(";
1862 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1866 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1869 ss
<< " int gid0=get_global_id(0);\n";
1870 ss
<< " int singleIndex = gid0;\n";
1871 ss
<< " double tmp;\n";
1872 GenTmpVariables(ss
,vSubArguments
);
1873 CheckAllSubArgumentIsNan(ss
,vSubArguments
);
1874 ss
<< " tmp = !(fmod(floor(fabs(tmp0)), 2.0)<0.5);\n";
1875 ss
<< " return tmp;\n";
1878 void OpOdd::GenSlidingWindowFunction(
1879 std::stringstream
&ss
, const std::string sSymName
,
1880 SubArguments
&vSubArguments
)
1882 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
1883 const formula::SingleVectorRefToken
*tmpCurDVR
= dynamic_cast<const
1884 formula::SingleVectorRefToken
*>(tmpCur
);
1885 ss
<< Math_Intg_Str
;
1886 ss
<< "\ndouble " << sSymName
;
1887 ss
<< "_"<< BinFuncName() <<"(";
1888 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1892 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1895 ss
<<" int gid0=get_global_id(0);\n";
1896 ss
<< " double tmp=0;\n";
1897 ss
<< " double arg0 = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
1900 ss
<< " if(isNan(arg0)||(gid0>=";
1901 ss
<<tmpCurDVR
->GetArrayLength();
1905 ss
<< " if (arg0 > 0.0 ){\n";
1906 ss
<< " tmp=Intg(arg0);\n";
1907 ss
<< " if(tmp-trunc(tmp/2)*2 == 0)\n";
1908 ss
<< " tmp=tmp+1;\n";
1909 ss
<< " }else if (arg0 < 0.0 ){\n";
1910 ss
<< " tmp=Intg(arg0);\n";
1911 ss
<< " if(tmp-trunc(tmp/2)*2 == 0)\n";
1912 ss
<< " tmp=tmp-1.0;\n";
1913 ss
<< " }else if (arg0 == 0.0 )\n";
1914 ss
<< " tmp=1.0;\n";
1915 ss
<< " return tmp;\n";
1918 void OpCountIf::GenSlidingWindowFunction(std::stringstream
&ss
,
1919 const std::string sSymName
, SubArguments
&vSubArguments
)
1921 ss
<< "\ndouble " << sSymName
;
1922 ss
<< "_"<< BinFuncName() <<"(";
1923 for (unsigned i
= 0; i
< 2; i
++)
1927 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1931 ss
<< " int gid0=get_global_id(0);\n";
1932 ss
<< " double vara, varb;\n";
1933 ss
<< " int varc = 0;\n";
1934 FormulaToken
*tmpCur
= vSubArguments
[1]->GetFormulaToken();
1936 if(ocPush
== vSubArguments
[1]->GetFormulaToken()->GetOpCode())
1938 if(tmpCur
->GetType() == formula::svSingleVectorRef
)
1940 const formula::SingleVectorRefToken
* tmpCurDVR
=
1942 const formula::SingleVectorRefToken
*>(tmpCur
);
1944 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
1947 ss
<< " if(isNan(varb)||(gid0>=";
1948 ss
<< tmpCurDVR
->GetArrayLength();
1950 ss
<< " varb = 0;\n";
1953 else if(tmpCur
->GetType() == formula::svDouble
)
1956 ss
<< tmpCur
->GetDouble() << ";\n";
1962 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
1965 tmpCur
= vSubArguments
[0]->GetFormulaToken();
1967 if(ocPush
== vSubArguments
[0]->GetFormulaToken()->GetOpCode())
1970 if (tmpCur
->GetType() == formula::svDoubleVectorRef
)
1972 const formula::DoubleVectorRefToken
* pDVR
=
1973 dynamic_cast<const formula::DoubleVectorRefToken
*>(tmpCur
);
1974 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
1975 ss
<< " for (int i = ";
1976 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
1979 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
1980 ss
<< " && i < " << nCurWindowSize
<< "; ++i)\n";
1983 ss
<< "gid0; i < "<< nCurWindowSize
<< "; ++i)\n";
1987 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
1990 ss
<< "0; i < " << pDVR
->GetArrayLength();
1991 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; ++i)\n";
1994 ss
<< "0; i < gid0+"<< nCurWindowSize
<< "; ++i)\n";
1998 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
2001 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
2002 ss
<< " && i < "<< nCurWindowSize
<< "; ++i)\n";
2005 ss
<< "0; i < "<< nCurWindowSize
<< "; ++i)\n";
2012 ss
<< "0; i < "<< nCurWindowSize
<< "; ++i)\n";
2015 ss
<< "0; i < "<< nCurWindowSize
<< "; ++i)\n";
2020 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
2023 ss
<< " if (isNan(vara))\n";
2024 ss
<< " continue;\n";
2026 ss
<< " (vara == varb) && varc++;\n";
2029 else if(tmpCur
->GetType() == formula::svSingleVectorRef
)
2031 const formula::SingleVectorRefToken
* tmpCurDVR
=
2033 const formula::SingleVectorRefToken
*>(tmpCur
);
2035 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
2038 ss
<< " if(isNan(vara)||(gid0>=";
2039 ss
<< tmpCurDVR
->GetArrayLength();
2041 ss
<< " return 0;\n";
2042 ss
<< " (vara == varb) && varc++;\n";
2046 ss
<< " return varc;\n";
2049 void OpSumIf::GenSlidingWindowFunction(std::stringstream
&ss
,
2050 const std::string sSymName
, SubArguments
&vSubArguments
)
2052 ss
<< "\ndouble " << sSymName
;
2053 ss
<< "_"<< BinFuncName() <<"(";
2055 (3 == vSubArguments
.size()) && (flag
= 2);
2056 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2060 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2064 ss
<< " int gid0=get_global_id(0);\n";
2065 ss
<< " double vara, varb, varc, sum = 0.0f;\n";
2066 FormulaToken
*tmpCur
= vSubArguments
[1]->GetFormulaToken();
2068 if(ocPush
== vSubArguments
[1]->GetFormulaToken()->GetOpCode())
2070 if(tmpCur
->GetType() == formula::svSingleVectorRef
)
2072 const formula::SingleVectorRefToken
* tmpCurDVR
=
2074 const formula::SingleVectorRefToken
*>(tmpCur
);
2076 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
2079 ss
<< " if(isNan(varb)||(gid0>=";
2080 ss
<< tmpCurDVR
->GetArrayLength();
2082 ss
<< " varb = 0;\n";
2085 else if(tmpCur
->GetType() == formula::svDouble
)
2088 ss
<< tmpCur
->GetDouble() << ";\n";
2094 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef();
2097 tmpCur
= vSubArguments
[0]->GetFormulaToken();
2099 if(ocPush
== vSubArguments
[0]->GetFormulaToken()->GetOpCode())
2102 if (tmpCur
->GetType() == formula::svDoubleVectorRef
)
2104 const formula::DoubleVectorRefToken
* pDVR
=
2105 dynamic_cast<const formula::DoubleVectorRefToken
*>(tmpCur
);
2106 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
2107 ss
<< " for (int i = ";
2108 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
2111 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
2112 ss
<< " && i < " << nCurWindowSize
<< "; ++i)\n";
2115 ss
<< "gid0; i < "<< nCurWindowSize
<< "; ++i)\n";
2119 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
2122 ss
<< "0; i < " << pDVR
->GetArrayLength();
2123 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; ++i)\n";
2126 ss
<< "0; i < gid0+"<< nCurWindowSize
<< "; ++i)\n";
2130 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
2133 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
2134 ss
<< " && i < "<< nCurWindowSize
<< "; ++i)\n";
2137 ss
<< "0; i < "<< nCurWindowSize
<< "; ++i)\n";
2144 ss
<< "0; i < "<< nCurWindowSize
<< "; ++i)\n";
2147 ss
<< "0; i < "<< nCurWindowSize
<< "; ++i)\n";
2152 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
2155 ss
<< " if (isNan(vara))\n";
2156 ss
<< " continue;\n";
2159 ss
<< vSubArguments
[flag
]->GenSlidingWindowDeclRef();
2162 ss
<< " if (isNan(varc))\n";
2163 ss
<< " varc = 0.0f;\n";
2165 ss
<< " (vara == varb)&&(sum = sum + varc);\n";
2168 else if(tmpCur
->GetType() == formula::svSingleVectorRef
)
2170 const formula::SingleVectorRefToken
* tmpCurDVR
=
2172 const formula::SingleVectorRefToken
*>(tmpCur
);
2174 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
2177 ss
<< " if(isNan(vara)||(gid0>=";
2178 ss
<< tmpCurDVR
->GetArrayLength();
2180 ss
<< " return 0;\n";
2182 ss
<< " int i = 0;\n";
2184 ss
<< vSubArguments
[flag
]->GenSlidingWindowDeclRef();
2187 ss
<< " if(isNan(varc)||(gid0>=";
2188 ss
<< tmpCurDVR
->GetArrayLength();
2190 ss
<< " varc = 0.0f;\n";
2193 ss
<< " (vara == varb)&&(sum = sum + varc);\n";
2197 ss
<< " return sum;\n";
2200 void OpTrunc::GenSlidingWindowFunction(std::stringstream
&ss
,
2201 const std::string sSymName
, SubArguments
&vSubArguments
)
2203 ss
<< "\ndouble " << sSymName
;
2204 ss
<< "_"<< BinFuncName() <<"(";
2205 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2209 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2213 ss
<< " int gid0=get_global_id(0);\n";
2214 ss
<< " double arg[2];\n";
2215 for( unsigned i
=0; i
< vSubArguments
.size(); ++i
)
2217 FormulaToken
*tmpCur
= vSubArguments
[i
]->GetFormulaToken();
2219 if(ocPush
== vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
2221 if(tmpCur
->GetType() == formula::svDoubleVectorRef
)
2223 const formula::DoubleVectorRefToken
* tmpCurDVR
=
2225 const formula::DoubleVectorRefToken
*>(tmpCur
);
2226 ss
<< " int i = 0;\n";
2227 ss
<< " arg["<<i
<<"] = ";
2228 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2231 ss
<< " if(isNan(arg["<<i
;
2232 ss
<< "])||(gid0>=";
2233 ss
<< tmpCurDVR
->GetArrayLength();
2239 else if(tmpCur
->GetType() == formula::svSingleVectorRef
)
2241 const formula::SingleVectorRefToken
* tmpCurDVR
=
2243 const formula::SingleVectorRefToken
*>(tmpCur
);
2244 ss
<< " arg["<<i
<<"] = ";
2245 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2248 ss
<< " if(isNan(arg["<<i
;
2249 ss
<< "])||(gid0>=";
2250 ss
<< tmpCurDVR
->GetArrayLength();
2256 else if(tmpCur
->GetType() == formula::svDouble
)
2258 ss
<< " arg["<<i
<<"] = ";
2259 ss
<< tmpCur
->GetDouble() << ";\n";
2264 ss
<< " arg["<<i
<<"] = ";
2265 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2269 ss
<< " double argm = arg[0];\n";
2270 ss
<< " int n = (int)arg[1];\n";
2271 ss
<< " double nn = 1.0f;\n";
2272 ss
<< " for(int i = 0; i < n; ++i)\n";
2274 ss
<< " argm = argm * 10;\n";
2275 ss
<< " nn = nn * 10;\n";
2277 ss
<< " modf(argm, &argm);\n";
2278 ss
<< " return argm / nn;\n";
2281 void OpFloor::GenSlidingWindowFunction(
2282 std::stringstream
&ss
, const std::string sSymName
,
2283 SubArguments
&vSubArguments
)
2285 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
2286 const formula::SingleVectorRefToken
*tmpCurDVR
= dynamic_cast<const
2287 formula::SingleVectorRefToken
*>(tmpCur
);
2288 ss
<< "\ndouble " << sSymName
;
2289 ss
<< "_"<< BinFuncName() <<"(";
2290 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2294 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2297 ss
<<" int gid0=get_global_id(0);\n";
2298 ss
<< " double arg0 = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
2300 ss
<< " double arg1 = " << vSubArguments
[1]->GenSlidingWindowDeclRef();
2302 ss
<< " double arg2 = " << vSubArguments
[2]->GenSlidingWindowDeclRef();
2305 ss
<< " if(isNan(arg0)||(gid0>=";
2306 ss
<<tmpCurDVR
->GetArrayLength();
2309 ss
<< " if(isNan(arg1)||(gid0>=";
2310 ss
<<tmpCurDVR
->GetArrayLength();
2313 ss
<< " if(isNan(arg2)||(gid0>=";
2314 ss
<<tmpCurDVR
->GetArrayLength();
2318 ss
<<" if(arg1==0.0)\n";
2319 ss
<<" return 0.0;\n";
2320 ss
<<" else if(arg0*arg1<0.0)\n";
2321 ss
<<" return 0.0000000001;\n";
2322 ss
<<" else if(arg2==0.0&&arg0<0.0)\n";
2323 ss
<<" return (trunc(arg0/arg1)+1)*arg1;\n";
2325 ss
<<" return trunc(arg0/arg1)*arg1;\n";
2328 void OpBitOr::GenSlidingWindowFunction(std::stringstream
&ss
,
2329 const std::string sSymName
, SubArguments
&vSubArguments
)
2331 ss
<< "\ndouble " << sSymName
;
2332 ss
<< "_"<< BinFuncName() <<"(";
2333 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2336 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2339 ss
<< " int gid0 = get_global_id(0);\n";
2340 ss
<< " double num1 = " << GetBottom() << ";\n";
2341 ss
<< " double num2 = " << GetBottom() << ";\n";
2343 FormulaToken
*iNum1
= vSubArguments
[0]->GetFormulaToken();
2344 const formula::SingleVectorRefToken
* tmpCurDVRNum1
=
2345 dynamic_cast<const formula::SingleVectorRefToken
*>(iNum1
);
2346 FormulaToken
*iNum2
= vSubArguments
[1]->GetFormulaToken();
2347 const formula::SingleVectorRefToken
* tmpCurDVRNum2
=
2348 dynamic_cast<const formula::SingleVectorRefToken
*>(iNum2
);
2349 ss
<< " int buffer_num1_len = "<<tmpCurDVRNum1
->GetArrayLength()<<";\n";
2350 ss
<< " int buffer_num2_len = "<<tmpCurDVRNum2
->GetArrayLength()<<";\n";
2351 ss
<< " if((gid0)>=buffer_num1_len || isNan(";
2352 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << "))\n";
2353 ss
<< " num1 = " << GetBottom() << ";\n";
2356 ss
<< " num1 = floor(" << vSubArguments
[0]->GenSlidingWindowDeclRef();
2359 ss
<< " if((gid0)>=buffer_num2_len || isNan(";
2360 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << "))\n";
2361 ss
<< " num2 = " << GetBottom() << ";\n";
2364 ss
<< " num2 = floor(" << vSubArguments
[1]->GenSlidingWindowDeclRef();
2366 ss
<< " return (long)num1 | (long)num2;\n";
2369 void OpBitXor::GenSlidingWindowFunction(std::stringstream
&ss
,
2370 const std::string sSymName
, SubArguments
&vSubArguments
)
2372 ss
<< "\ndouble " << sSymName
;
2373 ss
<< "_"<< BinFuncName() <<"(";
2374 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2377 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2380 ss
<< " int gid0 = get_global_id(0);\n";
2381 ss
<< " double num1 = " << GetBottom() << ";\n";
2382 ss
<< " double num2 = " << GetBottom() << ";\n";
2384 FormulaToken
*iNum1
= vSubArguments
[0]->GetFormulaToken();
2385 const formula::SingleVectorRefToken
* tmpCurDVRNum1
=
2386 dynamic_cast<const formula::SingleVectorRefToken
*>(iNum1
);
2387 FormulaToken
*iNum2
= vSubArguments
[1]->GetFormulaToken();
2388 const formula::SingleVectorRefToken
* tmpCurDVRNum2
=
2389 dynamic_cast<const formula::SingleVectorRefToken
*>(iNum2
);
2390 ss
<< " int buffer_num1_len = " << tmpCurDVRNum1
->GetArrayLength() << ";\n";
2391 ss
<< " int buffer_num2_len = " << tmpCurDVRNum2
->GetArrayLength() << ";\n";
2393 ss
<< " if((gid0)>=buffer_num1_len || isNan(";
2394 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << "))\n";
2395 ss
<< " num1 = " << GetBottom() << ";\n";
2398 ss
<< " num1 = floor(" << vSubArguments
[0]->GenSlidingWindowDeclRef();
2401 ss
<< " if((gid0)>=buffer_num2_len || isNan(";
2402 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << "))\n";
2403 ss
<< " num2 = " << GetBottom() << ";\n";
2406 ss
<< " num2 = floor(" << vSubArguments
[1]->GenSlidingWindowDeclRef();
2408 ss
<< " return (long)num1 ^ (long)num2;\n";
2411 void OpBitLshift::GenSlidingWindowFunction(std::stringstream
&ss
,
2412 const std::string sSymName
, SubArguments
&vSubArguments
)
2414 ss
<< "\ndouble " << sSymName
;
2415 ss
<< "_"<< BinFuncName() <<"(";
2416 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2419 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2422 ss
<< " int gid0 = get_global_id(0);\n";
2423 ss
<< " double num = " << GetBottom() << ";\n";
2424 ss
<< " double shift_amount = " << GetBottom() << ";\n";
2426 FormulaToken
*iNum
= vSubArguments
[0]->GetFormulaToken();
2427 const formula::SingleVectorRefToken
* tmpCurDVRNum
=
2428 dynamic_cast<const formula::SingleVectorRefToken
*>(iNum
);
2429 FormulaToken
*iShiftAmount
= vSubArguments
[1]->GetFormulaToken();
2430 const formula::SingleVectorRefToken
* tmpCurDVRShiftAmount
=
2431 dynamic_cast<const formula::SingleVectorRefToken
*>(iShiftAmount
);
2432 ss
<< " int buffer_num_len = "<< tmpCurDVRNum
->GetArrayLength()<<";\n";
2433 ss
<< " int buffer_shift_amount_len = ";
2434 ss
<< tmpCurDVRShiftAmount
->GetArrayLength() << ";\n";
2435 ss
<< " if((gid0)>=buffer_num_len || isNan(";
2436 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << "))\n";
2437 ss
<< " num = " << GetBottom() << ";\n";
2440 ss
<< " num = floor(";
2441 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ");\n";
2443 ss
<< " if((gid0)>=buffer_shift_amount_len || isNan(";
2444 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << "))\n";
2445 ss
<< " shift_amount = " << GetBottom() << ";\n";
2448 ss
<< " shift_amount = floor(";
2449 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ");\n";
2450 ss
<< " return floor(" << "shift_amount >= 0 ? ";
2451 ss
<< "num * pow(2.0, shift_amount) : ";
2452 ss
<< "num / pow(2.0, fabs(shift_amount)));\n";
2455 void OpBitRshift::GenSlidingWindowFunction(std::stringstream
&ss
,
2456 const std::string sSymName
, SubArguments
&vSubArguments
)
2458 ss
<< "\ndouble " << sSymName
;
2459 ss
<< "_"<< BinFuncName() <<"(";
2460 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2463 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2466 ss
<< " int gid0 = get_global_id(0);\n";
2467 ss
<< " double num = " << GetBottom() << ";\n";
2468 ss
<< " double shift_amount = " << GetBottom() << ";\n";
2470 FormulaToken
*iNum
= vSubArguments
[0]->GetFormulaToken();
2471 const formula::SingleVectorRefToken
* tmpCurDVRNum
=
2472 dynamic_cast<const formula::SingleVectorRefToken
*>(iNum
);
2473 FormulaToken
*iShiftAmount
= vSubArguments
[1]->GetFormulaToken();
2474 const formula::SingleVectorRefToken
* tmpCurDVRShiftAmount
=
2475 dynamic_cast<const formula::SingleVectorRefToken
*>(iShiftAmount
);
2476 ss
<< " int buffer_num_len = ";
2477 ss
<< tmpCurDVRNum
->GetArrayLength() << ";\n";
2478 ss
<< " int buffer_shift_amount_len = ";
2479 ss
<< tmpCurDVRShiftAmount
->GetArrayLength() << ";\n";
2481 ss
<< " if((gid0)>=buffer_num_len || isNan(";
2482 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << "))\n";
2483 ss
<< " num = " << GetBottom() << ";\n";
2486 ss
<< " num = floor(";
2487 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ");\n";
2489 ss
<< " if((gid0)>=buffer_shift_amount_len || isNan(";
2490 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << "))\n";
2491 ss
<< " shift_amount = " <<GetBottom()<< ";\n";
2494 ss
<< " shift_amount = floor(";
2495 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ");\n";
2496 ss
<< " return floor(";
2497 ss
<< "shift_amount >= 0 ? num / pow(2.0, shift_amount) : ";
2498 ss
<< "num * pow(2.0, fabs(shift_amount)));\n";
2501 void OpSumSQ::GenSlidingWindowFunction(std::stringstream
&ss
,
2502 const std::string sSymName
, SubArguments
&vSubArguments
)
2504 ss
<< "\ndouble " << sSymName
;
2505 ss
<< "_"<< BinFuncName() <<"(";
2506 for (unsigned i
= 0; i
< vSubArguments
.size(); ++i
)
2510 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2514 ss
<< " int gid0=get_global_id(0);\n";
2515 ss
<< " double sum = 0.0f, arg;\n";
2516 for( unsigned i
=0; i
< vSubArguments
.size(); ++i
)
2518 FormulaToken
*tmpCur
= vSubArguments
[i
]->GetFormulaToken();
2520 if(ocPush
== vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
2522 if (tmpCur
->GetType() == formula::svDoubleVectorRef
)
2524 const formula::DoubleVectorRefToken
* pDVR
=
2525 dynamic_cast<const formula::DoubleVectorRefToken
*>(tmpCur
);
2526 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
2527 ss
<< " for (int i = ";
2528 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
2531 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
2532 ss
<< " && i < " << nCurWindowSize
<< "; ++i)\n";
2535 ss
<< "gid0; i < "<< nCurWindowSize
<< "; ++i)\n";
2539 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
2542 ss
<< "0; i < " << pDVR
->GetArrayLength();
2543 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; ++i)\n";
2546 ss
<< "0; i < gid0+"<< nCurWindowSize
<< "; ++i)\n";
2550 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
2553 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
2554 ss
<< " && i < "<< nCurWindowSize
<< "; ++i)\n";
2557 ss
<< "0; i < "<< nCurWindowSize
<< "; ++i)\n";
2564 ss
<< "0; i < "<< nCurWindowSize
<< "; ++i)\n";
2567 ss
<< "0; i < "<< nCurWindowSize
<< "; ++i)\n";
2572 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2575 ss
<< " if (isNan(arg))\n";
2576 ss
<< " continue;\n";
2578 ss
<< " sum += pown(arg, 2);\n";
2581 else if(tmpCur
->GetType() == formula::svSingleVectorRef
)
2583 const formula::SingleVectorRefToken
* tmpCurDVR
=
2585 const formula::SingleVectorRefToken
*>(tmpCur
);
2587 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2590 ss
<< " if(isNan(arg)||(gid0>=";
2591 ss
<< tmpCurDVR
->GetArrayLength();
2593 ss
<< " arg = 0.0f;\n";
2594 ss
<< " sum += pown(arg, 2);\n";
2597 else if(tmpCur
->GetType() == formula::svDouble
)
2600 ss
<< tmpCur
->GetDouble() << ";\n";
2601 ss
<< " sum += pown(arg, 2);\n";
2607 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2609 ss
<< " sum += pown(arg, 2);\n";
2612 ss
<< " return sum;\n";
2615 void OpSqrtPi::GenSlidingWindowFunction(std::stringstream
&ss
,
2616 const std::string sSymName
, SubArguments
&vSubArguments
)
2618 ss
<< "\ndouble " << sSymName
;
2619 ss
<< "_"<< BinFuncName() <<"(";
2620 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2624 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2628 ss
<< " int gid0=get_global_id(0);\n";
2629 ss
<< " double arg0 = 0.0f;\n";
2630 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
2632 if(ocPush
== vSubArguments
[0]->GetFormulaToken()->GetOpCode())
2634 if(tmpCur
->GetType() == formula::svSingleVectorRef
)
2636 const formula::SingleVectorRefToken
*tmpCurDVR
=
2638 <const formula::SingleVectorRefToken
*>(tmpCur
);
2640 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
2644 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
2646 ss
<< tmpCurDVR
->GetArrayLength();
2648 ss
<< " { arg0 = 0.0f; }\n";
2651 else if(tmpCur
->GetType() == formula::svDouble
)
2654 ss
<< tmpCur
->GetDouble() << ";\n";
2660 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
2663 ss
<< " return (double)sqrt(arg0 *";
2664 ss
<< " 3.1415926535897932384626433832795f);\n";
2667 void OpCeil::GenSlidingWindowFunction(std::stringstream
&ss
,
2668 const std::string sSymName
, SubArguments
&vSubArguments
)
2670 ss
<< "\ndouble " << sSymName
;
2671 ss
<< "_"<< BinFuncName() <<"(";
2672 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2675 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2678 ss
<< " int gid0 = get_global_id(0);\n";
2679 ss
<< " double num = " << GetBottom() << ";\n";
2680 ss
<< " double significance = " << GetBottom() << ";\n";
2681 ss
<< " double bAbs = 0;\n";
2684 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << "))\n";
2685 ss
<< " num = " << GetBottom() << ";\n";
2688 ss
<< " num = " << vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
2691 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << "))\n";
2692 ss
<< " return 0.0;\n";
2695 ss
<< " significance = ";
2696 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
2697 if (vSubArguments
.size() > 2)
2700 FormulaToken
*bAbs
= vSubArguments
[2]->GetFormulaToken();
2701 if(bAbs
->GetType() == formula::svSingleVectorRef
)
2703 const formula::SingleVectorRefToken
* tmpCurSVRIsAbs
=
2704 dynamic_cast<const formula::SingleVectorRefToken
*>(bAbs
);
2705 ss
<< " if((gid0)>=" << tmpCurSVRIsAbs
->GetArrayLength() << " ||";
2707 if(bAbs
->GetType() == formula::svDoubleVectorRef
)
2709 const formula::DoubleVectorRefToken
* tmpCurDVRIsAbs
=
2710 dynamic_cast<const formula::DoubleVectorRefToken
*>(bAbs
);
2711 ss
<< " if((gid0)>=" << tmpCurDVRIsAbs
->GetArrayLength() << " ||";
2713 if(bAbs
->GetType() == formula::svDouble
)
2718 ss
<< vSubArguments
[2]->GenSlidingWindowDeclRef() << "))\n";
2719 ss
<< " bAbs = 0;\n";
2722 ss
<< " bAbs = "<<vSubArguments
[2]->GenSlidingWindowDeclRef()<<";\n";
2724 ss
<< " if(significance == 0.0)\n";
2725 ss
<< " return 0.0;\n";
2727 ss
<< "( !(int)bAbs && num < 0.0 ? floor( num / significance ) : ";
2728 ss
<< "ceil( num / significance ) )";
2729 ss
<< "*significance;\n";
2732 void OpKombin::GenSlidingWindowFunction(std::stringstream
&ss
,
2733 const std::string sSymName
, SubArguments
&vSubArguments
)
2735 ss
<< "\ndouble " << sSymName
;
2736 ss
<< "_"<< BinFuncName() <<"(";
2737 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2740 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2743 ss
<< " int gid0 = get_global_id(0);\n";
2744 ss
<< " double num = " << GetBottom() << ";\n";
2745 ss
<< " double num_chosen = " << GetBottom() << ";\n";
2746 ss
<< " double result = -1.0;\n";
2747 FormulaToken
*iNum
= vSubArguments
[0]->GetFormulaToken();
2748 FormulaToken
*iNumChosen
= vSubArguments
[1]->GetFormulaToken();
2751 if(ocPush
== vSubArguments
[0]->GetFormulaToken()->GetOpCode())
2753 if(iNum
->GetType() == formula::svSingleVectorRef
&&
2754 iNumChosen
->GetType() == formula::svSingleVectorRef
)
2758 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << "))\n";
2759 ss
<< " num = " << GetBottom() << ";\n";
2762 ss
<< " num = floor(";
2763 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ");\n";
2766 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << "))\n";
2767 ss
<< " num_chosen = " << GetBottom() << ";\n";
2770 ss
<< " num_chosen = floor(";
2771 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ");\n";
2773 else if(iNum
->GetType() == formula::svDouble
&&
2774 iNumChosen
->GetType() == formula::svDouble
)
2776 ss
<< " num = floor(" << iNum
->GetDouble() << ");\n";
2777 ss
<< " num_chosen = floor("<< iNumChosen
->GetDouble()<< ");\n";
2782 ss
<< " num = floor(";
2783 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ");\n";
2784 ss
<< " num_chosen = floor(";
2785 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << ");\n";
2787 ss
<< " result = select(result, 0.0, (ulong)(num < num_chosen));\n";
2788 ss
<< " result = select(result, 1.0, (ulong)(num_chosen == 0.0));\n";
2789 ss
<< " if(result == 0 || result ==1)\n";
2790 ss
<< " return result;\n";
2791 ss
<< " double4 db4num;\n";
2792 ss
<< " double4 db4num_chosen;\n";
2793 ss
<< " double4 db4result;\n";
2794 ss
<< " double2 db2result;\n";
2795 ss
<< " result = 1.0;\n";
2796 ss
<< " int loop = num_chosen/4;\n";
2797 ss
<< " for(int i=0; i<loop; i++)\n";
2799 ss
<< " db4num = (double4){num,\n";
2800 ss
<< " num-1.0,\n";
2801 ss
<< " num-2.0,\n";
2802 ss
<< " num-3.0};\n";
2803 ss
<< " db4num_chosen = (double4){num_chosen,\n";
2804 ss
<< " num_chosen-1.0,\n";
2805 ss
<< " num_chosen-2.0,\n";
2806 ss
<< " num_chosen-3.0};\n";
2807 ss
<< " db4result = db4num * pown(db4num_chosen, -1);\n";
2808 ss
<< " db2result = db4result.xy * db4result.zw;\n";
2809 ss
<< " result *= db2result.x * db2result.y;\n";
2810 ss
<< " num = num - 4.0;\n";
2811 ss
<< " num_chosen = num_chosen - 4.0;\n";
2813 ss
<< " while ( num_chosen > 0){\n";
2814 ss
<< " result *= num / num_chosen;\n";
2815 ss
<< " num = num - 1.0;\n";
2816 ss
<< " num_chosen = num_chosen - 1.0;\n";
2818 ss
<< " return result;\n";
2821 void OpConvert::GenSlidingWindowFunction(
2822 std::stringstream
&ss
, const std::string sSymName
,
2823 SubArguments
&vSubArguments
)
2825 int arg1
=vSubArguments
[1]->GetFormulaToken()->GetString().\
2826 getString().toAsciiUpperCase().hashCode();
2827 int arg2
=vSubArguments
[2]->GetFormulaToken()->GetString().\
2828 getString().toAsciiUpperCase().hashCode();
2829 if( !((arg1
==5584&&arg2
==108)||
2830 (arg1
==108&&arg2
==5584)||
2831 (arg1
==5665&&arg2
==268206)||
2832 (arg1
==268206&&arg2
==5665)) )
2835 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
2836 const formula::SingleVectorRefToken
*tmpCurDVR
= dynamic_cast<const
2837 formula::SingleVectorRefToken
*>(tmpCur
);
2838 ss
<< "\ndouble " << sSymName
;
2839 ss
<< "_"<< BinFuncName() <<"(";
2840 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2844 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2847 ss
<<" int gid0=get_global_id(0);\n";
2848 ss
<< " double arg0 = " << vSubArguments
[0]->GenSlidingWindowDeclRef();
2850 ss
<< " double arg1 = " << vSubArguments
[1]->GenSlidingWindowDeclRef();
2852 ss
<< " double arg2 = " << vSubArguments
[2]->GenSlidingWindowDeclRef();
2855 ss
<< " if(isNan(arg0)||(gid0>=";
2856 ss
<<tmpCurDVR
->GetArrayLength();
2859 ss
<< " if(isNan(arg1)||(gid0>=";
2860 ss
<<tmpCurDVR
->GetArrayLength();
2863 ss
<< " if(isNan(arg2)||(gid0>=";
2864 ss
<<tmpCurDVR
->GetArrayLength();
2868 ss
<<" if(arg1==5584U&&arg2==108U)\n";
2869 ss
<<" return arg0*1000.0;\n";
2870 ss
<<" else if(arg1==108U&&arg2==3385U)\n";
2871 ss
<<" return arg0/1000.0;\n";
2872 ss
<<" else if(arg1==5665U&&arg2==268206U)\n";
2873 ss
<<" return arg0*60.0;\n";
2874 ss
<<" else if(arg1==268206U&&arg2==5665U)\n";
2875 ss
<<" return arg0/60.0;\n";
2877 ss
<<" return -9999999999;\n";
2882 void OpProduct::GenSlidingWindowFunction(std::stringstream
&ss
,
2883 const std::string sSymName
, SubArguments
&vSubArguments
)
2885 ss
<< "\ndouble " << sSymName
;
2886 ss
<< "_"<< BinFuncName() <<"( ";
2887 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2891 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2894 ss
<< " int gid0 = get_global_id(0);\n";
2895 ss
<< " int i = 0;\n";
2896 ss
<< " double product=0.0;\n\n";
2897 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2899 std::stringstream ssArgNoI
;
2901 std::string sArgNoI
= ssArgNoI
.str();
2902 ss
<< std::string(" double arg")+sArgNoI
+";\n";
2903 FormulaToken
*pCur
= vSubArguments
[i
]->GetFormulaToken();
2905 if (pCur
->GetType() == formula::svDoubleVectorRef
)
2907 const formula::DoubleVectorRefToken
* pDVR
=
2908 dynamic_cast<const formula::DoubleVectorRefToken
*>(pCur
);
2909 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
2910 ss
<< std::string(" arg")+sArgNoI
+" = ";
2911 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2914 ss
<< std::string(" if(isNan(arg")+sArgNoI
+")||((gid0+i)>=";
2915 ss
<< pDVR
->GetArrayLength();
2918 ss
<< std::string(" arg")+sArgNoI
+" = 0;\n";
2921 ss
<< std::string(" product = arg")+sArgNoI
+";\n";
2923 ss
<< "1; i < "<< nCurWindowSize
<< "; i++)\n";
2925 ss
<< std::string(" arg")+sArgNoI
+" = ";
2926 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2929 ss
<<std::string(" if(isNan(arg")+sArgNoI
+")||((gid0+i)>=";
2930 ss
<< pDVR
->GetArrayLength();
2933 ss
<< std::string(" arg")+sArgNoI
+" = 0;\n";
2936 ss
<< std::string(" product*=arg")+sArgNoI
+";\n";
2939 else if (pCur
->GetType() == formula::svSingleVectorRef
)
2942 ss
<< std::string(" arg")+sArgNoI
+" = ";
2943 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2945 ss
<< std::string(" product*=arg")+sArgNoI
+";\n";
2948 else if (pCur
->GetType() == formula::svDouble
)
2951 ss
<< std::string(" arg")+sArgNoI
+" = ";
2952 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
2954 ss
<< std::string(" product*=arg")+sArgNoI
+";\n";
2958 ss
<< " return product;\n";
2961 void OpAverageIf::GenSlidingWindowFunction(std::stringstream
&ss
,
2962 const std::string sSymName
, SubArguments
&vSubArguments
)
2965 ss
<< "\ndouble " << sSymName
;
2966 ss
<< "_"<< BinFuncName() <<"(";
2967 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
2970 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
2973 ss
<< " int gid0=get_global_id(0);\n";
2974 ss
<< " double tmp =0;\n";
2975 ss
<< " double count=0;\n";
2976 ss
<< " int singleIndex =gid0;\n";
2977 ss
<< " int doubleIndex;\n";
2980 GenTmpVariables(ss
,vSubArguments
);
2982 unsigned paraOneIsDoubleVector
= 0;
2983 unsigned paraOneWidth
= 1;
2984 unsigned paraTwoWidth
= 1;
2985 unsigned paraThreeWidth
= 1;
2986 unsigned loopTimes
= 0;
2987 unsigned loopIndex
= 0;
2988 if(vSubArguments
[0]->GetFormulaToken()->GetType() ==
2989 formula::svDoubleVectorRef
)
2991 paraOneIsDoubleVector
= 1;
2992 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
2993 const formula::DoubleVectorRefToken
*pCurDVR0
= dynamic_cast<const
2994 formula::DoubleVectorRefToken
*>(tmpCur0
);
2995 paraOneWidth
= pCurDVR0
->GetArrays().size();
2996 loopTimes
= paraOneWidth
;
2997 if(paraOneWidth
> 1)
3003 if(vSubArguments
[paraOneWidth
]->GetFormulaToken()->GetType() ==
3004 formula::svDoubleVectorRef
)
3007 FormulaToken
*tmpCur1
= vSubArguments
[1]->GetFormulaToken();
3008 const formula::DoubleVectorRefToken
*pCurDVR1
= dynamic_cast<const
3009 formula::DoubleVectorRefToken
*>(tmpCur1
);
3010 paraTwoWidth
= pCurDVR1
->GetArrays().size();
3011 if(paraTwoWidth
> 1)
3016 if (!pCurDVR1
->IsStartFixed() && pCurDVR1
->IsEndFixed()) {
3021 if(!pCurDVR1
->IsStartFixed() && !pCurDVR1
->IsEndFixed())
3023 ss
<< " doubleIndex =i+gid0;\n";
3026 ss
<< " doubleIndex =i;\n";
3030 CheckSubArgumentIsNan(ss
,vSubArguments
,paraOneWidth
);
3032 unsigned paraThreeIndex
= paraOneWidth
+ paraTwoWidth
;
3033 if(vSubArguments
.size() > paraThreeIndex
)
3035 if(vSubArguments
[paraThreeIndex
]->GetFormulaToken()->GetType() ==
3036 formula::svDoubleVectorRef
)
3038 FormulaToken
*tmpCur2
=
3039 vSubArguments
[paraThreeIndex
]->GetFormulaToken();
3040 const formula::DoubleVectorRefToken
*pCurDVR2
= dynamic_cast<const
3041 formula::DoubleVectorRefToken
*>(tmpCur2
);
3042 paraThreeWidth
= pCurDVR2
->GetArrays().size();
3043 if(paraThreeWidth
> 1)
3050 if(paraOneIsDoubleVector
)
3052 FormulaToken
*tmpCur0
= vSubArguments
[0]->GetFormulaToken();
3053 const formula::DoubleVectorRefToken
*pCurDVR0
= dynamic_cast<const
3054 formula::DoubleVectorRefToken
*>(tmpCur0
);
3055 size_t nCurWindowSize
= pCurDVR0
->GetArrayLength() <
3056 pCurDVR0
->GetRefRowSize() ? pCurDVR0
->GetArrayLength():
3057 pCurDVR0
->GetRefRowSize() ;
3059 for(loopIndex
=0; loopIndex
< loopTimes
; loopIndex
++)
3062 if (!pCurDVR0
->IsStartFixed() && pCurDVR0
->IsEndFixed()) {
3063 ss
<< "gid0; i < "<< nCurWindowSize
<<"; i++)\n";
3064 } else if (pCurDVR0
->IsStartFixed() && !pCurDVR0
->IsEndFixed()) {
3065 ss
<< "0; i < gid0+"<< nCurWindowSize
<<"; i++)\n";
3067 ss
<< "0; i < "<< nCurWindowSize
<<"; i++)\n";
3070 if(!pCurDVR0
->IsStartFixed() && !pCurDVR0
->IsEndFixed())
3072 ss
<< " doubleIndex =i+gid0;\n";
3075 ss
<< " doubleIndex =i;\n";
3078 CheckSubArgumentIsNan(ss
,vSubArguments
, loopIndex
);
3080 ss
<< " if ( isequal( tmp";
3081 ss
<< loopIndex
<<" , tmp"<<paraOneWidth
<<") ) \n";
3083 if(vSubArguments
.size() == paraThreeIndex
)
3084 ss
<< " tmp += tmp"<<loopIndex
<<";\n";
3087 CheckSubArgumentIsNan(ss
,vSubArguments
,
3088 paraThreeIndex
+loopIndex
);
3089 ss
<< " tmp += tmp";
3090 ss
<< paraThreeIndex
+loopIndex
<<";\n";
3092 ss
<< " count+=1.0;\n";
3099 CheckSubArgumentIsNan(ss
,vSubArguments
, 0);
3100 ss
<< " if ( isequal( tmp0 , tmp1 ) ) \n";
3102 if(vSubArguments
.size() == 2)
3103 ss
<< " tmp += tmp0;\n";
3106 CheckSubArgumentIsNan(ss
,vSubArguments
,2);
3107 ss
<< " tmp += tmp2;\n";
3109 ss
<< " count+=1.0;\n";
3113 ss
<< " if(count!=0)\n";
3114 ss
<< " tmp=tmp/count;\n";
3116 ss
<< " tmp= 0 ;\n";
3117 ss
<< " return tmp;\n";
3120 void OpDeg::GenSlidingWindowFunction(std::stringstream
&ss
,
3121 const std::string sSymName
, SubArguments
&vSubArguments
)
3123 ss
<< "\ndouble " << sSymName
;
3124 ss
<< "_"<< BinFuncName() <<"(";
3125 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3129 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3133 ss
<< " int gid0=get_global_id(0);\n";
3134 ss
<< " double arg0 = 0.0f;\n";
3135 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
3137 if(ocPush
== vSubArguments
[0]->GetFormulaToken()->GetOpCode())
3139 if(tmpCur
->GetType() == formula::svSingleVectorRef
)
3141 const formula::SingleVectorRefToken
*tmpCurDVR
=
3143 <const formula::SingleVectorRefToken
*>(tmpCur
);
3145 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
3149 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
3151 ss
<< tmpCurDVR
->GetArrayLength();
3153 ss
<< " { arg0 = 0.0f; }\n";
3156 else if(tmpCur
->GetType() == formula::svDouble
)
3159 ss
<< tmpCur
->GetDouble() << ";\n";
3165 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
3168 ss
<< " return arg0 * pown(M_PI, -1) * 180;;\n";
3172 void OpFact::GenSlidingWindowFunction(std::stringstream
& ss
,
3173 const std::string sSymName
, SubArguments
& vSubArguments
)
3175 ss
<< "\ndouble " << sSymName
;
3176 ss
<< "_" << BinFuncName() << "(";
3177 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3181 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3184 ss
<< " double tmp = " << GetBottom() << ";\n";
3185 ss
<< " int gid0 = get_global_id(0);\n";
3186 ss
<< " double arg0 = " << GetBottom() << ";\n";
3187 FormulaToken
* pCur
= vSubArguments
[0]->GetFormulaToken();
3189 if (pCur
->GetType() == formula::svSingleVectorRef
)
3192 const formula::SingleVectorRefToken
* pSVR
=
3193 dynamic_cast< const formula::SingleVectorRefToken
* >(pCur
);
3194 ss
<< " if (gid0 < " << pSVR
->GetArrayLength() << "){\n";
3197 else if (pCur
->GetType() == formula::svDouble
)
3204 if(ocPush
==vSubArguments
[0]->GetFormulaToken()->GetOpCode())
3206 ss
<< " if (isNan(";
3207 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef();
3209 ss
<< " arg0 = 0;\n";
3212 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
3213 ss
<< " arg0 = floor(arg0);\n";
3214 ss
<< " if (arg0 < 0.0)\n";
3215 ss
<< " return 0.0;\n";
3216 ss
<< " else if (arg0 == 0.0)\n";
3217 ss
<< " return 1.0;\n";
3218 ss
<< " else if (arg0 <= 170.0)\n";
3220 ss
<< " double fTemp = arg0;\n";
3221 ss
<< " while (fTemp > 2.0)\n";
3223 ss
<< " fTemp = fTemp - 1;\n";
3224 ss
<< " arg0 = arg0 * fTemp;\n";
3228 ss
<< " return -DBL_MAX;\n";
3234 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
3238 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
3240 ss
<< " return arg0;\n";
3243 void OpQuotient::GenSlidingWindowFunction(std::stringstream
&ss
,
3244 const std::string sSymName
, SubArguments
&vSubArguments
)
3246 ss
<< "\ndouble " << sSymName
;
3247 ss
<< "_"<< BinFuncName() <<"(";
3248 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3251 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3254 ss
<< " int gid0 = get_global_id(0);\n";
3255 ss
<< " double num1 = 1.0;\n";
3256 ss
<< " double num2 = 1.0;\n";
3259 ss
<< vSubArguments
[0]->GenSlidingWindowDeclRef() << "))\n";
3260 ss
<< " num1 = 1.0;\n";
3263 ss
<< " num1 = " << vSubArguments
[0]->GenSlidingWindowDeclRef() << ";\n";
3266 ss
<< vSubArguments
[1]->GenSlidingWindowDeclRef() << "))\n";
3267 ss
<< " num2 = 1.0;\n";
3270 ss
<< " num2 = " << vSubArguments
[1]->GenSlidingWindowDeclRef() << ";\n";
3271 ss
<< " return trunc(num1/num2);\n";
3274 void OpSeriesSum::GenSlidingWindowFunction(std::stringstream
&ss
,
3275 const std::string sSymName
, SubArguments
&vSubArguments
)
3277 if( vSubArguments
.size() != 4){return;}
3278 ss
<< "\ndouble " << sSymName
;
3279 ss
<< "_"<< BinFuncName() <<"(";
3280 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
3284 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
3288 ss
<< " int gid0=get_global_id(0);\n";
3289 ss
<< " double var[3], coeff, res = 0.0f;\n";
3290 FormulaToken
*tmpCur
;
3291 for(int i
= 0; i
< 3; ++i
)
3293 tmpCur
= vSubArguments
[i
]->GetFormulaToken();
3295 if(ocPush
== vSubArguments
[i
]->GetFormulaToken()->GetOpCode())
3297 if(tmpCur
->GetType() == formula::svSingleVectorRef
)
3299 const formula::SingleVectorRefToken
* tmpCurDVR
=
3301 const formula::SingleVectorRefToken
*>(tmpCur
);
3302 ss
<< " var["<<i
<<"] = ";
3303 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
3306 ss
<< " if(isNan(var["<<i
<<"])||(gid0>=";
3307 ss
<< tmpCurDVR
->GetArrayLength();
3309 ss
<< " var["<<i
<<"] = 0;\n";
3312 else if(tmpCur
->GetType() == formula::svDouble
)
3314 ss
<< " var["<<i
<<"] = ";
3315 ss
<< tmpCur
->GetDouble() << ";\n";
3320 ss
<< " var["<<i
<<"] = ";
3321 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef();
3325 tmpCur
= vSubArguments
[3]->GetFormulaToken();
3327 if(ocPush
== vSubArguments
[3]->GetFormulaToken()->GetOpCode())
3330 if (tmpCur
->GetType() == formula::svDoubleVectorRef
)
3332 const formula::DoubleVectorRefToken
* pDVR
=
3333 dynamic_cast<const formula::DoubleVectorRefToken
*>(tmpCur
);
3334 size_t nCurWindowSize
= pDVR
->GetRefRowSize();
3335 ss
<< " int j = 0;\n";
3336 ss
<< " for (int i = ";
3337 if (!pDVR
->IsStartFixed() && pDVR
->IsEndFixed())
3340 ss
<< "gid0; i < " << pDVR
->GetArrayLength();
3341 ss
<< " && i < " << nCurWindowSize
<< "; ++i)\n";
3344 ss
<< "gid0; i < "<< nCurWindowSize
<< "; ++i)\n";
3348 else if (pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
3351 ss
<< "0; i < " << pDVR
->GetArrayLength();
3352 ss
<< " && i < gid0+"<< nCurWindowSize
<< "; ++i)\n";
3355 ss
<< "0; i < gid0+"<< nCurWindowSize
<< "; ++i)\n";
3359 else if (!pDVR
->IsStartFixed() && !pDVR
->IsEndFixed())
3362 ss
<< "0; i + gid0 < " << pDVR
->GetArrayLength();
3363 ss
<< " && i < "<< nCurWindowSize
<< "; ++i)\n";
3366 ss
<< "0; i < "<< nCurWindowSize
<< "; ++i)\n";
3373 ss
<< "0; i < "<< nCurWindowSize
<< "; ++i)\n";
3376 ss
<< "0; i < "<< nCurWindowSize
<< "; ++i)\n";
3381 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
3384 ss
<< " if (isNan(coeff))\n";
3385 ss
<< " continue;\n";
3387 ss
<< " res = res + coeff * pow(var[0],";
3388 ss
<< " var[1] + j * var[2]);\n";
3392 else if(tmpCur
->GetType() == formula::svSingleVectorRef
)
3394 const formula::SingleVectorRefToken
* tmpCurDVR
=
3396 const formula::SingleVectorRefToken
*>(tmpCur
);
3398 ss
<< vSubArguments
[3]->GenSlidingWindowDeclRef();
3401 ss
<< " if(isNan(coeff)||(gid0>=";
3402 ss
<< tmpCurDVR
->GetArrayLength();
3404 ss
<< " return 0;\n";
3408 ss
<< " return res;\n";
3413 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */