[Libreoffice-commits] core.git: 31 commits - sc/Library_scopencl.mk sc/qa sc/source

mingli mingli at multicorewareinc.com
Wed Dec 18 18:35:27 PST 2013


 sc/Library_scopencl.mk                             |    1 
 sc/qa/unit/data/xls/opencl/logical/not.xls         |binary
 sc/qa/unit/data/xls/opencl/logical/or.xls          |binary
 sc/qa/unit/data/xls/opencl/logical/xor.xls         |binary
 sc/qa/unit/data/xls/opencl/spreadsheet/VLookup.xls |binary
 sc/qa/unit/opencl-test.cxx                         |  104 ++
 sc/source/core/opencl/formulagroupcl.cxx           |   17 
 sc/source/core/opencl/op_financial.cxx             |  410 ++++----
 sc/source/core/opencl/op_logical.cxx               |  207 ++++
 sc/source/core/opencl/op_logical.hxx               |   23 
 sc/source/core/opencl/op_math.cxx                  |  156 +--
 sc/source/core/opencl/op_math.hxx                  |    5 
 sc/source/core/opencl/op_spreadsheet.cxx           |  238 +++++
 sc/source/core/opencl/op_spreadsheet.hxx           |   29 
 sc/source/core/opencl/op_statistical.cxx           |  971 +++++++++++++--------
 sc/source/core/opencl/op_statistical.hxx           |    2 
 sc/source/core/opencl/opbase.cxx                   |   65 +
 sc/source/core/opencl/opbase.hxx                   |    5 
 sc/source/core/opencl/opinlinefun_math.hxx         |   25 
 sc/source/core/opencl/opinlinefun_statistical.cxx  |   77 +
 sc/source/core/tool/token.cxx                      |    3 
 21 files changed, 1707 insertions(+), 631 deletions(-)

New commits:
commit 3c32af65d42b2091e0557e238581fead39dea072
Author: mingli <mingli at multicorewareinc.com>
Date:   Thu Dec 5 09:54:10 2013 +0800

    GPU Calc: Optimized GAUSS
    
    AMLOEXT-276
    
    Change-Id: I29517305ffda2673961c2fa4dc46503690933645
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx
index b9aff2d..edf2910 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -3886,13 +3886,19 @@ formula::SingleVectorRefToken *>(tmpCur);
     ss << "return tmp;\n";
     ss << "}\n";
 }
+void OpGauss::BinInlineFun(std::set<std::string>& decls,
+    std::set<std::string>& funs)
+{
+    decls.insert(taylorDecl);decls.insert(phiDecl);
+    decls.insert(gaussDecl);
+    funs.insert(taylor);funs.insert(phi);
+    funs.insert(gauss);
+}
 
 void OpGauss::GenSlidingWindowFunction(
-    std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
+    std::stringstream &ss, const std::string sSymName, SubArguments &
+vSubArguments)
 {
-    FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR= dynamic_cast<const
-                formula::SingleVectorRefToken *>(tmpCur);
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (unsigned i = 0; i < vSubArguments.size(); i++)
@@ -3901,18 +3907,45 @@ void OpGauss::GenSlidingWindowFunction(
             ss << ",";
         vSubArguments[i]->GenSlidingWindowDecl(ss);
     }
-    ss << ") {\n\t";
-    ss <<"int gid0=get_global_id(0);\n\t";
-    ss << "double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
-    ss << ";\n\t";
+    ss << ") {\n";
+    ss <<"    int gid0=get_global_id(0);\n";
+    ss <<"    double arg0;\n";
+    if(vSubArguments.size() != 1)
+    {
+        ss << "    return DBL_MAX;\n";
+        return ;
+    }
+    FormulaToken *pCur = vSubArguments[0]->GetFormulaToken();
+    assert(pCur);
+    if (pCur->GetType() == formula::svDoubleVectorRef)
+    {
+        ss << "    return DBL_MAX;\n";
+        return ;
+    }
+    else if (pCur->GetType() == formula::svSingleVectorRef)
+    {
+        const formula::SingleVectorRefToken* pSVR =
+                dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
+        ss << "    arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
+        ss << ";\n";
 #ifdef ISNAN
-    ss<< "if(isNan(arg0)||(gid0>=";
-    ss<<tmpCurDVR->GetArrayLength();
-    ss<<"))\n\t\t";
-    ss<<"arg0 = 0;\n\t";
+        ss<< "    if(isNan(arg0)||(gid0>=";
+        ss<<pSVR->GetArrayLength();
+        ss<<"))\n";
+        ss<<"        arg0 = 0;\n";
 #endif
-    ss << "double tmp=0.5 *erfc(-arg0 * 0.7071067811865475)-0.5;\n\t";
-    ss << "return tmp;\n";
+    }
+    else if (pCur->GetType() == formula::svDouble)
+    {
+        ss << "    arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
+        ss << ";\n";
+#ifdef ISNAN
+        ss << "    if(isNan(arg0))\n";
+        ss << "        return DBL_MAX;\n";
+#endif
+    }
+    ss << "    double tmp=gauss(arg0);\n";
+    ss << "    return tmp;\n";
     ss << "}\n";
 }
 
diff --git a/sc/source/core/opencl/op_statistical.hxx b/sc/source/core/opencl/op_statistical.hxx
index 06929f4..c6443c2 100644
--- a/sc/source/core/opencl/op_statistical.hxx
+++ b/sc/source/core/opencl/op_statistical.hxx
@@ -192,6 +192,8 @@ class OpGauss: public Normal
 public:
     virtual void GenSlidingWindowFunction(std::stringstream &ss,
             const std::string sSymName, SubArguments &vSubArguments);
+       virtual void BinInlineFun(std::set<std::string>& ,
+        std::set<std::string>& );
     virtual std::string BinFuncName(void) const { return "Gauss"; }
 };
 
diff --git a/sc/source/core/opencl/opinlinefun_statistical.cxx b/sc/source/core/opencl/opinlinefun_statistical.cxx
index 81e8150..ab03479 100644
--- a/sc/source/core/opencl/opinlinefun_statistical.cxx
+++ b/sc/source/core/opencl/opinlinefun_statistical.cxx
@@ -1272,7 +1272,76 @@ std::string lcl_IterateInverse =
 "    }\n"
 "    return fRx;\n"
 "}\n";
