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

I-Jui Sung (Ray) ray at multicorewareinc.com
Mon Nov 4 06:16:56 CET 2013


 sc/qa/unit/data/xls/opencl/financial/Price.xls |binary
 sc/qa/unit/opencl-test.cxx                     |   25 +
 sc/source/core/opencl/formulagroupcl.cxx       |    6 
 sc/source/core/opencl/op_financial.cxx         |  371 +++++++++++++++++--------
 sc/source/core/opencl/op_financial.hxx         |    8 
 5 files changed, 294 insertions(+), 116 deletions(-)

New commits:
commit 1834860a3233a0af5f093d06dc631feefa5716d3
Author: I-Jui (Ray) Sung <ray at multicorewareinc.com>
Date:   Sun Nov 3 23:15:04 2013 -0600

    GPU Calc: refactor op_financial.cxx to fix warning and bad indentation
    
    Change-Id: I93db1e5d2b03904a3d7787cc16f642ebf4752d85

diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index fb6610e..f9f1fa6 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -2155,241 +2155,239 @@ void OpPrice::GenSlidingWindowFunction(std::stringstream &ss,
     ss<<"double tmp3=0;\n    ";
     ss<<"double tmp4=0,tmp5=0;\n    ";
     ss<<"double tmp6=0;\n    ";
-    unsigned i = vSubArguments.size();
     size_t nItems = 0;
     ss <<"\n    ";
-    //while (i-- > 1)
-   for (size_t i = 0; i < vSubArguments.size(); i++)
-   {
-       FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
-       assert(pCur);
-       if (pCur->GetType() == formula::svDoubleVectorRef)
-       {
-           const formula::DoubleVectorRefToken* pDVR =
-           dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
-           size_t nCurWindowSize = pDVR->GetRefRowSize();
-           ss << "for (int i = ";
-           if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
+    for (size_t i = 0; i < vSubArguments.size(); i++)
+    {
+        FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
+        assert(pCur);
+        if (pCur->GetType() == formula::svDoubleVectorRef)
+        {
+            const formula::DoubleVectorRefToken* pDVR =
+                dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+            size_t nCurWindowSize = pDVR->GetRefRowSize();
+            ss << "for (int i = ";
+            if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
 #ifdef  ISNAN
-               ss << "gid0; i < " << pDVR->GetArrayLength();
-               ss << " && i < " << nCurWindowSize  << "; i++){\n        ";
+                ss << "gid0; i < " << pDVR->GetArrayLength();
+                ss << " && i < " << nCurWindowSize  << "; i++){\n        ";
 #else
-               ss << "gid0; i < "<< nCurWindowSize << "; i++)\n        ";
+                ss << "gid0; i < "<< nCurWindowSize << "; i++)\n        ";
 #endif
-           } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
+            } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
 #ifdef  ISNAN
-               ss << "0; i < " << pDVR->GetArrayLength();
-               ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n        ";
+                ss << "0; i < " << pDVR->GetArrayLength();
+                ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n        ";
 #else
-               ss << "0; i < gid0+"<< nCurWindowSize << "; i++)\n        ";
+                ss << "0; i < gid0+"<< nCurWindowSize << "; i++)\n        ";
 #endif
-           } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
+            } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
 #ifdef  ISNAN
-               ss << "0; i + gid0 < " << pDVR->GetArrayLength();
-               ss << " &&  i < "<< nCurWindowSize << "; i++){\n        ";
+                ss << "0; i + gid0 < " << pDVR->GetArrayLength();
+                ss << " &&  i < "<< nCurWindowSize << "; i++){\n        ";
 #else
-               ss << "0; i < "<< nCurWindowSize << "; i++)\n        ";
+                ss << "0; i < "<< nCurWindowSize << "; i++)\n        ";
 #endif
-           }
-           else {
+            }
+            else {
 #ifdef  ISNAN
-               ss << "0; i < "<< nCurWindowSize << "; i++){\n        ";
+                ss << "0; i < "<< nCurWindowSize << "; i++){\n        ";
 #else
-               ss << "0; i < "<< nCurWindowSize << "; i++)\n        ";
+                ss << "0; i < "<< nCurWindowSize << "; i++)\n        ";
 #endif
-           }
-           nItems += nCurWindowSize;
-       }
-       else if (pCur->GetType() == formula::svSingleVectorRef)
-       {
+            }
+            nItems += nCurWindowSize;
+        }
+        else if (pCur->GetType() == formula::svSingleVectorRef)
+        {
 #ifdef  ISNAN
-               const formula::SingleVectorRefToken* pSVR =
-               dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
-           ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n        ";
+            const formula::SingleVectorRefToken* pSVR =
+                dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
+            ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n        ";
 #else
-           nItems += 1;
+            nItems += 1;
 #endif
-       }
-       else if (pCur->GetType() == formula::svDouble)
-       {
+        }
+        else if (pCur->GetType() == formula::svDouble)
+        {
 #ifdef  ISNAN
-           ss << "{\n        ";
+            ss << "{\n        ";
 #endif
-           nItems += 1;
-       }
-       else
-       {
+            nItems += 1;
+        }
+        else
+        {
 #ifdef  ISNAN
 #endif
-           nItems += 1;
-       }
+            nItems += 1;
+        }
 #ifdef  ISNAN
