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

hongyu zhong hongyu at multicorewareinc.com
Mon Nov 11 18:55:33 PST 2013


 sc/qa/unit/data/xls/opencl/statistical/Median.xls  |binary
 sc/qa/unit/data/xls/opencl/statistical/Weibull.xls |binary
 sc/qa/unit/opencl-test.cxx                         |   52 +++++
 sc/source/core/opencl/formulagroupcl.cxx           |    8 
 sc/source/core/opencl/op_statistical.cxx           |  217 +++++++++++++++++++++
 sc/source/core/opencl/op_statistical.hxx           |   14 +
 sc/source/core/tool/token.cxx                      |    2 
 7 files changed, 293 insertions(+)

New commits:
commit 62ee42a209dfd4862cab9311868f4f38a6e000ac
Author: hongyu zhong <hongyu at multicorewareinc.com>
Date:   Mon Nov 4 17:31:04 2013 +0800

    GPU Calc: unit test cases for MEDIAN
    
    Need open macro NO_FALLBACK_TO_SWINTERP in formulagroupcl.cxx for test
    
    AMLOEXT-100 BUG
    
    Change-Id: Idbc6a697c42b639a310200b4df9eb35ba5e8eca7
    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/Median.xls b/sc/qa/unit/data/xls/opencl/statistical/Median.xls
new file mode 100644
index 0000000..232629e
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/statistical/Median.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index b406894..b593174 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -130,6 +130,7 @@ public:
     void testMathFormulaTanH();
     void testStatisticalFormulaStandard();
     void testStatisticalFormulaWeibull();
+    void testStatisticalFormulaMedian();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -191,6 +192,7 @@ public:
     CPPUNIT_TEST(testMathFormulaTanH);
     CPPUNIT_TEST(testStatisticalFormulaStandard);
     CPPUNIT_TEST(testStatisticalFormulaWeibull);
