[Libreoffice-commits] core.git: 2 commits - sc/qa sc/source
yiming ju
yiming at multicorewareinc.com
Tue Nov 5 21:02:14 CET 2013
sc/qa/unit/data/xls/opencl/financial/PV.xls |binary
sc/qa/unit/opencl-test.cxx | 24 ++++
sc/source/core/opencl/formulagroupcl.cxx | 4
sc/source/core/opencl/op_financial.cxx | 144 ++++++++++++++++++++++++++++
sc/source/core/opencl/op_financial.hxx | 8 +
sc/source/core/tool/token.cxx | 1
6 files changed, 181 insertions(+)
New commits:
commit c1492fe9ea81eb7d6af3e636f022a23fb7874b9d
Author: yiming ju <yiming at multicorewareinc.com>
Date: Mon Nov 4 15:54:15 2013 +0800
GPU Calc: implement fix for PV
AMLOEXT-73 FIX
Change-Id: I0b9014a5d78165adaaa41c7e6cc05e876981f37d
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 d3ad8bc..c8c07e4 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1028,6 +1028,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
mvSubArguments.push_back(SoPHelper(ts,
ft->Children[i], new OpAbs));
break;
+ case ocBW:
+ mvSubArguments.push_back(SoPHelper(ts,
+ ft->Children[i], new OpPV));
+ 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 d5853f6..cb31cd1 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -3388,6 +3388,150 @@ void OpTbillyield::GenSlidingWindowFunction(
ss << "}\n";
}
+void OpPV::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 result = " <<"0"<<";\n";
+ ss << " int gid0 = get_global_id(0);\n";
+ ss << " double zins;\n";
+ ss << " double zzr;\n";
+ ss << " double rmz;\n";
+ ss << " double zw;\n";
+ ss << " double flag;\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);
+
+ const formula::SingleVectorRefToken*tmpCurDVR3;
+ const formula::SingleVectorRefToken*tmpCurDVR4;
+
+ if(vSubArguments.size()>3)
+ {
+ FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
+ tmpCurDVR3= dynamic_cast<const formula::SingleVectorRefToken *>(
+tmpCur3);
+ ss<< " int buffer_zw_len = ";
+ ss<< tmpCurDVR3->GetArrayLength();
+ ss << ";\n";
+ }
+
+ if(vSubArguments.size()>4)
+ {
+ FormulaToken *tmpCur4 = vSubArguments[4]->GetFormulaToken();
+ tmpCurDVR4= dynamic_cast<const formula::SingleVectorRefToken *>(
+tmpCur4);
+ ss<< " int buffer_flag_len = ";
+ ss<< tmpCurDVR4->GetArrayLength();
+ ss << ";\n";
+ }
+
+ ss<< " int buffer_zins_len = ";
+ ss<< tmpCurDVR0->GetArrayLength();
+ ss << ";\n";
+
+ ss<< " int buffer_zzr_len = ";
+ ss<< tmpCurDVR1->GetArrayLength();
+ ss << ";\n";
+
+ ss<< " int buffer_rmz_len = ";
+ ss<< tmpCurDVR2->GetArrayLength();
+ ss << ";\n";
+
+#endif
+
+#ifdef ISNAN
+ ss<<" if(gid0>=buffer_zins_len || isNan(";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss<<"))\n";
+ ss<<" zins = 0;\n else \n";
+#endif
+ ss<<" zins = ";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss<<";\n";
+
+#ifdef ISNAN
+ ss<<" if(gid0>=buffer_zzr_len || isNan(";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss<<"))\n";
+ ss<<" zzr = 0;\n else \n";
+#endif
+ ss<<" zzr = ";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss<<";\n";
+
+#ifdef ISNAN
+ ss<<" if(gid0>=buffer_rmz_len || isNan(";
+ ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss<<"))\n";
+ ss<<" rmz = 0;\n else \n";
+#endif
+ ss<<" rmz = ";
+ ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss<<";\n";
+
+ if(vSubArguments.size()>3)
+ {
+#ifdef ISNAN
+ ss<<" if(gid0>=buffer_zw_len || isNan(";
+ ss << vSubArguments[3]->GenSlidingWindowDeclRef();
+ ss<<"))\n";
+ ss<<" zw = 0;\n else \n";
+#endif
+ ss<<" zw = ";
+ ss << vSubArguments[3]->GenSlidingWindowDeclRef();
+ ss<<";\n";
+ }else
+ {
+ ss<<" zw = 0;\n";
+ }
+
+ if(vSubArguments.size()>4)
+ {
+#ifdef ISNAN
+ ss<<" if(gid0>=buffer_flag_len || isNan(";
+ ss << vSubArguments[4]->GenSlidingWindowDeclRef();
+ ss<<"))\n";
+ ss<<" flag = 0;\n else \n";
+#endif
+ ss<<" flag = ";
+ ss << vSubArguments[4]->GenSlidingWindowDeclRef();
+ ss<<";\n";
+ }else
+ {
+ ss<<" flag = 0;\n";
+ }
+ ss << " if(zins == 0)\n";
+ ss << " result=zw+rmz*zzr;\n";
+ ss << " else if(flag > 0)\n";
+ ss << " result=(zw*pow(1+zins,-zzr))+";
+ ss << "(rmz*(1-pow(1+zins,-zzr+1))/zins)+rmz;\n";
+ ss << " else\n";
+ ss << " result=(zw*pow(1+zins,-zzr))+";
+ ss << "(rmz*(1-pow(1+zins,-zzr))/zins);\n";
+ ss << " return -result;\n";
+ ss << "}";
+}
+
}}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/opencl/op_financial.hxx b/sc/source/core/opencl/op_financial.hxx
index 6bc3c19..544fc5f 100644
--- a/sc/source/core/opencl/op_financial.hxx
+++ b/sc/source/core/opencl/op_financial.hxx
@@ -390,6 +390,14 @@ public:
virtual std::string BinFuncName(void) const { return "MIRR"; }
};
+class OpPV: public Normal
+{
+public:
+ virtual void GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments);
+ virtual std::string BinFuncName(void) const { return "PV"; }
+};
+
}}
#endif
commit 66530aeeaf9212bfcb371048d9b6f6ca3c09e196
Author: yiming ju <yiming at multicorewareinc.com>
Date: Mon Nov 4 15:48:10 2013 +0800
GPU Calc: unit test cases for PV
Need open macro NO_FALLBACK_TO_SWINTERP in formulagroupcl.cxx for test
AMLOEXT-73 BUG
Change-Id: I2ed3e1dfa07aac5f28942a1a2c94826757c9d0cd
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/PV.xls b/sc/qa/unit/data/xls/opencl/financial/PV.xls
new file mode 100644
index 0000000..a6f8d9c
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/financial/PV.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 90867ba..de5bd74 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -124,6 +124,7 @@ public:
void testFinancialCoupnumFormula();
void testMathFormulaSinh();
void testMathFormulaAbs();
+ void testFinacialPVFormula();
CPPUNIT_TEST_SUITE(ScOpenclTest);
CPPUNIT_TEST(testSharedFormulaXLS);
CPPUNIT_TEST(testFinacialFormula);
@@ -179,6 +180,7 @@ public:
CPPUNIT_TEST(testFinancialCoupnumFormula);
CPPUNIT_TEST(testMathFormulaSinh);
CPPUNIT_TEST(testMathFormulaAbs);
+ CPPUNIT_TEST(testFinacialPVFormula);
CPPUNIT_TEST_SUITE_END();
private:
@@ -1240,6 +1242,28 @@ void ScOpenclTest::testFinacialDISCFormula()
xDocSh->DoClose();
xDocShRes->DoClose();
}
+//[AMLOEXT-73]
+void ScOpenclTest:: testFinacialPVFormula()
+{
+ if (!detectOpenCLDevice())
+ return;
+ ScDocShellRef xDocSh = loadDoc("opencl/financial/PV.", XLS);
+ ScDocument *pDoc = xDocSh->GetDocument();
+ CPPUNIT_ASSERT(pDoc);
+ enableOpenCL();
+ pDoc->CalcAll();
+ ScDocShellRef xDocShRes = loadDoc("opencl/financial/PV.", 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();
+}
//[AMLOEXT-75]
void ScOpenclTest::testFinacialINTRATEFormula()
{
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index c9d8d70..ac0be80 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1370,6 +1370,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
case ocLaufz:
case ocSinHyp:
case ocAbs:
+ case ocBW:
// Don't change the state.
break;
default:
More information about the Libreoffice-commits
mailing list