-
+std::string phiDecl=
+"double phi(double x);\n";
+std::string phi =
+"double phi(double x)\n"
+"{\n"
+"    return  0.39894228040143268 * exp(-(x * x) / 2.0);\n"
+"}\n";
+std::string taylorDecl =
+"double taylor(double* pPolynom, uint nMax, double x);\n";
+std::string taylor =
+"double taylor(double* pPolynom, uint nMax, double x)\n"
+"{\n"
+"    double nVal = pPolynom[nMax];\n"
+"    for (short i = nMax-1; i >= 0; i--)\n"
+"    {\n"
+"        nVal = pPolynom[i] + (nVal * x);\n"
+"    }\n"
+"    return nVal;\n"
+"}";
+std::string gaussDecl = "double gauss(double x);\n";
+std::string gauss =
+"double gauss(double x)\n"
+"{\n"
+"    double xAbs = fabs(x);\n"
+"    uint xShort = (uint)(floor(xAbs));\n"
+"    double nVal = 0.0;\n"
+"    if (xShort == 0)\n"
+"    {\n"
+"        double t0[] =\n"
+"        { 0.39894228040143268, -0.06649038006690545,  0.00997355701003582,\n"
+"         -0.00118732821548045,  0.00011543468761616, -0.00000944465625950,\n"
+"          0.00000066596935163, -0.00000004122667415,  0.00000000227352982,\n"
+"          0.00000000011301172,  0.00000000000511243, -0.00000000000021218 };\n"
+"        nVal = taylor(t0, 11, (xAbs * xAbs)) * xAbs;\n"
+"    }\n"
+"    else if ((xShort >= 1) && (xShort <= 2))\n"
+"    {\n"
+"        double t2[] =\n"
+"        { 0.47724986805182079,  0.05399096651318805, -0.05399096651318805,\n"
+"          0.02699548325659403, -0.00449924720943234, -0.00224962360471617,\n"
+"          0.00134977416282970, -0.00011783742691370, -0.00011515930357476,\n"
+"          0.00003704737285544,  0.00000282690796889, -0.00000354513195524,\n"
+"          0.00000037669563126,  0.00000019202407921, -0.00000005226908590,\n"
+"         -0.00000000491799345,  0.00000000366377919, -0.00000000015981997,\n"
+"         -0.00000000017381238,  0.00000000002624031,  0.00000000000560919,\n"
+"         -0.00000000000172127, -0.00000000000008634, 0.00000000000007894 };\n"
+"        nVal = taylor(t2, 23, (xAbs - 2.0));\n"
+"    }\n"
+"    else if ((xShort >= 3) && (xShort <= 4))\n"
+"    {\n"
+"       double t4[] =\n"
+"       { 0.49996832875816688,  0.00013383022576489, -0.00026766045152977,\n"
+"         0.00033457556441221, -0.00028996548915725,  0.00018178605666397,\n"
+"        -0.00008252863922168,  0.00002551802519049, -0.00000391665839292,\n"
+"        -0.00000074018205222,  0.00000064422023359, -0.00000017370155340,\n"
+"         0.00000000909595465,  0.00000000944943118, -0.00000000329957075,\n"
+"         0.00000000029492075,  0.00000000011874477, -0.00000000004420396,\n"
+"         0.00000000000361422,  0.00000000000143638, -0.00000000000045848 };\n"
+"        nVal = taylor(t4, 20, (xAbs - 4.0));\n"
+"    }\n"
+"    else\n"
+"    {\n"
+"        double asympt[] = { -1.0, 1.0, -3.0, 15.0, -105.0 };\n"
+"        nVal = 0.5 + phi(xAbs) * taylor(asympt, 4, 1.0/(xAbs * xAbs))/xAbs;\n"
+"    }\n"
+"    if (x < 0.0)\n"
+"        return -nVal;\n"
+"    else\n"
+"        return nVal;\n"
+"}\n";
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit d2fe0c84f30092ba7da2d9d5d8a39841608336c1
Author: fengzeng <fengzeng at multicorewareinc.com>
Date:   Thu Dec 5 09:40:05 2013 +0800

    GPU Calc: Optimized SIN
    
    AMLOEXT-275
    
    Change-Id: I8c33b2ac82c492a085222649f5f89ccb2802a3eb
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_math.cxx b/sc/source/core/opencl/op_math.cxx
index bf2e92c..f5c677b 100644
--- a/sc/source/core/opencl/op_math.cxx
+++ b/sc/source/core/opencl/op_math.cxx
@@ -861,8 +861,8 @@ void OpSin::GenSlidingWindowFunction(std::stringstream &ss,
     ss << "))\n";
     ss << "        arg0 = 0;\n";
 #endif
-    ss << "    double tmp=sin(arg0);\n";
-    ss << "    return tmp;\n";
+    ss << "    double x = arg0 * M_1_PI;\n";
+    ss << "    return sinpi(x);\n";
     ss << "}";
 }
 void OpAbs::GenSlidingWindowFunction(std::stringstream &ss,
commit e0c571adbc959c87a777675af571cb21c667e0f1
Author: fengzeng <fengzeng at multicorewareinc.com>
Date:   Thu Dec 5 09:36:46 2013 +0800

    GPU Calc: Optimized TAN
    
    AMLOEXT-274
    
    Change-Id: I971bb4a44ff68af5c9fc952419e7035d1127fd5f
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_math.cxx b/sc/source/core/opencl/op_math.cxx
index 3ae28bc..bf2e92c 100644
--- a/sc/source/core/opencl/op_math.cxx
+++ b/sc/source/core/opencl/op_math.cxx
@@ -956,30 +956,51 @@ void OpArcCosHyp::GenSlidingWindowFunction(std::stringstream &ss,
 void OpTan::GenSlidingWindowFunction(std::stringstream &ss,
             const std::string sSymName, SubArguments &vSubArguments)
 {
-    FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR= dynamic_cast<const
-          formula::SingleVectorRefToken *>(tmpCur);
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (unsigned i = 0; i < vSubArguments.size(); i++)
     {
-        if (i)
-            ss << ",";
+        if (i) ss << ",";
         vSubArguments[i]->GenSlidingWindowDecl(ss);
     }
     ss << ")\n";
     ss << "{\n";
     ss << "    int gid0=get_global_id(0);\n";
-    ss << "    double arg0 = "<< vSubArguments[0]->GenSlidingWindowDeclRef();
-    ss << ";\n";
+    ss << "    double arg0 = 0.0f;\n";
+    FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
+    assert(tmpCur);
+    if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
+    {
+        if(tmpCur->GetType() == formula::svSingleVectorRef)
+        {
+            const formula::SingleVectorRefToken*tmpCurDVR=
+                dynamic_cast
+                <const formula::SingleVectorRefToken *>(tmpCur);
+            ss << "    arg0 = ";
+            ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+            ss << ";\n";
 #ifdef ISNAN
-    ss << "    if(isNan(arg0)||(gid0>=";
-    ss << tmpCurDVR->GetArrayLength();
-    ss << "))\n";
-    ss << "        arg0 = 0;\n";
+            ss << "    if(isNan(";
+            ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+            ss << ")||(gid0>=";
+            ss << tmpCurDVR->GetArrayLength();
+            ss << "))\n";
+            ss << "    { arg0 = 0.0f; }\n";
 #endif
-    ss << "    double tmp=tan(arg0);\n";
-    ss << "    return tmp;\n";
+        }
+        else if(tmpCur->GetType() == formula::svDouble)
+        {
+            ss << "    arg0=" << tmpCur->GetDouble() << ";\n";
+        }
+    }
+    else
+    {
+        ss << "        arg0 = ";
+        ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+        ss << ";\n";
+    }
+    ss << "    arg0 = arg0 * M_1_PI;\n";
+    ss << "    return sinpi(arg0) * pow(cospi(arg0), -1);\n";
     ss << "}";
 }
 void OpTanH::GenSlidingWindowFunction(std::stringstream &ss,
commit 821e19f227dba1fd2fbe63475e30559f06db4652
Author: yangzhang <yangzhang at multicorewareinc.com>
Date:   Thu Dec 5 09:30:35 2013 +0800

    GPU Calc: Optimized ATANH
    
    AMLOEXT-273
    
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_math.cxx b/sc/source/core/opencl/op_math.cxx
index e96c7ca..3ae28bc 100644
--- a/sc/source/core/opencl/op_math.cxx
+++ b/sc/source/core/opencl/op_math.cxx
@@ -1273,7 +1273,9 @@ void OpArcTanH::GenSlidingWindowFunction(std::stringstream &ss,
     ss << "    else \n    ";
 #endif
     ss << "    tmp = " << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
-    ss << "    return atanh(tmp);\n";
+    ss << "    double a = 1.0 + tmp;\n";
+    ss << "    double b = 1.0 - tmp;\n";
+    ss << "    return log(pow(a/b, 0.5));\n";
     ss << "}";
 }
 void OpBitAnd::GenSlidingWindowFunction(std::stringstream &ss,
commit de0013f64ad18f93dc175bdf3843aec1cfa102cb
Author: minwang <min at multicorewareinc.com>
Date:   Thu Dec 5 09:06:17 2013 +0800

    GPU Calc: unit test cases for XOR
    
    Need turn NO_FALLBACK_TO_SWINTERP on  in formulagroupcl.cxx for test
    
    AMLOEXT-272 BUG
    
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/qa/unit/data/xls/opencl/logical/xor.xls b/sc/qa/unit/data/xls/opencl/logical/xor.xls
new file mode 100644
index 0000000..fccba9b
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/logical/xor.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 4587844..7796b57 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -247,6 +247,7 @@ public:
     void testStatisticalParallelCountBug();
     void testSpreadSheetFormulaVLookup();
     void testLogicalFormulaNot();
+    void testLogicalFormulaXor();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -425,6 +426,7 @@ public:
     CPPUNIT_TEST(testSpreadSheetFormulaVLookup);
     CPPUNIT_TEST(testLogicalFormulaOr);
     CPPUNIT_TEST(testLogicalFormulaNot);
+    CPPUNIT_TEST(testLogicalFormulaXor);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -4950,6 +4952,28 @@ void ScOpenclTest:: testLogicalFormulaNot()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
+//[AMLOEXT-272]
+void ScOpenclTest:: testLogicalFormulaXor()
+{
+    if (!detectOpenCLDevice())
+        return;
+    ScDocShellRef xDocSh = loadDoc("opencl/logical/xor.", XLS);
+    ScDocument *pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+    ScDocShellRef xDocShRes = loadDoc("opencl/logical/xor.", XLS);
+    ScDocument *pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    for (SCROW i = 0; i < 30000; ++i)
+    {
+        double fLibre = pDoc->GetValue(ScAddress(1, i, 0));
+        double fExcel = pDocRes->GetValue(ScAddress(1, i, 0));
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel));
+    }
+    xDocSh->DoClose();
+    xDocShRes->DoClose();
+}
 ScOpenclTest::ScOpenclTest()
       : ScBootstrapFixture( "/sc/qa/unit/data" )
 {
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 8417191..860dbe2 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1475,6 +1475,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
             case ocAnd:
             case ocOr:
             case ocNot:
+            case ocXor:
             // Don't change the state.
             break;
             default:
commit 4ea6b93c0ffec54f5aa8e742acba06a09276dae1
Author: minwang <min at multicorewareinc.com>
Date:   Thu Dec 5 09:13:54 2013 +0800

    GPU Calc: implemented for XOR
    
    AMLOEXT-272 FIX
    
    Change-Id: I7df1d62999012a2a7b6273e59b93f4eef1cf4709
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index d5739dc..e89bcdf 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -2307,6 +2307,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
                 mvSubArguments.push_back(SoPHelper(ts,
                          ft->Children[i], new OpNot));
                  break;
+            case ocXor:
+                mvSubArguments.push_back(SoPHelper(ts,
+                         ft->Children[i], new OpXor));
+                 break;
             case ocExternal:
                 if ( !(pChild->GetExternal().compareTo(OUString(
                     "com.sun.star.sheet.addin.Analysis.getEffect"))))
diff --git a/sc/source/core/opencl/op_logical.cxx b/sc/source/core/opencl/op_logical.cxx
index 093efa5..b3048cd 100644
--- a/sc/source/core/opencl/op_logical.cxx
+++ b/sc/source/core/opencl/op_logical.cxx
@@ -227,5 +227,90 @@ void OpNot::GenSlidingWindowFunction(std::stringstream &ss,
     ss << "    return tmp;\n";
     ss << "}\n";
 }
+
+void OpXor::GenSlidingWindowFunction(std::stringstream &ss,
+    const std::string sSymName, SubArguments &vSubArguments)
+{
+    ss << "\ndouble " << sSymName;
+    ss << "_"<< BinFuncName() <<"(";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
+    {
+        if (i)
+            ss << ",";
+        vSubArguments[i]->GenSlidingWindowDecl(ss);
+    }
+    ss << ") {\n";
+    ss << "    int gid0 = get_global_id(0);\n";
+    ss << "    int t = 0,tmp0 = 0;\n";
+    ss << "    double tmp = 0;\n";
+    for(unsigned int j = 0; j< vSubArguments.size(); j++)
+    {
+        FormulaToken *tmpCur0 = vSubArguments[j]->GetFormulaToken();
+        if(tmpCur0->GetType() == formula::svSingleVectorRef)
+        {
+#ifdef ISNAN
+            const formula::SingleVectorRefToken*pCurDVR= dynamic_cast<const
+                formula::SingleVectorRefToken *>(tmpCur0);
+            ss <<"    if(gid0 >= "<<pCurDVR->GetArrayLength()<<" || isNan(";
+            ss <<vSubArguments[j]->GenSlidingWindowDeclRef();
+            ss <<"))\n";
+            ss <<"        tmp = 0;\n    else\n";
+#endif
+            ss <<"        tmp = ";
+            ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
+            ss <<"    tmp0 = (tmp != 0);\n";
+            ss <<"    t = t ^tmp0;\n";
+        }
+        else if(tmpCur0->GetType() == formula::svDouble)
+        {
+            ss <<"        tmp = ";
+            ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
+            ss <<"    tmp0 = (tmp != 0);\n";
+            ss <<"    t = t ^tmp0;\n";
+        }
+        else if(tmpCur0->GetType() == formula::svDoubleVectorRef)
+        {
+            const formula::DoubleVectorRefToken*pCurDVR= dynamic_cast<const
+            formula::DoubleVectorRefToken *>(tmpCur0);
+            size_t nCurWindowSize = pCurDVR->GetArrayLength() <
+            pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
+            pCurDVR->GetRefRowSize() ;
+            ss << "    for(int i = ";
+            if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
+            ss << "gid0; i < " << nCurWindowSize << "; i++) {\n";
+            }
+            else if(pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()){
+            ss << "0; i < gid0 + " << nCurWindowSize << "; i++) {\n";
+            }
+            else{
+            ss << "0; i < " << nCurWindowSize << "; i++) {\n";
+            }
+#ifdef ISNAN
+            if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
+                {
+            ss <<"    if(isNan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
+            ss <<")||i+gid0>="<<pCurDVR->GetArrayLength();
+            ss <<")\n";
+            ss <<"        tmp = 0;\n    else\n";
+                }
+            else
+                {
+            ss <<"    if(isNan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
+            ss <<")||i>="<<pCurDVR->GetArrayLength();
+            ss <<")\n";
+            ss <<"        tmp = 0;\n    else\n";
+                }
+#endif
+            ss <<"        tmp = ";
+            ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
+            ss <<"    tmp0 = (tmp != 0);\n";
+            ss <<"    t = t ^tmp0;\n";
+            ss <<"    }\n";
+        }
+    }
+    ss << "    return t;\n";
+    ss << "}\n";
+}
+
 }}
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/opencl/op_logical.hxx b/sc/source/core/opencl/op_logical.hxx
index 3c3e339..50aa469 100644
--- a/sc/source/core/opencl/op_logical.hxx
+++ b/sc/source/core/opencl/op_logical.hxx
@@ -37,6 +37,13 @@ public:
             const std::string sSymName, SubArguments &vSubArguments);
     virtual std::string BinFuncName(void) const { return "Not"; }
 };
+class OpXor: public Normal
+{
+public:
+    virtual void GenSlidingWindowFunction(std::stringstream &ss,
+            const std::string sSymName, SubArguments &vSubArguments);
+    virtual std::string BinFuncName(void) const { return "Xor"; }
+};
 
 }}
 
commit 04a284012ae17165c834c32257e1b36fbae53155
Author: fengzeng <fengzeng at multicorewareinc.com>
Date:   Wed Dec 4 16:52:51 2013 +0800

    GPU Calc: Optimized EXP
    
    AMLOEXT-271
    
    Change-Id: I61eaa744d8b4f10804254c6cede39af274c150ad
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_math.cxx b/sc/source/core/opencl/op_math.cxx
index f54f22b..e96c7ca 100644
--- a/sc/source/core/opencl/op_math.cxx
+++ b/sc/source/core/opencl/op_math.cxx
@@ -702,7 +702,7 @@ void OpExp::GenSlidingWindowFunction(std::stringstream &ss,
     ss<<"))\n\t\t";
     ss<<"arg0 = 0;\n\t";
 #endif
-    ss << "double tmp=exp(arg0);\n\t";
+    ss << "double tmp = pow(M_E, arg0);\n\t";
     ss << "return tmp;\n";
     ss << "}";
 }
commit 160d5e54b578895424a1c77de805beae46b82226
Author: minwang <min at multicorewareinc.com>
Date:   Wed Dec 4 15:04:06 2013 +0800

    GPU Calc: unit test cases for NOT
    
    Need turn NO_FALLBACK_TO_SWINTERP on  in formulagroupcl.cxx for test
    
    AMLOEXT-267 BUG
    
    Change-Id: I5d438b79df9af1f59645cbcbc84811bfc4055bd3
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/qa/unit/data/xls/opencl/logical/not.xls b/sc/qa/unit/data/xls/opencl/logical/not.xls
new file mode 100644
index 0000000..651a8f9
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/logical/not.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index d926a15..4587844 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -246,6 +246,7 @@ public:
     void testMathFormulaSumProduct2();
     void testStatisticalParallelCountBug();
     void testSpreadSheetFormulaVLookup();
+    void testLogicalFormulaNot();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -423,6 +424,7 @@ public:
     CPPUNIT_TEST(testStatisticalParallelCountBug);
     CPPUNIT_TEST(testSpreadSheetFormulaVLookup);
     CPPUNIT_TEST(testLogicalFormulaOr);
