[Libreoffice-commits] core.git: Branch 'feature/calc-group-interpreter-4' - 18 commits - sc/qa sc/source
yiming ju
yiming at multicorewareinc.com
Tue Nov 12 22:59:53 PST 2013
sc/qa/unit/data/ods/opencl/math/ArcCos.ods |binary
sc/qa/unit/data/ods/opencl/math/ArcCosHyp.ods |binary
sc/qa/unit/data/xls/opencl/financial/NPER.xls |binary
sc/qa/unit/data/xls/opencl/financial/VDB.xls |binary
sc/qa/unit/data/xls/opencl/financial/XIRR.xls |binary
sc/qa/unit/data/xls/opencl/math/sqrt.xls |binary
sc/qa/unit/data/xls/opencl/math/sumifs.xls |binary
sc/qa/unit/data/xls/opencl/statistical/Kurt.xls |binary
sc/qa/unit/data/xls/opencl/statistical/Normdist.xls |binary
sc/qa/unit/opencl-test.cxx | 260 ++++++++++++++++++++
sc/source/core/opencl/formulagroupcl.cxx | 38 ++
sc/source/core/opencl/op_financial.cxx | 238 ++++++++++++++++++
sc/source/core/opencl/op_financial.hxx | 26 ++
sc/source/core/opencl/op_math.cxx | 151 +++++++++++
sc/source/core/opencl/op_math.hxx | 30 ++
sc/source/core/opencl/op_statistical.cxx | 165 ++++++++++++
sc/source/core/opencl/op_statistical.hxx | 14 +
sc/source/core/opencl/opbase.cxx | 61 ++++
sc/source/core/opencl/opbase.hxx | 10
sc/source/core/opencl/opinlinefun_finacial.cxx | 136 ++++++++++
sc/source/core/tool/token.cxx | 7
21 files changed, 1132 insertions(+), 4 deletions(-)
New commits:
commit 6a1c38402ecb275ba567c9801a801bc6dda358e4
Author: yiming ju <yiming at multicorewareinc.com>
Date: Tue Nov 5 17:12:48 2013 +0800
GPU Calc: unit test cases for XIRR
Need open macro NO_FALLBACK_TO_SWINTERP in formulagroupcl.cxx for test
AMLOEXT-137 BUG
Change-Id: I6b57b304a7eaf3315d083831f0b1d9d2b06b8d94
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/XIRR.xls b/sc/qa/unit/data/xls/opencl/financial/XIRR.xls
new file mode 100644
index 0000000..b9a87ef
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/financial/XIRR.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 3e2e8c0..3fcccb6 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -147,6 +147,7 @@ public:
void testMathFormulaArcCos();
void testMathFormulaSqrt();
void testMathFormulaArcCosHyp();
+ void testFinancialXirrFormula();
CPPUNIT_TEST_SUITE(ScOpenclTest);
CPPUNIT_TEST(testSharedFormulaXLS);
CPPUNIT_TEST(testFinacialFormula);
@@ -223,6 +224,7 @@ public:
CPPUNIT_TEST(testMathFormulaArcCos);
CPPUNIT_TEST(testMathFormulaSqrt);
CPPUNIT_TEST(testMathFormulaArcCosHyp);
+ CPPUNIT_TEST(testFinancialXirrFormula);
CPPUNIT_TEST_SUITE_END();
private:
@@ -2278,6 +2280,34 @@ void ScOpenclTest:: testFinancialVDBFormula()
xDocSh->DoClose();
xDocShRes->DoClose();
}
+ //[AMLOEXT-137]
+void ScOpenclTest:: testFinancialXirrFormula()
+{
+ if (!detectOpenCLDevice())
+ return;
+ ScDocShellRef xDocSh = loadDoc("opencl/financial/XIRR.", XLS);
+ ScDocument *pDoc = xDocSh->GetDocument();
+ CPPUNIT_ASSERT(pDoc);
+ enableOpenCL();
+ pDoc->CalcAll();
+ ScDocShellRef xDocShRes = loadDoc("opencl/financial/XIRR.", XLS);
+ ScDocument *pDocRes = xDocShRes->GetDocument();
+ CPPUNIT_ASSERT(pDocRes);
+ for (SCROW i = 0; i <= 9; ++i)
+ {
+ double fLibre = pDoc->GetValue(ScAddress(2, i, 0));
+ double fExcel = pDocRes->GetValue(ScAddress(2, i, 0));
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel));
+ }
+ for (SCROW i = 18; i <= 26; ++i)
+ {
+ double fLibre = pDoc->GetValue(ScAddress(2, i, 0));
+ double fExcel = pDocRes->GetValue(ScAddress(2, i, 0));
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel));
+ }
+ xDocSh->DoClose();
+ xDocShRes->DoClose();
+}
ScOpenclTest::ScOpenclTest()
: ScBootstrapFixture( "/sc/qa/unit/data" )
{
commit 9c8eb7e0520bdab1ce0e06095654c336d61c18a8
Author: yiming ju <yiming at multicorewareinc.com>
Date: Tue Nov 5 17:16:36 2013 +0800
GPU Calc: implemented for XIRR
AMLOEXT-137 FIX
Change-Id: I108a55037dbbff18848c0166604b316548e1f3c0
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 ce882ad..f7d3eda 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1243,6 +1243,12 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
mvSubArguments.push_back(SoPHelper(ts, ft->Children[i],
new OpMDuration));
}
+ else if ( !(pChild->GetExternal().compareTo(OUString(
+ "com.sun.star.sheet.addin.Analysis.getXirr"))))
+ {
+ mvSubArguments.push_back(SoPHelper(ts, ft->Children[i],
+ new OpXirr));
+ }
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 158bdea..b47b8f7 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -4256,6 +4256,126 @@ void OpVDB::GenSlidingWindowFunction(
}
}
+
+void OpXirr::GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments)
+{
+ FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
+ const formula::DoubleVectorRefToken*pCurDVR= dynamic_cast<const
+ formula::DoubleVectorRefToken *>(tmpCur);
+ size_t nCurWindowSize = pCurDVR->GetArrayLength() <
+ pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
+ pCurDVR->GetRefRowSize() ;
+ 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 << " int doubleIndex = gid0;\n";
+ ss << " int singleIndex = gid0;\n";
+ ss << " double result = 0;\n";
+ ss << " int i=0;\n";
+ if(vSubArguments.size()<2)
+ {
+ ss << " result = -DBL_MAX;\n";
+ ss << " return result;\n";
+ }else
+ {
+ GenTmpVariables(ss,vSubArguments);
+ if(vSubArguments.size() == 2)
+ {
+ ss << " double tmp2 = 0.1;\n";
+ }else
+ {
+ CheckSubArgumentIsNan(ss,vSubArguments,2);
+ }
+ ss << " if(tmp2<=-1)\n";
+ ss << " result = -DBL_MAX;\n";
+ ss << " else\n";
+ ss << " {\n";
+ ss << " double fMaxEps = 1e-10;\n";
+ ss << " int nMaxIter = 50;\n";
+ ss << " double fNewRate, fRateEps, fResultValue, fResultValue2;\n";
+ ss << " int nIter = 0;\n";
+ ss << " int bContLoop;\n";
+ ss << " int windowsSize = ";
+ ss << nCurWindowSize;
+ ss << ";\n";
+ CheckSubArgumentIsNan(ss,vSubArguments,0);
+ CheckSubArgumentIsNan(ss,vSubArguments,1);
+ ss << " double D_0 = tmp1;\n";
+ ss << " double V_0 = tmp0;\n";
+ ss << " double fResultRate = tmp2;\n";
+ ss << " double r;\n";
+ ss << " double fResult;\n";
+ ss << " do\n";
+ ss << " {\n";
+ ss << " fResultValue = V_0;\n";
+ ss << " r = fResultRate + 1;\n";
+ ss << " for (i = ";
+ if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
+ ss << "gid0+1; i < "<< nCurWindowSize <<"; i++)\n";
+ } else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) {
+ ss << "1; i < gid0+"<< nCurWindowSize <<"; i++)\n";
+ } else {
+ ss << "1; i < "<< nCurWindowSize <<"; i++)\n";
+ }
+ ss << " {\n";
+ if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
+ {
+ ss<< " doubleIndex =i+gid0;\n";
+ }else
+ {
+ ss<< " doubleIndex =i;\n";
+ }
+ CheckSubArgumentIsNan(ss,vSubArguments,0);
+ CheckSubArgumentIsNan(ss,vSubArguments,1);
+ ss << " fResultValue += tmp0/pow(r,(tmp1 - D_0)/365.0);\n";
+ ss << " }\n";
+ ss << " fResultValue2 = 0;\n";
+
+ ss << " for (i = ";
+ if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
+ ss << "gid0+1; i < "<< nCurWindowSize <<"; i++)\n";
+ } else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) {
+ ss << "1; i < gid0+"<< nCurWindowSize <<"; i++)\n";
+ } else {
+ ss << "1; i < "<< nCurWindowSize <<"; i++)\n";
+ }
+ ss << " {\n";
+ if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
+ {
+ ss<< " doubleIndex =i+gid0;\n";
+ }else
+ {
+ ss<< " doubleIndex =i;\n";
+ }
+ CheckSubArgumentIsNan(ss,vSubArguments,0);
+ CheckSubArgumentIsNan(ss,vSubArguments,1);
+ ss << " double E_i = (tmp1 - D_0)/365.0;\n";
+ ss << " fResultValue2 -= E_i * tmp0 / pow(r,E_i + 1.0);\n";
+ ss << " }\n";
+ ss << " fNewRate = fResultRate - fResultValue / fResultValue2;\n";
+ ss << " fRateEps = fabs( fNewRate - fResultRate );\n";
+ ss << " fResultRate = fNewRate;\n";
+ ss << " bContLoop = (fRateEps > fMaxEps) && (fabs( fResultValue ) > fMaxEps);\n";
+ ss << " }\n";
+ ss << " while( bContLoop && (++nIter < nMaxIter) );\n";
+ ss << " if( bContLoop )\n";
+ ss << " result = -DBL_MAX;\n";
+ ss << " result = fResultRate;\n";
+ ss << " }\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 c7450bd..68f2915 100644
--- a/sc/source/core/opencl/op_financial.hxx
+++ b/sc/source/core/opencl/op_financial.hxx
@@ -481,6 +481,16 @@ public:
virtual std::string BinFuncName(void) const { return "VDB"; }
virtual void BinInlineFun(std::set<std::string>& ,std::set<std::string>& );
};
+
+class OpXirr: public CheckVariables
+{
+public:
+ virtual void GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments);
+
+ virtual std::string BinFuncName(void) const { return "Xirr"; }
+};
+
}}
#endif
commit 56e6e11a582fc2d8b37390357b07407d6a2025c3
Author: yangzhang <yangzhang at multicorewareinc.com>
Date: Tue Nov 5 17:01:43 2013 +0800
GPU Calc: unit test cases for ARCCOSHYP
Need open macro NO_FALLBACK_TO_SWINTERP in formulagroupcl.cxx for test
AMLOEXT-125 BUG
Change-Id: I6aacd001f5dac09433d00d0f99c1376ca828a48c
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/ods/opencl/math/ArcCosHyp.ods b/sc/qa/unit/data/ods/opencl/math/ArcCosHyp.ods
new file mode 100644
index 0000000..f244d2f
Binary files /dev/null and b/sc/qa/unit/data/ods/opencl/math/ArcCosHyp.ods differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index b63675a..3e2e8c0 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -146,6 +146,7 @@ public:
void testStatisticalFormulaNormdist();
void testMathFormulaArcCos();
void testMathFormulaSqrt();
+ void testMathFormulaArcCosHyp();
CPPUNIT_TEST_SUITE(ScOpenclTest);
CPPUNIT_TEST(testSharedFormulaXLS);
CPPUNIT_TEST(testFinacialFormula);
@@ -221,6 +222,7 @@ public:
CPPUNIT_TEST(testStatisticalFormulaNormdist);
CPPUNIT_TEST(testMathFormulaArcCos);
CPPUNIT_TEST(testMathFormulaSqrt);
+ CPPUNIT_TEST(testMathFormulaArcCosHyp);
CPPUNIT_TEST_SUITE_END();
private:
@@ -2133,6 +2135,31 @@ void ScOpenclTest:: testFinancialDuration_ADDFormula()
xDocSh->DoClose();
xDocShRes->DoClose();
}
+//[AMLOEXT-125]
+void ScOpenclTest::testMathFormulaArcCosHyp()
+{
+ if (!detectOpenCLDevice())
+ return;
+ ScDocShellRef xDocSh =
+ loadDoc("opencl/math/ArcCosHyp.", ODS);
+ ScDocument* pDoc = xDocSh->GetDocument();
+ CPPUNIT_ASSERT(pDoc);
+ enableOpenCL();
+ pDoc->CalcAll();
+ ScDocShellRef xDocShRes =
+ loadDoc("opencl/math/ArcCosHyp.", ODS);
+ ScDocument* pDocRes = xDocShRes->GetDocument();
+ CPPUNIT_ASSERT(pDocRes);
+ // Verify ACosH Function
+ for (SCROW i = 1; i <= 1000; ++i)
+ {
+ double fLibre = pDoc->GetValue(ScAddress(1,i,0));
+ double fExcel = pDocRes->GetValue(ScAddress(1,i,0));
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel));
+ }
+ xDocSh->DoClose();
+ xDocShRes->DoClose();
+}
//[AMLOEXT-126]
void ScOpenclTest:: testFinancialMDurationFormula()
{
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 5fde8c6..aa6e68c 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1385,6 +1385,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
case ocNormDist:
case ocArcCos:
case ocSqrt:
+ case ocArcCosHyp:
// Don't change the state.
break;
default:
commit 868b56b365c89a80d623c9b60294b2778b91ed27
Author: yangzhang <yangzhang at multicorewareinc.com>
Date: Tue Nov 5 17:05:05 2013 +0800
GPU Calc: implemented for ARCCOSHYP
AMLOEXT-125 FIX
Change-Id: I93432a89ad7c60c4575999d9adecda30e5d58198
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 16a99d8..ce882ad 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1092,6 +1092,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
mvSubArguments.push_back(SoPHelper(ts,
ft->Children[i],new OpSqrt));
break;
+ case ocArcCosHyp:
+ mvSubArguments.push_back(SoPHelper(ts,
+ ft->Children[i], new OpArcCosHyp));
+ break;
case ocExternal:
if ( !(pChild->GetExternal().compareTo(OUString(
"com.sun.star.sheet.addin.Analysis.getEffect"))))
diff --git a/sc/source/core/opencl/op_math.cxx b/sc/source/core/opencl/op_math.cxx
index f4ea666..273b814 100644
--- a/sc/source/core/opencl/op_math.cxx
+++ b/sc/source/core/opencl/op_math.cxx
@@ -262,6 +262,34 @@ void OpArcCos::GenSlidingWindowFunction(std::stringstream &ss,
ss << " return acos(tmp);\n";
ss << "}";
}
+void OpArcCosHyp::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";
+#ifdef ISNAN
+ FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR0=
+ dynamic_cast<const formula::SingleVectorRefToken *>(tmpCur0);
+ ss << " int buffer_len = " << tmpCurDVR0->GetArrayLength()<< ";\n";
+ ss << " if((gid0)>=buffer_len || isNan(";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
+ ss << " tmp = " << GetBottom() << ";\n";
+ ss << " else \n ";
+#endif
+ ss << " tmp = ";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+ ss << " return acosh(tmp);\n";
+ ss << "}";
+}
void OpTan::GenSlidingWindowFunction(std::stringstream &ss,
const std::string sSymName, SubArguments &vSubArguments)
{
diff --git a/sc/source/core/opencl/op_math.hxx b/sc/source/core/opencl/op_math.hxx
index 0998b4f..3731c31 100644
--- a/sc/source/core/opencl/op_math.hxx
+++ b/sc/source/core/opencl/op_math.hxx
@@ -65,6 +65,13 @@ public:
virtual std::string GetBottom(void) { return "0.0"; }
virtual std::string BinFuncName(void) const { return "ScACos"; }
};
+class OpArcCosHyp:public Normal{
+public:
+ virtual void GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments);
+ virtual std::string GetBottom(void) { return "1.0"; }
+ virtual std::string BinFuncName(void) const { return "ScACosH"; }
+};
class OpTan: public Normal
{
public:
commit 887a919d7ae3943cd8bbce7b087c9211bb74718f
Author: fengzeng <fengzeng at multicorewareinc.com>
Date: Tue Nov 5 16:49:26 2013 +0800
GPU Calc: unit test cases for SQRT
Need open macro NO_FALLBACK_TO_SWINTERP in formulagroupcl.cxx for test
AMLOEXT-62 BUG
Change-Id: Ibf5a4789deebf75cd017cc015bc2f8ae2618f6f0
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/math/sqrt.xls b/sc/qa/unit/data/xls/opencl/math/sqrt.xls
new file mode 100644
index 0000000..83551c4
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/math/sqrt.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 100764e..b63675a 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -145,6 +145,7 @@ public:
void testFinacialNPERFormula();
void testStatisticalFormulaNormdist();
void testMathFormulaArcCos();
+ void testMathFormulaSqrt();
CPPUNIT_TEST_SUITE(ScOpenclTest);
CPPUNIT_TEST(testSharedFormulaXLS);
CPPUNIT_TEST(testFinacialFormula);
@@ -219,6 +220,7 @@ public:
CPPUNIT_TEST(testFinacialNPERFormula);
CPPUNIT_TEST(testStatisticalFormulaNormdist);
CPPUNIT_TEST(testMathFormulaArcCos);
+ CPPUNIT_TEST(testMathFormulaSqrt);
CPPUNIT_TEST_SUITE_END();
private:
@@ -1277,6 +1279,28 @@ void ScOpenclTest::testMathFormulaTanH()
xDocSh->DoClose();
xDocShRes->DoClose();
}
+//[AMLOEXT-62]
+void ScOpenclTest::testMathFormulaSqrt()
+{
+ if (!detectOpenCLDevice())
+ return;
+ ScDocShellRef xDocSh = loadDoc("opencl/math/sqrt.", XLS);
+ ScDocument* pDoc = xDocSh->GetDocument();
+ CPPUNIT_ASSERT(pDoc);
+ enableOpenCL();
+ pDoc->CalcAll();
+ ScDocShellRef xDocShRes = loadDoc("opencl/math/sqrt.", XLS);
+ ScDocument* pDocRes = xDocShRes->GetDocument();
+ CPPUNIT_ASSERT(pDocRes);
+ for (SCROW i = 0; i <= 15; ++i)
+ {
+ double fLibre = pDoc->GetValue(ScAddress(1,i,0));
+ double fExcel = pDocRes->GetValue(ScAddress(1,i,0));
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel));
+ }
+ xDocSh->DoClose();
+ xDocShRes->DoClose();
+}
//[AMLOEXT-63]
void ScOpenclTest::testFinacialPriceFormula()
{
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 1d5b801..5fde8c6 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1384,6 +1384,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
case ocZZR:
case ocNormDist:
case ocArcCos:
+ case ocSqrt:
// Don't change the state.
break;
default:
commit dd8fdec7210122100e61fb109c050704a4444b02
Author: fengzeng <fengzeng at multicorewareinc.com>
Date: Tue Nov 5 16:53:49 2013 +0800
GPU Calc: implemented for SQRT
AMLOEXT-62 FIX
Change-Id: I5f5bf7f3883442a62c2f7dbd75af166987ff3371
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 2df8c2c..16a99d8 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1088,6 +1088,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
mvSubArguments.push_back(SoPHelper(ts,
ft->Children[i], new OpArcCos));
break;
+ case ocSqrt:
+ mvSubArguments.push_back(SoPHelper(ts,
+ ft->Children[i],new OpSqrt));
+ break;
case ocExternal:
if ( !(pChild->GetExternal().compareTo(OUString(
"com.sun.star.sheet.addin.Analysis.getEffect"))))
diff --git a/sc/source/core/opencl/op_math.cxx b/sc/source/core/opencl/op_math.cxx
index 2d59228..f4ea666 100644
--- a/sc/source/core/opencl/op_math.cxx
+++ b/sc/source/core/opencl/op_math.cxx
@@ -320,6 +320,35 @@ void OpTanH::GenSlidingWindowFunction(std::stringstream &ss,
ss << " return tmp;\n";
ss << "}";
}
+void OpSqrt::GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments)
+{
+ FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur);
+ ss << "\ndouble " << sSymName;
+ ss << "_"<< BinFuncName() <<"(";
+ for (unsigned i = 0; i < vSubArguments.size(); i++)
+ {
+ if (i)
+ ss << ",";
+ vSubArguments[i]->GenSlidingWindowDecl(ss);
+ }
+ ss << ")\n";
+ ss << "{\n";
+ ss << " int gid0=get_global_id(0);\n";
+ ss << " double arg0 = "<< vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss << ";\n";
+#ifdef ISNAN
+ ss << " if(isNan(arg0)||(gid0>=";
+ ss << tmpCurDVR->GetArrayLength();
+ ss << "))\n";
+ ss << " arg0 = 0;\n";
+#endif
+ ss << " double tmp=sqrt(arg0);\n";
+ ss << " return tmp;\n";
+ ss << "}";
+}
}}
diff --git a/sc/source/core/opencl/op_math.hxx b/sc/source/core/opencl/op_math.hxx
index e888849..0998b4f 100644
--- a/sc/source/core/opencl/op_math.hxx
+++ b/sc/source/core/opencl/op_math.hxx
@@ -81,6 +81,14 @@ public:
virtual std::string BinFuncName(void) const { return "TanH"; }
};
+class OpSqrt: public Normal
+{
+public:
+ virtual void GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments);
+
+ virtual std::string BinFuncName(void) const { return "Sqrt"; }
+};
}}
#endif
commit 25e4448b92f2575fd66f8b90ded69c1a60470434
Author: yangzhang <yangzhang at multicorewareinc.com>
Date: Tue Nov 5 16:39:27 2013 +0800
GPU Calc: unit test cases for ARCCOS
Need open macro NO_FALLBACK_TO_SWINTERP in formulagroupcl.cxx for test
AMLOEXT-113 BUG
Change-Id: Ibccb2a40b7a9ffc49d30b694d2f0bab858db14c6
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/ods/opencl/math/ArcCos.ods b/sc/qa/unit/data/ods/opencl/math/ArcCos.ods
new file mode 100644
index 0000000..adce6d3
Binary files /dev/null and b/sc/qa/unit/data/ods/opencl/math/ArcCos.ods differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 529048a..100764e 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -144,6 +144,7 @@ public:
void testStatisticalFormulaKurt();
void testFinacialNPERFormula();
void testStatisticalFormulaNormdist();
+ void testMathFormulaArcCos();
CPPUNIT_TEST_SUITE(ScOpenclTest);
CPPUNIT_TEST(testSharedFormulaXLS);
CPPUNIT_TEST(testFinacialFormula);
@@ -217,6 +218,7 @@ public:
CPPUNIT_TEST(testStatisticalFormulaKurt);
CPPUNIT_TEST(testFinacialNPERFormula);
CPPUNIT_TEST(testStatisticalFormulaNormdist);
+ CPPUNIT_TEST(testMathFormulaArcCos);
CPPUNIT_TEST_SUITE_END();
private:
@@ -2038,6 +2040,31 @@ void ScOpenclTest:: testFinancialDurationFormula()
xDocSh->DoClose();
xDocShRes->DoClose();
}
+//[AMLOEXT-113]
+void ScOpenclTest::testMathFormulaArcCos()
+{
+ if (!detectOpenCLDevice())
+ return;
+ ScDocShellRef xDocSh =
+ loadDoc("opencl/math/ArcCos.", ODS);
+ ScDocument* pDoc = xDocSh->GetDocument();
+ CPPUNIT_ASSERT(pDoc);
+ enableOpenCL();
+ pDoc->CalcAll();
+ ScDocShellRef xDocShRes =
+ loadDoc("opencl/math/ArcCos.", ODS);
+ ScDocument* pDocRes = xDocShRes->GetDocument();
+ CPPUNIT_ASSERT(pDocRes);
+ // Verify ACos Function
+ for (SCROW i = 1; i <= 1000; ++i)
+ {
+ double fLibre = pDoc->GetValue(ScAddress(1,i,0));
+ double fExcel = pDocRes->GetValue(ScAddress(1,i,0));
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel));
+ }
+ xDocSh->DoClose();
+ xDocShRes->DoClose();
+}
//[AMLOEXT-119]
void ScOpenclTest:: testFinacialPPMTFormula()
{
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 73a6a94..1d5b801 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1383,6 +1383,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
case ocKurt:
case ocZZR:
case ocNormDist:
+ case ocArcCos:
// Don't change the state.
break;
default:
commit f1ac3a7f4cb4ed16ab8c60c6194489d479377869
Author: yangzhang <yangzhang at multicorewareinc.com>
Date: Tue Nov 5 16:43:33 2013 +0800
GPU Calc: implemented for ARCCOS
AMLOEXT-113 FIX
Change-Id: I321f50c9c57af1ae68228ed62ce2981ced4846d4
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 b2cd20c..2df8c2c 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1084,6 +1084,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
mvSubArguments.push_back(SoPHelper(ts,
ft->Children[i],new OpNormdist));
break;
+ case ocArcCos:
+ mvSubArguments.push_back(SoPHelper(ts,
+ ft->Children[i], new OpArcCos));
+ break;
case ocExternal:
if ( !(pChild->GetExternal().compareTo(OUString(
"com.sun.star.sheet.addin.Analysis.getEffect"))))
diff --git a/sc/source/core/opencl/op_math.cxx b/sc/source/core/opencl/op_math.cxx
index 2aa6dd1..2d59228 100644
--- a/sc/source/core/opencl/op_math.cxx
+++ b/sc/source/core/opencl/op_math.cxx
@@ -234,6 +234,34 @@ void OpAbs::GenSlidingWindowFunction(std::stringstream &ss,
ss << " return fabs(tmp);\n";
ss << "}";
}
+void OpArcCos::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";
+#ifdef ISNAN
+ FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR0=
+ dynamic_cast<const formula::SingleVectorRefToken *>(tmpCur0);
+ ss << " int buffer_len = "<< tmpCurDVR0->GetArrayLength()<< ";\n";
+ ss << " if((gid0)>=buffer_len || isNan(";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef()<< "))\n";
+ ss << " tmp = " << GetBottom() << ";\n";
+ ss << " else \n ";
+#endif
+ ss << " tmp = ";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef()<< ";\n";
+ ss << " return acos(tmp);\n";
+ ss << "}";
+}
void OpTan::GenSlidingWindowFunction(std::stringstream &ss,
const std::string sSymName, SubArguments &vSubArguments)
{
diff --git a/sc/source/core/opencl/op_math.hxx b/sc/source/core/opencl/op_math.hxx
index d6dda45..e888849 100644
--- a/sc/source/core/opencl/op_math.hxx
+++ b/sc/source/core/opencl/op_math.hxx
@@ -58,6 +58,13 @@ public:
virtual std::string GetBottom(void) { return "0.0"; }
virtual std::string BinFuncName(void) const { return "ScAbs"; }
};
+class OpArcCos:public Normal{
+public:
+ virtual void GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments);
+ virtual std::string GetBottom(void) { return "0.0"; }
+ virtual std::string BinFuncName(void) const { return "ScACos"; }
+};
class OpTan: public Normal
{
public:
commit 9a48f00098077cf78662a059a8d306c26e3bf9e9
Author: hongyu zhong <hongyu at multicorewareinc.com>
Date: Tue Nov 5 16:24:19 2013 +0800
GPU Calc: unit test cases for NORMDIST
Need open macro NO_FALLBACK_TO_SWINTERP in formulagroupcl.cxx for test
AMLOEXT-101 BUG
Change-Id: I794119f51940b10f45be320bd179c6383b97c953
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/statistical/Normdist.xls b/sc/qa/unit/data/xls/opencl/statistical/Normdist.xls
new file mode 100644
index 0000000..a9f2e07
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/statistical/Normdist.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index e2808fd..529048a 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -143,6 +143,7 @@ public:
void testFinancialVDBFormula();
void testStatisticalFormulaKurt();
void testFinacialNPERFormula();
+ void testStatisticalFormulaNormdist();
CPPUNIT_TEST_SUITE(ScOpenclTest);
CPPUNIT_TEST(testSharedFormulaXLS);
CPPUNIT_TEST(testFinacialFormula);
@@ -215,6 +216,7 @@ public:
CPPUNIT_TEST(testFinancialVDBFormula);
CPPUNIT_TEST(testStatisticalFormulaKurt);
CPPUNIT_TEST(testFinacialNPERFormula);
+ CPPUNIT_TEST(testStatisticalFormulaNormdist);
CPPUNIT_TEST_SUITE_END();
private:
@@ -1624,6 +1626,29 @@ void ScOpenclTest::testStatisticalFormulaMedian()
xDocSh->DoClose();
xDocShRes->DoClose();
}
+//[AMLOEXT-101]
+void ScOpenclTest::testStatisticalFormulaNormdist()
+{
+ if (!detectOpenCLDevice())
+ return;
+ ScDocShellRef xDocSh = loadDoc("opencl/statistical/Normdist.",XLS);
+ ScDocument* pDoc = xDocSh->GetDocument();
+ CPPUNIT_ASSERT(pDoc);
+ enableOpenCL();
+ pDoc->CalcAll();
+ ScDocShellRef xDocShRes = loadDoc("opencl/statistical/Normdist.",XLS);
+ ScDocument* pDocRes = xDocShRes->GetDocument();
+ CPPUNIT_ASSERT(pDocRes);
+ // Check the results of formula cells in the shared formula range.
+ for (SCROW i = 1; i <= 19; ++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-108]
void ScOpenclTest::testFinacialNPERFormula()
{
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 80a1236..73a6a94 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1382,6 +1382,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
case ocVBD:
case ocKurt:
case ocZZR:
+ case ocNormDist:
// Don't change the state.
break;
default:
commit 0d5c4847c0a078bebb8b14905fd365456cc36928
Author: hongyu zhong <hongyu at multicorewareinc.com>
Date: Tue Nov 5 16:33:10 2013 +0800
GPU Calc: implemented NORMDIST
AMLOEXT-101 FIX
Change-Id: Id0e65824f63fd3d88b8092566b064719aeb11596
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 20242e0..b2cd20c 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1080,6 +1080,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
mvSubArguments.push_back(SoPHelper(ts,
ft->Children[i], new OpNPER));
break;
+ case ocNormDist:
+ mvSubArguments.push_back(SoPHelper(ts,
+ ft->Children[i],new OpNormdist));
+ break;
case ocExternal:
if ( !(pChild->GetExternal().compareTo(OUString(
"com.sun.star.sheet.addin.Analysis.getEffect"))))
diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx
index 5b61957..f1758b5 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -938,6 +938,89 @@ void OpRsq::GenSlidingWindowFunction(
ss << "return (tmp * tmp);\n";
ss << "}\n";
}
+void OpNormdist::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 << "{\n";
+ ss << " double x,mue,sigma,c;\n";
+ ss << " int gid0=get_global_id(0);\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_x_len = ";
+ ss << tmpCurDVR0->GetArrayLength();
+ ss << ";\n";
+ ss << " int buffer_mue_len = ";
+ ss << tmpCurDVR1->GetArrayLength();
+ ss << ";\n";
+ ss << " int buffer_sigma_len = ";
+ ss << tmpCurDVR2->GetArrayLength();
+ ss << ";\n";
+ ss << " int buffer_c_len = ";
+ ss << tmpCurDVR3->GetArrayLength();
+ ss << ";\n";
+#endif
+#ifdef ISNAN
+ ss <<"if((gid0)>=buffer_c_len || isNan(";
+ ss << vSubArguments[3]->GenSlidingWindowDeclRef();
+ ss <<"))\n";
+ ss <<" c = 0;\nelse \n";
+#endif
+ ss << " c = "<<vSubArguments[3]->GenSlidingWindowDeclRef();
+ ss << ";\n";
+#ifdef ISNAN
+ ss <<"if((gid0)>=buffer_sigma_len || isNan(";
+ ss << vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss <<"))\n";
+ ss <<" sigma = 0;\nelse \n";
+#endif
+ ss <<" sigma = "<<vSubArguments[2]->GenSlidingWindowDeclRef();
+ ss <<";\n";
+#ifdef ISNAN
+ ss <<" if((gid0)>=buffer_mue_len || isNan(";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss <<"))\n";
+ ss <<" mue = 0;\nelse \n";
+#endif
+ ss <<" mue = "<<vSubArguments[1]->GenSlidingWindowDeclRef();
+ ss <<";\n";
+#ifdef ISNAN
+ ss<<" if((gid0)>=buffer_x_len || isNan(";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss<<"))\n";
+ ss<<" x = 0;\nelse \n";
+#endif
+ ss <<" x = "<<vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss << ";\n";
+ ss << "double mid,tmp;\n";
+ ss << "mid = (x - mue)/sigma;\n";
+ ss << "if(c)\n";
+ ss << " tmp = 0.5 *erfc(-mid * 0.7071067811865475);\n";
+ ss << "else \n";
+ ss <<" tmp=(0.39894228040143268*exp(-(mid * mid)/2.0))/sigma;\n";
+ ss << "return tmp;\n";
+ ss << "}\n";
+}
void OpMedian::GenSlidingWindowFunction(
std::stringstream &ss, const std::string sSymName,
diff --git a/sc/source/core/opencl/op_statistical.hxx b/sc/source/core/opencl/op_statistical.hxx
index 87b02b9..e3e4573 100644
--- a/sc/source/core/opencl/op_statistical.hxx
+++ b/sc/source/core/opencl/op_statistical.hxx
@@ -117,6 +117,12 @@ public:
const std::string sSymName, SubArguments &vSubArguments);
virtual std::string BinFuncName(void) const { return "OpRsq"; }
};
+class OpNormdist:public Normal{
+ public:
+ virtual void GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments);
+ virtual std::string BinFuncName(void) const { return "OpNormdist"; }
+};
class OpMedian:public Normal{
public:
virtual void GenSlidingWindowFunction(std::stringstream &ss,
commit 5e5f9e3814569e072426b376a0e19a5f12d1c0fc
Author: mulei <mulei at multicorewareinc.com>
Date: Tue Nov 5 15:46:15 2013 +0800
GPU Calc: unit test cases for NPER
Need open macro NO_FALLBACK_TO_SWINTERP in formulagroupcl.cxx for test
AMLOEXT-108 BUG
Change-Id: Ib1469a02884e926ea2f5f93a6ffde95ca9b948d7
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/NPER.xls b/sc/qa/unit/data/xls/opencl/financial/NPER.xls
new file mode 100644
index 0000000..a5e2cbc
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/financial/NPER.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 329d3b8..e2808fd 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -142,6 +142,7 @@ public:
void testMathSumIfsFormula();
void testFinancialVDBFormula();
void testStatisticalFormulaKurt();
+ void testFinacialNPERFormula();
CPPUNIT_TEST_SUITE(ScOpenclTest);
CPPUNIT_TEST(testSharedFormulaXLS);
CPPUNIT_TEST(testFinacialFormula);
@@ -213,6 +214,7 @@ public:
CPPUNIT_TEST(testMathSumIfsFormula);
CPPUNIT_TEST(testFinancialVDBFormula);
CPPUNIT_TEST(testStatisticalFormulaKurt);
+ CPPUNIT_TEST(testFinacialNPERFormula);
CPPUNIT_TEST_SUITE_END();
private:
@@ -1622,6 +1624,28 @@ void ScOpenclTest::testStatisticalFormulaMedian()
xDocSh->DoClose();
xDocShRes->DoClose();
}
+//[AMLOEXT-108]
+void ScOpenclTest::testFinacialNPERFormula()
+{
+ if (!detectOpenCLDevice())
+ return;
+ ScDocShellRef xDocSh = loadDoc("opencl/financial/NPER.", XLS);
+ ScDocument *pDoc = xDocSh->GetDocument();
+ CPPUNIT_ASSERT(pDoc);
+ enableOpenCL();
+ pDoc->CalcAll();
+ ScDocShellRef xDocShRes = loadDoc("opencl/financial/NPER.", XLS);
+ ScDocument *pDocRes = xDocShRes->GetDocument();
+ CPPUNIT_ASSERT(pDocRes);
+ for (SCROW i = 0; i <= 10; ++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-110]
void ScOpenclTest::testFinancialAmorlincFormula()
{
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 5988e98..80a1236 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1381,6 +1381,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
case ocZW:
case ocVBD:
case ocKurt:
+ case ocZZR:
// Don't change the state.
break;
default:
commit 1766baf00bef5c48f5079597bc7b93a87a09117e
Author: mulei <mulei at multicorewareinc.com>
Date: Tue Nov 5 15:53:28 2013 +0800
GPU Calc: implemented for NPER
AMLOEXT-108 FIX
Change-Id: I3abd1f270c7fe257f59d0080a8fc5a4fd5c7b33e
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 b5adc66..20242e0 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1076,6 +1076,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
mvSubArguments.push_back(SoPHelper(ts,
ft->Children[i], new OpKurt));
break;
+ case ocZZR:
+ mvSubArguments.push_back(SoPHelper(ts,
+ ft->Children[i], new OpNPER));
+ 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 410429a..158bdea 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -2459,6 +2459,74 @@ void OpPrice::GenSlidingWindowFunction(std::stringstream &ss,
ss << "return tmp;\n";
ss << "}";
}
+void OpNPER::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 = 0;\n";
+ ss << " int gid0 = get_global_id(0);\n";
+ for (unsigned n = 0; n < vSubArguments.size(); n++)
+ {
+ ss<<" double tmp"<<n<<"=";
+ ss<<vSubArguments[n]->GenSlidingWindowDeclRef();
+ ss<<";\n";
+ }
+#ifdef ISNAN
+ FormulaToken *tmpCur0 = vSubArguments[0]
+ ->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR0= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur0);
+ ss<<" if("<<tmpCurDVR0->GetArrayLength()<<"<=gid0||";
+ ss <<"isNan(tmp0))\n";
+ ss<<" tmp0= 0;\n";
+ FormulaToken *tmpCur1 = vSubArguments[1]
+ ->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR1= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur1);
+ ss<<" if("<<tmpCurDVR1->GetArrayLength()<<"<=gid0||";
+ ss <<"isNan(tmp1))\n";
+ ss<<" tmp1= 0;\n";
+ FormulaToken *tmpCur2 = vSubArguments[2]
+ ->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR2= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur2);
+ ss<<" if("<<tmpCurDVR2->GetArrayLength()<<"<=gid0||";
+ ss <<"isNan(tmp2))\n";
+ ss<<" tmp2= 0;\n";
+ FormulaToken *tmpCur3 = vSubArguments[3]
+ ->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR3= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur3);
+ ss<<" if("<<tmpCurDVR3->GetArrayLength()<<"<=gid0||";
+ ss <<"isNan(tmp3))\n";
+ ss<<" tmp3= 0;\n";
+ FormulaToken *tmpCur4 = vSubArguments[4]
+ ->GetFormulaToken();
+ const formula::SingleVectorRefToken*tmpCurDVR4= dynamic_cast<const
+ formula::SingleVectorRefToken *>(tmpCur4);
+ ss<<" if("<<tmpCurDVR4->GetArrayLength()<<"<=gid0||";
+ ss <<"isNan(tmp4))\n";
+ ss<<" tmp4= 0;\n";
+#endif
+ ss <<" if (tmp0 == 0.0)\n";
+ ss <<" tmp=(-(tmp2 + tmp3)/tmp1);\n";
+ ss <<" else if (tmp4 > 0.0)\n";
+ ss <<" tmp=log(-(tmp0*tmp3-tmp1*(1.0+tmp0))/";
+ ss <<"(tmp0*tmp2+tmp1*(1.0+tmp0)))/log(1.0+tmp0);\n";
+ ss <<" else\n";
+ ss <<" tmp=log(-(tmp0*tmp3-tmp1)/(tmp0*tmp2+tmp1))";
+ ss <<"/log(1.0+tmp0);\n";
+ ss <<" return tmp;\n";
+ ss <<"}";
+}
void OpPPMT::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 a24db10..c7450bd 100644
--- a/sc/source/core/opencl/op_financial.hxx
+++ b/sc/source/core/opencl/op_financial.hxx
@@ -313,6 +313,13 @@ public:
virtual std::string BinFuncName(void) const { return "Price"; }
};
+class OpNPER: public Normal
+{
+public:
+ virtual void GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments);
+ virtual std::string BinFuncName(void) const { return "NPER"; }
+};
class OpPPMT: public Normal
{
public:
commit 7ca1aefe95967760389f7e27b86668cd14647b85
Author: mingli ju <mingli at multicorewareinc.com>
Date: Tue Nov 5 15:27:00 2013 +0800
GPU Calc: unit test cases for KURT
Need open macro NO_FALLBACK_TO_SWINTERP in formulagroupcl.cxx for test
AMLOEXT-87 BUG
Change-Id: Id0ba1660027fa45653a99a1b1e63f730fdfb2bee
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/statistical/Kurt.xls b/sc/qa/unit/data/xls/opencl/statistical/Kurt.xls
new file mode 100644
index 0000000..f4ed4db
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/statistical/Kurt.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 53e59c3..329d3b8 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -141,6 +141,7 @@ public:
void testFinancialMDurationFormula();
void testMathSumIfsFormula();
void testFinancialVDBFormula();
+ void testStatisticalFormulaKurt();
CPPUNIT_TEST_SUITE(ScOpenclTest);
CPPUNIT_TEST(testSharedFormulaXLS);
CPPUNIT_TEST(testFinacialFormula);
@@ -211,6 +212,7 @@ public:
CPPUNIT_TEST(testFinancialMDurationFormula);
CPPUNIT_TEST(testMathSumIfsFormula);
CPPUNIT_TEST(testFinancialVDBFormula);
+ CPPUNIT_TEST(testStatisticalFormulaKurt);
CPPUNIT_TEST_SUITE_END();
private:
@@ -1479,6 +1481,29 @@ void ScOpenclTest::testStatisticalFormulaRsq()
xDocSh->DoClose();
xDocShRes->DoClose();
}
+//[AMLOEXT-87]
+void ScOpenclTest::testStatisticalFormulaKurt()
+{
+ if (!detectOpenCLDevice())
+ return;
+ ScDocShellRef xDocSh = loadDoc("opencl/statistical/Kurt.", XLS);
+ ScDocument* pDoc = xDocSh->GetDocument();
+ CPPUNIT_ASSERT(pDoc);
+ enableOpenCL();
+ pDoc->CalcAll();
+ ScDocShellRef xDocShRes = loadDoc("opencl/statistical/Kurt.", XLS);
+ ScDocument* pDocRes = xDocShRes->GetDocument();
+ CPPUNIT_ASSERT(pDocRes);
+ // Check the results of formula cells in the shared formula range.
+ for (SCROW i = 1; i <= 19; ++i)
+ {
+ double fLibre = pDoc->GetValue(ScAddress(1,i,0));
+ double fExcel = pDocRes->GetValue(ScAddress(1,i,0));
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel));
+ }
+ xDocSh->DoClose();
+ xDocShRes->DoClose();
+}
//[AMLOEXT-90]
void ScOpenclTest::testMathFormulaCsc()
{
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 02dd30a..5988e98 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1380,6 +1380,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
case ocGDA:
case ocZW:
case ocVBD:
+ case ocKurt:
// Don't change the state.
break;
default:
commit 7d37296024b9ee713467d3a5bb68300053aa7cc7
Author: mingli <mingli at multicorewareinc.com>
Date: Tue Nov 5 15:34:53 2013 +0800
GPU Calc: implemented for KURT
AMLOEXT-87 FIX
Change-Id: I5b16116f53b00619b4bbeaa358545f32297f33da
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 e14d570..b5adc66 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1072,6 +1072,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
mvSubArguments.push_back(SoPHelper(ts,
ft->Children[i],new OpVDB));
break;
+ case ocKurt:
+ mvSubArguments.push_back(SoPHelper(ts,
+ ft->Children[i], new OpKurt));
+ break;
case ocExternal:
if ( !(pChild->GetExternal().compareTo(OUString(
"com.sun.star.sheet.addin.Analysis.getEffect"))))
diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx
index 356b170..5b61957 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -1015,7 +1015,87 @@ void OpMedian::GenSlidingWindowFunction(
ss <<" return tmp;\n";
ss << "}\n";
}
-
+void OpKurt:: GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments)
+{
+ FormulaToken *pCur = vSubArguments[0]->GetFormulaToken();
+ assert(pCur);
+ const formula::DoubleVectorRefToken* pCurDVR =
+ dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
+ size_t nCurWindowSize = pCurDVR->GetRefRowSize();
+ 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 fSum = 0.0;\n";
+ ss << " double vSum = 0.0;\n";
+ ss << " int length="<<nCurWindowSize<<";\n";
+ ss << " double tmp = 0;\n";
+ ss << " for (int i = 0; i <" << nCurWindowSize << "; i++)\n";
+ ss << " {\n";
+ ss << " double arg0 = ";
+ ss<< vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss << ";\n";
+#ifdef ISNAN
+ ss<< " if(isNan(arg0)||((gid0+i)>=";
+ ss<<pCurDVR->GetArrayLength();
+ ss<< "))\n";
+ ss<< " {\n";
+ ss<< " length--;\n";
+ ss<< " continue;\n";
+ ss<< " }\n";
+#endif
+ ss<< " fSum += arg0;\n";
+ ss<< " }\n";
+ ss<< " double fMean = fSum / length;\n";
+ ss<< " for (int i = 0; i <" << nCurWindowSize << "; i++)\n";
+ ss<< " {\n";
+ ss<< " double arg0 = ";
+ ss<< vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss<< ";\n";
+#ifdef ISNAN
+ ss<< " if(isNan(arg0)||((gid0+i)>=";
+ ss<< pCurDVR->GetArrayLength();
+ ss<< "))\n";
+ ss<< " {\n";
+ ss<< " continue;\n";
+ ss<< " }\n";
+#endif
+ ss<< " vSum += (arg0 - fMean) * (arg0 - fMean);\n";
+ ss<< " }\n";
+ ss<< " double fStdDev = sqrt(vSum / (length - 1.0));\n";
+ ss<< " double dx = 0.0;\n";
+ ss<< " double xpower4 = 0.0;\n";
+ ss<< " for (int i = 0; i <" << nCurWindowSize << "; i++)\n";
+ ss<< " {\n";
+ ss<< " double arg0 = ";
+ ss<< vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss<< ";\n";
+#ifdef ISNAN
+ ss<< " if(isNan(arg0)||((gid0+i)>=";
+ ss<< pCurDVR->GetArrayLength();
+ ss<< "))\n";
+ ss<< " {\n";
+ ss<< " continue;\n";
+ ss<< " }\n";
+#endif
+ ss<< " dx = (arg0 -fMean) / fStdDev;\n";
+ ss<< " xpower4 = xpower4 + (dx * dx * dx * dx);\n";
+ ss<< " }\n";
+ ss<< " double k_d = (length - 2.0) * (length - 3.0);\n";
+ ss<< " double k_l = length * (length + 1.0) /";
+ ss<< "((length - 1.0) * k_d);\n";
+ ss<< " double k_t = 3.0 * (length - 1.0) * (length - 1.0) / k_d;\n";
+ ss<< " tmp = xpower4 * k_l - k_t;\n";
+ ss<< " return tmp;\n";
+ ss<< "}";
+}
}}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/opencl/op_statistical.hxx b/sc/source/core/opencl/op_statistical.hxx
index 1002fa9..87b02b9 100644
--- a/sc/source/core/opencl/op_statistical.hxx
+++ b/sc/source/core/opencl/op_statistical.hxx
@@ -123,7 +123,13 @@ class OpMedian:public Normal{
const std::string sSymName, SubArguments &vSubArguments);
virtual std::string BinFuncName(void) const { return "OpMedian"; }
};
-
+class OpKurt: public Normal
+{
+public:
+ virtual void GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments);
+ virtual std::string BinFuncName(void) const { return "Kurt"; }
+};
}}
#endif
commit 3a7b8b3c43fa524dd8e803f37bea396d26eb44ee
Author: yiming ju <yiming at multicorewareinc.com>
Date: Tue Nov 5 15:10:50 2013 +0800
GPU Calc: unit test cases for VDB
Need open macro NO_FALLBACK_TO_SWINTERP in formulagroupcl.cxx for test
AMLOEXT-133 BUG
Change-Id: I16fa478bf7dbccbc8dcd98922d17501a6aa988b1
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/VDB.xls b/sc/qa/unit/data/xls/opencl/financial/VDB.xls
new file mode 100644
index 0000000..d0f58b5
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/financial/VDB.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 88bf276..53e59c3 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -140,6 +140,7 @@ public:
void testFinancialFVFormula();
void testFinancialMDurationFormula();
void testMathSumIfsFormula();
+ void testFinancialVDBFormula();
CPPUNIT_TEST_SUITE(ScOpenclTest);
CPPUNIT_TEST(testSharedFormulaXLS);
CPPUNIT_TEST(testFinacialFormula);
@@ -209,6 +210,7 @@ public:
CPPUNIT_TEST(testFinancialFVFormula);
CPPUNIT_TEST(testFinancialMDurationFormula);
CPPUNIT_TEST(testMathSumIfsFormula);
+ CPPUNIT_TEST(testFinancialVDBFormula);
CPPUNIT_TEST_SUITE_END();
private:
@@ -2090,6 +2092,40 @@ void ScOpenclTest::testMathSumIfsFormula()
xDocSh->DoClose();
xDocShRes->DoClose();
}
+ //[AMLOEXT-133]
+void ScOpenclTest:: testFinancialVDBFormula()
+{
+ if (!detectOpenCLDevice())
+ return;
+ ScDocShellRef xDocSh = loadDoc("opencl/financial/VDB.", XLS);
+ ScDocument *pDoc = xDocSh->GetDocument();
+ CPPUNIT_ASSERT(pDoc);
+ enableOpenCL();
+ pDoc->CalcAll();
+ ScDocShellRef xDocShRes = loadDoc("opencl/financial/VDB.", XLS);
+ ScDocument *pDocRes = xDocShRes->GetDocument();
+ CPPUNIT_ASSERT(pDocRes);
+ for (SCROW i = 0; i <= 10; ++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));
+ }
+ for (SCROW i = 15; i <= 26; ++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));
+ }
+ for (SCROW i = 30; i <= 41; ++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 b738e16..02dd30a 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1379,6 +1379,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
case ocMedian:
case ocGDA:
case ocZW:
+ case ocVBD:
// Don't change the state.
break;
default:
commit 3f0ce0447d1f3aba9220d1901bb9e8f986cdaf2b
Author: yiming ju <yiming at multicorewareinc.com>
Date: Tue Nov 5 15:20:52 2013 +0800
GPU Calc: implemented for VDB
AMLOEXT-133 FIX
Change-Id: I8147c2626131800d9c0075fee8dfdfd70b5bef5c
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 85c09ec..e14d570 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1068,6 +1068,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
mvSubArguments.push_back(SoPHelper(ts,
ft->Children[i],new OpSumIfs));
break;
+ case ocVBD:
+ mvSubArguments.push_back(SoPHelper(ts,
+ ft->Children[i],new OpVDB));
+ 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 0c592d5..410429a 100644
--- a/sc/source/core/opencl/op_financial.cxx
+++ b/sc/source/core/opencl/op_financial.cxx
@@ -4137,7 +4137,57 @@ tmpCur4);
ss << " return -result;\n";
ss << "}";
}
+ void OpVDB::BinInlineFun(std::set<std::string>& decls,
+ std::set<std::string>& funs)
+{
+ decls.insert(ScGetGDADecl);decls.insert(DblMinDecl);
+ decls.insert(ScInterVDBDecl);decls.insert(VDBImplementDecl);
+ funs.insert(ScGetGDA);funs.insert(DblMin);
+ funs.insert(ScInterVDB);funs.insert(VDBImplement);
+}
+
+void OpVDB::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 << " int singleIndex = gid0;\n";
+ ss << " double result = 0;\n";
+ if(vSubArguments.size()<5)
+ {
+ ss << " result = -DBL_MAX;\n";
+ ss << " return result;\n";
+ }else
+ {
+ GenTmpVariables(ss,vSubArguments);
+ CheckAllSubArgumentIsNan(ss,vSubArguments);
+ if(vSubArguments.size() <= 6)
+ {
+ ss << " int tmp6 = 0;\n";
+ }
+ if(vSubArguments.size() == 5)
+ {
+ ss << " double tmp5= 2.0;\n";
+ }
+ ss << " if(tmp3 < 0 || tmp4<tmp3 || tmp4>tmp2 || tmp0<0 ||tmp1>tmp0";
+ ss << "|| tmp5 <=0)\n";
+ ss << " result = -DBL_MAX;\n";
+ ss << " else\n";
+ ss << " result =";
+ ss << "VDBImplement(tmp0,tmp1,tmp2,tmp3,tmp4,tmp5,tmp6);\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 3a1350a..a24db10 100644
--- a/sc/source/core/opencl/op_financial.hxx
+++ b/sc/source/core/opencl/op_financial.hxx
@@ -465,6 +465,15 @@ public:
virtual std::string BinFuncName(void) const { return "PV"; }
};
+class OpVDB: public CheckVariables
+{
+public:
+ virtual void GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments);
+
+ virtual std::string BinFuncName(void) const { return "VDB"; }
+ virtual void BinInlineFun(std::set<std::string>& ,std::set<std::string>& );
+};
}}
#endif
diff --git a/sc/source/core/opencl/opinlinefun_finacial.cxx b/sc/source/core/opencl/opinlinefun_finacial.cxx
index 86f93eb..7770458 100644
--- a/sc/source/core/opencl/opinlinefun_finacial.cxx
+++ b/sc/source/core/opencl/opinlinefun_finacial.cxx
@@ -995,6 +995,142 @@ std::string GetDuration=
" fDur /= nFreq;\n"
" return fDur;\n""}\n";
+std::string ScGetGDADecl=
+"double ScGetGDA(double fWert, double fRest, double fDauer, double fPeriode,"
+"double fFaktor);\n";
+
+std::string ScGetGDA=
+"double ScGetGDA(double fWert, double fRest, double fDauer, double fPeriode,"
+"double fFaktor)\n"
+"{\n"
+" double fGda, fZins, fAlterWert, fNeuerWert;\n"
+" fZins = fFaktor / fDauer;\n"
+" if (fZins >= 1.0)\n"
+" {\n"
+" fZins = 1.0;\n"
+" if (fPeriode == 1.0)\n"
+" fAlterWert = fWert;\n"
+" else\n"
+" fAlterWert = 0.0;\n"
+" }\n"
+" else\n"
+" fAlterWert = fWert * pow(1.0 - fZins, fPeriode - 1.0);\n"
+" fNeuerWert = fWert * pow(1.0 - fZins, fPeriode);\n"
+
+" if (fNeuerWert < fRest)\n"
+" fGda = fAlterWert - fRest;\n"
+" else\n"
+" fGda = fAlterWert - fNeuerWert;\n"
+" if (fGda < 0.0)\n"
+" fGda = 0.0;\n"
+" return fGda;\n"
+"}\n";
+
+std::string DblMinDecl=
+"inline double DblMin( double a, double b );\n";
+
+std::string DblMin=
+"inline double DblMin( double a, double b )\n"
+"{\n"
+" return (a < b) ? a : b;\n"
+"}\n";
+
+std::string ScInterVDBDecl=
+"double ScInterVDB(double fWert,double fRest,double fDauer, double fDauer1,"
+"double fPeriode,double fFaktor);\n";
+
+std::string ScInterVDB=
+"double ScInterVDB(double fWert,double fRest,double fDauer, double fDauer1,"
+"double fPeriode,double fFaktor)\n"
+"{\n"
+" double fVdb=0;\n"
+" double fIntEnd = ceil(fPeriode);\n"
+" int nLoopEnd = fIntEnd;\n"
+
+" double fTerm, fLia;\n"
+" double fRestwert = fWert - fRest;\n"
+" int bNowLia = 0;\n"
+" double fGda;\n"
+" int i;\n"
+" fLia=0;\n"
+" for ( i = 1; i <= nLoopEnd; i++)\n"
+" {\n"
+" if(!bNowLia)\n"
+" {\n"
+" fGda = ScGetGDA(fWert, fRest, fDauer, (double) i, fFaktor);\n"
+" fLia = fRestwert/ (fDauer1 - (double) (i-1));\n"
+" if (fLia > fGda)\n"
+" {\n"
+" fTerm = fLia;\n"
+" bNowLia = 1;\n"
+" }\n"
+" else\n"
+" {\n"
+" fTerm = fGda;\n"
+" fRestwert =fRestwert- fGda;\n"
+" }\n"
+" }\n"
+" else\n"
+" {\n"
+" fTerm = fLia;\n"
+" }\n"
+
+" if ( i == nLoopEnd)\n"
+" fTerm *= ( fPeriode + 1.0 - fIntEnd );\n"
+
+" fVdb += fTerm;\n"
+" }\n"
+" return fVdb;\n"
+"}\n";
+
+std::string VDBImplementDecl=
+"double VDBImplement(double fWert,double fRest, double fDauer, double fAnfang"
+", double fEnde, double fFaktor,int bFlag);\n";
+
+std::string VDBImplement=
+"double VDBImplement(double fWert,double fRest, double fDauer, double fAnfang"
+", double fEnde, double fFaktor,int bFlag)\n"
+"{\n"
+" double result=0;\n"
+" double fIntStart = floor(fAnfang);\n"
+" double fIntEnd = ceil(fEnde);\n"
+" int nLoopStart = (int) fIntStart;\n"
+" int nLoopEnd = (int) fIntEnd;\n"
+" if (bFlag)\n"
+" {\n"
+" for (int i = nLoopStart + 1; i <= nLoopEnd; i++)\n"
+" {\n"
+" double fTerm = ScGetGDA(fWert, fRest, fDauer, (double) i, fFaktor"
+");\n"
+" if ( i == nLoopStart+1 )\n"
+" fTerm *= ( DblMin( fEnde, fIntStart + 1.0 ) - fAnfang );\n"
+" else if ( i == nLoopEnd )\n"
+" fTerm *= ( fEnde + 1.0 - fIntEnd );\n"
+" result += fTerm;\n"
+" }\n"
+" }\n"
+" else\n"
+" {\n"
+" double fDauer1=fDauer;\n"
+" if(!isequal(fAnfang,floor(fAnfang)))\n"
+" {\n"
+" if(fFaktor>1)\n"
+" {\n"
+" if(fAnfang>fDauer/2 || isequal(fAnfang,fDauer/2))\n"
+" {\n"
+" double fPart=fAnfang-fDauer/2;\n"
+" fAnfang=fDauer/2;\n"
+" fEnde-=fPart;\n"
+" fDauer1+=1;\n"
+" }\n"
+" }\n"
+" }\n"
+" fWert-=ScInterVDB(fWert,fRest,fDauer,fDauer1,fAnfang,fFaktor);\n"
+" result=ScInterVDB(fWert,fRest,fDauer,fDauer-fAnfang,fEnde-fAnfang,"
+"fFaktor);\n"
+" }\n"
+" return result;\n"
+"}\n";
#endif
commit 4dfa1562b2d8e8ac13c895910f3805fcec1ed00b
Author: yiming ju <yiming at multicorewareinc.com>
Date: Tue Nov 5 14:55:02 2013 +0800
GPU Calc: unit test cases for SUMIFS
Need open macro NO_FALLBACK_TO_SWINTERP in formulagroupcl.cxx for test
AMLOEXT-128 BUG
Change-Id: I32a5e83a61987cbdb45e7522f2893bdebadbe7c4
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/math/sumifs.xls b/sc/qa/unit/data/xls/opencl/math/sumifs.xls
new file mode 100644
index 0000000..4ee7274
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/math/sumifs.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index e733217..88bf276 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -139,6 +139,7 @@ public:
void testFinancialDDBFormula();
void testFinancialFVFormula();
void testFinancialMDurationFormula();
+ void testMathSumIfsFormula();
CPPUNIT_TEST_SUITE(ScOpenclTest);
CPPUNIT_TEST(testSharedFormulaXLS);
CPPUNIT_TEST(testFinacialFormula);
@@ -207,6 +208,7 @@ public:
CPPUNIT_TEST(testFinancialDDBFormula);
CPPUNIT_TEST(testFinancialFVFormula);
CPPUNIT_TEST(testFinancialMDurationFormula);
+ CPPUNIT_TEST(testMathSumIfsFormula);
CPPUNIT_TEST_SUITE_END();
private:
@@ -2048,6 +2050,46 @@ void ScOpenclTest:: testFinancialFVFormula()
xDocSh->DoClose();
xDocShRes->DoClose();
}
+//[AMLOEXT-128]
+void ScOpenclTest::testMathSumIfsFormula()
+{
+ if (!detectOpenCLDevice())
+ return;
+ ScDocShellRef xDocSh = loadDoc("opencl/math/sumifs.", XLS);
+ ScDocument* pDoc = xDocSh->GetDocument();
+ CPPUNIT_ASSERT(pDoc);
+ sc::FormulaGroupInterpreter::enableOpenCL(true);
+ xDocSh->DoHardRecalc(true);
+ ScDocShellRef xDocShRes = loadDoc("opencl/math/sumifs.", XLS);
+ ScDocument* pDocRes = xDocShRes->GetDocument();
+ CPPUNIT_ASSERT(pDocRes);
+ for (SCROW i = 2; i <= 11; ++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));
+ }
+ for (SCROW i = 2; i <= 11; ++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));
+ }
+ for (SCROW i = 2; i <= 11; ++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));
+ }
+ for (SCROW i = 2; i <= 11; ++i)
+ {
+ double fLibre = pDoc->GetValue(ScAddress(8,i,0));
+ double fExcel = pDocRes->GetValue(ScAddress(8,i,0));
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel));
+ }
+ xDocSh->DoClose();
+ xDocShRes->DoClose();
+}
ScOpenclTest::ScOpenclTest()
: ScBootstrapFixture( "/sc/qa/unit/data" )
{
commit 4950edb8a6deeed82a09b016a241eed719889992
Author: yiming ju <yiming at multicorewareinc.com>
Date: Tue Nov 5 15:03:14 2013 +0800
GPU Calc: implemented for SUMIFS
AMLOEXT-128 FIX
Change-Id: I9addf29388eb9dbf6c48382ba5aa940719f7c430
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 3249df5..85c09ec 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1064,6 +1064,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
mvSubArguments.push_back(SoPHelper(ts,
ft->Children[i],new OpFV));
break;
+ case ocSumIfs:
+ mvSubArguments.push_back(SoPHelper(ts,
+ ft->Children[i],new OpSumIfs));
+ break;
case ocExternal:
if ( !(pChild->GetExternal().compareTo(OUString(
"com.sun.star.sheet.addin.Analysis.getEffect"))))
diff --git a/sc/source/core/opencl/op_math.cxx b/sc/source/core/opencl/op_math.cxx
index d7286be..2aa6dd1 100644
--- a/sc/source/core/opencl/op_math.cxx
+++ b/sc/source/core/opencl/op_math.cxx
@@ -79,7 +79,71 @@ void OpCsc::GenSlidingWindowFunction(
ss << "return tmp;\n";
ss << "}";
}
-
+void OpSumIfs::GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments)
+{
+ FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
+ const formula::DoubleVectorRefToken*pCurDVR= dynamic_cast<const
+ formula::DoubleVectorRefToken *>(tmpCur);
+ size_t nCurWindowSize = pCurDVR->GetArrayLength() <
+ pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
+ pCurDVR->GetRefRowSize() ;
+ ss << "\ndouble " << sSymName;
+ ss << "_"<< BinFuncName() <<"(";
+ for (unsigned i = 0; i < vSubArguments.size(); i++)
+ {
+ if (i)
+ ss << ",";
+ vSubArguments[i]->GenSlidingWindowDecl(ss);
+ }
+ ss << ")\n {\n";
+ ss <<" int gid0=get_global_id(0);\n";
+ ss << " double tmp =0;\n";
+ ss << " int i ;\n";
+ GenTmpVariables(ss,vSubArguments);
+ ss << " for (i = ";
+ if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
+ ss << "gid0; i < "<< nCurWindowSize <<"; i++)\n";
+ } else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) {
+ ss << "0; i < gid0+"<< nCurWindowSize <<"; i++)\n";
+ } else {
+ ss << "0; i < "<< nCurWindowSize <<"; i++)\n";
+ }
+ ss << " {\n";
+ if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
+ {
+ ss<< " int doubleIndex =i+gid0;\n";
+ }else
+ {
+ ss<< " int doubleIndex =i;\n";
+ }
+ ss<< " int singleIndex =gid0;\n";
+ int m=0;
+ for(unsigned j=1;j<vSubArguments.size();j+=2,m++)
+ {
+ CheckSubArgumentIsNan(ss,vSubArguments,j);
+ CheckSubArgumentIsNan(ss,vSubArguments,j+1);
+ ss <<" if(isequal(";
+ ss <<"tmp";
+ ss <<j;
+ ss <<" , ";
+ ss << "tmp";
+ ss << j+1;
+ ss << ")){\n";
+ }
+ CheckSubArgumentIsNan(ss,vSubArguments,0);
+ ss << " tmp += tmp0;\n";
+ for(unsigned j=1;j<=vSubArguments.size();j+=2,m--)
+ {
+ for(int n = 0;n<m+1;n++)
+ {
+ ss << " ";
+ }
+ ss<< "}\n";
+ }
+ ss << "return tmp;\n";
+ ss << "}";
+}
void OpSinh::GenSlidingWindowFunction(std::stringstream &ss,
const std::string sSymName, SubArguments &vSubArguments)
{
diff --git a/sc/source/core/opencl/op_math.hxx b/sc/source/core/opencl/op_math.hxx
index d7ce226..d6dda45 100644
--- a/sc/source/core/opencl/op_math.hxx
+++ b/sc/source/core/opencl/op_math.hxx
@@ -30,7 +30,13 @@ public:
const std::string sSymName, SubArguments &vSubArguments);
virtual std::string BinFuncName(void) const { return "Csc"; }
};
-
+class OpSumIfs: public CheckVariables
+{
+public:
+ virtual void GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments);
+ virtual std::string BinFuncName(void) const { return "SumIfs"; }
+};
class OpSinh: public Normal
{
public:
diff --git a/sc/source/core/opencl/opbase.cxx b/sc/source/core/opencl/opbase.cxx
index ffe7c6a..e95d8c5 100644
--- a/sc/source/core/opencl/opbase.cxx
+++ b/sc/source/core/opencl/opbase.cxx
@@ -105,6 +105,67 @@ void Normal::GenSlidingWindowFunction(
ss << "}";
}
+void CheckVariables::GenTmpVariables(
+ std::stringstream & ss, SubArguments & vSubArguments)
+{
+ for(unsigned i=0;i<vSubArguments.size();i++)
+ {
+ ss << " double tmp";
+ ss << i;
+ ss <<";\n";
+ }
+}
+
+void CheckVariables::CheckSubArgumentIsNan( std::stringstream & ss,
+ SubArguments &vSubArguments, int argumentNum)
+{
+ int i = argumentNum;
+#ifdef ISNAN
+ if(vSubArguments[i]->GetFormulaToken()->GetType() ==
+ formula::svSingleVectorRef)
+ {
+ const formula::SingleVectorRefToken*pTmpDVR1= dynamic_cast<const
+ formula::SingleVectorRefToken *>(vSubArguments[i]->GetFormulaToken());
+ ss<< " if(singleIndex>=";
+ ss<< pTmpDVR1->GetArrayLength();
+ ss<<" ||";
+ }
+ if(vSubArguments[i]->GetFormulaToken()->GetType() ==
+ formula::svDoubleVectorRef)
+ {
+ const formula::DoubleVectorRefToken*pTmpDVR2= dynamic_cast<const
+ formula::DoubleVectorRefToken *>(vSubArguments[i]->GetFormulaToken());
+ ss<< " if(doubleIndex>=";
+ ss<< pTmpDVR2->GetArrayLength();
+ ss<<" ||";
+ }
+ if(vSubArguments[i]->GetFormulaToken()->GetType() == formula::svDouble)
+ {
+ ss<< " if(";
+ }
+ ss<< "isNan(";
+ ss<< vSubArguments[i]->GenSlidingWindowDeclRef();
+ ss<<"))\n";
+ ss<< " tmp";
+ ss<< i;
+ ss <<"=0;\n else \n";
+#endif
+ ss <<" tmp";
+ ss <<i;
+ ss << "=";
+ ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+ ss<<";\n";
+}
+void CheckVariables::CheckAllSubArgumentIsNan(
+ std::stringstream & ss, SubArguments & vSubArguments)
+{
+ ss<<" int k = gid0;\n";
+ for(unsigned i=0;i<vSubArguments.size();i++)
+ {
+ CheckSubArgumentIsNan(ss,vSubArguments,i);
+ }
+}
+
}}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/opencl/opbase.hxx b/sc/source/core/opencl/opbase.hxx
index 11f0c7f..4898962 100644
--- a/sc/source/core/opencl/opbase.hxx
+++ b/sc/source/core/opencl/opbase.hxx
@@ -149,6 +149,16 @@ public:
virtual bool takeNumeric() const { return true; }
};
+class CheckVariables:public Normal
+{
+public:
+ void GenTmpVariables(std::stringstream &ss, SubArguments &vSubArguments);
+ void CheckSubArgumentIsNan(std::stringstream &ss,
+ SubArguments &vSubArguments, int argumentNum);
+ void CheckAllSubArgumentIsNan(std::stringstream &ss,
+ SubArguments &vSubArguments);
+};
+
}}
#endif
More information about the Libreoffice-commits
mailing list