summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authoryangzhang <yangzhang@multicorewareinc.com>2013-12-17 11:54:08 +0800
committerI-Jui (Ray) Sung <ray@multicorewareinc.com>2013-12-19 17:54:04 -0600
commit14294525adf96f3da84f434e4a949332e6bab31d (patch)
tree96661273f5b8439fdec60440adb0cfdcdf513d97 /sc
parentdb3ff40e35216ad60c8d427415369a919c86a364 (diff)
GPU Calc: implemented SERIESSUM
AMLOEXT-373 FIX Change-Id: I23926b7a390dbdb44e7f897d2079d9baf4befd02 Signed-off-by: haochen <haochen@multicorewareinc.com> Signed-off-by: Wei Wei <weiwei@multicorewareinc.com> Signed-off-by: I-Jui (Ray) Sung <ray@multicorewareinc.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/core/opencl/formulagroupcl.cxx6
-rw-r--r--sc/source/core/opencl/op_math.cxx137
-rw-r--r--sc/source/core/opencl/op_math.hxx7
3 files changed, 150 insertions, 0 deletions
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index 1cf6a472a8c2..ddfb665df714 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -2809,6 +2809,12 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
mvSubArguments.push_back(SoPHelper(ts, ft->Children[i],
new OpQuotient));
}
+ else if ( !(pChild->GetExternal().compareTo(OUString(
+ "com.sun.star.sheet.addin.Analysis.getSeriessum"))))
+ {
+ mvSubArguments.push_back(SoPHelper(ts, ft->Children[i],
+ new OpSeriesSum));
+ }
break;
default:
diff --git a/sc/source/core/opencl/op_math.cxx b/sc/source/core/opencl/op_math.cxx
index cb3b2dfd1da0..53d2ce79ddc2 100644
--- a/sc/source/core/opencl/op_math.cxx
+++ b/sc/source/core/opencl/op_math.cxx
@@ -2891,6 +2891,143 @@ void OpQuotient::GenSlidingWindowFunction(std::stringstream &ss,
ss << " return trunc(num1/num2);\n";
ss << "}";
}
+void OpSeriesSum::GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments)
+{
+ if( vSubArguments.size() != 4){return;}
+ 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 var[3], coeff, res = 0.0f;\n";
+ FormulaToken *tmpCur;
+ for(int i = 0; i < 3; ++i)
+ {
+ tmpCur = vSubArguments[i]->GetFormulaToken();
+ assert(tmpCur);
+ if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
+ {
+ if(tmpCur->GetType() == formula::svSingleVectorRef)
+ {
+ const formula::SingleVectorRefToken* tmpCurDVR=
+ dynamic_cast<
+ const formula::SingleVectorRefToken *>(tmpCur);
+ ss << " var["<<i<<"] = ";
+ ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+ ss << ";\n";
+#ifdef ISNAN
+ ss << " if(isNan(var["<<i<<"])||(gid0>=";
+ ss << tmpCurDVR->GetArrayLength();
+ ss << "))\n";
+ ss << " var["<<i<<"] = 0;\n";
+#endif
+ }
+ else if(tmpCur->GetType() == formula::svDouble)
+ {
+ ss << " var["<<i<<"] = ";
+ ss << tmpCur->GetDouble() << ";\n";
+ }
+ }
+ else
+ {
+ ss << " var["<<i<<"] = ";
+ ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+ ss << ";\n";
+ }
+ }
+ tmpCur = vSubArguments[3]->GetFormulaToken();
+ assert(tmpCur);
+ if(ocPush == vSubArguments[3]->GetFormulaToken()->GetOpCode())
+ {
+ //TODO DoubleVector
+ if (tmpCur->GetType() == formula::svDoubleVectorRef)
+ {
+ const formula::DoubleVectorRefToken* pDVR =
+ dynamic_cast<const formula::DoubleVectorRefToken *>(tmpCur);
+ size_t nCurWindowSize = pDVR->GetRefRowSize();
+ ss << " int j = 0;\n";
+ ss << " for (int i = ";
+ if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
+ {
+#ifdef ISNAN
+ ss << "gid0; i < " << pDVR->GetArrayLength();
+ ss << " && i < " << nCurWindowSize << "; ++i)\n";
+ ss << " {\n";
+#else
+ ss << "gid0; i < "<< nCurWindowSize << "; ++i)\n";
+ ss << " {\n";
+#endif
+ }
+ else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
+ {
+#ifdef ISNAN
+ ss << "0; i < " << pDVR->GetArrayLength();
+ ss << " && i < gid0+"<< nCurWindowSize << "; ++i)\n";
+ ss << " {\n";
+#else
+ ss << "0; i < gid0+"<< nCurWindowSize << "; ++i)\n";
+ ss << " {\n";
+#endif
+ }
+ else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
+ {
+#ifdef ISNAN
+ ss << "0; i + gid0 < " << pDVR->GetArrayLength();
+ ss << " && i < "<< nCurWindowSize << "; ++i)\n";
+ ss << " {\n";
+#else
+ ss << "0; i < "<< nCurWindowSize << "; ++i)\n";
+ ss << " {\n";
+#endif
+ }
+ else
+ {
+#ifdef ISNAN
+ ss << "0; i < "<< nCurWindowSize << "; ++i)\n";
+ ss << " {\n";
+#else
+ ss << "0; i < "<< nCurWindowSize << "; ++i)\n";
+ ss << " {\n";
+#endif
+ }
+ ss << " coeff = ";
+ ss << vSubArguments[3]->GenSlidingWindowDeclRef();
+ ss << ";\n";
+#ifdef ISNAN
+ ss << " if (isNan(coeff))\n";
+ ss << " continue;\n";
+#endif
+ ss << " res = res + coeff * pow(var[0],";
+ ss << " var[1] + j * var[2]);\n";
+ ss << " ++j;\n";
+ ss << " }\n";
+ }
+ else if(tmpCur->GetType() == formula::svSingleVectorRef)
+ {
+ const formula::SingleVectorRefToken* tmpCurDVR=
+ dynamic_cast<
+ const formula::SingleVectorRefToken *>(tmpCur);
+ ss << " coeff = ";
+ ss << vSubArguments[3]->GenSlidingWindowDeclRef();
+ ss << ";\n";
+#ifdef ISNAN
+ ss << " if(isNan(coeff)||(gid0>=";
+ ss << tmpCurDVR->GetArrayLength();
+ ss << "))\n";
+ ss << " return 0;\n";
+#endif
+ }
+ }
+ ss << " return res;\n";
+ ss << "}";
+}
}}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/opencl/op_math.hxx b/sc/source/core/opencl/op_math.hxx
index 7d61ce7a0bf7..79a31d0d8c25 100644
--- a/sc/source/core/opencl/op_math.hxx
+++ b/sc/source/core/opencl/op_math.hxx
@@ -461,6 +461,13 @@ public:
virtual std::string GetBottom(void) { return "0.0"; }
virtual std::string BinFuncName(void) const { return "Fact"; }
};
+class OpSeriesSum: public Normal
+{
+public:
+ virtual void GenSlidingWindowFunction(std::stringstream &ss,
+ const std::string sSymName, SubArguments &vSubArguments);
+ virtual std::string BinFuncName(void) const { return "SeriesSum"; }
+};
class OpQuotient: public Normal
{
public: