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

xinjiang xinjiang at multicorewareinc.com
Tue Nov 12 18:45:52 PST 2013


 sc/qa/unit/data/xls/opencl/financial/Duration_ADD.xls |binary
 sc/qa/unit/opencl-test.cxx                            |   25 +++++++
 sc/source/core/opencl/formulagroupcl.cxx              |    6 +
 sc/source/core/opencl/op_financial.cxx                |   60 ++++++++++++++++++
 sc/source/core/opencl/op_financial.hxx                |   14 ++++
 sc/source/core/opencl/opinlinefun_finacial.cxx        |   32 +++++++++
 6 files changed, 136 insertions(+), 1 deletion(-)

New commits:
commit 20029a72b3bb9a119e99bff7974bf6bb20e17924
Author: xinjiang <xinjiang at multicorewareinc.com>
Date:   Tue Nov 5 09:31:14 2013 +0800

    GPU Calc: unit test cases for DURATION_ADD
    
    Need open macro NO_FALLBACK_TO_SWINTERP in formulagroupcl.cxx for test
    
    AMLOEXT-121 BUG
    
    Change-Id: Id78c89f77cdfe14d368831c22ff708b968e8fee2
    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/Duration_ADD.xls b/sc/qa/unit/data/xls/opencl/financial/Duration_ADD.xls
new file mode 100644
index 0000000..18e5ddb
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/financial/Duration_ADD.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index b593174..b040e32 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -131,6 +131,7 @@ public:
     void testStatisticalFormulaStandard();
     void testStatisticalFormulaWeibull();
     void testStatisticalFormulaMedian();
+    void testFinancialDuration_ADDFormula();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -193,6 +194,7 @@ public:
     CPPUNIT_TEST(testStatisticalFormulaStandard);
     CPPUNIT_TEST(testStatisticalFormulaWeibull);
     CPPUNIT_TEST(testStatisticalFormulaMedian);
+    CPPUNIT_TEST(testFinancialDuration_ADDFormula);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -1902,7 +1904,28 @@ void ScOpenclTest:: testFinacialPPMTFormula()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
-
+//[AMLOEXT-121]
+void ScOpenclTest:: testFinancialDuration_ADDFormula()
+{
+    if (!detectOpenCLDevice())
+        return;
+    ScDocShellRef xDocSh = loadDoc("opencl/financial/Duration_ADD.", XLS);
+    ScDocument* pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+    ScDocShellRef xDocShRes = loadDoc("opencl/financial/Duration_ADD.", XLS);
+    ScDocument* pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    for (SCROW i = 0; i <= 9; ++i)
+    {
+        double fLibre = pDoc->GetValue(ScAddress(6, i, 0));
+        double fExcel = pDocRes->GetValue(ScAddress(6, i, 0));
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel));
+    }
+    xDocSh->DoClose();
+    xDocShRes->DoClose();
+}
 ScOpenclTest::ScOpenclTest()
       : ScBootstrapFixture( "/sc/qa/unit/data" )
 {
commit 9425b3a938faf2df4d58acdcaf4437dc52ebd23c
Author: xinjiang <xinjiang at multicorewareinc.com>
Date:   Tue Nov 5 09:47:10 2013 +0800

    GPU Calc: implement fix for DURATION_ADD
    
    AMLOEXT-121 FIX
    
    Change-Id: Ie6b10eacc4e5fc0b2dcfe816982836b8b244af05
    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 c6ae8e8..6d613a4 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1179,6 +1179,12 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
                     mvSubArguments.push_back(SoPHelper(ts, ft->Children[i],
                         new OpCoupnum));
                 }
+                else if ( !(pChild->GetExternal().compareTo(OUString(
+                   "com.sun.star.sheet.addin.Analysis.getDuration"))))
+                {
+                    mvSubArguments.push_back(
+                        SoPHelper(ts, ft->Children[i], new OpDuration_ADD));
+                }
                 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 cb31cd1..1db9119 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -574,6 +574,66 @@ void OpDuration::GenSlidingWindowFunction(std::stringstream& ss,
         ss << "}";
 }
 
