[Libreoffice-commits] core.git: Branch 'feature/calc-group-interpreter-4' - 2 commits - sc/qa sc/source

hongyu zhong hongyu at multicorewareinc.com
Sat Nov 16 20:13:06 PST 2013


 sc/qa/unit/data/xls/opencl/statistical/Betainv.xls |binary
 sc/qa/unit/opencl-test.cxx                         |   25 +++
 sc/source/core/opencl/formulagroupcl.cxx           |    5 
 sc/source/core/opencl/op_statistical.cxx           |  153 +++++++++++++++++++++
 sc/source/core/opencl/op_statistical.hxx           |    8 -
 sc/source/core/opencl/opbase.cxx                   |    4 
 sc/source/core/opencl/opinlinefun_statistical.cxx  |    1 
 sc/source/core/tool/token.cxx                      |    1 
 8 files changed, 193 insertions(+), 4 deletions(-)

New commits:
commit ca30bd2c6c637746fb56dc9ef45bc84baa743faa
Author: hongyu zhong <hongyu at multicorewareinc.com>
Date:   Sat Nov 16 17:33:30 2013 +0800

    GPU Calc: implemented BETAINV
    
    AMLOEXT-201 FIX
    
    Change-Id: I68a7277b7353ed5a6f4d2ea8d1a4f7fb894bf487
    Signed-off-by: haochen <haochen at multicorewareinc.com>

diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index b9469f2..0d63e4c 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1762,6 +1762,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
                 mvSubArguments.push_back(SoPHelper(ts,
                          ft->Children[i],new OpSumX2PY2));
                  break;
+            case ocBetaInv:
+                mvSubArguments.push_back(SoPHelper(ts,
+                         ft->Children[i],new OpBetainv));
+                 break;
             case ocExternal:
                 if ( !(pChild->GetExternal().compareTo(OUString(
                     "com.sun.star.sheet.addin.Analysis.getEffect"))))
diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx
index ddad803..48c015d 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -6198,6 +6198,159 @@ void OpBetaDist::GenSlidingWindowFunction(std::stringstream &ss,
     ss << "    return tmp;\n";
     ss << "}\n";
 }
+void OpBetainv::BinInlineFun(std::set<std::string>& decls,
+    std::set<std::string>& funs)
+{
+    decls.insert(fMachEpsDecl);
+    funs.insert("");
+    decls.insert(fMaxGammaArgumentDecl);
+    funs.insert("");
+    decls.insert(lcl_IterateInverseBetaInvDecl);
+    funs.insert(lcl_IterateInverseBetaInv);
+    decls.insert(GetBetaDistDecl);
+    funs.insert(GetBetaDist);
+    decls.insert(lcl_HasChangeOfSignDecl);
+    funs.insert(lcl_HasChangeOfSign);
+    decls.insert(lcl_HasChangeOfSignDecl);
+    funs.insert(lcl_HasChangeOfSign);
+    decls.insert(lcl_HasChangeOfSignDecl);
+    funs.insert(lcl_HasChangeOfSign);
+    decls.insert(lcl_GetBetaHelperContFracDecl);
+    funs.insert(lcl_GetBetaHelperContFrac);
+    decls.insert(GetBetaDistPDFDecl);
+    funs.insert(GetBetaDistPDF);
+    decls.insert(GetLogBetaDecl);
+    funs.insert(GetLogBeta);
+    decls.insert(GetBetaDecl);
+    funs.insert(GetBeta);
+    decls.insert(lcl_getLanczosSumDecl);
+    funs.insert(lcl_getLanczosSum);
+}
+void OpBetainv::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 << "{\n";
+    ss << "    double tmp0,tmp1,tmp2,tmp3,tmp4;\n";
+    ss << "    int gid0=get_global_id(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)
+        {
+#ifdef  ISNAN
+                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)
+        {
+#ifdef  ISNAN
+            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<<"=\n";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << ";\n}\n";
+        }
+        else
+        {
+            ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss <<";\n";
+        }
+#else
+    ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
+    ss <<";\n";
+#endif
+    }
+    ss << "    if (tmp0 < 0.0 || tmp0 >= 1.0 ||";
+    ss << "tmp3 == tmp4 || tmp1 <= 0.0 || tmp2 <= 0.0)\n";
+    ss << "    {\n";
+    ss << "        return DBL_MIN;\n";
+    ss << "    }\n";
+    ss << "    if (tmp0 == 0.0)\n";
+    ss << "        return 0.0;\n";
+    ss << "    else\n";
+    ss << "    {";
+    ss << "        bool bConvError;";
+    ss << "        double fVal = lcl_IterateInverseBetaInv";
+    ss << "(tmp0, tmp1, tmp2, 0.0, 1.0, &bConvError);\n";
+    ss << "        if(bConvError)\n";
+    ss << "            return DBL_MIN;\n";
+    ss << "        else\n";
+    ss << "            return (tmp3 + fVal*(tmp4 - tmp3));\n";
+    ss << "    }";
+    ss << "}\n";
+}
 void OpDevSq::GenSlidingWindowFunction(std::stringstream& ss,
     const std::string sSymName, SubArguments& vSubArguments)
 {
diff --git a/sc/source/core/opencl/op_statistical.hxx b/sc/source/core/opencl/op_statistical.hxx
index 9f8f54a..43c829f 100644
--- a/sc/source/core/opencl/op_statistical.hxx
+++ b/sc/source/core/opencl/op_statistical.hxx
@@ -406,7 +406,13 @@ public:
 );
     virtual std::string BinFuncName(void) const { return "BetaDist"; }
 };
