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

Generated by: LCOV version 1.10