+    CPPUNIT_TEST(testLogicalFormulaNot);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -4926,6 +4928,28 @@ void ScOpenclTest:: testLogicalFormulaOr()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
+//[AMLOEXT-267]
+void ScOpenclTest:: testLogicalFormulaNot()
+{
+    if (!detectOpenCLDevice())
+        return;
+    ScDocShellRef xDocSh = loadDoc("opencl/logical/not.", XLS);
+    ScDocument *pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+    ScDocShellRef xDocShRes = loadDoc("opencl/logical/not.", XLS);
+    ScDocument *pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    for (SCROW i = 0; i < 30000; ++i)
+    {
+        double fLibre = pDoc->GetValue(ScAddress(1, i, 0));
+        double fExcel = pDocRes->GetValue(ScAddress(1, i, 0));
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel));
+    }
+    xDocSh->DoClose();
+    xDocShRes->DoClose();
+}
 ScOpenclTest::ScOpenclTest()
       : ScBootstrapFixture( "/sc/qa/unit/data" )
 {
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 131bd91..8417191 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1474,6 +1474,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
             case ocCovar:
             case ocAnd:
             case ocOr:
+            case ocNot:
             // Don't change the state.
             break;
             default:
commit 957fefd8f9f04203d5f0c142646b51956f90e6bc
Author: minwang <min at multicorewareinc.com>
Date:   Wed Dec 4 15:06:18 2013 +0800

    GPU Calc: implemented for NOT
    
    AMLOEXT-267 FIX
    
    Change-Id: If759780792ec1d4fbba8b9e05e1219a9845818cd
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index a4748c1..d5739dc 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -2303,6 +2303,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
                 mvSubArguments.push_back(SoPHelper(ts,
                          ft->Children[i], new OpOr));
                  break;
+            case ocNot:
+                mvSubArguments.push_back(SoPHelper(ts,
+                         ft->Children[i], new OpNot));
+                 break;
             case ocExternal:
                 if ( !(pChild->GetExternal().compareTo(OUString(
                     "com.sun.star.sheet.addin.Analysis.getEffect"))))
diff --git a/sc/source/core/opencl/op_logical.cxx b/sc/source/core/opencl/op_logical.cxx
index 6ac26d4..093efa5 100644
--- a/sc/source/core/opencl/op_logical.cxx
+++ b/sc/source/core/opencl/op_logical.cxx
@@ -189,5 +189,43 @@ void OpOr::GenSlidingWindowFunction(std::stringstream &ss,
     ss << "    return t;\n";
     ss << "}\n";
 }
+void OpNot::GenSlidingWindowFunction(std::stringstream &ss,
+    const std::string sSymName, SubArguments &vSubArguments)
+{
+    ss << "\ndouble " << sSymName;
+    ss << "_"<< BinFuncName() <<"(";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
+    {
+        if (i)
+            ss << ",";
+        vSubArguments[i]->GenSlidingWindowDecl(ss);
+    }
+    ss << ") {\n";
+    ss << "    int gid0 = get_global_id(0);\n";
+    ss << "    double tmp=0;\n";
+    FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
+    if(tmpCur0->GetType() == formula::svSingleVectorRef)
+    {
+#ifdef ISNAN
+        const formula::SingleVectorRefToken*pCurDVR= dynamic_cast<const
+            formula::SingleVectorRefToken *>(tmpCur0);
+        ss <<"    if(gid0 >= "<<pCurDVR->GetArrayLength()<<" || isNan(";
+        ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
+        ss <<"))\n";
+        ss <<"        tmp = 0;\n    else\n";
+#endif
+        ss <<"        tmp = ";
+        ss <<vSubArguments[0]->GenSlidingWindowDeclRef()<<";\n";
+        ss <<"    tmp = (tmp == 0.0);\n";
+    }
+    else if(tmpCur0->GetType() == formula::svDouble)
+    {
+        ss <<"        tmp = ";
+        ss <<vSubArguments[0]->GenSlidingWindowDeclRef()<<";\n";
+        ss <<"    tmp = (tmp == 0.0);\n";
+    }
+    ss << "    return tmp;\n";
+    ss << "}\n";
+}
 }}
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/opencl/op_logical.hxx b/sc/source/core/opencl/op_logical.hxx
index 40ab046..3c3e339 100644
--- a/sc/source/core/opencl/op_logical.hxx
+++ b/sc/source/core/opencl/op_logical.hxx
@@ -30,6 +30,13 @@ public:
             const std::string sSymName, SubArguments &vSubArguments);
     virtual std::string BinFuncName(void) const { return "Or"; }
 };
+class OpNot: public Normal
+{
+public:
+    virtual void GenSlidingWindowFunction(std::stringstream &ss,
+            const std::string sSymName, SubArguments &vSubArguments);
+    virtual std::string BinFuncName(void) const { return "Not"; }
+};
 
 }}
 
commit ec4b9fb267d6b3a071dd8bbf0a9f58272b339df1
Author: fengzeng <fengzeng at multicorewareinc.com>
Date:   Wed Dec 4 17:19:45 2013 +0800

    GPU Calc: Optimized PMT
    
    AMLOEXT-266
    
    Change-Id: Ia55a379aacb820b088ffd7e22409974918f9193a
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index ccf2bf4..cc22404 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -2451,110 +2451,72 @@ void OpPMT::GenSlidingWindowFunction(std::stringstream &ss,
             ss << ", ";
         vSubArguments[i]->GenSlidingWindowDecl(ss);
     }
-    ss << ") {\n    ";
-    ss << "double tmp = 0;\n    ";
-    ss << "int gid0 = get_global_id(0);\n    ";
-    ss<<"double tmp0,tmp1,tmp2;\n    ";
-    ss<<"double tmp3=0,tmp4=0;\n    ";
+    ss<<") {\n";
+    ss<<"    double tmp = 0;\n";
+    ss<<"    double temp=0.0;\n";
+    ss<<"    int gid0 = get_global_id(0);\n";
+    ss<<"    double tmp0=0,tmp1=0,tmp2=0;\n";
+    ss<<"    double tmp3=0,tmp4=0;\n";
     size_t i = vSubArguments.size();
-    size_t nItems = 0;
     ss <<"\n    ";
     //while (i-- > 1)
     for (i = 0; i < vSubArguments.size(); i++)
     {
         FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
         assert(pCur);
-        if (pCur->GetType() == formula::svDoubleVectorRef)
-        {
-            const formula::DoubleVectorRefToken* pDVR =
-            dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
-            size_t nCurWindowSize = pDVR->GetRefRowSize();
-            ss << "for (int i = ";
-            if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
-#ifdef  ISNAN
-                ss << "gid0; i < " << pDVR->GetArrayLength();
-                ss << " && i < " << nCurWindowSize  << "; i++){\n        ";
-#else
-                ss << "gid0; i < "<< nCurWindowSize << "; i++)\n        ";
-#endif
-            } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
-#ifdef  ISNAN
-                ss << "0; i < " << pDVR->GetArrayLength();
-                ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n        ";
-#else
-                ss << "0; i < gid0+"<< nCurWindowSize << "; i++)\n        ";
-#endif
-            } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
-#ifdef  ISNAN
-                ss << "0; i + gid0 < " << pDVR->GetArrayLength();
-                ss << " &&  i < "<< nCurWindowSize << "; i++){\n        ";
-#else
-                ss << "0; i < "<< nCurWindowSize << "; i++)\n        ";
-#endif
-            }
-            else {
-#ifdef  ISNAN
-                ss << "0; i < "<< nCurWindowSize << "; i++){\n        ";
-#else
-                ss << "0; i < "<< nCurWindowSize << "; i++)\n        ";
-#endif
-            }
-            nItems += nCurWindowSize;
-        }
-        else if (pCur->GetType() == formula::svSingleVectorRef)
+        if (pCur->GetType() == formula::svSingleVectorRef)
         {
 #ifdef  ISNAN
                 const formula::SingleVectorRefToken* pSVR =
                 dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
-            ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n        ";
+            ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
 #else
-            nItems += 1;
 #endif
         }
         else if (pCur->GetType() == formula::svDouble)
         {
 #ifdef  ISNAN
-            ss << "{\n        ";
+            ss << "{\n";
 #endif
-            nItems += 1;
         }
         else
         {
 #ifdef  ISNAN
 #endif
-            nItems += 1;
         }
 #ifdef  ISNAN
         if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
         {
-            ss << "if (isNan(";
-            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
-            ss << "))\n            ";
-            ss << "tmp"<<i<<"= 0;\n        ";
-            ss << "else\n            ";
-            ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
-            ss << ";\n    }\n    ";
+            ss <<"    temp="<<vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss <<";\n";
+            ss <<"    if (isNan(temp))\n";
+            ss <<"        tmp"<<i<<"= 0;\n";
+            ss <<"    else\n";
+            ss <<"        tmp"<<i<<"=temp;\n";
+            ss <<"    }\n";
         }
         else
         {
-            ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
-            ss <<";\n    ";
+            ss <<"    tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef(
+);
+            ss <<";\n";
         }
 #else
-    ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
-    ss <<";\n    ";
+    ss <<"    tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
+    ss <<";\n";
 
 #endif
     }
-    ss<<"if(tmp0==0.0)\n    ";
-    ss<<"    return -(tmp2+tmp3)/tmp1;\n    ";
-    ss<<"double abl = pow(1.0+tmp0,tmp1);\n    tmp-=tmp3";
-    ss<<";\n    tmp-=tmp2*abl;\n    ";
-    ss<<"tmp =tmp/(1.0+tmp0*tmp4";
-    ss<<") / ( (abl-1.0)/tmp0);\n    ";
-    ss << "return tmp;\n";
-    ss << "}";
+    ss<<"    if(tmp0==0.0)\n";
+    ss<<"        return -(tmp2+tmp3)/tmp1;\n";
+    ss<<"    tmp-=tmp3;\n";
+    ss<<"    tmp=tmp-tmp2*pow(1.0+tmp0,tmp1);\n";
+    ss<<"    tmp=tmp*pow(( (1.0+tmp0*tmp4)* ";
+    ss<<"( (pow(1.0+tmp0,tmp1)-1.0)/tmp0)),-1);\n";
+    ss<<"    return tmp;\n";
+    ss<<"}";
 }
