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

xinjiang xinjiang at multicorewareinc.com
Mon Nov 4 06:41:05 CET 2013


 sc/qa/unit/data/ods/opencl/financial/Duration.ods |binary
 sc/qa/unit/opencl-test.cxx                        |   24 ++++++++++++
 sc/source/core/opencl/formulagroupcl.cxx          |    4 ++
 sc/source/core/opencl/op_financial.cxx            |   42 ++++++++++++++++++++++
 sc/source/core/opencl/op_financial.hxx            |   12 ++++++
 sc/source/core/tool/token.cxx                     |    1 
 6 files changed, 83 insertions(+)

New commits:
commit 6f1aef5e9e3be786e6e841ad100d01a1a0744c8d
Author: xinjiang <xinjiang at multicorewareinc.com>
Date:   Mon Nov 4 11:18:04 2013 +0800

    GPU Calc: implemented DURATION
    
    AMLOEXT-111 FIX
    
    Change-Id: I114e5b20326657f7fd3e0de7162a8ae190059b2a
    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 2362cba..bc758f4 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1016,6 +1016,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
             case ocISPMT:
                 mvSubArguments.push_back(SoPHelper(ts, ft->Children[i], new OpISPMT));
                 break;
+            case ocLaufz:
+                mvSubArguments.push_back(SoPHelper(ts,
+                         ft->Children[i], new OpDuration));
+                break;
             case ocExternal:
                 if ( !(pChild->GetExternal().compareTo(OUString(
                     "com.sun.star.sheet.addin.Analysis.getEffect"))))
diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index f9f1fa6..a40a113 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -531,6 +531,48 @@ void OpISPMT::GenSlidingWindowFunction(std::stringstream& ss,
         ss << "}";
 }
 
+void OpDuration::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 = " << GetBottom() << ";\n";
+        ss << "    int gid0 = get_global_id(0);\n";
+        ss << "    double arg0 = " << GetBottom() << ";\n";
+        ss << "    double arg1 = " << GetBottom() << ";\n";
+        ss << "    double arg2 = " << GetBottom() << ";\n";
+        unsigned i = vSubArguments.size();
+        while (i--)
+        {
+            FormulaToken* pCur = vSubArguments[i]->GetFormulaToken();
+            assert(pCur);
+            if(pCur->GetType() == formula::svSingleVectorRef)
+            {
+#ifdef  ISNAN
+                const formula::SingleVectorRefToken* pSVR =
+                dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
+            ss << "    if(gid0 >= " << pSVR->GetArrayLength() << " || isNan(";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << "))\n";
+            ss << "        arg" << i << " = " <<GetBottom() << ";\n";
+            ss << "    else\n";
+#endif
+            ss << "        arg" << i << " = ";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << ";\n";
+            }
+        }
+        ss << "    tmp = log(arg2 / arg1) / log(arg0 + 1.0);\n";
+        ss << "    return tmp;\n";
+        ss << "}";
+}
 
 void Fvschedule::GenSlidingWindowFunction(
     std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
diff --git a/sc/source/core/opencl/op_financial.hxx b/sc/source/core/opencl/op_financial.hxx
index cd62f82..fc73076 100644
--- a/sc/source/core/opencl/op_financial.hxx
+++ b/sc/source/core/opencl/op_financial.hxx
@@ -97,6 +97,18 @@ public:
     virtual std::string BinFuncName(void) const { return "ISPMT"; }
 };
 
+class OpDuration: public Normal
+{
+public:
+    virtual std::string GetBottom(void) { return "0"; }
+
+    virtual void GenSlidingWindowFunction(std::stringstream& ss,
+            const std::string sSymName, SubArguments& vSubArguments);
+
+    virtual std::string BinFuncName(void) const { return "Duration"; }
+};
+
+
 class Fvschedule: public Normal
 {
 public:
commit feb89290371033110c9a3a62426e716bfafc9778
Author: xinjiang <xinjiang at multicorewareinc.com>
Date:   Mon Nov 4 11:12:17 2013 +0800

    GPU Calc: unit test cases for DURATION
    
    AMLOEXT-111 BUG
    
    Change-Id: I1d206b0eda0dca8254f0491399d0a4679eb39ef8
    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/ods/opencl/financial/Duration.ods b/sc/qa/unit/data/ods/opencl/financial/Duration.ods
new file mode 100644
index 0000000..d884dfe
Binary files /dev/null and b/sc/qa/unit/data/ods/opencl/financial/Duration.ods differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index d41046b..6654517 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -122,6 +122,7 @@ public:
     void testFinacialPPMTFormula();
     void testFinancialISPMTFormula();
     void testFinacialPriceFormula();
+    void testFinancialDurationFormula();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -173,6 +174,7 @@ public:
     CPPUNIT_TEST(testFinacialPMTFormula);
     CPPUNIT_TEST(testFinancialISPMTFormula);
     CPPUNIT_TEST(testFinacialPriceFormula);
+    CPPUNIT_TEST(testFinancialDurationFormula);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -1610,6 +1612,28 @@ void ScOpenclTest:: testFinacialPMTFormula()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
+//[AMLOEXT-111]
+void ScOpenclTest:: testFinancialDurationFormula()
+{
+    if (!detectOpenCLDevice())
+        return;
+    ScDocShellRef xDocSh = loadDoc("opencl/financial/Duration.", ODS);
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+    ScDocShellRef xDocShRes = loadDoc("opencl/financial/Duration.", ODS);
+    ScDocument* pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    for (SCROW i = 0; i <= 9; ++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-119]
 void ScOpenclTest:: testFinacialPPMTFormula()
 {
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 0cf62f4..5845c63 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1367,6 +1367,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
             case ocCosecant:
             case ocCosecantHyp:
             case ocISPMT:
+            case ocLaufz:
             // Don't change the state.
             break;
             default:


More information about the Libreoffice-commits mailing list