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

minwang min at multicorewareinc.com
Tue Nov 12 19:32:50 PST 2013


 sc/qa/unit/data/xls/opencl/financial/Amorlinc.xls |binary
 sc/qa/unit/opencl-test.cxx                        |   24 +++
 sc/source/core/opencl/formulagroupcl.cxx          |    6 
 sc/source/core/opencl/op_financial.cxx            |  154 +++++++++++++++++++++-
 sc/source/core/opencl/op_financial.hxx            |    9 +
 5 files changed, 192 insertions(+), 1 deletion(-)

New commits:
commit 89ed6a0e150549fb5aa00f06216637ea71b04f30
Author: minwang <min at multicorewareinc.com>
Date:   Tue Nov 5 10:28:57 2013 +0800

    GPU Calc: unit test cases for AMORLINC in GPU calc
    
    Need open macro NO_FALLBACK_TO_SWINTERP in formulagroupcl.cxx for test
    
    AMLOEXT-110 BUG
    
    Change-Id: Ia6e1333e7d1c91ff9b8a916109a8aa60f4725e03
    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/Amorlinc.xls b/sc/qa/unit/data/xls/opencl/financial/Amorlinc.xls
new file mode 100644
index 0000000..5962334
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/financial/Amorlinc.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 3c395c4..bc26113 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -133,6 +133,7 @@ public:
     void testStatisticalFormulaMedian();
     void testFinancialDuration_ADDFormula();
     void testFinancialAmordegrcFormula();
+    void testFinancialAmorlincFormula();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -197,6 +198,7 @@ public:
     CPPUNIT_TEST(testStatisticalFormulaMedian);
     CPPUNIT_TEST(testFinancialDuration_ADDFormula);
     CPPUNIT_TEST(testFinancialAmordegrcFormula);
+    CPPUNIT_TEST(testFinancialAmorlincFormula);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -1583,6 +1585,28 @@ void ScOpenclTest::testStatisticalFormulaMedian()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
+//[AMLOEXT-110]
+void ScOpenclTest::testFinancialAmorlincFormula()
+{
+    if (!detectOpenCLDevice())
+        return;
+    ScDocShellRef xDocSh = loadDoc("opencl/financial/Amorlinc.", XLS);
+    ScDocument *pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+    ScDocShellRef xDocShRes = loadDoc("opencl/financial/Amorlinc.", XLS);
+    ScDocument *pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    for (SCROW i = 0; i <= 9; ++i)
+    {
+        double fLibre = pDoc->GetValue(ScAddress(7, i, 0));
+        double fExcel = pDocRes->GetValue(ScAddress(7, i, 0));
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel));
+    }
+    xDocSh->DoClose();
+    xDocShRes->DoClose();
+}
 void ScOpenclTest::testFinacialPriceMatFormula()
 {
     if (!detectOpenCLDevice())
commit 7b33d0c12d487d953634fa1e06c6902124455e38
Author: minwang <min at multicorewareinc.com>
Date:   Tue Nov 5 10:33:53 2013 +0800

    GPU Calc: implement fix for AMORLINC in GPU calc
    
    AMLOEXT-110 FIX
    
    Change-Id: I068924cc83288261102ea03e29449e0faf8686f9
    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 fe0b8f8..55d2f25 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1191,6 +1191,12 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
                     mvSubArguments.push_back(SoPHelper(ts, ft->Children[i],
                         new OpAmordegrc));
                 }
+                else if ( !(pChild->GetExternal().compareTo(OUString(
+                   "com.sun.star.sheet.addin.Analysis.getAmorlinc"))))
+                {
+                    mvSubArguments.push_back(SoPHelper(ts, ft->Children[i],
+                        new OpAmorlinc));
+                }
                 break;
             default:
                 throw UnhandledToken(pChild, "unhandled opcode");
diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index 5e2509a..92a7f14 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -3063,7 +3063,159 @@ void OpAmordegrc::GenSlidingWindowFunction(std::stringstream &ss,
     ss <<"    return tmp;\n";
     ss <<"}";
 }