+
 void OpNPV::GenSlidingWindowFunction(std::stringstream &ss,
     const std::string sSymName, SubArguments &vSubArguments)
 {
commit 9a4bc2541d92bf935408a08e19547bfc00e59223
Author: mulei <mulei at multicorewareinc.com>
Date:   Wed Dec 4 16:28:30 2013 +0800

    GPU Calc: Optimized NOMINAL
    
    AMLOEXT-265
    
    Change-Id: I497b5cd9c89fc1c1afc4091023335b7db9fc8f4b
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index 016214e..ccf2bf4 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -102,7 +102,8 @@ void RRI::GenSlidingWindowFunction(
 }
 
 void OpNominal::GenSlidingWindowFunction(
-    std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
+    std::stringstream &ss, const std::string sSymName, SubArguments &
+vSubArguments)
 {
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
@@ -114,31 +115,59 @@ void OpNominal::GenSlidingWindowFunction(
     }
     ss << ") {\n\t";
     ss << "double tmp = 0;\n\t";
+    ss << "double temp = 0;\n\t";
     ss << "int gid0 = get_global_id(0);\n\t";
-    ss <<"double tmp0 = ";
-    ss <<vSubArguments[0]->GenSlidingWindowDeclRef()<<";\n\t";
-    ss <<"double tmp1 = ";
-    ss <<vSubArguments[1]->GenSlidingWindowDeclRef()<<";\n\t";
-#ifdef ISNAN
-
-    FormulaToken *tmpCur0 = vSubArguments[0]
-        ->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
-    formula::SingleVectorRefToken *>(tmpCur0);
-    ss<<"if("<<tmpCurDVR0->GetArrayLength()<<"<=gid0||";
-    ss <<"isNan(tmp0))\n\t\t";
-    ss<<" tmp0= 0;\n\t";
-    FormulaToken *tmpCur1 = vSubArguments[1]
-        ->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
-    formula::SingleVectorRefToken *>(tmpCur1);
-    ss<<"if("<<tmpCurDVR1->GetArrayLength()<<"<=gid0||";
-    ss <<"isNan(tmp1))\n\t\t";
-    ss<<" tmp1= 0;\n\t";
+    ss << "double tmp0=0,tmp1=0;\n";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
+    {
+        FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
+        assert(pCur);
+        if (pCur->GetType() == formula::svSingleVectorRef)
+        {
+#ifdef  ISNAN
+                const formula::SingleVectorRefToken* pSVR =
+                dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
+            ss << "    if (gid0 < " << pSVR->GetArrayLength() << "){\n";
+#else
+#endif
+        }
+        else if (pCur->GetType() == formula::svDouble)
+        {
+#ifdef  ISNAN
+            ss << "{\n";
+#endif
+        }
+        else
+        {
+#ifdef  ISNAN
 #endif
+        }
+#ifdef  ISNAN
+        if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
+        {
+            ss <<"    temp="<<vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss <<";\n";
+            ss <<"    if (isNan(temp))\n";
+            ss <<"        tmp"<<i<<"= 0;\n";
+            ss <<"    else\n";
+            ss <<"        tmp"<<i<<"=temp;\n";
+            ss <<"    }\n";
+        }
+        else
+        {
+            ss <<"    tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef(
+);
+            ss <<";\n";
+        }
+#else
+    ss <<"    tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
+    ss <<";\n";
+#endif
+    }
     ss<<"if(tmp1==0)\n\t";
     ss<<"\treturn 0;\n\t";
-    ss<<"tmp=( pow( tmp0+ 1.0, 1.0 / tmp1 ) - 1.0 ) *";
+    ss<<"tmp=pow( tmp1,-1);\n\t";
+    ss<<"tmp=( pow( tmp0+ 1.0, tmp ) - 1.0 ) *";
     ss<<"tmp1;\n\t";
     ss << "return tmp;\n";
     ss << "}";
commit 2180b1c9b0e944378288e6e7fe46b1b1cc1ca9af
Author: minwang <min at multicorewareinc.com>
Date:   Wed Dec 4 10:31:30 2013 +0800

    GPU Calc: unit test cases for OR
    
    Need turn NO_FALLBACK_TO_SWINTERP on  in formulagroupcl.cxx for test
    
    AMLOEXT-264 BUG
    
    Change-Id: I6d826bf53b801e2270734bf5bf7f38095ff0d2b0
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/qa/unit/data/xls/opencl/logical/or.xls b/sc/qa/unit/data/xls/opencl/logical/or.xls
new file mode 100644
index 0000000..5097098
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/logical/or.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index e1f435e..d926a15 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -241,6 +241,7 @@ public:
     void testStatisticalFormulaStDevP();
     void testStatisticalFormulaCovar();
     void testLogicalFormulaAnd();
+    void testLogicalFormulaOr();
     void testMathFormulaSumProduct();
     void testMathFormulaSumProduct2();
     void testStatisticalParallelCountBug();
@@ -421,6 +422,7 @@ public:
     CPPUNIT_TEST(testMathFormulaSumProduct2);
     CPPUNIT_TEST(testStatisticalParallelCountBug);
     CPPUNIT_TEST(testSpreadSheetFormulaVLookup);
+    CPPUNIT_TEST(testLogicalFormulaOr);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -4902,7 +4904,28 @@ void ScOpenclTest:: testStatisticalParallelCountBug()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
-
+//[AMLOEXT-264]
+void ScOpenclTest:: testLogicalFormulaOr()
+{
+    if (!detectOpenCLDevice())
+        return;
+    ScDocShellRef xDocSh = loadDoc("opencl/logical/or.", XLS);
+    ScDocument *pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+    ScDocShellRef xDocShRes = loadDoc("opencl/logical/or.", XLS);
+    ScDocument *pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    for (SCROW i = 0; i < 20; ++i)
+    {
+        double fLibre = pDoc->GetValue(ScAddress(2, i, 0));
+        double fExcel = pDocRes->GetValue(ScAddress(2, i, 0));
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel));
+    }
+    xDocSh->DoClose();
+    xDocShRes->DoClose();
+}
 ScOpenclTest::ScOpenclTest()
       : ScBootstrapFixture( "/sc/qa/unit/data" )
 {
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 772989b..131bd91 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1473,6 +1473,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
             case ocStDevP:
             case ocCovar:
             case ocAnd:
+            case ocOr:
             // Don't change the state.
             break;
             default:
commit ffedbc9603c7e940b157a53b5f193f0ea3249628
Author: minwang <min at multicorewareinc.com>
Date:   Wed Dec 4 10:57:52 2013 +0800

    GPU Calc: implemented for OR
    
    AMLOEXT-264 FIX
    
    Change-Id: I9558b416249cda0a7eb681f7e4b7ef0c6dd7cfa6
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index 66d9452..a4748c1 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -2299,6 +2299,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
                 mvSubArguments.push_back(SoPHelper(ts,
                          ft->Children[i], new OpVLookup));
                  break;
+            case ocOr:
+                mvSubArguments.push_back(SoPHelper(ts,
+                         ft->Children[i], new OpOr));
+                 break;
             case ocExternal:
                 if ( !(pChild->GetExternal().compareTo(OUString(
                     "com.sun.star.sheet.addin.Analysis.getEffect"))))
diff --git a/sc/source/core/opencl/op_logical.cxx b/sc/source/core/opencl/op_logical.cxx
index dd455ec..6ac26d4 100644
--- a/sc/source/core/opencl/op_logical.cxx
+++ b/sc/source/core/opencl/op_logical.cxx
@@ -105,5 +105,89 @@ void OpAnd::GenSlidingWindowFunction(std::stringstream &ss,
     ss << "    return t;\n";
     ss << "}\n";
 }
+
+void OpOr::GenSlidingWindowFunction(std::stringstream &ss,
+    const std::string sSymName, SubArguments &vSubArguments)
+{
+    ss << "\ndouble " << sSymName;
+    ss << "_"<< BinFuncName() <<"(";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
+    {
+        if (i)
+            ss << ",";
+        vSubArguments[i]->GenSlidingWindowDecl(ss);
+    }
+    ss << ") {\n";
+    ss << "    int gid0 = get_global_id(0);\n";
+    ss << "    double t = 0,tmp=0;\n";
+    for(unsigned int j = 0; j< vSubArguments.size(); j++)
+    {
+        ss << "    double tmp"<<j<<" = 0;\n";
+        FormulaToken *tmpCur0 = vSubArguments[j]->GetFormulaToken();
+        if(tmpCur0->GetType() == formula::svSingleVectorRef)
+        {
+#ifdef ISNAN
+        const formula::SingleVectorRefToken*pCurDVR= dynamic_cast<const
+            formula::SingleVectorRefToken *>(tmpCur0);
+        ss<< "    int buffer_len"<<j<<" = "<<pCurDVR->GetArrayLength();
+        ss<< ";\n";
+        ss <<"    if(gid0 >= buffer_len"<<j<<" || isNan(";
+        ss <<vSubArguments[j]->GenSlidingWindowDeclRef();
+        ss <<"))\n";
+        ss <<"        tmp = 0;\n    else\n";
+#endif
+        ss <<"        tmp = ";
+        ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
+        ss <<"    tmp"<<j<<" = tmp"<<j<<" || tmp;\n";
+        }
+        else if(tmpCur0->GetType() == formula::svDouble)
+        {
+            ss <<"        tmp = ";
+            ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
+            ss <<"    tmp"<<j<<" = tmp"<<j<<" || tmp;\n";
+        }
+        else if(tmpCur0->GetType() == formula::svDoubleVectorRef)
+        {
+            const formula::DoubleVectorRefToken*pCurDVR= dynamic_cast<const
+            formula::DoubleVectorRefToken *>(tmpCur0);
+            size_t nCurWindowSize = pCurDVR->GetArrayLength() <
+            pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
+            pCurDVR->GetRefRowSize() ;
+            ss << "    for(int i = ";
+            if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
+            ss << "gid0; i < " << nCurWindowSize << "; i++) {\n";
+            }
+            else if(pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()){
+            ss << "0; i < gid0 + " << nCurWindowSize << "; i++) {\n";
+            }
+            else{
+            ss << "0; i < " << nCurWindowSize << "; i++) {\n";
+            }
+#ifdef ISNAN
+            if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
+                {
+            ss <<"    if(isNan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
+            ss <<")||i+gid0>="<<pCurDVR->GetArrayLength();
+            ss <<")\n";
+            ss <<"        tmp = 0;\n    else\n";
+                }
+            else
+                {
+            ss <<"    if(isNan("<<vSubArguments[j]->GenSlidingWindowDeclRef();
+            ss <<")||i>="<<pCurDVR->GetArrayLength();
+            ss <<")\n";
+            ss <<"        tmp = 0;\n    else\n";
+                }
+#endif
+            ss <<"        tmp = ";
+            ss <<vSubArguments[j]->GenSlidingWindowDeclRef()<<";\n";
+            ss <<"    tmp"<<j<<" = tmp"<<j<<" || tmp;\n";
+            ss <<"    }\n";
+        }
+        ss <<"    t = t || tmp"<<j<<";\n";
+    }
+    ss << "    return t;\n";
+    ss << "}\n";
+}
 }}
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/opencl/op_logical.hxx b/sc/source/core/opencl/op_logical.hxx
index 3015830a5..40ab046 100644
--- a/sc/source/core/opencl/op_logical.hxx
+++ b/sc/source/core/opencl/op_logical.hxx
@@ -22,6 +22,15 @@ public:
             const std::string sSymName, SubArguments &vSubArguments);
     virtual std::string BinFuncName(void) const { return "And"; }
 };
+
+class OpOr: public Normal
+{
+public:
+    virtual void GenSlidingWindowFunction(std::stringstream &ss,
+            const std::string sSymName, SubArguments &vSubArguments);
+    virtual std::string BinFuncName(void) const { return "Or"; }
+};
+
 }}
 
 #endif
commit cefcac22d624e73d47d8d30d4b30b8a40e6c2648
Author: mulei <mulei at multicorewareinc.com>
Date:   Wed Dec 4 16:43:31 2013 +0800

    GPU Calc: Optimized NPV
    
    AMLOEXT-263
    
    Change-Id: Ifb2359a42329d48d14a26a2aeefae8e3b1122932
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index e84d632..016214e 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -2526,124 +2526,129 @@ void OpPMT::GenSlidingWindowFunction(std::stringstream &ss,
     ss << "return tmp;\n";
     ss << "}";
 }
- void OpNPV::GenSlidingWindowFunction(std::stringstream &ss,
-       const std::string sSymName, SubArguments &vSubArguments)
- {
-     ss << "\ndouble " << sSymName;
-     ss << "_"<< BinFuncName() <<"(";
-     for (unsigned i = 0; i < vSubArguments.size(); i++)
-     {
-         if (i)
-             ss << ", ";
-         vSubArguments[i]->GenSlidingWindowDecl(ss);
-     }
-     ss << ") {\n";
-     ss << "    double tmp = 0;\n";
-     ss << "    int gid0 = get_global_id(0);\n";
-     ss << "    int nCount = 1;\n";
-     size_t nItems = 0;
-     ss << "    double arg0=";
-     ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
-     ss <<";\n";
-     //while (i-- > 1)
-     for (size_t i = 1; i < vSubArguments.size(); i++)
-     {
-         FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
-         assert(pCur);
-         if (pCur->GetType() == formula::svDoubleVectorRef)
-         {
-             const formula::DoubleVectorRefToken* pDVR =
-             dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
-             size_t nCurWindowSize = pDVR->GetRefRowSize();
-             ss << "    for (int i = ";
-             if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
+void OpNPV::GenSlidingWindowFunction(std::stringstream &ss,
+    const std::string sSymName, SubArguments &vSubArguments)
+{
+    ss << "\ndouble " << sSymName;
+    ss << "_"<< BinFuncName() <<"(";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
+    {
+      if (i)
+          ss << ", ";
+      vSubArguments[i]->GenSlidingWindowDecl(ss);
+    }
+    ss << ") {\n";
+    ss << "    double tmp = 0.0;\n";
+    ss << "    int gid0 = get_global_id(0);\n";
+    ss << "    int nCount = 1;\n";
+    ss << "    double arg0=";
+    ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss <<";\n";
+    //while (i-- > 1)
+    for (size_t i = 1; i < vSubArguments.size(); i++)
+    {
+      FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
+      assert(pCur);
+      if (pCur->GetType() == formula::svDoubleVectorRef)
+      {
+            const formula::DoubleVectorRefToken* pDVR =
+            dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+            size_t nCurWindowSize = pDVR->GetRefRowSize();
+            ss << "    for (int i = ";
+            if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
 #ifdef  ISNAN
-                 ss << "gid0; i < " << pDVR->GetArrayLength();
-                 ss << " && i < " << nCurWindowSize  << "; i++){\n";
+                ss << "gid0; i < " << pDVR->GetArrayLength();
+                ss << " && i < " << nCurWindowSize  << "; i++){\n";
 #else
-                 ss << "gid0; i < "<< nCurWindowSize << "; i++)\n";
+                ss << "gid0; i < "<< nCurWindowSize << "; i++)\n";
 #endif
-             } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
+            } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
 #ifdef  ISNAN
-                 ss << "0; i < " << pDVR->GetArrayLength();
-                 ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
+                ss << "0; i < " << pDVR->GetArrayLength();
+                ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
 #else
-                 ss << "0; i < gid0+"<< nCurWindowSize << "; i++)\n";
+                ss << "0; i < gid0+"<< nCurWindowSize << "; i++)\n";
 #endif
-             } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
+            } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
 #ifdef  ISNAN
-                 ss << "0; i + gid0 < " << pDVR->GetArrayLength();
-                 ss << " &&  i < "<< nCurWindowSize << "; i++){\n";
+                ss << "0; i + gid0 < " << pDVR->GetArrayLength();
+                ss << " &&  i < "<< nCurWindowSize << "; i++){\n";
 #else
-                 ss << "0; i < "<< nCurWindowSize << "; i++)\n";
+                ss << "0; i < "<< nCurWindowSize << "; i++)\n";
 #endif
-             }
-             else {
+            }
+            else {
 #ifdef  ISNAN
-                 ss << "0; i < "<< nCurWindowSize << "; i++){\n";
+                ss << "0; i < "<< nCurWindowSize << "; i++){\n";
 #else
-                 ss << "0; i < "<< nCurWindowSize << "; i++)\n";
+                ss << "0; i < "<< nCurWindowSize << "; i++)\n";
 #endif
-             }
-             nItems += nCurWindowSize;
-         }
-         else if (pCur->GetType() == formula::svSingleVectorRef)
-         {
+            }
+        }
+        else if (pCur->GetType() == formula::svSingleVectorRef)
+        {
 #ifdef  ISNAN
-             const formula::SingleVectorRefToken* pSVR =
-               dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
-             ss << "    if (gid0 < " << pSVR->GetArrayLength() << "){\n";
+            const formula::SingleVectorRefToken* pSVR =
+            dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
+            ss << "    if (gid0 < " << pSVR->GetArrayLength() << "){\n";
 #else
-             nItems += 1;
 #endif
-         }
-         else if (pCur->GetType() == formula::svDouble)
-         {
+        }
+        else if (pCur->GetType() == formula::svDouble)
+        {
 #ifdef  ISNAN
-             ss << "{\n";
+            ss << "{\n";
 #endif
-             nItems += 1;
-         }
-         else
-         {
+        }
+        else
+        {
 #ifdef  ISNAN
-             ss << "nCount += 1;\n";
+            ss << "nCount += 1;\n";
 #endif
-             nItems += 1;
-         }
+        }
 #ifdef  ISNAN
