21 const std::string &sSymName,
SubArguments &vSubArguments)
26 ss <<
" int gid0 = get_global_id(0);\n";
33 const std::string &sSymName,
SubArguments &vSubArguments)
38 ss <<
" double tmp = 0;\n";
39 ss <<
" int gid0 = get_global_id(0);\n";
48 ss <<
" return cos(arg0);\n";
53 ss <<
" return 1.0 / cos(arg0);\n";
58 ss <<
" return 1.0 / cosh(arg0);\n";
62 std::set<std::string>& funs)
70 ss <<
" return local_cosh(arg0);\n";
75 ss <<
" arg0 = arg0 * M_1_PI;\n";
76 ss <<
" return cospi(arg0) / sinpi(arg0);\n";
80 std::set<std::string>& funs)
88 ss <<
" return local_coth(arg0);\n";
93 ss <<
" double tmp = fabs(arg0 / 2);\n";
94 ss <<
" if ( trunc(tmp) == tmp )\n";
95 ss <<
" tmp = tmp * 2;\n";
97 ss <<
" tmp = (trunc(tmp) + 1) * 2;\n";
98 ss <<
" if (arg0 < 0)\n";
99 ss <<
" tmp = tmp * -1.0;\n";
100 ss <<
" return tmp;\n";
105 ss <<
" return 1/sin(arg0);\n";
110 ss <<
" return 1/sinh(arg0);\n";
115 ss <<
" return pow(M_E, arg0);\n";
120 ss <<
" return log10(arg0);\n";
125 ss <<
" return ( exp(arg0)-exp(-arg0) )/2;\n";
130 ss <<
" arg0 = arg0 * M_1_PI;\n";
131 ss <<
" return sinpi(arg0);\n";
136 ss <<
" return fabs(arg0);\n";
140 std::set<std::string>& funs)
148 ss <<
" return arctan2(sqrt(1.0 - pow(arg0, 2)), arg0);\n";
153 ss <<
" if( arg0 < 1 )\n";
154 ss <<
" return CreateDoubleError(IllegalArgument);\n";
155 ss <<
" return log( arg0 + pow( (pown(arg0, 2) - 1.0), 0.5));\n";
160 ss <<
" arg0 = arg0 * M_1_PI;\n";
161 ss <<
" return sinpi(arg0) / cospi(arg0);\n";
166 ss <<
" return tanh(arg0);\n";
171 ss <<
" if( arg0 < 0 )\n";
172 ss <<
" return CreateDoubleError(IllegalArgument);\n";
173 ss <<
" return sqrt(arg0);\n";
178 ss <<
" return M_PI_2 - atan(arg0);\n";
183 ss <<
" return 0.5 * log(1 + 2 / (arg0 - 1.0));\n";
187 std::set<std::string>& funs)
195 ss <<
" return arctan2(arg0, sqrt(1.0 - pow(arg0, 2)));\n";
200 ss <<
" return log( arg0 + pow((pown(arg0, 2) + 1.0), 0.5));\n";
205 ss <<
" return atan(arg0);\n";
210 ss <<
" double a = 1.0 + arg0;\n";
211 ss <<
" double b = 1.0 - arg0;\n";
212 ss <<
" return log(pow(a/b, 0.5));\n";
217 ss <<
" return log1p(arg0-1);\n";
221 std::set<std::string>& funs)
231 ss <<
" return floor( value_approx( arg0 ));\n";
236 ss <<
" return -arg0;\n";
241 ss <<
" return arg0 * M_PI / 180.0;\n";
246 ss <<
" return (fmod(floor(fabs(arg0)), 2.0)<0.5);\n";
251 ss <<
" return !(fmod(floor(fabs(arg0)), 2.0)<0.5);\n";
256 ss <<
" return (double)sqrt(arg0 * M_PI);\n";
261 ss <<
" return arg0 / M_PI * 180;;\n";
266 ss <<
" arg0 = floor(arg0);\n";
267 ss <<
" if (arg0 < 0.0)\n";
268 ss <<
" return CreateDoubleError(IllegalArgument);\n";
269 ss <<
" else if (arg0 == 0.0)\n";
270 ss <<
" return 1.0;\n";
271 ss <<
" else if (arg0 <= 170.0)\n";
273 ss <<
" double fTemp = arg0;\n";
274 ss <<
" while (fTemp > 2.0)\n";
276 ss <<
" fTemp = fTemp - 1;\n";
277 ss <<
" arg0 = arg0 * fTemp;\n";
281 ss <<
" return CreateDoubleError(NoValue);\n";
282 ss <<
" return arg0;\n";
286 std::set<std::string>& funs)
294 ss <<
" double tmp;\n";
295 ss <<
" if (arg0 > 0.0 ){\n";
296 ss <<
" tmp=Intg(arg0);\n";
297 ss <<
" if(tmp-trunc(tmp/2)*2 == 0)\n";
298 ss <<
" tmp=tmp+1;\n";
299 ss <<
" }else if (arg0 < 0.0 ){\n";
300 ss <<
" tmp=Intg(arg0);\n";
301 ss <<
" if(tmp-trunc(tmp/2)*2 == 0)\n";
302 ss <<
" tmp=tmp-1.0;\n";
305 ss <<
" return tmp;\n";
310 ss<<
" if(arg1==0)\n";
311 ss<<
" return arg1;\n";
312 ss<<
" tmp=arg1 * round(arg0 / arg1);\n";
313 ss<<
" return tmp;\n";
317 std::set<std::string>& funs)
325 ss <<
" arg0 = trunc(arg0);\n";
326 ss <<
" arg1 = trunc(arg1);\n";
327 ss <<
" if (arg0 < 0.0 || arg1 < 0.0 || arg1 > arg0)\n";
328 ss <<
" return CreateDoubleError(IllegalArgument);\n";
329 ss <<
" double tem;\n";
330 ss <<
" if(arg0 >= arg1 && arg0 > 0 && arg1 > 0)\n";
331 ss <<
" tem = bik(arg0+arg1-1,arg1);\n";
332 ss <<
" else if(arg0 == 0 && arg1 == 0)\n";
334 ss <<
" else if(arg0 > 0 && arg1 == 0)\n";
337 ss <<
" tem = -1;\n";
338 ss <<
" double i = tem - trunc(tem);\n";
339 ss <<
" if(i < 0.5)\n";
340 ss <<
" tem = trunc(tem);\n";
342 ss <<
" tem = trunc(tem) + 1;\n";
343 ss <<
" return tem;\n";
348 ss <<
" double result = -1.0;\n";
349 ss <<
" double num = floor( arg0 );\n";
350 ss <<
" double num_chosen = floor( arg1 );\n";
351 ss <<
" if(num < 0 || num_chosen < 0 || num < num_chosen )\n";
352 ss <<
" return CreateDoubleError(IllegalArgument);\n";
353 ss <<
" result = select(result, 0.0, (ulong)(num < num_chosen));\n";
354 ss <<
" result = select(result, 1.0, (ulong)(num_chosen == 0.0));\n";
355 ss <<
" if(result == 0 || result ==1)\n";
356 ss <<
" return result;\n";
357 ss <<
" double4 db4num;\n";
358 ss <<
" double4 db4num_chosen;\n";
359 ss <<
" double4 db4result;\n";
360 ss <<
" double2 db2result;\n";
361 ss <<
" result = 1.0;\n";
362 ss <<
" int loop = num_chosen/4;\n";
363 ss <<
" for(int i=0; i<loop; i++)\n";
365 ss <<
" db4num = (double4){num,\n";
368 ss <<
" num-3.0};\n";
369 ss <<
" db4num_chosen = (double4){num_chosen,\n";
370 ss <<
" num_chosen-1.0,\n";
371 ss <<
" num_chosen-2.0,\n";
372 ss <<
" num_chosen-3.0};\n";
373 ss <<
" db4result = db4num / db4num_chosen;\n";
374 ss <<
" db2result = db4result.xy * db4result.zw;\n";
375 ss <<
" result *= db2result.x * db2result.y;\n";
376 ss <<
" num = num - 4.0;\n";
377 ss <<
" num_chosen = num_chosen - 4.0;\n";
379 ss <<
" while ( num_chosen > 0){\n";
380 ss <<
" result *= num / num_chosen;\n";
381 ss <<
" num = num - 1.0;\n";
382 ss <<
" num_chosen = num_chosen - 1.0;\n";
384 ss <<
" return result;\n";
401 ss <<
" double fNum = arg0;\n";
402 ss <<
" double fDenom = arg1;\n";
403 ss <<
" if(fDenom == 0)\n";
404 ss <<
" return CreateDoubleError(DivisionByZero);\n";
405 ss <<
" double fRes = fsub_approx( fNum, floor( value_approx( fNum / fDenom )) * fDenom );\n";
406 ss <<
" if ( ( fDenom > 0 && fRes >= 0 && fRes < fDenom ) ||\n";
407 ss <<
" ( fDenom < 0 && fRes <= 0 && fRes > fDenom ) )\n";
408 ss <<
" return fRes;\n";
409 ss <<
" return CreateDoubleError(NoValue);\n";
414 ss <<
" return pow(arg0,arg1);\n";
418 std::set<std::string>& funs)
426 ss <<
" return arctan2(arg1, arg0);\n";
431 ss <<
" if( arg0 < 0 || arg1 < 0 || arg0 >= 281474976710656.0 || arg1 >= 281474976710656.0 )\n";
432 ss <<
" return CreateDoubleError(IllegalArgument);\n";
433 ss <<
" return (long)arg0 & (long)arg1;\n";
438 ss <<
" if( arg0 < 0 || arg1 < 0 || arg0 >= 281474976710656.0 || arg1 >= 281474976710656.0 )\n";
439 ss <<
" return CreateDoubleError(IllegalArgument);\n";
440 ss <<
" return (long)arg0 | (long)arg1;\n";
445 ss <<
" if( arg0 < 0 || arg1 < 0 || arg0 >= 281474976710656.0 || arg1 >= 281474976710656.0 )\n";
446 ss <<
" return CreateDoubleError(IllegalArgument);\n";
447 ss <<
" return (long)arg0 ^ (long)arg1;\n";
452 ss <<
" double num = floor( arg0 );\n";
453 ss <<
" double shift_amount = floor( arg1 );\n";
454 ss <<
" if( num < 0 || num >= 281474976710656.0 )\n";
455 ss <<
" return CreateDoubleError(IllegalArgument);\n";
456 ss <<
" return floor(shift_amount >= 0 ? ";
457 ss <<
"num * pow(2.0, shift_amount) : ";
458 ss <<
"num / pow(2.0, fabs(shift_amount)));\n";
463 ss <<
" double num = floor( arg0 );\n";
464 ss <<
" double shift_amount = floor( arg1 );\n";
465 ss <<
" if( num < 0 || num >= 281474976710656.0 )\n";
466 ss <<
" return CreateDoubleError(IllegalArgument);\n";
467 ss <<
" return floor(";
468 ss <<
"shift_amount >= 0 ? num / pow(2.0, shift_amount) : ";
469 ss <<
"num * pow(2.0, fabs(shift_amount)));\n";
474 ss <<
" return trunc(arg0/arg1);\n";
478 std::set<std::string>& funs)
489 const std::string &sSymName,
SubArguments &vSubArguments)
494 ss <<
" double tmp = 0;\n";
495 ss <<
" int gid0 = get_global_id(0);\n";
498 ss <<
" return cell_equal( arg0, arg1, arg0_is_string, arg1_is_string );\n";
503 std::set<std::string>& funs)
514 const std::string &sSymName,
SubArguments &vSubArguments)
519 ss <<
" double tmp = 0;\n";
520 ss <<
" int gid0 = get_global_id(0);\n";
523 ss <<
" return !cell_equal( arg0, arg1, arg0_is_string, arg1_is_string );\n";
528 std::set<std::string>& funs)
538 ss <<
" return approx_equal( arg0, arg1 ) || arg0 <= arg1;\n";
543 ss <<
" return arg0 < arg1;\n";
547 std::set<std::string>& funs)
557 ss <<
" return approx_equal( arg0, arg1 ) || arg0 >= arg1;\n";
562 ss <<
" return arg0 > arg1;\n";
566 const std::string &sSymName,
SubArguments &vSubArguments)
571 ss <<
" int gid0 = get_global_id(0);\n";
574 ss <<
" return log10(arg0)/log10(arg1);;\n";
579 const std::string &sSymName,
SubArguments &vSubArguments)
581 FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
589 ss <<
" int gid0=get_global_id(0);\n";
590 ss <<
" int tmp =0;\n";
591 ss <<
" int loop;\n";
594 ss<<
" int singleIndex =gid0;\n";
599 for(
size_t j=0;j<vSubArguments.size();j+=2,
m++)
603 tmpss <<
" if(isequal(";
611 tmpss <<
" tmp ++;\n";
612 for(
size_t j=0;j<vSubArguments.size();j+=2,
m--)
614 for(
int n = 0;
n<
m+1;
n++)
622 ss <<
"return tmp;\n";
627 const std::string &sSymName,
SubArguments &vSubArguments)
629 FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
641 ss <<
"__kernel void ";
642 ss << vSubArguments[0]->GetName();
643 ss <<
"_SumIfs_reduction( ";
644 for (
size_t i = 0;
i < vSubArguments.size();
i++)
648 vSubArguments[
i]->GenSlidingWindowDecl(ss);
650 ss <<
", __global double *result,int arrayLength,int windowSize";
653 ss <<
" double tmp =0;\n";
657 ss <<
" double current_result = 0.0;\n";
658 ss <<
" int writePos = get_group_id(1);\n";
660 ss <<
" int offset = 0;\n";
662 ss <<
" int offset = get_group_id(1);\n";
666 ss <<
" int lidx = get_local_id(0);\n";
667 ss <<
" __local double shm_buf[256];\n";
668 ss <<
" barrier(CLK_LOCAL_MEM_FENCE);\n";
669 ss <<
" int loop = arrayLength/512 + 1;\n";
670 ss <<
" for (int l=0; l<loop; l++){\n";
671 ss <<
" tmp = 0.0;\n";
672 ss <<
" int loopOffset = l*512;\n";
674 ss <<
" int p1 = loopOffset + lidx + offset, p2 = p1 + 256;\n";
675 ss <<
" if (p2 < min(offset + windowSize, arrayLength)) {\n";
676 ss <<
" tmp0 = 0.0;\n";
678 std::string p1 =
"p1";
679 std::string p2 =
"p2";
680 for(
size_t j=1;j<vSubArguments.size();j+=2,
mm++)
695 ss <<
" tmp += tmp0;\n";
696 for(
size_t j=1;j<vSubArguments.size();j+=2,
mm--)
698 for(
int n = 0;
n<
mm+1;
n++)
705 for(
size_t j=1;j<vSubArguments.size();j+=2,
mm++)
718 ss <<
" tmp += tmp0;\n";
719 for(
size_t j=1;j< vSubArguments.size();j+=2,
mm--)
721 for(
int n = 0;
n<
mm+1;
n++)
729 ss <<
" else if (p1 < min(arrayLength, offset + windowSize)) {\n";
731 for(
size_t j=1;j<vSubArguments.size();j+=2,
mm++)
745 ss <<
" tmp += tmp0;\n";
746 for(
size_t j=1;j<vSubArguments.size();j+=2,
mm--)
748 for(
int n = 0;
n<
mm+1;
n++)
756 ss <<
" shm_buf[lidx] = tmp;\n";
757 ss <<
" barrier(CLK_LOCAL_MEM_FENCE);\n";
758 ss <<
" for (int i = 128; i >0; i/=2) {\n";
759 ss <<
" if (lidx < i)\n";
760 ss <<
" shm_buf[lidx] += shm_buf[lidx + i];\n";
761 ss <<
" barrier(CLK_LOCAL_MEM_FENCE);\n";
763 ss <<
" if (lidx == 0)\n";
764 ss <<
" current_result += shm_buf[0];\n";
765 ss <<
" barrier(CLK_LOCAL_MEM_FENCE);\n";
768 ss <<
" if (lidx == 0)\n";
769 ss <<
" result[writePos] = current_result;\n";
775 ss <<
" int gid0=get_global_id(0);\n";
776 ss <<
" double tmp =0;\n";
783 ss <<
"gid0; i < "<< nCurWindowSize <<
"; i++)\n";
785 ss <<
"0; i < gid0+"<< nCurWindowSize <<
"; i++)\n";
787 ss <<
"0; i < "<< nCurWindowSize <<
"; i++)\n";
792 ss<<
" int doubleIndex =i+gid0;\n";
795 ss<<
" int doubleIndex =i;\n";
797 ss<<
" int singleIndex =gid0;\n";
799 for(
size_t j=1;j<vSubArguments.size();j+=2,
m++)
812 ss <<
" tmp += tmp0;\n";
813 for(
size_t j=1;j<=vSubArguments.size();j+=2,
m--)
815 for(
int n = 0;
n<
m+1;
n++)
825 vSubArguments[0]->GenDeclRef(ss);
828 ss <<
"return tmp;\n";
833 const std::string &sSymName,
SubArguments &vSubArguments)
835 FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
843 ss <<
" int gid0=get_global_id(0);\n";
844 ss <<
" double tmp =0;\n";
845 ss <<
" int count=0;\n";
848 ss<<
" int singleIndex =gid0;\n";
851 for(
size_t j=1;j<vSubArguments.size();j+=2,
m++)
855 tmpss <<
" if(isequal(";
864 tmpss <<
" tmp += tmp0;\n";
865 tmpss <<
" count++;\n";
866 for(
size_t j=1;j<vSubArguments.size();j+=2,
m--)
868 for(
int n = 0;
n<
m+1;
n++)
877 ss <<
" if(count!=0)\n";
878 ss <<
" tmp=tmp/count;\n";
881 ss <<
"return tmp;\n";
893 const std::string &sSymName,
SubArguments &vSubArguments)
898 ss <<
" int gid0=get_global_id(0);\n";
900 if(vSubArguments.size() ==1)
901 ss <<
" return round(value);\n";
905 ss <<
" int dec = floor( fDec );\n";
906 ss <<
" if( dec < -20 || dec > 20 )\n";
907 ss <<
" return CreateDoubleError( IllegalArgument );\n";
908 ss <<
" if( dec == 0 )\n";
909 ss <<
" return round(value);\n";
910 ss <<
" double orig_value = value;\n";
911 ss <<
" value = fabs(value);\n";
912 ss <<
" double multiply = pown(10.0, dec);\n";
913 ss <<
" double tmp = value*multiply;\n";
914 ss <<
" tmp = Round( tmp );\n";
915 ss <<
" return copysign(tmp/multiply, orig_value);\n";
921 const std::string &sSymName,
SubArguments &vSubArguments)
926 ss <<
" int gid0=get_global_id(0);\n";
929 ss <<
" int dec = floor( fDec );\n";
930 ss <<
" if( dec < -20 || dec > 20 )\n";
931 ss <<
" return CreateDoubleError( IllegalArgument );\n";
932 ss <<
" double orig_value = value;\n";
933 ss <<
" value = fabs(value);\n";
934 ss <<
" double multiply = pown(10.0, dec);\n";
935 ss <<
" double tmp = value*multiply;\n";
936 ss <<
" double integral;\n";
940 ss <<
" if( modf( tmp, &integral ) / multiply < 1e-12 )\n";
941 ss <<
" tmp = integral;\n";
943 ss <<
" tmp = integral + 1;\n";
944 ss <<
" return copysign(tmp/multiply, orig_value);\n";
949 const std::string &sSymName,
SubArguments &vSubArguments)
954 ss <<
" int gid0=get_global_id(0);\n";
957 ss <<
" int dec = floor( fDec );\n";
958 ss <<
" if( dec < -20 || dec > 20 )\n";
959 ss <<
" return CreateDoubleError( IllegalArgument );\n";
960 ss <<
" double orig_value = value;\n";
961 ss <<
" value = fabs(value);\n";
962 ss <<
" double multiply = pown(10.0, dec);\n";
963 ss <<
" double tmp = value*multiply;\n";
964 ss <<
" double integral;\n";
968 ss <<
" if(( 1 - modf( tmp, &integral )) / multiply < 1e-12 )\n";
969 ss <<
" tmp = integral + 1;\n";
971 ss <<
" tmp = integral;\n";
972 ss <<
" return copysign(tmp/multiply, orig_value);\n";
977 const std::string &sSymName,
SubArguments &vSubArguments)
981 ss <<
" int gid0=get_global_id(0);\n";
982 ss <<
" double vara, varb;\n";
983 ss <<
" int varc = 0;\n";
984 FormulaToken *tmpCur = vSubArguments[1]->GetFormulaToken();
986 if(
ocPush == vSubArguments[1]->GetFormulaToken()->GetOpCode())
994 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
996 ss <<
" if(isnan(varb)||(gid0>=";
999 ss <<
" varb = 0;\n";
1010 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
1013 tmpCur = vSubArguments[0]->GetFormulaToken();
1015 if(
ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
1023 ss <<
" for (int i = ";
1027 ss <<
" && i < " << nCurWindowSize <<
"; ++i)\n";
1033 ss <<
" && i < gid0+"<< nCurWindowSize <<
"; ++i)\n";
1039 ss <<
" && i < "<< nCurWindowSize <<
"; ++i)\n";
1044 ss <<
"0; i < "<< nCurWindowSize <<
"; ++i)\n";
1048 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1050 ss <<
" if (isnan(vara))\n";
1051 ss <<
" continue;\n";
1052 ss <<
" (vara == varb) && varc++;\n";
1061 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1063 ss <<
" if(isnan(vara)||(gid0>=";
1066 ss <<
" return 0;\n";
1067 ss <<
" (vara == varb) && varc++;\n";
1070 ss <<
" return varc;\n";
1075 const std::string &sSymName,
SubArguments &vSubArguments)
1079 ss <<
" int gid0=get_global_id(0);\n";
1080 ss <<
" double vara, varb, varc, sum = 0.0f;\n";
1081 int flag = 3 == vSubArguments.size() ? 2 : 0;
1082 FormulaToken *tmpCur = vSubArguments[1]->GetFormulaToken();
1084 if(
ocPush == vSubArguments[1]->GetFormulaToken()->GetOpCode())
1092 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
1094 ss <<
" if(isnan(varb)||(gid0>=";
1097 ss <<
" varb = 0;\n";
1108 ss << vSubArguments[1]->GenSlidingWindowDeclRef();
1111 tmpCur = vSubArguments[0]->GetFormulaToken();
1113 if(
ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
1121 ss <<
" for (int i = ";
1125 ss <<
" && i < " << nCurWindowSize <<
"; ++i)\n";
1131 ss <<
" && i < gid0+"<< nCurWindowSize <<
"; ++i)\n";
1137 ss <<
" && i < "<< nCurWindowSize <<
"; ++i)\n";
1142 ss <<
"0; i < "<< nCurWindowSize <<
"; ++i)\n";
1146 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1148 ss <<
" if (isnan(vara))\n";
1149 ss <<
" continue;\n";
1151 ss << vSubArguments[flag]->GenSlidingWindowDeclRef();
1153 ss <<
" if (isnan(varc))\n";
1154 ss <<
" varc = 0.0f;\n";
1155 ss <<
" (vara == varb)&&(sum = sum + varc);\n";
1164 ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1166 ss <<
" if(isnan(vara)||(gid0>=";
1169 ss <<
" return 0;\n";
1170 ss <<
" int i = 0;\n";
1172 ss << vSubArguments[flag]->GenSlidingWindowDeclRef();
1174 ss <<
" if(isnan(varc)||(gid0>=";
1177 ss <<
" varc = 0.0f;\n";
1179 ss <<
" (vara == varb)&&(sum = sum + varc);\n";
1183 ss <<
" return sum;\n";
1194 ss <<
" int gid0=get_global_id(0);\n";
1198 ss <<
" if(isnan(arg0) || isnan(arg1))\n";
1199 ss <<
" return 0;\n";
1200 ss <<
" if(isnan(arg2))\n";
1201 ss <<
" arg2 = 0.0;\n";
1202 ss <<
" if(arg0*arg1<0)\n";
1203 ss <<
" return CreateDoubleError(IllegalArgument);\n";
1204 ss <<
" if(arg1 == 0.0)\n";
1205 ss <<
" return 0.0;\n";
1206 ss <<
" else if(arg2==0.0&&arg0<0.0)\n";
1207 ss <<
" return (trunc(arg0/arg1)+1)*arg1;\n";
1209 ss <<
" return trunc(arg0/arg1)*arg1;\n";
1214 const std::string &sSymName,
SubArguments &vSubArguments)
1219 ss <<
" int gid0=get_global_id(0);\n";
1220 ss <<
" double sum = 0.0f, arg;\n";
1222 " sum += pown(arg, 2);\n"
1224 ss <<
" return sum;\n";
1229 const std::string &sSymName,
SubArguments &vSubArguments)
1234 ss <<
" int gid0 = get_global_id(0);\n";
1236 GenerateArg(
"significance", 1, vSubArguments, ss );
1238 ss <<
" if(num*significance < 0.0)\n";
1239 ss <<
" return CreateDoubleError(IllegalArgument);\n";
1240 ss <<
" if(significance == 0.0)\n";
1241 ss <<
" return 0.0;\n";
1243 ss <<
"( !(int)bAbs && num < 0.0 ? floor( num / significance ) : ";
1244 ss <<
"ceil( num / significance ) )";
1245 ss <<
"*significance;\n";
1250 const std::string &sSymName,
SubArguments &vSubArguments)
1255 ss <<
" int gid0 = get_global_id(0);\n";
1256 ss <<
" double product=1.0;\n";
1257 ss <<
" int count = 0;\n\n";
1259 " product = product*arg;\n"
1262 ss <<
" if(count == 0)\n";
1263 ss <<
" return 0;\n";
1264 ss <<
" return product;\n";
1269 const std::string &sSymName,
SubArguments &vSubArguments)
1273 ss <<
" int gid0=get_global_id(0);\n";
1274 ss <<
" double tmp =0;\n";
1275 ss <<
" double count=0;\n";
1276 ss <<
" int singleIndex =gid0;\n";
1277 ss <<
" int doubleIndex;\n";
1282 unsigned paraOneIsDoubleVector = 0;
1283 unsigned paraOneWidth = 1;
1284 unsigned paraTwoWidth = 1;
1285 unsigned loopTimes = 0;
1289 paraOneIsDoubleVector = 1;
1290 FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
1293 paraOneWidth = pCurDVR0->
GetArrays().size();
1294 loopTimes = paraOneWidth;
1295 if(paraOneWidth > 1)
1301 if(vSubArguments[paraOneWidth]->GetFormulaToken()->GetType() ==
1305 FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
1308 paraTwoWidth = pCurDVR1->
GetArrays().size();
1309 if(paraTwoWidth > 1)
1321 ss <<
" doubleIndex =i+gid0;\n";
1324 ss <<
" doubleIndex =i;\n";
1330 unsigned paraThreeIndex = paraOneWidth + paraTwoWidth;
1331 if(vSubArguments.size() > paraThreeIndex)
1333 if(vSubArguments[paraThreeIndex]->GetFormulaToken()->GetType() ==
1337 vSubArguments[paraThreeIndex]->GetFormulaToken();
1340 unsigned paraThreeWidth = pCurDVR2->
GetArrays().size();
1341 if(paraThreeWidth > 1)
1348 if(paraOneIsDoubleVector)
1350 unsigned loopIndex = 0;
1351 FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
1358 for(loopIndex =0; loopIndex < loopTimes; loopIndex++)
1362 ss <<
"gid0; i < "<< nCurWindowSize <<
"; i++)\n";
1364 ss <<
"0; i < gid0+"<< nCurWindowSize <<
"; i++)\n";
1366 ss <<
"0; i < "<< nCurWindowSize <<
"; i++)\n";
1371 ss <<
" doubleIndex =i+gid0;\n";
1374 ss <<
" doubleIndex =i;\n";
1379 ss <<
" if ( isequal( tmp";
1380 ss << loopIndex<<
" , tmp"<<paraOneWidth<<
") ) \n";
1382 if(vSubArguments.size() == paraThreeIndex)
1383 ss <<
" tmp += tmp"<<loopIndex<<
";\n";
1387 paraThreeIndex+loopIndex);
1388 ss <<
" tmp += tmp";
1389 ss << paraThreeIndex+loopIndex<<
";\n";
1391 ss <<
" count+=1.0;\n";
1399 ss <<
" if ( isequal( tmp0 , tmp1 ) ) \n";
1401 if(vSubArguments.size() == 2)
1402 ss <<
" tmp += tmp0;\n";
1406 ss <<
" tmp += tmp2;\n";
1408 ss <<
" count+=1.0;\n";
1412 ss <<
" if(count!=0)\n";
1413 ss <<
" tmp=tmp/count;\n";
1415 ss <<
" tmp= 0 ;\n";
1416 ss <<
" return tmp;\n";
1421 const std::string &sSymName,
SubArguments &vSubArguments)
1426 ss <<
" int gid0=get_global_id(0);\n";
1427 ss <<
" double var[3], coeff, res = 0.0f;\n";
1431 ss <<
" if( var0 == 0 && var1 == 0 )\n";
1432 ss <<
" return CreateDoubleError(NoValue);\n";
1433 ss <<
" var[0] = var0;\n";
1434 ss <<
" var[1] = var1;\n";
1435 ss <<
" var[2] = var2;\n";
1436 ss <<
" int j = 0;\n";
1438 " double coeff = arg;\n"
1439 " res = res + coeff * pow(var[0], var[1] + j * var[2]);\n"
1442 ss <<
" return res;\n";
1447 const std::string& sSymName,
SubArguments& vSubArguments )
1449 size_t nCurWindowSize = 0;
1454 for (
size_t i = 0;
i < vSubArguments.size();
i++)
1456 size_t nCurChildWindowSize = vSubArguments[
i]->GetWindowSize();
1457 nCurWindowSize = (nCurWindowSize < nCurChildWindowSize) ?
1458 nCurChildWindowSize : nCurWindowSize;
1459 tmpCur = vSubArguments[
i]->GetFormulaToken();
1467 ss <<
" double tmp = 0.0;\n";
1468 ss <<
" int gid0 = get_global_id(0);\n";
1470 ss <<
"\tint i;\n\t";
1471 ss <<
"int currentCount0;\n";
1472 for (
size_t i = 0;
i < vSubArguments.size() - 1;
i++)
1473 ss <<
"int currentCount" <<
i + 1 <<
";\n";
1476 if (nCurWindowSize / outLoopSize != 0)
1478 ss <<
"for(int outLoop=0; outLoop<" <<
1479 nCurWindowSize / outLoopSize <<
"; outLoop++){\n\t";
1482 ss <<
"i = outLoop*" << outLoopSize <<
"+" <<
count <<
";\n";
1485 for (
size_t i = 0;
i < vSubArguments.size();
i++)
1487 tmpCur = vSubArguments[
i]->GetFormulaToken();
1493 temp3 <<
" currentCount";
1495 temp3 <<
" =i+gid0+1;\n";
1499 temp3 <<
" currentCount";
1501 temp3 <<
" =i+1;\n";
1506 temp3 <<
"tmp = fsum(";
1507 for (
size_t i = 0;
i < vSubArguments.size();
i++)
1511 if (
ocPush == vSubArguments[
i]->GetFormulaToken()->GetOpCode())
1514 temp3 <<
"(currentCount";
1517 if (vSubArguments[
i]->GetFormulaToken()->GetType() ==
1522 (vSubArguments[
i]->GetFormulaToken());
1524 temp3 <<
")||isnan(" << vSubArguments[
i]
1525 ->GenSlidingWindowDeclRef();
1527 temp3 << vSubArguments[
i]->GenSlidingWindowDeclRef();
1530 else if (vSubArguments[
i]->GetFormulaToken()->GetType() ==
1535 (vSubArguments[
i]->GetFormulaToken());
1537 temp3 <<
")||isnan(" << vSubArguments[
i]
1538 ->GenSlidingWindowDeclRef(
true);
1540 temp3 << vSubArguments[
i]->GenSlidingWindowDeclRef(
true);
1546 temp3 << vSubArguments[
i]->GenSlidingWindowDeclRef(
true);
1548 temp3 <<
", tmp);\n\t";
1555 for (
size_t count = nCurWindowSize / outLoopSize * outLoopSize;
1558 ss <<
"i =" <<
count <<
";\n";
1559 if (
count == nCurWindowSize / outLoopSize * outLoopSize)
1561 for (
size_t i = 0;
i < vSubArguments.size();
i++)
1563 tmpCur = vSubArguments[
i]->GetFormulaToken();
1569 temp4 <<
" currentCount";
1571 temp4 <<
" =i+gid0+1;\n";
1575 temp4 <<
" currentCount";
1577 temp4 <<
" =i+1;\n";
1582 temp4 <<
"tmp = fsum(";
1583 for (
size_t i = 0;
i < vSubArguments.size();
i++)
1587 if (
ocPush == vSubArguments[
i]->GetFormulaToken()->GetOpCode())
1590 temp4 <<
"(currentCount";
1593 if (vSubArguments[
i]->GetFormulaToken()->GetType() ==
1598 (vSubArguments[
i]->GetFormulaToken());
1600 temp4 <<
")||isnan(" << vSubArguments[
i]
1601 ->GenSlidingWindowDeclRef();
1603 temp4 << vSubArguments[
i]->GenSlidingWindowDeclRef();
1606 else if (vSubArguments[
i]->GetFormulaToken()->GetType() ==
1611 (vSubArguments[
i]->GetFormulaToken());
1613 temp4 <<
")||isnan(" << vSubArguments[
i]
1614 ->GenSlidingWindowDeclRef(
true);
1616 temp4 << vSubArguments[
i]->GenSlidingWindowDeclRef(
true);
1623 temp4 << vSubArguments[
i]
1624 ->GenSlidingWindowDeclRef(
true);
1627 temp4 <<
", tmp);\n\t";
1631 ss <<
"return tmp;\n";
static void CheckSubArgumentIsNan2(outputstream &ss, SubArguments &vSubArguments, int argumentNum, const std::string &p)
static void CheckSubArgumentIsNan(outputstream &ss, SubArguments &vSubArguments, int argumentNum)
static void GenTmpVariables(outputstream &ss, const SubArguments &vSubArguments)
static void UnrollDoubleVector(outputstream &ss, const outputstream &unrollstr, const formula::DoubleVectorRefToken *pCurDVR, int nCurWindowSize)
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void BinInlineFun(std::set< std::string > &, std::set< std::string > &) override
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void BinInlineFun(std::set< std::string > &, std::set< std::string > &) override
virtual void BinInlineFun(std::set< std::string > &, std::set< std::string > &) override
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the arguments are "arg0" and "arg1".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the arguments are "arg0" and "arg1".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the arguments are "arg0" and "arg1".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the arguments are "arg0" and "arg1".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the arguments are "arg0" and "arg1".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the arguments are "arg0" and "arg1".
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
virtual void BinInlineFun(std::set< std::string > &, std::set< std::string > &) override
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the arguments are "arg0" and "arg1".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the arguments are "arg0" and "arg1".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void BinInlineFun(std::set< std::string > &, std::set< std::string > &) override
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void BinInlineFun(std::set< std::string > &, std::set< std::string > &) override
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void BinInlineFun(std::set< std::string > &, std::set< std::string > &) override
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the arguments are "arg0" and "arg1".
virtual void BinInlineFun(std::set< std::string > &, std::set< std::string > &) override
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the arguments are "arg0" and "arg1".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void BinInlineFun(std::set< std::string > &, std::set< std::string > &) override
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void BinInlineFun(std::set< std::string > &, std::set< std::string > &) override
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the arguments are "arg0" and "arg1".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the arguments are "arg0" and "arg1".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the arguments are "arg0" and "arg1".
virtual void GenerateCode(outputstream &ss) const =0
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
virtual void GenerateCode(outputstream &ss) const =0
This writes out OpenCL code returning the computed value, the arguments are "arg0" and "arg1".
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
virtual void BinInlineFun(std::set< std::string > &, std::set< std::string > &) override
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the arguments are "arg0" and "arg1".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void BinInlineFun(std::set< std::string > &, std::set< std::string > &) override
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
virtual void BinInlineFun(std::set< std::string > &, std::set< std::string > &) override
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the arguments are "arg0" and "arg1".
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the arguments are "arg0" and "arg1".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
virtual void BinInlineFun(std::set< std::string > &, std::set< std::string > &) override
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void BinInlineFun(std::set< std::string > &decls, std::set< std::string > &funs) override
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
bool mNeedReductionKernel
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
virtual void BinInlineFun(std::set< std::string > &decls, std::set< std::string > &funs) override
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
virtual void GenerateCode(outputstream &ss) const override
This writes out OpenCL code returning the computed value, the argument is "arg0".
void GenerateArg(const char *name, int arg, SubArguments &vSubArguments, outputstream &ss, EmptyArgType empty=EmptyIsZero, GenerateArgTypeType generateType=DoNotGenerateArgType)
static void GenerateRangeArg(int arg, SubArguments &vSubArguments, outputstream &ss, EmptyArgType empty, const char *code)
void GenerateArgWithDefault(const char *name, int arg, double def, SubArguments &vSubArguments, outputstream &ss, EmptyArgType empty=EmptyIsZero)
void GenerateFunctionDeclaration(const std::string &sSymName, SubArguments &vSubArguments, outputstream &ss)
static void GenerateRangeArgs(int firstArg, int lastArg, SubArguments &vSubArguments, outputstream &ss, EmptyArgType empty, const char *code)
std::vector< DynamicKernelArgumentRef > SubArguments
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
const char fsum_approxDecl[]
const char local_cothDecl[]
const char is_representable_integerDecl[]
const char atan2Content[]
const char fsub_approxDecl[]
const char approx_equalDecl[]
const char approx_equal[]
const char local_coshDecl[]
const char value_approxDecl[]
const char value_approx[]
const char Math_IntgDecl[]
const char nCorrValDecl[]
const char cell_equalDecl[]
const char is_representable_integer[]
#define CHECK_PARAMETER_COUNT(min, max)