[Libreoffice-commits] core.git: 2 commits - sc/qa sc/source
mulei
mulei at multicorewareinc.com
Fri Nov 1 18:52:33 CET 2013
sc/qa/unit/data/xls/opencl/financial/PMT.xls |binary
sc/qa/unit/opencl-test.cxx | 25 +++++
sc/source/core/opencl/op_financial.cxx | 130 +++++++++++++++++++++------
3 files changed, 127 insertions(+), 28 deletions(-)
New commits:
commit 35f8d734dd54cafd1e9d07a1e67b63c366b93a9d
Author: mulei <mulei at multicorewareinc.com>
Date: Fri Nov 1 12:02:35 2013 -0500
GPU Calc: implement NAN argument handling in PMT
Change-Id: I1288a20652b4ceb66d90314f7acddb73506dfb43
Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
Signed-off-by: haochen <haochen at multicorewareinc.com>
diff --git a/sc/source/core/opencl/op_financial.cxx b/sc/source/core/opencl/op_financial.cxx
index da4845c..69f7d02 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -1837,44 +1837,118 @@ void OpYieldmat::GenSlidingWindowFunction(
ss << "}";
}
-void OpPMT::GenSlidingWindowFunction(
- std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
+void OpPMT::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 << ",";
+ ss << ", ";
vSubArguments[i]->GenSlidingWindowDecl(ss);
}
- ss << ") {\n\t";
- ss << "double tmp = 0;\n\t";
- ss<<"double tFv=0,tType=0;\n\t";
- ss << "int gid0 = get_global_id(0);\n\t";
- if(vSubArguments.size()==4)
- ss<<"tFv="<<vSubArguments[3]->GenSlidingWindowDeclRef()<<";\n\t";
- else if(vSubArguments.size()==5)
+ ss << ") {\n ";
+ ss << "double tmp = 0;\n ";
+ ss << "int gid0 = get_global_id(0);\n ";
+ ss<<"double tmp0,tmp1,tmp2;\n ";
+ ss<<"double tmp3=0,tmp4=0;\n ";
+ unsigned i = vSubArguments.size();
+ size_t nItems = 0;
+ ss <<"\n ";
+ //while (i-- > 1)
+ for (size_t i = 0; i < vSubArguments.size(); i++)
{
- ss<<"tType="<<vSubArguments[4]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
- ss<<"tFv="<<vSubArguments[3]->GenSlidingWindowDeclRef();
- ss<<";\n\t";
+ FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
+ assert(pCur);
+ if (pCur->GetType() == formula::svDoubleVectorRef)
+ {
+ const formula::DoubleVectorRefToken* pDVR =
+ dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+ size_t nCurWindowSize = pDVR->GetRefRowSize();
+ ss << "for (int i = ";
+ if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
+#ifdef ISNAN
+ ss << "gid0; i < " << pDVR->GetArrayLength();
+ ss << " && i < " << nCurWindowSize << "; i++){\n ";
+#else
+ ss << "gid0; i < "<< nCurWindowSize << "; i++)\n ";
+#endif
+ } else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
+#ifdef ISNAN
+ ss << "0; i < " << pDVR->GetArrayLength();
+ ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n ";
+#else
+ ss << "0; i < gid0+"<< nCurWindowSize << "; i++)\n ";
+#endif
+ } else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
+#ifdef ISNAN
+ ss << "0; i + gid0 < " << pDVR->GetArrayLength();
+ ss << " && i < "<< nCurWindowSize << "; i++){\n ";
+#else
+ ss << "0; i < "<< nCurWindowSize << "; i++)\n ";
+#endif
+ }
+ else {
+#ifdef ISNAN
+ ss << "0; i < "<< nCurWindowSize << "; i++){\n ";
+#else
+ ss << "0; i < "<< nCurWindowSize << "; i++)\n ";
+#endif
+ }
+ nItems += nCurWindowSize;
+ }
+ else if (pCur->GetType() == formula::svSingleVectorRef)
+ {
+#ifdef ISNAN
+ const formula::SingleVectorRefToken* pSVR =
+ dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
+ ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n ";
+#else
+ nItems += 1;
+#endif
+ }
+ else if (pCur->GetType() == formula::svDouble)
+ {
+#ifdef ISNAN
+ ss << "{\n ";
+#endif
+ nItems += 1;
+ }
+ else
+ {
+#ifdef ISNAN
+#endif
+ nItems += 1;
+ }
+#ifdef ISNAN
+ if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
+ {
+ ss << "if (isNan(";
+ ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+ ss << "))\n ";
+ ss << "tmp"<<i<<"= 0;\n ";
+ ss << "else\n ";
+ ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
+ ss << ";\n }\n ";
+ }
+ else
+ {
+ ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
+ ss <<";\n ";
+ }
+#else
+ ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
+ ss <<";\n ";
+
+#endif
}
- ss<<"if("<<vSubArguments[0]->GenSlidingWindowDeclRef()<<"==0.0)\n\t";
- ss<<"\treturn ("<<vSubArguments[2]->GenSlidingWindowDeclRef();
- ss<<"+tFv)/";
- ss<<vSubArguments[1]->GenSlidingWindowDeclRef()<<";\n\t";
- ss<<"double abl = pow(1.0+"<<vSubArguments[0]
- ->GenSlidingWindowDeclRef();
- ss << ","<<vSubArguments[1]->GenSlidingWindowDeclRef();
- ss<<");\n\ttmp-=tFv";
- ss<<";\n\ttmp-="<<vSubArguments[2]->GenSlidingWindowDeclRef();
- ss<<"*abl;\n\t"<<"tmp =tmp/(1.0+"<<vSubArguments[0]
- ->GenSlidingWindowDeclRef();
- ss<<"*tType";
- ss<<") / ( (abl-1.0)/"<<vSubArguments[0]->GenSlidingWindowDeclRef();
- ss << ");\n\t";
+ ss<<"if(tmp0==0.0)\n ";
+ ss<<" return -(tmp2+tmp3)/tmp1;\n ";
+ ss<<"double abl = pow(1.0+tmp0,tmp1);\n tmp-=tmp3";
+ ss<<";\n tmp-=tmp2*abl;\n ";
+ ss<<"tmp =tmp/(1.0+tmp0*tmp4";
+ ss<<") / ( (abl-1.0)/tmp0);\n ";
ss << "return tmp;\n";
ss << "}";
}
commit 9f73e855afb061ddeedcbb25f0fd826902784f3c
Author: mulei <mulei at multicorewareinc.com>
Date: Fri Nov 1 11:52:04 2013 -0500
GPU Calc: unit test cases for NAN argument handling in PMT
Change-Id: I8f8e7a6220cff7e825a08fe16352478ea7090964
Signed-off-by: I-Jui (Ray) Sung <ray at multicorewareinc.com>
Signed-off-by: haochen <haochen at multicorewareinc.com>
diff --git a/sc/qa/unit/data/xls/opencl/financial/PMT.xls b/sc/qa/unit/data/xls/opencl/financial/PMT.xls
new file mode 100644
index 0000000..8c14db6
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/financial/PMT.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 4e7e92e..156184f 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -116,6 +116,7 @@ public:
void testFinacialYIELDFormula();
void testFinacialYIELDDISCFormula();
void testFinacialYIELDMATFormula();
+ void testFinacialPMTFormula();
CPPUNIT_TEST_SUITE(ScOpenclTest);
CPPUNIT_TEST(testSharedFormulaXLS);
CPPUNIT_TEST(testFinacialFormula);
@@ -163,6 +164,7 @@ public:
CPPUNIT_TEST(testFinacialYIELDFormula);
CPPUNIT_TEST(testFinacialYIELDDISCFormula);
CPPUNIT_TEST(testFinacialYIELDMATFormula);
+ CPPUNIT_TEST(testFinacialPMTFormula);
CPPUNIT_TEST_SUITE_END();
private:
@@ -1534,6 +1536,29 @@ void ScOpenclTest::testFinacialYIELDMATFormula()
xDocSh->DoClose();
xDocShRes->DoClose();
}
+void ScOpenclTest:: testFinacialPMTFormula()
+{
+ if (!detectOpenCLDevice())
+ return;
+ ScDocShellRef xDocSh = loadDoc("opencl/financial/PMT.", XLS);
+ ScDocument *pDoc = xDocSh->GetDocument();
+ CPPUNIT_ASSERT(pDoc);
+ enableOpenCL();
+ pDoc->CalcAll();
+ ScDocShellRef xDocShRes = loadDoc("opencl/financial/PMT.", XLS);
+ ScDocument *pDocRes = xDocShRes->GetDocument();
+ CPPUNIT_ASSERT(pDocRes);
+ for (SCROW i = 0; i <= 6; ++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" )
{
More information about the Libreoffice-commits
mailing list