+    CPPUNIT_TEST(testStatisticalFormulaMedian);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -1532,6 +1534,29 @@ void ScOpenclTest:: testFinancialISPMTFormula()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
+//[AMLOEXT-100]
+void ScOpenclTest::testStatisticalFormulaMedian()
+{
+    if (!detectOpenCLDevice())
+        return;
+    ScDocShellRef xDocSh = loadDoc("opencl/statistical/Median.",XLS);
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+    ScDocShellRef xDocShRes = loadDoc("opencl/statistical/Median.",XLS);
+    ScDocument* pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    // Check the results of formula cells in the shared formula range.
+    for (SCROW i = 1; i <= 9; ++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();
+}
 void ScOpenclTest::testFinacialPriceMatFormula()
 {
     if (!detectOpenCLDevice())
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index e72e026..1bcf726 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1376,6 +1376,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
             case ocTanHyp:
             case ocStandard:
             case ocWeibull:
+            case ocMedian:
             // Don't change the state.
             break;
             default:
commit eb2c6bd19faca2607fa425bbd7f8a95f5407a1ac
Author: hongyu zhong <hongyu at multicorewareinc.com>
Date:   Mon Nov 4 17:39:20 2013 +0800

    GPU Calc: implemented MEDIAN
    
    AMLOEXT-100 FIX
    
    Change-Id: I9b002e6c2383c4416b98e6698d3dd2e81f7752f5
    Signed-off-by: haochen <haochen 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 380a6a6..60b126c 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1052,6 +1052,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
                 mvSubArguments.push_back(SoPHelper(ts,
                          ft->Children[i], new OpWeibull));
                 break;
+            case ocMedian:
+                mvSubArguments.push_back(SoPHelper(ts,
+                         ft->Children[i],new OpMedian));
+                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 64f2411..356b170 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -939,6 +939,83 @@ void OpRsq::GenSlidingWindowFunction(
     ss << "}\n";
 }
 
+void OpMedian::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";
+    ss << "    int i;\n";
+    ss << "    unsigned int startFlag = 0;\n";
+    ss << "    unsigned int endFlag = 0;\n";
+    ss << "    double dataIna;\n";
+    for (unsigned i = 0; i < vSubArguments.size(); i++)
+    {
+        FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
+        assert(pCur);
+        if (const formula::DoubleVectorRefToken* pCurDVR =
+            dynamic_cast<const formula::DoubleVectorRefToken *>(pCur))
+        {
+            size_t nCurWindowSize = pCurDVR->GetRefRowSize();
+            ss << "startFlag = ";
+            if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed())
+            {
+                ss << "gid0; endFlag = "<< nCurWindowSize <<"-gid0;\n";
+            }
+            else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
+            {
+                ss << "gid0; endFlag = gid0+"<< nCurWindowSize <<";\n";
+            }
+            else
+            {
+                ss << "gid0; endFlag = gid0+"<< nCurWindowSize <<";\n";
+            }
+        }
+        else
+        {
+            ss<<"startFlag=gid0;endFlag=gid0;\n";
+        }
+    }
+#ifdef ISNAN
+    FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
+    const formula::DoubleVectorRefToken*tmpCurDVR0= dynamic_cast<const
+    formula::DoubleVectorRefToken *>(tmpCur0);
+    ss << "int buffer_fIna_len = ";
+    ss << tmpCurDVR0->GetArrayLength();
+    ss << ";\n";
+#endif
+#ifdef ISNAN
+    ss<<"if((i+gid0)>=buffer_fIna_len || isNan(";
+    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss<<"))\n";
+    ss<<"    dataIna = 0;\n";
+#endif
+    ss << "    int nSize =endFlag- startFlag ;\n";
+    ss << "    if (nSize & 1)\n";
+    ss << "    {\n";
+    ss << "        tmp = "<<vSubArguments[0]->GetNameAsString();
+    ss << "        [startFlag+nSize/2];\n";
+    ss << "    }\n";
+    ss << "    else\n";
+    ss << "    {\n";
+    ss << "        tmp =("<<vSubArguments[0]->GetNameAsString();
+    ss << "        [startFlag+nSize/2]+";
+    ss <<          vSubArguments[0]->GetNameAsString();
+    ss << "        [startFlag+nSize/2-1])/2;\n";
+    ss << "    }\n";
+    ss <<"     return tmp;\n";
+    ss << "}\n";
+}
+
 }}
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/opencl/op_statistical.hxx b/sc/source/core/opencl/op_statistical.hxx
index b4d98df..1002fa9 100644
--- a/sc/source/core/opencl/op_statistical.hxx
+++ b/sc/source/core/opencl/op_statistical.hxx
@@ -117,6 +117,12 @@ public:
             const std::string sSymName, SubArguments &vSubArguments);
     virtual std::string BinFuncName(void) const { return "OpRsq"; }
 };
+class OpMedian:public Normal{
+    public:
+    virtual void GenSlidingWindowFunction(std::stringstream &ss,
+            const std::string sSymName, SubArguments &vSubArguments);
+    virtual std::string BinFuncName(void) const { return "OpMedian"; }
+};
 
 }}
 
commit cb7e9881168c33b75db4803f144d9df69990f989
Author: shiming zhang <shiming at multicorewareinc.com>
Date:   Mon Nov 4 17:11:40 2013 +0800

    GPU Calc: unit test cases for WEIBULL
    
    Need open macro NO_FALLBACK_TO_SWINTERP in formulagroupcl.cxx for test
    
    AMLOEXT-78 BUG
    
    Change-Id: I4235313f70d2237ce06d4f71163d0d32bc0f064d
    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/Weibull.xls b/sc/qa/unit/data/xls/opencl/statistical/Weibull.xls
new file mode 100644
index 0000000..e943041
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/statistical/Weibull.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index d108f83..b406894 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -129,6 +129,7 @@ public:
     void testMathFormulaTan();
     void testMathFormulaTanH();
     void testStatisticalFormulaStandard();