-         if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
-         {
-             ss << "        if (isNan(";
-             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
-             ss << ")){\n";
-             ss << "            tmp += 0;}\n";
-             ss << "        else{\n";
-             ss << "            tmp +="<<vSubArguments[i]
-               ->GenSlidingWindowDeclRef();
-             ss <<" / pow(1.0f+ arg0 ,";
-             ss <<" (double)nCount );\n";
-             ss << "        nCount += 1;\n";
-             ss << "        }\n";
-             ss << "    }\n";
-         }
-         else
-         {
-             ss << "    tmp +="<<vSubArguments[i]->GenSlidingWindowDeclRef();
-             ss <<" / pow(1.0f+ arg0 ,";
-             ss <<" (double)nCount );\n";
-             ss << "        nCount += 1;\n";
-         }
+        if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
+        {
+            ss << "        double temp=";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << ";\n";
+            ss << "        double temp1=1.0;";
+            ss << "        if (isNan(temp)){\n";
+            ss << "            tmp += 0;}\n";
+            ss << "        else{\n";
+            ss << "            for(int i=1;i<nCount;i+=2)\n";
+            ss << "                temp1*=pow(1.0f+ arg0 ,2);\n";
+            ss << "            if(nCount%2)\n";
+            ss << "                temp1*=1.0f+ arg0;\n";
+            ss << "            tmp +=temp/ temp1;\n";
+            ss << "        nCount += 1;\n";
+            ss << "        }\n";
+            ss << "    }\n";
+        }
+        else
+        {
+            ss << "        double temp=";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << ";\n";
+            ss << "    double temp1=1.0;";
+            ss << "            for(int i=1;i<nCount;i+=2)";
+            ss << "                temp1*=pow(1.0f+ arg0 ,2);\n";
+            ss << "            if(nCount%2)";
+            ss << "                temp1*=1.0f+ arg0;\n";
+            ss << "            tmp +=temp/ temp1;\n";
+            ss << "        nCount += 1;\n";
+        }
 #else
-         ss << "tmp +="<<vSubArguments[i]->GenSlidingWindowDeclRef();
-         ss <<" / pow(1.0f+ arg0 ,";
-         ss <<" (double)nCount );\n";
-         ss << "        nCount += 1;\n";
-#endif
-     }
-     ss << "    return tmp;\n";
-     ss << "}";
- }
+            ss << "tmp +="<<vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss <<" / pow(1.0f+ arg0 ,";
+            ss <<" (double)nCount );\n";
+            ss << "        nCount += 1;\n";
+#endif
+    }
+        ss << "    return tmp;\n";
+        ss << "}";
+}
+
  void OpPrice::BinInlineFun(std::set<std::string>& decls,
      std::set<std::string>& funs)
  {
commit de9248a8453702ecb2add5acd1c3e747740235a2
Author: mingli <mingli at multicorewareinc.com>
Date:   Tue Dec 3 16:10:43 2013 +0800

    GPU Calc: Optimized FISHER
    
    AMLOEXT-261
    
    Change-Id: Ic96d701aa8bbe1e1fe15ca196556960b34fd64d3
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx
index bf115bd..b9aff2d 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -3382,11 +3382,9 @@ void OpSTEYX::GenSlidingWindowFunction(std::stringstream &ss,
     }
 }
 void OpFisher::GenSlidingWindowFunction(
-    std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
+    std::stringstream &ss, const std::string sSymName, SubArguments &
+vSubArguments)
 {
-    FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR=
-        dynamic_cast<const formula::SingleVectorRefToken *>(tmpCur);
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (unsigned i = 0; i < vSubArguments.size(); i++)
@@ -3395,21 +3393,51 @@ void OpFisher::GenSlidingWindowFunction(
             ss << ",";
         vSubArguments[i]->GenSlidingWindowDecl(ss);
     }
-    ss << ") {\n\t";
-    ss <<"int gid0=get_global_id(0);\n\t";
-    ss << "double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
-    ss << ";\n\t";
+    ss << ") {\n";
+    ss <<"    int gid0=get_global_id(0);\n";
+    ss <<"    double arg0;\n";
+    if(vSubArguments.size() != 1)
+    {
+        ss << "    return DBL_MAX;\n";
+        return ;
+    }
+    FormulaToken *pCur = vSubArguments[0]->GetFormulaToken();
+    assert(pCur);
+    if (pCur->GetType() == formula::svDoubleVectorRef)
+    {
+        ss << "    return DBL_MAX;\n";
+        return ;
+    }
+    else if (pCur->GetType() == formula::svSingleVectorRef)
+    {
+        const formula::SingleVectorRefToken* pSVR =
+                dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
+        ss << "    arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
+        ss << ";\n";
 #ifdef ISNAN
-    ss<< "if(isNan(arg0)||(gid0>=";
-    ss<<tmpCurDVR->GetArrayLength();
-    ss<<"))\n\t\t";
-    ss<<"arg0 = 0;\n\t";
+        ss<< "    if(isNan(arg0)||(gid0>=";
+        ss<<pSVR->GetArrayLength();
+        ss<<"))\n";
+        ss<<"        arg0 = 0;\n";
 #endif
-    ss << "double tmp=atanh(arg0);\n\t";
-    ss << "return tmp;\n";
+    }
+    else if (pCur->GetType() == formula::svDouble)
+    {
+        ss << "    arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
+        ss << ";\n";
+#ifdef ISNAN
+        ss << "    if(isNan(arg0))\n";
+        ss << "        return DBL_MAX;\n";
+#endif
+    }
+    ss << "    if (fabs(arg0) >= 1.0)\n";
+    ss << "        return DBL_MAX;\n";
+    ss << "    double tmp=0.5*log((1+arg0)*pow((1-arg0),-1));\n";
+    ss << "    return tmp;\n";
     ss << "}\n";
 }
 
+
 void OpFisherInv::GenSlidingWindowFunction(
     std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
 {
commit d8afb5537c471cfc9046e06e27026623efb51696
Author: zhenyu yuan <zhenyuyuan at multicorewareinc.com>
Date:   Tue Dec 3 15:43:25 2013 +0800

    GPU Calc: Optimized COMBINA
    
    AMLOEXT-259
    
    Change-Id: I8c5330a92ff0065bf9f51ea374b8aa686fdebc3c
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_math.cxx b/sc/source/core/opencl/op_math.cxx
index 60b0227..f54f22b 100644
--- a/sc/source/core/opencl/op_math.cxx
+++ b/sc/source/core/opencl/op_math.cxx
@@ -200,19 +200,19 @@ void OpCombina::GenSlidingWindowFunction(std::stringstream &ss,
     }
     ss << "    arg0 = trunc(arg0);\n";
     ss << "    arg1 = trunc(arg1);\n";
-    ss << "    if(arg0 < arg1 || arg0 < 0 || arg1 < 0)\n";
-    ss << "        tem = -1;\n";
+    ss << "    if(arg0 >= arg1 && arg0 > 0 && arg1 > 0)\n";
+    ss << "        tem = bik(arg0+arg1-1,arg1);\n"; 
     ss << "    else if(arg0 == 0 && arg1 == 0)\n";
     ss << "        tem = 0;\n";
     ss << "    else if(arg0 > 0 && arg1 == 0)\n";
     ss << "        tem = 1;\n";
     ss << "    else\n";
-    ss << "        tem = bik(arg0+arg1-1,arg1);\n";
-    ss << "    double k = tem - trunc(tem);\n";
-    ss << "    if(k < 0.5)\n";
+    ss << "        tem = -1;\n";
+    ss << "    double i = tem - trunc(tem);\n";
+    ss << "    if(i < 0.5)\n";
     ss << "        tem = trunc(tem);\n";
     ss << "    else\n";
-    ss << "        tem = trunc(tem) + 1;";
+    ss << "        tem = trunc(tem) + 1;\n";
     ss << "    return tem;\n";
     ss << "}";
 }
diff --git a/sc/source/core/opencl/opinlinefun_math.hxx b/sc/source/core/opencl/opinlinefun_math.hxx
index 44196b5..b641c52 100644
--- a/sc/source/core/opencl/opinlinefun_math.hxx
+++ b/sc/source/core/opencl/opinlinefun_math.hxx
@@ -25,16 +25,18 @@ std::string bikDecl = "double bik(double n,double k);\n";
 std::string bik =
 "double bik(double n,double k)\n"
 "{\n"
-"    double nVal = n/k;\n"
+"    double nVal1 = n;\n"
+"    double nVal2 = k;\n"
 "    n = n - 1;\n"
 "    k = k - 1;\n"
 "    while (k > 0)\n"
 "    {\n"
-"        nVal = nVal * ( n/k );\n"
+"        nVal1 = nVal1 * n;\n"
+"        nVal2 = nVal2 * k;\n"
 "        k = k - 1;\n"
 "        n = n - 1;\n"
 "    }\n"
-"    return nVal;\n"
+"    return (nVal1 / nVal2);\n"
 "}\n";
 
 std::string local_cothDecl = "double local_coth(double n);\n";
commit 4873228bc84a2f5cda401547ac72dec641020ad5
Author: mingli <mingli at multicorewareinc.com>
Date:   Tue Dec 3 14:01:49 2013 +0800

    GPU Calc: Optimized HARMEAN
    
    AMLOEXT-258
    
    Change-Id: I0673fe55aedbce3d7f6618b51ede155859f2f295
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx
index fc64e08..bf115bd 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -3926,9 +3926,9 @@ void OpGeoMean::GenSlidingWindowFunction(
     ss << "return tmp;\n";
     ss << "}";
 }
-
 void OpHarMean::GenSlidingWindowFunction(
-    std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
+    std::stringstream &ss, const std::string sSymName, SubArguments &
+vSubArguments)
 {
     FormulaToken *pCur = vSubArguments[0]->GetFormulaToken();
     assert(pCur);
@@ -3943,25 +3943,54 @@ void OpHarMean::GenSlidingWindowFunction(
             ss << ",";
         vSubArguments[i]->GenSlidingWindowDecl(ss);
     }
-    ss << ") {\n\t";
-    ss << "int gid0 = get_global_id(0);\n\t";
-    ss << "double nVal=0.0;\n\t";
-    ss << "int length="<<nCurWindowSize;
-    ss << ";\n\tdouble tmp = 0;\n\t";
-    ss << "for (int i = 0; i <" << nCurWindowSize << "; i++)\n\t";
-    ss << "{\n\t";
-    ss << "double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
-    ss << ";\n\t";
+    ss << ") {\n";
+    ss << "    int gid0 = get_global_id(0);\n";
+    ss << "    double nVal=0.0;\n";
+    ss << "    int length="<<nCurWindowSize<<";\n";
+    ss << "    double tmp = 0;\n";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
+    {
+        FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
+        assert(pCur);
+        if (pCur->GetType() == formula::svDoubleVectorRef)
+        {
+            const formula::DoubleVectorRefToken* pDVR =
+            dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+            size_t nCurWindowSize = pDVR->GetRefRowSize();
+            ss << "    for (int i = ";
+#ifdef  ISNAN
+            ss << "0; i < "<< nCurWindowSize << "; i++){\n";
+            ss << "        double arg"<<i<<" = ";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << ";\n";
 #ifdef ISNAN
-    ss<< "if(isNan(arg0)||((gid0+i)>=";
-    ss<<pCurDVR->GetArrayLength();
-    ss<<"))\n\t{";
-    ss<<"length--;\n\t";
-    ss<<"continue;\n\t}\n\t";
+            ss << "        if(isNan(arg"<<i<<")||((gid0+i)>=";
+            ss << pDVR->GetArrayLength();
+            ss << "))\n";
+            ss << "        {\n";
+            ss << "            length--;\n";
+            ss << "            continue;\n";
+            ss << "        }\n";
 #endif
-    ss << "nVal += (1.0/arg0);\n\t}\n\t";
-    ss<<"tmp = length/nVal;\n\t";
-    ss << "return tmp;\n";
+            ss << "        nVal += pow(arg"<<i<<",-1);\n";
+            ss << "    }\n";
+#endif
+        }
+        else if (pCur->GetType() == formula::svSingleVectorRef)
+        {
+#ifdef  ISNAN
+            ss << "return HUGE_VAL";
+#endif
+        }
+        else if (pCur->GetType() == formula::svDouble)
+        {
+#ifdef  ISNAN
+            ss << "return HUGE_VAL";
+#endif
+        }
+    }
+    ss << "    tmp = length/nVal;\n\t";
+    ss << "    return tmp;\n";
     ss << "}";
 }
 
commit 65a73c407e636186bd28a004635ea2a59e2ef578
Author: mingli <mingli at multicorewareinc.com>
Date:   Tue Dec 3 13:57:08 2013 +0800

    GPU Calc: Optimized NORMDIST
    
    AMLOEXT-257
    
    Change-Id: I7ae98538e410d9bf6544299eaf1c17f230ebda09
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx
index 36a0a17..fc64e08 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -5770,18 +5770,84 @@ void OpLogNormDist::GenSlidingWindowFunction(std::stringstream &ss,
     }
     ss << ") {\n";
     ss << "    int gid0=get_global_id(0);\n";
-    ss << "    double arg0 = ";
-    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-    ss << ";\n";
-    ss << "    double arg1 = ";
-    ss << vSubArguments[1]->GenSlidingWindowDeclRef();
-    ss << ";\n";
-    ss << "    double arg2 = ";
-    ss << vSubArguments[2]->GenSlidingWindowDeclRef();
-    ss << ";\n";
-    ss << "    double arg3 = ";
-    ss << vSubArguments[3]->GenSlidingWindowDeclRef();
-    ss << ";\n";
+    ss << "    double arg0,arg1,arg2,arg3;\n";
+    size_t i = vSubArguments.size();
+    size_t nItems = 0;
+    for (i = 0; i < vSubArguments.size(); i++)
+    {
+        FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
+        assert(pCur);
+        if (pCur->GetType() == formula::svDoubleVectorRef)
+        {
+            const formula::DoubleVectorRefToken* pDVR =
+            dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+            size_t nCurWindowSize = pDVR->GetRefRowSize();
+            ss << "for (int i = ";
+            if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
+#ifdef  ISNAN
+                ss << "gid0; i < " << pDVR->GetArrayLength();
+                ss << " && i < " << nCurWindowSize  << "; i++){\n";
+#else
+                ss << "gid0; i < "<< nCurWindowSize << "; i++)\n";
+#endif
+            } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
+#ifdef  ISNAN
+                ss << "0; i < " << pDVR->GetArrayLength();
+                ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
+#else
+                ss << "0; i < gid0+"<< nCurWindowSize << "; i++)\n ";
+#endif
+            } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
+#ifdef  ISNAN
+                ss << "0; i + gid0 < " << pDVR->GetArrayLength();
+                ss << " &&  i < "<< nCurWindowSize << "; i++){\n ";
+#else
+                ss << "0; i < "<< nCurWindowSize << "; i++)\n";
+#endif
+            }
+            else {
+#ifdef  ISNAN
+                ss << "0; i < "<< nCurWindowSize << "; i++){\n";
+#else
+                ss << "0; i < "<< nCurWindowSize << "; i++)\n";
+#endif
+            }
+            nItems += nCurWindowSize;
+        }
+        else if (pCur->GetType() == formula::svSingleVectorRef)
+        {
+#ifdef  ISNAN
+            const formula::SingleVectorRefToken* pSVR =
+                dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
+            ss << "    if (gid0 < " << pSVR->GetArrayLength() << ")\n";
+            ss << "    {\n";
+            ss << "        if (isNan(";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << "))\n";
+            ss << "            arg"<<i<<"= 0;\n";
+            ss << "        else\n";
+            ss << "            arg"<<i<<"=";
+            ss<<vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << ";\n";
+            ss << "    }\n";
+            ss << "    else\n";
+            ss << "        arg"<<i<<"= 0;\n";
+#endif
+        }
+        else if (pCur->GetType() == formula::svDouble)
+        {
+#ifdef  ISNAN
+            ss << "    if (isNan(";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << "))\n";
+            ss << "        arg"<<i<<"= 0;\n";
+            ss << "    else\n";
+            ss << "        arg"<<i<<"=";
+            ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << ";\n";
+#endif
+        }
+    }
     ss << "    double tmp;\n";
 #ifdef ISNAN
     ss << "    if(isNan(arg0)||(gid0>=";