+void OpDuration_ADD::BinInlineFun(std::set<std::string>& decls,
+    std::set<std::string>& funs)
+{
+    decls.insert(GetDurationDecl);decls.insert(lcl_GetcoupnumDecl);
+    decls.insert(GetYearFracDecl);decls.insert(DaysToDateDecl);
+    decls.insert(GetNullDateDecl);decls.insert(DateToDaysDecl);
+    decls.insert(DaysInMonthDecl);decls.insert(IsLeapYearDecl);
+    funs.insert(GetDuration);funs.insert(lcl_Getcoupnum);
+    funs.insert(GetYearFrac);funs.insert(DaysToDate);
+    funs.insert(GetNullDate);funs.insert(DateToDays);
+    funs.insert(DaysInMonth);funs.insert(IsLeapYear);
+}
+
+void OpDuration_ADD::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";
+    ss << "    double arg4 = " << GetBottom() << ";\n";
+    ss << "    double arg5 = " << GetBottom() << ";\n";
+    unsigned j = vSubArguments.size();
+    while (j--)
+    {
+        FormulaToken* pCur = vSubArguments[j]->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[j]->GenSlidingWindowDeclRef();
+            ss << "))\n";
+            ss << "        arg" << j << " = " <<GetBottom() << ";\n";
+            ss << "    else\n";
+#endif
+            ss << "        arg" << j << " = ";
+            ss << vSubArguments[j]->GenSlidingWindowDeclRef();
+            ss << ";\n";
+            }
+        }
+    ss << "    int nNullDate = GetNullDate(30, 12, 1899);\n";
+    ss << "    tmp = GetDuration( nNullDate, (int)arg0, (int)arg1, arg2,";
+    ss << " arg3, (int)arg4, (int)arg5);\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 544fc5f..f48b650 100644
--- a/sc/source/core/opencl/op_financial.hxx
+++ b/sc/source/core/opencl/op_financial.hxx
@@ -108,6 +108,20 @@ public:
     virtual std::string BinFuncName(void) const { return "Duration"; }
 };
 
+class OpDuration_ADD: 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 "Duration_ADD"; }
+};
+
 
 class Fvschedule: public Normal
 {
diff --git a/sc/source/core/opencl/opinlinefun_finacial.cxx b/sc/source/core/opencl/opinlinefun_finacial.cxx
index 27a1625..86f93eb 100644
--- a/sc/source/core/opencl/opinlinefun_finacial.cxx
+++ b/sc/source/core/opencl/opinlinefun_finacial.cxx
@@ -964,6 +964,38 @@ std::string GetDiffDate360=
 "nDay2, nMonth2, nYear2, bUSAMethod );\n"
 "}\n";
 
+std::string GetDurationDecl=
+"double GetDuration( \n"
+"                int nNullDate, int nSettle, int nMat, double fCoup,\n"
+"                double fYield, int nFreq, int nBase );\n";
+
+std::string GetDuration=
+"double GetDuration( \n"
+"                int nNullDate, int nSettle, int nMat, double fCoup,\n"
+"                double fYield, int nFreq, int nBase )\n"
+"{\n"
+"    double fYearfrac = GetYearFrac( nNullDate, nSettle, nMat, nBase );\n"
+"    double fNumOfCoups = lcl_Getcoupnum(nNullDate,nSettle,nMat,nFreq);\n"
+"    double fDur = 0.0;\n"
+"    double f100 = 100.0;\n"
+"    fCoup *= f100 / nFreq;\n"
+"    fYield /= nFreq;\n"
+"    fYield += 1.0;\n"
+"    double nDiff = fYearfrac * nFreq - fNumOfCoups;\n"
+"    int  t;\n"
+"    for( t = 1 ; t < fNumOfCoups ; t++ )\n"
+"        fDur += ( t + nDiff ) * ( fCoup ) / pow( fYield, t + nDiff );\n"
+"    fDur += ( fNumOfCoups + nDiff ) * ( fCoup + f100 ) /"
+" pow( fYield, fNumOfCoups + nDiff );\n"
+"    double  p = 0.0;\n"
+"    for( t = 1 ; t < fNumOfCoups ; t++ )\n"
+"      p += fCoup / pow( fYield, t + nDiff );\n"
+"    p += ( fCoup + f100 ) / pow( fYield, fNumOfCoups + nDiff );\n"
+"    fDur /= p;\n"
+"    fDur /= nFreq;\n"
+"    return fDur;\n""}\n";
+
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list