+    void testStatisticalFormulaWeibull();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -189,6 +190,7 @@ public:
     CPPUNIT_TEST(testMathFormulaTan);
     CPPUNIT_TEST(testMathFormulaTanH);
     CPPUNIT_TEST(testStatisticalFormulaStandard);
+    CPPUNIT_TEST(testStatisticalFormulaWeibull);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -1386,6 +1388,31 @@ void ScOpenclTest::testStatisticalFormulaStandard()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
+//[AMLOEXT-78]
+void ScOpenclTest::testStatisticalFormulaWeibull()
+{
+    if (!detectOpenCLDevice())
+        return;
+
+    ScDocShellRef xDocSh = loadDoc("opencl/statistical/Weibull.", XLS);
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+
+    ScDocShellRef xDocShRes = loadDoc("opencl/statistical/Weibull.", 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(4,i,0));
+        double fExcel = pDocRes->GetValue(ScAddress(4,i,0));
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel));
+    }
+    xDocSh->DoClose();
+    xDocShRes->DoClose();
+}
 //[AMLOEXT-82]
 void ScOpenclTest::testStatisticalFormulaPearson()
 {
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 2de1508..e72e026 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1375,6 +1375,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
             case ocTan:
             case ocTanHyp:
             case ocStandard:
+            case ocWeibull:
             // Don't change the state.
             break;
             default:
commit 4e2e0d10ac893c6f75971255387468655b95d686
Author: shiming zhang <shiming at multicorewareinc.com>
Date:   Mon Nov 4 17:20:19 2013 +0800

    GPU Calc: implemented WEIBULL
    
    AMLOEXT-78 FIX
    
    Change-Id: Iebb516f31b7315cae3375288baa7536c31109fed
    Signed-off-by: haochen <haochen 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 228df59..380a6a6 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1048,6 +1048,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
                 mvSubArguments.push_back(SoPHelper(ts,
                          ft->Children[i], new OpStandard));
                 break;
+            case ocWeibull:
+                mvSubArguments.push_back(SoPHelper(ts,
+                         ft->Children[i], new OpWeibull));
+                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 4128507..64f2411 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -129,6 +129,146 @@ void OpStandard::GenSlidingWindowFunction(std::stringstream &ss,
     ss << "}";
 }
 
+
+void OpWeibull::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 << "    double x,alpha,beta,kum;\n";
+    if(vSubArguments.size() != 4)
+    {
+        ss << "    return DBL_MAX;\n" << "}\n";
+        return ;
+    }
+    FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
+    assert(tmpCur0);
+    if(tmpCur0->GetType() == formula::svSingleVectorRef)
+    {
+        const formula::SingleVectorRefToken*tmpCurDVR0 =
+            dynamic_cast<const formula::SingleVectorRefToken *>(tmpCur0);
+#ifdef ISNAN
+        ss << "    int buffer_x_len = ";
+        ss << tmpCurDVR0->GetArrayLength() << ";\n";
+        ss << "    if(gid0>=buffer_x_len || isNan(";
+        ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
+        ss << "        x = 0.0;\n";
+        ss << "    else\n";
+#endif
+        ss << "        x = ";
+        ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+    }
+    else if(tmpCur0->GetType() == formula::svDouble)
+    {
+        ss << "    x=" <<tmpCur0->GetDouble() << ";\n";
+    }
+    else
+    {
+        ss << "return DBL_MAX;\n" << "}\n";
+        return ;
+    }
+
+    FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
+    assert(tmpCur1);
+    if(tmpCur1->GetType() == formula::svSingleVectorRef)
+    {
+        const formula::SingleVectorRefToken*tmpCurDVR1 =
+            dynamic_cast<const formula::SingleVectorRefToken *>(tmpCur1);
+#ifdef ISNAN
+        ss << "    int buffer_alpha_len = ";
+        ss << tmpCurDVR1->GetArrayLength() << ";\n";
+        ss << "    if(gid0>=buffer_alpha_len || isNan(";
+        ss << vSubArguments[1]->GenSlidingWindowDeclRef() << "))\n";
+        ss << "        alpha = 0.0;\n";
+        ss << "    else\n";
+#endif
+        ss << "        alpha = ";
+        ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
+    }
+    else if(tmpCur1->GetType() == formula::svDouble)
+    {
+        ss << "    alpha=" <<tmpCur1->GetDouble() << ";\n";
+    }
+    else
+    {
+        ss << "return DBL_MAX;\n" << "}\n";
+        return ;
+    }
+
+    FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
+    assert(tmpCur2);
+    if(tmpCur2->GetType() == formula::svSingleVectorRef)
+    {
+        const formula::SingleVectorRefToken*tmpCurDVR2 =
+            dynamic_cast<const formula::SingleVectorRefToken *>(tmpCur2);
+#ifdef ISNAN
+        ss << "    int buffer_beta_len = ";
+        ss << tmpCurDVR2->GetArrayLength() << ";\n";
+        ss << "    if(gid0>=buffer_beta_len || isNan(";
+        ss << vSubArguments[2]->GenSlidingWindowDeclRef() << "))\n";
+        ss << "        beta = 0.0;\n";
+        ss << "    else\n";
+#endif
+        ss << "        beta = ";
+        ss << vSubArguments[2]->GenSlidingWindowDeclRef() << ";\n";
+    }
+    else if(tmpCur2->GetType() == formula::svDouble)
+    {
+        ss << "    beta=" <<tmpCur2->GetDouble() << ";\n";
+    }
+    else
+    {
+        ss << "    return DBL_MAX;\n" << "}\n";
+        return ;
+    }
+    FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
+    assert(tmpCur3);
+    if(tmpCur3->GetType() == formula::svSingleVectorRef)
+    {
+        const formula::SingleVectorRefToken*tmpCurDVR3 =
+            dynamic_cast<const formula::SingleVectorRefToken *>(tmpCur3);
+#ifdef ISNAN
+        ss << "    int buffer_kum_len = ";
+        ss << tmpCurDVR3->GetArrayLength() << ";\n";
+        ss << "    if(gid0>=buffer_kum_len || isNan(";
+        ss << vSubArguments[3]->GenSlidingWindowDeclRef() << "))\n";
+        ss << "        kum = 0.0;\n";
+        ss << "    else\n";
+#endif
+        ss << "        kum = ";
+        ss << vSubArguments[3]->GenSlidingWindowDeclRef() << ";\n";
+    }
+    else if(tmpCur3->GetType() == formula::svDouble)
+    {
+        ss << "    kum=" <<tmpCur3->GetDouble() << ";\n";
+    }
+    else
+    {
+        ss << "    return DBL_MAX;\n" << "}\n";
+        return ;
+    }
+    ss << "    if(alpha<=0.0||beta<=0.0||kum<0.0)\n";
+    ss << "        return DBL_MAX;\n";
+    ss << "    else if(kum==0.0)\n";
+    ss << "    {\n";
+    ss << "        tmp=alpha/pow(beta,alpha)*pow(x,alpha-1.0)";
+    ss << "*exp(-pow(x/beta,alpha));\n";
+    ss << "    }\n";
+    ss << "    else\n";
+    ss << "        tmp=1.0-exp(-pow(x/beta,alpha));\n";
+    ss << "    return tmp;\n";
+    ss << "}\n";
+}
+
 void OpFisher::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 4f09d66..b4d98df 100644
--- a/sc/source/core/opencl/op_statistical.hxx
+++ b/sc/source/core/opencl/op_statistical.hxx
@@ -22,6 +22,14 @@ public:
     virtual std::string BinFuncName(void) const { return "Standard"; }
 };
 
+class OpWeibull: public Normal
+{
+public:
+    virtual void GenSlidingWindowFunction(std::stringstream &ss,
+            const std::string sSymName, SubArguments &vSubArguments);
+    virtual std::string BinFuncName(void) const { return "Weibull"; }
+};
+
 class OpFisher: public Normal
 {
 public:


More information about the Libreoffice-commits mailing list