@@ -5816,11 +5882,12 @@ void OpLogNormDist::GenSlidingWindowFunction(std::stringstream &ss,
     ss << "            tmp = 0.5 * erfc(-temp * 0.7071067811865475);\n";
     ss << "    }\n";
     ss << "    else\n";
-    ss << "        tmp = (0.39894228040143268 * exp(-(temp * temp)";
-    ss << " / 2.0))/arg2/arg0;\n";
+    ss << "        tmp = (0.39894228040143268 * exp((-1)*pow(temp, 2)";
+    ss << " / 2.0))/(arg2*arg0);\n";
     ss << "    return tmp;\n";
     ss << "}\n";
 }
+
 void OpGammaDist::BinInlineFun(std::set<std::string>& decls,
     std::set<std::string>& funs)
 {
commit 6c29963fd762143605d74394eb5eb865602ce793
Author: zhenyu yuan <zhenyuyuan at multicorewareinc.com>
Date:   Tue Dec 3 14:12:13 2013 +0800

    GPU Calc: Optimized COSH
    
    AMLOEXT-256
    
    Change-Id: I1e94b145943b88ba3c5cfd650577d8151d806550
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_math.cxx b/sc/source/core/opencl/op_math.cxx
index 70135b1..60b0227 100644
--- a/sc/source/core/opencl/op_math.cxx
+++ b/sc/source/core/opencl/op_math.cxx
@@ -52,6 +52,13 @@ void OpCos::GenSlidingWindowFunction(std::stringstream &ss,
     ss << "}";
 }
 
+void OpCosh::BinInlineFun(std::set<std::string>& decls,
+    std::set<std::string>& funs)
+{
+    decls.insert(local_coshDecl);
+    funs.insert(local_cosh);
+}
+
 void OpCosh::GenSlidingWindowFunction(std::stringstream &ss,
             const std::string sSymName, SubArguments &vSubArguments)
 {
@@ -76,7 +83,7 @@ void OpCosh::GenSlidingWindowFunction(std::stringstream &ss,
     ss<<"))\n";
     ss<<"        arg0 = 0;\n";
 #endif
-    ss << "    double tmp=cosh(arg0);\n";
+    ss << "    double tmp=local_cosh(arg0);\n";
     ss << "    return tmp;\n";
     ss << "}";
 }
diff --git a/sc/source/core/opencl/op_math.hxx b/sc/source/core/opencl/op_math.hxx
index 0239acb..c3b5e7a 100644
--- a/sc/source/core/opencl/op_math.hxx
+++ b/sc/source/core/opencl/op_math.hxx
@@ -46,7 +46,7 @@ class OpCosh: public Normal
 public:
     virtual void GenSlidingWindowFunction(std::stringstream &ss,
             const std::string sSymName, SubArguments &vSubArguments);
-
+    virtual void BinInlineFun(std::set<std::string>& ,std::set<std::string>& );
     virtual std::string BinFuncName(void) const { return "Cosh"; }
 };
 class OpSinh: public Normal
diff --git a/sc/source/core/opencl/opinlinefun_math.hxx b/sc/source/core/opencl/opinlinefun_math.hxx
index 0f943d9..44196b5 100644
--- a/sc/source/core/opencl/opinlinefun_math.hxx
+++ b/sc/source/core/opencl/opinlinefun_math.hxx
@@ -47,6 +47,15 @@ std::string local_coth =
 "    return nVal;\n"
 "}\n";
 
+std::string local_coshDecl = "double local_cosh(double n);\n";
+std::string local_cosh =
+"double local_cosh(double n)\n"
+"{\n"
+"    double nVal = (exp(n) + exp(-n)) / 2;\n"
+"    return nVal;\n"
+"}\n";
+
+
 #endif //SC_OPENCL_OPINLINFUN_MATH
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit fa42c60b2c6d1bd38f01c10851e173402a84e8f9
Author: mingli <mingli at multicorewareinc.com>
Date:   Tue Dec 3 13:42:45 2013 +0800

    GPU Calc: Optimized FORECAST
    
    AMLOEXT-255
    
    Change-Id: I17389d38de5db7962d657552afba22d604c3a862
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx
index 9ff1694..36a0a17 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -5654,84 +5654,96 @@ void OpForecast::GenSlidingWindowFunction(std::stringstream &ss,
     ss << "    double fSumY = 0.0;\n";
     ss << "    double fSumDeltaXDeltaY = 0.0;\n";
     ss << "    double fSumSqrDeltaX = 0.0;\n";
-    ss << "    double arg0 = ";
-    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-    ss << ";\n";
+    if(pCur0->GetType()== formula::svDouble ||
+        pCur0->GetType() == formula::svSingleVectorRef)
+    {
+        ss << "    double arg0 = ";
+        ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+        ss << ";\n";
+    }
+    else
+        ss << "return HUGE_VAL";
+    if(pCur1->GetType() != formula::svDoubleVectorRef ||
+        pCur2->GetType() != formula::svDoubleVectorRef)
+        ss << "return HUGE_VAL";
+    else
+    {
 #ifdef ISNAN
-    ss<< "    if(isNan(arg0)||(gid0>=";
-    ss<<pCurDVR0->GetArrayLength();
-    ss<<"))\n";
-    ss<<"        arg0 = 0;\n";
+        ss<< "    if(isNan(arg0)||(gid0>=";
+        ss<<pCurDVR0->GetArrayLength();
+        ss<<"))\n";
+        ss<<"        arg0 = 0;\n";
 #endif
-    ss << "    int length="<<nCurWindowSize;
-    ss << ";\n";
-    ss << "    int length1= "<<nCurWindowSize1;
-    ss << ";\n";
-    ss << "    if(length!=length1)\n";
-    ss << "        return 0;\n";
-    ss << "    double tmp = 0;\n";
-    ss << "    for (int i = 0; i <" << nCurWindowSize << "; i++)\n";
-    ss << "    {\n";
-    ss << "        double arg1 = ";
-    ss << vSubArguments[1]->GenSlidingWindowDeclRef();
-    ss << ";\n";
-    ss << "        double arg2 = ";
-    ss << vSubArguments[2]->GenSlidingWindowDeclRef();
-    ss << ";\n";
+        ss << "    int length="<<nCurWindowSize;
+        ss << ";\n";
+        ss << "    int length1= "<<nCurWindowSize1;
+        ss << ";\n";
+        ss << "    if(length!=length1)\n";
+        ss << "        return 0;\n";
+        ss << "    double tmp = 0;\n";
+        ss << "    for (int i = 0; i <" << nCurWindowSize << "; i++)\n";
+        ss << "    {\n";
+        ss << "        double arg1 = ";
+        ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+        ss << ";\n";
+        ss << "        double arg2 = ";
+        ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+        ss << ";\n";
 #ifdef ISNAN
-    ss << "        if(isNan(arg1)||((gid0+i)>=";
-    ss << pCurDVR1->GetArrayLength();
-    ss << "))\n";
-    ss << "        {\n";
-    ss << "            length--;\n";
-    ss << "            continue;\n";
-    ss << "        }\n";
+        ss << "        if(isNan(arg1)||((gid0+i)>=";
+        ss << pCurDVR1->GetArrayLength();
+        ss << "))\n";
+        ss << "        {\n";
+        ss << "            length--;\n";
+        ss << "            continue;\n";
+        ss << "        }\n";
 #endif
 #ifdef ISNAN
-    ss << "        if(isNan(arg2)||((gid0+i)>=";
-    ss << pCurDVR2->GetArrayLength();
-    ss << "))\n";
-    ss << "        {\n";
-    ss << "            length--;\n";
-    ss << "            continue;\n";
-    ss << "        }\n";
+        ss << "        if(isNan(arg2)||((gid0+i)>=";
+        ss << pCurDVR2->GetArrayLength();
+        ss << "))\n";
+        ss << "        {\n";
+        ss << "            length--;\n";
+        ss << "            continue;\n";
+        ss << "        }\n";
 #endif
-    ss << "        fSumY+=arg1;\n";
-    ss << "        fSumX+=arg2;\n";
-    ss << "    }\n";
-    ss << "    double fMeanX = fSumX / length;\n";
-    ss << "    double fMeanY = fSumY / length;\n";
-    ss << "    for (int i = 0; i <" << nCurWindowSize << "; i++)\n";
-    ss << "    {\n";
-    ss << "        double arg1 = ";
-    ss << vSubArguments[1]->GenSlidingWindowDeclRef();
-    ss << ";\n";
-    ss << "        double arg2 = ";
-    ss << vSubArguments[2]->GenSlidingWindowDeclRef();
-    ss << ";\n";
+        ss << "        fSumY+=arg1;\n";
+        ss << "        fSumX+=arg2;\n";
+        ss << "    }\n";
+        ss << "    double fMeanX = fSumX / length;\n";
+        ss << "    double fMeanY = fSumY / length;\n";
+        ss << "    for (int i = 0; i <" << nCurWindowSize << "; i++)\n";
+        ss << "    {\n";
+        ss << "        double arg1 = ";
+        ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+        ss << ";\n";
+        ss << "        double arg2 = ";
+        ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+        ss << ";\n";
 #ifdef ISNAN
-    ss << "        if(isNan(arg1)||((gid0+i)>=";
-    ss <<pCurDVR1->GetArrayLength();
-    ss <<"))\n";
-    ss <<"        {\n";
-    ss <<"            continue;\n";
-    ss <<"        }\n";
+        ss << "        if(isNan(arg1)||((gid0+i)>=";
+        ss <<pCurDVR1->GetArrayLength();
+        ss <<"))\n";
+        ss <<"        {\n";
+        ss <<"            continue;\n";
+        ss <<"        }\n";
 #endif
 #ifdef ISNAN
-    ss << "        if(isNan(arg2)||((gid0+i)>=";
-    ss <<pCurDVR2->GetArrayLength();
-    ss <<"))\n";
-    ss <<"        {\n";
-    ss <<"            continue;\n";
-    ss <<"        }\n";
-#endif
-    ss <<"        fSumDeltaXDeltaY+=(arg2 - fMeanX) * (arg1 - fMeanY);\n";
-    ss <<"        fSumSqrDeltaX+=(arg2 - fMeanX) * (arg2 - fMeanX);\n";
-    ss <<"    }\n";
-    ss <<"    tmp =fMeanY + fSumDeltaXDeltaY / fSumSqrDeltaX *";
-    ss <<" (arg0 - fMeanX);\n";
-    ss <<"    return tmp;\n";
-    ss << "}";
+        ss << "        if(isNan(arg2)||((gid0+i)>=";
+        ss <<pCurDVR2->GetArrayLength();
+        ss <<"))\n";
+        ss <<"        {\n";
+        ss <<"            continue;\n";
+        ss <<"        }\n";
+#endif
+        ss <<"        fSumDeltaXDeltaY+=(arg2 - fMeanX) * (arg1 - fMeanY);\n";
+        ss <<"        fSumSqrDeltaX+=pow(arg2 - fMeanX, 2);\n";
+        ss <<"    }\n";
+        ss <<"    tmp =fMeanY + fSumDeltaXDeltaY / fSumSqrDeltaX *";
+        ss <<" (arg0 - fMeanX);\n";
+        ss <<"    return tmp;\n";
+        ss << "}";
+    }
 }
 void OpLogNormDist::GenSlidingWindowFunction(std::stringstream &ss,
             const std::string sSymName, SubArguments &vSubArguments)
commit bfa7a9b87ae9fa7ddc3337edb976d08c4535e1e3
Author: mingli <mingli at multicorewareinc.com>
Date:   Tue Dec 3 11:18:23 2013 +0800

    GPU Calc: Optimized LOGINV
    
    AMLOEXT-254
    
    Change-Id: I2103d54f50eb0faa2cc4afab7b83cf4d0bd78aed
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx
index 891c92f..9ff1694 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -5370,15 +5370,6 @@ void OpIntercept::GenSlidingWindowFunction(std::stringstream &ss,
 void OpLogInv:: GenSlidingWindowFunction(std::stringstream &ss,
             const std::string sSymName, SubArguments &vSubArguments)
 {
-    FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
-          formula::SingleVectorRefToken *>(tmpCur0);
-    FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
-          formula::SingleVectorRefToken *>(tmpCur1);
-    FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
-    const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
-          formula::SingleVectorRefToken *>(tmpCur2);
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (unsigned i = 0; i < vSubArguments.size(); i++)
@@ -5389,39 +5380,90 @@ void OpLogInv:: GenSlidingWindowFunction(std::stringstream &ss,
     }
     ss << ") {\n";
     ss << "    int gid0=get_global_id(0);\n";
-    ss << "    double arg0 = ";
-    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-    ss << ";\n";
-    ss << "    double arg1 = ";
-    ss << vSubArguments[1]->GenSlidingWindowDeclRef();
-    ss << ";\n";
-    ss << "    double arg2 = ";
-    ss << vSubArguments[2]->GenSlidingWindowDeclRef();
-    ss << ";\n";
     ss << "    double tmp;\n";
-#ifdef ISNAN
-    ss<< "    if(isNan(arg0)||(gid0>=";
-    ss<<tmpCurDVR0->GetArrayLength();
-    ss<<"))\n";
-    ss<<"        arg0 = 0;\n";
+    ss << "    double arg0,arg1,arg2,arg3;\n";
+    size_t i = vSubArguments.size();
+    size_t nItems = 0;
+    for (i = 0; i < vSubArguments.size(); i++)
+    {
+        FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
+        assert(pCur);
+        if (pCur->GetType() == formula::svDoubleVectorRef)
+        {
+            const formula::DoubleVectorRefToken* pDVR =
+            dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+            size_t nCurWindowSize = pDVR->GetRefRowSize();
+            ss << "for (int i = ";
+            if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
+#ifdef  ISNAN
+                ss << "gid0; i < " << pDVR->GetArrayLength();
+                ss << " && i < " << nCurWindowSize  << "; i++){\n";
+#else
+                ss << "gid0; i < "<< nCurWindowSize << "; i++)\n";
 #endif
-#ifdef ISNAN
-    ss<< "    if(isNan(arg1)||(gid0>=";
-    ss<< tmpCurDVR1->GetArrayLength();
-    ss<< "))\n";
-    ss<< "        arg1 = 0;\n";
+            } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
+#ifdef  ISNAN
+                ss << "0; i < " << pDVR->GetArrayLength();
+                ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
+#else
+                ss << "0; i < gid0+"<< nCurWindowSize << "; i++)\n ";
 #endif
-#ifdef ISNAN
-    ss<< "    if(isNan(arg2)||(gid0>=";
-    ss<< tmpCurDVR2->GetArrayLength();
-    ss<< "))\n";
-    ss<< "        arg2 = 0;\n";
+            } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
+#ifdef  ISNAN
+                ss << "0; i + gid0 < " << pDVR->GetArrayLength();
+                ss << " &&  i < "<< nCurWindowSize << "; i++){\n ";
+#else
+                ss << "0; i < "<< nCurWindowSize << "; i++)\n";
 #endif
+            }
+            else {
+#ifdef  ISNAN
+                ss << "0; i < "<< nCurWindowSize << "; i++){\n";
+#else
+                ss << "0; i < "<< nCurWindowSize << "; i++)\n";
+#endif
+            }
+            nItems += nCurWindowSize;
+        }
+        else if (pCur->GetType() == formula::svSingleVectorRef)
+        {
+#ifdef  ISNAN
+            const formula::SingleVectorRefToken* pSVR =
+                dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
+            ss << "    if (gid0 < " << pSVR->GetArrayLength() << ")\n";
+            ss << "    {\n";
+            ss << "        if (isNan(";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << "))\n";
+            ss << "            arg"<<i<<"= 0;\n";
+            ss << "        else\n";
+            ss << "            arg"<<i<<"=";
+            ss<<vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << ";\n";
+            ss << "    }\n";
+            ss << "    else\n";
+            ss << "        arg"<<i<<"= 0;\n";
+#endif
+        }
+        else if (pCur->GetType() == formula::svDouble)
+        {
+#ifdef  ISNAN
+            ss << "    if (isNan(";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << "))\n";
+            ss << "        arg"<<i<<"= 0;\n";
+            ss << "    else\n";
+            ss << "        arg"<<i<<"=";
+            ss<<vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << ";\n";
+#endif
+        }
+    }
     ss<< "    double q,t,z;\n";
     ss<< "    q = arg0 -0.5;\n";
     ss<< "    if(fabs(q)<=.425)\n";
     ss<< "    {\n";