-       if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
-       {
-           ss << "if (isNan(";
-           ss << vSubArguments[i]->GenSlidingWindowDeclRef();
-           ss << "))\n            ";
-           ss << "tmp"<<i<<"= 0;\n        ";
-           ss << "else\n            ";
-           ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
-           ss << ";\n    }\n    ";
-       }
-       else
-       {
-           ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
-           ss <<";\n    ";
-       }
+        if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
+        {
+            ss << "if (isNan(";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << "))\n            ";
+            ss << "tmp"<<i<<"= 0;\n        ";
+            ss << "else\n            ";
+            ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << ";\n    }\n    ";
+        }
+        else
+        {
+            ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss <<";\n    ";
+        }
 #else
-   ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
-   ss <<";\n    ";
+        ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
+        ss <<";\n    ";
 #endif
-   }
-      ss << "tmp = getPrice_(tmp0,tmp1,tmp2,tmp3,tmp4,tmp5,tmp6);\n\t";
-      ss << "return tmp;\n";
-      ss << "}";
+    }
+    ss << "tmp = getPrice_(tmp0,tmp1,tmp2,tmp3,tmp4,tmp5,tmp6);\n\t";
+    ss << "return tmp;\n";
+    ss << "}";
 }
- void OpPPMT::BinInlineFun(std::set<std::string>& decls,
-    std::set<std::string>& funs)
+void OpPPMT::BinInlineFun(std::set<std::string>& decls,
+        std::set<std::string>& funs)
 {
     decls.insert(GetZwDecl);
     funs.insert(GetZw);
 }
 
