20 const std::string &sSymName,
SubArguments &vSubArguments)
25 ss <<
" int gid0 = get_global_id(0);\n";
28 ss <<
" double f_2_DIV_PI = 2.0 / M_PI;\n";
29 ss <<
" if( N < 0.0 )\n";
30 ss <<
" return CreateDoubleError(IllegalArgument);\n";
31 ss <<
" if (x == 0.0)\n";
32 ss <<
" return (N == 0.0) ? 1.0 : 0.0;\n";
33 ss <<
" double fSign = ((int)N % 2 == 1 && x < 0.0) ? -1.0 : 1.0;\n";
34 ss <<
" double fX = fabs(x);\n";
35 ss <<
" double fMaxIteration = 9000000.0;\n";
36 ss <<
" double fEstimateIteration = fX * 1.5 + N;\n";
37 ss <<
" bool bAsymptoticPossible = pow(fX,0.4) > N;\n";
38 ss <<
" if (fEstimateIteration > fMaxIteration)\n";
40 ss <<
" if (bAsymptoticPossible)\n";
41 ss <<
" return fSign * sqrt(f_2_DIV_PI/fX)";
42 ss <<
"* cos(fX-N*M_PI_2-M_PI_4);\n";
44 ss <<
" return CreateDoubleError(NoConvergence);\n";
46 ss <<
" double epsilon = 1.0e-15;\n";
47 ss <<
" bool bHasfound = false;\n";
48 ss <<
" double k= 0.0;\n";
49 ss <<
" double u ;\n";
50 ss <<
" double m_bar;\n";
51 ss <<
" double g_bar;\n";
52 ss <<
" double g_bar_delta_u;\n";
53 ss <<
" double g = 0.0;\n";
54 ss <<
" double delta_u = 0.0;\n";
55 ss <<
" double f_bar = -1.0;\n";
59 ss <<
" g_bar_delta_u = 0.0;\n";
60 ss <<
" g_bar = - 2.0/fX; \n";
61 ss <<
" delta_u = g_bar_delta_u / g_bar;\n";
62 ss <<
" u = u + delta_u ;\n";
63 ss <<
" g = -1.0 / g_bar; \n";
64 ss <<
" f_bar = f_bar * g;\n";
70 ss <<
" for (k =1.0; k<= N-1; k = k + 1.0)\n";
72 ss <<
" m_bar=2.0 * fmod(k-1.0, 2.0) * f_bar;\n";
73 ss <<
" g_bar_delta_u = - g * delta_u - m_bar * u;\n";
74 ss <<
" g_bar = m_bar - 2.0*k/fX + g;\n";
75 ss <<
" delta_u = g_bar_delta_u / g_bar;\n";
76 ss <<
" u = u + delta_u;\n";
77 ss <<
" g = -1.0/g_bar;\n";
78 ss <<
" f_bar=f_bar * g;\n";
80 ss <<
" m_bar=2.0 * fmod(k-1.0, 2.0) * f_bar;\n";
81 ss <<
" g_bar_delta_u = f_bar - g * delta_u - m_bar * u;\n";
82 ss <<
" g_bar = m_bar - 2.0*k/fX + g;\n";
83 ss <<
" delta_u = g_bar_delta_u / g_bar;\n";
84 ss <<
" u = u + delta_u;\n";
85 ss <<
" g = -1.0/g_bar;\n";
86 ss <<
" f_bar = f_bar * g;\n";
87 ss <<
" k = k + 1.0;\n";
91 ss <<
" m_bar = 2.0 * fmod(k-1.0, 2.0) * f_bar;\n";
92 ss <<
" g_bar_delta_u = - g * delta_u - m_bar * u;\n";
93 ss <<
" g_bar = m_bar - 2.0*k/fX + g;\n";
94 ss <<
" delta_u = g_bar_delta_u / g_bar;\n";
95 ss <<
" u = u + delta_u;\n";
96 ss <<
" g = -pow(g_bar,-1.0);\n";
97 ss <<
" f_bar = f_bar * g;\n";
98 ss <<
" bHasfound = (fabs(delta_u)<=fabs(u)*epsilon);\n";
99 ss <<
" k = k + 1.0;\n";
101 ss <<
" while (!bHasfound && k <= fMaxIteration);\n";
102 ss <<
" if (bHasfound)\n";
103 ss <<
" return u * fSign;\n";
105 ss <<
" return CreateDoubleError(NoConvergence);\n";
115 ss <<
" double tmp=0;\n";
116 ss <<
" int gid0=get_global_id(0);\n";
120 ss <<
" tmp =tmp0 >= tmp1 ? 1 : 0;\n";
121 ss <<
" return tmp;\n";
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
void GenerateArg(const char *name, int arg, SubArguments &vSubArguments, outputstream &ss, EmptyArgType empty=EmptyIsZero, GenerateArgTypeType generateType=DoNotGenerateArgType)
void GenerateFunctionDeclaration(const std::string &sSymName, SubArguments &vSubArguments, outputstream &ss)
std::vector< DynamicKernelArgumentRef > SubArguments
#define CHECK_PARAMETER_COUNT(min, max)