sc/qa/unit/data/xls/opencl/financial/FV.xls |binary sc/qa/unit/data/xls/opencl/financial/MDuration.xls |binary sc/qa/unit/data/xls/opencl/financial/ddb.xls |binary sc/qa/unit/opencl-test.cxx | 72 ++++++ sc/source/core/opencl/formulagroupcl.cxx | 14 + sc/source/core/opencl/op_financial.cxx | 229 ++++++++++++++++++++- sc/source/core/opencl/op_financial.hxx | 34 +++ sc/source/core/tool/token.cxx | 2 8 files changed, 347 insertions(+), 4 deletions(-)
New commits: commit c396d531ad2a076885d91fa38e8c5f000cb61ea7 Author: xinjiang <xinji...@multicorewareinc.com> Date: Tue Nov 5 13:15:24 2013 +0800 GPU Calc: unit test cases for MDURATION Need open macro NO_FALLBACK_TO_SWINTERP in formulagroupcl.cxx for test AMLOEXT-126 BUG Change-Id: If308a54a79f9a093a845e53e65b9fae3b050c4e5 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/MDuration.xls b/sc/qa/unit/data/xls/opencl/financial/MDuration.xls new file mode 100644 index 0000000..807ca2d Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/financial/MDuration.xls differ diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx index 5890c62..6fd60a4 100644 --- a/sc/qa/unit/opencl-test.cxx +++ b/sc/qa/unit/opencl-test.cxx @@ -136,6 +136,7 @@ public: void testFinancialAmorlincFormula(); void testFinancialDDBFormula(); void testFinancialFVFormula(); + void testFinancialMDurationFormula(); CPPUNIT_TEST_SUITE(ScOpenclTest); CPPUNIT_TEST(testSharedFormulaXLS); CPPUNIT_TEST(testFinacialFormula); @@ -203,6 +204,7 @@ public: CPPUNIT_TEST(testFinancialAmorlincFormula); CPPUNIT_TEST(testFinancialDDBFormula); CPPUNIT_TEST(testFinancialFVFormula); + CPPUNIT_TEST(testFinancialMDurationFormula); CPPUNIT_TEST_SUITE_END(); private: @@ -2000,6 +2002,28 @@ void ScOpenclTest:: testFinancialDuration_ADDFormula() xDocSh->DoClose(); xDocShRes->DoClose(); } +//[AMLOEXT-126] +void ScOpenclTest:: testFinancialMDurationFormula() +{ + if (!detectOpenCLDevice()) + return; + ScDocShellRef xDocSh = loadDoc("opencl/financial/MDuration.", XLS); + ScDocument* pDoc = xDocSh->GetDocument(); + CPPUNIT_ASSERT(pDoc); + enableOpenCL(); + pDoc->CalcAll(); + ScDocShellRef xDocShRes = loadDoc("opencl/financial/MDuration.", 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(); +} //[AMLOEXT-131] void ScOpenclTest:: testFinancialFVFormula() { commit 63c897a672c1522896822c4a92f65c61d96872a6 Author: I-Jui (Ray) Sung <r...@multicorewareinc.com> Date: Tue Nov 12 22:27:34 2013 -0600 GPU Calc: fix compilation error in calling GetNullDate() Fix OpenCL compiler internal errors triggered by wrong # of args, on NVIDIA. Change-Id: Ifcc29d6fb59ac41d8e54ace348d02c942343ca5b diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx index 34f8ebd..30d4c85 100644 --- a/sc/source/core/opencl/op_financial.cxx +++ b/sc/source/core/opencl/op_financial.cxx @@ -365,7 +365,7 @@ void OpDISC::GenSlidingWindowFunction( ss<<"mode = "; ss << vSubArguments[4]->GenSlidingWindowDeclRef(); ss<<";\n\t"; - ss << "int nNullDate = GetNullDate( 30 , 12 , 1899 );\n\t"; + ss << "int nNullDate = GetNullDate();\n\t"; ss << "tmp = 1.0 - price / redemp;\n\t"; ss << "tmp /= GetYearFrac( nNullDate , settle , maturity , mode );\n\t"; ss << "return tmp;\n"; @@ -481,7 +481,7 @@ void OpINTRATE::GenSlidingWindowFunction( ss << "mode = "; ss << vSubArguments[4]->GenSlidingWindowDeclRef(); ss << ";\n\t"; - ss << "int nNullDate = GetNullDate(30,12,1899);\n\t"; + ss << "int nNullDate = GetNullDate();\n\t"; ss << "tmp = (redemp / price - 1.0) / GetYearDiff(nNullDate, settle, maturity, mode);\n\t"; ss << "return tmp;\n"; ss << "}"; @@ -678,7 +678,7 @@ void OpDuration_ADD::GenSlidingWindowFunction(std::stringstream& ss, ss << ";\n"; } } - ss << " int nNullDate = GetNullDate(30, 12, 1899);\n"; + ss << " int nNullDate = GetNullDate();\n"; ss << " tmp = GetDuration( nNullDate, (int)arg0, (int)arg1, arg2,"; ss << " arg3, (int)arg4, (int)arg5);\n"; ss << " return tmp;\n"; commit 9ad4cca4a031fbcc8a1def7172b8596489616b06 Author: xinjiang <xinji...@multicorewareinc.com> Date: Tue Nov 5 13:57:18 2013 +0800 GPU Calc: implemented for MDURATION AMLOEXT-126 FIX Change-Id: Ie246a39aab64c98497df07e866c77ccd0b26b308 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 c5b9d75..6d589fd 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -1205,6 +1205,12 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments( mvSubArguments.push_back(SoPHelper(ts, ft->Children[i], new OpAmorlinc)); } + else if ( !(pChild->GetExternal().compareTo(OUString( + "com.sun.star.sheet.addin.Analysis.getMduration")))) + { + mvSubArguments.push_back(SoPHelper(ts, ft->Children[i], + new OpMDuration)); + } 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 ab4099f..34f8ebd 100644 --- a/sc/source/core/opencl/op_financial.cxx +++ b/sc/source/core/opencl/op_financial.cxx @@ -684,6 +684,67 @@ void OpDuration_ADD::GenSlidingWindowFunction(std::stringstream& ss, ss << " return tmp;\n"; ss << "}"; } +void OpMDuration::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 OpMDuration::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();\n"; + ss << " tmp = GetDuration( nNullDate, (int)arg0, (int)arg1, arg2,"; + ss << " arg3, (int)arg4, (int)arg5);\n"; + ss << " tmp /= 1.0 + arg3 / (int)arg4;\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 35da5f3..3a1350a 100644 --- a/sc/source/core/opencl/op_financial.hxx +++ b/sc/source/core/opencl/op_financial.hxx @@ -135,7 +135,18 @@ public: virtual std::string BinFuncName(void) const { return "Duration_ADD"; } }; +class OpMDuration: 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 "MDuration"; } +}; class Fvschedule: public Normal { commit 6d59c61bf057a18dc1e10fe1401420a0f8d5ca60 Author: xinjiang <xinji...@multicorewareinc.com> Date: Tue Nov 5 10:55:06 2013 +0800 GPU Calc: unit test cases for FV Need open macro NO_FALLBACK_TO_SWINTERP in formulagroupcl.cxx for test AMLOEXT-131 BUG Change-Id: I54cd25681dfbfa9c6f664b9d3a2349e097a0dcdb 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/FV.xls b/sc/qa/unit/data/xls/opencl/financial/FV.xls new file mode 100644 index 0000000..681986a Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/financial/FV.xls differ diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx index 0dd15c4..5890c62 100644 --- a/sc/qa/unit/opencl-test.cxx +++ b/sc/qa/unit/opencl-test.cxx @@ -135,6 +135,7 @@ public: void testFinancialAmordegrcFormula(); void testFinancialAmorlincFormula(); void testFinancialDDBFormula(); + void testFinancialFVFormula(); CPPUNIT_TEST_SUITE(ScOpenclTest); CPPUNIT_TEST(testSharedFormulaXLS); CPPUNIT_TEST(testFinacialFormula); @@ -201,6 +202,7 @@ public: CPPUNIT_TEST(testFinancialAmordegrcFormula); CPPUNIT_TEST(testFinancialAmorlincFormula); CPPUNIT_TEST(testFinancialDDBFormula); + CPPUNIT_TEST(testFinancialFVFormula); CPPUNIT_TEST_SUITE_END(); private: @@ -1998,6 +2000,28 @@ void ScOpenclTest:: testFinancialDuration_ADDFormula() xDocSh->DoClose(); xDocShRes->DoClose(); } +//[AMLOEXT-131] +void ScOpenclTest:: testFinancialFVFormula() +{ + if (!detectOpenCLDevice()) + return; + ScDocShellRef xDocSh = loadDoc("opencl/financial/FV.", XLS); + ScDocument* pDoc = xDocSh->GetDocument(); + CPPUNIT_ASSERT(pDoc); + enableOpenCL(); + pDoc->CalcAll(); + ScDocShellRef xDocShRes = loadDoc("opencl/financial/FV.", XLS); + ScDocument* pDocRes = xDocShRes->GetDocument(); + CPPUNIT_ASSERT(pDocRes); + for (SCROW i = 0; i <= 9; ++i) + { + double fLibre = pDoc->GetValue(ScAddress(5, i, 0)); + double fExcel = pDocRes->GetValue(ScAddress(5, i, 0)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel)); + } + xDocSh->DoClose(); + xDocShRes->DoClose(); +} ScOpenclTest::ScOpenclTest() : ScBootstrapFixture( "/sc/qa/unit/data" ) { diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index a3d2ebb..b738e16 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -1378,6 +1378,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r ) case ocWeibull: case ocMedian: case ocGDA: + case ocZW: // Don't change the state. break; default: commit 26cba28d731c1e515058ea69f39528aa7a900c72 Author: xinjiang <xinji...@multicorewareinc.com> Date: Tue Nov 5 10:58:41 2013 +0800 GPU Calc: implemented for FV AMLOEXT-131 FIX Change-Id: I45aa49037b991958187a6287d0b7a4283791e186 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 069321f..c5b9d75 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -1060,6 +1060,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments( mvSubArguments.push_back(SoPHelper(ts, ft->Children[i],new OpDDB)); break; + case ocZW: + mvSubArguments.push_back(SoPHelper(ts, + ft->Children[i],new OpFV)); + break; case ocExternal: if ( !(pChild->GetExternal().compareTo(OUString( "com.sun.star.sheet.addin.Analysis.getEffect")))) diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx index b449a9d..ab4099f 100644 --- a/sc/source/core/opencl/op_financial.cxx +++ b/sc/source/core/opencl/op_financial.cxx @@ -486,7 +486,57 @@ void OpINTRATE::GenSlidingWindowFunction( ss << "return tmp;\n"; ss << "}"; } +void OpFV::BinInlineFun(std::set<std::string>& decls, + std::set<std::string>& funs) +{ + decls.insert(GetZwDecl); + funs.insert(GetZw); +} +void OpFV::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"; + 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 << " tmp = GetZw(arg0, arg1, arg2, arg3, arg4);\n"; + ss << " return tmp;\n"; + ss << "}"; +} void OpISPMT::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 de1ffc7..35da5f3 100644 --- a/sc/source/core/opencl/op_financial.hxx +++ b/sc/source/core/opencl/op_financial.hxx @@ -86,6 +86,20 @@ public: virtual std::string BinFuncName(void) const { return "INTRATE"; } }; +class OpFV: 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 "FV"; } +}; + class OpISPMT: public Normal { public: commit b723d47dee7cd1e31364a74daa10764aa531f04f Author: minwang <m...@multicorewareinc.com> Date: Tue Nov 5 10:42:57 2013 +0800 GPU Calc: unit test cases for DDB Need open macro NO_FALLBACK_TO_SWINTERP in formulagroupcl.cxx for test AMLOEXT-124 BUG Change-Id: Idfe027b7d5d61b093af60536ac4f482d5b6bda2d 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/ddb.xls b/sc/qa/unit/data/xls/opencl/financial/ddb.xls new file mode 100644 index 0000000..e98ae08 Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/financial/ddb.xls differ diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx index bc26113..0dd15c4 100644 --- a/sc/qa/unit/opencl-test.cxx +++ b/sc/qa/unit/opencl-test.cxx @@ -134,6 +134,7 @@ public: void testFinancialDuration_ADDFormula(); void testFinancialAmordegrcFormula(); void testFinancialAmorlincFormula(); + void testFinancialDDBFormula(); CPPUNIT_TEST_SUITE(ScOpenclTest); CPPUNIT_TEST(testSharedFormulaXLS); CPPUNIT_TEST(testFinacialFormula); @@ -199,6 +200,7 @@ public: CPPUNIT_TEST(testFinancialDuration_ADDFormula); CPPUNIT_TEST(testFinancialAmordegrcFormula); CPPUNIT_TEST(testFinancialAmorlincFormula); + CPPUNIT_TEST(testFinancialDDBFormula); CPPUNIT_TEST_SUITE_END(); private: @@ -1607,6 +1609,28 @@ void ScOpenclTest::testFinancialAmorlincFormula() xDocSh->DoClose(); xDocShRes->DoClose(); } +//[AMLOEXT-124] +void ScOpenclTest::testFinancialDDBFormula() +{ + if (!detectOpenCLDevice()) + return; + ScDocShellRef xDocSh = loadDoc("opencl/financial/ddb.", XLS); + ScDocument* pDoc = xDocSh->GetDocument(); + CPPUNIT_ASSERT(pDoc); + enableOpenCL(); + pDoc->CalcAll(); + ScDocShellRef xDocShRes = loadDoc("opencl/financial/ddb.", XLS); + ScDocument* pDocRes = xDocShRes->GetDocument(); + CPPUNIT_ASSERT(pDocRes); + for (SCROW i = 0; i <= 9; ++i) + { + double fLibre = pDoc->GetValue(ScAddress(5, i, 0)); + double fExcel = pDocRes->GetValue(ScAddress(5, i, 0)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel)); + } + xDocSh->DoClose(); + xDocShRes->DoClose(); +} void ScOpenclTest::testFinacialPriceMatFormula() { if (!detectOpenCLDevice()) diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index 1bcf726..a3d2ebb 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -1377,6 +1377,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r ) case ocStandard: case ocWeibull: case ocMedian: + case ocGDA: // Don't change the state. break; default: commit 48caa626012312e2ec13df5008c041b29acab44c Author: minwang <m...@multicorewareinc.com> Date: Tue Nov 5 10:47:06 2013 +0800 GPU Calc: implement fix for DDB AMLOEXT-124 FIX Change-Id: Id43ae2ec0aba83ab136787bdb6f2862bc77f6366 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 55d2f25..069321f 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -1056,6 +1056,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments( mvSubArguments.push_back(SoPHelper(ts, ft->Children[i],new OpMedian)); break; + case ocGDA: + mvSubArguments.push_back(SoPHelper(ts, + ft->Children[i],new OpDDB)); + break; case ocExternal: if ( !(pChild->GetExternal().compareTo(OUString( "com.sun.star.sheet.addin.Analysis.getEffect")))) diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx index 92a7f14..b449a9d 100644 --- a/sc/source/core/opencl/op_financial.cxx +++ b/sc/source/core/opencl/op_financial.cxx @@ -3770,7 +3770,117 @@ void OpTbillyield::GenSlidingWindowFunction( ss <<"return tmp;\n"; ss << "}\n"; } - +void OpDDB::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 = 0;\n"; + ss << " double fWert,fRest,fDauer,fPeriode,fFaktor;\n"; + ss << " double fGda, fZins, fAlterWert, fNeuerWert;\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); + ss<< " int buffer_wert_len = "; + ss<< tmpCurDVR0->GetArrayLength(); + ss << ";\n"; + ss<< " int buffer_rest_len = "; + ss<< tmpCurDVR1->GetArrayLength(); + ss << ";\n"; + ss<< " int buffer_dauer_len = "; + ss<< tmpCurDVR2->GetArrayLength(); + ss << ";\n"; + ss<< " int buffer_periode_len = "; + ss<< tmpCurDVR3->GetArrayLength(); + ss << ";\n"; + ss<< " int buffer_factor_len = "; + ss<< tmpCurDVR4->GetArrayLength(); + ss << ";\n"; +#endif +#ifdef ISNAN + ss <<" if(gid0 >= buffer_wert_len || isNan("; + ss <<vSubArguments[0]->GenSlidingWindowDeclRef(); + ss <<"))\n"; + ss <<" fWert = 0;\n else\n"; +#endif + ss <<" fWert = "<<vSubArguments[0]->GenSlidingWindowDeclRef(); + ss <<";\n"; +#ifdef ISNAN + ss <<" if(gid0 >= buffer_rest_len || isNan("; + ss <<vSubArguments[1]->GenSlidingWindowDeclRef(); + ss <<"))\n"; + ss <<" fRest = 0;\n else\n"; +#endif + ss <<" fRest = "; + ss <<vSubArguments[1]->GenSlidingWindowDeclRef(); + ss <<";\n"; +#ifdef ISNAN + ss <<" if(gid0 >= buffer_dauer_len || isNan("; + ss <<vSubArguments[2]->GenSlidingWindowDeclRef(); + ss <<"))\n"; + ss <<" fDauer = 0;\n else\n"; +#endif + ss <<" fDauer = "<<vSubArguments[2]->GenSlidingWindowDeclRef(); + ss <<";\n"; +#ifdef ISNAN + ss <<" if(gid0 >= buffer_periode_len || isNan("; + ss <<vSubArguments[3]->GenSlidingWindowDeclRef(); + ss <<"))\n"; + ss <<" fPeriode = 0;\n else\n"; +#endif + ss <<" fPeriode = "<<vSubArguments[3]->GenSlidingWindowDeclRef(); + ss <<";\n"; +#ifdef ISNAN + ss <<" if(gid0 >= buffer_factor_len || isNan("; + ss <<vSubArguments[4]->GenSlidingWindowDeclRef(); + ss <<"))\n"; + ss <<" fFaktor = 0;\n else\n"; +#endif + ss <<" fFaktor = "<<vSubArguments[4]->GenSlidingWindowDeclRef(); + ss <<";\n"; + ss <<" fZins = fFaktor / fDauer;\n"; + ss <<" if (fZins >= 1.0)\n"; + ss <<" {\n"; + ss <<" fZins = 1.0;\n"; + ss <<" if (fPeriode == 1.0)\n"; + ss <<" fAlterWert = fWert;\n"; + ss <<" else\n"; + ss <<" fAlterWert = 0.0;\n"; + ss <<" }\n"; + ss <<" else\n"; + ss <<" fAlterWert = fWert * pow(1.0 - fZins, fPeriode - 1.0);\n"; + ss <<" fNeuerWert = fWert * pow(1.0 - fZins, fPeriode);\n"; + ss <<" if (fNeuerWert < fRest)\n"; + ss <<" fGda = fAlterWert - fRest;\n"; + ss <<" else\n"; + ss <<" fGda = fAlterWert - fNeuerWert;\n"; + ss <<" if (fGda < 0.0)\n"; + ss <<" fGda = 0.0;\n"; + ss <<" tmp = fGda;\n"; + ss <<" return tmp;\n"; + ss <<"}"; +} void OpPV::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 fbf5bee..de1ffc7 100644 --- a/sc/source/core/opencl/op_financial.hxx +++ b/sc/source/core/opencl/op_financial.hxx @@ -339,6 +339,15 @@ public: virtual std::string BinFuncName(void) const { return "Coupnum"; } }; +class OpDDB:public Normal +{ +public: + virtual void GenSlidingWindowFunction(std::stringstream &ss, + const std::string sSymName, SubArguments &vSubArguments); + + virtual std::string BinFuncName(void) const { return "DDB"; } +}; + class OpAmordegrc:public Normal { public: _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits