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

shiming zhang shiming at multicorewareinc.com
Tue Nov 5 22:24:07 CET 2013


 sc/qa/unit/data/xls/opencl/statistical/Standard.xls |binary
 sc/qa/unit/opencl-test.cxx                          |   27 +++++
 sc/source/core/opencl/formulagroupcl.cxx            |    4 
 sc/source/core/opencl/op_statistical.cxx            |  107 ++++++++++++++++++++
 sc/source/core/opencl/op_statistical.hxx            |    8 +
 sc/source/core/tool/token.cxx                       |    1 
 6 files changed, 147 insertions(+)

New commits:
commit f1d75291e3e04c636b4dc2c44827d85b0263c46b
Author: shiming zhang <shiming at multicorewareinc.com>
Date:   Mon Nov 4 17:05:54 2013 +0800

    GPU Calc: implemented STANDARDIZE
    
    AMLOEXT-77 FIX
    
    Change-Id: I5f91d497417e87a489728949a4436f33ed3da235
    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 cd040d6..a68188c 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1044,6 +1044,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
                 mvSubArguments.push_back(SoPHelper(ts,
                          ft->Children[i], new OpTanH));
                 break;
+            case ocStandard:
+                mvSubArguments.push_back(SoPHelper(ts,
+                         ft->Children[i], new OpStandard));
+                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 134a0ca..4128507 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -22,6 +22,113 @@ using namespace formula;
 
 namespace sc { namespace opencl {
 
+void OpStandard::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,mu,sigma;\n";
+    if(vSubArguments.size() != 3)
+    {
+        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_mu_len = ";
+        ss << tmpCurDVR1->GetArrayLength() << ";\n";
+        ss << "    if(gid0>=buffer_mu_len || isNan(";
+        ss << vSubArguments[1]->GenSlidingWindowDeclRef() << "))\n";
+        ss << "        mu = 0.0;\n";
+        ss << "    else\n";
+#endif
+        ss << "        mu = ";
+        ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
+    }
+    else if(tmpCur1->GetType() == formula::svDouble)
+    {
+        ss << "    mu=" <<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_sigma_len = ";
+        ss << tmpCurDVR2->GetArrayLength() << ";\n";
+        ss << "    if(gid0>=buffer_sigma_len || isNan(";
+        ss << vSubArguments[2]->GenSlidingWindowDeclRef() << "))\n";
+        ss << "        sigma = 0.0;\n";
+        ss << "    else\n";
+#endif
+        ss << "        sigma = ";
+        ss << vSubArguments[2]->GenSlidingWindowDeclRef() << ";\n";
+    }
+    else if(tmpCur2->GetType() == formula::svDouble)
+    {
+        ss << "    sigma=" <<tmpCur2->GetDouble() << ";\n";
+    }
+    else
+    {
+        ss << "    return DBL_MAX;\n" << "}\n";
+        return ;
+    }
+    ss << "    if(" << "sigma" << "<=0)\n";
+    ss << "        tmp=DBL_MAX;\n";
+    ss << "    else\n";
+    ss << "        tmp=(" << "x" << "-" << "mu" << ")/" << "sigma" << ";\n";
+    ss << "    return tmp;\n";
+    ss << "}";
+}
+
 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 e92ab82..4f09d66 100644
--- a/sc/source/core/opencl/op_statistical.hxx
+++ b/sc/source/core/opencl/op_statistical.hxx
@@ -14,6 +14,14 @@
 
 namespace sc { namespace opencl {
 
+class OpStandard: public Normal
+{
+public:
+    virtual void GenSlidingWindowFunction(std::stringstream &ss,
+            const std::string sSymName, SubArguments &vSubArguments);
+    virtual std::string BinFuncName(void) const { return "Standard"; }
+};
+
 class OpFisher: public Normal
 {
 public:
commit f7cd30228fea8426d2652df5f673808a1032ebe0
Author: shiming zhang <shiming at multicorewareinc.com>
Date:   Mon Nov 4 16:58:38 2013 +0800

    GPU Calc: unit test cases for STANDARDIZE
    
    Need open macro NO_FALLBACK_TO_SWINTERP in formulagroupcl.cxx for test
    
    AMLOEXT-77 BUG
    
    Change-Id: Ie2919ca8d99e19ff2d17fe9d7fc3fbe2a49a4e05
    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/Standard.xls b/sc/qa/unit/data/xls/opencl/statistical/Standard.xls
new file mode 100644
index 0000000..fe735e5
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/statistical/Standard.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 87414c0..d108f83 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -128,6 +128,7 @@ public:
     void testMathFormulaSin();
     void testMathFormulaTan();
     void testMathFormulaTanH();
+    void testStatisticalFormulaStandard();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -187,6 +188,7 @@ public:
     CPPUNIT_TEST(testMathFormulaSin);
     CPPUNIT_TEST(testMathFormulaTan);
     CPPUNIT_TEST(testMathFormulaTanH);
+    CPPUNIT_TEST(testStatisticalFormulaStandard);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -1359,6 +1361,31 @@ void ScOpenclTest::testFinacialINTRATEFormula()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
+//[AMLOEXT-77]
+void ScOpenclTest::testStatisticalFormulaStandard()
+{
+    if (!detectOpenCLDevice())
+        return;
+
+    ScDocShellRef xDocSh = loadDoc("opencl/statistical/Standard.", XLS);
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+
+    ScDocShellRef xDocShRes = loadDoc("opencl/statistical/Standard.", 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(3,i,0));
+        double fExcel = pDocRes->GetValue(ScAddress(3,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 ee9e1ce..2de1508 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1374,6 +1374,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
             case ocSin:
             case ocTan:
             case ocTanHyp:
+            case ocStandard:
             // Don't change the state.
             break;
             default:


More information about the Libreoffice-commits mailing list