- void OpPPMT::GenSlidingWindowFunction(std::stringstream &ss,
-         const std::string sSymName, SubArguments &vSubArguments)
- {
-     ArgVector argVector;
-     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 = 0;\n    ";
-     ss << "int gid0 = get_global_id(0);\n    ";
-     ss<<"double tmp0=0;\n    ";
-     ss<<"double tmp1=0;\n    ";
-     ss<<"double tmp2=0;\n    ";
-     ss<<"double tmp3=0;\n    ";
-     ss<<"double tmp4=0,tmp5=0;\n    ";
-     size_t nItems = 0;
-     ss <<"\n    ";
-     //while (i-- > 1)
-     for (size_t i = 0; i < vSubArguments.size(); i++)
-     {
-         FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
-         assert(pCur);
-         if (pCur->GetType() == formula::svDoubleVectorRef)
-         {
-             const formula::DoubleVectorRefToken* pDVR =
-             dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
-             size_t nCurWindowSize = pDVR->GetRefRowSize();
-             ss << "for (int i = ";
-             if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
+void OpPPMT::GenSlidingWindowFunction(std::stringstream &ss,
+        const std::string sSymName, SubArguments &vSubArguments)
+{
+    ArgVector argVector;
+    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 = 0;\n    ";
+    ss << "int gid0 = get_global_id(0);\n    ";
+    ss<<"double tmp0=0;\n    ";
+    ss<<"double tmp1=0;\n    ";
+    ss<<"double tmp2=0;\n    ";
+    ss<<"double tmp3=0;\n    ";
+    ss<<"double tmp4=0,tmp5=0;\n    ";
+    size_t nItems = 0;
+    ss <<"\n    ";
+    //while (i-- > 1)
+    for (size_t i = 0; i < vSubArguments.size(); i++)
+    {
+        FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
+        assert(pCur);
+        if (pCur->GetType() == formula::svDoubleVectorRef)
+        {
+            const formula::DoubleVectorRefToken* pDVR =
+                dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+            size_t nCurWindowSize = pDVR->GetRefRowSize();
+            ss << "for (int i = ";
+            if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
 #ifdef  ISNAN
-                 ss << "gid0; i < " << pDVR->GetArrayLength();
-                 ss << " && i < " << nCurWindowSize  << "; i++){\n        ";
+                ss << "gid0; i < " << pDVR->GetArrayLength();
+                ss << " && i < " << nCurWindowSize  << "; i++){\n        ";
 #else
-                 ss << "gid0; i < "<< nCurWindowSize << "; i++)\n        ";
+                ss << "gid0; i < "<< nCurWindowSize << "; i++)\n        ";
 #endif
-             } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
+            } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
 #ifdef  ISNAN
-                 ss << "0; i < " << pDVR->GetArrayLength();
-                 ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n        ";
+                ss << "0; i < " << pDVR->GetArrayLength();
+                ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n        ";
 #else
-                 ss << "0; i < gid0+"<< nCurWindowSize << "; i++)\n        ";
+                ss << "0; i < gid0+"<< nCurWindowSize << "; i++)\n        ";
 #endif
-             } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
+            } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
 #ifdef  ISNAN
-                 ss << "0; i + gid0 < " << pDVR->GetArrayLength();
-                 ss << " &&  i < "<< nCurWindowSize << "; i++){\n        ";
+                ss << "0; i + gid0 < " << pDVR->GetArrayLength();
+                ss << " &&  i < "<< nCurWindowSize << "; i++){\n        ";
 #else
-                 ss << "0; i < "<< nCurWindowSize << "; i++)\n        ";
+                ss << "0; i < "<< nCurWindowSize << "; i++)\n        ";
 #endif
-             }
-             else {
+            }
+            else {
 #ifdef  ISNAN
-                 ss << "0; i < "<< nCurWindowSize << "; i++){\n        ";
+                ss << "0; i < "<< nCurWindowSize << "; i++){\n        ";
 #else
-                 ss << "0; i < "<< nCurWindowSize << "; i++)\n        ";
+                ss << "0; i < "<< nCurWindowSize << "; i++)\n        ";
 #endif
-             }
-             nItems += nCurWindowSize;
-         }
-         else if (pCur->GetType() == formula::svSingleVectorRef)
-         {
+            }
+            nItems += nCurWindowSize;
+        }
+        else if (pCur->GetType() == formula::svSingleVectorRef)
+        {
 #ifdef  ISNAN
-                 const formula::SingleVectorRefToken* pSVR =
-                 dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
-             ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n        ";
+            const formula::SingleVectorRefToken* pSVR =
+                dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
+            ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n        ";
 #else
-             nItems += 1;
+            nItems += 1;
 #endif
-         }
-         else if (pCur->GetType() == formula::svDouble)
-         {
+        }
+        else if (pCur->GetType() == formula::svDouble)
+        {
 #ifdef  ISNAN
-             ss << "{\n        ";
+            ss << "{\n        ";
 #endif
-             nItems += 1;
-         }
-         else
-         {
+            nItems += 1;
+        }
+        else
+        {
 #ifdef  ISNAN
 #endif
-             nItems += 1;
-         }
+            nItems += 1;
+        }
 #ifdef  ISNAN
-         if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
-         {
-             ss << "if (isNan(";
-             ss << vSubArguments[i]->GenSlidingWindowDeclRef();
-             ss << "))\n            ";
-             ss << "tmp"<<i<<"= 0;\n        ";
-             ss << "else\n            ";
-             ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
-             ss << ";\n    }\n    ";
-         }
-         else
-         {
-             ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
-             ss <<";\n    ";
-         }
+        if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
+        {
+            ss << "if (isNan(";
+            ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << "))\n            ";
+            ss << "tmp"<<i<<"= 0;\n        ";
+            ss << "else\n            ";
+            ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss << ";\n    }\n    ";
+        }
+        else
+        {
+            ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
+            ss <<";\n    ";
+        }
 #else
