[Libreoffice-commits] core.git: 19 commits - sc/qa sc/source

haochen haochen at multicorewareinc.com
Tue Dec 31 15:20:25 PST 2013


 sc/qa/unit/data/xls/opencl/financial/MDuration1.xls |binary
 sc/qa/unit/data/xls/opencl/math/averageif_mix.xls   |binary
 sc/qa/unit/data/xls/opencl/statistical/HarMean1.xls |binary
 sc/qa/unit/data/xls/opencl/statistical/Kurt1.xls    |binary
 sc/qa/unit/data/xls/opencl/statistical/StDevA1.xls  |binary
 sc/qa/unit/data/xls/opencl/statistical/StDevPA1.xls |binary
 sc/qa/unit/data/xls/opencl/statistical/VarA1.xls    |binary
 sc/qa/unit/data/xls/opencl/statistical/VarPA1.xls   |binary
 sc/qa/unit/opencl-test.cxx                          |  205 +++++++++++
 sc/source/core/opencl/formulagroupcl.cxx            |   10 
 sc/source/core/opencl/op_financial.cxx              |  150 +++-----
 sc/source/core/opencl/op_financial.hxx              |    2 
 sc/source/core/opencl/op_math.cxx                   |  163 +++++++-
 sc/source/core/opencl/op_math.hxx                   |    2 
 sc/source/core/opencl/op_spreadsheet.cxx            |   53 +-
 sc/source/core/opencl/op_statistical.cxx            |  368 ++++++++++++++------
 sc/source/core/opencl/opinlinefun_finacial.cxx      |   38 ++
 17 files changed, 744 insertions(+), 247 deletions(-)

New commits:
commit af31ebe82a294ff08bb6c3e46becb29830864f14
Author: haochen <haochen at multicorewareinc.com>
Date:   Tue Dec 31 16:36:53 2013 +0800

    GPU Calc: Remove unnecessary 'std::cerr'
    
    And add 'exception catching' for return  to CPU caculate
    
    Change-Id: I640894d677eaf73367bb51dec51c8baeb412bca6
    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 4ae6fef..38c91a9 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1930,7 +1930,8 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
                     mvSubArguments.push_back(
                             SubArgument(new DynamicKernelConstantArgument(ts,
                                     ft->Children[i])));
