Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : */
9 :
10 : #include "op_math.hxx"
11 :
12 : #include "formulagroup.hxx"
13 : #include "document.hxx"
14 : #include "formulacell.hxx"
15 : #include "tokenarray.hxx"
16 : #include "compiler.hxx"
17 : #include "interpre.hxx"
18 : #include <formula/vectortoken.hxx>
19 : #include "opinlinefun_math.hxx"
20 : #include <sstream>
21 :
22 : using namespace formula;
23 :
24 : namespace sc { namespace opencl {
25 :
26 0 : void OpCos::GenSlidingWindowFunction(std::stringstream &ss,
27 : const std::string &sSymName, SubArguments &vSubArguments)
28 : {
29 0 : ss << "\ndouble " << sSymName;
30 0 : ss << "_"<< BinFuncName() <<"(";
31 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
32 : {
33 0 : if (i) ss << ",";
34 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
35 : }
36 0 : ss << ")\n";
37 0 : ss << "{\n";
38 0 : ss << " int gid0=get_global_id(0);\n";
39 0 : ss << " double arg0 = 0.0f;\n";
40 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
41 : assert(tmpCur);
42 0 : if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
43 : {
44 0 : if(tmpCur->GetType() == formula::svSingleVectorRef)
45 : {
46 : const formula::SingleVectorRefToken*tmpCurDVR=
47 : static_cast
48 0 : <const formula::SingleVectorRefToken *>(tmpCur);
49 0 : ss << " arg0 = ";
50 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
51 0 : ss << ";\n";
52 0 : ss << " if(isNan(";
53 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
54 0 : ss << ")||(gid0>=";
55 0 : ss << tmpCurDVR->GetArrayLength();
56 0 : ss << "))\n";
57 0 : ss << " { arg0 = 0.0f; }\n";
58 : }
59 0 : else if(tmpCur->GetType() == formula::svDouble)
60 : {
61 0 : ss << " arg0=" << tmpCur->GetDouble() << ";\n";
62 : }
63 : }
64 : else
65 : {
66 0 : ss << " arg0 = ";
67 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
68 0 : ss << ";\n";
69 : }
70 0 : ss << " return cos(arg0);\n";
71 0 : ss << "}";
72 :
73 0 : }
74 0 : void OpSec::GenSlidingWindowFunction(std::stringstream &ss,
75 : const std::string &sSymName, SubArguments &vSubArguments)
76 : {
77 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
78 : const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const
79 0 : formula::SingleVectorRefToken *>(tmpCur);
80 0 : ss << "\ndouble " << sSymName;
81 0 : ss << "_"<< BinFuncName() <<"(";
82 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
83 : {
84 0 : if (i)
85 0 : ss << ",";
86 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
87 : }
88 0 : ss << ") {\n";
89 0 : ss <<" int gid0=get_global_id(0);\n";
90 0 : ss <<" double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
91 0 : ss <<";\n";
92 0 : ss<<" if(isNan(arg0)||(gid0>=";
93 0 : ss<<tmpCurDVR->GetArrayLength();
94 0 : ss<<"))\n";
95 0 : ss<<" arg0 = 0;\n";
96 0 : ss << " return pow(cos(arg0),-1 );\n";
97 0 : ss << "}";
98 0 : }
99 0 : void OpCosh::BinInlineFun(std::set<std::string>& decls,
100 : std::set<std::string>& funs)
101 : {
102 0 : decls.insert(local_coshDecl);
103 0 : funs.insert(local_cosh);
104 0 : }
105 0 : void OpSecH::GenSlidingWindowFunction(std::stringstream &ss,
106 : const std::string &sSymName, SubArguments &vSubArguments)
107 : {
108 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
109 : const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const
110 0 : formula::SingleVectorRefToken *>(tmpCur);
111 0 : ss << "\ndouble " << sSymName;
112 0 : ss << "_"<< BinFuncName() <<"(";
113 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
114 : {
115 0 : if (i)
116 0 : ss << ",";
117 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
118 : }
119 0 : ss << ") {\n";
120 0 : ss <<" int gid0=get_global_id(0);\n";
121 0 : ss <<" double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
122 0 : ss <<";\n";
123 0 : ss<<" if(isNan(arg0)||(gid0>=";
124 0 : ss<<tmpCurDVR->GetArrayLength();
125 0 : ss<<"))\n";
126 0 : ss<<" arg0 = 0;\n";
127 0 : ss << " return pow(cosh(arg0),-1 );\n";
128 0 : ss << "}";
129 0 : }
130 0 : void OpMROUND::GenSlidingWindowFunction(std::stringstream &ss,
131 : const std::string &sSymName, SubArguments &vSubArguments)
132 : {
133 0 : ss << "\ndouble " << sSymName;
134 0 : ss << "_"<< BinFuncName() <<"(";
135 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
136 : {
137 0 : if (i)
138 0 : ss << ", ";
139 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
140 : }
141 0 : ss<<") {\n";
142 0 : ss<<" double tmp = 0;\n";
143 0 : ss<<" int gid0 = get_global_id(0);\n";
144 0 : ss<<" double arg0=0;\n";
145 0 : ss<<" double arg1=0;\n";
146 0 : ss <<"\n ";
147 : //while (i-- > 1)
148 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
149 : {
150 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
151 : assert(pCur);
152 0 : if (pCur->GetType() == formula::svSingleVectorRef)
153 : {
154 : const formula::SingleVectorRefToken* pSVR =
155 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
156 0 : ss << "if (gid0 < " << pSVR->GetArrayLength() << "){\n";
157 : }
158 0 : else if (pCur->GetType() == formula::svDouble)
159 : {
160 0 : ss << "{\n";
161 : }
162 : else
163 : {
164 : }
165 0 : if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
166 : {
167 0 : ss << " tmp=";
168 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
169 0 : ss << ";\n";
170 0 : ss << " if (isNan(tmp))\n";
171 0 : ss << " arg"<<i<<"= 0;\n";
172 0 : ss << " else\n";
173 0 : ss << " arg"<<i<<"=tmp;\n";
174 0 : ss << " }\n";
175 : }
176 : else
177 : {
178 0 : ss<<" arg"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
179 0 : ss<<";\n";
180 : }
181 : }
182 0 : ss<<" if(arg1==0)\n";
183 0 : ss<<" return arg1;\n";
184 0 : ss<<" tmp=arg1 * round(arg0 * pow(arg1,-1));\n";
185 0 : ss<<" return tmp;\n";
186 0 : ss<<"}";
187 0 : }
188 0 : void OpCosh::GenSlidingWindowFunction(std::stringstream &ss,
189 : const std::string &sSymName, SubArguments &vSubArguments)
190 : {
191 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
192 : const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const
193 0 : formula::SingleVectorRefToken *>(tmpCur);
194 0 : ss << "\ndouble " << sSymName;
195 0 : ss << "_"<< BinFuncName() <<"(";
196 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
197 : {
198 0 : if (i)
199 0 : ss << ",";
200 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
201 : }
202 0 : ss << ")\n{\n";
203 0 : ss <<" int gid0=get_global_id(0);\n";
204 0 : ss << " double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
205 0 : ss << ";\n";
206 0 : ss<< " if(isNan(arg0)||(gid0>=";
207 0 : ss<<tmpCurDVR->GetArrayLength();
208 0 : ss<<"))\n";
209 0 : ss<<" arg0 = 0;\n";
210 0 : ss << " double tmp=local_cosh(arg0);\n";
211 0 : ss << " return tmp;\n";
212 0 : ss << "}";
213 0 : }
214 :
215 0 : void OpCot::GenSlidingWindowFunction(std::stringstream &ss,
216 : const std::string &sSymName, SubArguments &vSubArguments)
217 : {
218 0 : ss << "\ndouble " << sSymName;
219 0 : ss << "_"<< BinFuncName() <<"(";
220 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
221 : {
222 0 : if (i)
223 0 : ss << ",";
224 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
225 : }
226 0 : ss << ")\n";
227 0 : ss << "{\n";
228 0 : ss << " int gid0=get_global_id(0);\n";
229 0 : ss << " double arg0 = 0.0f;\n";
230 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
231 : assert(tmpCur);
232 0 : if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
233 : {
234 0 : if(tmpCur->GetType() == formula::svSingleVectorRef)
235 : {
236 : const formula::SingleVectorRefToken*tmpCurDVR=
237 : static_cast
238 0 : <const formula::SingleVectorRefToken *>(tmpCur);
239 0 : ss << " arg0 = ";
240 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
241 0 : ss << ";\n";
242 0 : ss << " if(isNan(";
243 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
244 0 : ss << ")||(gid0>=";
245 0 : ss << tmpCurDVR->GetArrayLength();
246 0 : ss << "))\n";
247 0 : ss << " { arg0 = 0.0f; }\n";
248 : }
249 0 : else if(tmpCur->GetType() == formula::svDouble)
250 : {
251 0 : ss << " arg0=";
252 0 : ss << tmpCur->GetDouble() << ";\n";
253 : }
254 : }
255 : else
256 : {
257 0 : ss << " arg0 = ";
258 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
259 0 : ss << ";\n";
260 : }
261 0 : ss << " arg0 = arg0 * M_1_PI;\n";
262 0 : ss << " return cospi(arg0) * pow(sinpi(arg0), -1);\n";
263 0 : ss << "}";
264 0 : }
265 :
266 0 : void OpCoth::BinInlineFun(std::set<std::string>& decls,
267 : std::set<std::string>& funs)
268 : {
269 0 : decls.insert(local_cothDecl);
270 0 : funs.insert(local_coth);
271 0 : }
272 :
273 0 : void OpCoth::GenSlidingWindowFunction(std::stringstream &ss,
274 : const std::string &sSymName, SubArguments &vSubArguments)
275 : {
276 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
277 : const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const
278 0 : formula::SingleVectorRefToken *>(tmpCur);
279 0 : ss << "\ndouble " << sSymName;
280 0 : ss << "_"<< BinFuncName() <<"(";
281 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
282 : {
283 0 : if (i)
284 0 : ss << ",";
285 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
286 : }
287 0 : ss << ")\n{\n";
288 0 : ss <<" int gid0=get_global_id(0);\n";
289 0 : ss << " double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
290 0 : ss << ";\n";
291 0 : ss<< " if(isNan(arg0)||(gid0>=";
292 0 : ss<<tmpCurDVR->GetArrayLength();
293 0 : ss<<"))\n";
294 0 : ss<<" arg0 = 0;\n";
295 0 : ss << " double tmp=local_coth(arg0);\n";
296 0 : ss << " return tmp;\n";
297 0 : ss << "}";
298 0 : }
299 :
300 0 : void OpCombinA::BinInlineFun(std::set<std::string>& decls,
301 : std::set<std::string>& funs)
302 : {
303 0 : decls.insert(bikDecl);
304 0 : funs.insert(bik);
305 0 : }
306 :
307 0 : void OpCombinA::GenSlidingWindowFunction(std::stringstream &ss,
308 : const std::string &sSymName, SubArguments &vSubArguments)
309 : {
310 0 : ss << "\ndouble " << sSymName;
311 0 : ss << "_"<< BinFuncName() <<"(";
312 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
313 : {
314 0 : if (i)
315 0 : ss << ",";
316 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
317 : }
318 0 : ss << ")\n{\n";
319 0 : ss << " int gid0 = get_global_id(0);\n";
320 0 : ss << " double tem;\n";
321 0 : ss << " double arg0,arg1;\n";
322 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
323 : {
324 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
325 : assert(pCur);
326 0 : ss << " arg"<<i<<" = "<<vSubArguments[i]->GenSlidingWindowDeclRef();
327 0 : ss << ";\n";
328 0 : if(pCur->GetType() == formula::svSingleVectorRef)
329 : {
330 : const formula::SingleVectorRefToken* pSVR =
331 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
332 0 : ss << " if(isNan(arg" << i <<")||(gid0 >= ";
333 0 : ss << pSVR->GetArrayLength();
334 0 : ss << "))\n";
335 0 : ss << " arg" << i << " = 0;\n";
336 : }
337 0 : else if (pCur->GetType() == formula::svDouble)
338 : {
339 0 : ss << " if(isNan(arg" << i <<"))\n";
340 0 : ss << " arg" << i << " = 0;\n";
341 : }
342 : }
343 0 : ss << " arg0 = trunc(arg0);\n";
344 0 : ss << " arg1 = trunc(arg1);\n";
345 0 : ss << " if(arg0 >= arg1 && arg0 > 0 && arg1 > 0)\n";
346 0 : ss << " tem = bik(arg0+arg1-1,arg1);\n";
347 0 : ss << " else if(arg0 == 0 && arg1 == 0)\n";
348 0 : ss << " tem = 0;\n";
349 0 : ss << " else if(arg0 > 0 && arg1 == 0)\n";
350 0 : ss << " tem = 1;\n";
351 0 : ss << " else\n";
352 0 : ss << " tem = -1;\n";
353 0 : ss << " double i = tem - trunc(tem);\n";
354 0 : ss << " if(i < 0.5)\n";
355 0 : ss << " tem = trunc(tem);\n";
356 0 : ss << " else\n";
357 0 : ss << " tem = trunc(tem) + 1;\n";
358 0 : ss << " return tem;\n";
359 0 : ss << "}";
360 0 : }
361 0 : void OpEven::GenSlidingWindowFunction(std::stringstream &ss,
362 : const std::string &sSymName, SubArguments &vSubArguments)
363 : {
364 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
365 : const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const
366 0 : formula::SingleVectorRefToken *>(tmpCur);
367 0 : ss << "\ndouble " << sSymName;
368 0 : ss << "_"<< BinFuncName() <<"(";
369 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
370 : {
371 0 : if (i)
372 0 : ss << ",";
373 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
374 : }
375 0 : ss << ")\n{\n";
376 0 : ss <<" int gid0=get_global_id(0);\n";
377 0 : ss << " double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
378 0 : ss << ";\n";
379 0 : ss<< " if(isNan(arg0)||(gid0>=";
380 0 : ss<<tmpCurDVR->GetArrayLength();
381 0 : ss<<"))\n";
382 0 : ss<<" arg0 = 0;\n";
383 0 : ss << " double tmp;\n";
384 0 : ss << " tmp = fabs(arg0 / 2);\n";
385 0 : ss << " if ( trunc(tmp) == tmp )\n";
386 0 : ss << " tmp = tmp * 2;\n";
387 0 : ss << " else\n";
388 0 : ss << " tmp = (trunc(tmp) + 1) * 2;\n";
389 0 : ss << " if (arg0 < 0)\n";
390 0 : ss << " tmp = tmp * -1.0;\n";
391 0 : ss << " return tmp;\n";
392 0 : ss << "}";
393 0 : }
394 :
395 0 : void OpMod::GenSlidingWindowFunction(std::stringstream &ss,
396 : const std::string &sSymName, SubArguments &vSubArguments)
397 : {
398 0 : ss << "\ndouble " << sSymName;
399 0 : ss << "_"<< BinFuncName() <<"(";
400 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
401 : {
402 0 : if (i)
403 0 : ss << ",";
404 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
405 : }
406 0 : ss << ")\n{\n";
407 0 : ss <<" int gid0=get_global_id(0);\n";
408 0 : ss << " double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
409 0 : ss << ";\n";
410 0 : ss << " double arg1 =" << vSubArguments[1]->GenSlidingWindowDeclRef();
411 0 : ss << ";\n";
412 0 : ss << " if(isNan(arg0)||arg0 == 0)\n";
413 0 : ss << " return 0;\n";
414 0 : ss << " if(isNan(arg1) || arg1 ==0)\n";
415 0 : ss << " return NAN;\n";
416 0 : ss << " double tem;\n";
417 0 : ss << " if(arg0 < 0 && arg1 > 0)\n";
418 0 : ss << " while(arg0 < 0)\n";
419 0 : ss << " arg0 += arg1;\n";
420 0 : ss << " else if (arg0 > 0 && arg1 < 0)\n";
421 0 : ss << " while(arg0 > 0)\n";
422 0 : ss << " arg0 += arg1;\n";
423 0 : ss << " tem = fmod(arg0,arg1);\n";
424 0 : ss << " if(arg1 < 0 && tem > 0)\n";
425 0 : ss << " tem = -tem;\n";
426 0 : ss << " return tem;\n";
427 0 : ss << "}";
428 0 : }
429 0 : void OpLog::GenSlidingWindowFunction(std::stringstream &ss,
430 : const std::string &sSymName, SubArguments &vSubArguments)
431 : {
432 0 : ss << "\ndouble " << sSymName;
433 0 : ss << "_"<< BinFuncName() <<"(";
434 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
435 : {
436 0 : if (i)
437 0 : ss << ",";
438 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
439 : }
440 0 : ss << ")\n{\n";
441 0 : ss << " int gid0 = get_global_id(0);\n";
442 0 : ss << " double tem;\n";
443 0 : ss << " double arg0,arg1;\n";
444 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
445 : {
446 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
447 : assert(pCur);
448 0 : ss << " arg"<<i<<" = "<<vSubArguments[i]->GenSlidingWindowDeclRef();
449 0 : ss << ";\n";
450 0 : if(pCur->GetType() == formula::svSingleVectorRef)
451 : {
452 : const formula::SingleVectorRefToken* pSVR =
453 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
454 0 : ss << " if(isNan(arg" << i <<")||(gid0 >= ";
455 0 : ss << pSVR->GetArrayLength();
456 0 : ss << "))\n";
457 0 : if( i == 0)
458 0 : ss << " arg0 = 0;\n";
459 0 : else if ( i == 1)
460 0 : ss << " arg1 = 10;\n";
461 : }
462 0 : else if (pCur->GetType() == formula::svDouble)
463 : {
464 0 : ss << " if(isNan(arg" << i <<"))\n";
465 0 : if( i == 0)
466 0 : ss << " arg0 = 0;\n";
467 0 : else if ( i == 1)
468 0 : ss << " arg1 = 10;\n";
469 : }
470 : }
471 0 : if (vSubArguments.size() < 2)
472 0 : ss << " arg1 = 10;\n";
473 0 : ss << " tem = log10(arg0)/log10(arg1);;\n";
474 0 : ss << " return tem;\n";
475 0 : ss << "}";
476 0 : }
477 0 : void OpCsc::GenSlidingWindowFunction(
478 : std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
479 : {
480 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
481 : const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const
482 0 : formula::SingleVectorRefToken *>(tmpCur);
483 0 : ss << "\ndouble " << sSymName;
484 0 : ss << "_"<< BinFuncName() <<"(";
485 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
486 : {
487 0 : if (i)
488 0 : ss << ",";
489 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
490 : }
491 0 : ss << ")\n{\n\t";
492 0 : ss <<"int gid0=get_global_id(0);\n\t";
493 0 : ss << "double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
494 0 : ss << ";\n\t";
495 0 : ss<< "if(isNan(arg0)||(gid0>=";
496 0 : ss<<tmpCurDVR->GetArrayLength();
497 0 : ss<<"))\n\t\t";
498 0 : ss<<"arg0 = 0;\n\t";
499 0 : ss << "double tmp=1/sin(arg0);\n\t";
500 0 : ss << "return tmp;\n";
501 0 : ss << "}";
502 0 : }
503 0 : void OpCountIfs::GenSlidingWindowFunction(std::stringstream &ss,
504 : const std::string &sSymName, SubArguments &vSubArguments)
505 : {
506 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
507 : const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
508 0 : formula::DoubleVectorRefToken *>(tmpCur);
509 0 : size_t nCurWindowSize = pCurDVR->GetArrayLength() <
510 0 : pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
511 0 : pCurDVR->GetRefRowSize() ;
512 0 : ss << "\ndouble " << sSymName;
513 0 : ss << "_"<< BinFuncName() <<"(";
514 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
515 : {
516 0 : if (i)
517 0 : ss << ",";
518 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
519 : }
520 0 : ss << ")\n {\n";
521 0 : ss <<" int gid0=get_global_id(0);\n";
522 0 : ss << " int tmp =0;\n";
523 0 : ss << " int loop;\n";
524 0 : GenTmpVariables(ss,vSubArguments);
525 :
526 0 : ss<< " int singleIndex =gid0;\n";
527 0 : int m=0;
528 :
529 0 : std::stringstream tmpss;
530 :
531 0 : for(size_t j=0;j<vSubArguments.size();j+=2,m++)
532 : {
533 0 : CheckSubArgumentIsNan(tmpss,vSubArguments,j);
534 0 : CheckSubArgumentIsNan(ss,vSubArguments,j+1);
535 0 : tmpss <<" if(isequal(";
536 0 : tmpss <<"tmp";
537 0 : tmpss <<j;
538 0 : tmpss <<" , ";
539 0 : tmpss << "tmp";
540 0 : tmpss << j+1;
541 0 : tmpss << ")){\n";
542 : }
543 0 : tmpss << " tmp ++;\n";
544 0 : for(size_t j=0;j<vSubArguments.size();j+=2,m--)
545 : {
546 0 : for(int n = 0;n<m+1;n++)
547 : {
548 0 : tmpss << " ";
549 : }
550 0 : tmpss<< "}\n";
551 : }
552 0 : UnrollDoubleVector(ss,tmpss,pCurDVR,nCurWindowSize);
553 :
554 0 : ss << "return tmp;\n";
555 0 : ss << "}";
556 0 : }
557 0 : void OpSumIfs::GenSlidingWindowFunction(std::stringstream &ss,
558 : const std::string &sSymName, SubArguments &vSubArguments)
559 : {
560 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
561 : const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
562 0 : formula::DoubleVectorRefToken *>(tmpCur);
563 0 : size_t nCurWindowSize = pCurDVR->GetArrayLength() <
564 0 : pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
565 0 : pCurDVR->GetRefRowSize() ;
566 :
567 0 : mNeedReductionKernel = vSubArguments[0]->NeedParallelReduction();
568 0 : if (mNeedReductionKernel)
569 : {
570 : // generate reduction functions
571 :
572 0 : ss << "__kernel void ";
573 0 : ss << vSubArguments[0]->GetName();
574 0 : ss << "_SumIfs_reduction( ";
575 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
576 : {
577 0 : if (i)
578 0 : ss << ",";
579 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
580 : }
581 0 : ss << ", __global double *result,int arrayLength,int windowSize";
582 :
583 0 : ss << ")\n{\n";
584 0 : ss << " double tmp =0;\n";
585 0 : ss << " int i ;\n";
586 :
587 0 : GenTmpVariables(ss,vSubArguments);
588 0 : ss << " double current_result = 0.0;\n";
589 0 : ss << " int writePos = get_group_id(1);\n";
590 0 : if (pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed())
591 0 : ss << " int offset = 0;\n";
592 0 : else if (!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
593 0 : ss << " int offset = get_group_id(1);\n";
594 : else
595 0 : throw Unhandled();
596 : // actually unreachable
597 0 : ss << " int lidx = get_local_id(0);\n";
598 0 : ss << " __local double shm_buf[256];\n";
599 0 : ss << " barrier(CLK_LOCAL_MEM_FENCE);\n";
600 0 : ss << " int loop = arrayLength/512 + 1;\n";
601 0 : ss << " for (int l=0; l<loop; l++){\n";
602 0 : ss << " tmp = 0.0;\n";
603 0 : ss << " int loopOffset = l*512;\n";
604 :
605 0 : ss << " int p1 = loopOffset + lidx + offset, p2 = p1 + 256;\n";
606 0 : ss << " if (p2 < min(offset + windowSize, arrayLength)) {\n";
607 0 : ss << " tmp0 = 0.0;\n";
608 0 : int mm=0;
609 0 : std::string p1 = "p1";
610 0 : std::string p2 = "p2";
611 0 : for(size_t j=1;j<vSubArguments.size();j+=2,mm++)
612 : {
613 0 : CheckSubArgumentIsNan2(ss,vSubArguments,j,p1);
614 0 : CheckSubArgumentIsNan2(ss,vSubArguments,j+1,p1);
615 0 : ss << "";
616 0 : ss <<" if(isequal(";
617 0 : ss <<"tmp";
618 0 : ss <<j;
619 0 : ss <<" , ";
620 0 : ss << "tmp";
621 0 : ss << j+1;
622 0 : ss << "))";
623 0 : ss << "{\n";
624 : }
625 0 : CheckSubArgumentIsNan2(ss,vSubArguments,0,p1);
626 0 : ss << " tmp += tmp0;\n";
627 0 : for(size_t j=1;j<vSubArguments.size();j+=2,mm--)
628 : {
629 0 : for(int n = 0;n<mm+1;n++)
630 : {
631 0 : ss << " ";
632 : }
633 0 : ss<< "}\n\n";
634 : }
635 0 : mm=0;
636 0 : for(size_t j=1;j<vSubArguments.size();j+=2,mm++)
637 : {
638 0 : CheckSubArgumentIsNan2(ss,vSubArguments,j,p2);
639 0 : CheckSubArgumentIsNan2(ss,vSubArguments,j+1,p2);
640 0 : ss <<" if(isequal(";
641 0 : ss <<"tmp";
642 0 : ss <<j;
643 0 : ss <<" , ";
644 0 : ss << "tmp";
645 0 : ss << j+1;
646 0 : ss << ")){\n";
647 : }
648 0 : CheckSubArgumentIsNan2(ss,vSubArguments,0,p2);
649 0 : ss << " tmp += tmp0;\n";
650 0 : for(size_t j=1;j< vSubArguments.size();j+=2,mm--)
651 : {
652 0 : for(int n = 0;n<mm+1;n++)
653 : {
654 0 : ss << " ";
655 : }
656 0 : ss<< "}\n";
657 : }
658 0 : ss << " }\n";
659 :
660 0 : ss << " else if (p1 < min(arrayLength, offset + windowSize)) {\n";
661 0 : mm=0;
662 0 : for(size_t j=1;j<vSubArguments.size();j+=2,mm++)
663 : {
664 0 : CheckSubArgumentIsNan2(ss,vSubArguments,j,p1);
665 0 : CheckSubArgumentIsNan2(ss,vSubArguments,j+1,p1);
666 :
667 0 : ss <<" if(isequal(";
668 0 : ss <<"tmp";
669 0 : ss <<j;
670 0 : ss <<" , ";
671 0 : ss << "tmp";
672 0 : ss << j+1;
673 0 : ss << ")){\n";
674 : }
675 0 : CheckSubArgumentIsNan2(ss,vSubArguments,0,p1);
676 0 : ss << " tmp += tmp0;\n";
677 0 : for(size_t j=1;j<vSubArguments.size();j+=2,mm--)
678 : {
679 0 : for(int n = 0;n<mm+1;n++)
680 : {
681 0 : ss << " ";
682 : }
683 0 : ss<< "}\n\n";
684 : }
685 :
686 0 : ss << " }\n";
687 0 : ss << " shm_buf[lidx] = tmp;\n";
688 0 : ss << " barrier(CLK_LOCAL_MEM_FENCE);\n";
689 0 : ss << " for (int i = 128; i >0; i/=2) {\n";
690 0 : ss << " if (lidx < i)\n";
691 0 : ss << " shm_buf[lidx] += shm_buf[lidx + i];\n";
692 0 : ss << " barrier(CLK_LOCAL_MEM_FENCE);\n";
693 0 : ss << " }\n";
694 0 : ss << " if (lidx == 0)\n";
695 0 : ss << " current_result += shm_buf[0];\n";
696 0 : ss << " barrier(CLK_LOCAL_MEM_FENCE);\n";
697 0 : ss << " }\n";
698 :
699 0 : ss << " if (lidx == 0)\n";
700 0 : ss << " result[writePos] = current_result;\n";
701 0 : ss << "}\n";
702 : }// finish generate reduction code
703 : // generate functions as usual
704 0 : ss << "\ndouble " << sSymName;
705 0 : ss << "_"<< BinFuncName() <<"(";
706 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
707 : {
708 0 : if (i)
709 0 : ss << ",";
710 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
711 : }
712 0 : ss << ")\n {\n";
713 0 : ss <<" int gid0=get_global_id(0);\n";
714 0 : ss << " double tmp =0;\n";
715 0 : if (!mNeedReductionKernel)
716 : {
717 0 : ss << " int i ;\n";
718 0 : GenTmpVariables(ss,vSubArguments);
719 0 : ss << " for (i = ";
720 0 : if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
721 0 : ss << "gid0; i < "<< nCurWindowSize <<"; i++)\n";
722 0 : } else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) {
723 0 : ss << "0; i < gid0+"<< nCurWindowSize <<"; i++)\n";
724 : } else {
725 0 : ss << "0; i < "<< nCurWindowSize <<"; i++)\n";
726 : }
727 0 : ss << " {\n";
728 0 : if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
729 : {
730 0 : ss<< " int doubleIndex =i+gid0;\n";
731 : }else
732 : {
733 0 : ss<< " int doubleIndex =i;\n";
734 : }
735 0 : ss<< " int singleIndex =gid0;\n";
736 0 : int m=0;
737 0 : for(size_t j=1;j<vSubArguments.size();j+=2,m++)
738 : {
739 0 : CheckSubArgumentIsNan(ss,vSubArguments,j);
740 0 : CheckSubArgumentIsNan(ss,vSubArguments,j+1);
741 0 : ss <<" if(isequal(";
742 0 : ss <<"tmp";
743 0 : ss <<j;
744 0 : ss <<" , ";
745 0 : ss << "tmp";
746 0 : ss << j+1;
747 0 : ss << ")){\n";
748 : }
749 0 : CheckSubArgumentIsNan(ss,vSubArguments,0);
750 0 : ss << " tmp += tmp0;\n";
751 0 : for(size_t j=1;j<=vSubArguments.size();j+=2,m--)
752 : {
753 0 : for(int n = 0;n<m+1;n++)
754 : {
755 0 : ss << " ";
756 : }
757 0 : ss<< "}\n";
758 : }
759 : }
760 0 : if (mNeedReductionKernel)
761 : {
762 0 : ss << "tmp =";
763 0 : vSubArguments[0]->GenDeclRef(ss);
764 0 : ss << "[gid0];\n";
765 : }
766 0 : ss << "return tmp;\n";
767 0 : ss << "}";
768 0 : }
769 0 : void OpCscH::GenSlidingWindowFunction(
770 : std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
771 : {
772 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
773 : const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const
774 0 : formula::SingleVectorRefToken *>(tmpCur);
775 0 : ss << "\ndouble " << sSymName;
776 0 : ss << "_"<< BinFuncName() <<"(";
777 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
778 : {
779 0 : if (i)
780 0 : ss << ",";
781 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
782 : }
783 0 : ss << ")\n{\n\t";
784 0 : ss <<"int gid0=get_global_id(0);\n\t";
785 0 : ss << "double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
786 0 : ss << ";\n\t";
787 0 : ss<< "if(isNan(arg0)||(gid0>=";
788 0 : ss<<tmpCurDVR->GetArrayLength();
789 0 : ss<<"))\n\t\t";
790 0 : ss<<"arg0 = 0;\n\t";
791 0 : ss << "double tmp=1/sinh(arg0);\n\t";
792 0 : ss << "return tmp;\n";
793 0 : ss << "}";
794 0 : }
795 0 : void OpExp::GenSlidingWindowFunction(std::stringstream &ss,
796 : const std::string &sSymName, SubArguments &vSubArguments)
797 : {
798 0 : ss << "\ndouble " << sSymName;
799 0 : ss << "_"<< BinFuncName() <<"(";
800 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
801 : {
802 0 : if (i) ss << ",";
803 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
804 : }
805 0 : ss << ")\n";
806 0 : ss << "{\n";
807 0 : ss << " int gid0=get_global_id(0);\n";
808 0 : ss << " double arg0 = 0.0f;\n";
809 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
810 : assert(tmpCur);
811 0 : if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
812 : {
813 0 : if(tmpCur->GetType() == formula::svSingleVectorRef)
814 : {
815 : const formula::SingleVectorRefToken*tmpCurDVR=
816 : static_cast
817 0 : <const formula::SingleVectorRefToken *>(tmpCur);
818 0 : ss << " arg0 = ";
819 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
820 0 : ss << ";\n";
821 0 : ss << " if(isNan(";
822 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
823 0 : ss << ")||(gid0>=";
824 0 : ss << tmpCurDVR->GetArrayLength();
825 0 : ss << "))\n";
826 0 : ss << " { arg0 = 0.0f; }\n";
827 : }
828 0 : else if(tmpCur->GetType() == formula::svDouble)
829 : {
830 0 : ss << " arg0=" << tmpCur->GetDouble() << ";\n";
831 : }
832 : }
833 : else
834 : {
835 0 : ss << " arg0 = ";
836 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
837 0 : ss << ";\n";
838 : }
839 0 : ss << " return pow(M_E, arg0);\n";
840 0 : ss << "}";
841 0 : }
842 :
843 0 : void OpAverageIfs::GenSlidingWindowFunction(std::stringstream &ss,
844 : const std::string &sSymName, SubArguments &vSubArguments)
845 : {
846 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
847 : const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
848 0 : formula::DoubleVectorRefToken *>(tmpCur);
849 0 : size_t nCurWindowSize = pCurDVR->GetArrayLength() <
850 0 : pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
851 0 : pCurDVR->GetRefRowSize() ;
852 0 : ss << "\ndouble " << sSymName;
853 0 : ss << "_"<< BinFuncName() <<"(";
854 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
855 : {
856 0 : if (i)
857 0 : ss << ",";
858 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
859 : }
860 0 : ss << ")\n {\n";
861 0 : ss <<" int gid0=get_global_id(0);\n";
862 0 : ss << " double tmp =0;\n";
863 0 : ss << " int count=0;\n";
864 0 : ss << " int loop;";
865 0 : GenTmpVariables(ss,vSubArguments);
866 0 : ss<< " int singleIndex =gid0;\n";
867 0 : int m=0;
868 0 : std::stringstream tmpss;
869 0 : for(size_t j=1;j<vSubArguments.size();j+=2,m++)
870 : {
871 0 : CheckSubArgumentIsNan(tmpss,vSubArguments,j);
872 0 : CheckSubArgumentIsNan(ss,vSubArguments,j+1);
873 0 : tmpss <<" if(isequal(";
874 0 : tmpss <<"tmp";
875 0 : tmpss <<j;
876 0 : tmpss <<" , ";
877 0 : tmpss << "tmp";
878 0 : tmpss << j+1;
879 0 : tmpss << ")){\n";
880 : }
881 0 : CheckSubArgumentIsNan(tmpss,vSubArguments,0);
882 0 : tmpss << " tmp += tmp0;\n";
883 0 : tmpss << " count++;\n";
884 0 : for(size_t j=1;j<vSubArguments.size();j+=2,m--)
885 : {
886 0 : for(int n = 0;n<m+1;n++)
887 : {
888 0 : tmpss << " ";
889 : }
890 0 : tmpss<< "}\n";
891 : }
892 :
893 0 : UnrollDoubleVector(ss,tmpss,pCurDVR,nCurWindowSize);
894 :
895 0 : ss << " if(count!=0)\n";
896 0 : ss << " tmp=tmp/count;\n";
897 0 : ss << " else\n";
898 0 : ss << " tmp= 0 ;\n";
899 0 : ss << "return tmp;\n";
900 0 : ss << "}";
901 0 : }
902 :
903 0 : void OpLog10::GenSlidingWindowFunction(std::stringstream &ss,
904 : const std::string &sSymName, SubArguments &vSubArguments)
905 : {
906 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
907 : const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const
908 0 : formula::SingleVectorRefToken *>(tmpCur);
909 0 : ss << "\ndouble " << sSymName;
910 0 : ss << "_"<< BinFuncName() <<"(";
911 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
912 : {
913 0 : if (i)
914 0 : ss << ",";
915 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
916 : }
917 0 : ss << ")\n{\n\t";
918 0 : ss <<"int gid0=get_global_id(0);\n\t";
919 0 : ss << "double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
920 0 : ss << ";\n\t";
921 0 : ss<< "if(isNan(arg0)||(gid0>=";
922 0 : ss<<tmpCurDVR->GetArrayLength();
923 0 : ss<<"))\n\t\t";
924 0 : ss<<"arg0 = 0;\n\t";
925 0 : ss << "double tmp=log10(arg0);\n\t";
926 0 : ss << "return tmp;\n";
927 0 : ss << "}";
928 0 : }
929 :
930 0 : void OpSinh::GenSlidingWindowFunction(std::stringstream &ss,
931 : const std::string &sSymName, SubArguments &vSubArguments)
932 : {
933 0 : ss << "\ndouble " << sSymName;
934 0 : ss << "_"<< BinFuncName() <<"(";
935 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
936 : {
937 0 : if (i)
938 0 : ss << ",";
939 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
940 : }
941 0 : ss <<") {\n";
942 0 : ss <<" int gid0=get_global_id(0);\n";
943 0 : ss <<" double arg0 = " <<
944 0 : vSubArguments[0]->GenSlidingWindowDeclRef();
945 0 : ss <<";\n";
946 0 : ss<< " if(isNan(arg0))\n";
947 0 : ss<<" arg0 = 0;\n";
948 0 : ss << " double tmp=( exp(arg0)-exp(-arg0) )/2;\n";
949 0 : ss << " return tmp;\n";
950 0 : ss << "}";
951 0 : }
952 0 : void OpSin::GenSlidingWindowFunction(std::stringstream &ss,
953 : const std::string &sSymName, SubArguments &vSubArguments)
954 : {
955 0 : ss << "\ndouble " << sSymName;
956 0 : ss << "_"<< BinFuncName() <<"(";
957 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
958 : {
959 0 : if (i) ss << ",";
960 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
961 : }
962 0 : ss << ")\n";
963 0 : ss << "{\n";
964 0 : ss << " int gid0=get_global_id(0);\n";
965 0 : ss << " double arg0 = 0.0f;\n";
966 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
967 : assert(tmpCur);
968 0 : if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
969 : {
970 0 : if(tmpCur->GetType() == formula::svSingleVectorRef)
971 : {
972 : const formula::SingleVectorRefToken*tmpCurDVR=
973 : static_cast
974 0 : <const formula::SingleVectorRefToken *>(tmpCur);
975 0 : ss << " arg0 = ";
976 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
977 0 : ss << ";\n";
978 0 : ss << " if(isNan(";
979 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
980 0 : ss << ")||(gid0>=";
981 0 : ss << tmpCurDVR->GetArrayLength();
982 0 : ss << "))\n";
983 0 : ss << " { arg0 = 0.0f; }\n";
984 : }
985 0 : else if(tmpCur->GetType() == formula::svDouble)
986 : {
987 0 : ss << " arg0=" << tmpCur->GetDouble() << ";\n";
988 : }
989 : }
990 : else
991 : {
992 0 : ss << " arg0 = ";
993 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
994 0 : ss << ";\n";
995 : }
996 0 : ss << " arg0 = arg0 * M_1_PI;\n";
997 0 : ss << " return sinpi(arg0);\n";
998 0 : ss << "}";
999 0 : }
1000 :
1001 0 : void OpAbs::GenSlidingWindowFunction(std::stringstream &ss,
1002 : const std::string &sSymName, SubArguments &vSubArguments)
1003 : {
1004 0 : ss << "\ndouble " << sSymName;
1005 0 : ss << "_"<< BinFuncName() <<"(";
1006 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1007 : {
1008 0 : if (i)
1009 0 : ss << ",";
1010 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1011 : }
1012 0 : ss << ") {\n";
1013 0 : ss << " int gid0 = get_global_id(0);\n";
1014 0 : ss << " double tmp = " << GetBottom() << ";\n";
1015 0 : FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
1016 : const formula::SingleVectorRefToken*tmpCurDVR0=
1017 0 : static_cast<const formula::SingleVectorRefToken *>(tmpCur0);
1018 0 : ss << " int buffer_len = ";
1019 0 : ss << tmpCurDVR0->GetArrayLength();
1020 0 : ss << ";\n";
1021 0 : ss << " if((gid0)>=buffer_len || isNan(";
1022 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1023 0 : ss << "))\n";
1024 0 : ss << " tmp = " << GetBottom() << ";\n else \n";
1025 0 : ss << " tmp = ";
1026 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1027 0 : ss << ";\n";
1028 0 : ss << " return fabs(tmp);\n";
1029 0 : ss << "}";
1030 0 : }
1031 0 : void OpArcCos::BinInlineFun(std::set<std::string>& decls,
1032 : std::set<std::string>& funs)
1033 : {
1034 0 : decls.insert(atan2Decl);
1035 0 : funs.insert(atan2Content);
1036 0 : }
1037 0 : void OpArcCos::GenSlidingWindowFunction(std::stringstream &ss,
1038 : const std::string &sSymName, SubArguments &vSubArguments)
1039 : {
1040 0 : ss << "\ndouble " << sSymName;
1041 0 : ss << "_"<< BinFuncName() <<"(";
1042 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1043 : {
1044 0 : if (i) ss << ",";
1045 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1046 : }
1047 0 : ss << ") {\n";
1048 0 : ss << " int gid0 = get_global_id(0);\n";
1049 0 : ss << " double tmp = " << GetBottom() << ";\n";
1050 0 : FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
1051 : const formula::SingleVectorRefToken*tmpCurDVR0=
1052 0 : static_cast<const formula::SingleVectorRefToken *>(tmpCur0);
1053 0 : ss << " int buffer_len = "<< tmpCurDVR0->GetArrayLength()<< ";\n";
1054 0 : ss << " if((gid0)>=buffer_len || isNan(";
1055 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef()<< "))\n";
1056 0 : ss << " tmp = " << GetBottom() << ";\n";
1057 0 : ss << " else \n ";
1058 0 : ss << " tmp = ";
1059 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef()<< ";\n";
1060 0 : ss << " return arctan2(sqrt(1.0 - pow(tmp, 2)), tmp);\n";
1061 0 : ss << "}";
1062 0 : }
1063 0 : void OpArcCosHyp::GenSlidingWindowFunction(std::stringstream &ss,
1064 : const std::string &sSymName, SubArguments &vSubArguments)
1065 : {
1066 0 : ss << "\ndouble " << sSymName;
1067 0 : ss << "_"<< BinFuncName() <<"(";
1068 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1069 : {
1070 0 : if (i) ss << ",";
1071 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1072 : }
1073 0 : ss << ") {\n";
1074 0 : ss << " int gid0 = get_global_id(0);\n";
1075 0 : ss << " double tmp = " << GetBottom() << ";\n";
1076 0 : FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
1077 : assert(tmpCur0);
1078 0 : if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
1079 : {
1080 0 : if(tmpCur0->GetType() == formula::svSingleVectorRef)
1081 : {
1082 : const formula::SingleVectorRefToken*tmpCurDVR0=
1083 0 : static_cast<const formula::SingleVectorRefToken *>(tmpCur0);
1084 0 : ss << " int buffer_len = "<<tmpCurDVR0->GetArrayLength()<<";\n";
1085 0 : ss << " if((gid0)>=buffer_len || isNan(";
1086 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
1087 0 : ss << " tmp = " << GetBottom() << ";\n";
1088 0 : ss << " else \n ";
1089 0 : ss << " tmp = " << vSubArguments[0]->GenSlidingWindowDeclRef();
1090 0 : ss << ";\n";
1091 : }
1092 0 : else if(tmpCur0->GetType() == formula::svDouble)
1093 : {
1094 0 : ss << " tmp = " << tmpCur0->GetDouble() << ";\n";
1095 : }
1096 : }
1097 : else
1098 : {
1099 0 : ss << " tmp = " << vSubArguments[0]->GenSlidingWindowDeclRef();
1100 0 : ss << ";\n";
1101 : }
1102 :
1103 0 : ss << " return log( tmp + pow( (pown(tmp, 2) - 1.0), 0.5));\n";
1104 0 : ss << "}";
1105 0 : }
1106 0 : void OpTan::GenSlidingWindowFunction(std::stringstream &ss,
1107 : const std::string &sSymName, SubArguments &vSubArguments)
1108 : {
1109 0 : ss << "\ndouble " << sSymName;
1110 0 : ss << "_"<< BinFuncName() <<"(";
1111 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1112 : {
1113 0 : if (i) ss << ",";
1114 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1115 : }
1116 0 : ss << ")\n";
1117 0 : ss << "{\n";
1118 0 : ss << " int gid0=get_global_id(0);\n";
1119 0 : ss << " double arg0 = 0.0f;\n";
1120 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
1121 : assert(tmpCur);
1122 0 : if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
1123 : {
1124 0 : if(tmpCur->GetType() == formula::svSingleVectorRef)
1125 : {
1126 : const formula::SingleVectorRefToken*tmpCurDVR=
1127 : static_cast
1128 0 : <const formula::SingleVectorRefToken *>(tmpCur);
1129 0 : ss << " arg0 = ";
1130 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1131 0 : ss << ";\n";
1132 0 : ss << " if(isNan(";
1133 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1134 0 : ss << ")||(gid0>=";
1135 0 : ss << tmpCurDVR->GetArrayLength();
1136 0 : ss << "))\n";
1137 0 : ss << " { arg0 = 0.0f; }\n";
1138 : }
1139 0 : else if(tmpCur->GetType() == formula::svDouble)
1140 : {
1141 0 : ss << " arg0=" << tmpCur->GetDouble() << ";\n";
1142 : }
1143 : }
1144 : else
1145 : {
1146 0 : ss << " arg0 = ";
1147 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1148 0 : ss << ";\n";
1149 : }
1150 0 : ss << " arg0 = arg0 * M_1_PI;\n";
1151 0 : ss << " return sinpi(arg0) * pow(cospi(arg0), -1);\n";
1152 0 : ss << "}";
1153 0 : }
1154 0 : void OpTanH::GenSlidingWindowFunction(std::stringstream &ss,
1155 : const std::string &sSymName, SubArguments &vSubArguments)
1156 : {
1157 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
1158 : const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const
1159 0 : formula::SingleVectorRefToken *>(tmpCur);
1160 0 : ss << "\ndouble " << sSymName;
1161 0 : ss << "_"<< BinFuncName() <<"(";
1162 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1163 : {
1164 0 : if (i)
1165 0 : ss << ",";
1166 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1167 : }
1168 0 : ss << ")\n";
1169 0 : ss << "{\n";
1170 0 : ss << " int gid0=get_global_id(0);\n";
1171 0 : ss << " double arg0 = "<< vSubArguments[0]->GenSlidingWindowDeclRef();
1172 0 : ss << ";\n";
1173 0 : ss << " if(isNan(arg0)||(gid0>=";
1174 0 : ss << tmpCurDVR->GetArrayLength();
1175 0 : ss << "))\n";
1176 0 : ss << " arg0 = 0;\n";
1177 0 : ss << " double tmp=tanh(arg0);\n";
1178 0 : ss << " return tmp;\n";
1179 0 : ss << "}";
1180 0 : }
1181 0 : void OpPower::GenSlidingWindowFunction(std::stringstream &ss,
1182 : const std::string &sSymName, SubArguments &vSubArguments)
1183 : {
1184 0 : ss << "\ndouble " << sSymName;
1185 0 : ss << "_"<< BinFuncName() <<"(";
1186 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1187 : {
1188 0 : if (i)
1189 0 : ss << ",";
1190 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1191 : }
1192 0 : ss << ")\n";
1193 0 : ss << "{\n";
1194 0 : ss << " int gid0=get_global_id(0);\n";
1195 0 : ss << " double arg[2];\n";
1196 0 : for( size_t i=0; i < vSubArguments.size(); ++i)
1197 : {
1198 0 : FormulaToken *tmpCur = vSubArguments[i]->GetFormulaToken();
1199 : assert(tmpCur);
1200 0 : if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
1201 : {
1202 0 : if(tmpCur->GetType() == formula::svDoubleVectorRef)
1203 : {
1204 : const formula::DoubleVectorRefToken* tmpCurDVR =
1205 : static_cast<
1206 0 : const formula::DoubleVectorRefToken *>(tmpCur);
1207 0 : ss << " int i = 0;\n";
1208 0 : ss << " arg["<<i<<"] = ";
1209 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
1210 0 : ss << ";\n";
1211 0 : ss << " if(isNan(arg["<<i;
1212 0 : ss << "])||(gid0>=";
1213 0 : ss << tmpCurDVR->GetArrayLength();
1214 0 : ss << "))\n";
1215 0 : ss << " arg["<<i;
1216 0 : ss << "] = 0;\n";
1217 : }
1218 0 : else if(tmpCur->GetType() == formula::svSingleVectorRef)
1219 : {
1220 : const formula::SingleVectorRefToken* tmpCurDVR=
1221 : static_cast<
1222 0 : const formula::SingleVectorRefToken *>(tmpCur);
1223 0 : ss << " arg["<<i<<"] = ";
1224 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
1225 0 : ss << ";\n";
1226 0 : ss << " if(isNan(arg["<<i;
1227 0 : ss << "])||(gid0>=";
1228 0 : ss << tmpCurDVR->GetArrayLength();
1229 0 : ss << "))\n";
1230 0 : ss << " arg["<<i;
1231 0 : ss << "] = 0;\n";
1232 : }
1233 0 : else if(tmpCur->GetType() == formula::svDouble)
1234 : {
1235 0 : ss << " arg["<<i<<"] = ";
1236 0 : ss << tmpCur->GetDouble() << ";\n";
1237 : }
1238 : }
1239 : else
1240 : {
1241 0 : ss << " arg["<<i<<"] = ";
1242 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
1243 0 : ss << ";\n";
1244 : }
1245 : }
1246 0 : ss << " return pow(arg[0],arg[1]);\n";
1247 0 : ss << "}";
1248 0 : }
1249 0 : void OpSqrt::GenSlidingWindowFunction(std::stringstream &ss,
1250 : const std::string &sSymName, SubArguments &vSubArguments)
1251 : {
1252 0 : ss << "\ndouble " << sSymName;
1253 0 : ss << "_"<< BinFuncName() <<"(";
1254 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1255 : {
1256 0 : if (i)
1257 0 : ss << ",";
1258 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1259 : }
1260 0 : ss << ")\n";
1261 0 : ss << "{\n";
1262 0 : ss << " int gid0=get_global_id(0);\n";
1263 0 : ss << " double arg0 = 0.0f;\n";
1264 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
1265 : assert(tmpCur);
1266 0 : if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
1267 : {
1268 0 : if(tmpCur->GetType() == formula::svSingleVectorRef)
1269 : {
1270 : const formula::SingleVectorRefToken*tmpCurDVR=
1271 : static_cast
1272 0 : <const formula::SingleVectorRefToken *>(tmpCur);
1273 0 : ss << " arg0 = ";
1274 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1275 0 : ss << ";\n";
1276 0 : ss << " if(isNan(";
1277 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1278 0 : ss << ")||(gid0>=";
1279 0 : ss << tmpCurDVR->GetArrayLength();
1280 0 : ss << "))\n";
1281 0 : ss << " { arg0 = 0; }\n";
1282 : }
1283 0 : else if(tmpCur->GetType() == formula::svDouble)
1284 : {
1285 0 : ss << " arg0=";
1286 0 : ss << tmpCur->GetDouble() << ";\n";
1287 : }
1288 : }
1289 : else
1290 : {
1291 0 : ss << " arg0 = ";
1292 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1293 0 : ss << ";\n";
1294 : }
1295 0 : ss << " return sqrt(arg0);\n";
1296 0 : ss << "}";
1297 0 : }
1298 0 : void OpArcCot::GenSlidingWindowFunction(std::stringstream &ss,
1299 : const std::string &sSymName, SubArguments &vSubArguments)
1300 : {
1301 0 : ss << "\ndouble " << sSymName;
1302 0 : ss << "_"<< BinFuncName() <<"(";
1303 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1304 : {
1305 0 : if (i) ss << ",";
1306 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1307 : }
1308 0 : ss << ") {\n";
1309 0 : ss << " int gid0 = get_global_id(0);\n";
1310 0 : ss << " double tmp = " << GetBottom() << ";\n";
1311 0 : FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
1312 : const formula::SingleVectorRefToken*tmpCurDVR0=
1313 0 : static_cast<const formula::SingleVectorRefToken *>(tmpCur0);
1314 0 : ss << " int buffer_len = " << tmpCurDVR0->GetArrayLength()<< ";\n";
1315 0 : ss << " if((gid0)>=buffer_len || isNan(";
1316 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
1317 0 : ss << " tmp = " << GetBottom() << ";\n";
1318 0 : ss << " else \n ";
1319 0 : ss << " tmp = " << vSubArguments[0]->GenSlidingWindowDeclRef() <<";\n";
1320 0 : ss << " return M_PI_2 - atan(tmp);\n";
1321 0 : ss << "}";
1322 0 : }
1323 0 : void OpArcCotHyp::GenSlidingWindowFunction(std::stringstream &ss,
1324 : const std::string &sSymName, SubArguments &vSubArguments)
1325 : {
1326 0 : ss << "\ndouble " << sSymName;
1327 0 : ss << "_"<< BinFuncName() <<"(";
1328 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1329 : {
1330 0 : if (i) ss << ",";
1331 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1332 : }
1333 0 : ss << ")\n";
1334 0 : ss << "{\n";
1335 0 : ss << " int gid0=get_global_id(0);\n";
1336 0 : ss << " double arg0 = 0.0f;\n";
1337 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
1338 : assert(tmpCur);
1339 0 : if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
1340 : {
1341 0 : if(tmpCur->GetType() == formula::svSingleVectorRef)
1342 : {
1343 : const formula::SingleVectorRefToken*tmpCurDVR=
1344 : static_cast
1345 0 : <const formula::SingleVectorRefToken *>(tmpCur);
1346 0 : ss << " arg0 = ";
1347 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1348 0 : ss << ";\n";
1349 0 : ss << " if(isNan(";
1350 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1351 0 : ss << ")||(gid0>=";
1352 0 : ss << tmpCurDVR->GetArrayLength();
1353 0 : ss << "))\n";
1354 0 : ss << " { arg0 = 0.0f; }\n";
1355 : }
1356 0 : else if(tmpCur->GetType() == formula::svDouble)
1357 : {
1358 0 : ss << " arg0=";
1359 0 : ss << tmpCur->GetDouble() << ";\n";
1360 : }
1361 : }
1362 : else
1363 : {
1364 0 : ss << " arg0 = ";
1365 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1366 0 : ss << ";\n";
1367 : }
1368 0 : ss << " return 0.5 * log(1 + 2 * pown(arg0 - 1.0, -1));\n";
1369 0 : ss << "}";
1370 0 : }
1371 0 : void OpArcSin::BinInlineFun(std::set<std::string>& decls,
1372 : std::set<std::string>& funs)
1373 : {
1374 0 : decls.insert(atan2Decl);
1375 0 : funs.insert(atan2Content);
1376 0 : }
1377 0 : void OpArcSin::GenSlidingWindowFunction(std::stringstream &ss,
1378 : const std::string &sSymName, SubArguments &vSubArguments)
1379 : {
1380 0 : ss << "\ndouble " << sSymName;
1381 0 : ss << "_"<< BinFuncName() <<"(";
1382 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1383 : {
1384 0 : if (i) ss << ",";
1385 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1386 : }
1387 0 : ss << ") {\n";
1388 0 : ss << " int gid0 = get_global_id(0);\n";
1389 0 : ss << " double tmp = " << GetBottom() << ";\n";
1390 0 : FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
1391 : const formula::SingleVectorRefToken*tmpCurDVR0=
1392 0 : static_cast<const formula::SingleVectorRefToken *>(tmpCur0);
1393 0 : ss << " int buffer_len = " << tmpCurDVR0->GetArrayLength() << ";\n";
1394 0 : ss << " if((gid0)>=buffer_len || isNan(";
1395 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
1396 0 : ss << " tmp = " << GetBottom() << ";\n";
1397 0 : ss << " else \n ";
1398 0 : ss << " tmp = " << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
1399 0 : ss << " return arctan2(tmp, sqrt(1.0 - pow(tmp, 2)));\n";
1400 0 : ss << "}";
1401 0 : }
1402 0 : void OpArcSinHyp::GenSlidingWindowFunction(std::stringstream &ss,
1403 : const std::string &sSymName, SubArguments &vSubArguments)
1404 : {
1405 0 : ss << "\ndouble " << sSymName;
1406 0 : ss << "_"<< BinFuncName() <<"(";
1407 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1408 : {
1409 0 : if (i) ss << ",";
1410 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1411 : }
1412 0 : ss << ") {\n";
1413 0 : ss << " int gid0 = get_global_id(0);\n";
1414 0 : ss << " double tmp = " << GetBottom() << ";\n";
1415 0 : FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
1416 : assert(tmpCur0);
1417 0 : if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
1418 : {
1419 0 : if(tmpCur0->GetType() == formula::svSingleVectorRef)
1420 : {
1421 : const formula::SingleVectorRefToken*tmpCurDVR0=
1422 0 : static_cast<const formula::SingleVectorRefToken *>(tmpCur0);
1423 0 : ss << " int buffer_len = "<<tmpCurDVR0->GetArrayLength()<<";\n";
1424 0 : ss << " if((gid0)>=buffer_len || isNan(";
1425 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
1426 0 : ss << " tmp = " << GetBottom() << ";\n";
1427 0 : ss << " else \n ";
1428 0 : ss << " tmp = " << vSubArguments[0]->GenSlidingWindowDeclRef();
1429 0 : ss << ";\n";
1430 : }
1431 0 : else if(tmpCur0->GetType() == formula::svDouble)
1432 : {
1433 0 : ss << " tmp = " << tmpCur0->GetDouble() << ";\n";
1434 : }
1435 : }
1436 : else
1437 : {
1438 0 : ss << " tmp = " << vSubArguments[0]->GenSlidingWindowDeclRef();
1439 0 : ss << ";\n";
1440 : }
1441 0 : ss << " return log( tmp + pow((pown(tmp, 2) + 1.0), 0.5));\n";
1442 0 : ss << "}";
1443 0 : }
1444 0 : void OpArcTan2::BinInlineFun(std::set<std::string>& decls,
1445 : std::set<std::string>& funs)
1446 : {
1447 0 : decls.insert(atan2Decl);
1448 0 : funs.insert(atan2Content);
1449 0 : }
1450 0 : void OpArcTan2::GenSlidingWindowFunction(std::stringstream &ss,
1451 : const std::string &sSymName, SubArguments &vSubArguments)
1452 : {
1453 0 : ss << "\ndouble " << sSymName;
1454 0 : ss << "_"<< BinFuncName() <<"(";
1455 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1456 : {
1457 0 : if (i) ss << ",";
1458 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1459 : }
1460 0 : ss << ") {\n";
1461 0 : ss << " int gid0 = get_global_id(0);\n";
1462 0 : ss << " double x_num = " << GetBottom() << ";\n";
1463 0 : ss << " double y_num = " << GetBottom() << ";\n";
1464 0 : FormulaToken *iXNum = vSubArguments[0]->GetFormulaToken();
1465 : const formula::SingleVectorRefToken*tmpCurDVRX=
1466 0 : static_cast<const formula::SingleVectorRefToken *>(iXNum);
1467 0 : FormulaToken *iYNum = vSubArguments[1]->GetFormulaToken();
1468 : const formula::SingleVectorRefToken*tmpCurDVRY=
1469 0 : static_cast<const formula::SingleVectorRefToken *>(iYNum);
1470 0 : ss << " int buffer_x_len = " << tmpCurDVRX->GetArrayLength() << ";\n";
1471 0 : ss << " int buffer_y_len = " << tmpCurDVRY->GetArrayLength() << ";\n";
1472 0 : ss << " if((gid0)>=buffer_x_len || isNan(";
1473 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
1474 0 : ss << " x_num = " << GetBottom() << ";\n";
1475 0 : ss << " else \n ";
1476 0 : ss << " x_num = "<< vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
1477 0 : ss << " if((gid0)>=buffer_y_len || isNan(";
1478 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << "))\n";
1479 0 : ss << " y_num = " << GetBottom() << ";\n";
1480 0 : ss << " else \n ";
1481 0 : ss << " y_num = "<< vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
1482 0 : ss << " return arctan2(y_num, x_num);\n";
1483 0 : ss << "}";
1484 0 : }
1485 0 : void OpArcTan::GenSlidingWindowFunction(std::stringstream &ss,
1486 : const std::string &sSymName, SubArguments &vSubArguments)
1487 : {
1488 0 : ss << "\ndouble " << sSymName;
1489 0 : ss << "_"<< BinFuncName() <<"(";
1490 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1491 : {
1492 0 : if (i) ss << ",";
1493 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1494 : }
1495 0 : ss << ")\n";
1496 0 : ss << "{\n";
1497 0 : ss << " int gid0=get_global_id(0);\n";
1498 0 : ss << " double arg0 = 0.0f;\n";
1499 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
1500 : assert(tmpCur);
1501 0 : if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
1502 : {
1503 0 : if(tmpCur->GetType() == formula::svSingleVectorRef)
1504 : {
1505 : const formula::SingleVectorRefToken*tmpCurDVR=
1506 : static_cast
1507 0 : <const formula::SingleVectorRefToken *>(tmpCur);
1508 0 : ss << " arg0 = ";
1509 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1510 0 : ss << ";\n";
1511 0 : ss << " if(isNan(";
1512 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1513 0 : ss << ")||(gid0>=";
1514 0 : ss << tmpCurDVR->GetArrayLength();
1515 0 : ss << "))\n";
1516 0 : ss << " { arg0 = 0.0f; }\n";
1517 : }
1518 0 : else if(tmpCur->GetType() == formula::svDouble)
1519 : {
1520 0 : ss << " arg0=" << tmpCur->GetDouble() << ";\n";
1521 : }
1522 : }
1523 : else
1524 : {
1525 0 : ss << " arg0 = ";
1526 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1527 0 : ss << ";\n";
1528 : }
1529 0 : ss << " return atan(arg0);\n";
1530 0 : ss << "}";
1531 0 : }
1532 0 : void OpArcTanH::GenSlidingWindowFunction(std::stringstream &ss,
1533 : const std::string &sSymName, SubArguments &vSubArguments)
1534 : {
1535 0 : ss << "\ndouble " << sSymName;
1536 0 : ss << "_"<< BinFuncName() <<"(";
1537 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1538 : {
1539 0 : if (i) ss << ",";
1540 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1541 : }
1542 0 : ss << ") {\n";
1543 0 : ss << " int gid0 = get_global_id(0);\n";
1544 0 : ss << " double tmp = " << GetBottom() << ";\n";
1545 0 : FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
1546 : const formula::SingleVectorRefToken*tmpCurDVR0=
1547 0 : static_cast<const formula::SingleVectorRefToken *>(tmpCur0);
1548 0 : ss << " int buffer_len = " << tmpCurDVR0->GetArrayLength() << ";\n";
1549 0 : ss << " if((gid0)>=buffer_len || isNan(";
1550 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
1551 0 : ss << " tmp = " << GetBottom() << ";\n";
1552 0 : ss << " else \n ";
1553 0 : ss << " tmp = " << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
1554 0 : ss << " double a = 1.0 + tmp;\n";
1555 0 : ss << " double b = 1.0 - tmp;\n";
1556 0 : ss << " return log(pow(a/b, 0.5));\n";
1557 0 : ss << "}";
1558 0 : }
1559 0 : void OpBitAnd::GenSlidingWindowFunction(std::stringstream &ss,
1560 : const std::string &sSymName, SubArguments &vSubArguments)
1561 : {
1562 0 : ss << "\ndouble " << sSymName;
1563 0 : ss << "_"<< BinFuncName() <<"(";
1564 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1565 : {
1566 0 : if (i) ss << ",";
1567 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1568 : }
1569 0 : ss << ") {\n";
1570 0 : ss << " int gid0 = get_global_id(0);\n";
1571 0 : ss << " double num1 = " << GetBottom() << ";\n";
1572 0 : ss << " double num2 = " << GetBottom() << ";\n";
1573 0 : FormulaToken *iNum1 = vSubArguments[0]->GetFormulaToken();
1574 : const formula::SingleVectorRefToken* tmpCurDVRNum1=
1575 0 : static_cast<const formula::SingleVectorRefToken *>(iNum1);
1576 0 : FormulaToken *iNum2 = vSubArguments[1]->GetFormulaToken();
1577 : const formula::SingleVectorRefToken* tmpCurDVRNum2=
1578 0 : static_cast<const formula::SingleVectorRefToken *>(iNum2);
1579 0 : ss << " int buffer_num1_len = "<<tmpCurDVRNum1->GetArrayLength()<<";\n";
1580 0 : ss << " int buffer_num2_len = "<<tmpCurDVRNum2->GetArrayLength()<<";\n";
1581 0 : ss << " if((gid0)>=buffer_num1_len || isNan(";
1582 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
1583 0 : ss << " num1 = " << GetBottom() << ";\n";
1584 0 : ss << " else \n ";
1585 0 : ss << " num1 = " << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
1586 0 : ss << " if((gid0)>=buffer_num2_len || isNan(";
1587 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << "))\n";
1588 0 : ss << " num2 = " << GetBottom() << ";\n";
1589 0 : ss << " else \n ";
1590 0 : ss << " num2 = " << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
1591 0 : ss << " return (long)num1 & (long)num2;\n";
1592 0 : ss << "}";
1593 0 : }
1594 0 : void OpLn::GenSlidingWindowFunction(
1595 : std::stringstream &ss, const std::string &sSymName, SubArguments &vSubArguments)
1596 : {
1597 0 : ss << "\ndouble " << sSymName;
1598 0 : ss << "_"<< BinFuncName() <<"(";
1599 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1600 : {
1601 0 : if (i)
1602 0 : ss << ",";
1603 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1604 : }
1605 0 : ss << ")\n{\n";
1606 0 : ss << " int gid0=get_global_id(0);\n";
1607 0 : ss << " int singleIndex = gid0;\n";
1608 :
1609 0 : GenTmpVariables(ss,vSubArguments);
1610 0 : CheckAllSubArgumentIsNan(ss,vSubArguments);
1611 :
1612 0 : ss << " double tmp=log1p(tmp0-1);\n";
1613 0 : ss << " return tmp;\n";
1614 0 : ss << "}";
1615 0 : }
1616 :
1617 0 : void OpRound::GenSlidingWindowFunction(std::stringstream &ss,
1618 : const std::string &sSymName, SubArguments &vSubArguments)
1619 : {
1620 0 : ss << "\ndouble " << sSymName;
1621 0 : ss << "_"<< BinFuncName() <<"(";
1622 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1623 : {
1624 0 : if (i)
1625 0 : ss << ",";
1626 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1627 : }
1628 0 : ss << ")\n{\n";
1629 0 : ss << " int gid0=get_global_id(0);\n";
1630 0 : ss << " int singleIndex = gid0;\n";
1631 0 : GenTmpVariables(ss,vSubArguments);
1632 0 : CheckAllSubArgumentIsNan(ss,vSubArguments);
1633 0 : if(vSubArguments.size() ==2)
1634 : {
1635 0 : ss << " for(int i=0;i<tmp1;i++)\n";
1636 0 : ss << " tmp0 = tmp0 * 10;\n";
1637 : }
1638 0 : ss << " double tmp=round(tmp0);\n";
1639 0 : if(vSubArguments.size() ==2)
1640 : {
1641 0 : ss << " for(int i=0;i<tmp1;i++)\n";
1642 0 : ss << " tmp = tmp / 10;\n";
1643 : }
1644 0 : ss << " return tmp;\n";
1645 0 : ss << "}";
1646 0 : }
1647 0 : void OpRoundUp::GenSlidingWindowFunction(std::stringstream &ss,
1648 : const std::string &sSymName, SubArguments &vSubArguments)
1649 : {
1650 0 : ss << "\ndouble " << sSymName;
1651 0 : ss << "_"<< BinFuncName() <<"(";
1652 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1653 : {
1654 0 : if (i)
1655 0 : ss << ",";
1656 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1657 : }
1658 0 : ss << ")\n{\n";
1659 0 : ss << " int gid0=get_global_id(0);\n";
1660 0 : ss << " int singleIndex = gid0;\n";
1661 0 : ss << " int intTmp;\n";
1662 0 : ss << " double doubleTmp;\n";
1663 0 : ss << " double tmp;\n";
1664 0 : GenTmpVariables(ss,vSubArguments);
1665 0 : CheckAllSubArgumentIsNan(ss,vSubArguments);
1666 0 : ss << " if(tmp1 >20 || tmp1 < -20)";
1667 0 : ss << " {\n";
1668 0 : ss << " tmp = NAN;\n";
1669 0 : ss << " }else\n";
1670 0 : ss << " {\n";
1671 0 : ss << " for(int i=0;i<tmp1;i++)\n";
1672 0 : ss << " tmp0 = tmp0 * 10;\n";
1673 0 : ss << " intTmp = (int)tmp0;\n";
1674 0 : ss << " doubleTmp = intTmp;\n";
1675 0 : ss << " if(isequal(doubleTmp,tmp0))\n";
1676 0 : ss << " tmp = doubleTmp;\n";
1677 0 : ss << " else\n";
1678 0 : ss << " tmp = doubleTmp + 1;\n";
1679 0 : ss << " for(int i=0;i<tmp1;i++)\n";
1680 0 : ss << " tmp = tmp / 10;\n";
1681 0 : ss << " }\n";
1682 0 : ss << " return tmp;\n";
1683 0 : ss << "}";
1684 0 : }
1685 0 : void OpRoundDown::GenSlidingWindowFunction(std::stringstream &ss,
1686 : const std::string &sSymName, SubArguments &vSubArguments)
1687 : {
1688 0 : ss << "\ndouble " << sSymName;
1689 0 : ss << "_"<< BinFuncName() <<"(";
1690 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1691 : {
1692 0 : if (i)
1693 0 : ss << ",";
1694 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1695 : }
1696 0 : ss << ")\n{\n";
1697 0 : ss << " int gid0=get_global_id(0);\n";
1698 0 : ss << " int singleIndex = gid0;\n";
1699 0 : ss << " int intTmp;\n";
1700 0 : ss << " double tmp;\n";
1701 0 : GenTmpVariables(ss,vSubArguments);
1702 0 : CheckAllSubArgumentIsNan(ss,vSubArguments);
1703 0 : ss << " if(tmp1 >20 || tmp1 < -20)";
1704 0 : ss << " {\n";
1705 0 : ss << " tmp = NAN;\n";
1706 0 : ss << " }else\n";
1707 0 : ss << " {\n";
1708 0 : ss << " for(int i=0;i<tmp1;i++)\n";
1709 0 : ss << " tmp0 = tmp0 * 10;\n";
1710 0 : ss << " intTmp = (int)tmp0;\n";
1711 0 : ss << " tmp = intTmp;\n";
1712 0 : ss << " for(int i=0;i<tmp1;i++)\n";
1713 0 : ss << " tmp = tmp / 10;\n";
1714 0 : ss << " }\n";
1715 0 : ss << " return tmp;\n";
1716 0 : ss << "}";
1717 0 : }
1718 0 : void OpInt::GenSlidingWindowFunction(std::stringstream &ss,
1719 : const std::string &sSymName, SubArguments &vSubArguments)
1720 : {
1721 0 : ss << "\ndouble " << sSymName;
1722 0 : ss << "_"<< BinFuncName() <<"(";
1723 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1724 : {
1725 0 : if (i)
1726 0 : ss << ",";
1727 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1728 : }
1729 0 : ss << ")\n{\n";
1730 0 : ss << " int gid0=get_global_id(0);\n";
1731 0 : ss << " int singleIndex = gid0;\n";
1732 0 : ss << " int intTmp;\n";
1733 0 : ss << " double tmp;\n";
1734 0 : GenTmpVariables(ss,vSubArguments);
1735 0 : CheckAllSubArgumentIsNan(ss,vSubArguments);
1736 0 : ss << " intTmp = (int)tmp0;\n";
1737 0 : ss << " tmp = intTmp;\n";
1738 0 : ss << " return tmp;\n";
1739 0 : ss << "}";
1740 0 : }
1741 0 : void OpNegSub::GenSlidingWindowFunction(std::stringstream &ss,
1742 : const std::string &sSymName, SubArguments &vSubArguments)
1743 : {
1744 0 : ss << "\ndouble " << sSymName;
1745 0 : ss << "_"<< BinFuncName() <<"(";
1746 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1747 : {
1748 0 : if (i)
1749 0 : ss << ",";
1750 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1751 : }
1752 0 : ss << ")\n{\n";
1753 0 : ss << " int gid0=get_global_id(0);\n";
1754 0 : ss << " int singleIndex = gid0;\n";
1755 0 : GenTmpVariables(ss,vSubArguments);
1756 0 : CheckAllSubArgumentIsNan(ss,vSubArguments);
1757 0 : ss << " return -tmp0;\n";
1758 0 : ss << "}";
1759 0 : }
1760 :
1761 0 : void OpRadians::GenSlidingWindowFunction(std::stringstream &ss,
1762 : const std::string &sSymName, SubArguments &vSubArguments)
1763 : {
1764 0 : ss << "\ndouble " << sSymName;
1765 0 : ss << "_"<< BinFuncName() <<"(";
1766 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1767 : {
1768 0 : if (i)
1769 0 : ss << ",";
1770 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1771 : }
1772 0 : ss << ")\n{\n";
1773 0 : ss << " int gid0=get_global_id(0);\n";
1774 0 : ss << " int singleIndex = gid0;\n";
1775 0 : ss << " double tmp;\n";
1776 0 : GenTmpVariables(ss,vSubArguments);
1777 0 : CheckAllSubArgumentIsNan(ss,vSubArguments);
1778 0 : ss << " tmp = tmp0 * 3.14159265358979 * pow(180.0,-1);\n";
1779 0 : ss << " return tmp;\n";
1780 0 : ss << "}";
1781 0 : }
1782 0 : void OpIsEven::GenSlidingWindowFunction(std::stringstream &ss,
1783 : const std::string &sSymName, SubArguments &vSubArguments)
1784 : {
1785 0 : ss << "\ndouble " << sSymName;
1786 0 : ss << "_"<< BinFuncName() <<"(";
1787 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1788 : {
1789 0 : if (i)
1790 0 : ss << ",";
1791 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1792 : }
1793 0 : ss << ")\n{\n";
1794 0 : ss << " int gid0=get_global_id(0);\n";
1795 0 : ss << " int singleIndex = gid0;\n";
1796 0 : ss << " double tmp;\n";
1797 0 : GenTmpVariables(ss,vSubArguments);
1798 0 : CheckAllSubArgumentIsNan(ss,vSubArguments);
1799 0 : ss << " tmp = (fmod(floor(fabs(tmp0)), 2.0)<0.5);\n";
1800 0 : ss << " return tmp;\n";
1801 0 : ss << "}";
1802 0 : }
1803 0 : void OpIsOdd::GenSlidingWindowFunction(std::stringstream &ss,
1804 : const std::string &sSymName, SubArguments &vSubArguments)
1805 : {
1806 0 : ss << "\ndouble " << sSymName;
1807 0 : ss << "_"<< BinFuncName() <<"(";
1808 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1809 : {
1810 0 : if (i)
1811 0 : ss << ",";
1812 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1813 : }
1814 0 : ss << ")\n{\n";
1815 0 : ss << " int gid0=get_global_id(0);\n";
1816 0 : ss << " int singleIndex = gid0;\n";
1817 0 : ss << " double tmp;\n";
1818 0 : GenTmpVariables(ss,vSubArguments);
1819 0 : CheckAllSubArgumentIsNan(ss,vSubArguments);
1820 0 : ss << " tmp = !(fmod(floor(fabs(tmp0)), 2.0)<0.5);\n";
1821 0 : ss << " return tmp;\n";
1822 0 : ss << "}";
1823 0 : }
1824 0 : void OpOdd::GenSlidingWindowFunction(
1825 : std::stringstream &ss, const std::string &sSymName,
1826 : SubArguments &vSubArguments)
1827 : {
1828 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
1829 : const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const
1830 0 : formula::SingleVectorRefToken *>(tmpCur);
1831 0 : ss << Math_Intg_Str;
1832 0 : ss << "\ndouble " << sSymName;
1833 0 : ss << "_"<< BinFuncName() <<"(";
1834 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1835 : {
1836 0 : if (i)
1837 0 : ss << ",";
1838 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1839 : }
1840 0 : ss << ")\n{\n";
1841 0 : ss <<" int gid0=get_global_id(0);\n";
1842 0 : ss << " double tmp=0;\n";
1843 0 : ss << " double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
1844 0 : ss << ";\n";
1845 0 : ss<< " if(isNan(arg0)||(gid0>=";
1846 0 : ss<<tmpCurDVR->GetArrayLength();
1847 0 : ss<<"))\n";
1848 0 : ss<<" arg0 = 0;\n";
1849 0 : ss << " if (arg0 > 0.0 ){\n";
1850 0 : ss << " tmp=Intg(arg0);\n";
1851 0 : ss << " if(tmp-trunc(tmp/2)*2 == 0)\n";
1852 0 : ss << " tmp=tmp+1;\n";
1853 0 : ss << " }else if (arg0 < 0.0 ){\n";
1854 0 : ss << " tmp=Intg(arg0);\n";
1855 0 : ss << " if(tmp-trunc(tmp/2)*2 == 0)\n";
1856 0 : ss << " tmp=tmp-1.0;\n";
1857 0 : ss << " }else if (arg0 == 0.0 )\n";
1858 0 : ss << " tmp=1.0;\n";
1859 0 : ss << " return tmp;\n";
1860 0 : ss << "}";
1861 0 : }
1862 0 : void OpCountIf::GenSlidingWindowFunction(std::stringstream &ss,
1863 : const std::string &sSymName, SubArguments &vSubArguments)
1864 : {
1865 0 : ss << "\ndouble " << sSymName;
1866 0 : ss << "_"<< BinFuncName() <<"(";
1867 0 : for (unsigned i = 0; i < 2; i++)
1868 : {
1869 0 : if (i)
1870 0 : ss << ",";
1871 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1872 : }
1873 0 : ss << ")\n";
1874 0 : ss << "{\n";
1875 0 : ss << " int gid0=get_global_id(0);\n";
1876 0 : ss << " double vara, varb;\n";
1877 0 : ss << " int varc = 0;\n";
1878 0 : FormulaToken *tmpCur = vSubArguments[1]->GetFormulaToken();
1879 : assert(tmpCur);
1880 0 : if(ocPush == vSubArguments[1]->GetFormulaToken()->GetOpCode())
1881 : {
1882 0 : if(tmpCur->GetType() == formula::svSingleVectorRef)
1883 : {
1884 : const formula::SingleVectorRefToken* tmpCurDVR=
1885 : static_cast<
1886 0 : const formula::SingleVectorRefToken *>(tmpCur);
1887 0 : ss << " varb = ";
1888 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef();
1889 0 : ss << ";\n";
1890 0 : ss << " if(isNan(varb)||(gid0>=";
1891 0 : ss << tmpCurDVR->GetArrayLength();
1892 0 : ss << "))\n";
1893 0 : ss << " varb = 0;\n";
1894 : }
1895 0 : else if(tmpCur->GetType() == formula::svDouble)
1896 : {
1897 0 : ss << " varb = ";
1898 0 : ss << tmpCur->GetDouble() << ";\n";
1899 : }
1900 : }
1901 : else
1902 : {
1903 0 : ss << " varb = ";
1904 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef();
1905 0 : ss << ";\n";
1906 : }
1907 0 : tmpCur = vSubArguments[0]->GetFormulaToken();
1908 : assert(tmpCur);
1909 0 : if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
1910 : {
1911 : //TODO DoubleVector
1912 0 : if (tmpCur->GetType() == formula::svDoubleVectorRef)
1913 : {
1914 : const formula::DoubleVectorRefToken* pDVR =
1915 0 : static_cast<const formula::DoubleVectorRefToken *>(tmpCur);
1916 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
1917 0 : ss << " for (int i = ";
1918 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
1919 : {
1920 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
1921 0 : ss << " && i < " << nCurWindowSize << "; ++i)\n";
1922 0 : ss << " {\n";
1923 : }
1924 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
1925 : {
1926 0 : ss << "0; i < " << pDVR->GetArrayLength();
1927 0 : ss << " && i < gid0+"<< nCurWindowSize << "; ++i)\n";
1928 0 : ss << " {\n";
1929 : }
1930 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
1931 : {
1932 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
1933 0 : ss << " && i < "<< nCurWindowSize << "; ++i)\n";
1934 0 : ss << " {\n";
1935 : }
1936 : else
1937 : {
1938 0 : ss << "0; i < "<< nCurWindowSize << "; ++i)\n";
1939 0 : ss << " {\n";
1940 : }
1941 0 : ss << " vara = ";
1942 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1943 0 : ss << ";\n";
1944 0 : ss << " if (isNan(vara))\n";
1945 0 : ss << " continue;\n";
1946 0 : ss << " (vara == varb) && varc++;\n";
1947 0 : ss << " }\n";
1948 : }
1949 0 : else if(tmpCur->GetType() == formula::svSingleVectorRef)
1950 : {
1951 : const formula::SingleVectorRefToken* tmpCurDVR=
1952 : static_cast<
1953 0 : const formula::SingleVectorRefToken *>(tmpCur);
1954 0 : ss << " vara = ";
1955 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
1956 0 : ss << ";\n";
1957 0 : ss << " if(isNan(vara)||(gid0>=";
1958 0 : ss << tmpCurDVR->GetArrayLength();
1959 0 : ss << "))\n";
1960 0 : ss << " return 0;\n";
1961 0 : ss << " (vara == varb) && varc++;\n";
1962 : }
1963 : }
1964 0 : ss << " return varc;\n";
1965 0 : ss << "}";
1966 0 : }
1967 0 : void OpSumIf::GenSlidingWindowFunction(std::stringstream &ss,
1968 : const std::string &sSymName, SubArguments &vSubArguments)
1969 : {
1970 0 : ss << "\ndouble " << sSymName;
1971 0 : ss << "_"<< BinFuncName() <<"(";
1972 0 : int flag = 3 == vSubArguments.size() ? 2 : 0;
1973 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
1974 : {
1975 0 : if (i)
1976 0 : ss << ",";
1977 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
1978 : }
1979 0 : ss << ")\n";
1980 0 : ss << "{\n";
1981 0 : ss << " int gid0=get_global_id(0);\n";
1982 0 : ss << " double vara, varb, varc, sum = 0.0f;\n";
1983 0 : FormulaToken *tmpCur = vSubArguments[1]->GetFormulaToken();
1984 : assert(tmpCur);
1985 0 : if(ocPush == vSubArguments[1]->GetFormulaToken()->GetOpCode())
1986 : {
1987 0 : if(tmpCur->GetType() == formula::svSingleVectorRef)
1988 : {
1989 : const formula::SingleVectorRefToken* tmpCurDVR=
1990 : static_cast<
1991 0 : const formula::SingleVectorRefToken *>(tmpCur);
1992 0 : ss << " varb = ";
1993 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef();
1994 0 : ss << ";\n";
1995 0 : ss << " if(isNan(varb)||(gid0>=";
1996 0 : ss << tmpCurDVR->GetArrayLength();
1997 0 : ss << "))\n";
1998 0 : ss << " varb = 0;\n";
1999 : }
2000 0 : else if(tmpCur->GetType() == formula::svDouble)
2001 : {
2002 0 : ss << " varb = ";
2003 0 : ss << tmpCur->GetDouble() << ";\n";
2004 : }
2005 : }
2006 : else
2007 : {
2008 0 : ss << " varb = ";
2009 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef();
2010 0 : ss << ";\n";
2011 : }
2012 0 : tmpCur = vSubArguments[0]->GetFormulaToken();
2013 : assert(tmpCur);
2014 0 : if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
2015 : {
2016 : //TODO DoubleVector
2017 0 : if (tmpCur->GetType() == formula::svDoubleVectorRef)
2018 : {
2019 : const formula::DoubleVectorRefToken* pDVR =
2020 0 : static_cast<const formula::DoubleVectorRefToken *>(tmpCur);
2021 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
2022 0 : ss << " for (int i = ";
2023 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
2024 : {
2025 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
2026 0 : ss << " && i < " << nCurWindowSize << "; ++i)\n";
2027 0 : ss << " {\n";
2028 : }
2029 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
2030 : {
2031 0 : ss << "0; i < " << pDVR->GetArrayLength();
2032 0 : ss << " && i < gid0+"<< nCurWindowSize << "; ++i)\n";
2033 0 : ss << " {\n";
2034 : }
2035 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
2036 : {
2037 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
2038 0 : ss << " && i < "<< nCurWindowSize << "; ++i)\n";
2039 0 : ss << " {\n";
2040 : }
2041 : else
2042 : {
2043 0 : ss << "0; i < "<< nCurWindowSize << "; ++i)\n";
2044 0 : ss << " {\n";
2045 : }
2046 0 : ss << " vara = ";
2047 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
2048 0 : ss << ";\n";
2049 0 : ss << " if (isNan(vara))\n";
2050 0 : ss << " continue;\n";
2051 0 : ss << " varc = ";
2052 0 : ss << vSubArguments[flag]->GenSlidingWindowDeclRef();
2053 0 : ss << ";\n";
2054 0 : ss << " if (isNan(varc))\n";
2055 0 : ss << " varc = 0.0f;\n";
2056 0 : ss << " (vara == varb)&&(sum = sum + varc);\n";
2057 0 : ss << " }\n";
2058 : }
2059 0 : else if(tmpCur->GetType() == formula::svSingleVectorRef)
2060 : {
2061 : const formula::SingleVectorRefToken* tmpCurDVR=
2062 : static_cast<
2063 0 : const formula::SingleVectorRefToken *>(tmpCur);
2064 0 : ss << " vara = ";
2065 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
2066 0 : ss << ";\n";
2067 0 : ss << " if(isNan(vara)||(gid0>=";
2068 0 : ss << tmpCurDVR->GetArrayLength();
2069 0 : ss << "))\n";
2070 0 : ss << " return 0;\n";
2071 0 : ss << " int i = 0;\n";
2072 0 : ss << " varc = ";
2073 0 : ss << vSubArguments[flag]->GenSlidingWindowDeclRef();
2074 0 : ss << ";\n";
2075 0 : ss << " if(isNan(varc)||(gid0>=";
2076 0 : ss << tmpCurDVR->GetArrayLength();
2077 0 : ss << "))\n";
2078 0 : ss << " varc = 0.0f;\n";
2079 :
2080 0 : ss << " (vara == varb)&&(sum = sum + varc);\n";
2081 :
2082 : }
2083 : }
2084 0 : ss << " return sum;\n";
2085 0 : ss << "}";
2086 0 : }
2087 0 : void OpTrunc::GenSlidingWindowFunction(std::stringstream &ss,
2088 : const std::string &sSymName, SubArguments &vSubArguments)
2089 : {
2090 0 : ss << "\ndouble " << sSymName;
2091 0 : ss << "_"<< BinFuncName() <<"(";
2092 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
2093 : {
2094 0 : if (i)
2095 0 : ss << ",";
2096 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
2097 : }
2098 0 : ss << ")\n";
2099 0 : ss << "{\n";
2100 0 : ss << " int gid0=get_global_id(0);\n";
2101 0 : ss << " double arg[2];\n";
2102 0 : for( size_t i=0; i < vSubArguments.size(); ++i)
2103 : {
2104 0 : FormulaToken *tmpCur = vSubArguments[i]->GetFormulaToken();
2105 : assert(tmpCur);
2106 0 : if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
2107 : {
2108 0 : if(tmpCur->GetType() == formula::svDoubleVectorRef)
2109 : {
2110 : const formula::DoubleVectorRefToken* tmpCurDVR =
2111 : static_cast<
2112 0 : const formula::DoubleVectorRefToken *>(tmpCur);
2113 0 : ss << " int i = 0;\n";
2114 0 : ss << " arg["<<i<<"] = ";
2115 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
2116 0 : ss << ";\n";
2117 0 : ss << " if(isNan(arg["<<i;
2118 0 : ss << "])||(gid0>=";
2119 0 : ss << tmpCurDVR->GetArrayLength();
2120 0 : ss << "))\n";
2121 0 : ss << " arg["<<i;
2122 0 : ss << "] = 0;\n";
2123 : }
2124 0 : else if(tmpCur->GetType() == formula::svSingleVectorRef)
2125 : {
2126 : const formula::SingleVectorRefToken* tmpCurDVR=
2127 : static_cast<
2128 0 : const formula::SingleVectorRefToken *>(tmpCur);
2129 0 : ss << " arg["<<i<<"] = ";
2130 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
2131 0 : ss << ";\n";
2132 0 : ss << " if(isNan(arg["<<i;
2133 0 : ss << "])||(gid0>=";
2134 0 : ss << tmpCurDVR->GetArrayLength();
2135 0 : ss << "))\n";
2136 0 : ss << " arg["<<i;
2137 0 : ss << "] = 0;\n";
2138 : }
2139 0 : else if(tmpCur->GetType() == formula::svDouble)
2140 : {
2141 0 : ss << " arg["<<i<<"] = ";
2142 0 : ss << tmpCur->GetDouble() << ";\n";
2143 : }
2144 : }
2145 : else
2146 : {
2147 0 : ss << " arg["<<i<<"] = ";
2148 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
2149 0 : ss << ";\n";
2150 : }
2151 : }
2152 0 : ss << " double argm = arg[0];\n";
2153 0 : ss << " int n = (int)arg[1];\n";
2154 0 : ss << " double nn = 1.0f;\n";
2155 0 : ss << " for(int i = 0; i < n; ++i)\n";
2156 0 : ss << " {\n";
2157 0 : ss << " argm = argm * 10;\n";
2158 0 : ss << " nn = nn * 10;\n";
2159 0 : ss << " }\n";
2160 0 : ss << " modf(argm, &argm);\n";
2161 0 : ss << " return argm / nn;\n";
2162 0 : ss << "}";
2163 0 : }
2164 0 : void OpFloor::GenSlidingWindowFunction(
2165 : std::stringstream &ss, const std::string &sSymName,
2166 : SubArguments &vSubArguments)
2167 : {
2168 0 : ss << "\ndouble " << sSymName;
2169 0 : ss << "_"<< BinFuncName() <<"(";
2170 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
2171 : {
2172 0 : if (i)
2173 0 : ss << ",";
2174 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
2175 : }
2176 0 : ss << ")\n{\n";
2177 0 : ss << " int gid0=get_global_id(0);\n";
2178 0 : ss << " double arg0,arg1,arg2=0.0;\n";
2179 0 : ss << " arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
2180 0 : ss << ";\n";
2181 0 : ss << " arg1 = " << vSubArguments[1]->GenSlidingWindowDeclRef();
2182 0 : ss << ";\n";
2183 0 : if ( 3 == vSubArguments.size() )
2184 : {
2185 0 : ss << " arg2 = " << vSubArguments[2]->GenSlidingWindowDeclRef();
2186 0 : ss << ";\n";
2187 : }
2188 0 : ss << " if(isNan(arg0) || isNan(arg1))\n";
2189 0 : ss << " return 0;\n";
2190 0 : ss << " if(isNan(arg2))\n";
2191 0 : ss << " arg2 = 0.0;\n";
2192 0 : ss << " if(arg0*arg1<0)\n";
2193 0 : ss << " return NAN;\n";
2194 0 : ss << " else if(arg2==0.0&&arg0<0.0)\n";
2195 0 : ss << " return (trunc(arg0/arg1)+1)*arg1;\n";
2196 0 : ss << " else\n";
2197 0 : ss << " return trunc(arg0/arg1)*arg1;\n";
2198 0 : ss << "}\n";
2199 0 : }
2200 0 : void OpBitOr::GenSlidingWindowFunction(std::stringstream &ss,
2201 : const std::string &sSymName, SubArguments &vSubArguments)
2202 : {
2203 0 : ss << "\ndouble " << sSymName;
2204 0 : ss << "_"<< BinFuncName() <<"(";
2205 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
2206 : {
2207 0 : if (i) ss << ",";
2208 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
2209 : }
2210 0 : ss << ") {\n";
2211 0 : ss << " int gid0 = get_global_id(0);\n";
2212 0 : ss << " double num1 = " << GetBottom() << ";\n";
2213 0 : ss << " double num2 = " << GetBottom() << ";\n";
2214 0 : FormulaToken *iNum1 = vSubArguments[0]->GetFormulaToken();
2215 : const formula::SingleVectorRefToken* tmpCurDVRNum1=
2216 0 : static_cast<const formula::SingleVectorRefToken *>(iNum1);
2217 0 : FormulaToken *iNum2 = vSubArguments[1]->GetFormulaToken();
2218 : const formula::SingleVectorRefToken* tmpCurDVRNum2=
2219 0 : static_cast<const formula::SingleVectorRefToken *>(iNum2);
2220 0 : ss << " int buffer_num1_len = "<<tmpCurDVRNum1->GetArrayLength()<<";\n";
2221 0 : ss << " int buffer_num2_len = "<<tmpCurDVRNum2->GetArrayLength()<<";\n";
2222 0 : ss << " if((gid0)>=buffer_num1_len || isNan(";
2223 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
2224 0 : ss << " num1 = " << GetBottom() << ";\n";
2225 0 : ss << " else \n ";
2226 0 : ss << " num1 = floor(" << vSubArguments[0]->GenSlidingWindowDeclRef();
2227 0 : ss << ");\n";
2228 0 : ss << " if((gid0)>=buffer_num2_len || isNan(";
2229 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << "))\n";
2230 0 : ss << " num2 = " << GetBottom() << ";\n";
2231 0 : ss << " else\n ";
2232 0 : ss << " num2 = floor(" << vSubArguments[1]->GenSlidingWindowDeclRef();
2233 0 : ss << ");\n";
2234 0 : ss << " return (long)num1 | (long)num2;\n";
2235 0 : ss << "}";
2236 0 : }
2237 0 : void OpBitXor::GenSlidingWindowFunction(std::stringstream &ss,
2238 : const std::string &sSymName, SubArguments &vSubArguments)
2239 : {
2240 0 : ss << "\ndouble " << sSymName;
2241 0 : ss << "_"<< BinFuncName() <<"(";
2242 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
2243 : {
2244 0 : if (i) ss << ",";
2245 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
2246 : }
2247 0 : ss << ") {\n";
2248 0 : ss << " int gid0 = get_global_id(0);\n";
2249 0 : ss << " double num1 = " << GetBottom() << ";\n";
2250 0 : ss << " double num2 = " << GetBottom() << ";\n";
2251 0 : FormulaToken *iNum1 = vSubArguments[0]->GetFormulaToken();
2252 : const formula::SingleVectorRefToken* tmpCurDVRNum1=
2253 0 : static_cast<const formula::SingleVectorRefToken *>(iNum1);
2254 0 : FormulaToken *iNum2 = vSubArguments[1]->GetFormulaToken();
2255 : const formula::SingleVectorRefToken* tmpCurDVRNum2=
2256 0 : static_cast<const formula::SingleVectorRefToken *>(iNum2);
2257 0 : ss << " int buffer_num1_len = " << tmpCurDVRNum1->GetArrayLength() << ";\n";
2258 0 : ss << " int buffer_num2_len = " << tmpCurDVRNum2->GetArrayLength() << ";\n";
2259 :
2260 0 : ss << " if((gid0)>=buffer_num1_len || isNan(";
2261 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
2262 0 : ss << " num1 = " << GetBottom() << ";\n";
2263 0 : ss << " else\n ";
2264 0 : ss << " num1 = floor(" << vSubArguments[0]->GenSlidingWindowDeclRef();
2265 0 : ss << ");\n";
2266 0 : ss << " if((gid0)>=buffer_num2_len || isNan(";
2267 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << "))\n";
2268 0 : ss << " num2 = " << GetBottom() << ";\n";
2269 0 : ss << " else\n ";
2270 0 : ss << " num2 = floor(" << vSubArguments[1]->GenSlidingWindowDeclRef();
2271 0 : ss << ");\n";
2272 0 : ss << " return (long)num1 ^ (long)num2;\n";
2273 0 : ss << "}";
2274 0 : }
2275 0 : void OpBitLshift::GenSlidingWindowFunction(std::stringstream &ss,
2276 : const std::string &sSymName, SubArguments &vSubArguments)
2277 : {
2278 0 : ss << "\ndouble " << sSymName;
2279 0 : ss << "_"<< BinFuncName() <<"(";
2280 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
2281 : {
2282 0 : if (i) ss << ",";
2283 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
2284 : }
2285 0 : ss << ") {\n";
2286 0 : ss << " int gid0 = get_global_id(0);\n";
2287 0 : ss << " double num = " << GetBottom() << ";\n";
2288 0 : ss << " double shift_amount = " << GetBottom() << ";\n";
2289 0 : FormulaToken *iNum = vSubArguments[0]->GetFormulaToken();
2290 : const formula::SingleVectorRefToken* tmpCurDVRNum=
2291 0 : static_cast<const formula::SingleVectorRefToken*>(iNum);
2292 0 : FormulaToken *iShiftAmount = vSubArguments[1]->GetFormulaToken();
2293 : const formula::SingleVectorRefToken* tmpCurDVRShiftAmount=
2294 0 : static_cast<const formula::SingleVectorRefToken*>(iShiftAmount);
2295 0 : ss << " int buffer_num_len = "<< tmpCurDVRNum->GetArrayLength()<<";\n";
2296 0 : ss << " int buffer_shift_amount_len = ";
2297 0 : ss << tmpCurDVRShiftAmount->GetArrayLength() << ";\n";
2298 0 : ss << " if((gid0)>=buffer_num_len || isNan(";
2299 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
2300 0 : ss << " num = " << GetBottom() << ";\n";
2301 0 : ss << " else\n ";
2302 0 : ss << " num = floor(";
2303 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ");\n";
2304 0 : ss << " if((gid0)>=buffer_shift_amount_len || isNan(";
2305 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << "))\n";
2306 0 : ss << " shift_amount = " << GetBottom() << ";\n";
2307 0 : ss << " else\n ";
2308 0 : ss << " shift_amount = floor(";
2309 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ");\n";
2310 0 : ss << " return floor(shift_amount >= 0 ? ";
2311 0 : ss << "num * pow(2.0, shift_amount) : ";
2312 0 : ss << "num / pow(2.0, fabs(shift_amount)));\n";
2313 0 : ss << "}";
2314 0 : }
2315 0 : void OpBitRshift::GenSlidingWindowFunction(std::stringstream &ss,
2316 : const std::string &sSymName, SubArguments &vSubArguments)
2317 : {
2318 0 : ss << "\ndouble " << sSymName;
2319 0 : ss << "_"<< BinFuncName() <<"(";
2320 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
2321 : {
2322 0 : if (i) ss << ",";
2323 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
2324 : }
2325 0 : ss << ") {\n";
2326 0 : ss << " int gid0 = get_global_id(0);\n";
2327 0 : ss << " double num = " << GetBottom() << ";\n";
2328 0 : ss << " double shift_amount = " << GetBottom() << ";\n";
2329 0 : FormulaToken *iNum = vSubArguments[0]->GetFormulaToken();
2330 : const formula::SingleVectorRefToken* tmpCurDVRNum=
2331 0 : static_cast<const formula::SingleVectorRefToken*>(iNum);
2332 0 : FormulaToken *iShiftAmount = vSubArguments[1]->GetFormulaToken();
2333 : const formula::SingleVectorRefToken* tmpCurDVRShiftAmount=
2334 0 : static_cast<const formula::SingleVectorRefToken*>(iShiftAmount);
2335 0 : ss << " int buffer_num_len = ";
2336 0 : ss << tmpCurDVRNum->GetArrayLength() << ";\n";
2337 0 : ss << " int buffer_shift_amount_len = ";
2338 0 : ss << tmpCurDVRShiftAmount->GetArrayLength() << ";\n";
2339 :
2340 0 : ss << " if((gid0)>=buffer_num_len || isNan(";
2341 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
2342 0 : ss << " num = " << GetBottom() << ";\n";
2343 0 : ss << " else\n ";
2344 0 : ss << " num = floor(";
2345 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ");\n";
2346 0 : ss << " if((gid0)>=buffer_shift_amount_len || isNan(";
2347 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << "))\n";
2348 0 : ss << " shift_amount = " <<GetBottom()<< ";\n";
2349 0 : ss << " else\n ";
2350 0 : ss << " shift_amount = floor(";
2351 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ");\n";
2352 0 : ss << " return floor(";
2353 0 : ss << "shift_amount >= 0 ? num / pow(2.0, shift_amount) : ";
2354 0 : ss << "num * pow(2.0, fabs(shift_amount)));\n";
2355 0 : ss << "}";
2356 0 : }
2357 0 : void OpSumSQ::GenSlidingWindowFunction(std::stringstream &ss,
2358 : const std::string &sSymName, SubArguments &vSubArguments)
2359 : {
2360 0 : ss << "\ndouble " << sSymName;
2361 0 : ss << "_"<< BinFuncName() <<"(";
2362 0 : for (size_t i = 0; i < vSubArguments.size(); ++i)
2363 : {
2364 0 : if (i)
2365 0 : ss << ",";
2366 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
2367 : }
2368 0 : ss << ")\n";
2369 0 : ss << "{\n";
2370 0 : ss << " int gid0=get_global_id(0);\n";
2371 0 : ss << " double sum = 0.0f, arg;\n";
2372 0 : for( size_t i=0; i < vSubArguments.size(); ++i)
2373 : {
2374 0 : FormulaToken *tmpCur = vSubArguments[i]->GetFormulaToken();
2375 : assert(tmpCur);
2376 0 : if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
2377 : {
2378 0 : if (tmpCur->GetType() == formula::svDoubleVectorRef)
2379 : {
2380 : const formula::DoubleVectorRefToken* pDVR =
2381 0 : static_cast<const formula::DoubleVectorRefToken *>(tmpCur);
2382 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
2383 0 : ss << " for (int i = ";
2384 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
2385 : {
2386 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
2387 0 : ss << " && i < " << nCurWindowSize << "; ++i)\n";
2388 0 : ss << " {\n";
2389 : }
2390 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
2391 : {
2392 0 : ss << "0; i < " << pDVR->GetArrayLength();
2393 0 : ss << " && i < gid0+"<< nCurWindowSize << "; ++i)\n";
2394 0 : ss << " {\n";
2395 : }
2396 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
2397 : {
2398 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
2399 0 : ss << " && i < "<< nCurWindowSize << "; ++i)\n";
2400 0 : ss << " {\n";
2401 : }
2402 : else
2403 : {
2404 0 : ss << "0; i < "<< nCurWindowSize << "; ++i)\n";
2405 0 : ss << " {\n";
2406 : }
2407 0 : ss << " arg = ";
2408 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
2409 0 : ss << ";\n";
2410 0 : ss << " if (isNan(arg))\n";
2411 0 : ss << " continue;\n";
2412 0 : ss << " sum += pown(arg, 2);\n";
2413 0 : ss << " }\n";
2414 : }
2415 0 : else if(tmpCur->GetType() == formula::svSingleVectorRef)
2416 : {
2417 : const formula::SingleVectorRefToken* tmpCurDVR=
2418 : static_cast<
2419 0 : const formula::SingleVectorRefToken *>(tmpCur);
2420 0 : ss << " arg = ";
2421 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
2422 0 : ss << ";\n";
2423 0 : ss << " if(isNan(arg)||(gid0>=";
2424 0 : ss << tmpCurDVR->GetArrayLength();
2425 0 : ss << "))\n";
2426 0 : ss << " arg = 0.0f;\n";
2427 0 : ss << " sum += pown(arg, 2);\n";
2428 : }
2429 0 : else if(tmpCur->GetType() == formula::svDouble)
2430 : {
2431 0 : ss << " arg = ";
2432 0 : ss << tmpCur->GetDouble() << ";\n";
2433 0 : ss << " sum += pown(arg, 2);\n";
2434 : }
2435 : }
2436 : else
2437 : {
2438 0 : ss << " arg = ";
2439 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
2440 0 : ss << ";\n";
2441 0 : ss << " sum += pown(arg, 2);\n";
2442 : }
2443 : }
2444 0 : ss << " return sum;\n";
2445 0 : ss << "}";
2446 0 : }
2447 0 : void OpSqrtPi::GenSlidingWindowFunction(std::stringstream &ss,
2448 : const std::string &sSymName, SubArguments &vSubArguments)
2449 : {
2450 0 : ss << "\ndouble " << sSymName;
2451 0 : ss << "_"<< BinFuncName() <<"(";
2452 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
2453 : {
2454 0 : if (i)
2455 0 : ss << ",";
2456 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
2457 : }
2458 0 : ss << ")\n";
2459 0 : ss << "{\n";
2460 0 : ss << " int gid0=get_global_id(0);\n";
2461 0 : ss << " double arg0 = 0.0f;\n";
2462 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
2463 : assert(tmpCur);
2464 0 : if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
2465 : {
2466 0 : if(tmpCur->GetType() == formula::svSingleVectorRef)
2467 : {
2468 : const formula::SingleVectorRefToken*tmpCurDVR=
2469 : static_cast
2470 0 : <const formula::SingleVectorRefToken *>(tmpCur);
2471 0 : ss << " arg0 = ";
2472 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
2473 0 : ss << ";\n";
2474 0 : ss << " if(isNan(";
2475 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
2476 0 : ss << ")||(gid0>=";
2477 0 : ss << tmpCurDVR->GetArrayLength();
2478 0 : ss << "))\n";
2479 0 : ss << " { arg0 = 0.0f; }\n";
2480 : }
2481 0 : else if(tmpCur->GetType() == formula::svDouble)
2482 : {
2483 0 : ss << " arg0=";
2484 0 : ss << tmpCur->GetDouble() << ";\n";
2485 : }
2486 : }
2487 : else
2488 : {
2489 0 : ss << " arg0 = ";
2490 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
2491 0 : ss << ";\n";
2492 : }
2493 0 : ss << " return (double)sqrt(arg0 *";
2494 0 : ss << " 3.1415926535897932384626433832795f);\n";
2495 0 : ss << "}";
2496 0 : }
2497 0 : void OpCeil::GenSlidingWindowFunction(std::stringstream &ss,
2498 : const std::string &sSymName, SubArguments &vSubArguments)
2499 : {
2500 0 : ss << "\ndouble " << sSymName;
2501 0 : ss << "_"<< BinFuncName() <<"(";
2502 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
2503 : {
2504 0 : if (i) ss << ",";
2505 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
2506 : }
2507 0 : ss << ") {\n";
2508 0 : ss << " int gid0 = get_global_id(0);\n";
2509 0 : ss << " double num = " << GetBottom() << ";\n";
2510 0 : ss << " double significance = " << GetBottom() << ";\n";
2511 0 : ss << " double bAbs = 0;\n";
2512 0 : ss << " if(isNan(";
2513 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
2514 0 : ss << " num = " << GetBottom() << ";\n";
2515 0 : ss << " else\n ";
2516 0 : ss << " num = " << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
2517 0 : ss << " if(isNan(";
2518 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << "))\n";
2519 0 : ss << " return 0.0;\n";
2520 0 : ss << " else\n ";
2521 0 : ss << " significance = ";
2522 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
2523 0 : if (vSubArguments.size() > 2)
2524 : {
2525 0 : FormulaToken *bAbs = vSubArguments[2]->GetFormulaToken();
2526 0 : if(bAbs->GetType() == formula::svSingleVectorRef)
2527 : {
2528 : const formula::SingleVectorRefToken* tmpCurSVRIsAbs=
2529 0 : static_cast<const formula::SingleVectorRefToken*>(bAbs);
2530 0 : ss<< " if((gid0)>=" << tmpCurSVRIsAbs->GetArrayLength() << " ||";
2531 : }
2532 0 : if(bAbs->GetType() == formula::svDoubleVectorRef)
2533 : {
2534 : const formula::DoubleVectorRefToken* tmpCurDVRIsAbs=
2535 0 : static_cast<const formula::DoubleVectorRefToken*>(bAbs);
2536 0 : ss<< " if((gid0)>=" << tmpCurDVRIsAbs->GetArrayLength() << " ||";
2537 : }
2538 0 : if(bAbs->GetType() == formula::svDouble)
2539 : {
2540 0 : ss<< " if(";
2541 : }
2542 0 : ss << "isNan(";
2543 0 : ss << vSubArguments[2]->GenSlidingWindowDeclRef() << "))\n";
2544 0 : ss << " bAbs = 0;\n";
2545 0 : ss << " else\n ";
2546 0 : ss << " bAbs = "<<vSubArguments[2]->GenSlidingWindowDeclRef()<<";\n";
2547 : }
2548 0 : ss << " if(significance == 0.0)\n";
2549 0 : ss << " return 0.0;\n";
2550 0 : ss << " return ";
2551 0 : ss << "( !(int)bAbs && num < 0.0 ? floor( num / significance ) : ";
2552 0 : ss << "ceil( num / significance ) )";
2553 0 : ss << "*significance;\n";
2554 0 : ss << "}";
2555 0 : }
2556 0 : void OpCombin::GenSlidingWindowFunction(std::stringstream &ss,
2557 : const std::string &sSymName, SubArguments &vSubArguments)
2558 : {
2559 0 : ss << "\ndouble " << sSymName;
2560 0 : ss << "_"<< BinFuncName() <<"(";
2561 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
2562 : {
2563 0 : if (i) ss << ",";
2564 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
2565 : }
2566 0 : ss << ") {\n";
2567 0 : ss << " int gid0 = get_global_id(0);\n";
2568 0 : ss << " double num = " << GetBottom() << ";\n";
2569 0 : ss << " double num_chosen = " << GetBottom() << ";\n";
2570 0 : ss << " double result = -1.0;\n";
2571 0 : FormulaToken *iNum = vSubArguments[0]->GetFormulaToken();
2572 0 : FormulaToken *iNumChosen = vSubArguments[1]->GetFormulaToken();
2573 :
2574 : assert(iNum);
2575 0 : if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
2576 : {
2577 0 : if(iNum->GetType() == formula::svSingleVectorRef &&
2578 0 : iNumChosen->GetType() == formula::svSingleVectorRef)
2579 : {
2580 0 : ss << " if(isNan(";
2581 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
2582 0 : ss << " num = " << GetBottom() << ";\n";
2583 0 : ss << " else\n ";
2584 0 : ss << " num = floor(";
2585 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ");\n";
2586 0 : ss << " if(isNan(";
2587 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << "))\n";
2588 0 : ss << " num_chosen = " << GetBottom() << ";\n";
2589 0 : ss << " else\n ";
2590 0 : ss << " num_chosen = floor(";
2591 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ");\n";
2592 : }
2593 0 : else if(iNum->GetType() == formula::svDouble &&
2594 0 : iNumChosen->GetType() == formula::svDouble)
2595 : {
2596 0 : ss << " num = floor(" << iNum->GetDouble() << ");\n";
2597 0 : ss << " num_chosen = floor("<< iNumChosen->GetDouble()<< ");\n";
2598 : }
2599 : }
2600 : else
2601 : {
2602 0 : ss << " num = floor(";
2603 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ");\n";
2604 0 : ss << " num_chosen = floor(";
2605 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << ");\n";
2606 : }
2607 0 : ss << " result = select(result, 0.0, (ulong)(num < num_chosen));\n";
2608 0 : ss << " result = select(result, 1.0, (ulong)(num_chosen == 0.0));\n";
2609 0 : ss << " if(result == 0 || result ==1)\n";
2610 0 : ss << " return result;\n";
2611 0 : ss << " double4 db4num;\n";
2612 0 : ss << " double4 db4num_chosen;\n";
2613 0 : ss << " double4 db4result;\n";
2614 0 : ss << " double2 db2result;\n";
2615 0 : ss << " result = 1.0;\n";
2616 0 : ss << " int loop = num_chosen/4;\n";
2617 0 : ss << " for(int i=0; i<loop; i++)\n";
2618 0 : ss << " {\n";
2619 0 : ss << " db4num = (double4){num,\n";
2620 0 : ss << " num-1.0,\n";
2621 0 : ss << " num-2.0,\n";
2622 0 : ss << " num-3.0};\n";
2623 0 : ss << " db4num_chosen = (double4){num_chosen,\n";
2624 0 : ss << " num_chosen-1.0,\n";
2625 0 : ss << " num_chosen-2.0,\n";
2626 0 : ss << " num_chosen-3.0};\n";
2627 0 : ss << " db4result = db4num * pown(db4num_chosen, -1);\n";
2628 0 : ss << " db2result = db4result.xy * db4result.zw;\n";
2629 0 : ss << " result *= db2result.x * db2result.y;\n";
2630 0 : ss << " num = num - 4.0;\n";
2631 0 : ss << " num_chosen = num_chosen - 4.0;\n";
2632 0 : ss << " }\n";
2633 0 : ss << " while ( num_chosen > 0){\n";
2634 0 : ss << " result *= num / num_chosen;\n";
2635 0 : ss << " num = num - 1.0;\n";
2636 0 : ss << " num_chosen = num_chosen - 1.0;\n";
2637 0 : ss << " }\n";
2638 0 : ss << " return result;\n";
2639 0 : ss << "}\n";
2640 0 : }
2641 0 : void OpConvert::GenSlidingWindowFunction(
2642 : std::stringstream &ss, const std::string &sSymName,
2643 : SubArguments &vSubArguments)
2644 : {
2645 : // The CONVERT function converts a value from one unit of
2646 : // measurement to another. It takes the units of measurements to
2647 : // convert between as string arguments. This implementation
2648 : // handles just a very small subset of such conversions.
2649 :
2650 0 : int arg1=vSubArguments[1]->GetFormulaToken()->GetString().\
2651 0 : getString().toAsciiUpperCase().hashCode();
2652 0 : int arg2=vSubArguments[2]->GetFormulaToken()->GetString().\
2653 0 : getString().toAsciiUpperCase().hashCode();
2654 :
2655 : // Check if the from and to units are those combinations that the
2656 : // code below supports.
2657 0 : if( !((arg1==5584&&arg2==108)||
2658 0 : (arg1==108&&arg2==5584)||
2659 0 : (arg1==5665&&arg2==268206)||
2660 0 : (arg1==268206&&arg2==5665)) )
2661 0 : throw Unhandled();
2662 :
2663 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
2664 : const formula::SingleVectorRefToken*tmpCurDVR= static_cast<const
2665 0 : formula::SingleVectorRefToken *>(tmpCur);
2666 0 : ss << "\ndouble " << sSymName;
2667 0 : ss << "_"<< BinFuncName() <<"(";
2668 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
2669 : {
2670 0 : if (i)
2671 0 : ss << ",";
2672 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
2673 : }
2674 0 : ss << ")\n{\n";
2675 0 : ss <<" int gid0=get_global_id(0);\n";
2676 0 : ss << " double arg0 = " << vSubArguments[0]->GenSlidingWindowDeclRef();
2677 0 : ss << ";\n";
2678 0 : ss << " double arg1 = " << vSubArguments[1]->GenSlidingWindowDeclRef();
2679 0 : ss << ";\n";
2680 0 : ss << " double arg2 = " << vSubArguments[2]->GenSlidingWindowDeclRef();
2681 0 : ss << ";\n";
2682 0 : ss<< " if(isNan(arg0)||(gid0>=";
2683 0 : ss<<tmpCurDVR->GetArrayLength();
2684 0 : ss<<"))\n";
2685 0 : ss<<" arg0 = 0;\n";
2686 0 : ss<< " if(isNan(arg1)||(gid0>=";
2687 0 : ss<<tmpCurDVR->GetArrayLength();
2688 0 : ss<<"))\n";
2689 0 : ss<<" arg1 = 0;\n";
2690 0 : ss<< " if(isNan(arg2)||(gid0>=";
2691 0 : ss<<tmpCurDVR->GetArrayLength();
2692 0 : ss<<"))\n";
2693 0 : ss<<" arg2 = 0;\n";
2694 0 : ss<<" if(arg1==5584U&&arg2==108U)\n";
2695 0 : ss<<" return arg0*1000.0;\n";
2696 0 : ss<<" else if(arg1==108U&&arg2==3385U)\n";
2697 0 : ss<<" return arg0/1000.0;\n";
2698 0 : ss<<" else if(arg1==5665U&&arg2==268206U)\n";
2699 0 : ss<<" return arg0*60.0;\n";
2700 0 : ss<<" else if(arg1==268206U&&arg2==5665U)\n";
2701 0 : ss<<" return arg0/60.0;\n";
2702 0 : ss<<" else\n";
2703 0 : ss<<" return -9999999999;\n";
2704 0 : ss << "}\n";
2705 :
2706 0 : }
2707 :
2708 0 : void OpProduct::GenSlidingWindowFunction(std::stringstream &ss,
2709 : const std::string &sSymName, SubArguments &vSubArguments)
2710 : {
2711 0 : ss << "\ndouble " << sSymName;
2712 0 : ss << "_"<< BinFuncName() <<"( ";
2713 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
2714 : {
2715 0 : if (i)
2716 0 : ss << ",";
2717 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
2718 : }
2719 0 : ss << ") {\n";
2720 0 : ss << " int gid0 = get_global_id(0);\n";
2721 0 : ss << " int i = 0;\n";
2722 0 : ss << " double product=1.0;\n\n";
2723 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
2724 : {
2725 0 : FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
2726 : assert(pCur);
2727 0 : if (pCur->GetType() == formula::svDoubleVectorRef)
2728 : {
2729 : const formula::DoubleVectorRefToken* pDVR =
2730 0 : static_cast<const formula::DoubleVectorRefToken *>(pCur);
2731 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
2732 :
2733 0 : ss << " for (int i = ";
2734 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
2735 : {
2736 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
2737 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
2738 0 : ss << " {\n";
2739 : }
2740 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
2741 : {
2742 0 : ss << "0; i < " << pDVR->GetArrayLength();
2743 0 : ss << " && i < gid0+" << nCurWindowSize << "; i++)\n";
2744 0 : ss << " {\n";
2745 : }
2746 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
2747 : {
2748 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
2749 0 : ss << " && i < " << nCurWindowSize << "; i++)\n";
2750 0 : ss << " {\n";
2751 : }
2752 0 : else if (pDVR->IsStartFixed() && pDVR->IsEndFixed())
2753 : {
2754 :
2755 0 : ss << "0; i < " << pDVR->GetArrayLength() << "; i++)\n";
2756 0 : ss << " {\n";
2757 : }
2758 0 : ss << "if(!isNan("<<vSubArguments[i]->GenSlidingWindowDeclRef()<<"))\n";
2759 0 : ss << "product = product*";
2760 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef()<<";\n";
2761 0 : ss << " }\n";
2762 : }
2763 0 : else if (pCur->GetType() == formula::svSingleVectorRef)
2764 : {
2765 0 : ss << "if(!isNan("<<vSubArguments[i]->GenSlidingWindowDeclRef()<<"))\n";
2766 0 : ss << "product = product*";
2767 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef()<<";\n";
2768 :
2769 : }
2770 : else
2771 : {
2772 0 : ss << "if(!isNan("<<vSubArguments[i]->GenSlidingWindowDeclRef()<<"))\n";
2773 0 : ss << "product = product*";
2774 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef()<<";\n";
2775 : }
2776 : }
2777 0 : ss << " return product;\n";
2778 0 : ss << "}";
2779 0 : }
2780 0 : void OpAverageIf::GenSlidingWindowFunction(std::stringstream &ss,
2781 : const std::string &sSymName, SubArguments &vSubArguments)
2782 : {
2783 :
2784 0 : ss << "\ndouble " << sSymName;
2785 0 : ss << "_"<< BinFuncName() <<"(";
2786 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
2787 : {
2788 0 : if (i) ss << ",";
2789 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
2790 : }
2791 0 : ss << ")\n{\n";
2792 0 : ss << " int gid0=get_global_id(0);\n";
2793 0 : ss << " double tmp =0;\n";
2794 0 : ss << " double count=0;\n";
2795 0 : ss << " int singleIndex =gid0;\n";
2796 0 : ss << " int doubleIndex;\n";
2797 0 : ss << " int i ;\n";
2798 0 : ss << " int j ;\n";
2799 0 : GenTmpVariables(ss,vSubArguments);
2800 :
2801 0 : unsigned paraOneIsDoubleVector = 0;
2802 0 : unsigned paraOneWidth = 1;
2803 0 : unsigned paraTwoWidth = 1;
2804 0 : unsigned loopTimes = 0;
2805 :
2806 0 : if(vSubArguments[0]->GetFormulaToken()->GetType() == formula::svDoubleVectorRef)
2807 : {
2808 0 : paraOneIsDoubleVector = 1;
2809 0 : FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
2810 : const formula::DoubleVectorRefToken*pCurDVR0= static_cast<const
2811 0 : formula::DoubleVectorRefToken *>(tmpCur0);
2812 0 : paraOneWidth = pCurDVR0->GetArrays().size();
2813 0 : loopTimes = paraOneWidth;
2814 0 : if(paraOneWidth > 1)
2815 : {
2816 0 : throw Unhandled();
2817 : }
2818 : }
2819 :
2820 0 : if(vSubArguments[paraOneWidth]->GetFormulaToken()->GetType() ==
2821 : formula::svDoubleVectorRef)
2822 :
2823 : {
2824 0 : FormulaToken *tmpCur1 = vSubArguments[1]->GetFormulaToken();
2825 : const formula::DoubleVectorRefToken*pCurDVR1= static_cast<const
2826 0 : formula::DoubleVectorRefToken *>(tmpCur1);
2827 0 : paraTwoWidth = pCurDVR1->GetArrays().size();
2828 0 : if(paraTwoWidth > 1)
2829 : {
2830 0 : throw Unhandled();
2831 : }
2832 0 : ss << " i = ";
2833 0 : if (!pCurDVR1->IsStartFixed() && pCurDVR1->IsEndFixed()) {
2834 0 : ss << "gid0;\n";
2835 : } else {
2836 0 : ss << "0;\n";
2837 : }
2838 0 : if(!pCurDVR1->IsStartFixed() && !pCurDVR1->IsEndFixed())
2839 : {
2840 0 : ss << " doubleIndex =i+gid0;\n";
2841 : }else
2842 : {
2843 0 : ss << " doubleIndex =i;\n";
2844 : }
2845 : }
2846 :
2847 0 : CheckSubArgumentIsNan(ss,vSubArguments,paraOneWidth);
2848 :
2849 0 : unsigned paraThreeIndex = paraOneWidth + paraTwoWidth;
2850 0 : if(vSubArguments.size() > paraThreeIndex)
2851 : {
2852 0 : if(vSubArguments[paraThreeIndex]->GetFormulaToken()->GetType() ==
2853 : formula::svDoubleVectorRef)
2854 : {
2855 : FormulaToken *tmpCur2 =
2856 0 : vSubArguments[paraThreeIndex]->GetFormulaToken();
2857 : const formula::DoubleVectorRefToken*pCurDVR2= static_cast<const
2858 0 : formula::DoubleVectorRefToken *>(tmpCur2);
2859 0 : unsigned paraThreeWidth = pCurDVR2->GetArrays().size();
2860 0 : if(paraThreeWidth > 1)
2861 : {
2862 0 : throw Unhandled();
2863 : }
2864 : }
2865 : }
2866 :
2867 0 : if(paraOneIsDoubleVector)
2868 : {
2869 0 : unsigned loopIndex = 0;
2870 0 : FormulaToken *tmpCur0 = vSubArguments[0]->GetFormulaToken();
2871 : const formula::DoubleVectorRefToken*pCurDVR0= static_cast<const
2872 0 : formula::DoubleVectorRefToken *>(tmpCur0);
2873 0 : size_t nCurWindowSize = pCurDVR0->GetArrayLength() <
2874 0 : pCurDVR0->GetRefRowSize() ? pCurDVR0->GetArrayLength():
2875 0 : pCurDVR0->GetRefRowSize() ;
2876 :
2877 0 : for(loopIndex =0; loopIndex < loopTimes; loopIndex++)
2878 : {
2879 0 : ss << " for (i = ";
2880 0 : if (!pCurDVR0->IsStartFixed() && pCurDVR0->IsEndFixed()) {
2881 0 : ss << "gid0; i < "<< nCurWindowSize <<"; i++)\n";
2882 0 : } else if (pCurDVR0->IsStartFixed() && !pCurDVR0->IsEndFixed()) {
2883 0 : ss << "0; i < gid0+"<< nCurWindowSize <<"; i++)\n";
2884 : } else {
2885 0 : ss << "0; i < "<< nCurWindowSize <<"; i++)\n";
2886 : }
2887 0 : ss << " {\n";
2888 0 : if(!pCurDVR0->IsStartFixed() && !pCurDVR0->IsEndFixed())
2889 : {
2890 0 : ss << " doubleIndex =i+gid0;\n";
2891 : }else
2892 : {
2893 0 : ss << " doubleIndex =i;\n";
2894 : }
2895 :
2896 0 : CheckSubArgumentIsNan(ss,vSubArguments, loopIndex);
2897 :
2898 0 : ss << " if ( isequal( tmp";
2899 0 : ss << loopIndex<<" , tmp"<<paraOneWidth<<") ) \n";
2900 0 : ss << " {\n";
2901 0 : if(vSubArguments.size() == paraThreeIndex)
2902 0 : ss << " tmp += tmp"<<loopIndex<<";\n";
2903 : else
2904 : {
2905 : CheckSubArgumentIsNan(ss,vSubArguments,
2906 0 : paraThreeIndex+loopIndex);
2907 0 : ss << " tmp += tmp";
2908 0 : ss << paraThreeIndex+loopIndex<<";\n";
2909 : }
2910 0 : ss << " count+=1.0;\n";
2911 0 : ss << " }\n";
2912 0 : ss << " }\n";
2913 : }
2914 : }
2915 : else
2916 : {
2917 0 : CheckSubArgumentIsNan(ss,vSubArguments, 0);
2918 0 : ss << " if ( isequal( tmp0 , tmp1 ) ) \n";
2919 0 : ss << " {\n";
2920 0 : if(vSubArguments.size() == 2)
2921 0 : ss << " tmp += tmp0;\n";
2922 : else
2923 : {
2924 0 : CheckSubArgumentIsNan(ss,vSubArguments,2);
2925 0 : ss << " tmp += tmp2;\n";
2926 : }
2927 0 : ss << " count+=1.0;\n";
2928 0 : ss << " }\n";
2929 : }
2930 :
2931 0 : ss << " if(count!=0)\n";
2932 0 : ss << " tmp=tmp/count;\n";
2933 0 : ss << " else\n";
2934 0 : ss << " tmp= 0 ;\n";
2935 0 : ss << " return tmp;\n";
2936 0 : ss << "}";
2937 0 : }
2938 0 : void OpDeg::GenSlidingWindowFunction(std::stringstream &ss,
2939 : const std::string &sSymName, SubArguments &vSubArguments)
2940 : {
2941 0 : ss << "\ndouble " << sSymName;
2942 0 : ss << "_"<< BinFuncName() <<"(";
2943 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
2944 : {
2945 0 : if (i)
2946 0 : ss << ",";
2947 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
2948 : }
2949 0 : ss << ")\n";
2950 0 : ss << "{\n";
2951 0 : ss << " int gid0=get_global_id(0);\n";
2952 0 : ss << " double arg0 = 0.0f;\n";
2953 0 : FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
2954 : assert(tmpCur);
2955 0 : if(ocPush == vSubArguments[0]->GetFormulaToken()->GetOpCode())
2956 : {
2957 0 : if(tmpCur->GetType() == formula::svSingleVectorRef)
2958 : {
2959 : const formula::SingleVectorRefToken*tmpCurDVR=
2960 : static_cast
2961 0 : <const formula::SingleVectorRefToken *>(tmpCur);
2962 0 : ss << " arg0 = ";
2963 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
2964 0 : ss << ";\n";
2965 0 : ss << " if(isNan(";
2966 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
2967 0 : ss << ")||(gid0>=";
2968 0 : ss << tmpCurDVR->GetArrayLength();
2969 0 : ss << "))\n";
2970 0 : ss << " { arg0 = 0.0f; }\n";
2971 : }
2972 0 : else if(tmpCur->GetType() == formula::svDouble)
2973 : {
2974 0 : ss << " arg0=";
2975 0 : ss << tmpCur->GetDouble() << ";\n";
2976 : }
2977 : }
2978 : else
2979 : {
2980 0 : ss << " arg0 = ";
2981 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
2982 0 : ss << ";\n";
2983 : }
2984 0 : ss << " return arg0 * pown(M_PI, -1) * 180;;\n";
2985 0 : ss << "}";
2986 0 : }
2987 :
2988 0 : void OpFact::GenSlidingWindowFunction(std::stringstream& ss,
2989 : const std::string &sSymName, SubArguments& vSubArguments)
2990 : {
2991 0 : ss << "\ndouble " << sSymName;
2992 0 : ss << "_" << BinFuncName() << "(";
2993 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
2994 : {
2995 0 : if (i)
2996 0 : ss << ",";
2997 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
2998 : }
2999 0 : ss << ") {\n";
3000 0 : ss << " double tmp = " << GetBottom() << ";\n";
3001 0 : ss << " int gid0 = get_global_id(0);\n";
3002 0 : ss << " double arg0 = " << GetBottom() << ";\n";
3003 0 : FormulaToken* pCur = vSubArguments[0]->GetFormulaToken();
3004 : assert(pCur);
3005 0 : if (pCur->GetType() == formula::svSingleVectorRef)
3006 : {
3007 : const formula::SingleVectorRefToken* pSVR =
3008 0 : static_cast< const formula::SingleVectorRefToken* >(pCur);
3009 0 : ss << " if (gid0 < " << pSVR->GetArrayLength() << "){\n";
3010 : }
3011 0 : else if (pCur->GetType() == formula::svDouble)
3012 : {
3013 0 : ss << " {\n";
3014 : }
3015 0 : if(ocPush==vSubArguments[0]->GetFormulaToken()->GetOpCode())
3016 : {
3017 0 : ss << " if (isNan(";
3018 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef();
3019 0 : ss << "))\n";
3020 0 : ss << " arg0 = 0;\n";
3021 0 : ss << " else\n";
3022 0 : ss << " arg0 = ";
3023 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
3024 0 : ss << " arg0 = floor(arg0);\n";
3025 0 : ss << " if (arg0 < 0.0)\n";
3026 0 : ss << " return 0.0;\n";
3027 0 : ss << " else if (arg0 == 0.0)\n";
3028 0 : ss << " return 1.0;\n";
3029 0 : ss << " else if (arg0 <= 170.0)\n";
3030 0 : ss << " {\n";
3031 0 : ss << " double fTemp = arg0;\n";
3032 0 : ss << " while (fTemp > 2.0)\n";
3033 0 : ss << " {\n";
3034 0 : ss << " fTemp = fTemp - 1;\n";
3035 0 : ss << " arg0 = arg0 * fTemp;\n";
3036 0 : ss << " }\n";
3037 0 : ss << " }\n";
3038 0 : ss << " else\n";
3039 0 : ss << " return -DBL_MAX;\n";
3040 0 : ss << " }\n";
3041 : }
3042 : else
3043 : {
3044 0 : ss << " arg0 = ";
3045 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
3046 : }
3047 0 : ss << " return arg0;\n";
3048 0 : ss << "}";
3049 0 : }
3050 0 : void OpQuotient::GenSlidingWindowFunction(std::stringstream &ss,
3051 : const std::string &sSymName, SubArguments &vSubArguments)
3052 : {
3053 0 : ss << "\ndouble " << sSymName;
3054 0 : ss << "_"<< BinFuncName() <<"(";
3055 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
3056 : {
3057 0 : if (i) ss << ",";
3058 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
3059 : }
3060 0 : ss << ") {\n";
3061 0 : ss << " int gid0 = get_global_id(0);\n";
3062 0 : ss << " double num1 = 1.0;\n";
3063 0 : ss << " double num2 = 1.0;\n";
3064 0 : ss << " if(isNan(";
3065 0 : ss << vSubArguments[0]->GenSlidingWindowDeclRef() << "))\n";
3066 0 : ss << " num1 = 1.0;\n";
3067 0 : ss << " else \n ";
3068 0 : ss << " num1 = " << vSubArguments[0]->GenSlidingWindowDeclRef() << ";\n";
3069 0 : ss << " if(isNan(";
3070 0 : ss << vSubArguments[1]->GenSlidingWindowDeclRef() << "))\n";
3071 0 : ss << " num2 = 1.0;\n";
3072 0 : ss << " else \n ";
3073 0 : ss << " num2 = " << vSubArguments[1]->GenSlidingWindowDeclRef() << ";\n";
3074 0 : ss << " return trunc(num1/num2);\n";
3075 0 : ss << "}";
3076 0 : }
3077 0 : void OpSeriesSum::GenSlidingWindowFunction(std::stringstream &ss,
3078 : const std::string &sSymName, SubArguments &vSubArguments)
3079 : {
3080 0 : if( vSubArguments.size() != 4){return;}
3081 0 : ss << "\ndouble " << sSymName;
3082 0 : ss << "_"<< BinFuncName() <<"(";
3083 0 : for (size_t i = 0; i < vSubArguments.size(); i++)
3084 : {
3085 0 : if (i)
3086 0 : ss << ",";
3087 0 : vSubArguments[i]->GenSlidingWindowDecl(ss);
3088 : }
3089 0 : ss << ")\n";
3090 0 : ss << "{\n";
3091 0 : ss << " int gid0=get_global_id(0);\n";
3092 0 : ss << " double var[3], coeff, res = 0.0f;\n";
3093 : FormulaToken *tmpCur;
3094 0 : for(int i = 0; i < 3; ++i)
3095 : {
3096 0 : tmpCur = vSubArguments[i]->GetFormulaToken();
3097 : assert(tmpCur);
3098 0 : if(ocPush == vSubArguments[i]->GetFormulaToken()->GetOpCode())
3099 : {
3100 0 : if(tmpCur->GetType() == formula::svSingleVectorRef)
3101 : {
3102 : const formula::SingleVectorRefToken* tmpCurDVR=
3103 : static_cast<
3104 0 : const formula::SingleVectorRefToken *>(tmpCur);
3105 0 : ss << " var["<<i<<"] = ";
3106 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
3107 0 : ss << ";\n";
3108 0 : ss << " if(isNan(var["<<i<<"])||(gid0>=";
3109 0 : ss << tmpCurDVR->GetArrayLength();
3110 0 : ss << "))\n";
3111 0 : ss << " var["<<i<<"] = 0;\n";
3112 : }
3113 0 : else if(tmpCur->GetType() == formula::svDouble)
3114 : {
3115 0 : ss << " var["<<i<<"] = ";
3116 0 : ss << tmpCur->GetDouble() << ";\n";
3117 : }
3118 : }
3119 : else
3120 : {
3121 0 : ss << " var["<<i<<"] = ";
3122 0 : ss << vSubArguments[i]->GenSlidingWindowDeclRef();
3123 0 : ss << ";\n";
3124 : }
3125 : }
3126 0 : tmpCur = vSubArguments[3]->GetFormulaToken();
3127 : assert(tmpCur);
3128 0 : if(ocPush == vSubArguments[3]->GetFormulaToken()->GetOpCode())
3129 : {
3130 : //TODO DoubleVector
3131 0 : if (tmpCur->GetType() == formula::svDoubleVectorRef)
3132 : {
3133 : const formula::DoubleVectorRefToken* pDVR =
3134 0 : static_cast<const formula::DoubleVectorRefToken *>(tmpCur);
3135 0 : size_t nCurWindowSize = pDVR->GetRefRowSize();
3136 0 : ss << " int j = 0;\n";
3137 0 : ss << " for (int i = ";
3138 0 : if (!pDVR->IsStartFixed() && pDVR->IsEndFixed())
3139 : {
3140 0 : ss << "gid0; i < " << pDVR->GetArrayLength();
3141 0 : ss << " && i < " << nCurWindowSize << "; ++i)\n";
3142 0 : ss << " {\n";
3143 : }
3144 0 : else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed())
3145 : {
3146 0 : ss << "0; i < " << pDVR->GetArrayLength();
3147 0 : ss << " && i < gid0+"<< nCurWindowSize << "; ++i)\n";
3148 0 : ss << " {\n";
3149 : }
3150 0 : else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed())
3151 : {
3152 0 : ss << "0; i + gid0 < " << pDVR->GetArrayLength();
3153 0 : ss << " && i < "<< nCurWindowSize << "; ++i)\n";
3154 0 : ss << " {\n";
3155 : }
3156 : else
3157 : {
3158 0 : ss << "0; i < "<< nCurWindowSize << "; ++i)\n";
3159 0 : ss << " {\n";
3160 : }
3161 0 : ss << " coeff = ";
3162 0 : ss << vSubArguments[3]->GenSlidingWindowDeclRef();
3163 0 : ss << ";\n";
3164 0 : ss << " if (isNan(coeff))\n";
3165 0 : ss << " continue;\n";
3166 0 : ss << " res = res + coeff * pow(var[0],";
3167 0 : ss << " var[1] + j * var[2]);\n";
3168 0 : ss << " ++j;\n";
3169 0 : ss << " }\n";
3170 : }
3171 0 : else if(tmpCur->GetType() == formula::svSingleVectorRef)
3172 : {
3173 : const formula::SingleVectorRefToken* tmpCurDVR=
3174 : static_cast<
3175 0 : const formula::SingleVectorRefToken *>(tmpCur);
3176 0 : ss << " coeff = ";
3177 0 : ss << vSubArguments[3]->GenSlidingWindowDeclRef();
3178 0 : ss << ";\n";
3179 0 : ss << " if(isNan(coeff)||(gid0>=";
3180 0 : ss << tmpCurDVR->GetArrayLength();
3181 0 : ss << "))\n";
3182 0 : ss << " return 0;\n";
3183 : }
3184 : }
3185 0 : ss << " return res;\n";
3186 0 : ss << "}";
3187 : }
3188 156 : }}
3189 :
3190 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|