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

xinjiang xinjiang at multicorewareinc.com
Mon Nov 4 05:59:47 CET 2013


 sc/qa/unit/data/xls/opencl/financial/ISPMT.xls |binary
 sc/qa/unit/opencl-test.cxx                     |   24 +++++++++++++
 sc/source/core/opencl/formulagroupcl.cxx       |    3 +
 sc/source/core/opencl/op_financial.cxx         |   45 +++++++++++++++++++++++++
 sc/source/core/opencl/op_financial.hxx         |   11 ++++++
 sc/source/core/tool/token.cxx                  |    1 
 6 files changed, 84 insertions(+)

New commits:
commit 2cfd2307ac641f251dc3276f12b32b5a617cef24
Author: xinjiang <xinjiang at multicorewareinc.com>
Date:   Mon Nov 4 10:40:51 2013 +0800

    GPU Calc: implemented ISPMT in GPU calc
    
    AMLOEXT-99 FIX
    
    Change-Id: I8cd9f130c190e6925873a00579cb7c334201f418
    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 b4bb0f9..b47e192 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1013,6 +1013,9 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
             case ocCosecant:
                 mvSubArguments.push_back(SoPHelper(ts, ft->Children[i], new OpCsc));
                 break;
+            case ocISPMT:
+                mvSubArguments.push_back(SoPHelper(ts, ft->Children[i], new OpISPMT));
+                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 329dd77..503087b 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -487,6 +487,51 @@ void OpINTRATE::GenSlidingWindowFunction(
     ss << "}";
 }
 
+void OpISPMT::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";
+        ss << "    double arg3 = " << 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 = arg3 * arg0 * ( arg1 / arg2 - 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 7a79dde..6add67f 100644
--- a/sc/source/core/opencl/op_financial.hxx
+++ b/sc/source/core/opencl/op_financial.hxx
@@ -86,6 +86,17 @@ public:
     virtual std::string BinFuncName(void) const { return "INTRATE"; }
 };
 
+class OpISPMT: 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 "ISPMT"; }
+};
+
 class Fvschedule: public Normal
 {
 public:
commit c7a6959004bcacc2d971b0697a57b08b7b3f9931
Author: xinjiang <xinjiang at multicorewareinc.com>
Date:   Mon Nov 4 10:36:28 2013 +0800

    GPU Calc: unit test cases for ISPMT in GPU calc
    
    AMLOEXT-99 BUG
    
    Change-Id: I4388b184b23cf616dacfb20c61d2295765925ede
    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/financial/ISPMT.xls b/sc/qa/unit/data/xls/opencl/financial/ISPMT.xls
new file mode 100644
index 0000000..8759e7e
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/financial/ISPMT.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 043c99f..dd3630e 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -120,6 +120,7 @@ public:
     void testFinacialYIELDMATFormula();
     void testFinacialPMTFormula();
     void testFinacialPPMTFormula();
+    void testFinancialISPMTFormula();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -169,6 +170,7 @@ public:
     CPPUNIT_TEST(testFinacialYIELDMATFormula);
     CPPUNIT_TEST(testFinacialPPMTFormula);
     CPPUNIT_TEST(testFinacialPMTFormula);
+    CPPUNIT_TEST(testFinancialISPMTFormula);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -1260,6 +1262,28 @@ void ScOpenclTest::testFinacialXNPVFormula()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
+//[AMLOEXT-99]
+void ScOpenclTest:: testFinancialISPMTFormula()
+{
+    if (!detectOpenCLDevice())
+        return;
+    ScDocShellRef xDocSh = loadDoc("opencl/financial/ISPMT.", XLS);
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+    ScDocShellRef xDocShRes = loadDoc("opencl/financial/ISPMT.", XLS);
+    ScDocument* pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    for (SCROW i = 0; i <= 9; ++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();
+}
 void ScOpenclTest::testFinacialPriceMatFormula()
 {
     if (!detectOpenCLDevice())
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 89dcf9a..0cf62f4 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1366,6 +1366,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
             case ocCos:
             case ocCosecant:
             case ocCosecantHyp:
+            case ocISPMT:
             // Don't change the state.
             break;
             default:


More information about the Libreoffice-commits mailing list