-
+class OpBetainv: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 "OpBetainv"; }
+};
 }}
 
 #endif
diff --git a/sc/source/core/opencl/opinlinefun_statistical.cxx b/sc/source/core/opencl/opinlinefun_statistical.cxx
index b97dd11..8aaff82 100644
--- a/sc/source/core/opencl/opinlinefun_statistical.cxx
+++ b/sc/source/core/opencl/opinlinefun_statistical.cxx
@@ -432,6 +432,7 @@ std::string lcl_IterateInverseBetaInv =
 "{\n"
 "   *rConvError = false;\n"
 "    double fYEps = 1.0E-307;\n"
+"    double fXEps = fMachEps;\n"
 "   if(!(fAx < fBx))\n"
 "   {\n"
 "       //print error\n"
commit 21d0a70086652d319b8200a60ae28329ea8fb245
Author: hongyu zhong <hongyu at multicorewareinc.com>
Date:   Sat Nov 16 17:00:14 2013 +0800

    GPU Calc: unit test cases for BETAINV
    
    Turn  NO_FALLBACK_TO_SWINTERP on in  formulagroupcl.cxx for test
    
    resolve compile warning in opbase.cxx
    
    AMLOEXT-201 BUG
    
    Change-Id: I82917b13c43c1bcaa01928b89210c8eb7495a167
    Signed-off-by: haochen <haochen at multicorewareinc.com>
    Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>

diff --git a/sc/qa/unit/data/xls/opencl/statistical/Betainv.xls b/sc/qa/unit/data/xls/opencl/statistical/Betainv.xls
new file mode 100644
index 0000000..d06dfca
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/statistical/Betainv.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 291f87f..684bab1 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -234,6 +234,7 @@ public:
     void testStatisticalFormulaHypGeomDist();
     void testArrayFormulaSumX2MY2();
     void testArrayFormulaSumX2PY2();
+    void testStatisticalFormulaBetainv();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -397,6 +398,7 @@ public:
     CPPUNIT_TEST(testStatisticalFormulaHypGeomDist);
     CPPUNIT_TEST(testArrayFormulaSumX2MY2);
     CPPUNIT_TEST(testArrayFormulaSumX2PY2);
+    CPPUNIT_TEST(testStatisticalFormulaBetainv);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -4524,6 +4526,29 @@ void ScOpenclTest:: testArrayFormulaSumX2PY2()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
+//[AMLOEXT-201]
+void ScOpenclTest::testStatisticalFormulaBetainv()
+{
+    if (!detectOpenCLDevice())
+        return;
+    ScDocShellRef xDocSh = loadDoc("opencl/statistical/Betainv.", XLS);
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+    ScDocShellRef xDocShRes = loadDoc("opencl/statistical/Betainv.", 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(5,i,0));
+        double fExcel = pDocRes->GetValue(ScAddress(5,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/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index 36517c7..b9469f2 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -2292,7 +2292,6 @@ bool FormulaGroupInterpreterOpenCL::interpret( ScDocument& rDoc,
         if (err != CL_SUCCESS)
             throw OpenCLError(err);
         delete mpKernel;
-        return true;
     }
 #undef NO_FALLBACK_TO_SWINTERP /* undef this for non-TDD runs */
     catch (const UnhandledToken &ut) {
diff --git a/sc/source/core/opencl/opbase.cxx b/sc/source/core/opencl/opbase.cxx
index fe7fc24..394ee7a 100644
--- a/sc/source/core/opencl/opbase.cxx
+++ b/sc/source/core/opencl/opbase.cxx
@@ -184,8 +184,7 @@ void CheckVariables::CheckSubArgumentIsNan2( std::stringstream & ss,
      formula::svSingleVectorRef)
         ss<<"[get_group_id(1)]";
     ss<<", 0);\n";
-    return;
-#endif
+#else
     ss <<"    tmp";
     ss <<i;
     ss << "=";
@@ -198,6 +197,7 @@ void CheckVariables::CheckSubArgumentIsNan2( std::stringstream & ss,
         ss<<"[get_group_id(1)]";
 
     ss<<";\n";
+#endif
 }
 
 void CheckVariables::CheckAllSubArgumentIsNan(
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index c105592..310b5f7 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1462,6 +1462,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
             case ocHypGeomDist:
             case ocSumX2MY2:
             case ocSumX2DY2:
+            case ocBetaInv:
             // Don't change the state.
             break;
             default:


More information about the Libreoffice-commits mailing list