[Libreoffice-commits] core.git: Branch 'feature/calc-group-interpreter-4' - 4 commits - sc/qa sc/source
hongyu zhong
hongyu at multicorewareinc.com
Mon Nov 11 15:07:05 PST 2013
sc/qa/unit/data/xls/opencl/statistical/Median.xls |binary
sc/qa/unit/data/xls/opencl/statistical/Weibull.xls |binary
sc/qa/unit/opencl-test.cxx | 52 +++++
sc/source/core/opencl/formulagroupcl.cxx | 8
sc/source/core/opencl/op_statistical.cxx | 217 +++++++++++++++++++++
sc/source/core/opencl/op_statistical.hxx | 14 +
sc/source/core/tool/token.cxx | 2
7 files changed, 293 insertions(+)
New commits:
commit 6cb7a09682a51923e64ad5c638ff3a4ab4e7748e
Author: hongyu zhong <hongyu at multicorewareinc.com>
Date: Mon Nov 4 17:31:04 2013 +0800
GPU Calc: unit test cases for MEDIAN
Need open macro NO_FALLBACK_TO_SWINTERP in formulagroupcl.cxx for test
AMLOEXT-100 BUG
Change-Id: Idbc6a697c42b639a310200b4df9eb35ba5e8eca7
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/Median.xls b/sc/qa/unit/data/xls/opencl/statistical/Median.xls
new file mode 100644
index 0000000..232629e
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/statistical/Median.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 0b8166a..69c8c3e 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -132,6 +132,7 @@ public:
void testMathFormulaTanH();
void testStatisticalFormulaStandard();
void testStatisticalFormulaWeibull();
+ void testStatisticalFormulaMedian();
CPPUNIT_TEST_SUITE(ScOpenclTest);
CPPUNIT_TEST(testSharedFormulaXLS);
CPPUNIT_TEST(testFinacialFormula);
@@ -193,6 +194,7 @@ public:
CPPUNIT_TEST(testMathFormulaTanH);
CPPUNIT_TEST(testStatisticalFormulaStandard);
CPPUNIT_TEST(testStatisticalFormulaWeibull);
+ CPPUNIT_TEST(testStatisticalFormulaMedian);
CPPUNIT_TEST_SUITE_END();
private:
@@ -1534,6 +1536,29 @@ void ScOpenclTest:: testFinancialISPMTFormula()
xDocSh->DoClose();
xDocShRes->DoClose();
}
+//[AMLOEXT-100]
+void ScOpenclTest::testStatisticalFormulaMedian()
+{
+ if (!detectOpenCLDevice())
+ return;
+ ScDocShellRef xDocSh = loadDoc("opencl/statistical/Median.",XLS);
+ ScDocument* pDoc = xDocSh->GetDocument();
+ CPPUNIT_ASSERT(pDoc);
+ enableOpenCL();
+ pDoc->CalcAll();
+ ScDocShellRef xDocShRes = loadDoc("opencl/statistical/Median.",XLS);
+ ScDocument* pDocRes = xDocShRes->GetDocument();
+ CPPUNIT_ASSERT(pDocRes);
+ // Check the results of formula cells in the shared formula range.
+ for (SCROW i = 1; i <= 9; ++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();
+}
void ScOpenclTest::testFinacialPriceMatFormula()
{
if (!detectOpenCLDevice())
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index e72e026..1bcf726 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1376,6 +1376,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
case ocTanHyp:
case ocStandard:
case ocWeibull:
+ case ocMedian:
// Don't change the state.
break;
default:
commit fb66e504b99cf09355e730b1064545ef9dc22319
Author: hongyu zhong <hongyu at multicorewareinc.com>
Date: Mon Nov 4 17:39:20 2013 +0800
GPU Calc: implemented MEDIAN
AMLOEXT-100 FIX
Change-Id: I9b002e6c2383c4416b98e6698d3dd2e81f7752f5
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 a6cf6e1..96e8f0f 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1052,6 +1052,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
mvSubArguments.push_back(SoPHelper(ts,
ft->Children[i], new OpWeibull));
break;
+ case ocMedian:
+ mvSubArguments.push_back(SoPHelper(ts,
+ ft->Children[i],new OpMedian));
+ 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 64f2411..356b170 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -939,6 +939,83 @@ void OpRsq::GenSlidingWindowFunction(
ss << "}\n";
}
+void OpMedian::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 << " int i;\n";
+ ss << " unsigned int startFlag = 0;\n";
+ ss << " unsigned int endFlag = 0;\n";
+ ss << " double dataIna;\n";
+ for (unsigned i = 0; i < vSubArguments.size(); i++)
+ {
+ FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
+ assert(pCur);
+ if (const formula::DoubleVectorRefToken* pCurDVR =
+ dynamic_cast<const formula::DoubleVectorRefToken *>(pCur))
+ {
+ size_t nCurWindowSize = pCurDVR->GetRefRowSize();
+ ss << "startFlag = ";
+ if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed())
+ {
+ ss << "gid0; endFlag = "<< nCurWindowSize <<"-gid0;\n";
+ }
+ else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
+ {
+ ss << "gid0; endFlag = gid0+"<< nCurWindowSize <<";\n";
+ }
+ else
+ {
+ ss << "gid0; endFlag = gid0+"<< nCurWindowSize <<";\n";
+ }
+ }
+ else
+ {
+ ss<<"startFlag=gid0;endFlag=gid0;\n";
+ }
+ }
+#ifdef ISNAN
+ FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
+ const formula::DoubleVectorRefToken*tmpCurDVR0= dynamic_cast<const
+ formula::DoubleVectorRefToken *>(tmpCur0);
+ ss << "int buffer_fIna_len = ";
+ ss << tmpCurDVR0->GetArrayLength();
+ ss << ";\n";
+#endif
+#ifdef ISNAN
+ ss<<"if((i+gid0)>=buffer_fIna_len || isNan(";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef();
+ ss<<"))\n";
+ ss<<" dataIna = 0;\n";
+#endif
+ ss << " int nSize =endFlag- startFlag ;\n";
+ ss << " if (nSize & 1)\n";
+ ss << " {\n";
+ ss << " tmp = "<<vSubArguments[0]->GetNameAsString();
+ ss << " [startFlag+nSize/2];\n";
+ ss << " }\n";
+ ss << " else\n";
+ ss << " {\n";
+ ss << " tmp =("<<vSubArguments[0]->GetNameAsString();
+ ss << " [startFlag+nSize/2]+";
+ ss << vSubArguments[0]->GetNameAsString();
+ ss << " [startFlag+nSize/2-1])/2;\n";
+ ss << " }\n";
+ ss <<" return tmp;\n";
+ ss << "}\n";
+}
+
}}
/* 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 b4d98df..1002fa9 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 OpMedian:public Normal{
+ public:
+ virtual void GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments);
+ virtual std::string BinFuncName(void) const { return "OpMedian"; }
+};
}}
commit d61eb89482f11f73705d8d0ea3d8cd7f47c228e0
Author: shiming zhang <shiming at multicorewareinc.com>
Date: Mon Nov 4 17:11:40 2013 +0800
GPU Calc: unit test cases for WEIBULL
Need open macro NO_FALLBACK_TO_SWINTERP in formulagroupcl.cxx for test
AMLOEXT-78 BUG
Change-Id: I4235313f70d2237ce06d4f71163d0d32bc0f064d
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/Weibull.xls b/sc/qa/unit/data/xls/opencl/statistical/Weibull.xls
new file mode 100644
index 0000000..e943041
Binary files /dev/null and b/sc/qa/unit/data/xls/opencl/statistical/Weibull.xls differ
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 7af709e..0b8166a 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -131,6 +131,7 @@ public:
void testMathFormulaTan();
void testMathFormulaTanH();
void testStatisticalFormulaStandard();
+ void testStatisticalFormulaWeibull();
CPPUNIT_TEST_SUITE(ScOpenclTest);
CPPUNIT_TEST(testSharedFormulaXLS);
CPPUNIT_TEST(testFinacialFormula);
@@ -191,6 +192,7 @@ public:
CPPUNIT_TEST(testMathFormulaTan);
CPPUNIT_TEST(testMathFormulaTanH);
CPPUNIT_TEST(testStatisticalFormulaStandard);
+ CPPUNIT_TEST(testStatisticalFormulaWeibull);
CPPUNIT_TEST_SUITE_END();
private:
@@ -1388,6 +1390,31 @@ void ScOpenclTest::testStatisticalFormulaStandard()
xDocSh->DoClose();
xDocShRes->DoClose();
}
+//[AMLOEXT-78]
+void ScOpenclTest::testStatisticalFormulaWeibull()
+{
+ if (!detectOpenCLDevice())
+ return;
+
+ ScDocShellRef xDocSh = loadDoc("opencl/statistical/Weibull.", XLS);
+ ScDocument* pDoc = xDocSh->GetDocument();
+ CPPUNIT_ASSERT(pDoc);
+ enableOpenCL();
+ pDoc->CalcAll();
+
+ ScDocShellRef xDocShRes = loadDoc("opencl/statistical/Weibull.", XLS);
+ ScDocument* pDocRes = xDocShRes->GetDocument();
+ CPPUNIT_ASSERT(pDocRes);
+ // Check the results of formula cells in the shared formula range.
+ for (SCROW i = 1; i <= 20; ++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-82]
void ScOpenclTest::testStatisticalFormulaPearson()
{
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 2de1508..e72e026 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1375,6 +1375,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r )
case ocTan:
case ocTanHyp:
case ocStandard:
+ case ocWeibull:
// Don't change the state.
break;
default:
commit 35839837126e5df2613ef67eb7f7b8258d3279c2
Author: shiming zhang <shiming at multicorewareinc.com>
Date: Mon Nov 4 17:20:19 2013 +0800
GPU Calc: implemented WEIBULL
AMLOEXT-78 FIX
Change-Id: Iebb516f31b7315cae3375288baa7536c31109fed
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 bb8d369..a6cf6e1 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -1048,6 +1048,10 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
mvSubArguments.push_back(SoPHelper(ts,
ft->Children[i], new OpStandard));
break;
+ case ocWeibull:
+ mvSubArguments.push_back(SoPHelper(ts,
+ ft->Children[i], new OpWeibull));
+ 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 4128507..64f2411 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -129,6 +129,146 @@ void OpStandard::GenSlidingWindowFunction(std::stringstream &ss,
ss << "}";
}
+
+void OpWeibull::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";
+ ss << " double x,alpha,beta,kum;\n";
+ if(vSubArguments.size() != 4)
+ {
+ ss << " return DBL_MAX;\n" << "}\n";
+ return ;
+ }
+ FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
+ assert(tmpCur0);
+ if(tmpCur0->GetType() == formula::svSingleVectorRef)
+ {
+ const formula::SingleVectorRefToken*tmpCurDVR0 =
+ dynamic_cast<const formula::SingleVectorRefToken *>(tmpCur0);
+#ifdef ISNAN
+ ss << " int buffer_x_len = ";
+ ss << tmpCurDVR0->GetArrayLength() << ";\n";
+ ss << " if(gid0>=buffer_x_len || isNan(";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
+ ss << " x = 0.0;\n";
+ ss << " else\n";
+#endif
+ ss << " x = ";
+ ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
+ }
+ else if(tmpCur0->GetType() == formula::svDouble)
+ {
+ ss << " x=" <<tmpCur0->GetDouble() << ";\n";
+ }
+ else
+ {
+ ss << "return DBL_MAX;\n" << "}\n";
+ return ;
+ }
+
+ FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
+ assert(tmpCur1);
+ if(tmpCur1->GetType() == formula::svSingleVectorRef)
+ {
+ const formula::SingleVectorRefToken*tmpCurDVR1 =
+ dynamic_cast<const formula::SingleVectorRefToken *>(tmpCur1);
+#ifdef ISNAN
+ ss << " int buffer_alpha_len = ";
+ ss << tmpCurDVR1->GetArrayLength() << ";\n";
+ ss << " if(gid0>=buffer_alpha_len || isNan(";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef() << "))\n";
+ ss << " alpha = 0.0;\n";
+ ss << " else\n";
+#endif
+ ss << " alpha = ";
+ ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
+ }
+ else if(tmpCur1->GetType() == formula::svDouble)
+ {
+ ss << " alpha=" <<tmpCur1->GetDouble() << ";\n";
+ }
+ else
+ {
+ ss << "return DBL_MAX;\n" << "}\n";
+ return ;
+ }
+
+ FormulaToken *tmpCur2 = vSubArguments[2]->GetFormulaToken();
+ assert(tmpCur2);
+ if(tmpCur2->GetType() == formula::svSingleVectorRef)
+ {
+ const formula::SingleVectorRefToken*tmpCurDVR2 =
+ dynamic_cast<const formula::SingleVectorRefToken *>(tmpCur2);
+#ifdef ISNAN
+ ss << " int buffer_beta_len = ";
+ ss << tmpCurDVR2->GetArrayLength() << ";\n";
+ ss << " if(gid0>=buffer_beta_len || isNan(";
+ ss << vSubArguments[2]->GenSlidingWindowDeclRef() << "))\n";
+ ss << " beta = 0.0;\n";
+ ss << " else\n";
+#endif
+ ss << " beta = ";
+ ss << vSubArguments[2]->GenSlidingWindowDeclRef() << ";\n";
+ }
+ else if(tmpCur2->GetType() == formula::svDouble)
+ {
+ ss << " beta=" <<tmpCur2->GetDouble() << ";\n";
+ }
+ else
+ {
+ ss << " return DBL_MAX;\n" << "}\n";
+ return ;
+ }
+ FormulaToken *tmpCur3 = vSubArguments[3]->GetFormulaToken();
+ assert(tmpCur3);
+ if(tmpCur3->GetType() == formula::svSingleVectorRef)
+ {
+ const formula::SingleVectorRefToken*tmpCurDVR3 =
+ dynamic_cast<const formula::SingleVectorRefToken *>(tmpCur3);
+#ifdef ISNAN
+ ss << " int buffer_kum_len = ";
+ ss << tmpCurDVR3->GetArrayLength() << ";\n";
+ ss << " if(gid0>=buffer_kum_len || isNan(";
+ ss << vSubArguments[3]->GenSlidingWindowDeclRef() << "))\n";
+ ss << " kum = 0.0;\n";
+ ss << " else\n";
+#endif
+ ss << " kum = ";
+ ss << vSubArguments[3]->GenSlidingWindowDeclRef() << ";\n";
+ }
+ else if(tmpCur3->GetType() == formula::svDouble)
+ {
+ ss << " kum=" <<tmpCur3->GetDouble() << ";\n";
+ }
+ else
+ {
+ ss << " return DBL_MAX;\n" << "}\n";
+ return ;
+ }
+ ss << " if(alpha<=0.0||beta<=0.0||kum<0.0)\n";
+ ss << " return DBL_MAX;\n";
+ ss << " else if(kum==0.0)\n";
+ ss << " {\n";
+ ss << " tmp=alpha/pow(beta,alpha)*pow(x,alpha-1.0)";
+ ss << "*exp(-pow(x/beta,alpha));\n";
+ ss << " }\n";
+ ss << " else\n";
+ ss << " tmp=1.0-exp(-pow(x/beta,alpha));\n";
+ ss << " return tmp;\n";
+ ss << "}\n";
+}
+
void OpFisher::GenSlidingWindowFunction(
std::stringstream &ss, const std::string sSymName, SubArguments &vSubArguments)
{
diff --git a/sc/source/core/opencl/op_statistical.hxx b/sc/source/core/opencl/op_statistical.hxx
index 4f09d66..b4d98df 100644
--- a/sc/source/core/opencl/op_statistical.hxx
+++ b/sc/source/core/opencl/op_statistical.hxx
@@ -22,6 +22,14 @@ public:
virtual std::string BinFuncName(void) const { return "Standard"; }
};
+class OpWeibull: public Normal
+{
+public:
+ virtual void GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments);
+ virtual std::string BinFuncName(void) const { return "Weibull"; }
+};
+
class OpFisher: public Normal
{
public:
More information about the Libreoffice-commits
mailing list