summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sc/qa/unit/opencl-test.cxx1
-rw-r--r--sc/source/core/opencl/op_statistical.cxx97
2 files changed, 48 insertions, 50 deletions
diff --git a/sc/qa/unit/opencl-test.cxx b/sc/qa/unit/opencl-test.cxx
index 7796b57a675a..9d283597141c 100644
--- a/sc/qa/unit/opencl-test.cxx
+++ b/sc/qa/unit/opencl-test.cxx
@@ -1494,7 +1494,6 @@ void ScOpenclTest::testStatisticalFormulaNegbinomdist()
{
double fLibre = pDoc->GetValue(ScAddress(3,i,0));
double fExcel = pDocRes->GetValue(ScAddress(3,i,0));
- std::cout<<fLibre<<"\t"<<fExcel<<"\n";
CPPUNIT_ASSERT_DOUBLES_EQUAL(fExcel, fLibre, fabs(0.0001*fExcel));
}
xDocSh->DoClose();
diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx
index 17690566344d..4af1fd367616 100644
--- a/sc/source/core/opencl/op_statistical.cxx
+++ b/sc/source/core/opencl/op_statistical.cxx
@@ -3708,64 +3708,63 @@ void OpNegbinomdist::GenSlidingWindowFunction(
}
ss << ")\n";
ss << "{\n\t";
- ss << "double f,s,p;\n\t";
- ss << " int gid0=get_global_id(0);\n\t";
-#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);
- ss<< "int buffer_f_len = ";
- ss<< tmpCurDVR0->GetArrayLength();
- ss << ";\n\t";
-
- ss<< "int buffer_s_len = ";
- ss<< tmpCurDVR1->GetArrayLength();
- ss << ";\n\t";
-
- ss<< "int buffer_p_len = ";
- ss<< tmpCurDVR2->GetArrayLength();
- ss << ";\n\t";
+ ss << "double f,s,p,tmp0,tmp1,tmp2;\n";
+ ss << " int gid0=get_global_id(0);\n";
+ size_t i = vSubArguments.size();
+ ss <<"\n";
+ for (i = 0; i < vSubArguments.size(); i++)
+ {
+ FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
+ assert(pCur);
+ if (pCur->GetType() == formula::svSingleVectorRef)
+ {
+#ifdef ISNAN
+ const formula::SingleVectorRefToken* pSVR =
+ dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
+ ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
#endif
-#ifdef ISNAN
- ss<<"if((gid0)>=buffer_p_len || isNan(";
- ss << vSubArguments[2]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"p = 0;\n\telse \n\t\t";
+ }
+ else if (pCur->GetType() == formula::svDouble)
+ {
+#ifdef ISNAN
+ ss << "{\n";
#endif
- ss << " p = "<<vSubArguments[2]->GenSlidingWindowDeclRef();
- ss << " ;\n\t";
-#ifdef ISNAN
- ss<<"if((gid0)>=buffer_s_len || isNan(";
- ss << vSubArguments[1]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"s = 0;\n\telse \n\t\t";
+ }
+ else
+ {
+#ifdef ISNAN
#endif
- ss << " s = "<<vSubArguments[1]->GenSlidingWindowDeclRef();
- ss << " ;\n\t";
-#ifdef ISNAN
- ss<<"if((gid0)>=buffer_f_len || isNan(";
- ss << vSubArguments[0]->GenSlidingWindowDeclRef();
- ss<<"))\n\t\t";
- ss<<"f = 0;\n\telse \n\t\t";
+ }
+#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<<"=\n";
+ ss << vSubArguments[i]->GenSlidingWindowDeclRef();
+ ss << ";\n}\n";
+ }
+ else
+ {
+ ss << "tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
+ ss <<";\n";
+ }
#endif
- ss << " f = "<<vSubArguments[0]->GenSlidingWindowDeclRef();
- ss << " ;\n\t";
+ }
+ ss << " p = tmp2;\n";
+ ss << " s = tmp1;\n";
+ ss << " f = tmp0;\n";
ss << " double q = 1.0 - p;\n\t";
ss << " double fFactor = pow(p,s);\n\t";
ss << " for(int i=0; i<f; i++)\n\t";
ss << " {\n\t";
- ss << " fFactor *= ((double)i+s)/((double)i+1.0)*q;\n\t";
+ ss << " fFactor *= ((double)i+s)*pow(((double)i+1.0),-1.0)/pow(q,-1);\n";
ss << " }\n\t";
- ss << " double tmp=fFactor;\n\t";
- ss << " return tmp;\n";
+ ss << " double temp=fFactor;\n\t";
+ ss << " return temp;\n";
ss << "}\n";
}