-                } else if (pChild->GetType() == formula::svString) {
+                } else if (pChild->GetType() == formula::svString
+                && pCodeGen->takeString()) {
                     mvSubArguments.push_back(
                             SubArgument(new ConstStringArgument(ts,
                                     ft->Children[i])));
@@ -3040,19 +3041,16 @@ void DynamicKernel::CreateKernel(void)
     std::string KernelHash = mKernelSignature+GetMD5();
     if (lastOneKernelHash == KernelHash && lastOneProgram)
     {
-        std::cerr<<"cl_program cache hit: "<< KernelHash << "\n";
         mpProgram = lastOneProgram;
     }
     else if(lastSecondKernelHash == KernelHash && lastSecondProgram)
     {
-        std::cerr<<"cl_program cache hit: "<< KernelHash << "\n";
         mpProgram = lastSecondProgram;
     }
     else
     {   // doesn't match the last compiled formula.
 
         if (lastSecondProgram) {
-            std::cerr<<"Freeing lastsecond program: "<< GetMD5() << "\n";
             clReleaseProgram(lastSecondProgram);
         }
         if (OpenclDevice::buildProgramFromBinary("",
@@ -3240,6 +3238,10 @@ DynamicKernel* DynamicKernel::create(ScDocument& /* rDoc */,
         return NULL;
 #endif
     }
+    catch (...) {
+        std::cerr << "Dynamic formula compiler: unhandled compiler error\n";
+        return NULL;
+    }
     return pDynamicKernel;
 }
 
diff --git a/sc/source/core/opencl/op_math.hxx b/sc/source/core/opencl/op_math.hxx
index 80b3a8e..29214bc 100644
--- a/sc/source/core/opencl/op_math.hxx
+++ b/sc/source/core/opencl/op_math.hxx
@@ -364,6 +364,8 @@ public:
     virtual void GenSlidingWindowFunction(std::stringstream &ss,
         const std::string sSymName, SubArguments &vSubArguments);
     virtual std::string BinFuncName(void) const { return "Convert"; }
+    virtual bool takeString() const { return true; }
+
 };
 class OpEven: public Normal
 {
commit 45211c27c464309f01c7a4bb56c73d829966c4b1
Author: xinjiang <xinjiang at multicorewareinc.com>
Date:   Tue Dec 31 15:08:49 2013 +0800

    GPU Calc: Fix accuracy not reach 11 in MDURATION
    
    AMLOEXT-223 FIX
    
    Change-Id: Ic7f35d85cc10f14487411633a54c43bbfafe688f
    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 e13b86c..2bd250e 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -761,13 +761,15 @@ void OpDuration_ADD::GenSlidingWindowFunction(std::stringstream& ss,
 void OpMDuration::BinInlineFun(std::set<std::string>& decls,
     std::set<std::string>& funs)
 {
-    decls.insert(GetDurationDecl);decls.insert(lcl_GetcoupnumDecl);
+    decls.insert(GetDuration_newDecl);decls.insert(lcl_Getcoupnum_newDecl);
+    decls.insert(addMonthsDecl);decls.insert(checklessthanDecl);
+    decls.insert(setDayDecl);decls.insert(ScaDateDecl);
     decls.insert(GetYearFracDecl);decls.insert(DaysToDateDecl);
-    decls.insert(GetNullDateDecl);decls.insert(DateToDaysDecl);
     decls.insert(DaysInMonthDecl);decls.insert(IsLeapYearDecl);
-    funs.insert(GetDuration);funs.insert(lcl_Getcoupnum);
+    funs.insert(GetDuration_new);funs.insert(lcl_Getcoupnum_new);
+    funs.insert(addMonths);funs.insert(checklessthan);
+    funs.insert(setDay);funs.insert(ScaDate);
     funs.insert(GetYearFrac);funs.insert(DaysToDate);
-    funs.insert(GetNullDate);funs.insert(DateToDays);
     funs.insert(DaysInMonth);funs.insert(IsLeapYear);
 }
 
@@ -791,31 +793,50 @@ void OpMDuration::GenSlidingWindowFunction(std::stringstream& ss,
     ss << "    double arg3 = " << GetBottom() << ";\n";
     ss << "    double arg4 = " << GetBottom() << ";\n";
     ss << "    double arg5 = " << GetBottom() << ";\n";
-    unsigned j = vSubArguments.size();
-    while (j--)
-        {
-        FormulaToken* pCur = vSubArguments[j]->GetFormulaToken();
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
+    {
+        FormulaToken* pCur = vSubArguments[i]->GetFormulaToken();
         assert(pCur);
-        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() << " || isNan(";
-            ss << vSubArguments[j]->GenSlidingWindowDeclRef();
-            ss << "))\n";
-            ss << "        arg" << j << " = " <<GetBottom() << ";\n";
-            ss << "    else\n";
+                dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
+            ss << "    if (gid0 < " << pSVR->GetArrayLength() << "){\n";
 #endif
-            ss << "        arg" << j << " = ";
-            ss << vSubArguments[j]->GenSlidingWindowDeclRef();
-            ss << ";\n";
-            }
         }
-    ss << "    int nNullDate = GetNullDate();\n";
-    ss << "    tmp = GetDuration( nNullDate, (int)arg0, (int)arg1, arg2,";
+        else if (pCur->GetType() == formula::svDouble)
+        {
+#ifdef  ISNAN
+            ss << "    {\n";
+#endif
+        }
+#ifdef  ISNAN
+        if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
+        {
+            ss << "        if (isNan(";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << "))\n";
+            ss << "            arg" << i << " = 0;\n";
+            ss << "        else\n";
+            ss << "            arg" << i << " = ";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
+            ss << "    }\n";
+        }
+        else
+        {
+            ss << "    arg" << i << " = ";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
+        }
+#else
+        ss << "    arg" << i;
+        ss << vSubArguments[i]->GenSlidingWindowDeclRef() << ";\n";
+#endif
+    }
+    ss << "    int nNullDate = 693594;\n";
+    ss << "    tmp = GetDuration_new( nNullDate, (int)arg0, (int)arg1, arg2,";
     ss << " arg3, (int)arg4, (int)arg5);\n";
-    ss << "    tmp /= 1.0 + arg3 / (int)arg4;\n";
+    ss << "    tmp = tmp * pow(1.0 + arg3 * pow((int)arg4, -1.0), -1);\n";
     ss << "    return tmp;\n";
     ss << "}";
 }
diff --git a/sc/source/core/opencl/opinlinefun_finacial.cxx b/sc/source/core/opencl/opinlinefun_finacial.cxx
index 91d04d2..154a9f5 100644
--- a/sc/source/core/opencl/opinlinefun_finacial.cxx
+++ b/sc/source/core/opencl/opinlinefun_finacial.cxx
@@ -1428,6 +1428,44 @@ std::string GetDuration=
 "    fDur /= nFreq;\n"
 "    return fDur;\n""}\n";
 
+std::string GetDuration_newDecl=
+"double GetDuration_new( \n"
+"                int nNullDate, int nSettle, int nMat, double fCoup,\n"
+"                double fYield, int nFreq, int nBase );\n";
+
+std::string GetDuration_new=
+"double GetDuration_new( \n"
+"                int nNullDate, int nSettle, int nMat, double fCoup,\n"
+"                double fYield, int nFreq, int nBase )\n"
+"    {\n"
+"        double fYearfrac = GetYearFrac(nNullDate,nSettle,nMat,nBase);\n"
+"        double fNumOfCoups = lcl_Getcoupnum_new(nNullDate,nSettle,nMat,"
+"nFreq,nBase);\n"
+"        double fDur = 0.0;\n"
+"        fCoup = fCoup * 100.0 * pow(nFreq, -1.0);\n"
+"        fYield = fYield * pow(nFreq, -1.0);\n"
+"        fYield += 1.0;\n"
+"        double nDiff = fYearfrac * nFreq - fNumOfCoups;\n"
+"        int  t;\n"
+"        double tmp0 = 0, tmp1 = 0, tmp2 = 0;\n"
+"        for( t = 1 ; t < fNumOfCoups ; t++ ){\n"
+"            tmp0 = (t + nDiff) * ( fCoup ) ;\n"
+"            tmp1 = pow( fYield, t + nDiff ) ;\n"
+"            tmp2 = tmp0 * pow(tmp1, -1);\n"
+"            fDur += tmp2;\n"
+"        }\n"
+"        fDur += (fNumOfCoups + nDiff) * (fCoup + 100.0) * pow(pow(fYield,"
+" fNumOfCoups + nDiff ),-1);\n"
+"        double  p = 0.0;\n"
+"        for( t = 1 ; t < fNumOfCoups ; t++ ){\n"
+"            tmp0 = pow( fYield, t + nDiff );\n"
+"            p += fCoup * pow(tmp0, -1);}\n"
+"        p += (fCoup + 100.0) * pow(pow(fYield, fNumOfCoups + nDiff), -1);\n"
+"        fDur = fDur * pow(p, -1.0);\n"
+"        fDur = fDur * pow(nFreq, -1.0);\n"
+"        return fDur;\n"
+"    }\n";
+
 std::string ScGetGDADecl=
 "double ScGetGDA(double fWert, double fRest, double fDauer, double fPeriode,"
 "double fFaktor);\n";
commit 5e8ec8912e6f9cb2eb7c3ae726f1f56515753dce
Author: xinjiang <xinjiang at multicorewareinc.com>
Date:   Tue Dec 31 15:04:24 2013 +0800

    GPU Calc: unit test cases for accuracy not reach 11 in MDURATION
    
    AMLOEXT-223 BUG
    
    Change-Id: Ib8349015152da6b641193b8558cb8a2959513631
    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/financial/MDuration1.xls b/sc/qa/unit/data/xls/opencl/financial/MDuration1.xls
new file mode 100644
index 0000000..c382aa8
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/financial/MDuration1.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 95eeb04..843c9a9 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -293,6 +293,7 @@ public:
     void testStatisticalFormulaVarPA1();
     void testStatisticalFormulaStDevA1();
     void testStatisticalFormulaStDevPA1();
+    void testFinancialMDurationFormula1();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -517,6 +518,7 @@ public:
     CPPUNIT_TEST(testStatisticalFormulaVarPA1);
     CPPUNIT_TEST(testStatisticalFormulaStDevA1);
     CPPUNIT_TEST(testStatisticalFormulaStDevPA1);
+    CPPUNIT_TEST(testFinancialMDurationFormula1);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -5162,6 +5164,28 @@ void ScOpenclTest::testStatisticalFormulaStDevPA()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
+//[AMLOEXT-223]
+void ScOpenclTest:: testFinancialMDurationFormula1()
+{
+    if (!detectOpenCLDevice())
+        return;
+    ScDocShellRef xDocSh = loadDoc("opencl/financial/MDuration1.", XLS);
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+    ScDocShellRef xDocShRes = loadDoc("opencl/financial/MDuration1.", XLS);
+    ScDocument* pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    for (SCROW i = 0; i <= 9; ++i)
+    {
+        double fLibre = pDoc->GetValue(ScAddress(6, i, 0));
+        double fExcel = pDocRes->GetValue(ScAddress(6, i, 0));
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel,fLibre,fabs(0.00000000001*fExcel));
+    }
+    xDocSh->DoClose();
+    xDocShRes->DoClose();
+}
 //[AMLOEXT-245]
 void ScOpenclTest::testMathFormulaSumProduct2()
 {
commit 1b519473cc7d3f897566e3f66f4930207d8eced4
Author: haochen <haochen at multicorewareinc.com>
Date:   Tue Dec 31 14:25:40 2013 +0800

    GPU Calc: Optimize Vlookup
    
    AMLOEXT-406
    
    Change-Id: Ibd1ad4e93ccfa1bb3a64545f4f007e4116691791
    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_spreadsheet.cxx b/sc/source/core/opencl/op_spreadsheet.cxx
index 9d3db14..abb7568 100644
--- a/sc/source/core/opencl/op_spreadsheet.cxx
+++ b/sc/source/core/opencl/op_spreadsheet.cxx
@@ -73,9 +73,8 @@ void OpVLookup::GenSlidingWindowFunction(std::stringstream &ss,
         size_t nCurWindowSize = pCurDVR->GetArrayLength() <
         pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
         pCurDVR->GetRefRowSize() ;
-        int unrollSize = 16;
+        int unrollSize = 8;
         ss << "    int loop;\n";
-        ss << "    int remainder;\n";
         if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
             ss << "    loop = ("<<nCurWindowSize<<" - gid0)/";
             ss << unrollSize<<";\n";
@@ -126,7 +125,6 @@ void OpVLookup::GenSlidingWindowFunction(std::stringstream &ss,
                 ss << 1+i;
                 ss << ";\n";
                 ss << "            }\n";
-
                 ss << "            i++;\n";
                 ss << "            doubleIndex++;\n";
             }
@@ -143,13 +141,29 @@ void OpVLookup::GenSlidingWindowFunction(std::stringstream &ss,
                 ss << "            {\n";
                 ss << "                rowNum = doubleIndex;\n";
                 ss << "            }\n";
-
                 ss << "            i++;\n";
                 ss << "            doubleIndex++;\n";
             }
             ss << "        }\n\n";
 
             ss << "    }\n";
+            ss << "    if(rowNum!=-1)\n";
+            ss << "    {\n";
+            for(int j=0;j< secondParaWidth; j++)
+            {
+
+                ss << "        if(tmp";
+                ss << 2+(secondParaWidth-1);
+                ss << " == ";
+                ss << j+1;
+                ss << ")\n";
+                ss << "            tmp = ";
+                vSubArguments[1+j]->GenDeclRef(ss);
+                ss << "[rowNum];\n";
+
+            }
+            ss << "    return tmp;\n";
+            ss << "    }\n";
             ss << "    for (int i = ";
             if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
                ss << "gid0 + loop *"<<unrollSize<<"; i < ";
@@ -196,25 +210,27 @@ void OpVLookup::GenSlidingWindowFunction(std::stringstream &ss,
             ss << "        }\n";
 
             ss << "    }\n\n";
+            ss << "    if(rowNum!=-1)\n";
+            ss << "    {\n";
 
-        }
+            for(int j=0;j< secondParaWidth; j++)
+            {
 
-        ss << "    if(rowNum!=-1)\n";
-        ss << "    {\n";
+                ss << "        if(tmp";
+                ss << 2+(secondParaWidth-1);
+                ss << " == ";
+                ss << j+1;
+                ss << ")\n";
+                ss << "            tmp = ";
+                vSubArguments[1+j]->GenDeclRef(ss);
+                ss << "[rowNum];\n";
 
-        for(int j=0;j< secondParaWidth; j++)
-        {
+            }
+            ss << "    return tmp;\n";
+            ss << "    }\n";
 
-            ss << "        if(tmp";
-            ss << 2+(secondParaWidth-1);
-            ss << " == ";
-            ss << j+1;
-            ss << ")\n";
-            ss << "            tmp = ";
-            vSubArguments[1+j]->GenDeclRef(ss);
-            ss << "[rowNum];\n";
         }
-        ss << "    }\n";
+
     }
     else
     {
@@ -228,7 +244,6 @@ void OpVLookup::GenSlidingWindowFunction(std::stringstream &ss,
         ss << "            tmp = tmp1;\n";
         ss << "    }\n";
     }
-
     ss << "    return tmp;\n";
     ss << "}";
 }
commit 85c401704e49f3fd8ee2f4a1f4baa8832a04a1ba
Author: shiming zhang <shiming at multicorewareinc.com>
Date:   Tue Dec 31 14:20:06 2013 +0800

    GPU Calc: Fix bug of support optional parameter for STDEVPA
    
    AMLOEXT-405 FIX
    
    Change-Id: I7057104900140197a8e018710de863415920827d
    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 f26d7ba..673ed21 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -11084,6 +11084,7 @@ void OpStDevPA::GenSlidingWindowFunction(std::stringstream &ss,
             {
                 const formula::DoubleVectorRefToken* pDVR =
                     dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+                assert(pDVR);
                 if(pDVR->GetArrays()[0].mpNumericArray
                     && pDVR->GetArrays()[0].mpStringArray)
                     isMixedDV = svDoubleVectorRefDoubleString;
@@ -11296,6 +11297,17 @@ void OpStDevPA::GenSlidingWindowFunction(std::stringstream &ss,
             {
                 const formula::DoubleVectorRefToken* pDVR =
                     dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+                assert(pDVR);
+                if(pDVR->GetArrays()[0].mpNumericArray
+                    && pDVR->GetArrays()[0].mpStringArray)
+                    isMixedDV = svDoubleVectorRefDoubleString;
+                else if(pDVR->GetArrays()[0].mpNumericArray)
+                    isMixedDV = svDoubleVectorRefDouble;
+                else if(pDVR->GetArrays()[0].mpStringArray)
+                    isMixedDV = svDoubleVectorRefString;
+                else
+                    isMixedDV = svDoubleVectorRefNULL;
+
                 size_t nCurWindowSize = pDVR->GetRefRowSize();
                 ss << "    for (int i = ";
                 if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
@@ -11394,6 +11406,16 @@ void OpStDevPA::GenSlidingWindowFunction(std::stringstream &ss,
                 const formula::SingleVectorRefToken* pSVR =
                     dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
                 assert(pSVR);
+                if(pSVR->GetArray().mpNumericArray
+                    && pSVR->GetArray().mpStringArray)
+                    isMixedSV = svSingleVectorRefDoubleString;
+                else if(pSVR->GetArray().mpNumericArray)
+                    isMixedSV = svSingleVectorRefDouble;
+                else if(pSVR->GetArray().mpStringArray)
+                    isMixedSV = svSingleVectorRefString;
+                else
+                    isMixedSV = svSingleVectorRefNULL;
+
                 if(isMixedSV == svSingleVectorRefDoubleString)
                 {
 #ifdef  ISNAN
@@ -11473,6 +11495,7 @@ void OpStDevPA::GenSlidingWindowFunction(std::stringstream &ss,
     ss << "        return sqrt(vSum * pow(fCount,-1.0));\n";
     ss << "}\n";
 }
+
 void OpAveDev:: GenSlidingWindowFunction(std::stringstream &ss,
             const std::string sSymName, SubArguments &vSubArguments)
 {
commit 6da394c12599cd4cfafa3a2a932a932bf0388a7e
Author: shiming zhang <shiming at multicorewareinc.com>
Date:   Tue Dec 31 14:07:16 2013 +0800

    GPU Calc: unit test cases for support optional parameter for STDEVPA
    
    AMLOEXT-405 BUG
    
    Change-Id: I65cf098eefbffd5c1c838a2f4d91ba3472caf50c
    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/statistical/StDevPA1.xls b/sc/qa/unit/data/xls/opencl/statistical/StDevPA1.xls
new file mode 100644
index 0000000..e9c9957
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/statistical/StDevPA1.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index eafa228..95eeb04 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -292,6 +292,7 @@ public:
     void testStatisticalFormulaVarA1();
     void testStatisticalFormulaVarPA1();
     void testStatisticalFormulaStDevA1();
+    void testStatisticalFormulaStDevPA1();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -515,6 +516,7 @@ public:
     CPPUNIT_TEST(testStatisticalFormulaVarA1);
     CPPUNIT_TEST(testStatisticalFormulaVarPA1);
     CPPUNIT_TEST(testStatisticalFormulaStDevA1);
+    CPPUNIT_TEST(testStatisticalFormulaStDevPA1);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -6100,6 +6102,31 @@ void ScOpenclTest::testStatisticalFormulaStDevA1()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
+//[AMLOEXT-405]
+void ScOpenclTest::testStatisticalFormulaStDevPA1()
+{
+    if (!detectOpenCLDevice())
+        return;
+
+    ScDocShellRef xDocSh = loadDoc("opencl/statistical/StDevPA1.", XLS);
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+
+    ScDocShellRef xDocShRes = loadDoc("opencl/statistical/StDevPA1.", XLS);
+    ScDocument* pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    // Check the results of formula cells in the shared formula range.
+    for (SCROW i = 1; i <= 20; ++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" )
 {
commit 2203cc63c494a9330cb4e078797b44310a684148
Author: shiming zhang <shiming at multicorewareinc.com>
Date:   Tue Dec 31 14:01:08 2013 +0800

    GPU Calc: Fix bug of support optional parameter for STDEVA
    
    AMLOEXT-404 FIX
    
    Change-Id: Idb3dae8907b753c8680de8673621102128e43ef0
    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 ba1e20a..f26d7ba 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -10640,6 +10640,7 @@ void OpStDevA::GenSlidingWindowFunction(std::stringstream &ss,
             {
                 const formula::DoubleVectorRefToken* pDVR =
                     dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+                assert(pDVR);
                 if(pDVR->GetArrays()[0].mpNumericArray
                     && pDVR->GetArrays()[0].mpStringArray)
                     isMixedDV = svDoubleVectorRefDoubleString;
@@ -10852,6 +10853,17 @@ void OpStDevA::GenSlidingWindowFunction(std::stringstream &ss,
             {
                 const formula::DoubleVectorRefToken* pDVR =
                     dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+                assert(pDVR);
+                if(pDVR->GetArrays()[0].mpNumericArray
+                    && pDVR->GetArrays()[0].mpStringArray)
+                    isMixedDV = svDoubleVectorRefDoubleString;
+                else if(pDVR->GetArrays()[0].mpNumericArray)
+                    isMixedDV = svDoubleVectorRefDouble;
+                else if(pDVR->GetArrays()[0].mpStringArray)
+                    isMixedDV = svDoubleVectorRefString;
+                else
+                    isMixedDV = svDoubleVectorRefNULL;
+
                 size_t nCurWindowSize = pDVR->GetRefRowSize();
                 ss << "    for (int i = ";
                 if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
@@ -10950,6 +10962,16 @@ void OpStDevA::GenSlidingWindowFunction(std::stringstream &ss,
                 const formula::SingleVectorRefToken* pSVR =
                     dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
                 assert(pSVR);
+                if(pSVR->GetArray().mpNumericArray
+                    && pSVR->GetArray().mpStringArray)
+                    isMixedSV = svSingleVectorRefDoubleString;
+                else if(pSVR->GetArray().mpNumericArray)
+                    isMixedSV = svSingleVectorRefDouble;
+                else if(pSVR->GetArray().mpStringArray)
+                    isMixedSV = svSingleVectorRefString;
+                else
+                    isMixedSV = svSingleVectorRefNULL;
+
                 if(isMixedSV == svSingleVectorRefDoubleString)
                 {
 #ifdef  ISNAN
@@ -11029,6 +11051,7 @@ void OpStDevA::GenSlidingWindowFunction(std::stringstream &ss,
     ss << "        return sqrt(vSum * pow(fCount - 1.0,-1.0));\n";
     ss << "}\n";
 }
+
 void OpStDevPA::GenSlidingWindowFunction(std::stringstream &ss,
             const std::string sSymName, SubArguments &vSubArguments)
 {
commit 93c0e1dfc64ffbf155cdc8fbd235d628444967b0
Author: shiming zhang <shiming at multicorewareinc.com>
Date:   Tue Dec 31 14:00:28 2013 +0800

    GPU Calc: unit test cases for support optional parameter for STDEVA
    
    AMLOEXT-404 BUG
    
    Change-Id: I7dfbbecee5f178a42b28d9df0f4f205fa694d152
    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/statistical/StDevA1.xls b/sc/qa/unit/data/xls/opencl/statistical/StDevA1.xls
new file mode 100644
index 0000000..e17e90d
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/statistical/StDevA1.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 8e14c27..eafa228 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -291,6 +291,7 @@ public:
     void testStatisticalFormulaHarMean1();
     void testStatisticalFormulaVarA1();
     void testStatisticalFormulaVarPA1();
+    void testStatisticalFormulaStDevA1();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -513,6 +514,7 @@ public:
     CPPUNIT_TEST(testStatisticalFormulaHarMean1);
     CPPUNIT_TEST(testStatisticalFormulaVarA1);
     CPPUNIT_TEST(testStatisticalFormulaVarPA1);
+    CPPUNIT_TEST(testStatisticalFormulaStDevA1);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -6073,6 +6075,31 @@ void ScOpenclTest::testStatisticalFormulaVarPA1()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
+//[AMLOEXT-404]
+void ScOpenclTest::testStatisticalFormulaStDevA1()
+{
+    if (!detectOpenCLDevice())
+        return;
+
+    ScDocShellRef xDocSh = loadDoc("opencl/statistical/StDevA1.", XLS);
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+
+    ScDocShellRef xDocShRes = loadDoc("opencl/statistical/StDevA1.", XLS);
+    ScDocument* pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    // Check the results of formula cells in the shared formula range.
+    for (SCROW i = 1; i <= 20; ++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" )
 {
commit 77373d6eabcc73312e76aa7507092b63e4770959
Author: shiming zhang <shiming at multicorewareinc.com>
Date:   Tue Dec 31 13:36:50 2013 +0800

    GPU Calc: Fix bug of support optional parameter for VARPA
    
    AMLOEXT-403 FIX
    
    Change-Id: I21e0cd502abfa081885327316bd42e3c1702c494
    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 864146c..ba1e20a 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -10197,6 +10197,7 @@ void OpVarPA::GenSlidingWindowFunction(std::stringstream &ss,
             {
                 const formula::DoubleVectorRefToken* pDVR =
                     dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+                assert(pDVR);
                 if(pDVR->GetArrays()[0].mpNumericArray
                     && pDVR->GetArrays()[0].mpStringArray)
                     isMixedDV = svDoubleVectorRefDoubleString;
@@ -10409,6 +10410,17 @@ void OpVarPA::GenSlidingWindowFunction(std::stringstream &ss,
             {
                 const formula::DoubleVectorRefToken* pDVR =
                     dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+                assert(pDVR);
+                if(pDVR->GetArrays()[0].mpNumericArray
+                    && pDVR->GetArrays()[0].mpStringArray)
+                    isMixedDV = svDoubleVectorRefDoubleString;
+                else if(pDVR->GetArrays()[0].mpNumericArray)
+                    isMixedDV = svDoubleVectorRefDouble;
+                else if(pDVR->GetArrays()[0].mpStringArray)
+                    isMixedDV = svDoubleVectorRefString;
+                else
+                    isMixedDV = svDoubleVectorRefNULL;
+
                 size_t nCurWindowSize = pDVR->GetRefRowSize();
                 ss << "    for (int i = ";
                 if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
@@ -10507,6 +10519,16 @@ void OpVarPA::GenSlidingWindowFunction(std::stringstream &ss,
                 const formula::SingleVectorRefToken* pSVR =
                     dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
                 assert(pSVR);
+                if(pSVR->GetArray().mpNumericArray
+                    && pSVR->GetArray().mpStringArray)
+                    isMixedSV = svSingleVectorRefDoubleString;
+                else if(pSVR->GetArray().mpNumericArray)
+                    isMixedSV = svSingleVectorRefDouble;
+                else if(pSVR->GetArray().mpStringArray)
+                    isMixedSV = svSingleVectorRefString;
+                else
+                    isMixedSV = svSingleVectorRefNULL;
+
                 if(isMixedSV == svSingleVectorRefDoubleString)
                 {
 #ifdef  ISNAN
commit 94f80ccf67075008af44ed39a3539c526768aad7
Author: shiming zhang <shiming at multicorewareinc.com>
Date:   Tue Dec 31 13:24:24 2013 +0800

    GPU Calc: unit test cases for support optional parameter for VARPA
    
    AMLOEXT-403 BUG
    
    Change-Id: Ie48f1e6a6abb6dae95477902a5211729dd91ee5e
    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/statistical/VarPA1.xls b/sc/qa/unit/data/xls/opencl/statistical/VarPA1.xls
new file mode 100644
index 0000000..dc09093
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/statistical/VarPA1.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 9a83989..8e14c27 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -290,6 +290,7 @@ public:
     void testStatisticalFormulaKurt1();
     void testStatisticalFormulaHarMean1();
     void testStatisticalFormulaVarA1();
+    void testStatisticalFormulaVarPA1();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -511,6 +512,7 @@ public:
     CPPUNIT_TEST(testStatisticalFormulaKurt1);
     CPPUNIT_TEST(testStatisticalFormulaHarMean1);
     CPPUNIT_TEST(testStatisticalFormulaVarA1);
+    CPPUNIT_TEST(testStatisticalFormulaVarPA1);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -6046,7 +6048,31 @@ void ScOpenclTest::testStatisticalFormulaVarA1()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
+//[AMLOEXT-403]
+void ScOpenclTest::testStatisticalFormulaVarPA1()
+{
+    if (!detectOpenCLDevice())
+        return;
+
+    ScDocShellRef xDocSh = loadDoc("opencl/statistical/VarPA1.", XLS);
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
 
+    ScDocShellRef xDocShRes = loadDoc("opencl/statistical/VarPA1.", XLS);
+    ScDocument* pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    // Check the results of formula cells in the shared formula range.
+    for (SCROW i = 1; i <= 20; ++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" )
 {
commit 7c0f22ffd20417abde916ad08468b8230f349e8b
Author: shiming zhang <shiming at multicorewareinc.com>
Date:   Tue Dec 31 13:09:33 2013 +0800

    GPU Calc: Fix bug of support optional parameter for VARA
    
    AMLOEXT-402 FIX
    
    Change-Id: I61b051324bb1421aafb048d3b76b50e182734076
    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 54ec99c..864146c 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -9753,6 +9753,7 @@ void OpVarA::GenSlidingWindowFunction(std::stringstream &ss,
             {
                 const formula::DoubleVectorRefToken* pDVR =
                     dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+                assert(pDVR);
                 if(pDVR->GetArrays()[0].mpNumericArray
                     && pDVR->GetArrays()[0].mpStringArray)
                     isMixedDV = svDoubleVectorRefDoubleString;
@@ -9965,6 +9966,17 @@ void OpVarA::GenSlidingWindowFunction(std::stringstream &ss,
             {
                 const formula::DoubleVectorRefToken* pDVR =
                     dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+                assert(pDVR);
+                if(pDVR->GetArrays()[0].mpNumericArray
+                    && pDVR->GetArrays()[0].mpStringArray)
+                    isMixedDV = svDoubleVectorRefDoubleString;
+                else if(pDVR->GetArrays()[0].mpNumericArray)
+                    isMixedDV = svDoubleVectorRefDouble;
+                else if(pDVR->GetArrays()[0].mpStringArray)
+                    isMixedDV = svDoubleVectorRefString;
+                else
+                    isMixedDV = svDoubleVectorRefNULL;
+
                 size_t nCurWindowSize = pDVR->GetRefRowSize();
                 ss << "    for (int i = ";
                 if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
@@ -10063,6 +10075,16 @@ void OpVarA::GenSlidingWindowFunction(std::stringstream &ss,
                 const formula::SingleVectorRefToken* pSVR =
                     dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
                 assert(pSVR);
+                if(pSVR->GetArray().mpNumericArray
+                    && pSVR->GetArray().mpStringArray)
+                    isMixedSV = svSingleVectorRefDoubleString;
+                else if(pSVR->GetArray().mpNumericArray)
+                    isMixedSV = svSingleVectorRefDouble;
+                else if(pSVR->GetArray().mpStringArray)
+                    isMixedSV = svSingleVectorRefString;
+                else
+                    isMixedSV = svSingleVectorRefNULL;
+
                 if(isMixedSV == svSingleVectorRefDoubleString)
                 {
 #ifdef  ISNAN
@@ -10142,6 +10164,7 @@ void OpVarA::GenSlidingWindowFunction(std::stringstream &ss,
     ss << "        return vSum * pow(fCount - 1.0,-1.0);\n";
     ss << "}\n";
 }
+
 void OpVarPA::GenSlidingWindowFunction(std::stringstream &ss,
             const std::string sSymName, SubArguments &vSubArguments)
 {
commit 28759cea9eecd2be14028ebbd76d48031070e663
Author: shiming zhang <shiming at multicorewareinc.com>
Date:   Tue Dec 31 13:00:43 2013 +0800

    GPU Calc: unit test cases for support optional parameter for VARA
    
    AMLOEXT-402 BUG
    
    Change-Id: If6f4064d3e706957cc1db0c668f42675642455c3
    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/statistical/VarA1.xls b/sc/qa/unit/data/xls/opencl/statistical/VarA1.xls
new file mode 100644
index 0000000..4aa4082
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/statistical/VarA1.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 98e8917..9a83989 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -289,6 +289,7 @@ public:
     void testMathFormulaAverageIf_Mix();
     void testStatisticalFormulaKurt1();
     void testStatisticalFormulaHarMean1();
+    void testStatisticalFormulaVarA1();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -509,6 +510,7 @@ public:
     CPPUNIT_TEST(testMathFormulaAverageIf_Mix);
     CPPUNIT_TEST(testStatisticalFormulaKurt1);
     CPPUNIT_TEST(testStatisticalFormulaHarMean1);
+    CPPUNIT_TEST(testStatisticalFormulaVarA1);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -6019,6 +6021,32 @@ void ScOpenclTest::testStatisticalFormulaHarMean1()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
+//[AMLOEXT-402]
+void ScOpenclTest::testStatisticalFormulaVarA1()
+{
+    if (!detectOpenCLDevice())
+        return;
+
+    ScDocShellRef xDocSh = loadDoc("opencl/statistical/VarA1.", XLS);
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+
+    ScDocShellRef xDocShRes = loadDoc("opencl/statistical/VarA1.", XLS);
+    ScDocument* pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    // Check the results of formula cells in the shared formula range.
+    for (SCROW i = 1; i <= 20; ++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" )
 {
commit 076a2d991a59ffb2d22bb056010c8f3dcc3007f1
Author: mingli <mingli at multicorewareinc.com>
Date:   Tue Dec 31 12:42:07 2013 +0800

    GPU Calc: Fix Not support multiple data types of HARMEAN
    
    AMLOEXT-401 FIX
    
    Change-Id: If398e6abfb7eec11033290fb7e9c87c26829ef90
    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 b1ccaca..54ec99c 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -4428,26 +4428,29 @@ vSubArguments)
         }
         else if (pCur->GetType() == formula::svSingleVectorRef)
         {
-            ss << "    double arg0 = ";
+            ss << "    tmp = ";
             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
             ss << ";\n";
 #ifdef ISNAN
-            ss << "    if(isNan(arg0))\n";
+            ss << "    if(!isNan(tmp))\n";
             ss << "    {\n";
-            ss << "        continue;\n";
+            ss << "        nVal += (1.0 * pow( tmp,-1));\n";
+            ss << "        totallength +=1;\n";
             ss << "    }\n";
 #endif
-            ss << "    nVal += (1.0 * pow( arg0,-1));\n";
-            ss << "    totallength +=1;\n";
         }
         else if (pCur->GetType() == formula::svDouble)
         {
-           ss << "    double arg0 = ";
+           ss << "    tmp = ";
            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
            ss << ";\n";
-           ss << "    nVal += (1.0 *pow( arg0,-1));\n";
+           ss << "    nVal += (1.0 *pow( tmp,-1));\n";
            ss << "    totallength +=1;\n";
         }
+        else
+        {
+            ss << "    return DBL_MIN;\n";
+        }
     }
     ss << "    tmp = totallength*pow(nVal,-1);\n";
     ss << "    return tmp;\n";
commit 165e22397d237245fbda17d265ee3e75ed472ed6
Author: mingli <mingli at multicorewareinc.com>
Date:   Tue Dec 31 12:38:44 2013 +0800

    GPU Calc: unit test cases for Not support multiple data types of HARMEAN
    
    AMLOEXT-401 BUG
    
    Change-Id: I7960b47c62a4a5d65e0ae5814d5b14763cea4e74
    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/statistical/HarMean1.xls b/sc/qa/unit/data/xls/opencl/statistical/HarMean1.xls
new file mode 100644
index 0000000..ab9bc58
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/statistical/HarMean1.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 2635988..98e8917 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -288,6 +288,7 @@ public:
     void testStatisticalFormulaAvedev();
     void testMathFormulaAverageIf_Mix();
     void testStatisticalFormulaKurt1();
+    void testStatisticalFormulaHarMean1();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -507,6 +508,7 @@ public:
     CPPUNIT_TEST(testStatisticalFormulaAvedev);
     CPPUNIT_TEST(testMathFormulaAverageIf_Mix);
     CPPUNIT_TEST(testStatisticalFormulaKurt1);
+    CPPUNIT_TEST(testStatisticalFormulaHarMean1);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -5994,6 +5996,29 @@ void ScOpenclTest::testStatisticalFormulaKurt1()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
+//[AMLOEXT-401]
+void ScOpenclTest::testStatisticalFormulaHarMean1()
+{
+    if (!detectOpenCLDevice())
+        return;
+    ScDocShellRef xDocSh = loadDoc("opencl/statistical/HarMean1.", XLS);
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+    ScDocShellRef xDocShRes = loadDoc("opencl/statistical/HarMean1.", XLS);
+    ScDocument* pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    // Check the results of formula cells in the shared formula range.
+    for (SCROW i = 1; i <= 19; ++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" )
 {
commit c6e6a7d45fe6485af61c4abfdeb0cc9d4a9da342
Author: mingli <mingli at multicorewareinc.com>
Date:   Tue Dec 31 12:00:14 2013 +0800

    GPU Calc: Fix Not support multiple data types of KURT
    
    AMLOEXT-387 FIX
    
    Change-Id: I7faa87205bc82a1078f29bcb763d9ba3c3c20f2f
    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 858de87..b1ccaca 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -5801,109 +5801,185 @@ void OpMedian::GenSlidingWindowFunction(
 void OpKurt:: GenSlidingWindowFunction(std::stringstream &ss,
             const std::string sSymName, SubArguments &vSubArguments)
 {
-        FormulaToken *pCur = vSubArguments[0]->GetFormulaToken();
+    ss << "\ndouble " << sSymName;
+    ss << "_"<< BinFuncName() <<"( ";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
+    {
+        if (i)
+            ss << ",";
+        vSubArguments[i]->GenSlidingWindowDecl(ss);
+    }
+    ss << ")\n";
+    ss <<"{\n";
+    ss << "    int gid0 = get_global_id(0);\n";
+    ss << "    double fSum = 0.0;\n";
+    ss << "    double vSum = 0.0;\n";
+    ss << "    double length;\n";
+    ss << "    double totallength=0;\n";
+    ss << "    double tmp = 0;\n";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
+    {
+        FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
         assert(pCur);
-        const formula::DoubleVectorRefToken* pCurDVR =
-            dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
-        size_t nCurWindowSize = pCurDVR->GetRefRowSize();
-        ss << "\ndouble " << sSymName;
-        ss << "_"<< BinFuncName() <<"( ";
-        for (unsigned i = 0; i < vSubArguments.size(); i++)
+        if (pCur->GetType() == formula::svDoubleVectorRef)
         {
-            if (i)
-                ss << ",";
-            vSubArguments[i]->GenSlidingWindowDecl(ss);
+            const formula::DoubleVectorRefToken* pDVR =
+            dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+            size_t nCurWindowSize = pDVR->GetRefRowSize();
+            ss << "    length="<<nCurWindowSize;
+            ss << ";\n";
+            ss << "    for (int i = ";
+            ss << "0; i < "<< nCurWindowSize << "; i++)\n";
+            ss << "    {\n";
+            ss << "        double arg"<<i<<" = ";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << ";\n";
+#ifdef ISNAN
+            ss << "        if(isNan(arg"<<i<<")||((gid0+i)>=";
+            ss << pDVR->GetArrayLength();
+            ss << "))\n";
+            ss << "        {\n";
+            ss << "            length-=1.0;\n";
+            ss << "            continue;\n";
+            ss << "        }\n";
+#endif
+            ss << "        fSum +=  arg"<<i<<";\n";
+            ss << "    }\n";
+            ss << "    totallength +=length;\n";
         }
-        ss << ") {\n";
-        ss << "    int gid0 = get_global_id(0);\n";
-        ss << "    double fSum = 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";
-        for (unsigned i = 0; i < vSubArguments.size(); i++)
+        else if (pCur->GetType() == formula::svSingleVectorRef)
         {
-            pCur = vSubArguments[i]->GetFormulaToken();
-            assert(pCur);
-            if (pCur->GetType() == formula::svDoubleVectorRef)
-            {
-                const formula::DoubleVectorRefToken* pDVR =
-                dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
-                nCurWindowSize = pDVR->GetRefRowSize();
-                ss << "    for (int i = 0; i <" << nCurWindowSize;
-                ss << "; i++)\n";
-                ss << "    {\n";
-                ss << "        double arg0 = ";
-                ss<< vSubArguments[i]->GenSlidingWindowDeclRef();
-                ss << ";\n";
+            ss << "    tmp = ";
+            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<< "    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";
+            ss << "    if(!isNan(tmp))\n";
+            ss << "    {\n";
+            ss << "        fSum += tmp;\n";
+            ss << "        totallength +=1;\n";
+            ss << "    }\n";
+#endif
+        }
+        else if (pCur->GetType() == formula::svDouble)
+        {
+           ss << "    tmp = ";
+           ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+           ss << ";\n";
+           ss << "    fSum += tmp;\n";
+           ss << "    totallength +=1;\n";
+        }
+        else
+        {
+            ss << "    return DBL_MIN;\n";
+        }
+    }
+    ss << "    double fMean = fSum * pow(totallength,-1);\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 = ";
+            ss << "0; i < "<< nCurWindowSize << "; i++)\n";
+            ss << "    {\n";
+            ss << "        double arg"<<i<<" = ";
+            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<< "        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";
+            ss << "        if(isNan(arg"<<i<<")||((gid0+i)>=";
+            ss << pDVR->GetArrayLength();
+            ss << "))\n";
+            ss << "        {\n";
+            ss << "            continue;\n";
+            ss << "        }\n";
+#endif
+            ss << "        vSum +=  (arg"<<i<<"-fMean)*(arg"<<i<<"-fMean);\n";
+            ss << "    }\n";
+        }
+        else if (pCur->GetType() == formula::svSingleVectorRef)
+        {
+            ss << "    tmp = ";
+            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";
+            ss << "    if(!isNan(tmp))\n";
+            ss << "    {\n";
+            ss << "        vSum += (tmp-fMean)*(tmp-fMean);\n";
+            ss << "    }\n";
 #endif
-                ss<< "        fSum = (arg0 -fMean) / fStdDev;\n";
-                ss<< "        xpower4 += pow(fSum, 4);\n";
-                ss<< "    }\n";
-            }
-            else if (pCur->GetType() == formula::svSingleVectorRef)
-            {
-#ifdef  ISNAN
-                ss << "return HUGE_VAL";
+        }
+        else if (pCur->GetType() == formula::svDouble)
+        {
+           ss << "    tmp = ";
+           ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+           ss << ";\n";
+           ss << "    vSum += (tmp-fMean)*(tmp-fMean);\n";
+        }
+    }
+    ss << "    double fStdDev = sqrt(vSum / (totallength - 1.0));\n";
+    ss << "    double dx = 0.0;\n";
+    ss << "    double xpower4 = 0.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 = ";
+            ss << "0; i < "<< nCurWindowSize << "; i++)\n";
+            ss << "    {\n";
+            ss << "        double arg"<<i<<" = ";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << ";\n";
+#ifdef ISNAN
+            ss << "        if(isNan(arg"<<i<<")||((gid0+i)>=";
+            ss << pDVR->GetArrayLength();
+            ss << "))\n";
+            ss << "        {\n";
+            ss << "            continue;\n";
+            ss << "        }\n";
 #endif
-            }
-            else if (pCur->GetType() == formula::svDouble)
-            {
-#ifdef  ISNAN
-                ss << "return HUGE_VAL";
+            ss<< "        dx = (arg"<<i<<" -fMean) / fStdDev;\n";
+            ss<< "        xpower4 = xpower4 + (dx * dx * dx * dx);\n";
+            ss << "    }\n";
+        }
+        else if (pCur->GetType() == formula::svSingleVectorRef)
+        {
+            ss << "    tmp = ";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << ";\n";
+#ifdef ISNAN
+            ss << "    if(!isNan(tmp))\n";
+            ss << "    {\n";
+            ss<< "        dx = (tmp -fMean) / fStdDev;\n";
+            ss<< "        xpower4 = xpower4 + (dx * dx * dx * dx);\n";
+            ss << "    }\n";
 #endif
-            }
         }
-        ss<< "    fSum = (length - 2.0) * (length - 3.0);\n";
-        ss<< "    fMean = length * (length + 1.0) /";
-        ss<< "((length - 1.0) * fSum);\n";
-        ss<< "    fStdDev = 3.0 * (length - 1.0) * (length - 1.0) / fSum;\n";
-        ss<< "    tmp = xpower4 * fMean - fStdDev;\n";
-        ss<< "    return tmp;\n";
-        ss<< "}";
+        else if (pCur->GetType() == formula::svDouble)
+        {
+           ss << "    tmp = ";
+           ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+           ss << ";\n";
+           ss<< "        dx = (tmp -fMean) / fStdDev;\n";
+           ss<< "        xpower4 = xpower4 + (dx * dx * dx * dx);\n";
+        }
+    }
+    ss<< "    double k_d = (totallength - 2.0) * (totallength - 3.0);\n";
+    ss<< "    double k_l = totallength * (totallength + 1.0) /";
+    ss<< "((totallength - 1.0) * k_d);\n";
+    ss<< "    double k_t = 3.0 * (totallength - 1.0) * ";
+    ss<< "(totallength - 1.0) / k_d;\n";
+    ss<< "    tmp = xpower4 * k_l - k_t;\n";
+    ss<< "    return tmp;\n";
+    ss << "}";
 }
 
 void OpIntercept::GenSlidingWindowFunction(std::stringstream &ss,
commit 92a81d621a0a37d619067e90b0c54d97a18085a0
Author: mingli <mingli at multicorewareinc.com>
Date:   Tue Dec 31 11:54:03 2013 +0800

    GPU Calc: unit test cases for Not support multiple data types of KURT
    
    AMLOEXT-387 BUG
    
    Change-Id: I491dfd98183691033a15f21f41efe514bf96de85
    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/statistical/Kurt1.xls b/sc/qa/unit/data/xls/opencl/statistical/Kurt1.xls
new file mode 100644
index 0000000..24f489f
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/statistical/Kurt1.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index cf3e014..2635988 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -287,6 +287,7 @@ public:
     void testNegSub();
     void testStatisticalFormulaAvedev();
     void testMathFormulaAverageIf_Mix();
+    void testStatisticalFormulaKurt1();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -505,6 +506,7 @@ public:
     CPPUNIT_TEST(testNegSub);
     CPPUNIT_TEST(testStatisticalFormulaAvedev);
     CPPUNIT_TEST(testMathFormulaAverageIf_Mix);
+    CPPUNIT_TEST(testStatisticalFormulaKurt1);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -5969,6 +5971,29 @@ void ScOpenclTest::testMathFormulaAverageIf_Mix()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
+//[AMLOEXT-387]
+void ScOpenclTest::testStatisticalFormulaKurt1()
+{
+    if (!detectOpenCLDevice())
+        return;
+    ScDocShellRef xDocSh = loadDoc("opencl/statistical/Kurt1.", XLS);
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+    ScDocShellRef xDocShRes = loadDoc("opencl/statistical/Kurt1.", XLS);
+    ScDocument* pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    // Check the results of formula cells in the shared formula range.
+    for (SCROW i = 1; i <= 19; ++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" )
 {
commit b8d852c170582cee3ec4d120da25abe5fd5bbf55
Author: yiming ju <yiming at multicorewareinc.com>
Date:   Tue Dec 31 11:35:26 2013 +0800

    GPU Calc: Optimized TBILLPRICE
    
    AMLOEXT-386
    
    Change-Id: Ida4704f9864e0ba3fe043f33ac58b8ae1a7ab098
    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 5931ab5..e13b86c 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -4571,11 +4571,11 @@ void OpYielddisc::GenSlidingWindowFunction(
  void OpTbillprice::BinInlineFun(std::set<std::string>& decls,
     std::set<std::string>& funs)
 {
-    decls.insert(GetYearFracDecl);decls.insert(GetNullDateDecl);
+    decls.insert(GetYearFracDecl);
     decls.insert(DateToDaysDecl);decls.insert(DaysToDateDecl);
     decls.insert(DaysInMonthDecl);decls.insert(IsLeapYearDecl);
 
-    funs.insert(GetYearFrac);funs.insert(GetNullDate);
+    funs.insert(GetYearFrac);
     funs.insert(DateToDays);funs.insert(DaysToDate);
     funs.insert(DaysInMonth);funs.insert(IsLeapYear);
 }
@@ -4591,75 +4591,20 @@ void OpTbillprice::GenSlidingWindowFunction(
             ss << ",";
         vSubArguments[i]->GenSlidingWindowDecl(ss);
     }
-    ss << ") {\n\t";
-    ss << "int gid0 = get_global_id(0);\n\t";
-    ss << "double tmp = 0;\n\t";
-    ss << "double tmp000;\n\t";
-    ss << "double tmp001;\n\t";
-    ss << "double tmp002;\n\t";
-
-
-
-#ifdef ISNAN
-    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<< "int buffer_tmp000_len = ";
-    ss<< tmpCurDVR0->GetArrayLength();
-    ss << ";\n\t";
-
-    ss<< "int buffer_tmp001_len = ";
-    ss<< tmpCurDVR1->GetArrayLength();
-    ss << ";\n\t";
-
-    ss<< "int buffer_tmp002_len = ";
-    ss<< tmpCurDVR2->GetArrayLength();
-    ss << ";\n\t";
-#endif
-
-#ifdef ISNAN
-    ss<<"if(gid0>=buffer_tmp000_len || isNan(";
-    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-    ss<<"))\n\t\t";
-    ss<<"tmp000 = 0;\n\telse \n\t\t";
-#endif
-    ss<<"tmp000 = ";
-    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
-    ss<<";\n\t";
-
-#ifdef ISNAN
-    ss<<"if(gid0>=buffer_tmp001_len || isNan(";
-    ss << vSubArguments[1]->GenSlidingWindowDeclRef();
-    ss<<"))\n\t\t";
-    ss<<"tmp001 = 0;\n\telse \n\t\t";
-#endif
-    ss<<"tmp001 = ";
-    ss << vSubArguments[1]->GenSlidingWindowDeclRef();
-    ss<<";\n\t";
+    ss << ") {\n";
+    ss << "    int gid0 = get_global_id(0);\n";
+    ss << "    double tmp = 0;\n";
 
-#ifdef ISNAN
-    ss<<"if(gid0>=buffer_tmp002_len || isNan(";
-    ss << vSubArguments[2]->GenSlidingWindowDeclRef();
-    ss<<"))\n\t\t";
-    ss<<"tmp002 = 0;\n\telse \n\t\t";
-#endif
-    ss<<"tmp002 = ";
-    ss << vSubArguments[2]->GenSlidingWindowDeclRef();
-    ss<<";\n\t";
+    ss << "    int singleIndex = gid0;\n";
+    ss << "    int doubleIndex = gid0;\n";
+    ss << "    int i = gid0;\n";
+    GenTmpVariables(ss,vSubArguments);
+    CheckAllSubArgumentIsNan(ss,vSubArguments);
 
-    ss<<"tmp001+=1.0;\n";
-    ss<<"double  fFraction =GetYearFrac(GetNullDate(),tmp000,tmp001,0);\n";
-    ss<<"tmp = 100.0 * ( 1.0 - tmp002 * fFraction );\n";
-    ss << "return tmp;\n";
+    ss << "    tmp1+=1.0;\n";
+    ss << "    double  fFraction =GetYearFrac(693594,tmp0,tmp1,0);\n";
+    ss << "    tmp = 100.0 * ( 1.0 - tmp2 * fFraction );\n";
+    ss << "    return tmp;\n";
     ss << "}\n";
 }
  void RATE::BinInlineFun(std::set<std::string>& decls,
diff --git a/sc/source/core/opencl/op_financial.hxx b/sc/source/core/opencl/op_financial.hxx
index 11d5fcd..34019be 100644
--- a/sc/source/core/opencl/op_financial.hxx
+++ b/sc/source/core/opencl/op_financial.hxx
@@ -503,7 +503,7 @@ public:
     virtual void BinInlineFun(std::set<std::string>& ,std::set<std::string>& );
 };
 
-class OpTbillprice: public Normal
+class OpTbillprice: public CheckVariables
 {
 public:
     virtual void GenSlidingWindowFunction(std::stringstream &ss,
commit de6cd548c108a9001158946e4fba251b281c0bf0
Author: yiming ju <yiming at multicorewareinc.com>
Date:   Tue Dec 31 11:23:54 2013 +0800

    GPU Calc: Fix bug of Averageif not support double vector
    
    AMLOEXT-386 FIX
    
    Change-Id: If8bd95079c725c690e5ca10c6c5954d01f971c0e
    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 3422b3b..9b7dca0 100644
--- a/sc/source/core/opencl/op_math.cxx
+++ b/sc/source/core/opencl/op_math.cxx
@@ -2961,12 +2961,7 @@ void OpProduct::GenSlidingWindowFunction(std::stringstream &ss,
 void OpAverageIf::GenSlidingWindowFunction(std::stringstream &ss,
     const std::string sSymName, SubArguments &vSubArguments)
 {
-    FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
-    const formula::DoubleVectorRefToken*pCurDVR= dynamic_cast<const
-        formula::DoubleVectorRefToken *>(tmpCur);
-    size_t nCurWindowSize = pCurDVR->GetArrayLength() <
-        pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
-        pCurDVR->GetRefRowSize() ;
+
     ss << "\ndouble " << sSymName;
     ss << "_"<< BinFuncName() <<"(";
     for (unsigned i = 0; i < vSubArguments.size(); i++)
@@ -2978,39 +2973,143 @@ void OpAverageIf::GenSlidingWindowFunction(std::stringstream &ss,
     ss << "    int gid0=get_global_id(0);\n";
     ss << "    double tmp =0;\n";
     ss << "    double count=0;\n";
+    ss << "    int singleIndex =gid0;\n";
+    ss << "    int doubleIndex;\n";
     ss << "    int i ;\n";
+    ss << "    int j ;\n";
     GenTmpVariables(ss,vSubArguments);
-    ss << "    for (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";
+
+    unsigned paraOneIsDoubleVector = 0;
+    unsigned paraOneWidth = 1;
+    unsigned paraTwoWidth = 1;
+    unsigned paraThreeWidth = 1;
+    unsigned loopTimes = 0;
+    unsigned loopIndex = 0;
+    if(vSubArguments[0]->GetFormulaToken()->GetType() ==
+    formula::svDoubleVectorRef)
+    {
+        paraOneIsDoubleVector = 1;
+        FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
+        const formula::DoubleVectorRefToken*pCurDVR0= dynamic_cast<const
+            formula::DoubleVectorRefToken *>(tmpCur0);
+        paraOneWidth = pCurDVR0->GetArrays().size();
+        loopTimes = paraOneWidth;
+        if(paraOneWidth > 1)
+        {
+            throw Unhandled();
+        } 
     }
-    ss << "    {\n";
-    if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
-    {
-        ss << "        int doubleIndex =i+gid0;\n";
-    }else
+
+    if(vSubArguments[paraOneWidth]->GetFormulaToken()->GetType() ==
+     formula::svDoubleVectorRef)
+ 
     {
-        ss << "        int doubleIndex =i;\n";
+        FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
+        const formula::DoubleVectorRefToken*pCurDVR1= dynamic_cast<const
+            formula::DoubleVectorRefToken *>(tmpCur1);
+        paraTwoWidth = pCurDVR1->GetArrays().size();
+        if(paraTwoWidth > 1)
+        {
+            throw Unhandled();
+        }
+        ss << "    i = ";
+        if (!pCurDVR1->IsStartFixed() && pCurDVR1->IsEndFixed()) {
+            ss << "gid0;\n";
+        } else {
+            ss << "0;\n";
+        }
+        if(!pCurDVR1->IsStartFixed() && !pCurDVR1->IsEndFixed())
+        {
+            ss << "        doubleIndex =i+gid0;\n";
+        }else
+        {
+            ss << "        doubleIndex =i;\n";
+        }
     }
-    ss << "        int singleIndex =gid0;\n";
-    CheckSubArgumentIsNan(ss,vSubArguments,0);
-    CheckSubArgumentIsNan(ss,vSubArguments,1);
-    ss << "        if ( isequal( tmp0 , tmp1 ) ) \n";
-    ss << "        {";
-    if(vSubArguments.size() == 2)
-        ss << "            tmp += tmp0;\n";
-    else
+
+    CheckSubArgumentIsNan(ss,vSubArguments,paraOneWidth);
+
+    unsigned paraThreeIndex = paraOneWidth + paraTwoWidth;
+    if(vSubArguments.size() > paraThreeIndex)
+    {
+        if(vSubArguments[paraThreeIndex]->GetFormulaToken()->GetType() ==
+        formula::svDoubleVectorRef)
+        {
+            FormulaToken *tmpCur2 =
+            vSubArguments[paraThreeIndex]->GetFormulaToken();
+            const formula::DoubleVectorRefToken*pCurDVR2= dynamic_cast<const
+                formula::DoubleVectorRefToken *>(tmpCur2);
+            paraThreeWidth = pCurDVR2->GetArrays().size();
+             if(paraThreeWidth > 1)
+            {
+                throw Unhandled();
+            }
+        }
+    }
+
+    if(paraOneIsDoubleVector)
+    {
+        FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
+        const formula::DoubleVectorRefToken*pCurDVR0= dynamic_cast<const
+            formula::DoubleVectorRefToken *>(tmpCur0);
+        size_t nCurWindowSize = pCurDVR0->GetArrayLength() <
+            pCurDVR0->GetRefRowSize() ? pCurDVR0->GetArrayLength():
+            pCurDVR0->GetRefRowSize() ;
+
+        for(loopIndex =0; loopIndex < loopTimes; loopIndex++)
+        {
+            ss << "    for (i = ";
+            if (!pCurDVR0->IsStartFixed() && pCurDVR0->IsEndFixed()) {
+                ss << "gid0; i < "<< nCurWindowSize <<"; i++)\n";
+            } else if (pCurDVR0->IsStartFixed() && !pCurDVR0->IsEndFixed()) {
+                ss << "0; i < gid0+"<< nCurWindowSize <<"; i++)\n";
+            } else {
+                ss << "0; i < "<< nCurWindowSize <<"; i++)\n";
+            }
+            ss << "    {\n";
+            if(!pCurDVR0->IsStartFixed() && !pCurDVR0->IsEndFixed())
+            {
+                ss << "        doubleIndex =i+gid0;\n";
+            }else
+            {
+                ss << "        doubleIndex =i;\n";
+            }
+
+            CheckSubArgumentIsNan(ss,vSubArguments, loopIndex);
+
+            ss << "        if ( isequal( tmp";
+            ss << loopIndex<<" , tmp"<<paraOneWidth<<") ) \n";
+            ss << "        {\n";
+            if(vSubArguments.size() == paraThreeIndex)
+                ss << "            tmp += tmp"<<loopIndex<<";\n";
+            else
+            {
+                CheckSubArgumentIsNan(ss,vSubArguments,
+                paraThreeIndex+loopIndex);
+                ss << "            tmp += tmp";
+                ss << paraThreeIndex+loopIndex<<";\n";
+            }
+            ss << "            count+=1.0;\n";
+            ss << "        }\n";
+            ss << "    }\n";
+        }
+    }
+      else
     {
-        CheckSubArgumentIsNan(ss,vSubArguments,2);
-        ss << "            tmp += tmp2;\n";
+        CheckSubArgumentIsNan(ss,vSubArguments, 0);
+        ss << "        if ( isequal( tmp0 , tmp1 ) ) \n";
+        ss << "        {\n";
+        if(vSubArguments.size() == 2)
+            ss << "            tmp += tmp0;\n";
+        else
+        {
+            CheckSubArgumentIsNan(ss,vSubArguments,2);
+            ss << "            tmp += tmp2;\n";
+        }
+        ss << "            count+=1.0;\n";
+        ss << "        }\n";
     }
-    ss << "            count+=1.0;\n";
-    ss << "        }\n";
-    ss << "    }\n";
+  
     ss << "    if(count!=0)\n";
     ss << "        tmp=tmp/count;\n";
     ss << "    else\n";
commit dc6639a4f2556bec5d0031cbefca230e6e31eef5
Author: yiming ju <yiming at multicorewareinc.com>
Date:   Tue Dec 31 11:16:23 2013 +0800

    GPU Calc: unit test cases for Averageif not support double vector
    
    AMLOEXT-386 BUG
    
    Change-Id: Ie7c20cf9e354ca4c88388238ba735262098bb09f
    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/math/averageif_mix.xls b/sc/qa/unit/data/xls/opencl/math/averageif_mix.xls
new file mode 100644
index 0000000..0fd3f8d
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/math/averageif_mix.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 4103dad..cf3e014 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -286,6 +286,7 @@ public:
     void testAddInFormulaBesseLJ();
     void testNegSub();
     void testStatisticalFormulaAvedev();
+    void testMathFormulaAverageIf_Mix();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -503,6 +504,7 @@ public:
     CPPUNIT_TEST(testAddInFormulaBesseLJ);
     CPPUNIT_TEST(testNegSub);
     CPPUNIT_TEST(testStatisticalFormulaAvedev);
+    CPPUNIT_TEST(testMathFormulaAverageIf_Mix);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -5945,7 +5947,28 @@ void ScOpenclTest::testNegSub()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
-
+//[AMLOEXT-386]
+void ScOpenclTest::testMathFormulaAverageIf_Mix()
+{
+    if (!detectOpenCLDevice())
+        return;
+    ScDocShellRef xDocSh = loadDoc("opencl/math/averageif_mix.", XLS);
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+    ScDocShellRef xDocShRes = loadDoc("opencl/math/averageif_mix.", XLS);
+    ScDocument* pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    for (SCROW i = 0; i <= 9; ++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" )
 {


More information about the Libreoffice-commits mailing list