sc/qa/unit/data/xls/opencl/financial/Coupnum.xls |binary sc/qa/unit/opencl-test.cxx | 25 +++++ sc/source/core/opencl/formulagroupcl.cxx | 6 + sc/source/core/opencl/op_financial.cxx | 97 ++++++++++++++++++++++- sc/source/core/opencl/op_financial.hxx | 9 ++ 5 files changed, 136 insertions(+), 1 deletion(-)
New commits: commit 9ab405788ef7dfc2ae0461eb7f31569c181671c5 Author: minwang <m...@multicorewareinc.com> Date: Mon Nov 4 11:32:43 2013 +0800 GPU Calc: implemented COUPNUM AMLOEXT-74 FIX Change-Id: Ic7f274f089f7f6cc6b767c4a07844014eeded61d Signed-off-by: haochen <haoc...@multicorewareinc.com> Signed-off-by: I-Jui (Ray) Sung <r...@multicorewareinc.com> diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx index bc758f4..07ea246 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -1137,6 +1137,12 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments( mvSubArguments.push_back(SoPHelper(ts, ft->Children[i], new OpPrice)); } + else if ( !(pChild->GetExternal().compareTo(OUString( + "com.sun.star.sheet.addin.Analysis.getCoupnum")))) + { + mvSubArguments.push_back(SoPHelper(ts, ft->Children[i], + new OpCoupnum)); + } 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 a40a113..b5b9a5c 100644 --- a/sc/source/core/opencl/op_financial.cxx +++ b/sc/source/core/opencl/op_financial.cxx @@ -2740,7 +2740,102 @@ void OpCoupdaysnc::GenSlidingWindowFunction( ss << "}"; } - void OpReceived::BinInlineFun(std::set<std::string>& decls, +void OpCoupnum::BinInlineFun(std::set<std::string>& decls, + std::set<std::string>& funs) +{ + decls.insert(IsLeapYearDecl);decls.insert(DaysInMonthDecl); + decls.insert(DaysToDateDecl);decls.insert(DateToDaysDecl); + decls.insert(GetNullDateDecl);decls.insert(lcl_GetcoupnumDecl); + decls.insert(coupnumDecl); + funs.insert(IsLeapYear);funs.insert(DaysInMonth); + funs.insert(DaysToDate);funs.insert(DateToDays); + funs.insert(GetNullDate); + funs.insert(lcl_Getcoupnum); + funs.insert(coupnum); +} +void OpCoupnum::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 << "int nSettle,nMat,nFreq,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); + ss<< "int buffer_nSettle_len = "; + ss<< tmpCurDVR0->GetArrayLength(); + ss << ";\n "; + ss<< "int buffer_nMat_len = "; + ss<< tmpCurDVR1->GetArrayLength(); + ss << ";\n "; + ss<< "int buffer_nFreq_len = "; + ss<< tmpCurDVR2->GetArrayLength(); + ss << ";\n "; + ss<< "int buffer_nBase_len = "; + ss<< tmpCurDVR3->GetArrayLength(); + ss << ";\n "; +#endif +#ifdef ISNAN + ss <<"if(gid0 >= buffer_nSettle_len || isNan("; + ss <<vSubArguments[0]->GenSlidingWindowDeclRef(); + ss <<"))\n "; + ss <<"nSettle = 0;\n else\n "; +#endif + ss << "nSettle=(int)"; + ss << vSubArguments[0]->GenSlidingWindowDeclRef(); + ss <<";\n "; +#ifdef ISNAN + ss <<"if(gid0 >= buffer_nMat_len || isNan("; + ss <<vSubArguments[1]->GenSlidingWindowDeclRef(); + ss <<"))\n "; + ss <<"nMat = 0;\n else\n "; +#endif + ss << "nMat=(int)"; + ss << vSubArguments[1]->GenSlidingWindowDeclRef(); + ss << ";\n "; +#ifdef ISNAN + ss <<"if(gid0 >= buffer_nFreq_len || isNan("; + ss <<vSubArguments[2]->GenSlidingWindowDeclRef(); + ss <<"))\n "; + ss <<"nFreq = 0;\n else\n "; +#endif + ss << "nFreq=(int)"; + ss << vSubArguments[2]->GenSlidingWindowDeclRef(); + ss <<";\n "; +#ifdef ISNAN + ss <<"if(gid0 >= buffer_nBase_len || isNan("; + ss <<vSubArguments[3]->GenSlidingWindowDeclRef(); + ss <<"))\n "; + ss <<"nBase = 0;\n else\n "; +#endif + ss << "nBase=(int)"; + ss << vSubArguments[3]->GenSlidingWindowDeclRef(); + ss << ";\n "; + ss <<"tmp = coupnum(nSettle,nMat,nFreq,nBase);\n "; + ss << "return tmp;\n"; + ss << "}"; +} + +void OpReceived::BinInlineFun(std::set<std::string>& decls, std::set<std::string>& funs) { decls.insert(GetYearDiffDecl);decls.insert(GetDiffDateDecl); diff --git a/sc/source/core/opencl/op_financial.hxx b/sc/source/core/opencl/op_financial.hxx index fc73076..6bc3c19 100644 --- a/sc/source/core/opencl/op_financial.hxx +++ b/sc/source/core/opencl/op_financial.hxx @@ -315,7 +315,16 @@ public: virtual std::string BinFuncName(void) const { return "Coupdaysnc"; } }; +class OpCoupnum: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 "Coupnum"; } +}; class OpReceived:public Normal { public: commit 38afbb6af4d02e51095b079075391648860e19ff Author: minwang <m...@multicorewareinc.com> Date: Mon Nov 4 11:27:40 2013 +0800 GPU Calc: unit test cases for COUPNUM AMLOEXT-74 BUG Change-Id: Ice115dc1e9b22fdaff9a8fdadabe9b93635ef315 Signed-off-by: haochen <haoc...@multicorewareinc.com> Signed-off-by: I-Jui (Ray) Sung <r...@multicorewareinc.com> diff --git a/sc/qa/unit/data/xls/opencl/financial/Coupnum.xls b/sc/qa/unit/data/xls/opencl/financial/Coupnum.xls new file mode 100644 index 0000000..914612e Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/financial/Coupnum.xls differ diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx index 6654517..9199a5d 100644 --- a/sc/qa/unit/opencl-test.cxx +++ b/sc/qa/unit/opencl-test.cxx @@ -123,6 +123,7 @@ public: void testFinancialISPMTFormula(); void testFinacialPriceFormula(); void testFinancialDurationFormula(); + void testFinancialCoupnumFormula(); CPPUNIT_TEST_SUITE(ScOpenclTest); CPPUNIT_TEST(testSharedFormulaXLS); CPPUNIT_TEST(testFinacialFormula); @@ -175,6 +176,7 @@ public: CPPUNIT_TEST(testFinancialISPMTFormula); CPPUNIT_TEST(testFinacialPriceFormula); CPPUNIT_TEST(testFinancialDurationFormula); + CPPUNIT_TEST(testFinancialCoupnumFormula); CPPUNIT_TEST_SUITE_END(); private: @@ -1076,6 +1078,29 @@ void ScOpenclTest::testFinancialAccrintmFormula() xDocSh->DoClose(); xDocShRes->DoClose(); } +//[AMLOEXT-74] +void ScOpenclTest::testFinancialCoupnumFormula() +{ + if (!detectOpenCLDevice()) + return; + ScDocShellRef xDocSh = loadDoc("opencl/financial/Coupnum.", XLS); + ScDocument* pDoc = xDocSh->GetDocument(); + CPPUNIT_ASSERT(pDoc); + enableOpenCL(); + pDoc->CalcAll(); + ScDocShellRef xDocShRes = loadDoc("opencl/financial/Coupnum.", XLS); + ScDocument* pDocRes = xDocShRes->GetDocument(); + CPPUNIT_ASSERT(pDocRes); + for (SCROW i = 0; i <= 9; ++i) + { + double fLibre = pDoc->GetValue(ScAddress(4, i, 0)); + double fExcel = pDocRes->GetValue(ScAddress(4, i, 0)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel)); + } + xDocSh->DoClose(); + xDocShRes->DoClose(); +} + //[AMLOEXT-57] void ScOpenclTest::testStatisticalFormulaNegbinomdist() { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits