sc/qa/unit/data/xls/opencl/financial/Amordegrc.xls |binary sc/qa/unit/opencl-test.cxx | 24 ++ sc/source/core/opencl/formulagroupcl.cxx | 6 sc/source/core/opencl/op_financial.cxx | 171 +++++++++++++++++++++ sc/source/core/opencl/op_financial.hxx | 10 + 5 files changed, 211 insertions(+)
New commits: commit 8aee57d797ac1e6e34c5a689103195dfd6c8251c Author: minwang <m...@multicorewareinc.com> Date: Tue Nov 5 10:02:29 2013 +0800 GPU Calc: unit test cases for AMORDEGRC in GPU calc Need open macro NO_FALLBACK_TO_SWINTERP in formulagroupcl.cxx for test AMLOEXT-98 BUG Change-Id: I0867627c69eefdbc7127d19559af23fbd70b3ccc 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/Amordegrc.xls b/sc/qa/unit/data/xls/opencl/financial/Amordegrc.xls new file mode 100644 index 0000000..7cb9e47 Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/financial/Amordegrc.xls differ diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx index 3ecd34c..75d28ca 100644 --- a/sc/qa/unit/opencl-test.cxx +++ b/sc/qa/unit/opencl-test.cxx @@ -134,6 +134,7 @@ public: void testStatisticalFormulaWeibull(); void testStatisticalFormulaMedian(); void testFinancialDuration_ADDFormula(); + void testFinancialAmordegrcFormula(); CPPUNIT_TEST_SUITE(ScOpenclTest); CPPUNIT_TEST(testSharedFormulaXLS); CPPUNIT_TEST(testFinacialFormula); @@ -197,6 +198,7 @@ public: CPPUNIT_TEST(testStatisticalFormulaWeibull); CPPUNIT_TEST(testStatisticalFormulaMedian); CPPUNIT_TEST(testFinancialDuration_ADDFormula); + CPPUNIT_TEST(testFinancialAmordegrcFormula); CPPUNIT_TEST_SUITE_END(); private: @@ -1516,6 +1518,28 @@ void ScOpenclTest::testFinacialXNPVFormula() xDocSh->DoClose(); xDocShRes->DoClose(); } +//[AMLOEXT-98] +void ScOpenclTest::testFinancialAmordegrcFormula() +{ + if (!detectOpenCLDevice()) + return; + ScDocShellRef xDocSh = loadDoc("opencl/financial/Amordegrc.", XLS); + ScDocument* pDoc = xDocSh->GetDocument(); + CPPUNIT_ASSERT(pDoc); + enableOpenCL(); + pDoc->CalcAll(); + ScDocShellRef xDocShRes = loadDoc("opencl/financial/Amordegrc.", XLS); + ScDocument* pDocRes = xDocShRes->GetDocument(); + CPPUNIT_ASSERT(pDocRes); + for (SCROW i = 0; i <= 9; ++i) + { + double fLibre = pDoc->GetValue(ScAddress(7, i, 0)); + double fExcel = pDocRes->GetValue(ScAddress(7, i, 0)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel)); + } + xDocSh->DoClose(); + xDocShRes->DoClose(); +} //[AMLOEXT-99] void ScOpenclTest:: testFinancialISPMTFormula() { commit 55c2a05521e3bc7281abf1fefb345bce50549152 Author: minwang <m...@multicorewareinc.com> Date: Tue Nov 5 10:16:40 2013 +0800 GPU Calc: implement fix for AMORDEGRC in GPU calc AMLOEXT-98 FIX Change-Id: I9f63d023161e5ad7981374dedffb6f00663a1c66 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 fec3a68..d68b17b 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -1185,6 +1185,12 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments( mvSubArguments.push_back( SoPHelper(ts, ft->Children[i], new OpDuration_ADD)); } + else if ( !(pChild->GetExternal().compareTo(OUString( + "com.sun.star.sheet.addin.Analysis.getAmordegrc")))) + { + mvSubArguments.push_back(SoPHelper(ts, ft->Children[i], + new OpAmordegrc)); + } 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 0b46835..6681b78 100644 --- a/sc/source/core/opencl/op_financial.cxx +++ b/sc/source/core/opencl/op_financial.cxx @@ -2894,6 +2894,177 @@ void OpCoupnum::GenSlidingWindowFunction(std::stringstream &ss, ss << "return tmp;\n"; ss << "}"; } +void OpAmordegrc::BinInlineFun(std::set<std::string>& decls, + std::set<std::string>& funs) +{ + decls.insert(nKorrValDecl); decls.insert(RoundDecl); + decls.insert(IsLeapYearDecl);decls.insert(DaysInMonthDecl); + decls.insert(DaysToDateDecl); decls.insert(DateToDaysDecl); + decls.insert(GetNullDateDecl); decls.insert(GetYearFracDecl); + funs.insert(Round); + funs.insert(IsLeapYear);funs.insert(DaysInMonth); + funs.insert(DaysToDate);funs.insert(DateToDays); + funs.insert(GetNullDate);funs.insert(GetYearFrac); +} +void OpAmordegrc::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 << "int gid0 = get_global_id(0);\n"; + ss << " double tmp = " << GetBottom() <<";\n"; + ss << " double fCost,fRestVal,fPer,fRate;\n"; + ss << " int nDate,nFirstPer,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); + FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken(); + const formula::SingleVectorRefToken*tmpCurDVR4= dynamic_cast<const + formula::SingleVectorRefToken *>(tmpCur4); + FormulaToken *tmpCur5 = vSubArguments[5]->GetFormulaToken(); + const formula::SingleVectorRefToken*tmpCurDVR5= dynamic_cast<const + formula::SingleVectorRefToken *>(tmpCur5); + FormulaToken *tmpCur6 = vSubArguments[6]->GetFormulaToken(); + const formula::SingleVectorRefToken*tmpCurDVR6= dynamic_cast<const + formula::SingleVectorRefToken *>(tmpCur6); + ss<< " int buffer_Cost_len = "; + ss<< tmpCurDVR0->GetArrayLength(); + ss << ";\n"; + ss<< " int buffer_Date_len = "; + ss<< tmpCurDVR1->GetArrayLength(); + ss << ";\n"; + ss<< " int buffer_FirstPer_len = "; + ss<< tmpCurDVR2->GetArrayLength(); + ss << ";\n"; + ss<< " int buffer_RestVal_len = "; + ss<< tmpCurDVR3->GetArrayLength(); + ss << ";\n"; + ss<< " int buffer_Per_len = "; + ss<< tmpCurDVR4->GetArrayLength(); + ss << ";\n"; + ss<< " int buffer_Rate_len = "; + ss<< tmpCurDVR5->GetArrayLength(); + ss << ";\n"; + ss<< " int buffer_Base_len = "; + ss<< tmpCurDVR6->GetArrayLength(); + ss << ";\n"; +#endif +#ifdef ISNAN + ss <<" if(gid0 >= buffer_Cost_len || isNan("; + ss <<vSubArguments[0]->GenSlidingWindowDeclRef(); + ss <<"))\n"; + ss <<" fCost = 0;\n else\n"; + #endif + ss << " fCost="; + ss << vSubArguments[0]->GenSlidingWindowDeclRef(); + ss <<";\n"; +#ifdef ISNAN + ss <<" if(gid0 >= buffer_Date_len || isNan("; + ss <<vSubArguments[1]->GenSlidingWindowDeclRef(); + ss <<"))\n"; + ss <<" nDate = 0;\n else\n"; +#endif + ss << " nDate=(int)"; + ss << vSubArguments[1]->GenSlidingWindowDeclRef(); + ss << ";\n"; +#ifdef ISNAN + ss <<" if(gid0 >= buffer_FirstPer_len || isNan("; + ss <<vSubArguments[2]->GenSlidingWindowDeclRef(); + ss <<"))\n"; + ss <<" nFirstPer = 0;\n else\n"; +#endif + ss << " nFirstPer=(int)"; + ss << vSubArguments[2]->GenSlidingWindowDeclRef(); + ss <<";\n"; +#ifdef ISNAN + ss <<" if(gid0 >= buffer_RestVal_len || isNan("; + ss <<vSubArguments[3]->GenSlidingWindowDeclRef(); + ss <<"))\n"; + ss <<" fRestVal = 0;\n else\n"; +#endif + ss << " fRestVal="; + ss << vSubArguments[3]->GenSlidingWindowDeclRef(); + ss << ";\n"; +#ifdef ISNAN + ss <<" if(gid0 >= buffer_Per_len || isNan("; + ss <<vSubArguments[4]->GenSlidingWindowDeclRef(); + ss <<"))\n"; + ss <<" fPer = 0;\n else\n"; +#endif + ss << " fPer = "; + ss << vSubArguments[4]->GenSlidingWindowDeclRef(); + ss <<";\n"; +#ifdef ISNAN + ss <<" if(gid0 >= buffer_Rate_len || isNan("; + ss <<vSubArguments[5]->GenSlidingWindowDeclRef(); + ss <<"))\n"; + ss <<" fRate = 0;\n else\n"; +#endif + ss << " fRate="; + ss << vSubArguments[5]->GenSlidingWindowDeclRef(); + ss << ";\n"; +#ifdef ISNAN + ss <<" if(gid0 >= buffer_Base_len || isNan("; + ss <<vSubArguments[6]->GenSlidingWindowDeclRef(); + ss <<"))\n"; + ss <<" nBase = 0;\n else\n"; +#endif + ss << " nBase = (int)"; + ss << vSubArguments[6]->GenSlidingWindowDeclRef(); + ss << ";\n"; + ss <<" uint nPer = convert_int( fPer );\n"; + ss <<" double fUsePer = 1.0 / fRate;\n"; + ss <<" double fAmorCoeff;\n"; + ss <<" if( fUsePer < 3.0 )\n"; + ss <<" fAmorCoeff = 1.0;\n"; + ss <<" else if( fUsePer < 5.0 )\n"; + ss <<" fAmorCoeff = 1.5;\n"; + ss <<" else if( fUsePer <= 6.0 )\n"; + ss <<" fAmorCoeff = 2.0;\n"; + ss <<" else\n"; + ss <<" fAmorCoeff = 2.5;\n"; + ss <<" fRate *= fAmorCoeff;\n"; + ss <<" tmp = Round( GetYearFrac( GetNullDate(),"; + ss <<"nDate, nFirstPer, nBase ) * fRate * fCost);\n"; + ss <<" fCost = fCost-tmp;\n"; + ss <<" double fRest = fCost - fRestVal;\n"; + ss <<" for( uint n = 0 ; n < nPer ; n++ )\n"; + ss <<" {\n"; + ss <<" tmp = Round( fRate * fCost);\n"; + ss <<" fRest -= tmp;\n"; + ss <<" if( fRest < 0.0 )\n"; + ss <<" {\n"; + ss <<" switch( nPer - n )\n"; + ss <<" {\n"; + ss <<" case 0:\n"; + ss <<" case 1:\n"; + ss <<" tmp = Round( fCost * 0.5);\n"; + ss <<" default:\n"; + ss <<" tmp = 0.0;\n"; + ss <<" }\n"; + ss <<" }\n"; + ss <<" fCost -= tmp;\n"; + ss <<" }\n"; + ss <<" return tmp;\n"; + ss <<"}"; +} void OpReceived::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 f48b650..070d2bb 100644 --- a/sc/source/core/opencl/op_financial.hxx +++ b/sc/source/core/opencl/op_financial.hxx @@ -339,6 +339,16 @@ public: virtual std::string BinFuncName(void) const { return "Coupnum"; } }; +class OpAmordegrc: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 "Amordegrc"; } +}; + class OpReceived:public Normal { public: _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits