LCOV - code coverage report
Current view: top level - sc/source/core/opencl - op_math.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 2304 0.1 %
Date: 2014-11-03 Functions: 2 72 2.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #include "op_math.hxx"
      11             : 
      12             : #include "formulagroup.hxx"
      13             : #include "document.hxx"
      14             : #include "formulacell.hxx"
      15             : #include "tokenarray.hxx"
      16             : #include "compiler.hxx"
      17             : #include "interpre.hxx"
      18             : #include <formula/vectortoken.hxx>
      19             : #include "opinlinefun_math.hxx"
      20             : #include <sstream>
      21             : 
      22             : using namespace formula;
      23             : 
      24             : namespace sc { namespace opencl {
      25             : 
      26           0 : void OpCos::GenSlidingWindowFunction(std::stringstream &ss,
      27             :             const std::string &sSymName, SubArguments &vSubArguments)
      28             : {
      29           0 :         ss << "\ndouble " << sSymName;
      30           0 :         ss << "_"<< BinFuncName() <<"(";
      31           0 :         for (unsigned i = 0; i < vSubArguments.size(); i++)
      32             :         {
      33           0 :             if (i) ss << ",";
      34           0 :             vSubArguments[i]->GenSlidingWindowDecl(ss);
      35             :         }
      36           0 :         ss << ")\n";
      37           0 :         ss << "{\n";
      38           0 :         ss << "    int gid0=get_global_id(0);\n";
      39           0 :         ss << "    double arg0 = 0.0f;\n";
      40           0 :         FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
      41             :         assert(tmpCur);
      42           0 :         if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
      43             :         {
      44           0 :             if(tmpCur->GetType() == formula::svSingleVectorRef)
      45             :             {
      46             :                 const formula::SingleVectorRefToken*tmpCurDVR=
      47             :                     static_cast
      48           0 :                     <const formula::SingleVectorRefToken *>(tmpCur);
      49           0 :                 ss << "    arg0 = ";
      50           0 :                 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
      51           0 :                 ss << ";\n";
      52             : #ifdef ISNAN
      53           0 :                 ss << "    if(isNan(";
      54           0 :                 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
      55           0 :                 ss << ")||(gid0>=";
      56           0 :                 ss << tmpCurDVR->GetArrayLength();
      57           0 :                 ss << "))\n";
      58           0 :                 ss << "    { arg0 = 0.0f; }\n";
      59             : #endif
      60             :             }
      61           0 :             else if(tmpCur->GetType() == formula::svDouble)
      62             :             {
      63           0 :                 ss << "    arg0=" << tmpCur->GetDouble() << ";\n";
      64             :             }
      65             :         }
      66             :         else
      67             :         {
      68           0 :             ss << "        arg0 = ";
      69           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
      70           0 :             ss << ";\n";
      71             :         }
      72           0 :         ss << "    return cos(arg0);\n";
      73           0 :         ss << "}";
      74             : 
      75           0 : }
      76           0 : void OpSec::GenSlidingWindowFunction(std::stringstream &ss,
      77             :             const std::string &sSymName, SubArguments &vSubArguments)
      78             : {
      79           0 :     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
      80             :     const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const
      81           0 :           formula::SingleVectorRefToken *>(tmpCur);
      82           0 :     ss << "\ndouble " << sSymName;
      83           0 :     ss << "_"<< BinFuncName() <<"(";
      84           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
      85             :     {
      86           0 :         if (i)
      87           0 :             ss << ",";
      88           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
      89             :     }
      90           0 :     ss << ") {\n";
      91           0 :     ss <<"    int gid0=get_global_id(0);\n";
      92           0 :     ss <<"    double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
      93           0 :     ss <<";\n";
      94             : #ifdef ISNAN
      95           0 :     ss<<"    if(isNan(arg0)||(gid0>=";
      96           0 :     ss<<tmpCurDVR->GetArrayLength();
      97           0 :     ss<<"))\n";
      98           0 :     ss<<"        arg0 = 0;\n";
      99             : #endif
     100           0 :     ss << "    return pow(cos(arg0),-1 );\n";
     101           0 :     ss << "}";
     102           0 : }
     103           0 : void OpCosh::BinInlineFun(std::set<std::string>& decls,
     104             :     std::set<std::string>& funs)
     105             : {
     106           0 :     decls.insert(local_coshDecl);
     107           0 :     funs.insert(local_cosh);
     108           0 : }
     109           0 : void OpSecH::GenSlidingWindowFunction(std::stringstream &ss,
     110             :             const std::string &sSymName, SubArguments &vSubArguments)
     111             : {
     112           0 :     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
     113             :     const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const
     114           0 :           formula::SingleVectorRefToken *>(tmpCur);
     115           0 :     ss << "\ndouble " << sSymName;
     116           0 :     ss << "_"<< BinFuncName() <<"(";
     117           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     118             :     {
     119           0 :         if (i)
     120           0 :             ss << ",";
     121           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     122             :     }
     123           0 :     ss << ") {\n";
     124           0 :     ss <<"    int gid0=get_global_id(0);\n";
     125           0 :     ss <<"    double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
     126           0 :     ss <<";\n";
     127             : #ifdef ISNAN
     128           0 :     ss<<"    if(isNan(arg0)||(gid0>=";
     129           0 :     ss<<tmpCurDVR->GetArrayLength();
     130           0 :     ss<<"))\n";
     131           0 :     ss<<"        arg0 = 0;\n";
     132             : #endif
     133           0 :     ss << "    return pow(cosh(arg0),-1 );\n";
     134           0 :     ss << "}";
     135           0 : }
     136           0 : void OpMROUND::GenSlidingWindowFunction(std::stringstream &ss,
     137             :         const std::string &sSymName, SubArguments &vSubArguments)
     138             : {
     139           0 :     ss << "\ndouble " << sSymName;
     140           0 :     ss << "_"<< BinFuncName() <<"(";
     141           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     142             :     {
     143           0 :         if (i)
     144           0 :             ss << ", ";
     145           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     146             :     }
     147           0 :     ss<<") {\n";
     148           0 :     ss<<"    double tmp = 0;\n";
     149           0 :     ss<<"    int gid0 = get_global_id(0);\n";
     150           0 :     ss<<"    double arg0=0;\n";
     151           0 :     ss<<"    double arg1=0;\n";
     152           0 :     ss <<"\n    ";
     153             :     //while (i-- > 1)
     154           0 :     for (size_t i = 0; i < vSubArguments.size(); i++)
     155             :     {
     156           0 :         FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
     157             :         assert(pCur);
     158           0 :         if (pCur->GetType() == formula::svSingleVectorRef)
     159             :         {
     160             : #ifdef  ISNAN
     161             :             const formula::SingleVectorRefToken* pSVR =
     162           0 :                 static_cast< const formula::SingleVectorRefToken* >(pCur);
     163           0 :             ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
     164             : #else
     165             : #endif
     166             :         }
     167           0 :         else if (pCur->GetType() == formula::svDouble)
     168             :         {
     169             : #ifdef  ISNAN
     170           0 :             ss << "{\n";
     171             : #endif
     172             :         }
     173             :         else
     174             :         {
     175             : #ifdef  ISNAN
     176             : #endif
     177             :         }
     178             : #ifdef  ISNAN
     179           0 :         if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
     180             :         {
     181           0 :             ss << "        tmp=";
     182           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
     183           0 :             ss << ";\n";
     184           0 :             ss << "        if (isNan(tmp))\n";
     185           0 :             ss << "            arg"<<i<<"= 0;\n";
     186           0 :             ss << "        else\n";
     187           0 :             ss << "            arg"<<i<<"=tmp;\n";
     188           0 :             ss << "    }\n";
     189             :         }
     190             :         else
     191             :         {
     192           0 :             ss<<"    arg"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
     193           0 :             ss<<";\n";
     194             :         }
     195             : #else
     196             :         ss<<"arg"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
     197             :         ss<<";\n";
     198             : #endif
     199             :     }
     200           0 :     ss<<"    if(arg1==0)\n";
     201           0 :     ss<<"        return arg1;\n";
     202           0 :     ss<<"    tmp=arg1 * round(arg0 * pow(arg1,-1));\n";
     203           0 :     ss<<"    return tmp;\n";
     204           0 :     ss<<"}";
     205           0 : }
     206           0 : void OpCosh::GenSlidingWindowFunction(std::stringstream &ss,
     207             :             const std::string &sSymName, SubArguments &vSubArguments)
     208             : {
     209           0 :     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
     210             :     const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const
     211           0 :           formula::SingleVectorRefToken *>(tmpCur);
     212           0 :     ss << "\ndouble " << sSymName;
     213           0 :     ss << "_"<< BinFuncName() <<"(";
     214           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     215             :     {
     216           0 :         if (i)
     217           0 :             ss << ",";
     218           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     219             :     }
     220           0 :     ss << ")\n{\n";
     221           0 :     ss <<"    int gid0=get_global_id(0);\n";
     222           0 :     ss << "    double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
     223           0 :     ss << ";\n";
     224             : #ifdef ISNAN
     225           0 :     ss<< "    if(isNan(arg0)||(gid0>=";
     226           0 :     ss<<tmpCurDVR->GetArrayLength();
     227           0 :     ss<<"))\n";
     228           0 :     ss<<"        arg0 = 0;\n";
     229             : #endif
     230           0 :     ss << "    double tmp=local_cosh(arg0);\n";
     231           0 :     ss << "    return tmp;\n";
     232           0 :     ss << "}";
     233           0 : }
     234             : 
     235           0 : void OpCot::GenSlidingWindowFunction(std::stringstream &ss,
     236             :     const std::string &sSymName, SubArguments &vSubArguments)
     237             : {
     238           0 :     ss << "\ndouble " << sSymName;
     239           0 :     ss << "_"<< BinFuncName() <<"(";
     240           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     241             :     {
     242           0 :         if (i)
     243           0 :             ss << ",";
     244           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     245             :     }
     246           0 :     ss << ")\n";
     247           0 :     ss << "{\n";
     248           0 :     ss << "    int gid0=get_global_id(0);\n";
     249           0 :     ss << "    double arg0 = 0.0f;\n";
     250           0 :     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
     251             :     assert(tmpCur);
     252           0 :     if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
     253             :     {
     254           0 :         if(tmpCur->GetType() == formula::svSingleVectorRef)
     255             :         {
     256             :             const formula::SingleVectorRefToken*tmpCurDVR=
     257             :                 static_cast
     258           0 :                 <const formula::SingleVectorRefToken *>(tmpCur);
     259           0 :             ss << "    arg0 = ";
     260           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
     261           0 :             ss << ";\n";
     262             : #ifdef ISNAN
     263           0 :             ss << "    if(isNan(";
     264           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
     265           0 :             ss << ")||(gid0>=";
     266           0 :             ss << tmpCurDVR->GetArrayLength();
     267           0 :             ss << "))\n";
     268           0 :             ss << "    { arg0 = 0.0f; }\n";
     269             : #endif
     270             :         }
     271           0 :         else if(tmpCur->GetType() == formula::svDouble)
     272             :         {
     273           0 :             ss << "    arg0=";
     274           0 :             ss << tmpCur->GetDouble() << ";\n";
     275             :         }
     276             :     }
     277             :     else
     278             :     {
     279           0 :         ss << "        arg0 = ";
     280           0 :         ss << vSubArguments[0]->GenSlidingWindowDeclRef();
     281           0 :         ss << ";\n";
     282             :     }
     283           0 :     ss << "    arg0 = arg0 * M_1_PI;\n";
     284           0 :     ss << "    return cospi(arg0) * pow(sinpi(arg0), -1);\n";
     285           0 :     ss << "}";
     286           0 : }
     287             : 
     288           0 : void OpCoth::BinInlineFun(std::set<std::string>& decls,
     289             :     std::set<std::string>& funs)
     290             : {
     291           0 :     decls.insert(local_cothDecl);
     292           0 :     funs.insert(local_coth);
     293           0 : }
     294             : 
     295           0 : void OpCoth::GenSlidingWindowFunction(std::stringstream &ss,
     296             :             const std::string &sSymName, SubArguments &vSubArguments)
     297             : {
     298           0 :     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
     299             :     const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const
     300           0 :           formula::SingleVectorRefToken *>(tmpCur);
     301           0 :     ss << "\ndouble " << sSymName;
     302           0 :     ss << "_"<< BinFuncName() <<"(";
     303           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     304             :     {
     305           0 :         if (i)
     306           0 :             ss << ",";
     307           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     308             :     }
     309           0 :     ss << ")\n{\n";
     310           0 :     ss <<"    int gid0=get_global_id(0);\n";
     311           0 :     ss << "    double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
     312           0 :     ss << ";\n";
     313             : #ifdef ISNAN
     314           0 :     ss<< "    if(isNan(arg0)||(gid0>=";
     315           0 :     ss<<tmpCurDVR->GetArrayLength();
     316           0 :     ss<<"))\n";
     317           0 :     ss<<"        arg0 = 0;\n";
     318             : #endif
     319           0 :     ss << "    double tmp=local_coth(arg0);\n";
     320           0 :     ss << "    return tmp;\n";
     321           0 :     ss << "}";
     322           0 : }
     323             : 
     324           0 : void OpCombina::BinInlineFun(std::set<std::string>& decls,
     325             :     std::set<std::string>& funs)
     326             : {
     327           0 :     decls.insert(bikDecl);
     328           0 :     funs.insert(bik);
     329           0 : }
     330             : 
     331           0 : void OpCombina::GenSlidingWindowFunction(std::stringstream &ss,
     332             :             const std::string &sSymName, SubArguments &vSubArguments)
     333             : {
     334           0 :     ss << "\ndouble " << sSymName;
     335           0 :     ss << "_"<< BinFuncName() <<"(";
     336           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     337             :     {
     338           0 :         if (i)
     339           0 :             ss << ",";
     340           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     341             :     }
     342           0 :     ss << ")\n{\n";
     343           0 :     ss << "    int gid0 = get_global_id(0);\n";
     344           0 :     ss << "    double tem;\n";
     345           0 :     ss << "    double arg0,arg1;\n";
     346           0 :     for (unsigned int i = 0; i < vSubArguments.size(); i++)
     347             :     {
     348           0 :         FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
     349             :         assert(pCur);
     350           0 :         ss << "    arg"<<i<<" = "<<vSubArguments[i]->GenSlidingWindowDeclRef();
     351           0 :         ss << ";\n";
     352           0 :         if(pCur->GetType() == formula::svSingleVectorRef)
     353             :         {
     354             : #ifdef ISNAN
     355             :             const formula::SingleVectorRefToken* pSVR =
     356           0 :             static_cast< const formula::SingleVectorRefToken* >(pCur);
     357           0 :             ss << "    if(isNan(arg" << i <<")||(gid0 >= ";
     358           0 :             ss << pSVR->GetArrayLength();
     359           0 :             ss << "))\n";
     360           0 :             ss << "        arg" << i << " = 0;\n";
     361             :         }
     362           0 :         else if (pCur->GetType() == formula::svDouble)
     363             :         {
     364           0 :             ss << "    if(isNan(arg" << i <<"))\n";
     365           0 :             ss << "        arg" << i << " = 0;\n";
     366             :         }
     367             : #endif
     368             :     }
     369           0 :     ss << "    arg0 = trunc(arg0);\n";
     370           0 :     ss << "    arg1 = trunc(arg1);\n";
     371           0 :     ss << "    if(arg0 >= arg1 && arg0 > 0 && arg1 > 0)\n";
     372           0 :     ss << "        tem = bik(arg0+arg1-1,arg1);\n";
     373           0 :     ss << "    else if(arg0 == 0 && arg1 == 0)\n";
     374           0 :     ss << "        tem = 0;\n";
     375           0 :     ss << "    else if(arg0 > 0 && arg1 == 0)\n";
     376           0 :     ss << "        tem = 1;\n";
     377           0 :     ss << "    else\n";
     378           0 :     ss << "        tem = -1;\n";
     379           0 :     ss << "    double i = tem - trunc(tem);\n";
     380           0 :     ss << "    if(i < 0.5)\n";
     381           0 :     ss << "        tem = trunc(tem);\n";
     382           0 :     ss << "    else\n";
     383           0 :     ss << "        tem = trunc(tem) + 1;\n";
     384           0 :     ss << "    return tem;\n";
     385           0 :     ss << "}";
     386           0 : }
     387           0 : void OpEven::GenSlidingWindowFunction(std::stringstream &ss,
     388             :             const std::string &sSymName, SubArguments &vSubArguments)
     389             : {
     390           0 :     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
     391             :     const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const
     392           0 :           formula::SingleVectorRefToken *>(tmpCur);
     393           0 :     ss << "\ndouble " << sSymName;
     394           0 :     ss << "_"<< BinFuncName() <<"(";
     395           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     396             :     {
     397           0 :         if (i)
     398           0 :             ss << ",";
     399           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     400             :     }
     401           0 :     ss << ")\n{\n";
     402           0 :     ss <<"    int gid0=get_global_id(0);\n";
     403           0 :     ss << "    double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
     404           0 :     ss << ";\n";
     405             : #ifdef ISNAN
     406           0 :     ss<< "    if(isNan(arg0)||(gid0>=";
     407           0 :     ss<<tmpCurDVR->GetArrayLength();
     408           0 :     ss<<"))\n";
     409           0 :     ss<<"        arg0 = 0;\n";
     410             : #endif
     411           0 :     ss << "    double tmp;\n";
     412           0 :     ss << "    tmp = fabs(arg0 / 2);\n";
     413           0 :     ss << "    if ( trunc(tmp) == tmp )\n";
     414           0 :     ss << "        tmp = tmp * 2;\n";
     415           0 :     ss << "    else\n";
     416           0 :     ss << "        tmp = (trunc(tmp) + 1) * 2;\n";
     417           0 :     ss << "    if (arg0 < 0)\n";
     418           0 :     ss << "        tmp = tmp * -1.0;\n";
     419           0 :     ss << "    return tmp;\n";
     420           0 :     ss << "}";
     421           0 : }
     422             : 
     423           0 : void OpMod::GenSlidingWindowFunction(std::stringstream &ss,
     424             :             const std::string &sSymName, SubArguments &vSubArguments)
     425             : {
     426           0 :     ss << "\ndouble " << sSymName;
     427           0 :     ss << "_"<< BinFuncName() <<"(";
     428           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     429             :     {
     430           0 :         if (i)
     431           0 :             ss << ",";
     432           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     433             :     }
     434           0 :     ss << ")\n{\n";
     435           0 :     ss <<"    int gid0=get_global_id(0);\n";
     436           0 :     ss << "    double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
     437           0 :     ss << ";\n";
     438           0 :     ss << "    double arg1 =" << vSubArguments[1]->GenSlidingWindowDeclRef();
     439           0 :     ss << ";\n";
     440           0 :     ss << "    if(isNan(arg0)||arg0 == 0)\n";
     441           0 :     ss << "        return 0;\n";
     442           0 :     ss << "    if(isNan(arg1) || arg1 ==0)\n";
     443           0 :     ss << "        return NAN;\n";
     444           0 :     ss << "    double tem;\n";
     445           0 :     ss << "        if(arg0 < 0 && arg1 > 0)\n";
     446           0 :     ss << "            while(arg0 < 0)\n";
     447           0 :     ss << "                arg0 += arg1;\n";
     448           0 :     ss << "        else if (arg0 > 0 && arg1 < 0)\n";
     449           0 :     ss << "            while(arg0 > 0)\n";
     450           0 :     ss << "                arg0 += arg1;\n";
     451           0 :     ss << "        tem = fmod(arg0,arg1);\n";
     452           0 :     ss << "    if(arg1 < 0 && tem > 0)\n";
     453           0 :     ss << "        tem = -tem;\n";
     454           0 :     ss << "    return tem;\n";
     455           0 :     ss << "}";
     456           0 : }
     457           0 : void OpLog::GenSlidingWindowFunction(std::stringstream &ss,
     458             :             const std::string &sSymName, SubArguments &vSubArguments)
     459             : {
     460           0 :     ss << "\ndouble " << sSymName;
     461           0 :     ss << "_"<< BinFuncName() <<"(";
     462           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     463             :     {
     464           0 :         if (i)
     465           0 :             ss << ",";
     466           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     467             :     }
     468           0 :     ss << ")\n{\n";
     469           0 :     ss << "    int gid0 = get_global_id(0);\n";
     470           0 :     ss << "    double tem;\n";
     471           0 :     ss << "    double arg0,arg1;\n";
     472           0 :     for (unsigned int i = 0; i < vSubArguments.size(); i++)
     473             :     {
     474           0 :         FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
     475             :         assert(pCur);
     476           0 :         ss << "    arg"<<i<<" = "<<vSubArguments[i]->GenSlidingWindowDeclRef();
     477           0 :         ss << ";\n";
     478           0 :         if(pCur->GetType() == formula::svSingleVectorRef)
     479             :         {
     480             : #ifdef ISNAN
     481             :             const formula::SingleVectorRefToken* pSVR =
     482           0 :             static_cast< const formula::SingleVectorRefToken* >(pCur);
     483           0 :             ss << "    if(isNan(arg" << i <<")||(gid0 >= ";
     484           0 :             ss << pSVR->GetArrayLength();
     485           0 :             ss << "))\n";
     486           0 :             if( i == 0)
     487           0 :                 ss << "        arg0 = 0;\n";
     488           0 :             else if ( i == 1)
     489           0 :                 ss << "        arg1 = 10;\n";
     490             :         }
     491           0 :         else if (pCur->GetType() == formula::svDouble)
     492             :         {
     493           0 :             ss << "    if(isNan(arg" << i <<"))\n";
     494           0 :             if( i == 0)
     495           0 :                 ss << "        arg0 = 0;\n";
     496           0 :             else if ( i == 1)
     497           0 :                 ss << "        arg1 = 10;\n";
     498             :         }
     499             : #endif
     500             :     }
     501           0 :     if (vSubArguments.size() < 2)
     502           0 :         ss << "    arg1 = 10;\n";
     503           0 :     ss << "    tem = log10(arg0)/log10(arg1);;\n";
     504           0 :     ss << "    return tem;\n";
     505           0 :     ss << "}";
     506           0 : }
     507           0 : void OpCsc::GenSlidingWindowFunction(
     508             :     std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
     509             : {
     510           0 :     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
     511             :     const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const
     512           0 :           formula::SingleVectorRefToken *>(tmpCur);
     513           0 :     ss << "\ndouble " << sSymName;
     514           0 :     ss << "_"<< BinFuncName() <<"(";
     515           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     516             :     {
     517           0 :         if (i)
     518           0 :             ss << ",";
     519           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     520             :     }
     521           0 :     ss << ")\n{\n\t";
     522           0 :     ss <<"int gid0=get_global_id(0);\n\t";
     523           0 :     ss << "double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
     524           0 :     ss << ";\n\t";
     525             : #ifdef ISNAN
     526           0 :     ss<< "if(isNan(arg0)||(gid0>=";
     527           0 :     ss<<tmpCurDVR->GetArrayLength();
     528           0 :     ss<<"))\n\t\t";
     529           0 :     ss<<"arg0 = 0;\n\t";
     530             : #endif
     531           0 :     ss << "double tmp=1/sin(arg0);\n\t";
     532           0 :     ss << "return tmp;\n";
     533           0 :     ss << "}";
     534           0 : }
     535           0 : void OpCountIfs::GenSlidingWindowFunction(std::stringstream &ss,
     536             :             const std::string &sSymName, SubArguments &vSubArguments)
     537             : {
     538           0 :     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
     539             :     const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
     540           0 :          formula::DoubleVectorRefToken *>(tmpCur);
     541           0 :     size_t nCurWindowSize = pCurDVR->GetArrayLength() <
     542           0 :     pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
     543           0 :     pCurDVR->GetRefRowSize() ;
     544           0 :     ss << "\ndouble " << sSymName;
     545           0 :     ss << "_"<< BinFuncName() <<"(";
     546           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     547             :     {
     548           0 :         if (i)
     549           0 :             ss << ",";
     550           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     551             :     }
     552           0 :     ss << ")\n    {\n";
     553           0 :     ss <<"    int gid0=get_global_id(0);\n";
     554           0 :     ss << "    int tmp =0;\n";
     555           0 :     ss << "    int loop;\n";
     556           0 :     GenTmpVariables(ss,vSubArguments);
     557             : 
     558           0 :      ss<< "    int singleIndex =gid0;\n";
     559           0 :      int m=0;
     560             : 
     561           0 :      std::stringstream tmpss;
     562             : 
     563           0 :      for(unsigned j=0;j<vSubArguments.size();j+=2,m++)
     564             :      {
     565           0 :         CheckSubArgumentIsNan(tmpss,vSubArguments,j);
     566           0 :         CheckSubArgumentIsNan(ss,vSubArguments,j+1);
     567           0 :         tmpss <<"    if(isequal(";
     568           0 :         tmpss <<"tmp";
     569           0 :         tmpss <<j;
     570           0 :         tmpss <<" , ";
     571           0 :         tmpss << "tmp";
     572           0 :         tmpss << j+1;
     573           0 :         tmpss << ")){\n";
     574             :      }
     575           0 :     tmpss << "    tmp ++;\n";
     576           0 :     for(unsigned j=0;j<vSubArguments.size();j+=2,m--)
     577             :      {
     578           0 :          for(int n = 0;n<m+1;n++)
     579             :         {
     580           0 :             tmpss << "    ";
     581             :         }
     582           0 :         tmpss<< "}\n";
     583             :      }
     584           0 :      UnrollDoubleVector(ss,tmpss,pCurDVR,nCurWindowSize);
     585             : 
     586           0 :     ss << "return tmp;\n";
     587           0 :     ss << "}";
     588           0 : }
     589           0 : void OpSumIfs::GenSlidingWindowFunction(std::stringstream &ss,
     590             :             const std::string &sSymName, SubArguments &vSubArguments)
     591             : {
     592           0 :     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
     593             :     const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
     594           0 :          formula::DoubleVectorRefToken *>(tmpCur);
     595           0 :     size_t nCurWindowSize = pCurDVR->GetArrayLength() <
     596           0 :     pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
     597           0 :     pCurDVR->GetRefRowSize() ;
     598             : 
     599           0 :     mNeedReductionKernel = vSubArguments[0]->NeedParallelReduction();
     600           0 :     if (mNeedReductionKernel)
     601             :     {
     602             :         // generate reduction functions
     603             : 
     604           0 :         ss << "__kernel void ";
     605           0 :         ss << vSubArguments[0]->GetName();
     606           0 :         ss << "_SumIfs_reduction(  ";
     607           0 :         for (unsigned i = 0; i < vSubArguments.size(); i++)
     608             :         {
     609           0 :             if (i)
     610           0 :                 ss << ",";
     611           0 :             vSubArguments[i]->GenSlidingWindowDecl(ss);
     612             :         }
     613           0 :         ss << ", __global double *result,int arrayLength,int windowSize";
     614             : 
     615           0 :         ss << ")\n{\n";
     616           0 :         ss << "    double tmp =0;\n";
     617           0 :         ss << "    int i ;\n";
     618             : 
     619           0 :         GenTmpVariables(ss,vSubArguments);
     620           0 :         ss << "    double current_result = 0.0;\n";
     621           0 :         ss << "    int writePos = get_group_id(1);\n";
     622           0 :         if (pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed())
     623           0 :             ss << "    int offset = 0;\n";
     624           0 :         else if (!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
     625           0 :             ss << "    int offset = get_group_id(1);\n";
     626             :         else
     627           0 :             throw Unhandled();
     628             :         // actually unreachable
     629           0 :         ss << "    int lidx = get_local_id(0);\n";
     630           0 :         ss << "    __local double shm_buf[256];\n";
     631           0 :         ss << "    barrier(CLK_LOCAL_MEM_FENCE);\n";
     632           0 :         ss << "    int loop = arrayLength/512 + 1;\n";
     633           0 :         ss << "    for (int l=0; l<loop; l++){\n";
     634           0 :         ss << "        tmp = 0.0;\n";
     635           0 :         ss << "        int loopOffset = l*512;\n";
     636             : 
     637           0 :         ss << "        int p1 = loopOffset + lidx + offset, p2 = p1 + 256;\n";
     638           0 :         ss << "        if (p2 < min(offset + windowSize, arrayLength)) {\n";
     639           0 :         ss << "            tmp0 = 0.0;\n";
     640           0 :         int mm=0;
     641           0 :         std::string p1 = "p1";
     642           0 :         std::string p2 = "p2";
     643           0 :         for(unsigned j=1;j<vSubArguments.size();j+=2,mm++)
     644             :         {
     645           0 :             CheckSubArgumentIsNan2(ss,vSubArguments,j,p1);
     646           0 :             CheckSubArgumentIsNan2(ss,vSubArguments,j+1,p1);
     647           0 :             ss << "";
     648           0 :             ss <<"    if(isequal(";
     649           0 :             ss <<"tmp";
     650           0 :             ss <<j;
     651           0 :             ss <<" , ";
     652           0 :             ss << "tmp";
     653           0 :             ss << j+1;
     654           0 :             ss << "))";
     655           0 :             ss << "{\n";
     656             :         }
     657           0 :         CheckSubArgumentIsNan2(ss,vSubArguments,0,p1);
     658           0 :         ss << "    tmp += tmp0;\n";
     659           0 :         for(unsigned j=1;j<vSubArguments.size();j+=2,mm--)
     660             :         {
     661           0 :             for(int n = 0;n<mm+1;n++)
     662             :             {
     663           0 :                 ss << "    ";
     664             :             }
     665           0 :             ss<< "}\n\n";
     666             :         }
     667           0 :         mm=0;
     668           0 :         for(unsigned j=1;j<vSubArguments.size();j+=2,mm++)
     669             :         {
     670           0 :             CheckSubArgumentIsNan2(ss,vSubArguments,j,p2);
     671           0 :             CheckSubArgumentIsNan2(ss,vSubArguments,j+1,p2);
     672           0 :             ss <<"    if(isequal(";
     673           0 :             ss <<"tmp";
     674           0 :             ss <<j;
     675           0 :             ss <<" , ";
     676           0 :             ss << "tmp";
     677           0 :             ss << j+1;
     678           0 :             ss << ")){\n";
     679             :         }
     680           0 :         CheckSubArgumentIsNan2(ss,vSubArguments,0,p2);
     681           0 :         ss << "    tmp += tmp0;\n";
     682           0 :         for(unsigned j=1;j< vSubArguments.size();j+=2,mm--)
     683             :         {
     684           0 :             for(int n = 0;n<mm+1;n++)
     685             :             {
     686           0 :                 ss << "    ";
     687             :             }
     688           0 :             ss<< "}\n";
     689             :         }
     690           0 :         ss << "    }\n";
     691             : 
     692           0 :         ss << "    else if (p1 < min(arrayLength, offset + windowSize)) {\n";
     693           0 :         mm=0;
     694           0 :         for(unsigned j=1;j<vSubArguments.size();j+=2,mm++)
     695             :         {
     696           0 :             CheckSubArgumentIsNan2(ss,vSubArguments,j,p1);
     697           0 :             CheckSubArgumentIsNan2(ss,vSubArguments,j+1,p1);
     698             : 
     699           0 :             ss <<"    if(isequal(";
     700           0 :             ss <<"tmp";
     701           0 :             ss <<j;
     702           0 :             ss <<" , ";
     703           0 :             ss << "tmp";
     704           0 :             ss << j+1;
     705           0 :             ss << ")){\n";
     706             :         }
     707           0 :         CheckSubArgumentIsNan2(ss,vSubArguments,0,p1);
     708           0 :         ss << "    tmp += tmp0;\n";
     709           0 :         for(unsigned j=1;j<vSubArguments.size();j+=2,mm--)
     710             :         {
     711           0 :             for(int n = 0;n<mm+1;n++)
     712             :             {
     713           0 :                 ss << "    ";
     714             :             }
     715           0 :             ss<< "}\n\n";
     716             :         }
     717             : 
     718           0 :         ss << "    }\n";
     719           0 :         ss << "    shm_buf[lidx] = tmp;\n";
     720           0 :         ss << "    barrier(CLK_LOCAL_MEM_FENCE);\n";
     721           0 :         ss << "    for (int i = 128; i >0; i/=2) {\n";
     722           0 :         ss << "        if (lidx < i)\n";
     723           0 :         ss << "            shm_buf[lidx] += shm_buf[lidx + i];\n";
     724           0 :         ss << "        barrier(CLK_LOCAL_MEM_FENCE);\n";
     725           0 :         ss << "    }\n";
     726           0 :         ss << "    if (lidx == 0)\n";
     727           0 :         ss << "        current_result += shm_buf[0];\n";
     728           0 :         ss << "    barrier(CLK_LOCAL_MEM_FENCE);\n";
     729           0 :         ss << "    }\n";
     730             : 
     731           0 :         ss << "    if (lidx == 0)\n";
     732           0 :         ss << "        result[writePos] = current_result;\n";
     733           0 :         ss << "}\n";
     734             :     }// finish generate reduction code
     735             :     // generate functions as usual
     736           0 :     ss << "\ndouble " << sSymName;
     737           0 :     ss << "_"<< BinFuncName() <<"(";
     738           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     739             :     {
     740           0 :         if (i)
     741           0 :             ss << ",";
     742           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     743             :     }
     744           0 :     ss << ")\n    {\n";
     745           0 :     ss <<"    int gid0=get_global_id(0);\n";
     746           0 :     ss << "    double tmp =0;\n";
     747           0 :     if (!mNeedReductionKernel)
     748             :     {
     749           0 :         ss << "    int i ;\n";
     750           0 :         GenTmpVariables(ss,vSubArguments);
     751           0 :         ss << "    for (i = ";
     752           0 :         if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
     753           0 :             ss << "gid0; i < "<< nCurWindowSize <<"; i++)\n";
     754           0 :         } else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) {
     755           0 :             ss << "0; i < gid0+"<< nCurWindowSize <<"; i++)\n";
     756             :         } else {
     757           0 :             ss << "0; i < "<< nCurWindowSize <<"; i++)\n";
     758             :         }
     759           0 :         ss << "    {\n";
     760           0 :         if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
     761             :         {
     762           0 :             ss<< "    int doubleIndex =i+gid0;\n";
     763             :         }else
     764             :         {
     765           0 :             ss<< "    int doubleIndex =i;\n";
     766             :         }
     767           0 :         ss<< "    int singleIndex =gid0;\n";
     768           0 :         int m=0;
     769           0 :         for(unsigned j=1;j<vSubArguments.size();j+=2,m++)
     770             :         {
     771           0 :             CheckSubArgumentIsNan(ss,vSubArguments,j);
     772           0 :             CheckSubArgumentIsNan(ss,vSubArguments,j+1);
     773           0 :             ss <<"    if(isequal(";
     774           0 :             ss <<"tmp";
     775           0 :             ss <<j;
     776           0 :             ss <<" , ";
     777           0 :             ss << "tmp";
     778           0 :             ss << j+1;
     779           0 :             ss << ")){\n";
     780             :         }
     781           0 :         CheckSubArgumentIsNan(ss,vSubArguments,0);
     782           0 :         ss << "    tmp += tmp0;\n";
     783           0 :         for(unsigned j=1;j<=vSubArguments.size();j+=2,m--)
     784             :         {
     785           0 :             for(int n = 0;n<m+1;n++)
     786             :             {
     787           0 :                 ss << "    ";
     788             :             }
     789           0 :             ss<< "}\n";
     790             :         }
     791             :     }
     792           0 :     if (mNeedReductionKernel)
     793             :     {
     794           0 :         ss << "tmp =";
     795           0 :         vSubArguments[0]->GenDeclRef(ss);
     796           0 :         ss << "[gid0];\n";
     797             :     }
     798           0 :     ss << "return tmp;\n";
     799           0 :     ss << "}";
     800           0 : }
     801           0 : void OpCscH::GenSlidingWindowFunction(
     802             :     std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
     803             : {
     804           0 :     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
     805             :     const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const
     806           0 :           formula::SingleVectorRefToken *>(tmpCur);
     807           0 :     ss << "\ndouble " << sSymName;
     808           0 :     ss << "_"<< BinFuncName() <<"(";
     809           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     810             :     {
     811           0 :         if (i)
     812           0 :             ss << ",";
     813           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     814             :     }
     815           0 :     ss << ")\n{\n\t";
     816           0 :     ss <<"int gid0=get_global_id(0);\n\t";
     817           0 :     ss << "double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
     818           0 :     ss << ";\n\t";
     819             : #ifdef ISNAN
     820           0 :     ss<< "if(isNan(arg0)||(gid0>=";
     821           0 :     ss<<tmpCurDVR->GetArrayLength();
     822           0 :     ss<<"))\n\t\t";
     823           0 :     ss<<"arg0 = 0;\n\t";
     824             : #endif
     825           0 :     ss << "double tmp=1/sinh(arg0);\n\t";
     826           0 :     ss << "return tmp;\n";
     827           0 :     ss << "}";
     828           0 : }
     829           0 : void OpExp::GenSlidingWindowFunction(std::stringstream &ss,
     830             :             const std::string &sSymName, SubArguments &vSubArguments)
     831             : {
     832           0 :     ss << "\ndouble " << sSymName;
     833           0 :     ss << "_"<< BinFuncName() <<"(";
     834           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     835             :     {
     836           0 :         if (i) ss << ",";
     837           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     838             :     }
     839           0 :     ss << ")\n";
     840           0 :     ss << "{\n";
     841           0 :     ss << "    int gid0=get_global_id(0);\n";
     842           0 :     ss << "    double arg0 = 0.0f;\n";
     843           0 :     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
     844             :     assert(tmpCur);
     845           0 :     if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
     846             :     {
     847           0 :         if(tmpCur->GetType() == formula::svSingleVectorRef)
     848             :         {
     849             :             const formula::SingleVectorRefToken*tmpCurDVR=
     850             :                 static_cast
     851           0 :                 <const formula::SingleVectorRefToken *>(tmpCur);
     852           0 :             ss << "    arg0 = ";
     853           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
     854           0 :             ss << ";\n";
     855             : #ifdef ISNAN
     856           0 :             ss << "    if(isNan(";
     857           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
     858           0 :             ss << ")||(gid0>=";
     859           0 :             ss << tmpCurDVR->GetArrayLength();
     860           0 :             ss << "))\n";
     861           0 :             ss << "    { arg0 = 0.0f; }\n";
     862             : #endif
     863             :         }
     864           0 :         else if(tmpCur->GetType() == formula::svDouble)
     865             :         {
     866           0 :             ss << "    arg0=" << tmpCur->GetDouble() << ";\n";
     867             :         }
     868             :     }
     869             :     else
     870             :     {
     871           0 :         ss << "        arg0 = ";
     872           0 :         ss << vSubArguments[0]->GenSlidingWindowDeclRef();
     873           0 :         ss << ";\n";
     874             :     }
     875           0 :     ss << "    return pow(M_E, arg0);\n";
     876           0 :     ss << "}";
     877           0 : }
     878             : 
     879           0 : void OpAverageIfs::GenSlidingWindowFunction(std::stringstream &ss,
     880             :             const std::string &sSymName, SubArguments &vSubArguments)
     881             : {
     882           0 :     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
     883             :     const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
     884           0 :          formula::DoubleVectorRefToken *>(tmpCur);
     885           0 :     size_t nCurWindowSize = pCurDVR->GetArrayLength() <
     886           0 :     pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
     887           0 :     pCurDVR->GetRefRowSize() ;
     888           0 :     ss << "\ndouble " << sSymName;
     889           0 :     ss << "_"<< BinFuncName() <<"(";
     890           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     891             :     {
     892           0 :         if (i)
     893           0 :             ss << ",";
     894           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     895             :     }
     896           0 :     ss << ")\n    {\n";
     897           0 :     ss <<"     int gid0=get_global_id(0);\n";
     898           0 :     ss << "    double tmp =0;\n";
     899           0 :     ss << "    int count=0;\n";
     900           0 :     ss << "    int loop;";
     901           0 :     GenTmpVariables(ss,vSubArguments);
     902           0 :      ss<< "    int singleIndex =gid0;\n";
     903           0 :      int m=0;
     904           0 :      std::stringstream tmpss;
     905           0 :      for(unsigned j=1;j<vSubArguments.size();j+=2,m++)
     906             :      {
     907           0 :         CheckSubArgumentIsNan(tmpss,vSubArguments,j);
     908           0 :         CheckSubArgumentIsNan(ss,vSubArguments,j+1);
     909           0 :         tmpss <<"    if(isequal(";
     910           0 :         tmpss <<"tmp";
     911           0 :         tmpss <<j;
     912           0 :         tmpss <<" , ";
     913           0 :         tmpss << "tmp";
     914           0 :         tmpss << j+1;
     915           0 :         tmpss << ")){\n";
     916             :      }
     917           0 :      CheckSubArgumentIsNan(tmpss,vSubArguments,0);
     918           0 :     tmpss << "    tmp += tmp0;\n";
     919           0 :     tmpss << "    count++;\n";
     920           0 :     for(unsigned j=1;j<vSubArguments.size();j+=2,m--)
     921             :      {
     922           0 :          for(int n = 0;n<m+1;n++)
     923             :         {
     924           0 :             tmpss << "    ";
     925             :         }
     926           0 :         tmpss<< "}\n";
     927             :      }
     928             : 
     929           0 :     UnrollDoubleVector(ss,tmpss,pCurDVR,nCurWindowSize);
     930             : 
     931           0 :      ss << "    if(count!=0)\n";
     932           0 :      ss << "        tmp=tmp/count;\n";
     933           0 :      ss << "    else\n";
     934           0 :      ss << "        tmp= 0 ;\n";
     935           0 :     ss << "return tmp;\n";
     936           0 :     ss << "}";
     937           0 : }
     938             : 
     939           0 : void OpLog10::GenSlidingWindowFunction(std::stringstream &ss,
     940             :                const std::string &sSymName, SubArguments &vSubArguments)
     941             : {
     942           0 :     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
     943             :     const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const
     944           0 :           formula::SingleVectorRefToken *>(tmpCur);
     945           0 :     ss << "\ndouble " << sSymName;
     946           0 :     ss << "_"<< BinFuncName() <<"(";
     947           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     948             :     {
     949           0 :         if (i)
     950           0 :             ss << ",";
     951           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     952             :     }
     953           0 :     ss << ")\n{\n\t";
     954           0 :     ss <<"int gid0=get_global_id(0);\n\t";
     955           0 :     ss << "double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
     956           0 :     ss << ";\n\t";
     957             : #ifdef ISNAN
     958           0 :     ss<< "if(isNan(arg0)||(gid0>=";
     959           0 :     ss<<tmpCurDVR->GetArrayLength();
     960           0 :     ss<<"))\n\t\t";
     961           0 :     ss<<"arg0 = 0;\n\t";
     962             : #endif
     963           0 :     ss << "double tmp=log10(arg0);\n\t";
     964           0 :     ss << "return tmp;\n";
     965           0 :     ss << "}";
     966           0 : }
     967             : 
     968           0 : void OpSinh::GenSlidingWindowFunction(std::stringstream &ss,
     969             :             const std::string &sSymName, SubArguments &vSubArguments)
     970             : {
     971           0 :     ss << "\ndouble " << sSymName;
     972           0 :     ss << "_"<< BinFuncName() <<"(";
     973           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     974             :     {
     975           0 :         if (i)
     976           0 :             ss << ",";
     977           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     978             :     }
     979           0 :     ss <<") {\n";
     980           0 :     ss <<"    int gid0=get_global_id(0);\n";
     981           0 :     ss <<"    double arg0 = " <<
     982           0 :         vSubArguments[0]->GenSlidingWindowDeclRef();
     983           0 :     ss <<";\n";
     984           0 :     ss<< "    if(isNan(arg0))\n";
     985           0 :     ss<<"        arg0 = 0;\n";
     986           0 :     ss << "    double tmp=( exp(arg0)-exp(-arg0) )/2;\n";
     987           0 :     ss << "    return tmp;\n";
     988           0 :     ss << "}";
     989           0 : }
     990           0 : void OpSin::GenSlidingWindowFunction(std::stringstream &ss,
     991             :             const std::string &sSymName, SubArguments &vSubArguments)
     992             : {
     993           0 :     ss << "\ndouble " << sSymName;
     994           0 :     ss << "_"<< BinFuncName() <<"(";
     995           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
     996             :     {
     997           0 :         if (i) ss << ",";
     998           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
     999             :     }
    1000           0 :     ss << ")\n";
    1001           0 :     ss << "{\n";
    1002           0 :     ss << "    int gid0=get_global_id(0);\n";
    1003           0 :     ss << "    double arg0 = 0.0f;\n";
    1004           0 :     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
    1005             :     assert(tmpCur);
    1006           0 :     if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
    1007             :     {
    1008           0 :         if(tmpCur->GetType() == formula::svSingleVectorRef)
    1009             :         {
    1010             :             const formula::SingleVectorRefToken*tmpCurDVR=
    1011             :                 static_cast
    1012           0 :                 <const formula::SingleVectorRefToken *>(tmpCur);
    1013           0 :             ss << "    arg0 = ";
    1014           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1015           0 :             ss << ";\n";
    1016             : #ifdef ISNAN
    1017           0 :             ss << "    if(isNan(";
    1018           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1019           0 :             ss << ")||(gid0>=";
    1020           0 :             ss << tmpCurDVR->GetArrayLength();
    1021           0 :             ss << "))\n";
    1022           0 :             ss << "    { arg0 = 0.0f; }\n";
    1023             : #endif
    1024             :         }
    1025           0 :         else if(tmpCur->GetType() == formula::svDouble)
    1026             :         {
    1027           0 :             ss << "    arg0=" << tmpCur->GetDouble() << ";\n";
    1028             :         }
    1029             :     }
    1030             :     else
    1031             :     {
    1032           0 :         ss << "        arg0 = ";
    1033           0 :         ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1034           0 :         ss << ";\n";
    1035             :     }
    1036           0 :     ss << "    arg0 = arg0 * M_1_PI;\n";
    1037           0 :     ss << "    return sinpi(arg0);\n";
    1038           0 :     ss << "}";
    1039           0 : }
    1040             : 
    1041           0 : void OpAbs::GenSlidingWindowFunction(std::stringstream &ss,
    1042             :     const std::string &sSymName, SubArguments &vSubArguments)
    1043             : {
    1044           0 :     ss << "\ndouble " << sSymName;
    1045           0 :     ss << "_"<< BinFuncName() <<"(";
    1046           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1047             :     {
    1048           0 :         if (i)
    1049           0 :             ss << ",";
    1050           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1051             :     }
    1052           0 :     ss << ") {\n";
    1053           0 :     ss << "    int gid0   = get_global_id(0);\n";
    1054           0 :     ss << "    double tmp = " << GetBottom() << ";\n";
    1055             : #ifdef ISNAN
    1056           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
    1057             :     const formula::SingleVectorRefToken*tmpCurDVR0=
    1058           0 :         static_cast<const formula::SingleVectorRefToken *>(tmpCur0);
    1059           0 :     ss << "    int buffer_len = ";
    1060           0 :     ss << tmpCurDVR0->GetArrayLength();
    1061           0 :     ss << ";\n";
    1062           0 :     ss << "    if((gid0)>=buffer_len || isNan(";
    1063           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1064           0 :     ss << "))\n";
    1065           0 :     ss << "        tmp = " << GetBottom() << ";\n    else \n";
    1066             : #endif
    1067           0 :     ss << "        tmp = ";
    1068           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1069           0 :     ss << ";\n";
    1070           0 :     ss << "    return fabs(tmp);\n";
    1071           0 :     ss << "}";
    1072           0 : }
    1073           0 : void OpArcCos::BinInlineFun(std::set<std::string>& decls,
    1074             :     std::set<std::string>& funs)
    1075             : {
    1076           0 :     decls.insert(atan2Decl);
    1077           0 :     funs.insert(atan2Content);
    1078           0 : }
    1079           0 : void OpArcCos::GenSlidingWindowFunction(std::stringstream &ss,
    1080             :     const std::string &sSymName, SubArguments &vSubArguments)
    1081             : {
    1082           0 :     ss << "\ndouble " << sSymName;
    1083           0 :     ss << "_"<< BinFuncName() <<"(";
    1084           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1085             :     {
    1086           0 :         if (i) ss << ",";
    1087           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1088             :     }
    1089           0 :     ss << ") {\n";
    1090           0 :     ss << "    int gid0 = get_global_id(0);\n";
    1091           0 :     ss << "    double tmp = " << GetBottom() << ";\n";
    1092             : #ifdef ISNAN
    1093           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
    1094             :     const formula::SingleVectorRefToken*tmpCurDVR0=
    1095           0 :         static_cast<const formula::SingleVectorRefToken *>(tmpCur0);
    1096           0 :     ss << "    int buffer_len = "<< tmpCurDVR0->GetArrayLength()<< ";\n";
    1097           0 :     ss << "    if((gid0)>=buffer_len || isNan(";
    1098           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef()<< "))\n";
    1099           0 :     ss << "        tmp = " << GetBottom() << ";\n";
    1100           0 :     ss << "    else \n    ";
    1101             : #endif
    1102           0 :     ss << "    tmp = ";
    1103           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef()<< ";\n";
    1104           0 :     ss << "    return arctan2(sqrt(1.0 - pow(tmp, 2)), tmp);\n";
    1105           0 :     ss << "}";
    1106           0 : }
    1107           0 : void OpArcCosHyp::GenSlidingWindowFunction(std::stringstream &ss,
    1108             :     const std::string &sSymName, SubArguments &vSubArguments)
    1109             : {
    1110           0 :     ss << "\ndouble " << sSymName;
    1111           0 :     ss << "_"<< BinFuncName() <<"(";
    1112           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1113             :     {
    1114           0 :         if (i) ss << ",";
    1115           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1116             :     }
    1117           0 :     ss << ") {\n";
    1118           0 :     ss << "    int gid0   = get_global_id(0);\n";
    1119           0 :     ss << "    double tmp = " << GetBottom() << ";\n";
    1120           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
    1121             :     assert(tmpCur0);
    1122           0 :     if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
    1123             :     {
    1124           0 :         if(tmpCur0->GetType() == formula::svSingleVectorRef)
    1125             :         {
    1126             :             const formula::SingleVectorRefToken*tmpCurDVR0=
    1127           0 :                 static_cast<const formula::SingleVectorRefToken *>(tmpCur0);
    1128             : #ifdef ISNAN
    1129           0 :             ss << "    int buffer_len = "<<tmpCurDVR0->GetArrayLength()<<";\n";
    1130           0 :             ss << "    if((gid0)>=buffer_len || isNan(";
    1131           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
    1132           0 :             ss << "        tmp = " << GetBottom() << ";\n";
    1133           0 :             ss << "    else \n    ";
    1134             : #endif
    1135           0 :             ss << "    tmp = " << vSubArguments[0]->GenSlidingWindowDeclRef();
    1136           0 :             ss << ";\n";
    1137             :         }
    1138           0 :         else if(tmpCur0->GetType() == formula::svDouble)
    1139             :         {
    1140           0 :             ss << "    tmp = " << tmpCur0->GetDouble() << ";\n";
    1141             :         }
    1142             :     }
    1143             :     else
    1144             :     {
    1145           0 :         ss << "    tmp = " << vSubArguments[0]->GenSlidingWindowDeclRef();
    1146           0 :         ss << ";\n";
    1147             :     }
    1148             : 
    1149           0 :     ss << "    return  log( tmp + pow( (pown(tmp, 2) - 1.0), 0.5));\n";
    1150           0 :     ss << "}";
    1151           0 : }
    1152           0 : void OpTan::GenSlidingWindowFunction(std::stringstream &ss,
    1153             :             const std::string &sSymName, SubArguments &vSubArguments)
    1154             : {
    1155           0 :     ss << "\ndouble " << sSymName;
    1156           0 :     ss << "_"<< BinFuncName() <<"(";
    1157           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1158             :     {
    1159           0 :         if (i) ss << ",";
    1160           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1161             :     }
    1162           0 :     ss << ")\n";
    1163           0 :     ss << "{\n";
    1164           0 :     ss << "    int gid0=get_global_id(0);\n";
    1165           0 :     ss << "    double arg0 = 0.0f;\n";
    1166           0 :     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
    1167             :     assert(tmpCur);
    1168           0 :     if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
    1169             :     {
    1170           0 :         if(tmpCur->GetType() == formula::svSingleVectorRef)
    1171             :         {
    1172             :             const formula::SingleVectorRefToken*tmpCurDVR=
    1173             :                 static_cast
    1174           0 :                 <const formula::SingleVectorRefToken *>(tmpCur);
    1175           0 :             ss << "    arg0 = ";
    1176           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1177           0 :             ss << ";\n";
    1178             : #ifdef ISNAN
    1179           0 :             ss << "    if(isNan(";
    1180           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1181           0 :             ss << ")||(gid0>=";
    1182           0 :             ss << tmpCurDVR->GetArrayLength();
    1183           0 :             ss << "))\n";
    1184           0 :             ss << "    { arg0 = 0.0f; }\n";
    1185             : #endif
    1186             :         }
    1187           0 :         else if(tmpCur->GetType() == formula::svDouble)
    1188             :         {
    1189           0 :             ss << "    arg0=" << tmpCur->GetDouble() << ";\n";
    1190             :         }
    1191             :     }
    1192             :     else
    1193             :     {
    1194           0 :         ss << "        arg0 = ";
    1195           0 :         ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1196           0 :         ss << ";\n";
    1197             :     }
    1198           0 :     ss << "    arg0 = arg0 * M_1_PI;\n";
    1199           0 :     ss << "    return sinpi(arg0) * pow(cospi(arg0), -1);\n";
    1200           0 :     ss << "}";
    1201           0 : }
    1202           0 : void OpTanH::GenSlidingWindowFunction(std::stringstream &ss,
    1203             :             const std::string &sSymName, SubArguments &vSubArguments)
    1204             : {
    1205           0 :     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
    1206             :     const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const
    1207           0 :           formula::SingleVectorRefToken *>(tmpCur);
    1208           0 :     ss << "\ndouble " << sSymName;
    1209           0 :     ss << "_"<< BinFuncName() <<"(";
    1210           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1211             :     {
    1212           0 :         if (i)
    1213           0 :             ss << ",";
    1214           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1215             :     }
    1216           0 :     ss << ")\n";
    1217           0 :     ss << "{\n";
    1218           0 :     ss << "    int gid0=get_global_id(0);\n";
    1219           0 :     ss << "    double arg0 = "<< vSubArguments[0]->GenSlidingWindowDeclRef();
    1220           0 :     ss << ";\n";
    1221             : #ifdef ISNAN
    1222           0 :     ss << "    if(isNan(arg0)||(gid0>=";
    1223           0 :     ss << tmpCurDVR->GetArrayLength();
    1224           0 :     ss << "))\n";
    1225           0 :     ss << "        arg0 = 0;\n";
    1226             : #endif
    1227           0 :     ss << "    double tmp=tanh(arg0);\n";
    1228           0 :     ss << "    return tmp;\n";
    1229           0 :     ss << "}";
    1230           0 : }
    1231           0 : void OpPower::GenSlidingWindowFunction(std::stringstream &ss,
    1232             :             const std::string &sSymName, SubArguments &vSubArguments)
    1233             : {
    1234           0 :     ss << "\ndouble " << sSymName;
    1235           0 :     ss << "_"<< BinFuncName() <<"(";
    1236           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1237             :     {
    1238           0 :         if (i)
    1239           0 :             ss << ",";
    1240           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1241             :     }
    1242           0 :     ss << ")\n";
    1243           0 :     ss << "{\n";
    1244           0 :     ss << "    int gid0=get_global_id(0);\n";
    1245           0 :     ss << "    double arg[2];\n";
    1246           0 :     for( unsigned i=0; i < vSubArguments.size(); ++i)
    1247             :     {
    1248           0 :         FormulaToken *tmpCur = vSubArguments[i]->GetFormulaToken();
    1249             :         assert(tmpCur);
    1250           0 :         if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
    1251             :         {
    1252           0 :             if(tmpCur->GetType() == formula::svDoubleVectorRef)
    1253             :             {
    1254             :                 const formula::DoubleVectorRefToken* tmpCurDVR =
    1255             :                     static_cast<
    1256           0 :                     const formula::DoubleVectorRefToken *>(tmpCur);
    1257           0 :                 ss << "    int i = 0;\n";
    1258           0 :                 ss << "    arg["<<i<<"] = ";
    1259           0 :                 ss << vSubArguments[i]->GenSlidingWindowDeclRef();
    1260           0 :                 ss << ";\n";
    1261             : #ifdef ISNAN
    1262           0 :                 ss << "    if(isNan(arg["<<i;
    1263           0 :                 ss << "])||(gid0>=";
    1264           0 :                 ss << tmpCurDVR->GetArrayLength();
    1265           0 :                 ss << "))\n";
    1266           0 :                 ss << "        arg["<<i;
    1267           0 :                 ss << "] = 0;\n";
    1268             : #endif
    1269             :             }
    1270           0 :             else if(tmpCur->GetType() == formula::svSingleVectorRef)
    1271             :             {
    1272             :                 const formula::SingleVectorRefToken* tmpCurDVR=
    1273             :                       static_cast<
    1274           0 :                       const formula::SingleVectorRefToken *>(tmpCur);
    1275           0 :                 ss << "    arg["<<i<<"] = ";
    1276           0 :                 ss << vSubArguments[i]->GenSlidingWindowDeclRef();
    1277           0 :                 ss << ";\n";
    1278             : #ifdef ISNAN
    1279           0 :                 ss << "    if(isNan(arg["<<i;
    1280           0 :                 ss << "])||(gid0>=";
    1281           0 :                 ss << tmpCurDVR->GetArrayLength();
    1282           0 :                 ss << "))\n";
    1283           0 :                 ss << "        arg["<<i;
    1284           0 :                 ss << "] = 0;\n";
    1285             : #endif
    1286             :             }
    1287           0 :             else if(tmpCur->GetType() == formula::svDouble)
    1288             :             {
    1289           0 :                 ss << "        arg["<<i<<"] = ";
    1290           0 :                 ss << tmpCur->GetDouble() << ";\n";
    1291             :             }
    1292             :         }
    1293             :         else
    1294             :         {
    1295           0 :             ss << "        arg["<<i<<"] = ";
    1296           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
    1297           0 :             ss << ";\n";
    1298             :         }
    1299             :     }
    1300           0 :     ss << "    return pow(arg[0],arg[1]);\n";
    1301           0 :     ss << "}";
    1302           0 : }
    1303           0 : void OpSqrt::GenSlidingWindowFunction(std::stringstream &ss,
    1304             :             const std::string &sSymName, SubArguments &vSubArguments)
    1305             : {
    1306           0 :     ss << "\ndouble " << sSymName;
    1307           0 :     ss << "_"<< BinFuncName() <<"(";
    1308           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1309             :     {
    1310           0 :         if (i)
    1311           0 :             ss << ",";
    1312           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1313             :     }
    1314           0 :     ss << ")\n";
    1315           0 :     ss << "{\n";
    1316           0 :     ss << "    int gid0=get_global_id(0);\n";
    1317           0 :     ss << "    double arg0 = 0.0f;\n";
    1318           0 :     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
    1319             :     assert(tmpCur);
    1320           0 :     if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
    1321             :     {
    1322           0 :         if(tmpCur->GetType() == formula::svSingleVectorRef)
    1323             :         {
    1324             :             const formula::SingleVectorRefToken*tmpCurDVR=
    1325             :                 static_cast
    1326           0 :                 <const formula::SingleVectorRefToken *>(tmpCur);
    1327           0 :             ss << "    arg0 = ";
    1328           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1329           0 :             ss << ";\n";
    1330             : #ifdef ISNAN
    1331           0 :             ss << "    if(isNan(";
    1332           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1333           0 :             ss << ")||(gid0>=";
    1334           0 :             ss << tmpCurDVR->GetArrayLength();
    1335           0 :             ss << "))\n";
    1336           0 :             ss << "    { arg0 = 0; }\n";
    1337             : #endif
    1338             :         }
    1339           0 :         else if(tmpCur->GetType() == formula::svDouble)
    1340             :         {
    1341           0 :             ss << "    arg0=";
    1342           0 :             ss << tmpCur->GetDouble() << ";\n";
    1343             :         }
    1344             :     }
    1345             :     else
    1346             :     {
    1347           0 :         ss << "        arg0 = ";
    1348           0 :         ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1349           0 :         ss << ";\n";
    1350             :     }
    1351           0 :     ss << "    return sqrt(arg0);\n";
    1352           0 :     ss << "}";
    1353           0 : }
    1354           0 : void OpArcCot::GenSlidingWindowFunction(std::stringstream &ss,
    1355             :     const std::string &sSymName, SubArguments &vSubArguments)
    1356             : {
    1357           0 :     ss << "\ndouble " << sSymName;
    1358           0 :     ss << "_"<< BinFuncName() <<"(";
    1359           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1360             :     {
    1361           0 :         if (i) ss << ",";
    1362           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1363             :     }
    1364           0 :     ss << ") {\n";
    1365           0 :     ss << "    int gid0   = get_global_id(0);\n";
    1366           0 :     ss << "    double tmp = " << GetBottom() << ";\n";
    1367             : #ifdef ISNAN
    1368           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
    1369             :     const formula::SingleVectorRefToken*tmpCurDVR0=
    1370           0 :         static_cast<const formula::SingleVectorRefToken *>(tmpCur0);
    1371           0 :     ss << "    int buffer_len = " << tmpCurDVR0->GetArrayLength()<< ";\n";
    1372           0 :     ss << "    if((gid0)>=buffer_len || isNan(";
    1373           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
    1374           0 :     ss << "        tmp = " << GetBottom() << ";\n";
    1375           0 :     ss << "    else \n    ";
    1376             : #endif
    1377           0 :     ss << "    tmp = " << vSubArguments[0]->GenSlidingWindowDeclRef() <<";\n";
    1378           0 :     ss << "    return M_PI_2 - atan(tmp);\n";
    1379           0 :     ss << "}";
    1380           0 : }
    1381           0 : void OpArcCotHyp::GenSlidingWindowFunction(std::stringstream &ss,
    1382             :     const std::string &sSymName, SubArguments &vSubArguments)
    1383             : {
    1384           0 :     ss << "\ndouble " << sSymName;
    1385           0 :     ss << "_"<< BinFuncName() <<"(";
    1386           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1387             :     {
    1388           0 :         if (i) ss << ",";
    1389           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1390             :     }
    1391           0 :     ss << ")\n";
    1392           0 :     ss << "{\n";
    1393           0 :     ss << "    int gid0=get_global_id(0);\n";
    1394           0 :     ss << "    double arg0 = 0.0f;\n";
    1395           0 :     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
    1396             :     assert(tmpCur);
    1397           0 :     if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
    1398             :     {
    1399           0 :         if(tmpCur->GetType() == formula::svSingleVectorRef)
    1400             :         {
    1401             :             const formula::SingleVectorRefToken*tmpCurDVR=
    1402             :                 static_cast
    1403           0 :                 <const formula::SingleVectorRefToken *>(tmpCur);
    1404           0 :             ss << "    arg0 = ";
    1405           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1406           0 :             ss << ";\n";
    1407             : #ifdef ISNAN
    1408           0 :             ss << "    if(isNan(";
    1409           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1410           0 :             ss << ")||(gid0>=";
    1411           0 :             ss << tmpCurDVR->GetArrayLength();
    1412           0 :             ss << "))\n";
    1413           0 :             ss << "    { arg0 = 0.0f; }\n";
    1414             : #endif
    1415             :         }
    1416           0 :         else if(tmpCur->GetType() == formula::svDouble)
    1417             :         {
    1418           0 :             ss << "    arg0=";
    1419           0 :             ss << tmpCur->GetDouble() << ";\n";
    1420             :         }
    1421             :     }
    1422             :     else
    1423             :     {
    1424           0 :         ss << "        arg0 = ";
    1425           0 :         ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1426           0 :         ss << ";\n";
    1427             :     }
    1428           0 :      ss << "    return 0.5 * log(1 + 2 * pown(arg0 - 1.0, -1));\n";
    1429           0 :      ss << "}";
    1430           0 : }
    1431           0 : void OpArcSin::BinInlineFun(std::set<std::string>& decls,
    1432             :     std::set<std::string>& funs)
    1433             : {
    1434           0 :     decls.insert(atan2Decl);
    1435           0 :     funs.insert(atan2Content);
    1436           0 : }
    1437           0 : void OpArcSin::GenSlidingWindowFunction(std::stringstream &ss,
    1438             :     const std::string &sSymName, SubArguments &vSubArguments)
    1439             : {
    1440           0 :     ss << "\ndouble " << sSymName;
    1441           0 :     ss << "_"<< BinFuncName() <<"(";
    1442           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1443             :     {
    1444           0 :         if (i) ss << ",";
    1445           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1446             :     }
    1447           0 :     ss << ") {\n";
    1448           0 :     ss << "    int gid0   = get_global_id(0);\n";
    1449           0 :     ss << "    double tmp = " << GetBottom() << ";\n";
    1450             : #ifdef ISNAN
    1451           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
    1452             :     const formula::SingleVectorRefToken*tmpCurDVR0=
    1453           0 :         static_cast<const formula::SingleVectorRefToken *>(tmpCur0);
    1454           0 :     ss << "    int buffer_len = " << tmpCurDVR0->GetArrayLength() << ";\n";
    1455           0 :     ss << "    if((gid0)>=buffer_len || isNan(";
    1456           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
    1457           0 :     ss << "        tmp = " << GetBottom() << ";\n";
    1458           0 :     ss << "    else \n    ";
    1459             : #endif
    1460           0 :     ss << "    tmp = " << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
    1461           0 :     ss << "    return arctan2(tmp, sqrt(1.0 - pow(tmp, 2)));\n";
    1462           0 :     ss << "}";
    1463           0 : }
    1464           0 : void OpArcSinHyp::GenSlidingWindowFunction(std::stringstream &ss,
    1465             :     const std::string &sSymName, SubArguments &vSubArguments)
    1466             : {
    1467           0 :     ss << "\ndouble " << sSymName;
    1468           0 :     ss << "_"<< BinFuncName() <<"(";
    1469           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1470             :     {
    1471           0 :         if (i) ss << ",";
    1472           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1473             :     }
    1474           0 :     ss << ") {\n";
    1475           0 :     ss << "    int gid0   = get_global_id(0);\n";
    1476           0 :     ss << "    double tmp = " << GetBottom() << ";\n";
    1477           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
    1478             :     assert(tmpCur0);
    1479           0 :     if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
    1480             :     {
    1481           0 :         if(tmpCur0->GetType() == formula::svSingleVectorRef)
    1482             :         {
    1483             :             const formula::SingleVectorRefToken*tmpCurDVR0=
    1484           0 :                 static_cast<const formula::SingleVectorRefToken *>(tmpCur0);
    1485             : #ifdef ISNAN
    1486           0 :             ss << "    int buffer_len = "<<tmpCurDVR0->GetArrayLength()<<";\n";
    1487           0 :             ss << "    if((gid0)>=buffer_len || isNan(";
    1488           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
    1489           0 :             ss << "        tmp = " << GetBottom() << ";\n";
    1490           0 :             ss << "    else \n    ";
    1491             : #endif
    1492           0 :             ss << "    tmp = " << vSubArguments[0]->GenSlidingWindowDeclRef();
    1493           0 :             ss << ";\n";
    1494             :         }
    1495           0 :         else if(tmpCur0->GetType() == formula::svDouble)
    1496             :         {
    1497           0 :             ss << "    tmp = " << tmpCur0->GetDouble() << ";\n";
    1498             :         }
    1499             :     }
    1500             :     else
    1501             :     {
    1502           0 :         ss << "    tmp = " << vSubArguments[0]->GenSlidingWindowDeclRef();
    1503           0 :         ss << ";\n";
    1504             :     }
    1505           0 :     ss << "    return  log( tmp + pow((pown(tmp, 2) + 1.0), 0.5));\n";
    1506           0 :     ss << "}";
    1507           0 : }
    1508           0 : void OpArcTan2::BinInlineFun(std::set<std::string>& decls,
    1509             :     std::set<std::string>& funs)
    1510             : {
    1511           0 :     decls.insert(atan2Decl);
    1512           0 :     funs.insert(atan2Content);
    1513           0 : }
    1514           0 : void OpArcTan2::GenSlidingWindowFunction(std::stringstream &ss,
    1515             :     const std::string &sSymName, SubArguments &vSubArguments)
    1516             : {
    1517           0 :     ss << "\ndouble " << sSymName;
    1518           0 :     ss << "_"<< BinFuncName() <<"(";
    1519           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1520             :     {
    1521           0 :         if (i) ss << ",";
    1522           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1523             :     }
    1524           0 :     ss << ") {\n";
    1525           0 :     ss << "    int gid0 = get_global_id(0);\n";
    1526           0 :     ss << "    double x_num = " << GetBottom() << ";\n";
    1527           0 :     ss << "    double y_num = " << GetBottom() << ";\n";
    1528             : #ifdef ISNAN
    1529           0 :     FormulaToken *iXNum = vSubArguments[0]->GetFormulaToken();
    1530             :     const formula::SingleVectorRefToken*tmpCurDVRX=
    1531           0 :         static_cast<const formula::SingleVectorRefToken *>(iXNum);
    1532           0 :     FormulaToken *iYNum = vSubArguments[1]->GetFormulaToken();
    1533             :     const formula::SingleVectorRefToken*tmpCurDVRY=
    1534           0 :         static_cast<const formula::SingleVectorRefToken *>(iYNum);
    1535           0 :     ss << "    int buffer_x_len = " << tmpCurDVRX->GetArrayLength() << ";\n";
    1536           0 :     ss << "    int buffer_y_len = " << tmpCurDVRY->GetArrayLength() << ";\n";
    1537           0 :     ss << "    if((gid0)>=buffer_x_len || isNan(";
    1538           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
    1539           0 :     ss << "        x_num = " << GetBottom() << ";\n";
    1540           0 :     ss << "    else \n    ";
    1541             : #endif
    1542           0 :     ss << "    x_num = "<< vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
    1543             : #ifdef ISNAN
    1544           0 :     ss << "    if((gid0)>=buffer_y_len || isNan(";
    1545           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef() << "))\n";
    1546           0 :     ss << "        y_num = " << GetBottom() << ";\n";
    1547           0 :     ss << "    else \n    ";
    1548             : #endif
    1549           0 :     ss << "    y_num = "<< vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
    1550           0 :     ss << "    return arctan2(y_num, x_num);\n";
    1551           0 :     ss << "}";
    1552           0 : }
    1553           0 : void OpArcTan::GenSlidingWindowFunction(std::stringstream &ss,
    1554             :     const std::string &sSymName, SubArguments &vSubArguments)
    1555             : {
    1556           0 :     ss << "\ndouble " << sSymName;
    1557           0 :     ss << "_"<< BinFuncName() <<"(";
    1558           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1559             :     {
    1560           0 :         if (i) ss << ",";
    1561           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1562             :     }
    1563           0 :     ss << ")\n";
    1564           0 :     ss << "{\n";
    1565           0 :     ss << "    int gid0=get_global_id(0);\n";
    1566           0 :     ss << "    double arg0 = 0.0f;\n";
    1567           0 :     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
    1568             :     assert(tmpCur);
    1569           0 :     if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
    1570             :     {
    1571           0 :         if(tmpCur->GetType() == formula::svSingleVectorRef)
    1572             :         {
    1573             :             const formula::SingleVectorRefToken*tmpCurDVR=
    1574             :                 static_cast
    1575           0 :                 <const formula::SingleVectorRefToken *>(tmpCur);
    1576           0 :             ss << "    arg0 = ";
    1577           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1578           0 :             ss << ";\n";
    1579             : #ifdef ISNAN
    1580           0 :             ss << "    if(isNan(";
    1581           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1582           0 :             ss << ")||(gid0>=";
    1583           0 :             ss << tmpCurDVR->GetArrayLength();
    1584           0 :             ss << "))\n";
    1585           0 :             ss << "    { arg0 = 0.0f; }\n";
    1586             : #endif
    1587             :         }
    1588           0 :         else if(tmpCur->GetType() == formula::svDouble)
    1589             :         {
    1590           0 :             ss << "    arg0=" << tmpCur->GetDouble() << ";\n";
    1591             :         }
    1592             :     }
    1593             :     else
    1594             :     {
    1595           0 :         ss << "        arg0 = ";
    1596           0 :         ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    1597           0 :         ss << ";\n";
    1598             :     }
    1599           0 :     ss << "    return atan(arg0);\n";
    1600           0 :     ss << "}";
    1601           0 : }
    1602           0 : void OpArcTanH::GenSlidingWindowFunction(std::stringstream &ss,
    1603             :     const std::string &sSymName, SubArguments &vSubArguments)
    1604             : {
    1605           0 :     ss << "\ndouble " << sSymName;
    1606           0 :     ss << "_"<< BinFuncName() <<"(";
    1607           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1608             :     {
    1609           0 :         if (i) ss << ",";
    1610           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1611             :     }
    1612           0 :     ss << ") {\n";
    1613           0 :     ss << "    int gid0 = get_global_id(0);\n";
    1614           0 :     ss << "    double tmp = " << GetBottom() << ";\n";
    1615             : #ifdef ISNAN
    1616           0 :     FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
    1617             :     const formula::SingleVectorRefToken*tmpCurDVR0=
    1618           0 :         static_cast<const formula::SingleVectorRefToken *>(tmpCur0);
    1619           0 :     ss << "    int buffer_len = " << tmpCurDVR0->GetArrayLength() << ";\n";
    1620           0 :     ss << "    if((gid0)>=buffer_len || isNan(";
    1621           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
    1622           0 :     ss << "        tmp = " << GetBottom() << ";\n";
    1623           0 :     ss << "    else \n    ";
    1624             : #endif
    1625           0 :     ss << "    tmp = " << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
    1626           0 :     ss << "    double a = 1.0 + tmp;\n";
    1627           0 :     ss << "    double b = 1.0 - tmp;\n";
    1628           0 :     ss << "    return log(pow(a/b, 0.5));\n";
    1629           0 :     ss << "}";
    1630           0 : }
    1631           0 : void OpBitAnd::GenSlidingWindowFunction(std::stringstream &ss,
    1632             :     const std::string &sSymName, SubArguments &vSubArguments)
    1633             : {
    1634           0 :     ss << "\ndouble " << sSymName;
    1635           0 :     ss << "_"<< BinFuncName() <<"(";
    1636           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1637             :     {
    1638           0 :         if (i) ss << ",";
    1639           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1640             :     }
    1641           0 :     ss << ") {\n";
    1642           0 :     ss << "    int gid0 = get_global_id(0);\n";
    1643           0 :     ss << "    double num1 = " << GetBottom() << ";\n";
    1644           0 :     ss << "    double num2 = " << GetBottom() << ";\n";
    1645             : #ifdef ISNAN
    1646           0 :     FormulaToken *iNum1 = vSubArguments[0]->GetFormulaToken();
    1647             :     const formula::SingleVectorRefToken* tmpCurDVRNum1=
    1648           0 :         static_cast<const formula::SingleVectorRefToken *>(iNum1);
    1649           0 :     FormulaToken *iNum2 = vSubArguments[1]->GetFormulaToken();
    1650             :     const formula::SingleVectorRefToken* tmpCurDVRNum2=
    1651           0 :         static_cast<const formula::SingleVectorRefToken *>(iNum2);
    1652           0 :     ss << "    int buffer_num1_len = "<<tmpCurDVRNum1->GetArrayLength()<<";\n";
    1653           0 :     ss << "    int buffer_num2_len = "<<tmpCurDVRNum2->GetArrayLength()<<";\n";
    1654           0 :     ss << "    if((gid0)>=buffer_num1_len || isNan(";
    1655           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
    1656           0 :     ss << "        num1 = " << GetBottom() << ";\n";
    1657           0 :     ss << "    else \n    ";
    1658             : #endif
    1659           0 :     ss << "    num1 = " << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
    1660             : #ifdef ISNAN
    1661           0 :     ss << "    if((gid0)>=buffer_num2_len || isNan(";
    1662           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef() << "))\n";
    1663           0 :     ss << "        num2 = " << GetBottom() << ";\n";
    1664           0 :     ss << "    else \n    ";
    1665             : #endif
    1666           0 :     ss << "    num2 = " << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
    1667           0 :     ss << "    return (long)num1 & (long)num2;\n";
    1668           0 :     ss << "}";
    1669           0 : }
    1670           0 : void OpLn::GenSlidingWindowFunction(
    1671             :     std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
    1672             : {
    1673           0 :     ss << "\ndouble " << sSymName;
    1674           0 :     ss << "_"<< BinFuncName() <<"(";
    1675           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1676             :     {
    1677           0 :         if (i)
    1678           0 :             ss << ",";
    1679           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1680             :     }
    1681           0 :     ss << ")\n{\n";
    1682           0 :     ss << "    int gid0=get_global_id(0);\n";
    1683           0 :     ss << "    int singleIndex =  gid0;\n";
    1684             : 
    1685           0 :     GenTmpVariables(ss,vSubArguments);
    1686           0 :     CheckAllSubArgumentIsNan(ss,vSubArguments);
    1687             : 
    1688           0 :     ss << "    double tmp=log1p(tmp0-1);\n";
    1689           0 :     ss << "    return tmp;\n";
    1690           0 :     ss << "}";
    1691           0 : }
    1692             : 
    1693           0 : void OpRound::GenSlidingWindowFunction(std::stringstream &ss,
    1694             :              const std::string &sSymName, SubArguments &vSubArguments)
    1695             : {
    1696           0 :     ss << "\ndouble " << sSymName;
    1697           0 :     ss << "_"<< BinFuncName() <<"(";
    1698           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1699             :     {
    1700           0 :         if (i)
    1701           0 :             ss << ",";
    1702           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1703             :     }
    1704           0 :     ss << ")\n{\n";
    1705           0 :     ss << "    int gid0=get_global_id(0);\n";
    1706           0 :     ss << "    int singleIndex =  gid0;\n";
    1707           0 :     GenTmpVariables(ss,vSubArguments);
    1708           0 :     CheckAllSubArgumentIsNan(ss,vSubArguments);
    1709           0 :     if(vSubArguments.size() ==2)
    1710             :     {
    1711           0 :         ss << "    for(int i=0;i<tmp1;i++)\n";
    1712           0 :         ss << "        tmp0 = tmp0 * 10;\n";
    1713             :     }
    1714           0 :     ss << "    double tmp=round(tmp0);\n";
    1715           0 :     if(vSubArguments.size() ==2)
    1716             :     {
    1717           0 :         ss << "    for(int i=0;i<tmp1;i++)\n";
    1718           0 :         ss << "        tmp = tmp / 10;\n";
    1719             :     }
    1720           0 :     ss << "    return tmp;\n";
    1721           0 :     ss << "}";
    1722           0 : }
    1723           0 : void OpRoundUp::GenSlidingWindowFunction(std::stringstream &ss,
    1724             :              const std::string &sSymName, SubArguments &vSubArguments)
    1725             : {
    1726           0 :     ss << "\ndouble " << sSymName;
    1727           0 :     ss << "_"<< BinFuncName() <<"(";
    1728           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1729             :     {
    1730           0 :         if (i)
    1731           0 :             ss << ",";
    1732           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1733             :     }
    1734           0 :     ss << ")\n{\n";
    1735           0 :     ss << "    int gid0=get_global_id(0);\n";
    1736           0 :     ss << "    int singleIndex =  gid0;\n";
    1737           0 :     ss << "    int intTmp;\n";
    1738           0 :     ss << "    double doubleTmp;\n";
    1739           0 :     ss << "    double tmp;\n";
    1740           0 :     GenTmpVariables(ss,vSubArguments);
    1741           0 :     CheckAllSubArgumentIsNan(ss,vSubArguments);
    1742           0 :     ss << "    if(tmp1 >20 || tmp1 < -20)";
    1743           0 :     ss << "    {\n";
    1744           0 :     ss << "        tmp = NAN;\n";
    1745           0 :     ss << "    }else\n";
    1746           0 :     ss << "    {\n";
    1747           0 :     ss << "        for(int i=0;i<tmp1;i++)\n";
    1748           0 :     ss << "            tmp0 = tmp0 * 10;\n";
    1749           0 :     ss << "        intTmp = (int)tmp0;\n";
    1750           0 :     ss << "        doubleTmp = intTmp;\n";
    1751           0 :     ss << "        if(isequal(doubleTmp,tmp0))\n";
    1752           0 :     ss << "            tmp = doubleTmp;\n";
    1753           0 :     ss << "        else\n";
    1754           0 :     ss << "            tmp = doubleTmp + 1;\n";
    1755           0 :     ss << "        for(int i=0;i<tmp1;i++)\n";
    1756           0 :     ss << "            tmp = tmp / 10;\n";
    1757           0 :     ss << "    }\n";
    1758           0 :     ss << "    return tmp;\n";
    1759           0 :     ss << "}";
    1760           0 : }
    1761           0 : void OpRoundDown::GenSlidingWindowFunction(std::stringstream &ss,
    1762             :              const std::string &sSymName, SubArguments &vSubArguments)
    1763             : {
    1764           0 :     ss << "\ndouble " << sSymName;
    1765           0 :     ss << "_"<< BinFuncName() <<"(";
    1766           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1767             :     {
    1768           0 :         if (i)
    1769           0 :             ss << ",";
    1770           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1771             :     }
    1772           0 :     ss << ")\n{\n";
    1773           0 :     ss << "    int gid0=get_global_id(0);\n";
    1774           0 :     ss << "    int singleIndex =  gid0;\n";
    1775           0 :     ss << "    int intTmp;\n";
    1776           0 :     ss << "    double tmp;\n";
    1777           0 :     GenTmpVariables(ss,vSubArguments);
    1778           0 :     CheckAllSubArgumentIsNan(ss,vSubArguments);
    1779           0 :     ss << "    if(tmp1 >20 || tmp1 < -20)";
    1780           0 :     ss << "    {\n";
    1781           0 :     ss << "        tmp = NAN;\n";
    1782           0 :     ss << "    }else\n";
    1783           0 :     ss << "    {\n";
    1784           0 :     ss << "        for(int i=0;i<tmp1;i++)\n";
    1785           0 :     ss << "            tmp0 = tmp0 * 10;\n";
    1786           0 :     ss << "        intTmp = (int)tmp0;\n";
    1787           0 :     ss << "        tmp = intTmp;\n";
    1788           0 :     ss << "        for(int i=0;i<tmp1;i++)\n";
    1789           0 :     ss << "            tmp = tmp / 10;\n";
    1790           0 :     ss << "    }\n";
    1791           0 :     ss << "    return tmp;\n";
    1792           0 :     ss << "}";
    1793           0 : }
    1794           0 : void OpInt::GenSlidingWindowFunction(std::stringstream &ss,
    1795             :              const std::string &sSymName, SubArguments &vSubArguments)
    1796             : {
    1797           0 :     ss << "\ndouble " << sSymName;
    1798           0 :     ss << "_"<< BinFuncName() <<"(";
    1799           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1800             :     {
    1801           0 :         if (i)
    1802           0 :             ss << ",";
    1803           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1804             :     }
    1805           0 :     ss << ")\n{\n";
    1806           0 :     ss << "    int gid0=get_global_id(0);\n";
    1807           0 :     ss << "    int singleIndex =  gid0;\n";
    1808           0 :     ss << "    int intTmp;\n";
    1809           0 :     ss << "    double tmp;\n";
    1810           0 :     GenTmpVariables(ss,vSubArguments);
    1811           0 :     CheckAllSubArgumentIsNan(ss,vSubArguments);
    1812           0 :     ss << "    intTmp = (int)tmp0;\n";
    1813           0 :     ss << "    tmp = intTmp;\n";
    1814           0 :     ss << "    return tmp;\n";
    1815           0 :     ss << "}";
    1816           0 : }
    1817           0 : void OpNegSub::GenSlidingWindowFunction(std::stringstream &ss,
    1818             :              const std::string &sSymName, SubArguments &vSubArguments)
    1819             : {
    1820           0 :     ss << "\ndouble " << sSymName;
    1821           0 :     ss << "_"<< BinFuncName() <<"(";
    1822           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1823             :     {
    1824           0 :         if (i)
    1825           0 :             ss << ",";
    1826           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1827             :     }
    1828           0 :     ss << ")\n{\n";
    1829           0 :     ss << "    int gid0=get_global_id(0);\n";
    1830           0 :     ss << "    int singleIndex =  gid0;\n";
    1831           0 :     GenTmpVariables(ss,vSubArguments);
    1832           0 :     CheckAllSubArgumentIsNan(ss,vSubArguments);
    1833           0 :     ss << "    return -tmp0;\n";
    1834           0 :     ss << "}";
    1835           0 : }
    1836             : 
    1837           0 : void OpRadians::GenSlidingWindowFunction(std::stringstream &ss,
    1838             :              const std::string &sSymName, SubArguments &vSubArguments)
    1839             : {
    1840           0 :     ss << "\ndouble " << sSymName;
    1841           0 :     ss << "_"<< BinFuncName() <<"(";
    1842           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1843             :     {
    1844           0 :         if (i)
    1845           0 :             ss << ",";
    1846           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1847             :     }
    1848           0 :     ss << ")\n{\n";
    1849           0 :     ss << "    int gid0=get_global_id(0);\n";
    1850           0 :     ss << "    int singleIndex =  gid0;\n";
    1851           0 :     ss << "    double tmp;\n";
    1852           0 :     GenTmpVariables(ss,vSubArguments);
    1853           0 :     CheckAllSubArgumentIsNan(ss,vSubArguments);
    1854           0 :     ss << "    tmp = tmp0 * 3.141592657 * pow(180.0,-1);\n";
    1855           0 :     ss << "    return tmp;\n";
    1856           0 :     ss << "}";
    1857           0 : }
    1858           0 : void OpIsEven::GenSlidingWindowFunction(std::stringstream &ss,
    1859             :              const std::string &sSymName, SubArguments &vSubArguments)
    1860             : {
    1861           0 :     ss << "\ndouble " << sSymName;
    1862           0 :     ss << "_"<< BinFuncName() <<"(";
    1863           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1864             :     {
    1865           0 :         if (i)
    1866           0 :             ss << ",";
    1867           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1868             :     }
    1869           0 :     ss << ")\n{\n";
    1870           0 :     ss << "    int gid0=get_global_id(0);\n";
    1871           0 :     ss << "    int singleIndex =  gid0;\n";
    1872           0 :     ss << "    double tmp;\n";
    1873           0 :     GenTmpVariables(ss,vSubArguments);
    1874           0 :     CheckAllSubArgumentIsNan(ss,vSubArguments);
    1875           0 :     ss << "    tmp = (fmod(floor(fabs(tmp0)), 2.0)<0.5);\n";
    1876           0 :     ss << "    return tmp;\n";
    1877           0 :     ss << "}";
    1878           0 : }
    1879           0 : void OpIsOdd::GenSlidingWindowFunction(std::stringstream &ss,
    1880             :              const std::string &sSymName, SubArguments &vSubArguments)
    1881             : {
    1882           0 :     ss << "\ndouble " << sSymName;
    1883           0 :     ss << "_"<< BinFuncName() <<"(";
    1884           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1885             :     {
    1886           0 :         if (i)
    1887           0 :             ss << ",";
    1888           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1889             :     }
    1890           0 :     ss << ")\n{\n";
    1891           0 :     ss << "    int gid0=get_global_id(0);\n";
    1892           0 :     ss << "    int singleIndex =  gid0;\n";
    1893           0 :     ss << "    double tmp;\n";
    1894           0 :     GenTmpVariables(ss,vSubArguments);
    1895           0 :     CheckAllSubArgumentIsNan(ss,vSubArguments);
    1896           0 :     ss << "    tmp = !(fmod(floor(fabs(tmp0)), 2.0)<0.5);\n";
    1897           0 :     ss << "    return tmp;\n";
    1898           0 :     ss << "}";
    1899           0 : }
    1900           0 : void OpOdd::GenSlidingWindowFunction(
    1901             :     std::stringstream &ss, const std::string &sSymName,
    1902             :     SubArguments &vSubArguments)
    1903             : {
    1904           0 :     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
    1905             :     const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const
    1906           0 :         formula::SingleVectorRefToken *>(tmpCur);
    1907           0 :     ss << Math_Intg_Str;
    1908           0 :     ss << "\ndouble " << sSymName;
    1909           0 :     ss << "_"<< BinFuncName() <<"(";
    1910           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    1911             :     {
    1912           0 :         if (i)
    1913           0 :             ss << ",";
    1914           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1915             :     }
    1916           0 :     ss << ")\n{\n";
    1917           0 :     ss <<"    int gid0=get_global_id(0);\n";
    1918           0 :     ss << "    double tmp=0;\n";
    1919           0 :     ss << "    double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
    1920           0 :     ss << ";\n";
    1921             : #ifdef ISNAN
    1922           0 :     ss<< "    if(isNan(arg0)||(gid0>=";
    1923           0 :     ss<<tmpCurDVR->GetArrayLength();
    1924           0 :     ss<<"))\n";
    1925           0 :     ss<<"        arg0 = 0;\n";
    1926             : #endif
    1927           0 :     ss << "    if (arg0 > 0.0 ){\n";
    1928           0 :     ss << "        tmp=Intg(arg0);\n";
    1929           0 :     ss << "        if(tmp-trunc(tmp/2)*2 == 0)\n";
    1930           0 :     ss << "            tmp=tmp+1;\n";
    1931           0 :     ss << "    }else if (arg0 < 0.0 ){\n";
    1932           0 :     ss << "        tmp=Intg(arg0);\n";
    1933           0 :     ss << "        if(tmp-trunc(tmp/2)*2 == 0)\n";
    1934           0 :     ss << "            tmp=tmp-1.0;\n";
    1935           0 :     ss << "    }else if (arg0 == 0.0 )\n";
    1936           0 :     ss << "            tmp=1.0;\n";
    1937           0 :     ss << "    return tmp;\n";
    1938           0 :     ss << "}";
    1939           0 : }
    1940           0 : void OpCountIf::GenSlidingWindowFunction(std::stringstream &ss,
    1941             :     const std::string &sSymName, SubArguments &vSubArguments)
    1942             : {
    1943           0 :     ss << "\ndouble " << sSymName;
    1944           0 :     ss << "_"<< BinFuncName() <<"(";
    1945           0 :     for (unsigned i = 0; i < 2; i++)
    1946             :     {
    1947           0 :         if (i)
    1948           0 :             ss << ",";
    1949           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    1950             :     }
    1951           0 :     ss << ")\n";
    1952           0 :     ss << "{\n";
    1953           0 :     ss << "    int gid0=get_global_id(0);\n";
    1954           0 :     ss << "    double vara, varb;\n";
    1955           0 :     ss << "    int varc = 0;\n";
    1956           0 :     FormulaToken *tmpCur = vSubArguments[1]->GetFormulaToken();
    1957             :     assert(tmpCur);
    1958           0 :     if(ocPush == vSubArguments[1]->GetFormulaToken()->GetOpCode())
    1959             :     {
    1960           0 :         if(tmpCur->GetType() == formula::svSingleVectorRef)
    1961             :         {
    1962             :             const formula::SingleVectorRefToken* tmpCurDVR=
    1963             :                 static_cast<
    1964           0 :                 const formula::SingleVectorRefToken *>(tmpCur);
    1965           0 :             ss << "    varb = ";
    1966           0 :             ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    1967           0 :             ss << ";\n";
    1968             : #ifdef ISNAN
    1969           0 :             ss << "    if(isNan(varb)||(gid0>=";
    1970           0 :             ss << tmpCurDVR->GetArrayLength();
    1971           0 :             ss << "))\n";
    1972           0 :             ss << "        varb = 0;\n";
    1973             : #endif
    1974             :         }
    1975           0 :         else if(tmpCur->GetType() == formula::svDouble)
    1976             :         {
    1977           0 :             ss << "    varb = ";
    1978           0 :             ss << tmpCur->GetDouble() << ";\n";
    1979             :         }
    1980             :     }
    1981             :     else
    1982             :     {
    1983           0 :         ss << "    varb = ";
    1984           0 :         ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    1985           0 :         ss << ";\n";
    1986             :     }
    1987           0 :     tmpCur = vSubArguments[0]->GetFormulaToken();
    1988             :     assert(tmpCur);
    1989           0 :     if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
    1990             :     {
    1991             :         //TODO       DoubleVector
    1992           0 :         if (tmpCur->GetType() == formula::svDoubleVectorRef)
    1993             :         {
    1994             :             const formula::DoubleVectorRefToken* pDVR =
    1995           0 :                 static_cast<const formula::DoubleVectorRefToken *>(tmpCur);
    1996           0 :             size_t nCurWindowSize = pDVR->GetRefRowSize();
    1997           0 :             ss << "    for (int i = ";
    1998           0 :             if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
    1999             :             {
    2000             : #ifdef  ISNAN
    2001           0 :                 ss << "gid0; i < " << pDVR->GetArrayLength();
    2002           0 :                 ss << " && i < " << nCurWindowSize  << "; ++i)\n";
    2003           0 :                 ss << "    {\n";
    2004             : #else
    2005             :                 ss << "gid0; i < "<< nCurWindowSize << "; ++i)\n";
    2006             :                 ss << "    {\n";
    2007             : #endif
    2008             :             }
    2009           0 :             else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
    2010             :             {
    2011             : #ifdef  ISNAN
    2012           0 :                 ss << "0; i < " << pDVR->GetArrayLength();
    2013           0 :                 ss << " && i < gid0+"<< nCurWindowSize << "; ++i)\n";
    2014           0 :                 ss << "    {\n";
    2015             : #else
    2016             :                 ss << "0; i < gid0+"<< nCurWindowSize << "; ++i)\n";
    2017             :                 ss << "    {\n";
    2018             : #endif
    2019             :             }
    2020           0 :             else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
    2021             :             {
    2022             : #ifdef  ISNAN
    2023           0 :                 ss << "0; i + gid0 < " << pDVR->GetArrayLength();
    2024           0 :                 ss << " &&  i < "<< nCurWindowSize << "; ++i)\n";
    2025           0 :                 ss << "    {\n";
    2026             : #else
    2027             :                 ss << "0; i < "<< nCurWindowSize << "; ++i)\n";
    2028             :                 ss << "    {\n";
    2029             : #endif
    2030             :             }
    2031             :             else
    2032             :             {
    2033             : #ifdef  ISNAN
    2034           0 :                 ss << "0; i < "<< nCurWindowSize << "; ++i)\n";
    2035           0 :                 ss << "    {\n";
    2036             : #else
    2037             :                 ss << "0; i < "<< nCurWindowSize << "; ++i)\n";
    2038             :                 ss << "    {\n";
    2039             : #endif
    2040             :             }
    2041           0 :             ss << "        vara = ";
    2042           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    2043           0 :             ss << ";\n";
    2044             : #ifdef  ISNAN
    2045           0 :             ss << "        if (isNan(vara))\n";
    2046           0 :             ss << "            continue;\n";
    2047             : #endif
    2048           0 :             ss << "        (vara == varb) && varc++;\n";
    2049           0 :             ss << "    }\n";
    2050             :         }
    2051           0 :         else if(tmpCur->GetType() == formula::svSingleVectorRef)
    2052             :         {
    2053             :             const formula::SingleVectorRefToken* tmpCurDVR=
    2054             :                 static_cast<
    2055           0 :                 const formula::SingleVectorRefToken *>(tmpCur);
    2056           0 :             ss << "    vara = ";
    2057           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    2058           0 :             ss << ";\n";
    2059             : #ifdef ISNAN
    2060           0 :             ss << "    if(isNan(vara)||(gid0>=";
    2061           0 :             ss << tmpCurDVR->GetArrayLength();
    2062           0 :             ss << "))\n";
    2063           0 :             ss << "        return 0;\n";
    2064           0 :             ss << "    (vara == varb) && varc++;\n";
    2065             : #endif
    2066             :         }
    2067             :     }
    2068           0 :     ss << "    return varc;\n";
    2069           0 :     ss << "}";
    2070           0 : }
    2071           0 : void OpSumIf::GenSlidingWindowFunction(std::stringstream &ss,
    2072             :     const std::string &sSymName, SubArguments &vSubArguments)
    2073             : {
    2074           0 :     ss << "\ndouble " << sSymName;
    2075           0 :     ss << "_"<< BinFuncName() <<"(";
    2076           0 :     int flag = 3 == vSubArguments.size() ? 2 : 0;
    2077           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    2078             :     {
    2079           0 :         if (i)
    2080           0 :             ss << ",";
    2081           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    2082             :     }
    2083           0 :     ss << ")\n";
    2084           0 :     ss << "{\n";
    2085           0 :     ss << "    int gid0=get_global_id(0);\n";
    2086           0 :     ss << "    double vara, varb, varc, sum = 0.0f;\n";
    2087           0 :     FormulaToken *tmpCur = vSubArguments[1]->GetFormulaToken();
    2088             :     assert(tmpCur);
    2089           0 :     if(ocPush == vSubArguments[1]->GetFormulaToken()->GetOpCode())
    2090             :     {
    2091           0 :         if(tmpCur->GetType() == formula::svSingleVectorRef)
    2092             :         {
    2093             :             const formula::SingleVectorRefToken* tmpCurDVR=
    2094             :                 static_cast<
    2095           0 :                 const formula::SingleVectorRefToken *>(tmpCur);
    2096           0 :             ss << "    varb = ";
    2097           0 :             ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    2098           0 :             ss << ";\n";
    2099             : #ifdef ISNAN
    2100           0 :             ss << "    if(isNan(varb)||(gid0>=";
    2101           0 :             ss << tmpCurDVR->GetArrayLength();
    2102           0 :             ss << "))\n";
    2103           0 :             ss << "        varb = 0;\n";
    2104             : #endif
    2105             :         }
    2106           0 :         else if(tmpCur->GetType() == formula::svDouble)
    2107             :         {
    2108           0 :             ss << "    varb = ";
    2109           0 :             ss << tmpCur->GetDouble() << ";\n";
    2110             :         }
    2111             :     }
    2112             :     else
    2113             :     {
    2114           0 :         ss << "    varb = ";
    2115           0 :         ss << vSubArguments[1]->GenSlidingWindowDeclRef();
    2116           0 :         ss << ";\n";
    2117             :     }
    2118           0 :     tmpCur = vSubArguments[0]->GetFormulaToken();
    2119             :     assert(tmpCur);
    2120           0 :     if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
    2121             :     {
    2122             :         //TODO       DoubleVector
    2123           0 :         if (tmpCur->GetType() == formula::svDoubleVectorRef)
    2124             :         {
    2125             :             const formula::DoubleVectorRefToken* pDVR =
    2126           0 :                 static_cast<const formula::DoubleVectorRefToken *>(tmpCur);
    2127           0 :             size_t nCurWindowSize = pDVR->GetRefRowSize();
    2128           0 :             ss << "    for (int i = ";
    2129           0 :             if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
    2130             :             {
    2131             : #ifdef  ISNAN
    2132           0 :                 ss << "gid0; i < " << pDVR->GetArrayLength();
    2133           0 :                 ss << " && i < " << nCurWindowSize  << "; ++i)\n";
    2134           0 :                 ss << "    {\n";
    2135             : #else
    2136             :                 ss << "gid0; i < "<< nCurWindowSize << "; ++i)\n";
    2137             :                 ss << "    {\n";
    2138             : #endif
    2139             :             }
    2140           0 :             else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
    2141             :             {
    2142             : #ifdef  ISNAN
    2143           0 :                 ss << "0; i < " << pDVR->GetArrayLength();
    2144           0 :                 ss << " && i < gid0+"<< nCurWindowSize << "; ++i)\n";
    2145           0 :                 ss << "    {\n";
    2146             : #else
    2147             :                 ss << "0; i < gid0+"<< nCurWindowSize << "; ++i)\n";
    2148             :                 ss << "    {\n";
    2149             : #endif
    2150             :             }
    2151           0 :             else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
    2152             :             {
    2153             : #ifdef  ISNAN
    2154           0 :                 ss << "0; i + gid0 < " << pDVR->GetArrayLength();
    2155           0 :                 ss << " &&  i < "<< nCurWindowSize << "; ++i)\n";
    2156           0 :                 ss << "    {\n";
    2157             : #else
    2158             :                 ss << "0; i < "<< nCurWindowSize << "; ++i)\n";
    2159             :                 ss << "    {\n";
    2160             : #endif
    2161             :             }
    2162             :             else
    2163             :             {
    2164             : #ifdef  ISNAN
    2165           0 :                 ss << "0; i < "<< nCurWindowSize << "; ++i)\n";
    2166           0 :                 ss << "    {\n";
    2167             : #else
    2168             :                 ss << "0; i < "<< nCurWindowSize << "; ++i)\n";
    2169             :                 ss << "    {\n";
    2170             : #endif
    2171             :             }
    2172           0 :             ss << "        vara = ";
    2173           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    2174           0 :             ss << ";\n";
    2175             : #ifdef  ISNAN
    2176           0 :             ss << "        if (isNan(vara))\n";
    2177           0 :             ss << "            continue;\n";
    2178             : #endif
    2179           0 :             ss << "        varc = ";
    2180           0 :             ss << vSubArguments[flag]->GenSlidingWindowDeclRef();
    2181           0 :             ss << ";\n";
    2182             : #ifdef  ISNAN
    2183           0 :             ss << "        if (isNan(varc))\n";
    2184           0 :             ss << "            varc = 0.0f;\n";
    2185             : #endif
    2186           0 :             ss << "        (vara == varb)&&(sum = sum + varc);\n";
    2187           0 :             ss << "    }\n";
    2188             :         }
    2189           0 :         else if(tmpCur->GetType() == formula::svSingleVectorRef)
    2190             :         {
    2191             :             const formula::SingleVectorRefToken* tmpCurDVR=
    2192             :                 static_cast<
    2193           0 :                 const formula::SingleVectorRefToken *>(tmpCur);
    2194           0 :             ss << "    vara = ";
    2195           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    2196           0 :             ss << ";\n";
    2197             : #ifdef ISNAN
    2198           0 :             ss << "    if(isNan(vara)||(gid0>=";
    2199           0 :             ss << tmpCurDVR->GetArrayLength();
    2200           0 :             ss << "))\n";
    2201           0 :             ss << "        return 0;\n";
    2202             : #endif
    2203           0 :             ss << "    int i = 0;\n";
    2204           0 :             ss << "    varc = ";
    2205           0 :             ss << vSubArguments[flag]->GenSlidingWindowDeclRef();
    2206           0 :             ss << ";\n";
    2207             : #ifdef ISNAN
    2208           0 :             ss << "    if(isNan(varc)||(gid0>=";
    2209           0 :             ss << tmpCurDVR->GetArrayLength();
    2210           0 :             ss << "))\n";
    2211           0 :             ss << "        varc = 0.0f;\n";
    2212             : #endif
    2213             : 
    2214           0 :             ss << "        (vara == varb)&&(sum = sum + varc);\n";
    2215             : 
    2216             :         }
    2217             :     }
    2218           0 :     ss << "    return sum;\n";
    2219           0 :     ss << "}";
    2220           0 : }
    2221           0 : void OpTrunc::GenSlidingWindowFunction(std::stringstream &ss,
    2222             :             const std::string &sSymName, SubArguments &vSubArguments)
    2223             : {
    2224           0 :     ss << "\ndouble " << sSymName;
    2225           0 :     ss << "_"<< BinFuncName() <<"(";
    2226           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    2227             :     {
    2228           0 :         if (i)
    2229           0 :             ss << ",";
    2230           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    2231             :     }
    2232           0 :     ss << ")\n";
    2233           0 :     ss << "{\n";
    2234           0 :     ss << "    int gid0=get_global_id(0);\n";
    2235           0 :     ss << "    double arg[2];\n";
    2236           0 :     for( unsigned i=0; i < vSubArguments.size(); ++i)
    2237             :     {
    2238           0 :         FormulaToken *tmpCur = vSubArguments[i]->GetFormulaToken();
    2239             :         assert(tmpCur);
    2240           0 :         if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
    2241             :         {
    2242           0 :             if(tmpCur->GetType() == formula::svDoubleVectorRef)
    2243             :             {
    2244             :                 const formula::DoubleVectorRefToken* tmpCurDVR =
    2245             :                     static_cast<
    2246           0 :                     const formula::DoubleVectorRefToken *>(tmpCur);
    2247           0 :                 ss << "    int i = 0;\n";
    2248           0 :                 ss << "    arg["<<i<<"] = ";
    2249           0 :                 ss << vSubArguments[i]->GenSlidingWindowDeclRef();
    2250           0 :                 ss << ";\n";
    2251             : #ifdef ISNAN
    2252           0 :                 ss << "    if(isNan(arg["<<i;
    2253           0 :                 ss << "])||(gid0>=";
    2254           0 :                 ss << tmpCurDVR->GetArrayLength();
    2255           0 :                 ss << "))\n";
    2256           0 :                 ss << "        arg["<<i;
    2257           0 :                 ss << "] = 0;\n";
    2258             : #endif
    2259             :             }
    2260           0 :             else if(tmpCur->GetType() == formula::svSingleVectorRef)
    2261             :             {
    2262             :                 const formula::SingleVectorRefToken* tmpCurDVR=
    2263             :                       static_cast<
    2264           0 :                       const formula::SingleVectorRefToken *>(tmpCur);
    2265           0 :                 ss << "    arg["<<i<<"] = ";
    2266           0 :                 ss << vSubArguments[i]->GenSlidingWindowDeclRef();
    2267           0 :                 ss << ";\n";
    2268             : #ifdef ISNAN
    2269           0 :                 ss << "    if(isNan(arg["<<i;
    2270           0 :                 ss << "])||(gid0>=";
    2271           0 :                 ss << tmpCurDVR->GetArrayLength();
    2272           0 :                 ss << "))\n";
    2273           0 :                 ss << "        arg["<<i;
    2274           0 :                 ss << "] = 0;\n";
    2275             : #endif
    2276             :             }
    2277           0 :             else if(tmpCur->GetType() == formula::svDouble)
    2278             :             {
    2279           0 :                 ss << "        arg["<<i<<"] = ";
    2280           0 :                 ss << tmpCur->GetDouble() << ";\n";
    2281             :             }
    2282             :         }
    2283             :         else
    2284             :         {
    2285           0 :             ss << "        arg["<<i<<"] = ";
    2286           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
    2287           0 :             ss << ";\n";
    2288             :         }
    2289             :     }
    2290           0 :     ss << "    double argm = arg[0];\n";
    2291           0 :     ss << "    int n = (int)arg[1];\n";
    2292           0 :     ss << "    double nn = 1.0f;\n";
    2293           0 :     ss << "    for(int i = 0; i < n; ++i)\n";
    2294           0 :     ss << "    {\n";
    2295           0 :     ss << "        argm = argm * 10;\n";
    2296           0 :     ss << "        nn = nn * 10;\n";
    2297           0 :     ss << "    }\n";
    2298           0 :     ss << "    modf(argm, &argm);\n";
    2299           0 :     ss << "    return argm / nn;\n";
    2300           0 :     ss << "}";
    2301           0 : }
    2302           0 : void OpFloor::GenSlidingWindowFunction(
    2303             :     std::stringstream &ss, const std::string &sSymName,
    2304             :     SubArguments &vSubArguments)
    2305             : {
    2306           0 :     ss << "\ndouble " << sSymName;
    2307           0 :     ss << "_"<< BinFuncName() <<"(";
    2308           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    2309             :     {
    2310           0 :         if (i)
    2311           0 :             ss << ",";
    2312           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    2313             :     }
    2314           0 :     ss << ")\n{\n";
    2315           0 :     ss << "    int gid0=get_global_id(0);\n";
    2316           0 :     ss << "    double arg0,arg1,arg2=0.0;\n";
    2317           0 :     ss << "    arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
    2318           0 :     ss << ";\n";
    2319           0 :     ss << "    arg1 = " << vSubArguments[1]->GenSlidingWindowDeclRef();
    2320           0 :     ss << ";\n";
    2321           0 :     if ( 3 == vSubArguments.size() )
    2322             :     {
    2323           0 :         ss << "    arg2 = " << vSubArguments[2]->GenSlidingWindowDeclRef();
    2324           0 :         ss << ";\n";
    2325             :     }
    2326           0 :     ss << "    if(isNan(arg0) || isNan(arg1))\n";
    2327           0 :     ss << "        return 0;\n";
    2328           0 :     ss << "    if(isNan(arg2))\n";
    2329           0 :     ss << "        arg2 = 0.0;\n";
    2330           0 :     ss << "    if(arg0*arg1<0)\n";
    2331           0 :     ss << "        return NAN;\n";
    2332           0 :     ss << "    else if(arg2==0.0&&arg0<0.0)\n";
    2333           0 :     ss << "        return (trunc(arg0/arg1)+1)*arg1;\n";
    2334           0 :     ss << "    else\n";
    2335           0 :     ss << "        return trunc(arg0/arg1)*arg1;\n";
    2336           0 :     ss << "}\n";
    2337           0 : }
    2338           0 : void OpBitOr::GenSlidingWindowFunction(std::stringstream &ss,
    2339             :     const std::string &sSymName, SubArguments &vSubArguments)
    2340             : {
    2341           0 :     ss << "\ndouble " << sSymName;
    2342           0 :     ss << "_"<< BinFuncName() <<"(";
    2343           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    2344             :     {
    2345           0 :         if (i) ss << ",";
    2346           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    2347             :     }
    2348           0 :     ss << ") {\n";
    2349           0 :     ss << "    int gid0   = get_global_id(0);\n";
    2350           0 :     ss << "    double num1 = " << GetBottom() << ";\n";
    2351           0 :     ss << "    double num2 = " << GetBottom() << ";\n";
    2352             : #ifdef ISNAN
    2353           0 :     FormulaToken *iNum1 = vSubArguments[0]->GetFormulaToken();
    2354             :     const formula::SingleVectorRefToken* tmpCurDVRNum1=
    2355           0 :         static_cast<const formula::SingleVectorRefToken *>(iNum1);
    2356           0 :     FormulaToken *iNum2 = vSubArguments[1]->GetFormulaToken();
    2357             :     const formula::SingleVectorRefToken* tmpCurDVRNum2=
    2358           0 :         static_cast<const formula::SingleVectorRefToken *>(iNum2);
    2359           0 :     ss << "    int buffer_num1_len = "<<tmpCurDVRNum1->GetArrayLength()<<";\n";
    2360           0 :     ss << "    int buffer_num2_len = "<<tmpCurDVRNum2->GetArrayLength()<<";\n";
    2361           0 :     ss << "    if((gid0)>=buffer_num1_len || isNan(";
    2362           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
    2363           0 :     ss << "        num1 = " << GetBottom() << ";\n";
    2364           0 :     ss << "    else \n    ";
    2365             : #endif
    2366           0 :     ss << "    num1 = floor(" << vSubArguments[0]->GenSlidingWindowDeclRef();
    2367           0 :     ss << ");\n";
    2368             : #ifdef ISNAN
    2369           0 :     ss << "    if((gid0)>=buffer_num2_len || isNan(";
    2370           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef() << "))\n";
    2371           0 :     ss << "        num2 = " << GetBottom() << ";\n";
    2372           0 :     ss << "    else\n    ";
    2373             : #endif
    2374           0 :     ss << "    num2 = floor(" << vSubArguments[1]->GenSlidingWindowDeclRef();
    2375           0 :     ss << ");\n";
    2376           0 :     ss << "    return (long)num1 | (long)num2;\n";
    2377           0 :     ss << "}";
    2378           0 : }
    2379           0 : void OpBitXor::GenSlidingWindowFunction(std::stringstream &ss,
    2380             :     const std::string &sSymName, SubArguments &vSubArguments)
    2381             : {
    2382           0 :     ss << "\ndouble " << sSymName;
    2383           0 :     ss << "_"<< BinFuncName() <<"(";
    2384           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    2385             :     {
    2386           0 :         if (i) ss << ",";
    2387           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    2388             :     }
    2389           0 :     ss << ") {\n";
    2390           0 :     ss << "    int gid0 = get_global_id(0);\n";
    2391           0 :     ss << "    double num1 = " << GetBottom() << ";\n";
    2392           0 :     ss << "    double num2 = " << GetBottom() << ";\n";
    2393             : #ifdef ISNAN
    2394           0 :     FormulaToken *iNum1 = vSubArguments[0]->GetFormulaToken();
    2395             :     const formula::SingleVectorRefToken* tmpCurDVRNum1=
    2396           0 :         static_cast<const formula::SingleVectorRefToken *>(iNum1);
    2397           0 :     FormulaToken *iNum2 = vSubArguments[1]->GetFormulaToken();
    2398             :     const formula::SingleVectorRefToken* tmpCurDVRNum2=
    2399           0 :         static_cast<const formula::SingleVectorRefToken *>(iNum2);
    2400           0 :     ss << "    int buffer_num1_len = " << tmpCurDVRNum1->GetArrayLength() << ";\n";
    2401           0 :     ss << "    int buffer_num2_len = " << tmpCurDVRNum2->GetArrayLength() << ";\n";
    2402             : 
    2403           0 :     ss << "    if((gid0)>=buffer_num1_len || isNan(";
    2404           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
    2405           0 :     ss << "        num1 = " << GetBottom() << ";\n";
    2406           0 :     ss << "    else\n    ";
    2407             : #endif
    2408           0 :     ss << "    num1 = floor(" << vSubArguments[0]->GenSlidingWindowDeclRef();
    2409           0 :     ss << ");\n";
    2410             : #ifdef ISNAN
    2411           0 :     ss << "    if((gid0)>=buffer_num2_len || isNan(";
    2412           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef() << "))\n";
    2413           0 :     ss << "        num2 = " << GetBottom() << ";\n";
    2414           0 :     ss << "    else\n    ";
    2415             : #endif
    2416           0 :     ss << "    num2 = floor(" << vSubArguments[1]->GenSlidingWindowDeclRef();
    2417           0 :     ss << ");\n";
    2418           0 :     ss << "    return (long)num1 ^ (long)num2;\n";
    2419           0 :     ss << "}";
    2420           0 : }
    2421           0 : void OpBitLshift::GenSlidingWindowFunction(std::stringstream &ss,
    2422             :     const std::string &sSymName, SubArguments &vSubArguments)
    2423             : {
    2424           0 :     ss << "\ndouble " << sSymName;
    2425           0 :     ss << "_"<< BinFuncName() <<"(";
    2426           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    2427             :     {
    2428           0 :         if (i) ss << ",";
    2429           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    2430             :     }
    2431           0 :     ss << ") {\n";
    2432           0 :     ss << "    int gid0 = get_global_id(0);\n";
    2433           0 :     ss << "    double num = " << GetBottom() << ";\n";
    2434           0 :     ss << "    double shift_amount = " << GetBottom() << ";\n";
    2435             : #ifdef ISNAN
    2436           0 :     FormulaToken *iNum = vSubArguments[0]->GetFormulaToken();
    2437             :     const formula::SingleVectorRefToken* tmpCurDVRNum=
    2438           0 :         static_cast<const formula::SingleVectorRefToken*>(iNum);
    2439           0 :     FormulaToken *iShiftAmount = vSubArguments[1]->GetFormulaToken();
    2440             :     const formula::SingleVectorRefToken* tmpCurDVRShiftAmount=
    2441           0 :         static_cast<const formula::SingleVectorRefToken*>(iShiftAmount);
    2442           0 :     ss << "    int buffer_num_len = "<< tmpCurDVRNum->GetArrayLength()<<";\n";
    2443           0 :     ss << "    int buffer_shift_amount_len = ";
    2444           0 :     ss << tmpCurDVRShiftAmount->GetArrayLength() << ";\n";
    2445           0 :     ss << "    if((gid0)>=buffer_num_len || isNan(";
    2446           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
    2447           0 :     ss << "        num = " << GetBottom() << ";\n";
    2448           0 :     ss << "    else\n    ";
    2449             : #endif
    2450           0 :     ss << "    num = floor(";
    2451           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ");\n";
    2452             : #ifdef ISNAN
    2453           0 :     ss << "    if((gid0)>=buffer_shift_amount_len || isNan(";
    2454           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef() << "))\n";
    2455           0 :     ss << "        shift_amount = " << GetBottom() << ";\n";
    2456           0 :     ss << "    else\n    ";
    2457             : #endif
    2458           0 :     ss << "    shift_amount = floor(";
    2459           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ");\n";
    2460           0 :     ss << "    return floor(shift_amount >= 0 ? ";
    2461           0 :     ss << "num * pow(2.0, shift_amount) : ";
    2462           0 :     ss << "num / pow(2.0, fabs(shift_amount)));\n";
    2463           0 :     ss << "}";
    2464           0 : }
    2465           0 : void OpBitRshift::GenSlidingWindowFunction(std::stringstream &ss,
    2466             :     const std::string &sSymName, SubArguments &vSubArguments)
    2467             : {
    2468           0 :     ss << "\ndouble " << sSymName;
    2469           0 :     ss << "_"<< BinFuncName() <<"(";
    2470           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    2471             :     {
    2472           0 :         if (i) ss << ",";
    2473           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    2474             :     }
    2475           0 :     ss << ") {\n";
    2476           0 :     ss << "    int gid0 = get_global_id(0);\n";
    2477           0 :     ss << "    double num = " << GetBottom() << ";\n";
    2478           0 :     ss << "    double shift_amount = " << GetBottom() << ";\n";
    2479             : #ifdef ISNAN
    2480           0 :     FormulaToken *iNum = vSubArguments[0]->GetFormulaToken();
    2481             :     const formula::SingleVectorRefToken* tmpCurDVRNum=
    2482           0 :         static_cast<const formula::SingleVectorRefToken*>(iNum);
    2483           0 :     FormulaToken *iShiftAmount = vSubArguments[1]->GetFormulaToken();
    2484             :     const formula::SingleVectorRefToken* tmpCurDVRShiftAmount=
    2485           0 :         static_cast<const formula::SingleVectorRefToken*>(iShiftAmount);
    2486           0 :     ss << "    int buffer_num_len = ";
    2487           0 :     ss << tmpCurDVRNum->GetArrayLength() << ";\n";
    2488           0 :     ss << "    int buffer_shift_amount_len = ";
    2489           0 :     ss << tmpCurDVRShiftAmount->GetArrayLength() << ";\n";
    2490             : 
    2491           0 :     ss << "    if((gid0)>=buffer_num_len || isNan(";
    2492           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
    2493           0 :     ss << "        num = " << GetBottom() << ";\n";
    2494           0 :     ss << "    else\n    ";
    2495             : #endif
    2496           0 :     ss << "    num = floor(";
    2497           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ");\n";
    2498             : #ifdef ISNAN
    2499           0 :     ss << "    if((gid0)>=buffer_shift_amount_len || isNan(";
    2500           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef() << "))\n";
    2501           0 :     ss << "        shift_amount = " <<GetBottom()<< ";\n";
    2502           0 :     ss << "    else\n    ";
    2503             : #endif
    2504           0 :     ss << "    shift_amount = floor(";
    2505           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ");\n";
    2506           0 :     ss << "    return floor(";
    2507           0 :     ss << "shift_amount >= 0 ? num / pow(2.0, shift_amount) : ";
    2508           0 :     ss << "num * pow(2.0, fabs(shift_amount)));\n";
    2509           0 :     ss << "}";
    2510           0 : }
    2511           0 : void OpSumSQ::GenSlidingWindowFunction(std::stringstream &ss,
    2512             :             const std::string &sSymName, SubArguments &vSubArguments)
    2513             : {
    2514           0 :     ss << "\ndouble " << sSymName;
    2515           0 :     ss << "_"<< BinFuncName() <<"(";
    2516           0 :     for (unsigned i = 0; i < vSubArguments.size(); ++i)
    2517             :     {
    2518           0 :         if (i)
    2519           0 :             ss << ",";
    2520           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    2521             :     }
    2522           0 :     ss << ")\n";
    2523           0 :     ss << "{\n";
    2524           0 :     ss << "    int gid0=get_global_id(0);\n";
    2525           0 :     ss << "    double sum = 0.0f, arg;\n";
    2526           0 :     for( unsigned i=0; i < vSubArguments.size(); ++i)
    2527             :     {
    2528           0 :         FormulaToken *tmpCur = vSubArguments[i]->GetFormulaToken();
    2529             :         assert(tmpCur);
    2530           0 :         if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
    2531             :         {
    2532           0 :             if (tmpCur->GetType() == formula::svDoubleVectorRef)
    2533             :             {
    2534             :                 const formula::DoubleVectorRefToken* pDVR =
    2535           0 :                     static_cast<const formula::DoubleVectorRefToken *>(tmpCur);
    2536           0 :                 size_t nCurWindowSize = pDVR->GetRefRowSize();
    2537           0 :                 ss << "    for (int i = ";
    2538           0 :                 if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
    2539             :                 {
    2540             : #ifdef  ISNAN
    2541           0 :                     ss << "gid0; i < " << pDVR->GetArrayLength();
    2542           0 :                     ss << " && i < " << nCurWindowSize  << "; ++i)\n";
    2543           0 :                     ss << "    {\n";
    2544             : #else
    2545             :                     ss << "gid0; i < "<< nCurWindowSize << "; ++i)\n";
    2546             :                     ss << "    {\n";
    2547             : #endif
    2548             :                 }
    2549           0 :                 else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
    2550             :                 {
    2551             : #ifdef  ISNAN
    2552           0 :                     ss << "0; i < " << pDVR->GetArrayLength();
    2553           0 :                     ss << " && i < gid0+"<< nCurWindowSize << "; ++i)\n";
    2554           0 :                     ss << "    {\n";
    2555             : #else
    2556             :                     ss << "0; i < gid0+"<< nCurWindowSize << "; ++i)\n";
    2557             :                     ss << "    {\n";
    2558             : #endif
    2559             :                 }
    2560           0 :                 else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
    2561             :                 {
    2562             : #ifdef  ISNAN
    2563           0 :                     ss << "0; i + gid0 < " << pDVR->GetArrayLength();
    2564           0 :                     ss << " &&  i < "<< nCurWindowSize << "; ++i)\n";
    2565           0 :                     ss << "    {\n";
    2566             : #else
    2567             :                     ss << "0; i < "<< nCurWindowSize << "; ++i)\n";
    2568             :                     ss << "    {\n";
    2569             : #endif
    2570             :                 }
    2571             :                 else
    2572             :                 {
    2573             : #ifdef  ISNAN
    2574           0 :                     ss << "0; i < "<< nCurWindowSize << "; ++i)\n";
    2575           0 :                     ss << "    {\n";
    2576             : #else
    2577             :                     ss << "0; i < "<< nCurWindowSize << "; ++i)\n";
    2578             :                     ss << "    {\n";
    2579             : #endif
    2580             :                 }
    2581           0 :                 ss << "        arg = ";
    2582           0 :                 ss << vSubArguments[i]->GenSlidingWindowDeclRef();
    2583           0 :                 ss << ";\n";
    2584             : #ifdef  ISNAN
    2585           0 :                 ss << "        if (isNan(arg))\n";
    2586           0 :                 ss << "            continue;\n";
    2587             : #endif
    2588           0 :                 ss << "        sum += pown(arg, 2);\n";
    2589           0 :                 ss << "    }\n";
    2590             :             }
    2591           0 :             else if(tmpCur->GetType() == formula::svSingleVectorRef)
    2592             :             {
    2593             :                 const formula::SingleVectorRefToken* tmpCurDVR=
    2594             :                       static_cast<
    2595           0 :                       const formula::SingleVectorRefToken *>(tmpCur);
    2596           0 :                 ss << "    arg = ";
    2597           0 :                 ss << vSubArguments[i]->GenSlidingWindowDeclRef();
    2598           0 :                 ss << ";\n";
    2599             : #ifdef ISNAN
    2600           0 :                 ss << "    if(isNan(arg)||(gid0>=";
    2601           0 :                 ss << tmpCurDVR->GetArrayLength();
    2602           0 :                 ss << "))\n";
    2603           0 :                 ss << "        arg = 0.0f;\n";
    2604           0 :                 ss << "    sum += pown(arg, 2);\n";
    2605             : #endif
    2606             :             }
    2607           0 :             else if(tmpCur->GetType() == formula::svDouble)
    2608             :             {
    2609           0 :                 ss << "        arg = ";
    2610           0 :                 ss << tmpCur->GetDouble() << ";\n";
    2611           0 :                 ss << "        sum += pown(arg, 2);\n";
    2612             :             }
    2613             :         }
    2614             :         else
    2615             :         {
    2616           0 :             ss << "        arg = ";
    2617           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
    2618           0 :             ss << ";\n";
    2619           0 :             ss << "        sum += pown(arg, 2);\n";
    2620             :         }
    2621             :     }
    2622           0 :     ss << "    return sum;\n";
    2623           0 :     ss << "}";
    2624           0 : }
    2625           0 : void OpSqrtPi::GenSlidingWindowFunction(std::stringstream &ss,
    2626             :             const std::string &sSymName, SubArguments &vSubArguments)
    2627             : {
    2628           0 :     ss << "\ndouble " << sSymName;
    2629           0 :     ss << "_"<< BinFuncName() <<"(";
    2630           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    2631             :     {
    2632           0 :         if (i)
    2633           0 :             ss << ",";
    2634           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    2635             :     }
    2636           0 :     ss << ")\n";
    2637           0 :     ss << "{\n";
    2638           0 :     ss << "    int gid0=get_global_id(0);\n";
    2639           0 :     ss << "    double arg0 = 0.0f;\n";
    2640           0 :     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
    2641             :     assert(tmpCur);
    2642           0 :     if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
    2643             :     {
    2644           0 :         if(tmpCur->GetType() == formula::svSingleVectorRef)
    2645             :         {
    2646             :             const formula::SingleVectorRefToken*tmpCurDVR=
    2647             :                 static_cast
    2648           0 :                 <const formula::SingleVectorRefToken *>(tmpCur);
    2649           0 :             ss << "    arg0 = ";
    2650           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    2651           0 :             ss << ";\n";
    2652             : #ifdef ISNAN
    2653           0 :             ss << "    if(isNan(";
    2654           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    2655           0 :             ss << ")||(gid0>=";
    2656           0 :             ss << tmpCurDVR->GetArrayLength();
    2657           0 :             ss << "))\n";
    2658           0 :             ss << "    { arg0 = 0.0f; }\n";
    2659             : #endif
    2660             :         }
    2661           0 :         else if(tmpCur->GetType() == formula::svDouble)
    2662             :         {
    2663           0 :             ss << "    arg0=";
    2664           0 :             ss << tmpCur->GetDouble() << ";\n";
    2665             :         }
    2666             :     }
    2667             :     else
    2668             :     {
    2669           0 :         ss << "        arg0 = ";
    2670           0 :         ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    2671           0 :         ss << ";\n";
    2672             :     }
    2673           0 :     ss << "    return (double)sqrt(arg0 *";
    2674           0 :     ss << " 3.1415926535897932384626433832795f);\n";
    2675           0 :     ss << "}";
    2676           0 : }
    2677           0 : void OpCeil::GenSlidingWindowFunction(std::stringstream &ss,
    2678             :     const std::string &sSymName, SubArguments &vSubArguments)
    2679             : {
    2680           0 :     ss << "\ndouble " << sSymName;
    2681           0 :     ss << "_"<< BinFuncName() <<"(";
    2682           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    2683             :     {
    2684           0 :         if (i) ss << ",";
    2685           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    2686             :     }
    2687           0 :     ss << ") {\n";
    2688           0 :     ss << "    int gid0   = get_global_id(0);\n";
    2689           0 :     ss << "    double num = " << GetBottom() << ";\n";
    2690           0 :     ss << "    double significance = " << GetBottom() << ";\n";
    2691           0 :     ss << "    double bAbs = 0;\n";
    2692             : #ifdef ISNAN
    2693           0 :     ss << "    if(isNan(";
    2694           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
    2695           0 :     ss << "        num = " << GetBottom() << ";\n";
    2696           0 :     ss << "    else\n    ";
    2697             : #endif
    2698           0 :     ss << "    num = " << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
    2699             : #ifdef ISNAN
    2700           0 :     ss << "    if(isNan(";
    2701           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef() << "))\n";
    2702           0 :     ss << "        return 0.0;\n";
    2703           0 :     ss << "    else\n    ";
    2704             : #endif
    2705           0 :     ss << "    significance = ";
    2706           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
    2707           0 :     if (vSubArguments.size() > 2)
    2708             :     {
    2709             : #ifdef ISNAN
    2710           0 :         FormulaToken *bAbs = vSubArguments[2]->GetFormulaToken();
    2711           0 :         if(bAbs->GetType() == formula::svSingleVectorRef)
    2712             :         {
    2713             :             const formula::SingleVectorRefToken* tmpCurSVRIsAbs=
    2714           0 :                 static_cast<const formula::SingleVectorRefToken*>(bAbs);
    2715           0 :             ss<< "    if((gid0)>=" << tmpCurSVRIsAbs->GetArrayLength() << " ||";
    2716             :         }
    2717           0 :         if(bAbs->GetType() == formula::svDoubleVectorRef)
    2718             :         {
    2719             :             const formula::DoubleVectorRefToken* tmpCurDVRIsAbs=
    2720           0 :                 static_cast<const formula::DoubleVectorRefToken*>(bAbs);
    2721           0 :             ss<< "    if((gid0)>=" << tmpCurDVRIsAbs->GetArrayLength() << " ||";
    2722             :         }
    2723           0 :         if(bAbs->GetType() == formula::svDouble)
    2724             :         {
    2725           0 :             ss<< "    if(";
    2726             :         }
    2727           0 :         ss << "isNan(";
    2728           0 :         ss << vSubArguments[2]->GenSlidingWindowDeclRef() << "))\n";
    2729           0 :         ss << "        bAbs = 0;\n";
    2730           0 :         ss << "    else\n    ";
    2731             : #endif
    2732           0 :         ss << "    bAbs = "<<vSubArguments[2]->GenSlidingWindowDeclRef()<<";\n";
    2733             :     }
    2734           0 :     ss << "    if(significance == 0.0)\n";
    2735           0 :     ss << "        return 0.0;\n";
    2736           0 :     ss << "    return ";
    2737           0 :     ss << "( !(int)bAbs && num < 0.0 ? floor( num / significance ) : ";
    2738           0 :     ss << "ceil( num / significance ) )";
    2739           0 :     ss << "*significance;\n";
    2740           0 :     ss << "}";
    2741           0 : }
    2742           0 : void OpKombin::GenSlidingWindowFunction(std::stringstream &ss,
    2743             :     const std::string &sSymName, SubArguments &vSubArguments)
    2744             : {
    2745           0 :     ss << "\ndouble " << sSymName;
    2746           0 :     ss << "_"<< BinFuncName() <<"(";
    2747           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    2748             :     {
    2749           0 :         if (i) ss << ",";
    2750           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    2751             :     }
    2752           0 :     ss << ") {\n";
    2753           0 :     ss << "    int gid0 = get_global_id(0);\n";
    2754           0 :     ss << "    double num = " << GetBottom() << ";\n";
    2755           0 :     ss << "    double num_chosen = " << GetBottom() << ";\n";
    2756           0 :     ss << "    double result = -1.0;\n";
    2757           0 :     FormulaToken *iNum = vSubArguments[0]->GetFormulaToken();
    2758           0 :     FormulaToken *iNumChosen = vSubArguments[1]->GetFormulaToken();
    2759             : 
    2760             :     assert(iNum);
    2761           0 :     if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
    2762             :     {
    2763           0 :         if(iNum->GetType() == formula::svSingleVectorRef &&
    2764           0 :             iNumChosen->GetType() == formula::svSingleVectorRef)
    2765             :         {
    2766             : #ifdef ISNAN
    2767           0 :             ss << "    if(isNan(";
    2768           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
    2769           0 :             ss << "        num = " << GetBottom() << ";\n";
    2770           0 :             ss << "    else\n    ";
    2771             : #endif
    2772           0 :             ss << "    num = floor(";
    2773           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ");\n";
    2774             : #ifdef ISNAN
    2775           0 :             ss << "    if(isNan(";
    2776           0 :             ss << vSubArguments[1]->GenSlidingWindowDeclRef() << "))\n";
    2777           0 :             ss << "        num_chosen = " << GetBottom() << ";\n";
    2778           0 :             ss << "    else\n    ";
    2779             : #endif
    2780           0 :             ss << "    num_chosen = floor(";
    2781           0 :             ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ");\n";
    2782             :         }
    2783           0 :         else if(iNum->GetType() == formula::svDouble &&
    2784           0 :             iNumChosen->GetType() == formula::svDouble)
    2785             :         {
    2786           0 :             ss << "    num = floor(" << iNum->GetDouble() << ");\n";
    2787           0 :             ss << "    num_chosen = floor("<< iNumChosen->GetDouble()<< ");\n";
    2788             :         }
    2789             :     }
    2790             :     else
    2791             :     {
    2792           0 :         ss << "    num = floor(";
    2793           0 :         ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ");\n";
    2794           0 :         ss << "    num_chosen = floor(";
    2795           0 :         ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ");\n";
    2796             :     }
    2797           0 :     ss << "    result = select(result, 0.0, (ulong)(num < num_chosen));\n";
    2798           0 :     ss << "    result = select(result, 1.0, (ulong)(num_chosen == 0.0));\n";
    2799           0 :     ss << "    if(result == 0 || result ==1)\n";
    2800           0 :     ss << "        return result;\n";
    2801           0 :     ss << "    double4 db4num;\n";
    2802           0 :     ss << "    double4 db4num_chosen;\n";
    2803           0 :     ss << "    double4 db4result;\n";
    2804           0 :     ss << "    double2 db2result;\n";
    2805           0 :     ss << "    result = 1.0;\n";
    2806           0 :     ss << "    int loop = num_chosen/4;\n";
    2807           0 :     ss << "    for(int i=0; i<loop; i++)\n";
    2808           0 :     ss << "    {\n";
    2809           0 :     ss << "        db4num = (double4){num,\n";
    2810           0 :     ss << "            num-1.0,\n";
    2811           0 :     ss << "            num-2.0,\n";
    2812           0 :     ss << "            num-3.0};\n";
    2813           0 :     ss << "        db4num_chosen = (double4){num_chosen,\n";
    2814           0 :     ss << "            num_chosen-1.0,\n";
    2815           0 :     ss << "            num_chosen-2.0,\n";
    2816           0 :     ss << "            num_chosen-3.0};\n";
    2817           0 :     ss << "        db4result = db4num * pown(db4num_chosen, -1);\n";
    2818           0 :     ss << "        db2result = db4result.xy * db4result.zw;\n";
    2819           0 :     ss << "        result *=  db2result.x * db2result.y;\n";
    2820           0 :     ss << "        num = num - 4.0;\n";
    2821           0 :     ss << "        num_chosen = num_chosen - 4.0;\n";
    2822           0 :     ss << "    }\n";
    2823           0 :     ss << "    while ( num_chosen > 0){\n";
    2824           0 :     ss << "        result *= num / num_chosen;\n";
    2825           0 :     ss << "        num = num - 1.0;\n";
    2826           0 :     ss << "        num_chosen = num_chosen - 1.0;\n";
    2827           0 :     ss << "    }\n";
    2828           0 :     ss << "    return result;\n";
    2829           0 :     ss << "}\n";
    2830           0 : }
    2831           0 : void OpConvert::GenSlidingWindowFunction(
    2832             :     std::stringstream &ss, const std::string &sSymName,
    2833             :     SubArguments &vSubArguments)
    2834             : {
    2835           0 :     int arg1=vSubArguments[1]->GetFormulaToken()->GetString().\
    2836           0 :         getString().toAsciiUpperCase().hashCode();
    2837           0 :     int arg2=vSubArguments[2]->GetFormulaToken()->GetString().\
    2838           0 :         getString().toAsciiUpperCase().hashCode();
    2839           0 :     if( !((arg1==5584&&arg2==108)||
    2840           0 :         (arg1==108&&arg2==5584)||
    2841           0 :         (arg1==5665&&arg2==268206)||
    2842           0 :         (arg1==268206&&arg2==5665)) )
    2843           0 :         throw Unhandled();
    2844             : 
    2845           0 :     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
    2846             :     const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const
    2847           0 :         formula::SingleVectorRefToken *>(tmpCur);
    2848           0 :     ss << "\ndouble " << sSymName;
    2849           0 :     ss << "_"<< BinFuncName() <<"(";
    2850           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    2851             :     {
    2852           0 :         if (i)
    2853           0 :             ss << ",";
    2854           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    2855             :     }
    2856           0 :     ss << ")\n{\n";
    2857           0 :     ss <<"    int gid0=get_global_id(0);\n";
    2858           0 :     ss << "    double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
    2859           0 :     ss << ";\n";
    2860           0 :     ss << "    double arg1 = " << vSubArguments[1]->GenSlidingWindowDeclRef();
    2861           0 :     ss << ";\n";
    2862           0 :     ss << "    double arg2 = " << vSubArguments[2]->GenSlidingWindowDeclRef();
    2863           0 :     ss << ";\n";
    2864             : #ifdef ISNAN
    2865           0 :     ss<< "    if(isNan(arg0)||(gid0>=";
    2866           0 :     ss<<tmpCurDVR->GetArrayLength();
    2867           0 :     ss<<"))\n";
    2868           0 :     ss<<"        arg0 = 0;\n";
    2869           0 :     ss<< "    if(isNan(arg1)||(gid0>=";
    2870           0 :     ss<<tmpCurDVR->GetArrayLength();
    2871           0 :     ss<<"))\n";
    2872           0 :     ss<<"        arg1 = 0;\n";
    2873           0 :     ss<< "    if(isNan(arg2)||(gid0>=";
    2874           0 :     ss<<tmpCurDVR->GetArrayLength();
    2875           0 :     ss<<"))\n";
    2876           0 :     ss<<"        arg2 = 0;\n";
    2877             : #endif
    2878           0 :     ss<<"    if(arg1==5584U&&arg2==108U)\n";
    2879           0 :     ss<<"        return arg0*1000.0;\n";
    2880           0 :     ss<<"    else if(arg1==108U&&arg2==3385U)\n";
    2881           0 :     ss<<"        return arg0/1000.0;\n";
    2882           0 :     ss<<"    else if(arg1==5665U&&arg2==268206U)\n";
    2883           0 :     ss<<"        return arg0*60.0;\n";
    2884           0 :     ss<<"    else if(arg1==268206U&&arg2==5665U)\n";
    2885           0 :     ss<<"        return arg0/60.0;\n";
    2886           0 :     ss<<"    else\n";
    2887           0 :     ss<<"        return -9999999999;\n";
    2888           0 :     ss << "}\n";
    2889             : 
    2890           0 : }
    2891             : 
    2892           0 : void OpProduct::GenSlidingWindowFunction(std::stringstream &ss,
    2893             :             const std::string &sSymName, SubArguments &vSubArguments)
    2894             : {
    2895           0 :        ss << "\ndouble " << sSymName;
    2896           0 :     ss << "_"<< BinFuncName() <<"( ";
    2897           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    2898             :     {
    2899           0 :         if (i)
    2900           0 :             ss << ",";
    2901           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    2902             :     }
    2903           0 :     ss << ") {\n";
    2904           0 :     ss << "    int gid0 = get_global_id(0);\n";
    2905           0 :     ss << "    int i = 0;\n";
    2906           0 :     ss << "    double product=1.0;\n\n";
    2907           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    2908             :     {
    2909           0 :         FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
    2910             :         assert(pCur);
    2911           0 :         if (pCur->GetType() == formula::svDoubleVectorRef)
    2912             :         {
    2913             :             const formula::DoubleVectorRefToken* pDVR =
    2914           0 :             static_cast<const formula::DoubleVectorRefToken *>(pCur);
    2915           0 :             size_t nCurWindowSize = pDVR->GetRefRowSize();
    2916             : 
    2917           0 :              ss << "    for (int i = ";
    2918           0 :              if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
    2919             :              {
    2920           0 :                  ss << "gid0; i < " << pDVR->GetArrayLength();
    2921           0 :                  ss << " && i < " << nCurWindowSize  << "; i++)\n";
    2922           0 :                  ss << "    {\n";
    2923             :              }
    2924           0 :              else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
    2925             :              {
    2926           0 :                  ss << "0; i < " << pDVR->GetArrayLength();
    2927           0 :                  ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
    2928           0 :                  ss << "    {\n";
    2929             :              }
    2930           0 :              else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
    2931             :              {
    2932           0 :                  ss << "0; i + gid0 < " <<  pDVR->GetArrayLength();
    2933           0 :                  ss << " &&  i < " << nCurWindowSize << "; i++)\n";
    2934           0 :                  ss << "    {\n";
    2935             :               }
    2936           0 :               else if (pDVR->IsStartFixed() && pDVR->IsEndFixed())
    2937             :               {
    2938             : 
    2939           0 :                  ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
    2940           0 :                  ss << "    {\n";
    2941             :               }
    2942           0 :               ss << "if(!isNan("<<vSubArguments[i]->GenSlidingWindowDeclRef()<<"))\n";
    2943           0 :               ss << "product = product*";
    2944           0 :               ss << vSubArguments[i]->GenSlidingWindowDeclRef()<<";\n";
    2945           0 :               ss << "    }\n";
    2946             :             }
    2947           0 :             else if (pCur->GetType() == formula::svSingleVectorRef)
    2948             :             {
    2949           0 :                 ss << "if(!isNan("<<vSubArguments[i]->GenSlidingWindowDeclRef()<<"))\n";
    2950           0 :                 ss << "product = product*";
    2951           0 :                 ss << vSubArguments[i]->GenSlidingWindowDeclRef()<<";\n";
    2952             : 
    2953             :             }
    2954             :             else
    2955             :             {
    2956           0 :                 ss << "if(!isNan("<<vSubArguments[i]->GenSlidingWindowDeclRef()<<"))\n";
    2957           0 :                 ss << "product = product*";
    2958           0 :                 ss << vSubArguments[i]->GenSlidingWindowDeclRef()<<";\n";
    2959             :             }
    2960             :         }
    2961           0 :         ss << "    return product;\n";
    2962           0 :         ss << "}";
    2963           0 : }
    2964           0 : void OpAverageIf::GenSlidingWindowFunction(std::stringstream &ss,
    2965             :     const std::string &sSymName, SubArguments &vSubArguments)
    2966             : {
    2967             : 
    2968           0 :     ss << "\ndouble " << sSymName;
    2969           0 :     ss << "_"<< BinFuncName() <<"(";
    2970           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    2971             :     {
    2972           0 :         if (i) ss << ",";
    2973           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    2974             :     }
    2975           0 :     ss << ")\n{\n";
    2976           0 :     ss << "    int gid0=get_global_id(0);\n";
    2977           0 :     ss << "    double tmp =0;\n";
    2978           0 :     ss << "    double count=0;\n";
    2979           0 :     ss << "    int singleIndex =gid0;\n";
    2980           0 :     ss << "    int doubleIndex;\n";
    2981           0 :     ss << "    int i ;\n";
    2982           0 :     ss << "    int j ;\n";
    2983           0 :     GenTmpVariables(ss,vSubArguments);
    2984             : 
    2985           0 :     unsigned paraOneIsDoubleVector = 0;
    2986           0 :     unsigned paraOneWidth = 1;
    2987           0 :     unsigned paraTwoWidth = 1;
    2988           0 :     unsigned loopTimes = 0;
    2989             : 
    2990           0 :     if(vSubArguments[0]->GetFormulaToken()->GetType() == formula::svDoubleVectorRef)
    2991             :     {
    2992           0 :         paraOneIsDoubleVector = 1;
    2993           0 :         FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
    2994             :         const formula::DoubleVectorRefToken*pCurDVR0= static_cast<const
    2995           0 :             formula::DoubleVectorRefToken *>(tmpCur0);
    2996           0 :         paraOneWidth = pCurDVR0->GetArrays().size();
    2997           0 :         loopTimes = paraOneWidth;
    2998           0 :         if(paraOneWidth > 1)
    2999             :         {
    3000           0 :             throw Unhandled();
    3001             :         }
    3002             :     }
    3003             : 
    3004           0 :     if(vSubArguments[paraOneWidth]->GetFormulaToken()->GetType() ==
    3005             :      formula::svDoubleVectorRef)
    3006             : 
    3007             :     {
    3008           0 :         FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
    3009             :         const formula::DoubleVectorRefToken*pCurDVR1= static_cast<const
    3010           0 :             formula::DoubleVectorRefToken *>(tmpCur1);
    3011           0 :         paraTwoWidth = pCurDVR1->GetArrays().size();
    3012           0 :         if(paraTwoWidth > 1)
    3013             :         {
    3014           0 :             throw Unhandled();
    3015             :         }
    3016           0 :         ss << "    i = ";
    3017           0 :         if (!pCurDVR1->IsStartFixed() && pCurDVR1->IsEndFixed()) {
    3018           0 :             ss << "gid0;\n";
    3019             :         } else {
    3020           0 :             ss << "0;\n";
    3021             :         }
    3022           0 :         if(!pCurDVR1->IsStartFixed() && !pCurDVR1->IsEndFixed())
    3023             :         {
    3024           0 :             ss << "        doubleIndex =i+gid0;\n";
    3025             :         }else
    3026             :         {
    3027           0 :             ss << "        doubleIndex =i;\n";
    3028             :         }
    3029             :     }
    3030             : 
    3031           0 :     CheckSubArgumentIsNan(ss,vSubArguments,paraOneWidth);
    3032             : 
    3033           0 :     unsigned paraThreeIndex = paraOneWidth + paraTwoWidth;
    3034           0 :     if(vSubArguments.size() > paraThreeIndex)
    3035             :     {
    3036           0 :         if(vSubArguments[paraThreeIndex]->GetFormulaToken()->GetType() ==
    3037             :         formula::svDoubleVectorRef)
    3038             :         {
    3039             :             FormulaToken *tmpCur2 =
    3040           0 :             vSubArguments[paraThreeIndex]->GetFormulaToken();
    3041             :             const formula::DoubleVectorRefToken*pCurDVR2= static_cast<const
    3042           0 :                 formula::DoubleVectorRefToken *>(tmpCur2);
    3043           0 :             unsigned paraThreeWidth = pCurDVR2->GetArrays().size();
    3044           0 :              if(paraThreeWidth > 1)
    3045             :             {
    3046           0 :                 throw Unhandled();
    3047             :             }
    3048             :         }
    3049             :     }
    3050             : 
    3051           0 :     if(paraOneIsDoubleVector)
    3052             :     {
    3053           0 :         unsigned loopIndex = 0;
    3054           0 :         FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
    3055             :         const formula::DoubleVectorRefToken*pCurDVR0= static_cast<const
    3056           0 :             formula::DoubleVectorRefToken *>(tmpCur0);
    3057           0 :         size_t nCurWindowSize = pCurDVR0->GetArrayLength() <
    3058           0 :             pCurDVR0->GetRefRowSize() ? pCurDVR0->GetArrayLength():
    3059           0 :             pCurDVR0->GetRefRowSize() ;
    3060             : 
    3061           0 :         for(loopIndex =0; loopIndex < loopTimes; loopIndex++)
    3062             :         {
    3063           0 :             ss << "    for (i = ";
    3064           0 :             if (!pCurDVR0->IsStartFixed() && pCurDVR0->IsEndFixed()) {
    3065           0 :                 ss << "gid0; i < "<< nCurWindowSize <<"; i++)\n";
    3066           0 :             } else if (pCurDVR0->IsStartFixed() && !pCurDVR0->IsEndFixed()) {
    3067           0 :                 ss << "0; i < gid0+"<< nCurWindowSize <<"; i++)\n";
    3068             :             } else {
    3069           0 :                 ss << "0; i < "<< nCurWindowSize <<"; i++)\n";
    3070             :             }
    3071           0 :             ss << "    {\n";
    3072           0 :             if(!pCurDVR0->IsStartFixed() && !pCurDVR0->IsEndFixed())
    3073             :             {
    3074           0 :                 ss << "        doubleIndex =i+gid0;\n";
    3075             :             }else
    3076             :             {
    3077           0 :                 ss << "        doubleIndex =i;\n";
    3078             :             }
    3079             : 
    3080           0 :             CheckSubArgumentIsNan(ss,vSubArguments, loopIndex);
    3081             : 
    3082           0 :             ss << "        if ( isequal( tmp";
    3083           0 :             ss << loopIndex<<" , tmp"<<paraOneWidth<<") ) \n";
    3084           0 :             ss << "        {\n";
    3085           0 :             if(vSubArguments.size() == paraThreeIndex)
    3086           0 :                 ss << "            tmp += tmp"<<loopIndex<<";\n";
    3087             :             else
    3088             :             {
    3089             :                 CheckSubArgumentIsNan(ss,vSubArguments,
    3090           0 :                 paraThreeIndex+loopIndex);
    3091           0 :                 ss << "            tmp += tmp";
    3092           0 :                 ss << paraThreeIndex+loopIndex<<";\n";
    3093             :             }
    3094           0 :             ss << "            count+=1.0;\n";
    3095           0 :             ss << "        }\n";
    3096           0 :             ss << "    }\n";
    3097             :         }
    3098             :     }
    3099             :       else
    3100             :     {
    3101           0 :         CheckSubArgumentIsNan(ss,vSubArguments, 0);
    3102           0 :         ss << "        if ( isequal( tmp0 , tmp1 ) ) \n";
    3103           0 :         ss << "        {\n";
    3104           0 :         if(vSubArguments.size() == 2)
    3105           0 :             ss << "            tmp += tmp0;\n";
    3106             :         else
    3107             :         {
    3108           0 :             CheckSubArgumentIsNan(ss,vSubArguments,2);
    3109           0 :             ss << "            tmp += tmp2;\n";
    3110             :         }
    3111           0 :         ss << "            count+=1.0;\n";
    3112           0 :         ss << "        }\n";
    3113             :     }
    3114             : 
    3115           0 :     ss << "    if(count!=0)\n";
    3116           0 :     ss << "        tmp=tmp/count;\n";
    3117           0 :     ss << "    else\n";
    3118           0 :     ss << "        tmp= 0 ;\n";
    3119           0 :     ss << "    return tmp;\n";
    3120           0 :     ss << "}";
    3121           0 : }
    3122           0 : void OpDeg::GenSlidingWindowFunction(std::stringstream &ss,
    3123             :             const std::string &sSymName, SubArguments &vSubArguments)
    3124             : {
    3125           0 :     ss << "\ndouble " << sSymName;
    3126           0 :     ss << "_"<< BinFuncName() <<"(";
    3127           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    3128             :     {
    3129           0 :         if (i)
    3130           0 :             ss << ",";
    3131           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    3132             :     }
    3133           0 :     ss << ")\n";
    3134           0 :     ss << "{\n";
    3135           0 :     ss << "    int gid0=get_global_id(0);\n";
    3136           0 :     ss << "    double arg0 = 0.0f;\n";
    3137           0 :     FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
    3138             :     assert(tmpCur);
    3139           0 :     if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
    3140             :     {
    3141           0 :         if(tmpCur->GetType() == formula::svSingleVectorRef)
    3142             :         {
    3143             :             const formula::SingleVectorRefToken*tmpCurDVR=
    3144             :                 static_cast
    3145           0 :                 <const formula::SingleVectorRefToken *>(tmpCur);
    3146           0 :             ss << "    arg0 = ";
    3147           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    3148           0 :             ss << ";\n";
    3149             : #ifdef ISNAN
    3150           0 :             ss << "    if(isNan(";
    3151           0 :             ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    3152           0 :             ss << ")||(gid0>=";
    3153           0 :             ss << tmpCurDVR->GetArrayLength();
    3154           0 :             ss << "))\n";
    3155           0 :             ss << "    { arg0 = 0.0f; }\n";
    3156             : #endif
    3157             :         }
    3158           0 :         else if(tmpCur->GetType() == formula::svDouble)
    3159             :         {
    3160           0 :             ss << "    arg0=";
    3161           0 :             ss << tmpCur->GetDouble() << ";\n";
    3162             :         }
    3163             :     }
    3164             :     else
    3165             :     {
    3166           0 :         ss << "        arg0 = ";
    3167           0 :         ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    3168           0 :         ss << ";\n";
    3169             :     }
    3170           0 :     ss << "    return arg0 * pown(M_PI, -1) * 180;;\n";
    3171           0 :     ss << "}";
    3172           0 : }
    3173             : 
    3174           0 : void OpFact::GenSlidingWindowFunction(std::stringstream& ss,
    3175             :     const std::string &sSymName, SubArguments& vSubArguments)
    3176             : {
    3177           0 :     ss << "\ndouble " << sSymName;
    3178           0 :     ss << "_" << BinFuncName() << "(";
    3179           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    3180             :     {
    3181           0 :         if (i)
    3182           0 :             ss << ",";
    3183           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    3184             :     }
    3185           0 :     ss << ") {\n";
    3186           0 :     ss << "    double tmp = " << GetBottom() << ";\n";
    3187           0 :     ss << "    int gid0 = get_global_id(0);\n";
    3188           0 :     ss << "    double arg0 = " << GetBottom() << ";\n";
    3189           0 :     FormulaToken* pCur = vSubArguments[0]->GetFormulaToken();
    3190             :     assert(pCur);
    3191           0 :     if (pCur->GetType() == formula::svSingleVectorRef)
    3192             :     {
    3193             : #ifdef  ISNAN
    3194             :         const formula::SingleVectorRefToken* pSVR =
    3195           0 :             static_cast< const formula::SingleVectorRefToken* >(pCur);
    3196           0 :         ss << "    if (gid0 < " << pSVR->GetArrayLength() << "){\n";
    3197             : #endif
    3198             :     }
    3199           0 :     else if (pCur->GetType() == formula::svDouble)
    3200             :     {
    3201             : #ifdef  ISNAN
    3202           0 :         ss << "    {\n";
    3203             : #endif
    3204             :     }
    3205             : #ifdef  ISNAN
    3206           0 :     if(ocPush==vSubArguments[0]->GetFormulaToken()->GetOpCode())
    3207             :     {
    3208           0 :         ss << "        if (isNan(";
    3209           0 :         ss << vSubArguments[0]->GenSlidingWindowDeclRef();
    3210           0 :         ss << "))\n";
    3211           0 :         ss << "            arg0 = 0;\n";
    3212           0 :         ss << "        else\n";
    3213           0 :         ss << "            arg0 = ";
    3214           0 :         ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
    3215           0 :         ss << "    arg0 = floor(arg0);\n";
    3216           0 :         ss << "    if (arg0 < 0.0)\n";
    3217           0 :         ss << "        return 0.0;\n";
    3218           0 :         ss << "    else if (arg0 == 0.0)\n";
    3219           0 :         ss << "        return 1.0;\n";
    3220           0 :         ss << "    else if (arg0 <= 170.0)\n";
    3221           0 :         ss << "    {\n";
    3222           0 :         ss << "        double fTemp = arg0;\n";
    3223           0 :         ss << "        while (fTemp > 2.0)\n";
    3224           0 :         ss << "        {\n";
    3225           0 :         ss << "            fTemp = fTemp - 1;\n";
    3226           0 :         ss << "            arg0 = arg0 * fTemp;\n";
    3227           0 :         ss << "        }\n";
    3228           0 :         ss << "    }\n";
    3229           0 :         ss << "    else\n";
    3230           0 :         ss << "        return -DBL_MAX;\n";
    3231           0 :         ss << "    }\n";
    3232             :     }
    3233             :     else
    3234             :     {
    3235           0 :         ss << "    arg0 = ";
    3236           0 :         ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
    3237             :     }
    3238             : #else
    3239             :     ss << "    arg0 = ";
    3240             :     ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
    3241             : #endif
    3242           0 :     ss << "    return arg0;\n";
    3243           0 :     ss << "}";
    3244           0 : }
    3245           0 : void OpQuotient::GenSlidingWindowFunction(std::stringstream &ss,
    3246             :     const std::string &sSymName, SubArguments &vSubArguments)
    3247             : {
    3248           0 :     ss << "\ndouble " << sSymName;
    3249           0 :     ss << "_"<< BinFuncName() <<"(";
    3250           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    3251             :     {
    3252           0 :         if (i) ss << ",";
    3253           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    3254             :     }
    3255           0 :     ss << ") {\n";
    3256           0 :     ss << "    int gid0 = get_global_id(0);\n";
    3257           0 :     ss << "    double num1 = 1.0;\n";
    3258           0 :     ss << "    double num2 = 1.0;\n";
    3259             : #ifdef ISNAN
    3260           0 :     ss << "    if(isNan(";
    3261           0 :     ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
    3262           0 :     ss << "        num1 = 1.0;\n";
    3263           0 :     ss << "    else \n    ";
    3264             : #endif
    3265           0 :     ss << "    num1 = " << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
    3266             : #ifdef ISNAN
    3267           0 :     ss << "    if(isNan(";
    3268           0 :     ss << vSubArguments[1]->GenSlidingWindowDeclRef() << "))\n";
    3269           0 :     ss << "        num2 = 1.0;\n";
    3270           0 :     ss << "    else \n    ";
    3271             : #endif
    3272           0 :     ss << "    num2 = " << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
    3273           0 :     ss << "    return trunc(num1/num2);\n";
    3274           0 :     ss << "}";
    3275           0 : }
    3276           0 : void OpSeriesSum::GenSlidingWindowFunction(std::stringstream &ss,
    3277             :     const std::string &sSymName, SubArguments &vSubArguments)
    3278             : {
    3279           0 :     if( vSubArguments.size() != 4){return;}
    3280           0 :     ss << "\ndouble " << sSymName;
    3281           0 :     ss << "_"<< BinFuncName() <<"(";
    3282           0 :     for (unsigned i = 0; i < vSubArguments.size(); i++)
    3283             :     {
    3284           0 :         if (i)
    3285           0 :             ss << ",";
    3286           0 :         vSubArguments[i]->GenSlidingWindowDecl(ss);
    3287             :     }
    3288           0 :     ss << ")\n";
    3289           0 :     ss << "{\n";
    3290           0 :     ss << "    int gid0=get_global_id(0);\n";
    3291           0 :     ss << "    double var[3], coeff, res = 0.0f;\n";
    3292             :     FormulaToken *tmpCur;
    3293           0 :     for(int i = 0; i < 3; ++i)
    3294             :     {
    3295           0 :         tmpCur = vSubArguments[i]->GetFormulaToken();
    3296             :         assert(tmpCur);
    3297           0 :         if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
    3298             :         {
    3299           0 :             if(tmpCur->GetType() == formula::svSingleVectorRef)
    3300             :             {
    3301             :                 const formula::SingleVectorRefToken* tmpCurDVR=
    3302             :                     static_cast<
    3303           0 :                     const formula::SingleVectorRefToken *>(tmpCur);
    3304           0 :                 ss << "    var["<<i<<"] = ";
    3305           0 :                 ss << vSubArguments[i]->GenSlidingWindowDeclRef();
    3306           0 :                 ss << ";\n";
    3307             : #ifdef ISNAN
    3308           0 :                 ss << "    if(isNan(var["<<i<<"])||(gid0>=";
    3309           0 :                 ss << tmpCurDVR->GetArrayLength();
    3310           0 :                 ss << "))\n";
    3311           0 :                 ss << "        var["<<i<<"] = 0;\n";
    3312             : #endif
    3313             :             }
    3314           0 :             else if(tmpCur->GetType() == formula::svDouble)
    3315             :             {
    3316           0 :                 ss << "    var["<<i<<"] = ";
    3317           0 :                 ss << tmpCur->GetDouble() << ";\n";
    3318             :             }
    3319             :         }
    3320             :         else
    3321             :         {
    3322           0 :             ss << "    var["<<i<<"] = ";
    3323           0 :             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
    3324           0 :             ss << ";\n";
    3325             :         }
    3326             :     }
    3327           0 :     tmpCur = vSubArguments[3]->GetFormulaToken();
    3328             :     assert(tmpCur);
    3329           0 :     if(ocPush == vSubArguments[3]->GetFormulaToken()->GetOpCode())
    3330             :     {
    3331             :         //TODO       DoubleVector
    3332           0 :         if (tmpCur->GetType() == formula::svDoubleVectorRef)
    3333             :         {
    3334             :             const formula::DoubleVectorRefToken* pDVR =
    3335           0 :                 static_cast<const formula::DoubleVectorRefToken *>(tmpCur);
    3336           0 :             size_t nCurWindowSize = pDVR->GetRefRowSize();
    3337           0 :             ss << "    int j = 0;\n";
    3338           0 :             ss << "    for (int i = ";
    3339           0 :             if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
    3340             :             {
    3341             : #ifdef  ISNAN
    3342           0 :                 ss << "gid0; i < " << pDVR->GetArrayLength();
    3343           0 :                 ss << " && i < " << nCurWindowSize  << "; ++i)\n";
    3344           0 :                 ss << "    {\n";
    3345             : #else
    3346             :                 ss << "gid0; i < "<< nCurWindowSize << "; ++i)\n";
    3347             :                 ss << "    {\n";
    3348             : #endif
    3349             :             }
    3350           0 :             else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
    3351             :             {
    3352             : #ifdef  ISNAN
    3353           0 :                 ss << "0; i < " << pDVR->GetArrayLength();
    3354           0 :                 ss << " && i < gid0+"<< nCurWindowSize << "; ++i)\n";
    3355           0 :                 ss << "    {\n";
    3356             : #else
    3357             :                 ss << "0; i < gid0+"<< nCurWindowSize << "; ++i)\n";
    3358             :                 ss << "    {\n";
    3359             : #endif
    3360             :             }
    3361           0 :             else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
    3362             :             {
    3363             : #ifdef  ISNAN
    3364           0 :                 ss << "0; i + gid0 < " << pDVR->GetArrayLength();
    3365           0 :                 ss << " &&  i < "<< nCurWindowSize << "; ++i)\n";
    3366           0 :                 ss << "    {\n";
    3367             : #else
    3368             :                 ss << "0; i < "<< nCurWindowSize << "; ++i)\n";
    3369             :                 ss << "    {\n";
    3370             : #endif
    3371             :             }
    3372             :             else
    3373             :             {
    3374             : #ifdef  ISNAN
    3375           0 :                 ss << "0; i < "<< nCurWindowSize << "; ++i)\n";
    3376           0 :                 ss << "    {\n";
    3377             : #else
    3378             :                 ss << "0; i < "<< nCurWindowSize << "; ++i)\n";
    3379             :                 ss << "    {\n";
    3380             : #endif
    3381             :             }
    3382           0 :             ss << "        coeff = ";
    3383           0 :             ss << vSubArguments[3]->GenSlidingWindowDeclRef();
    3384           0 :             ss << ";\n";
    3385             : #ifdef  ISNAN
    3386           0 :             ss << "        if (isNan(coeff))\n";
    3387           0 :             ss << "            continue;\n";
    3388             : #endif
    3389           0 :             ss << "        res = res + coeff * pow(var[0],";
    3390           0 :             ss << " var[1] + j * var[2]);\n";
    3391           0 :             ss << "        ++j;\n";
    3392           0 :             ss << "    }\n";
    3393             :         }
    3394           0 :         else if(tmpCur->GetType() == formula::svSingleVectorRef)
    3395             :         {
    3396             :             const formula::SingleVectorRefToken* tmpCurDVR=
    3397             :                 static_cast<
    3398           0 :                 const formula::SingleVectorRefToken *>(tmpCur);
    3399           0 :             ss << "    coeff = ";
    3400           0 :             ss << vSubArguments[3]->GenSlidingWindowDeclRef();
    3401           0 :             ss << ";\n";
    3402             : #ifdef ISNAN
    3403           0 :             ss << "    if(isNan(coeff)||(gid0>=";
    3404           0 :             ss << tmpCurDVR->GetArrayLength();
    3405           0 :             ss << "))\n";
    3406           0 :             ss << "        return 0;\n";
    3407             : #endif
    3408             :         }
    3409             :     }
    3410           0 :     ss << "    return res;\n";
    3411           0 :     ss << "}";
    3412             : }
    3413         228 : }}
    3414             : 
    3415             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10