-     ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
-     ss <<";\n    ";
-#endif
-     }
-     ss <<"double pmt ;\n    ";
-     ss<<"if(tmp0==0.0)\n    ";
-     ss<<"    return -(tmp3+tmp4)/";
-     ss<<"tmp2;\n    double temp1=0;\n    ";
-     ss <<"double abl = pow(1.0+tmp0,tmp2);\n    ";
-     ss <<"temp1-=tmp4";
-     ss<<";\n    ";
-     ss<<"temp1-=tmp3*abl;\n    ";
-     ss <<"pmt = temp1/(1.0+tmp0*tmp5";
-     ss<<") / ( (abl-1.0)/tmp0);\n    ";
-     ss <<"double temp = pow( 1+tmp0,tmp1-2);\n    ";
-     ss <<"double re;\n    ";
-     ss <<"if(tmp1==1.0)\n    {\n    ";
-     ss <<"if(tmp5>0.0)\n    ";
-     ss <<"    re=0.0;\n    ";
-     ss << "else\n        re=-tmp3;\n    }\n    ";
-     ss <<"else\n    {\n    ";
-     ss <<"if(tmp5>0.0)\n    ";
-     ss <<"    re=GetZw(tmp0, tmp1-2.0, pmt, tmp3, 1.0) - pmt;\n    ";
-     ss <<"else\n    ";
-     ss <<"    re=GetZw(tmp0, tmp1-1.0, pmt, tmp3, 0.0);\n    ";
-     ss <<"}\n    ";
-     ss <<"re = re * tmp0;\n    ";
-     ss <<"tmp = pmt - re;\n    ";
-     ss << "return tmp;\n";
-     ss << "}";
- }
+        ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
+        ss <<";\n    ";
+#endif
+    }
+    ss <<"double pmt ;\n    ";
+    ss<<"if(tmp0==0.0)\n    ";
+    ss<<"    return -(tmp3+tmp4)/";
+    ss<<"tmp2;\n    double temp1=0;\n    ";
+    ss <<"double abl = pow(1.0+tmp0,tmp2);\n    ";
+    ss <<"temp1-=tmp4";
+    ss<<";\n    ";
+    ss<<"temp1-=tmp3*abl;\n    ";
+    ss <<"pmt = temp1/(1.0+tmp0*tmp5";
+    ss<<") / ( (abl-1.0)/tmp0);\n    ";
+    ss <<"double temp = pow( 1+tmp0,tmp1-2);\n    ";
+    ss <<"double re;\n    ";
+    ss <<"if(tmp1==1.0)\n    {\n    ";
+    ss <<"if(tmp5>0.0)\n    ";
+    ss <<"    re=0.0;\n    ";
+    ss << "else\n        re=-tmp3;\n    }\n    ";
+    ss <<"else\n    {\n    ";
+    ss <<"if(tmp5>0.0)\n    ";
+    ss <<"    re=GetZw(tmp0, tmp1-2.0, pmt, tmp3, 1.0) - pmt;\n    ";
+    ss <<"else\n    ";
+    ss <<"    re=GetZw(tmp0, tmp1-1.0, pmt, tmp3, 0.0);\n    ";
+    ss <<"}\n    ";
+    ss <<"re = re * tmp0;\n    ";
+    ss <<"tmp = pmt - re;\n    ";
+    ss << "return tmp;\n";
+    ss << "}";
+}
 void OpCoupdaybs::BinInlineFun(std::set<std::string>& decls,
     std::set<std::string>& funs)
 {
commit 80f98226bdb95298419762ec152a89743af48f35
Author: mulei <mulei at multicorewareinc.com>
Date:   Mon Nov 4 11:02:51 2013 +0800

    GPU Calc: implement for PRICE
    
    AMLOEXT-63 FIX
    
    Change-Id: I97271c8cd05347e0c9179d509f8985d5f4c5f276
    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 b47e192..2362cba 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1127,6 +1127,12 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
                 {
                     mvSubArguments.push_back(SoPHelper(ts, ft->Children[i], new OpINTRATE));
                 }
+                else if ( !(pChild->GetExternal().compareTo(OUString(
+                   "com.sun.star.sheet.addin.Analysis.getPrice"))))
+                {
+                    mvSubArguments.push_back(SoPHelper(ts,
+                                      ft->Children[i], new OpPrice));
+                }
                 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 503087b..fb6610e 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -2107,6 +2107,147 @@ void OpPMT::GenSlidingWindowFunction(std::stringstream &ss,
     ss << "return tmp;\n";
     ss << "}";
 }
+ void OpPrice::BinInlineFun(std::set<std::string>& decls,
+     std::set<std::string>& funs)
+ {
+    decls.insert(getPrice_Decl);
+    decls.insert(coupnumDecl);decls.insert(coupdaysncDecl);
+    decls.insert(coupdaybsDecl);decls.insert(coupdaysDecl);
+    decls.insert(lcl_GetcoupnumDecl);decls.insert(lcl_GetcoupdaysDecl);
+    decls.insert(lcl_GetcoupdaybsDecl);decls.insert(getDiffDecl);
+    decls.insert(getDaysInYearRangeDecl);decls.insert(GetDaysInYearDecl);
+    decls.insert(GetDaysInYearsDecl);decls.insert(getDaysInMonthRangeDecl);
+    decls.insert(addMonthsDecl);decls.insert(ScaDateDecl);
+    decls.insert(GetNullDateDecl);decls.insert(DateToDaysDecl);
+    decls.insert(DaysToDateDecl);decls.insert(DaysInMonthDecl);
+    decls.insert(IsLeapYearDecl);
+
+    funs.insert(getPrice_);
+    funs.insert(coupnum);funs.insert(coupdaysnc);
+    funs.insert(coupdaybs);funs.insert(coupdays);
+    funs.insert(lcl_Getcoupnum);funs.insert(lcl_Getcoupdays);
+    funs.insert(lcl_Getcoupdaybs);funs.insert(getDiff);
+    funs.insert(getDaysInYearRange);funs.insert(GetDaysInYear);
+    funs.insert(GetDaysInYears);funs.insert(getDaysInMonthRange);
+    funs.insert(addMonths);funs.insert(ScaDate);
+    funs.insert(GetNullDate);funs.insert(DateToDays);
+    funs.insert(DaysToDate);funs.insert(DaysInMonth);
+    funs.insert(IsLeapYear);
+ }
+void OpPrice::GenSlidingWindowFunction(std::stringstream &ss,
+          const std::string sSymName, SubArguments &vSubArguments)
+{
+    ArgVector argVector;
+    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 = 0;\n    ";
+    ss << "int gid0 = get_global_id(0);\n    ";
+    ss<<"double tmp0=0;\n    ";
+    ss<<"double tmp1=0;\n    ";
+    ss<<"double tmp2=0;\n    ";
+    ss<<"double tmp3=0;\n    ";
+    ss<<"double tmp4=0,tmp5=0;\n    ";
+    ss<<"double tmp6=0;\n    ";
+    unsigned i = vSubArguments.size();
+    size_t nItems = 0;
+    ss <<"\n    ";
+    //while (i-- > 1)
+   for (size_t i = 0; i < vSubArguments.size(); i++)
+   {
+       FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
+       assert(pCur);
+       if (pCur->GetType() == formula::svDoubleVectorRef)
+       {
+           const formula::DoubleVectorRefToken* pDVR =
+           dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+           size_t nCurWindowSize = pDVR->GetRefRowSize();
+           ss << "for (int i = ";
+           if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
+#ifdef  ISNAN
+               ss << "gid0; i < " << pDVR->GetArrayLength();
+               ss << " && i < " << nCurWindowSize  << "; i++){\n        ";
+#else
+               ss << "gid0; i < "<< nCurWindowSize << "; i++)\n        ";
+#endif
+           } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
+#ifdef  ISNAN
+               ss << "0; i < " << pDVR->GetArrayLength();
+               ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n        ";
+#else
+               ss << "0; i < gid0+"<< nCurWindowSize << "; i++)\n        ";
+#endif
+           } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
+#ifdef  ISNAN
+               ss << "0; i + gid0 < " << pDVR->GetArrayLength();
+               ss << " &&  i < "<< nCurWindowSize << "; i++){\n        ";
+#else
+               ss << "0; i < "<< nCurWindowSize << "; i++)\n        ";
+#endif
+           }
+           else {
+#ifdef  ISNAN
+               ss << "0; i < "<< nCurWindowSize << "; i++){\n        ";
+#else
+               ss << "0; i < "<< nCurWindowSize << "; i++)\n        ";
+#endif
+           }
+           nItems += nCurWindowSize;
+       }
+       else if (pCur->GetType() == formula::svSingleVectorRef)
+       {
+#ifdef  ISNAN
+               const formula::SingleVectorRefToken* pSVR =
+               dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
+           ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n        ";
+#else
+           nItems += 1;
+#endif
+       }
+       else if (pCur->GetType() == formula::svDouble)
+       {
+#ifdef  ISNAN
+           ss << "{\n        ";
+#endif
+           nItems += 1;
+       }
+       else
+       {
+#ifdef  ISNAN
+#endif
+           nItems += 1;
+       }
+#ifdef  ISNAN
+       if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
+       {
+           ss << "if (isNan(";
+           ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+           ss << "))\n            ";
+           ss << "tmp"<<i<<"= 0;\n        ";
+           ss << "else\n            ";
+           ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
+           ss << ";\n    }\n    ";
+       }
+       else
+       {
+           ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
+           ss <<";\n    ";
+       }
+#else
+   ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
+   ss <<";\n    ";
+#endif
+   }
+      ss << "tmp = getPrice_(tmp0,tmp1,tmp2,tmp3,tmp4,tmp5,tmp6);\n\t";
+      ss << "return tmp;\n";
+      ss << "}";
+}
  void OpPPMT::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 6add67f..cd62f82 100644