-
+void OpAmorlinc::BinInlineFun(std::set<std::string>& decls,
+    std::set<std::string>& funs)
+{
+    decls.insert(nKorrValDecl); decls.insert(RoundDecl);
+    decls.insert(IsLeapYearDecl);decls.insert(DaysInMonthDecl);
+    decls.insert(DaysToDateDecl); decls.insert(DateToDaysDecl);
+    decls.insert(GetNullDateDecl); decls.insert(GetYearFracDecl);
+    funs.insert(Round);
+    funs.insert(IsLeapYear);funs.insert(DaysInMonth);
+    funs.insert(DaysToDate);funs.insert(DateToDays);
+    funs.insert(GetNullDate);funs.insert(GetYearFrac);
+}
+void OpAmorlinc::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 = " << GetBottom() <<";\n";
+    ss << "    double fCost,fRestVal,fPer,fRate;\n";
+    ss << "    int nDate,nFirstPer,nBase;\n";
+#ifdef ISNAN
+    FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
+    const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
+    formula::SingleVectorRefToken *>(tmpCur0);
+    FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
+    const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
+    formula::SingleVectorRefToken *>(tmpCur1);
+    FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
+    const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
+    formula::SingleVectorRefToken *>(tmpCur2);
+    FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
+    const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const
+    formula::SingleVectorRefToken *>(tmpCur3);
+    FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
+    const formula::SingleVectorRefToken*tmpCurDVR4= dynamic_cast<const
+    formula::SingleVectorRefToken *>(tmpCur4);
+    FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken();
+    const formula::SingleVectorRefToken*tmpCurDVR5= dynamic_cast<const
+    formula::SingleVectorRefToken *>(tmpCur5);
+    FormulaToken *tmpCur6 = vSubArguments[6]->GetFormulaToken();
+    const formula::SingleVectorRefToken*tmpCurDVR6= dynamic_cast<const
+    formula::SingleVectorRefToken *>(tmpCur6);
+    ss<< "    int buffer_Cost_len = ";
+    ss<< tmpCurDVR0->GetArrayLength();
+    ss<< ";\n";
+    ss<< "    int buffer_Date_len = ";
+    ss<< tmpCurDVR1->GetArrayLength();
+    ss << ";\n";
+    ss<< "    int buffer_FirstPer_len = ";
+    ss<< tmpCurDVR2->GetArrayLength();
+    ss << ";\n";
+    ss<< "    int buffer_RestVal_len = ";
+    ss<< tmpCurDVR3->GetArrayLength();
+    ss << ";\n";
+    ss<< "    int buffer_Per_len = ";
+    ss<< tmpCurDVR4->GetArrayLength();
+    ss << ";\n";
+    ss<< "    int buffer_Rate_len = ";
+    ss<< tmpCurDVR5->GetArrayLength();
+    ss << ";\n";
+    ss<< "    int buffer_Base_len = ";
+    ss<< tmpCurDVR6->GetArrayLength();
+    ss << ";\n";
+#endif
+#ifdef ISNAN
+    ss <<"    if(gid0 >= buffer_Cost_len || isNan(";
+    ss <<vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss <<"))\n";
+    ss <<"        fCost = 0;\n    else\n";
+#endif
+    ss << "        fCost=";
+    ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+    ss <<";\n";
+#ifdef ISNAN
+    ss <<"    if(gid0 >= buffer_Date_len || isNan(";
+    ss <<vSubArguments[1]->GenSlidingWindowDeclRef();
+    ss <<"))\n";
+    ss <<"        nDate = 0;\n    else\n";
+#endif
+    ss << "        nDate=(int)";
+    ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+    ss << ";\n";
+#ifdef ISNAN
+    ss <<"    if(gid0 >= buffer_FirstPer_len || isNan(";
+    ss <<vSubArguments[2]->GenSlidingWindowDeclRef();
+    ss <<"))\n";
+    ss <<"        nFirstPer = 0;\n    else\n";
+#endif
+    ss << "        nFirstPer=(int)";
+    ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+    ss <<";\n";
+#ifdef ISNAN
+    ss <<"    if(gid0 >= buffer_RestVal_len || isNan(";
+    ss <<vSubArguments[3]->GenSlidingWindowDeclRef();
+    ss <<"))\n";
+    ss <<"        fRestVal = 0;\n    else\n";
+#endif
+    ss << "        fRestVal=";
+    ss << vSubArguments[3]->GenSlidingWindowDeclRef();
+    ss << ";\n";
+#ifdef ISNAN
+    ss <<"    if(gid0 >= buffer_Per_len || isNan(";
+    ss <<vSubArguments[4]->GenSlidingWindowDeclRef();
+    ss <<"))\n";
+    ss <<"        fPer = 0;\n    else\n";
+#endif
+    ss << "        fPer = ";
+    ss << vSubArguments[4]->GenSlidingWindowDeclRef();
+    ss <<";\n";
+#ifdef ISNAN
+    ss <<"    if(gid0 >= buffer_Rate_len || isNan(";
+    ss <<vSubArguments[5]->GenSlidingWindowDeclRef();
+    ss <<"))\n";
+    ss <<"        fRate = 0;\n    else\n";
+#endif
+    ss << "        fRate=";
+    ss << vSubArguments[5]->GenSlidingWindowDeclRef();
+    ss << ";\n";
+#ifdef ISNAN
+    ss <<"    if(gid0 >= buffer_Base_len || isNan(";
+    ss <<vSubArguments[6]->GenSlidingWindowDeclRef();
+    ss <<"))\n";
+    ss <<"        nBase = 0;\n    else\n";
+#endif
+    ss << "        nBase = (int)";
+    ss << vSubArguments[6]->GenSlidingWindowDeclRef();
+    ss << ";\n";
+    ss <<"    int  nPer = convert_int( fPer );\n";
+    ss <<"    double fOneRate = fCost * fRate;\n";
+    ss <<"    double fCostDelta = fCost - fRestVal;\n";
+    ss <<"    double f0Rate = GetYearFrac( GetNullDate(),";
+    ss <<"nDate, nFirstPer, nBase )* fRate * fCost;\n";
+    ss <<"    int nNumOfFullPeriods = (int)";
+    ss <<"( ( fCost - fRestVal - f0Rate) /fOneRate );\n";
+    ss <<"    if( nPer == 0 )\n";
+    ss <<"        tmp = f0Rate;\n";
+    ss <<"    else if( nPer <= nNumOfFullPeriods )\n";
+    ss <<"        tmp = fOneRate;\n";
+    ss <<"    else if( nPer == nNumOfFullPeriods + 1 )\n";
+    ss <<"        tmp = fCostDelta - fOneRate * nNumOfFullPeriods - f0Rate;\n";
+    ss <<"    else\n";
+    ss <<"        tmp = 0.0;\n";
+    ss <<"    return tmp;\n";
+    ss <<"}";
+}
 void OpReceived::BinInlineFun(std::set<std::string>& decls,
     std::set<std::string>& funs)
 {
diff --git a/sc/source/core/opencl/op_financial.hxx b/sc/source/core/opencl/op_financial.hxx
index 070d2bb..fbf5bee 100644
--- a/sc/source/core/opencl/op_financial.hxx
+++ b/sc/source/core/opencl/op_financial.hxx
@@ -348,6 +348,15 @@ public:
     virtual void BinInlineFun(std::set<std::string>& ,std::set<std::string>&);
     virtual std::string BinFuncName(void) const { return "Amordegrc"; }
 };
+class OpAmorlinc:public Normal
+{
+public:
+    virtual std::string GetBottom(void) { return "0";}
+    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 "Amorlinc"; }
+};
 
 class OpReceived:public Normal
 {


More information about the Libreoffice-commits mailing list