diff options
author | xinjiang <xinjiang@multicorewareinc.com> | 2013-11-05 09:47:10 +0800 |
---|---|---|
committer | I-Jui (Ray) Sung <ray@multicorewareinc.com> | 2013-11-12 20:41:08 -0600 |
commit | 9425b3a938faf2df4d58acdcaf4437dc52ebd23c (patch) | |
tree | ec4466338ae9a443d33f10402c9fe71bcaf37ff8 | |
parent | Avoid using UNO API formula tokens. (diff) | |
download | core-9425b3a938faf2df4d58acdcaf4437dc52ebd23c.tar.gz core-9425b3a938faf2df4d58acdcaf4437dc52ebd23c.zip |
GPU Calc: implement fix for DURATION_ADD
AMLOEXT-121 FIX
Change-Id: Ie6b10eacc4e5fc0b2dcfe816982836b8b244af05
Signed-off-by: haochen <haochen@multicorewareinc.com>
Signed-off-by: I-Jui (Ray) Sung <ray@multicorewareinc.com>
-rw-r--r-- | sc/source/core/opencl/formulagroupcl.cxx | 6 | ||||
-rw-r--r-- | sc/source/core/opencl/op_financial.cxx | 60 | ||||
-rw-r--r-- | sc/source/core/opencl/op_financial.hxx | 14 | ||||
-rw-r--r-- | sc/source/core/opencl/opinlinefun_finacial.cxx | 32 |
4 files changed, 112 insertions, 0 deletions
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx index c6ae8e8e235a..6d613a4abb80 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 cb31cd1876e9..1db911940e6c 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 544fc5fd40e0..f48b65005f04 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 27a16253a6ac..86f93eb5bde9 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: */ |