--- a/sc/source/core/opencl/op_financial.hxx
+++ b/sc/source/core/opencl/op_financial.hxx
@@ -253,6 +253,14 @@ public:
             const std::string sSymName, SubArguments &vSubArguments);
     virtual std::string BinFuncName(void) const { return "PMT"; }
 };
+class OpPrice: public Normal
+{
+public:
+    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 "Price"; }
+};
 
 class OpPPMT: public Normal
 {
commit 1ed98937997c3bf511773bd8057ad947bc980e06
Author: mulei <mulei at multicorewareinc.com>
Date:   Mon Nov 4 10:50:50 2013 +0800

    GPU Calc: unit test cases for PRICE
    
    AMLOEXT-63 BUG
    
    Change-Id: I747817487fe118106a549674c6918dab544522ba
    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/Price.xls b/sc/qa/unit/data/xls/opencl/financial/Price.xls
new file mode 100644
index 0000000..ed507fd
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/financial/Price.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index dd3630e..d41046b 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -121,6 +121,7 @@ public:
     void testFinacialPMTFormula();
     void testFinacialPPMTFormula();
     void testFinancialISPMTFormula();
+    void testFinacialPriceFormula();
     CPPUNIT_TEST_SUITE(ScOpenclTest);
     CPPUNIT_TEST(testSharedFormulaXLS);
     CPPUNIT_TEST(testFinacialFormula);
@@ -171,6 +172,7 @@ public:
     CPPUNIT_TEST(testFinacialPPMTFormula);
     CPPUNIT_TEST(testFinacialPMTFormula);
     CPPUNIT_TEST(testFinancialISPMTFormula);
+    CPPUNIT_TEST(testFinacialPriceFormula);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -1096,6 +1098,29 @@ void ScOpenclTest::testStatisticalFormulaNegbinomdist()
     xDocSh->DoClose();
     xDocShRes->DoClose();
 }
+//[AMLOEXT-63]
+void ScOpenclTest::testFinacialPriceFormula()
+{
+    if (!detectOpenCLDevice())
+        return;
+    ScDocShellRef xDocSh = loadDoc("opencl/financial/Price.", XLS);
+    ScDocument *pDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+    enableOpenCL();
+    pDoc->CalcAll();
+    ScDocShellRef xDocShRes = loadDoc("opencl/financial/Price.", XLS);
+    ScDocument *pDocRes = xDocShRes->GetDocument();
+    CPPUNIT_ASSERT(pDocRes);
+    for (SCROW i = 1; i <= 10; ++i)
+    {
+        double fLibre = pDoc->GetValue(ScAddress(7, i, 0));
+        double fExcel = pDocRes->GetValue(ScAddress(7, i, 0));
+        //CPPUNIT_ASSERT_EQUAL(fExcel, fLibre);
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel));
+    }
+    xDocSh->DoClose();
+    xDocShRes->DoClose();
+}
 //[AMLOEXT-64]
 void ScOpenclTest::testFinacialDollarfrFormula()
 {


More information about the Libreoffice-commits mailing list