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

xinjiang xinjiang at multicorewareinc.com
Tue Nov 12 19:02:56 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 163fd27708ab56baf731d9c65ccc7a5120024f45
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 69c8c3e..3ecd34c 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -133,6 +133,7 @@ public:
     void testStatisticalFormulaStandard();
     void testStatisticalFormulaWeibull();
     void testStatisticalFormulaMedian();
+    void testFinancialDuration_ADDFormula();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -195,6 +196,7 @@ public:
     CPPUNIT_TEST(testStatisticalFormulaStandard);
     CPPUNIT_TEST(testStatisticalFormulaWeibull);
     CPPUNIT_TEST(testStatisticalFormulaMedian);
+    CPPUNIT_TEST(testFinancialDuration_ADDFormula);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -1904,7 +1906,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 159bc70c590e2efb74fc1234480b43cff220731b
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 96e8f0f..fec3a68 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 3597f9f..0b46835 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