-    ss<< "        t=0.180625-q*q;\n";
+    ss<< "        t=0.180625-pow(q, 2);\n";
     ss<< "        z=\n"
     "        q*\n"
     "        (\n"
@@ -5472,10 +5514,7 @@ void OpLogInv:: GenSlidingWindowFunction(std::stringstream &ss,
     ss<<"    }\n";
     ss<<"    else\n";
     ss<<"    {\n";
-    ss<<"        if(q>0)\n";
-    ss<<"            t=1-arg0;\n";
-    ss<<"        else\n";
-    ss<<"            t=arg0;\n";
+    ss<<"        t = q > 0 ? 1 - arg0 : arg0;\n";
     ss<<"        t=sqrt(-log(t));\n";
     ss<<"        if(t<=5.0)\n";
     ss<<"        {\n";
@@ -5577,13 +5616,13 @@ void OpLogInv:: GenSlidingWindowFunction(std::stringstream &ss,
     "                *t+1.0\n"
     "            );\n";
     ss << "        }\n";
-    ss << "        if(q<0.0)\n";
-    ss << "            z=-z;\n";
+    ss << "        z = q < 0.0 ? (-1)*z : z;\n";
     ss << "    }\n";
     ss << "    tmp = exp(arg1+arg2*z);\n";
     ss << "    return tmp;\n";
     ss << "}\n";
 }
+
 void OpForecast::GenSlidingWindowFunction(std::stringstream &ss,
             const std::string sSymName, SubArguments &vSubArguments)
 {
commit d4ab0a4479441a60e6461021a3d0aec637e4ab07
Author: mingli <mingli at multicorewareinc.com>
Date:   Tue Dec 3 11:09:38 2013 +0800

    GPU Calc: Optimized INTERCEPT
    
    AMLOEXT-253
    
    Change-Id: If848c0dd4351188cd473f916648a71e448eca0a1
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx
index 62e73d0..891c92f 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -5282,6 +5282,27 @@ void OpIntercept::GenSlidingWindowFunction(std::stringstream &ss,
     ss << "    if(length!=length1)\n";
     ss << "        return 0;\n";
     ss << "    double tmp = 0;\n";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
+    {
+        FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
+        assert(pCur);
+        if (pCur->GetType() == formula::svDoubleVectorRef)
+        {
+
+        }
+        else if (pCur->GetType() == formula::svSingleVectorRef)
+        {
+#ifdef  ISNAN
+            ss << "return HUGE_VAL";
+#endif
+        }
+        else if (pCur->GetType() == formula::svDouble)
+        {
+#ifdef  ISNAN
+            ss << "return HUGE_VAL";
+#endif
+        }
+    }
     ss << "    for (int i = 0; i <" << nCurWindowSize << "; i++)\n";
     ss << "    {\n";
     ss << "        double arg0 = ";
@@ -5333,13 +5354,13 @@ void OpIntercept::GenSlidingWindowFunction(std::stringstream &ss,
     ss << "        if(isNan(arg1)||((gid0+i)>=";
     ss <<pCurDVR1->GetArrayLength();
     ss <<"))\n";
-    ss << "        {";
+    ss << "        {\n";
     ss << "            continue;\n";
     ss << "        }\n";
 #endif
     ss << "        fSumDeltaXDeltaY+=(arg1 - fMeanX) * (arg0 - fMeanY);";
     ss << ";\n";
-    ss << "        fSumSqrDeltaX+=(arg1 - fMeanX) * (arg1 - fMeanX);\n";
+    ss << "        fSumSqrDeltaX    += pow(arg1 - fMeanX, 2);\n";
     ss << "    }\n";
     ss << "    tmp = fMeanY - fSumDeltaXDeltaY / fSumSqrDeltaX";
     ss << "* fMeanX;\n";
commit 5dfc91da70e46ea56ca7ac929ef0b720914e6f41
Author: zhenyu yuan <zhenyuyuan at multicorewareinc.com>
Date:   Tue Dec 3 14:18:28 2013 +0800

    GPU Calc: Optimized COTH
    
    AMLOEXT-252
    
    Change-Id: If278a73af64a7ef074614b0d4dd44c07d965e823
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_math.cxx b/sc/source/core/opencl/op_math.cxx
index 9dc0270..70135b1 100644
--- a/sc/source/core/opencl/op_math.cxx
+++ b/sc/source/core/opencl/op_math.cxx
@@ -110,6 +110,13 @@ void OpCot::GenSlidingWindowFunction(std::stringstream &ss,
     ss << "}";
 }
 
+void OpCoth::BinInlineFun(std::set<std::string>& decls,
+    std::set<std::string>& funs)
+{
+    decls.insert(local_cothDecl);
+    funs.insert(local_coth);
+}
+
 void OpCoth::GenSlidingWindowFunction(std::stringstream &ss,
             const std::string sSymName, SubArguments &vSubArguments)
 {
@@ -134,7 +141,7 @@ void OpCoth::GenSlidingWindowFunction(std::stringstream &ss,
     ss<<"))\n";
     ss<<"        arg0 = 0;\n";
 #endif
-    ss << "    double tmp=1/tanh(arg0);\n";
+    ss << "    double tmp=local_coth(arg0);\n";
     ss << "    return tmp;\n";
     ss << "}";
 }
diff --git a/sc/source/core/opencl/op_math.hxx b/sc/source/core/opencl/op_math.hxx
index 7081b00..0239acb 100644
--- a/sc/source/core/opencl/op_math.hxx
+++ b/sc/source/core/opencl/op_math.hxx
@@ -235,7 +235,8 @@ class OpCoth: public Normal
 public:
     virtual void GenSlidingWindowFunction(std::stringstream &ss,
             const std::string sSymName, SubArguments &vSubArguments);
-
+    virtual void BinInlineFun(std::set<std::string>& ,
+            std::set<std::string>& );
     virtual std::string BinFuncName(void) const { return "Coth"; }
 };
 class OpPower: public Normal
diff --git a/sc/source/core/opencl/opinlinefun_math.hxx b/sc/source/core/opencl/opinlinefun_math.hxx
index e4927cc..0f943d9 100644
--- a/sc/source/core/opencl/opinlinefun_math.hxx
+++ b/sc/source/core/opencl/opinlinefun_math.hxx
@@ -37,6 +37,16 @@ std::string bik =
 "    return nVal;\n"
 "}\n";
 
+std::string local_cothDecl = "double local_coth(double n);\n";
+std::string local_coth =
+"double local_coth(double n)\n"
+"{\n"
+"    double a = exp(n);\n"
+"    double b = exp(-n);\n"
+"    double nVal = (a + b) / (a - b);\n"
+"    return nVal;\n"
+"}\n";
+
 #endif //SC_OPENCL_OPINLINFUN_MATH
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 54e7aedafc207105290762c2233aad737b552e98
Author: mulei <mulei at multicorewareinc.com>
Date:   Tue Dec 3 11:03:54 2013 +0800

    GPU Calc: Optimized NPER
    
    AMLOEXT-251
    
    Change-Id: Ifb4505158eccdab2ae95e4568c862ddfe8ec613c
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index 3d93721..e84d632 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -3203,44 +3203,7 @@ void OpNper::GenSlidingWindowFunction(std::stringstream &ss,
     {
         FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
         assert(pCur);
-        if (pCur->GetType() == formula::svDoubleVectorRef)
-        {
-            const formula::DoubleVectorRefToken* pDVR =
-            dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
-            size_t nCurWindowSize = pDVR->GetRefRowSize();
-            ss << "    for (int i = ";
-            if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
-#ifdef  ISNAN
-                ss << "gid0; i < " << pDVR->GetArrayLength();
-                ss << " && i < " << nCurWindowSize  << "; i++){\n";
-#else
-                ss << "gid0; i < "<< nCurWindowSize << "; i++)\n";
-#endif
-            } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
-#ifdef  ISNAN
-                ss << "0; i < " << pDVR->GetArrayLength();
-                ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
-#else
-                ss << "0; i < gid0+"<< nCurWindowSize << "; i++)\n";
-#endif
-            } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
-#ifdef  ISNAN
-                ss << "0; i + gid0 < " << pDVR->GetArrayLength();
-                ss << " &&  i < "<< nCurWindowSize << "; i++){\n";
-#else
-                ss << "0; i < "<< nCurWindowSize << "; i++)\n";
-#endif
-            }
-            else {
-#ifdef  ISNAN
-                ss << "0; i < "<< nCurWindowSize << "; i++){\n";
-#else
-                ss << "0; i < "<< nCurWindowSize << "; i++)\n";
-#endif
-            }
-            nItems += nCurWindowSize;
-        }
-        else if (pCur->GetType() == formula::svSingleVectorRef)
+        if (pCur->GetType() == formula::svSingleVectorRef)
         {
 #ifdef  ISNAN
             const formula::SingleVectorRefToken* pSVR =
@@ -3288,16 +3251,17 @@ void OpNper::GenSlidingWindowFunction(std::stringstream &ss,
 #endif
     }
     ss <<"    if (tmp0 == 0.0)\n";
-    ss <<"        tmp=(-(tmp2 + tmp3)/tmp1);\n";
+    ss <<"        tmp=(-1*(tmp2 + tmp3)/tmp1);\n";
     ss <<"    else if (tmp4 > 0.0)\n";
-    ss <<"        tmp=log(-(tmp0*tmp3-tmp1*(1.0+tmp0))/";
-    ss <<"(tmp0*tmp2+tmp1*(1.0+tmp0)))/log(1.0+tmp0);\n";
+    ss <<"        tmp=log(-1*(tmp0*tmp3-tmp1*(1.0+tmp0))*";
+    ss <<"pow((tmp0*tmp2+tmp1*(1.0+tmp0)),-1))/log(1.0+tmp0);\n";
     ss <<"    else\n";
-    ss <<"        tmp=log(-(tmp0*tmp3-tmp1)/(tmp0*tmp2+tmp1))";
+    ss <<"        tmp=log(-1*(tmp0*tmp3-tmp1)*pow(tmp0*tmp2+tmp1,-1))";
     ss <<"/log(1.0+tmp0);\n";
     ss <<"    return tmp;\n";
     ss <<"}";
  }
+
 void OpPPMT::BinInlineFun(std::set<std::string>& decls,
         std::set<std::string>& funs)
 {
commit ea85561eb725eebf44fa10046567c33de5984679
Author: zhenyu yuan <zhenyuyuan at multicorewareinc.com>
Date:   Tue Dec 3 10:44:48 2013 +0800

    GPU Calc: Optimized EVEN
    
    AMLOEXT-250
    
    Change-Id: Id2863ad9f4a3e2a03223b1dacd33c7d7557be63d
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: Wei Wei <weiwei at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_math.cxx b/sc/source/core/opencl/op_math.cxx
index 2d5ae39..9dc0270 100644
--- a/sc/source/core/opencl/op_math.cxx
+++ b/sc/source/core/opencl/op_math.cxx
@@ -227,22 +227,17 @@ void OpEven::GenSlidingWindowFunction(std::stringstream &ss,
     ss<<"        arg0 = 0;\n";
 #endif
     ss << "    double tmp;\n";
-    ss << "    arg0 = arg0 / 2;\n";
-    ss << "    if (arg0 < 0)\n";
-    ss << "        if (trunc(arg0) == arg0)\n";
-    ss << "            tmp = arg0 * 2;\n";
-    ss << "        else\n";
-    ss << "            tmp = (trunc(arg0) - 1) * 2;\n";
-    ss << "    else if (arg0 > 0)\n";
-    ss << "         if (trunc(arg0) == arg0)\n";
-    ss << "             tmp = arg0 * 2;\n";
-    ss << "         else\n";
-    ss << "             tmp = (trunc(arg0) + 1) * 2;\n";
+    ss << "    tmp = fabs(arg0 / 2);\n";
+    ss << "    if ( trunc(tmp) == tmp )\n";
+    ss << "        tmp = tmp * 2;\n";
     ss << "    else\n";
-    ss << "        tmp = 0;\n";
+    ss << "        tmp = (trunc(tmp) + 1) * 2;\n";
+    ss << "    if (arg0 < 0)\n";
+    ss << "        tmp = tmp * -1.0;\n";
     ss << "    return tmp;\n";
     ss << "}";
 }
+
 void OpMod::GenSlidingWindowFunction(std::stringstream &ss,
             const std::string sSymName, SubArguments &vSubArguments)
 {
commit 3ae85b912136993ccf157832f409416472026f17
Author: Wei Wei <weiwei at multicorewareinc.com>
Date:   Tue Dec 17 17:05:12 2013 -0600

    GPU Calc: optimize KURT
    
    Change-Id: Iab842ff0417a8e7da8c4b44ca525de8f1c2c8738
    
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx
index 589c704..62e73d0 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -5159,68 +5159,95 @@ void OpKurt:: GenSlidingWindowFunction(std::stringstream &ss,
         ss << ") {\n";
         ss << "    int gid0 = get_global_id(0);\n";
         ss << "    double fSum = 0.0;\n";
-        ss << "    double vSum = 0.0;\n";
+        ss<<  "    double xpower4 = 0.0;\n";
+        ss<<  "    double fMean =0.0;\n";
+        ss<<  "    double fStdDev = 0.0;\n";
         ss << "    int length="<<nCurWindowSize<<";\n";
         ss << "    double tmp = 0;\n";
-        ss << "    for (int i = 0; i <" << nCurWindowSize << "; i++)\n";
-        ss << "    {\n";
-        ss << "        double arg0 = ";
-        ss<< vSubArguments[0]->GenSlidingWindowDeclRef();
-        ss << ";\n";
+        for (unsigned i = 0; i < vSubArguments.size(); i++)
+        {
+            FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
+            assert(pCur);
+            if (pCur->GetType() == formula::svDoubleVectorRef)
+            {
+                const formula::DoubleVectorRefToken* pDVR =
+                dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+                size_t nCurWindowSize = pDVR->GetRefRowSize();
+                ss << "    for (int i = 0; i <" << nCurWindowSize;
+                ss << "; i++)\n";
+                ss << "    {\n";
+                ss << "        double arg0 = ";
+                ss<< vSubArguments[i]->GenSlidingWindowDeclRef();
+                ss << ";\n";
 #ifdef ISNAN
-        ss<< "        if(isNan(arg0)||((gid0+i)>=";
-        ss<<pCurDVR->GetArrayLength();
-        ss<< "))\n";
-        ss<< "        {\n";
-        ss<< "            length--;\n";
-        ss<< "            continue;\n";
-        ss<< "        }\n";
-#endif
-        ss<< "        fSum += arg0;\n";
-        ss<< "    }\n";
-        ss<< "    double fMean = fSum / length;\n";
-        ss<< "    for (int i = 0; i <" << nCurWindowSize << "; i++)\n";
-        ss<< "    {\n";
-        ss<< "        double arg0 = ";
-        ss<< vSubArguments[0]->GenSlidingWindowDeclRef();
-        ss<< ";\n";
+                ss<< "        if(isNan(arg0)||((gid0+i)>=";
+                ss<<pCurDVR->GetArrayLength();
+                ss<< "))\n";
+                ss<< "        {\n";
+                ss<< "            length--;\n";
+                ss<< "            continue;\n";
+                ss<< "        }\n";
+#endif
+                ss<< "        fSum += arg0;\n";
+                ss<< "    }\n";
+                ss<< "    fMean = fSum / length;\n";
+                ss<< "    fSum=0.0;\n";
+                ss<< "    for (int i = 0; i <" << nCurWindowSize << "; i++)\n";
+                ss<< "    {\n";
+                ss<< "        double arg0 = ";
+                ss<< vSubArguments[i]->GenSlidingWindowDeclRef();
+                ss<< ";\n";
 #ifdef ISNAN
-        ss<< "        if(isNan(arg0)||((gid0+i)>=";
-        ss<< pCurDVR->GetArrayLength();
-        ss<< "))\n";
-        ss<< "        {\n";
-        ss<< "            continue;\n";
-        ss<< "        }\n";
-#endif
-        ss<< "        vSum += (arg0 - fMean) * (arg0 - fMean);\n";
-        ss<< "    }\n";
-        ss<< "    double fStdDev = sqrt(vSum / (length - 1.0));\n";
-        ss<< "    double dx = 0.0;\n";
-        ss<< "    double xpower4 = 0.0;\n";
-        ss<< "    for (int i = 0; i <" << nCurWindowSize << "; i++)\n";
-        ss<< "    {\n";
-        ss<< "        double arg0 = ";
-        ss<< vSubArguments[0]->GenSlidingWindowDeclRef();
-        ss<< ";\n";
+                ss<< "        if(isNan(arg0)||((gid0+i)>=";
+                ss<< pCurDVR->GetArrayLength();
+                ss<< "))\n";
+                ss<< "        {\n";
+                ss<< "            continue;\n";
+                ss<< "        }\n";
+#endif
+                ss<< "        fSum += pow(arg0 - fMean, 2);\n";
+                ss<< "    }\n";
+                ss<< "    fStdDev = sqrt(fSum / (length - 1.0));\n";
+                ss<< "    fSum = 0.0;\n";
+                ss<< "    for (int i = 0; i <" << nCurWindowSize << "; i++)\n";
+                ss<< "    {\n";
+                ss<< "        double arg0 = ";
+                ss<< vSubArguments[i]->GenSlidingWindowDeclRef();
+                ss<< ";\n";
 #ifdef ISNAN
-        ss<< "        if(isNan(arg0)||((gid0+i)>=";
-        ss<< pCurDVR->GetArrayLength();
-        ss<< "))\n";
-        ss<< "        {\n";
-        ss<< "            continue;\n";
-        ss<< "        }\n";
-#endif
-        ss<< "        dx = (arg0 -fMean) / fStdDev;\n";
-        ss<< "        xpower4 = xpower4 + (dx * dx * dx * dx);\n";
-        ss<< "    }\n";
-        ss<< "    double k_d = (length - 2.0) * (length - 3.0);\n";

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list