1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #include "op_database.hxx"
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>
21 namespace sc
{ namespace opencl
{
23 void OpDmax::GenSlidingWindowFunction(std::stringstream
&ss
,
24 const std::string
&sSymName
, SubArguments
&vSubArguments
)
26 ss
<< "\ndouble " << sSymName
;
27 ss
<< "_"<< BinFuncName() <<"(";
28 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
32 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
35 ss
<< " int gid0=get_global_id(0);\n";
36 ss
<< " double max = -1000000000000;\n";
37 ss
<< " double value=0.0;\n";
38 GenTmpVariables(ss
,vSubArguments
);
41 if(vSubArguments
[0]->GetFormulaToken()->GetType() ==
42 formula::svDoubleVectorRef
)
44 formula::FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
45 const formula::DoubleVectorRefToken
*pCurDVR1
= static_cast<const
46 formula::DoubleVectorRefToken
*>(tmpCur
);
47 dataCol
= pCurDVR1
->GetArrays().size();
48 dataRow
= pCurDVR1
->GetArrayLength();
52 if(vSubArguments
[dataCol
]->GetFormulaToken()->GetType() ==
53 formula::svSingleVectorRef
)
55 const formula::SingleVectorRefToken
*pTmpDVR1
= static_cast<const
56 formula::SingleVectorRefToken
*>(vSubArguments
[dataCol
]->
58 ss
<< " tmp"<<dataCol
<<"=";
59 ss
<< vSubArguments
[dataCol
]->GenSlidingWindowDeclRef()<<";\n";
60 ss
<< " if(gid0>="<<pTmpDVR1
->GetArrayLength()<<" ||isNan(";
61 ss
<< "tmp"<<dataCol
<<"))\n";
62 ss
<< " tmp"<<dataCol
<<"=0;\n";
68 if(vSubArguments
[dataCol
+ 1]->GetFormulaToken()->GetType() ==
69 formula::svDoubleVectorRef
)
71 formula::FormulaToken
*tmpCur
= vSubArguments
[dataCol
+ 1]->
73 const formula::DoubleVectorRefToken
*pCurDVR2
= static_cast<const
74 formula::DoubleVectorRefToken
*>(tmpCur
);
75 conditionCol
= pCurDVR2
->GetArrays().size();
76 conditionRow
= pCurDVR2
->GetArrayLength();
81 if(dataCol
!=conditionCol
)
83 if(dataCol
> 0 && dataRow
> 0)
85 formula::FormulaToken
*tmpCur1
= vSubArguments
[0]->GetFormulaToken();
86 formula::FormulaToken
*tmpCur2
= vSubArguments
[dataCol
+ 1]->
88 const formula::DoubleVectorRefToken
*pCurDVR1
= static_cast<const
89 formula::DoubleVectorRefToken
*>(tmpCur1
);
90 const formula::DoubleVectorRefToken
*pCurDVR2
= static_cast<const
91 formula::DoubleVectorRefToken
*>(tmpCur2
);
93 if(pCurDVR1
->IsStartFixed() && pCurDVR1
->IsEndFixed() &&
94 pCurDVR2
->IsStartFixed() && pCurDVR2
->IsEndFixed())
96 ss
<< " int i,j,p;\n";
97 ss
<< " bool flag;\n";
98 ss
<< " for(p = 1;p < " << dataRow
<< ";++p)\n";
101 for(int i
= 0; i
< dataCol
; ++i
){
102 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
103 formula::svDoubleVectorRef
)
105 ss
<< " tmp"<<i
<<"=";
106 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
107 ss
<< " if(isNan(tmp"<<i
<<"))\n";
108 ss
<<" tmp"<<i
<<" = 0;\n";
110 ss
<< " flag = false;\n";
111 ss
<< " for(j = 1; j < " << conditionRow
<< ";++j)\n";
114 ss
<< " if (flag)\n";
117 for(int i
= dataCol
+ 1; i
< dataCol
+ 1 + conditionCol
; ++i
){
118 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
119 formula::svDoubleVectorRef
)
121 ss
<< " tmp"<<i
<<"=";
122 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
123 ss
<< " if(!isNan(tmp"<<i
<<")){\n";
124 ss
<< " if(tmp"<<(i
-dataCol
-1)<<"!=tmp";
126 ss
<< " continue;\n";
130 ss
<< " flag=true;\n";
133 ss
<< " if (flag){\n";
134 for(int i
= 0; i
< dataCol
; ++i
){
135 ss
<< " if(tmp"<<dataCol
<<"=="<<(i
+1)<<"){\n";
136 ss
<< " value=tmp"<<i
<<";\n";
139 ss
<< " if(max<value)\n";
149 ss
<< " return max;\n";
153 void OpDmin::GenSlidingWindowFunction(std::stringstream
&ss
,
154 const std::string
&sSymName
, SubArguments
&vSubArguments
)
156 ss
<< "\ndouble " << sSymName
;
157 ss
<< "_"<< BinFuncName() <<"(";
158 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
162 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
165 ss
<< " int gid0=get_global_id(0);\n";
166 ss
<< " double min = 1000000000000;\n";
167 ss
<< " double value=0.0;\n";
168 GenTmpVariables(ss
,vSubArguments
);
171 if(vSubArguments
[0]->GetFormulaToken()->GetType() ==
172 formula::svDoubleVectorRef
)
174 formula::FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
175 const formula::DoubleVectorRefToken
*pCurDVR1
= static_cast<const
176 formula::DoubleVectorRefToken
*>(tmpCur
);
177 dataCol
= pCurDVR1
->GetArrays().size();
178 dataRow
= pCurDVR1
->GetArrayLength();
182 if(vSubArguments
[dataCol
]->GetFormulaToken()->GetType() ==
183 formula::svSingleVectorRef
)
185 const formula::SingleVectorRefToken
*pTmpDVR1
= static_cast<const
186 formula::SingleVectorRefToken
*>(vSubArguments
[dataCol
]->
188 ss
<< " tmp"<<dataCol
<<"=";
189 ss
<< vSubArguments
[dataCol
]->GenSlidingWindowDeclRef()<<";\n";
190 ss
<< " if(gid0>="<<pTmpDVR1
->GetArrayLength()<<" ||isNan(";
191 ss
<< "tmp"<<dataCol
<<"))\n";
192 ss
<< " tmp"<<dataCol
<<"=0;\n";
196 int conditionCol
= 0;
197 int conditionRow
= 0;
198 if(vSubArguments
[dataCol
+ 1]->GetFormulaToken()->GetType() ==
199 formula::svDoubleVectorRef
)
201 formula::FormulaToken
*tmpCur
= vSubArguments
[dataCol
+ 1]->
203 const formula::DoubleVectorRefToken
*pCurDVR2
= static_cast<const
204 formula::DoubleVectorRefToken
*>(tmpCur
);
205 conditionCol
= pCurDVR2
->GetArrays().size();
206 conditionRow
= pCurDVR2
->GetArrayLength();
211 if(dataCol
!=conditionCol
)
213 if(dataCol
> 0 && dataRow
> 0)
215 formula::FormulaToken
*tmpCur1
= vSubArguments
[0]->GetFormulaToken();
216 formula::FormulaToken
*tmpCur2
= vSubArguments
[dataCol
+ 1]->
218 const formula::DoubleVectorRefToken
*pCurDVR1
= static_cast<const
219 formula::DoubleVectorRefToken
*>(tmpCur1
);
220 const formula::DoubleVectorRefToken
*pCurDVR2
= static_cast<const
221 formula::DoubleVectorRefToken
*>(tmpCur2
);
223 if(pCurDVR1
->IsStartFixed() && pCurDVR1
->IsEndFixed() &&
224 pCurDVR2
->IsStartFixed() && pCurDVR2
->IsEndFixed())
226 ss
<< " int i,j,p;\n";
227 ss
<< " bool flag;\n";
229 ss
<< " for(p = 1;p < " << dataRow
<< ";++p)\n";
232 for(int i
= 0; i
< dataCol
; ++i
){
233 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
234 formula::svDoubleVectorRef
)
236 ss
<< " tmp"<<i
<<"=";
237 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
238 ss
<< " if(isNan(tmp"<<i
<<"))\n";
239 ss
<<" tmp"<<i
<<" = 0;\n";
241 ss
<< " flag = false;\n";
242 ss
<< " for(j = 1; j < " << conditionRow
<< ";++j)\n";
245 ss
<< " if (flag)\n";
248 for(int i
= dataCol
+ 1; i
< dataCol
+ 1 + conditionCol
; ++i
){
249 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
250 formula::svDoubleVectorRef
)
252 ss
<< " tmp"<<i
<<"=";
253 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
254 ss
<< " if(!isNan(tmp"<<i
<<")){\n";
255 ss
<< " if(tmp"<<(i
-dataCol
-1)<<"!=tmp";
257 ss
<< " continue;\n";
261 ss
<< " flag=true;\n";
264 ss
<< " if (flag){\n";
265 for(int i
= 0; i
< dataCol
; ++i
){
266 ss
<< " if(tmp"<<dataCol
<<"=="<<(i
+1)<<"){\n";
267 ss
<< " value=tmp"<<i
<<";\n";
270 ss
<< " if(min>value)\n";
280 ss
<< " return min;\n";
284 void OpDproduct::GenSlidingWindowFunction(std::stringstream
&ss
,
285 const std::string
&sSymName
, SubArguments
&vSubArguments
)
287 ss
<< "\ndouble " << sSymName
;
288 ss
<< "_"<< BinFuncName() <<"(";
289 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
293 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
296 ss
<< " int gid0=get_global_id(0);\n";
297 ss
<< " double product = 1;\n";
298 ss
<< " double value =0;\n";
299 GenTmpVariables(ss
,vSubArguments
);
302 if(vSubArguments
[0]->GetFormulaToken()->GetType() ==
303 formula::svDoubleVectorRef
)
305 formula::FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
306 const formula::DoubleVectorRefToken
*pCurDVR1
= static_cast<const
307 formula::DoubleVectorRefToken
*>(tmpCur
);
308 dataCol
= pCurDVR1
->GetArrays().size();
309 dataRow
= pCurDVR1
->GetArrayLength();
313 if(vSubArguments
[dataCol
]->GetFormulaToken()->GetType() ==
314 formula::svSingleVectorRef
)
316 const formula::SingleVectorRefToken
*pTmpDVR1
= static_cast<const
317 formula::SingleVectorRefToken
*>(vSubArguments
[dataCol
]->
319 ss
<< " tmp"<<dataCol
<<"=";
320 ss
<< vSubArguments
[dataCol
]->GenSlidingWindowDeclRef()<<";\n";
321 ss
<< " if(gid0>="<<pTmpDVR1
->GetArrayLength()<<" ||isNan(";
322 ss
<< "tmp"<<dataCol
<<"))\n";
323 ss
<< " tmp"<<dataCol
<<"=0;\n";
327 int conditionCol
= 0;
328 int conditionRow
= 0;
329 if(vSubArguments
[dataCol
+ 1]->GetFormulaToken()->GetType() ==
330 formula::svDoubleVectorRef
)
332 formula::FormulaToken
*tmpCur
= vSubArguments
[dataCol
+ 1]->
334 const formula::DoubleVectorRefToken
*pCurDVR2
= static_cast<const
335 formula::DoubleVectorRefToken
*>(tmpCur
);
336 conditionCol
= pCurDVR2
->GetArrays().size();
337 conditionRow
= pCurDVR2
->GetArrayLength();
342 if(dataCol
!=conditionCol
)
344 if(dataCol
> 0 && dataRow
> 0)
346 formula::FormulaToken
*tmpCur1
= vSubArguments
[0]->GetFormulaToken();
347 formula::FormulaToken
*tmpCur2
= vSubArguments
[dataCol
+ 1]->
349 const formula::DoubleVectorRefToken
*pCurDVR1
= static_cast<const
350 formula::DoubleVectorRefToken
*>(tmpCur1
);
351 const formula::DoubleVectorRefToken
*pCurDVR2
= static_cast<const
352 formula::DoubleVectorRefToken
*>(tmpCur2
);
354 if(pCurDVR1
->IsStartFixed() && pCurDVR1
->IsEndFixed() &&
355 pCurDVR2
->IsStartFixed() && pCurDVR2
->IsEndFixed())
357 ss
<< " int i,j,p;\n";
358 ss
<< " bool flag;\n";
359 ss
<< " for(p = 1;p < " << dataRow
<< ";++p)\n";
362 for(int i
= 0; i
< dataCol
; ++i
){
363 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
364 formula::svDoubleVectorRef
)
366 ss
<< " tmp"<<i
<<"=";
367 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
368 ss
<< " if(isNan(tmp"<<i
<<"))\n";
369 ss
<<" tmp"<<i
<<" = 0;\n";
371 ss
<< " flag = false;\n";
372 ss
<< " for(j = 1; j < " << conditionRow
<< ";++j)\n";
375 ss
<< " if (flag)\n";
378 for(int i
= dataCol
+ 1; i
< dataCol
+ 1 + conditionCol
; ++i
){
379 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
380 formula::svDoubleVectorRef
)
382 ss
<< " tmp"<<i
<<"=";
383 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
384 ss
<< " if(!isNan(tmp"<<i
<<")){\n";
385 ss
<< " if(tmp"<<(i
-dataCol
-1)<<"!=tmp";
387 ss
<< " continue;\n";
391 ss
<< " flag=true;\n";
394 ss
<< " if (flag){\n";
395 for(int i
= 0; i
< dataCol
; ++i
){
396 ss
<< " if(tmp"<<dataCol
<<"=="<<(i
+1)<<"){\n";
397 ss
<< " value=tmp"<<i
<<";\n";
400 ss
<< " product*=value;\n";
405 ss
<< "product = -1;\n";
408 ss
<< "product = -1;\n";
409 ss
<< " return product;\n";
413 void OpDaverage::GenSlidingWindowFunction(std::stringstream
&ss
,
414 const std::string
&sSymName
, SubArguments
&vSubArguments
)
416 ss
<< "\ndouble " << sSymName
;
417 ss
<< "_"<< BinFuncName() <<"(";
418 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
422 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
425 ss
<< " int gid0=get_global_id(0);\n";
426 ss
<< " double sum = 0;\n";
427 ss
<< " int count = 0;\n";
428 ss
<< " double value =0;\n";
429 GenTmpVariables(ss
,vSubArguments
);
432 if(vSubArguments
[0]->GetFormulaToken()->GetType() ==
433 formula::svDoubleVectorRef
)
435 formula::FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
436 const formula::DoubleVectorRefToken
*pCurDVR1
= static_cast<const
437 formula::DoubleVectorRefToken
*>(tmpCur
);
438 dataCol
= pCurDVR1
->GetArrays().size();
439 dataRow
= pCurDVR1
->GetArrayLength();
443 if(vSubArguments
[dataCol
]->GetFormulaToken()->GetType() ==
444 formula::svSingleVectorRef
)
446 const formula::SingleVectorRefToken
*pTmpDVR1
= static_cast<const
447 formula::SingleVectorRefToken
*>(vSubArguments
[dataCol
]->
449 ss
<< " tmp"<<dataCol
<<"=";
450 ss
<< vSubArguments
[dataCol
]->GenSlidingWindowDeclRef()<<";\n";
451 ss
<< " if(gid0>="<<pTmpDVR1
->GetArrayLength()<<" ||isNan(";
452 ss
<< "tmp"<<dataCol
<<"))\n";
453 ss
<< " tmp"<<dataCol
<<"=0;\n";
457 int conditionCol
= 0;
458 int conditionRow
= 0;
459 if(vSubArguments
[dataCol
+ 1]->GetFormulaToken()->GetType() ==
460 formula::svDoubleVectorRef
)
462 formula::FormulaToken
*tmpCur
= vSubArguments
[dataCol
+ 1]->
464 const formula::DoubleVectorRefToken
*pCurDVR2
= static_cast<const
465 formula::DoubleVectorRefToken
*>(tmpCur
);
466 conditionCol
= pCurDVR2
->GetArrays().size();
467 conditionRow
= pCurDVR2
->GetArrayLength();
472 if(dataCol
!=conditionCol
)
474 if(dataCol
> 0 && dataRow
> 0)
476 formula::FormulaToken
*tmpCur1
= vSubArguments
[0]->GetFormulaToken();
477 formula::FormulaToken
*tmpCur2
= vSubArguments
[dataCol
+ 1]->
479 const formula::DoubleVectorRefToken
*pCurDVR1
= static_cast<const
480 formula::DoubleVectorRefToken
*>(tmpCur1
);
481 const formula::DoubleVectorRefToken
*pCurDVR2
= static_cast<const
482 formula::DoubleVectorRefToken
*>(tmpCur2
);
484 if(pCurDVR1
->IsStartFixed() && pCurDVR1
->IsEndFixed() &&
485 pCurDVR2
->IsStartFixed() && pCurDVR2
->IsEndFixed())
487 ss
<< " int i,j,p;\n";
488 ss
<< " bool flag;\n";
490 ss
<< " for(p = 1;p < " << dataRow
<< ";++p)\n";
493 for(int i
= 0; i
< dataCol
; ++i
){
494 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
495 formula::svDoubleVectorRef
)
497 ss
<< " tmp"<<i
<<"=";
498 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
499 ss
<< " if(isNan(tmp"<<i
<<"))\n";
500 ss
<<" tmp"<<i
<<" = 0;\n";
502 ss
<< " flag = false;\n";
503 ss
<< " for(j = 1; j < " << conditionRow
<< ";++j)\n";
506 ss
<< " if (flag)\n";
509 for(int i
= dataCol
+ 1; i
< dataCol
+ 1 + conditionCol
; ++i
){
510 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
511 formula::svDoubleVectorRef
)
513 ss
<< " tmp"<<i
<<"=";
514 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
515 ss
<< " if(!isNan(tmp"<<i
<<")){\n";
516 ss
<< " if(tmp"<<(i
-dataCol
-1)<<"!=tmp";
518 ss
<< " continue;\n";
522 ss
<< " flag=true;\n";
525 ss
<< " if (flag){\n";
527 for(int i
= 0; i
< dataCol
; ++i
){
528 ss
<< " if(tmp"<<dataCol
<<"=="<<(i
+1)<<"){\n";
529 ss
<< " value=tmp"<<i
<<";\n";
532 ss
<< " sum+=value;\n";
541 ss
<< " if(count==0)\n";
542 ss
<< " return 0;\n";
543 ss
<< " return sum/count;\n";
547 void OpDstdev::GenSlidingWindowFunction(std::stringstream
&ss
,
548 const std::string
&sSymName
, SubArguments
&vSubArguments
)
550 ss
<< "\ndouble " << sSymName
;
551 ss
<< "_"<< BinFuncName() <<"(";
552 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
556 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
559 ss
<< " int gid0=get_global_id(0);\n";
560 ss
<< " double var = 0;\n";
561 ss
<< " double mean = 0;\n";
562 ss
<< " double value =0;\n";
563 ss
<< " int count = 0;\n";
564 GenTmpVariables(ss
,vSubArguments
);
567 if(vSubArguments
[0]->GetFormulaToken()->GetType() ==
568 formula::svDoubleVectorRef
)
570 formula::FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
571 const formula::DoubleVectorRefToken
*pCurDVR1
= static_cast<const
572 formula::DoubleVectorRefToken
*>(tmpCur
);
573 dataCol
= pCurDVR1
->GetArrays().size();
574 dataRow
= pCurDVR1
->GetArrayLength();
578 if(vSubArguments
[dataCol
]->GetFormulaToken()->GetType() ==
579 formula::svSingleVectorRef
)
581 const formula::SingleVectorRefToken
*pTmpDVR1
= static_cast<const
582 formula::SingleVectorRefToken
*>(vSubArguments
[dataCol
]->
584 ss
<< " tmp"<<dataCol
<<"=";
585 ss
<< vSubArguments
[dataCol
]->GenSlidingWindowDeclRef()<<";\n";
586 ss
<< " if(gid0>="<<pTmpDVR1
->GetArrayLength()<<" ||isNan(";
587 ss
<< "tmp"<<dataCol
<<"))\n";
588 ss
<< " tmp"<<dataCol
<<"=0;\n";
592 int conditionCol
= 0;
593 int conditionRow
= 0;
594 if(vSubArguments
[dataCol
+ 1]->GetFormulaToken()->GetType() ==
595 formula::svDoubleVectorRef
)
597 formula::FormulaToken
*tmpCur
= vSubArguments
[dataCol
+ 1]->
599 const formula::DoubleVectorRefToken
*pCurDVR2
= static_cast<const
600 formula::DoubleVectorRefToken
*>(tmpCur
);
601 conditionCol
= pCurDVR2
->GetArrays().size();
602 conditionRow
= pCurDVR2
->GetArrayLength();
607 if(dataCol
!=conditionCol
)
609 if(dataCol
> 0 && dataRow
> 0)
611 formula::FormulaToken
*tmpCur1
= vSubArguments
[0]->GetFormulaToken();
612 formula::FormulaToken
*tmpCur2
= vSubArguments
[dataCol
+ 1]->
614 const formula::DoubleVectorRefToken
*pCurDVR1
= static_cast<const
615 formula::DoubleVectorRefToken
*>(tmpCur1
);
616 const formula::DoubleVectorRefToken
*pCurDVR2
= static_cast<const
617 formula::DoubleVectorRefToken
*>(tmpCur2
);
619 if(pCurDVR1
->IsStartFixed() && pCurDVR1
->IsEndFixed() &&
620 pCurDVR2
->IsStartFixed() && pCurDVR2
->IsEndFixed())
622 ss
<< " int i,j,p;\n";
623 ss
<< " bool flag;\n";
625 ss
<< " for(p = 1;p < " << dataRow
<< ";++p)\n";
628 for(int i
= 0; i
< dataCol
; ++i
){
629 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
630 formula::svDoubleVectorRef
)
632 ss
<< " tmp"<<i
<<"=";
633 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
634 ss
<< " if(isNan(tmp"<<i
<<"))\n";
635 ss
<<" tmp"<<i
<<" = 0;\n";
637 ss
<< " flag = false;\n";
638 ss
<< " for(j = 1; j < " << conditionRow
<< ";++j)\n";
641 ss
<< " if (flag)\n";
644 for(int i
= dataCol
+ 1; i
< dataCol
+ 1 + conditionCol
; ++i
){
645 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
646 formula::svDoubleVectorRef
)
648 ss
<< " tmp"<<i
<<"=";
649 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
650 ss
<< " if(!isNan(tmp"<<i
<<")){\n";
651 ss
<< " if(tmp"<<(i
-dataCol
-1)<<"!=tmp";
653 ss
<< " continue;\n";
657 ss
<< " flag=true;\n";
660 ss
<< " if (flag){\n";
662 for(int i
= 0; i
< dataCol
; ++i
){
663 ss
<< " if(tmp"<<dataCol
<<"=="<<(i
+1)<<"){\n";
664 ss
<< " value=tmp"<<i
<<";\n";
667 ss
<< " mean+=value;\n";
671 ss
<< " if(count<=1)\n";
672 ss
<< " return 0;\n";
674 ss
<< " mean/=count;\n";
676 ss
<< " for(p = 1;p < " << dataRow
<< ";++p)\n";
679 for(int i
= 0; i
< dataCol
; ++i
){
680 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
681 formula::svDoubleVectorRef
)
683 ss
<< " tmp"<<i
<<"=";
684 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
685 ss
<< " if(isNan(tmp"<<i
<<"))\n";
686 ss
<<" tmp"<<i
<<" = 0;\n";
688 ss
<< " flag = false;\n";
689 ss
<< " for(j = 1; j < " << conditionRow
<< ";++j)\n";
692 ss
<< " if (flag)\n";
695 for(int i
= dataCol
+ 1; i
< dataCol
+ 1 + conditionCol
; ++i
){
696 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
697 formula::svDoubleVectorRef
)
699 ss
<< " tmp"<<i
<<"=";
700 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
701 ss
<< " if(!isNan(tmp"<<i
<<")){\n";
702 ss
<< " if(tmp"<<(i
-dataCol
-1)<<"!=tmp";
704 ss
<< " continue;\n";
708 ss
<< " flag=true;\n";
711 ss
<< " if (flag){\n";
712 for(int i
= 0; i
< dataCol
; ++i
){
713 ss
<< " if(tmp"<<dataCol
<<"=="<<(i
+1)<<"){\n";
714 ss
<< " value=tmp"<<i
<<";\n";
717 ss
<< " var+=pow(mean-value,2);\n";
721 ss
<< " var = sqrt( var/(count-1) );\n";
728 ss
<< " return var;\n";
732 void OpDstdevp::GenSlidingWindowFunction(std::stringstream
&ss
,
733 const std::string
&sSymName
, SubArguments
&vSubArguments
)
735 ss
<< "\ndouble " << sSymName
;
736 ss
<< "_"<< BinFuncName() <<"(";
737 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
741 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
744 ss
<< " int gid0=get_global_id(0);\n";
745 ss
<< " double var = 0;\n";
746 ss
<< " double mean = 0;\n";
747 ss
<< " double value =0;\n";
748 ss
<< " int count = 0;\n";
749 GenTmpVariables(ss
,vSubArguments
);
752 if(vSubArguments
[0]->GetFormulaToken()->GetType() ==
753 formula::svDoubleVectorRef
)
755 formula::FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
756 const formula::DoubleVectorRefToken
*pCurDVR1
= static_cast<const
757 formula::DoubleVectorRefToken
*>(tmpCur
);
758 dataCol
= pCurDVR1
->GetArrays().size();
759 dataRow
= pCurDVR1
->GetArrayLength();
763 if(vSubArguments
[dataCol
]->GetFormulaToken()->GetType() ==
764 formula::svSingleVectorRef
)
766 const formula::SingleVectorRefToken
*pTmpDVR1
= static_cast<const
767 formula::SingleVectorRefToken
*>(vSubArguments
[dataCol
]->
769 ss
<< " tmp"<<dataCol
<<"=";
770 ss
<< vSubArguments
[dataCol
]->GenSlidingWindowDeclRef()<<";\n";
771 ss
<< " if(gid0>="<<pTmpDVR1
->GetArrayLength()<<" ||isNan(";
772 ss
<< "tmp"<<dataCol
<<"))\n";
773 ss
<< " tmp"<<dataCol
<<"=0;\n";
777 int conditionCol
= 0;
778 int conditionRow
= 0;
779 if(vSubArguments
[dataCol
+ 1]->GetFormulaToken()->GetType() ==
780 formula::svDoubleVectorRef
)
782 formula::FormulaToken
*tmpCur
= vSubArguments
[dataCol
+ 1]->
784 const formula::DoubleVectorRefToken
*pCurDVR2
= static_cast<const
785 formula::DoubleVectorRefToken
*>(tmpCur
);
786 conditionCol
= pCurDVR2
->GetArrays().size();
787 conditionRow
= pCurDVR2
->GetArrayLength();
792 if(dataCol
!=conditionCol
)
794 if(dataCol
> 0 && dataRow
> 0)
796 formula::FormulaToken
*tmpCur1
= vSubArguments
[0]->GetFormulaToken();
797 formula::FormulaToken
*tmpCur2
= vSubArguments
[dataCol
+ 1]->
799 const formula::DoubleVectorRefToken
*pCurDVR1
= static_cast<const
800 formula::DoubleVectorRefToken
*>(tmpCur1
);
801 const formula::DoubleVectorRefToken
*pCurDVR2
= static_cast<const
802 formula::DoubleVectorRefToken
*>(tmpCur2
);
804 if(pCurDVR1
->IsStartFixed() && pCurDVR1
->IsEndFixed() &&
805 pCurDVR2
->IsStartFixed() && pCurDVR2
->IsEndFixed())
807 ss
<< " int i,j,p;\n";
808 ss
<< " bool flag;\n";
810 ss
<< " for(p = 1;p < " << dataRow
<< ";++p)\n";
813 for(int i
= 0; i
< dataCol
; ++i
){
814 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
815 formula::svDoubleVectorRef
)
817 ss
<< " tmp"<<i
<<"=";
818 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
819 ss
<< " if(isNan(tmp"<<i
<<"))\n";
820 ss
<<" tmp"<<i
<<" = 0;\n";
822 ss
<< " flag = false;\n";
823 ss
<< " for(j = 1; j < " << conditionRow
<< ";++j)\n";
826 ss
<< " if (flag)\n";
829 for(int i
= dataCol
+ 1; i
< dataCol
+ 1 + conditionCol
; ++i
){
830 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
831 formula::svDoubleVectorRef
)
833 ss
<< " tmp"<<i
<<"=";
834 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
835 ss
<< " if(!isNan(tmp"<<i
<<")){\n";
836 ss
<< " if(tmp"<<(i
-dataCol
-1)<<"!=tmp";
838 ss
<< " continue;\n";
842 ss
<< " flag=true;\n";
845 ss
<< " if (flag){\n";
847 for(int i
= 0; i
< dataCol
; ++i
){
848 ss
<< " if(tmp"<<dataCol
<<"=="<<(i
+1)<<"){\n";
849 ss
<< " value=tmp"<<i
<<";\n";
852 ss
<< " mean+=value;\n";
856 ss
<< " if(count<=1)\n";
857 ss
<< " return 0;\n";
859 ss
<< " mean/=count;\n";
861 ss
<< " for(p = 1;p < " << dataRow
<< ";++p)\n";
864 for(int i
= 0; i
< dataCol
; ++i
){
865 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
866 formula::svDoubleVectorRef
)
868 ss
<< " tmp"<<i
<<"=";
869 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
870 ss
<< " if(isNan(tmp"<<i
<<"))\n";
871 ss
<<" tmp"<<i
<<" = 0;\n";
873 ss
<< " flag = false;\n";
874 ss
<< " for(j = 1; j < " << conditionRow
<< ";++j)\n";
877 ss
<< " if (flag)\n";
880 for(int i
= dataCol
+ 1; i
< dataCol
+ 1 + conditionCol
; ++i
){
881 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
882 formula::svDoubleVectorRef
)
884 ss
<< " tmp"<<i
<<"=";
885 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
886 ss
<< " if(!isNan(tmp"<<i
<<")){\n";
887 ss
<< " if(tmp"<<(i
-dataCol
-1)<<"!=tmp";
889 ss
<< " continue;\n";
893 ss
<< " flag=true;\n";
896 ss
<< " if (flag){\n";
897 for(int i
= 0; i
< dataCol
; ++i
){
898 ss
<< " if(tmp"<<dataCol
<<"=="<<(i
+1)<<"){\n";
899 ss
<< " value=tmp"<<i
<<";\n";
902 ss
<< " var+=pow(mean-value,2);\n";
906 ss
<< " var = sqrt( var/count );\n";
913 ss
<< " return var;\n";
917 void OpDsum::GenSlidingWindowFunction(std::stringstream
&ss
,
918 const std::string
&sSymName
, SubArguments
&vSubArguments
)
920 ss
<< "\ndouble " << sSymName
;
921 ss
<< "_"<< BinFuncName() <<"(";
922 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
926 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
929 ss
<< " int gid0=get_global_id(0);\n";
930 ss
<< " double sum = 0;\n";
931 ss
<< " double value =0;\n";
932 GenTmpVariables(ss
,vSubArguments
);
935 if(vSubArguments
[0]->GetFormulaToken()->GetType() ==
936 formula::svDoubleVectorRef
)
938 formula::FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
939 const formula::DoubleVectorRefToken
*pCurDVR1
= static_cast<const
940 formula::DoubleVectorRefToken
*>(tmpCur
);
941 dataCol
= pCurDVR1
->GetArrays().size();
942 dataRow
= pCurDVR1
->GetArrayLength();
946 if(vSubArguments
[dataCol
]->GetFormulaToken()->GetType() ==
947 formula::svSingleVectorRef
)
949 const formula::SingleVectorRefToken
*pTmpDVR1
= static_cast<const
950 formula::SingleVectorRefToken
*>(vSubArguments
[dataCol
]->
952 ss
<< " tmp"<<dataCol
<<"=";
953 ss
<< vSubArguments
[dataCol
]->GenSlidingWindowDeclRef()<<";\n";
954 ss
<< " if(gid0>="<<pTmpDVR1
->GetArrayLength()<<" ||isNan(";
955 ss
<< "tmp"<<dataCol
<<"))\n";
956 ss
<< " tmp"<<dataCol
<<"=0;\n";
960 int conditionCol
= 0;
961 int conditionRow
= 0;
962 if(vSubArguments
[dataCol
+ 1]->GetFormulaToken()->GetType() ==
963 formula::svDoubleVectorRef
)
965 formula::FormulaToken
*tmpCur
= vSubArguments
[dataCol
+ 1]->
967 const formula::DoubleVectorRefToken
*pCurDVR2
= static_cast<const
968 formula::DoubleVectorRefToken
*>(tmpCur
);
969 conditionCol
= pCurDVR2
->GetArrays().size();
970 conditionRow
= pCurDVR2
->GetArrayLength();
975 if(dataCol
!=conditionCol
)
977 if(dataCol
> 0 && dataRow
> 0)
979 formula::FormulaToken
*tmpCur1
= vSubArguments
[0]->GetFormulaToken();
980 formula::FormulaToken
*tmpCur2
= vSubArguments
[dataCol
+ 1]->
982 const formula::DoubleVectorRefToken
*pCurDVR1
= static_cast<const
983 formula::DoubleVectorRefToken
*>(tmpCur1
);
984 const formula::DoubleVectorRefToken
*pCurDVR2
= static_cast<const
985 formula::DoubleVectorRefToken
*>(tmpCur2
);
987 if(pCurDVR1
->IsStartFixed() && pCurDVR1
->IsEndFixed() &&
988 pCurDVR2
->IsStartFixed() && pCurDVR2
->IsEndFixed())
990 ss
<< " int i,j,p;\n";
991 ss
<< " bool flag;\n";
993 ss
<< " for(p = 1;p < " << dataRow
<< ";++p)\n";
996 for(int i
= 0; i
< dataCol
; ++i
){
997 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
998 formula::svDoubleVectorRef
)
1000 ss
<< " tmp"<<i
<<"=";
1001 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
1002 ss
<< " if(isNan(tmp"<<i
<<"))\n";
1003 ss
<<" tmp"<<i
<<" = 0;\n";
1005 ss
<< " flag = false;\n";
1006 ss
<< " for(j = 1; j < " << conditionRow
<< ";++j)\n";
1009 ss
<< " if (flag)\n";
1012 for(int i
= dataCol
+ 1; i
< dataCol
+ 1 + conditionCol
; ++i
){
1013 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
1014 formula::svDoubleVectorRef
)
1016 ss
<< " tmp"<<i
<<"=";
1017 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
1018 ss
<< " if(!isNan(tmp"<<i
<<")){\n";
1019 ss
<< " if(tmp"<<(i
-dataCol
-1)<<"!=tmp";
1021 ss
<< " continue;\n";
1025 ss
<< " flag=true;\n";
1028 ss
<< " if (flag){\n";
1029 for(int i
= 0; i
< dataCol
; ++i
){
1030 ss
<< " if(tmp"<<dataCol
<<"=="<<(i
+1)<<"){\n";
1031 ss
<< " value=tmp"<<i
<<";\n";
1034 ss
<< " sum+=value;\n";
1039 ss
<< "sum = -1;\n";
1042 ss
<< "sum = -1;\n";
1043 ss
<< " return sum;\n";
1047 void OpDvar::GenSlidingWindowFunction(std::stringstream
&ss
,
1048 const std::string
&sSymName
, SubArguments
&vSubArguments
)
1050 ss
<< "\ndouble " << sSymName
;
1051 ss
<< "_"<< BinFuncName() <<"(";
1052 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1056 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1059 ss
<< " int gid0=get_global_id(0);\n";
1060 ss
<< " double var = 0;\n";
1061 ss
<< " double mean = 0;\n";
1062 ss
<< " double value =0;\n";
1063 ss
<< " int count = 0;\n";
1064 GenTmpVariables(ss
,vSubArguments
);
1067 if(vSubArguments
[0]->GetFormulaToken()->GetType() ==
1068 formula::svDoubleVectorRef
)
1070 formula::FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
1071 const formula::DoubleVectorRefToken
*pCurDVR1
= static_cast<const
1072 formula::DoubleVectorRefToken
*>(tmpCur
);
1073 dataCol
= pCurDVR1
->GetArrays().size();
1074 dataRow
= pCurDVR1
->GetArrayLength();
1078 if(vSubArguments
[dataCol
]->GetFormulaToken()->GetType() ==
1079 formula::svSingleVectorRef
)
1081 const formula::SingleVectorRefToken
*pTmpDVR1
= static_cast<const
1082 formula::SingleVectorRefToken
*>(vSubArguments
[dataCol
]->
1084 ss
<< " tmp"<<dataCol
<<"=";
1085 ss
<< vSubArguments
[dataCol
]->GenSlidingWindowDeclRef()<<";\n";
1086 ss
<< " if(gid0>="<<pTmpDVR1
->GetArrayLength()<<" ||isNan(";
1087 ss
<< "tmp"<<dataCol
<<"))\n";
1088 ss
<< " tmp"<<dataCol
<<"=0;\n";
1092 int conditionCol
= 0;
1093 int conditionRow
= 0;
1094 if(vSubArguments
[dataCol
+ 1]->GetFormulaToken()->GetType() ==
1095 formula::svDoubleVectorRef
)
1097 formula::FormulaToken
*tmpCur
= vSubArguments
[dataCol
+ 1]->
1099 const formula::DoubleVectorRefToken
*pCurDVR2
= static_cast<const
1100 formula::DoubleVectorRefToken
*>(tmpCur
);
1101 conditionCol
= pCurDVR2
->GetArrays().size();
1102 conditionRow
= pCurDVR2
->GetArrayLength();
1107 if(dataCol
!=conditionCol
)
1109 if(dataCol
> 0 && dataRow
> 0)
1111 formula::FormulaToken
*tmpCur1
= vSubArguments
[0]->GetFormulaToken();
1112 formula::FormulaToken
*tmpCur2
= vSubArguments
[dataCol
+ 1]->
1114 const formula::DoubleVectorRefToken
*pCurDVR1
= static_cast<const
1115 formula::DoubleVectorRefToken
*>(tmpCur1
);
1116 const formula::DoubleVectorRefToken
*pCurDVR2
= static_cast<const
1117 formula::DoubleVectorRefToken
*>(tmpCur2
);
1119 if(pCurDVR1
->IsStartFixed() && pCurDVR1
->IsEndFixed() &&
1120 pCurDVR2
->IsStartFixed() && pCurDVR2
->IsEndFixed())
1122 ss
<< " int i,j,p;\n";
1123 ss
<< " bool flag;\n";
1125 ss
<< " for(p = 1;p < " << dataRow
<< ";++p)\n";
1128 for(int i
= 0; i
< dataCol
; ++i
){
1129 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
1130 formula::svDoubleVectorRef
)
1132 ss
<< " tmp"<<i
<<"=";
1133 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
1134 ss
<< " if(isNan(tmp"<<i
<<"))\n";
1135 ss
<<" tmp"<<i
<<" = 0;\n";
1137 ss
<< " flag = false;\n";
1138 ss
<< " for(j = 1; j < " << conditionRow
<< ";++j)\n";
1141 ss
<< " if (flag)\n";
1144 for(int i
= dataCol
+ 1; i
< dataCol
+ 1 + conditionCol
; ++i
){
1145 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
1146 formula::svDoubleVectorRef
)
1148 ss
<< " tmp"<<i
<<"=";
1149 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
1150 ss
<< " if(!isNan(tmp"<<i
<<")){\n";
1151 ss
<< " if(tmp"<<(i
-dataCol
-1)<<"!=tmp";
1153 ss
<< " continue;\n";
1157 ss
<< " flag=true;\n";
1160 ss
<< " if (flag){\n";
1161 ss
<< " count++;\n";
1162 for(int i
= 0; i
< dataCol
; ++i
){
1163 ss
<< " if(tmp"<<dataCol
<<"=="<<(i
+1)<<"){\n";
1164 ss
<< " value=tmp"<<i
<<";\n";
1167 ss
<< " mean+=value;\n";
1171 ss
<< " if(count<=1)\n";
1172 ss
<< " return 0;\n";
1174 ss
<< " mean/=count;\n";
1176 ss
<< " for(p = 1;p < " << dataRow
<< ";++p)\n";
1179 for(int i
= 0; i
< dataCol
; ++i
){
1180 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
1181 formula::svDoubleVectorRef
)
1183 ss
<< " tmp"<<i
<<"=";
1184 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
1185 ss
<< " if(isNan(tmp"<<i
<<"))\n";
1186 ss
<<" tmp"<<i
<<" = 0;\n";
1188 ss
<< " flag = false;\n";
1189 ss
<< " for(j = 1; j < " << conditionRow
<< ";++j)\n";
1192 ss
<< " if (flag)\n";
1195 for(int i
= dataCol
+ 1; i
< dataCol
+ 1 + conditionCol
; ++i
){
1196 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
1197 formula::svDoubleVectorRef
)
1199 ss
<< " tmp"<<i
<<"=";
1200 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
1201 ss
<< " if(!isNan(tmp"<<i
<<")){\n";
1202 ss
<< " if(tmp"<<(i
-dataCol
-1)<<"!=tmp";
1204 ss
<< " continue;\n";
1208 ss
<< " flag=true;\n";
1211 ss
<< " if (flag){\n";
1212 for(int i
= 0; i
< dataCol
; ++i
){
1213 ss
<< " if(tmp"<<dataCol
<<"=="<<(i
+1)<<"){\n";
1214 ss
<< " value=tmp"<<i
<<";\n";
1217 ss
<< " var+=pow(mean-value,2);\n";
1221 ss
<< " var = var/(count-1);\n";
1224 ss
<< "var = -1;\n";
1227 ss
<< "var = -1;\n";
1228 ss
<< " return var;\n";
1232 void OpDvarp::GenSlidingWindowFunction(std::stringstream
&ss
,
1233 const std::string
&sSymName
, SubArguments
&vSubArguments
)
1235 ss
<< "\ndouble " << sSymName
;
1236 ss
<< "_"<< BinFuncName() <<"(";
1237 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1241 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1244 ss
<< " int gid0=get_global_id(0);\n";
1245 ss
<< " double var = 0;\n";
1246 ss
<< " double mean = 0;\n";
1247 ss
<< " double value =0;\n";
1248 ss
<< " int count = 0;\n";
1249 GenTmpVariables(ss
,vSubArguments
);
1252 if(vSubArguments
[0]->GetFormulaToken()->GetType() ==
1253 formula::svDoubleVectorRef
)
1255 formula::FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
1256 const formula::DoubleVectorRefToken
*pCurDVR1
= static_cast<const
1257 formula::DoubleVectorRefToken
*>(tmpCur
);
1258 dataCol
= pCurDVR1
->GetArrays().size();
1259 dataRow
= pCurDVR1
->GetArrayLength();
1263 if(vSubArguments
[dataCol
]->GetFormulaToken()->GetType() ==
1264 formula::svSingleVectorRef
)
1266 const formula::SingleVectorRefToken
*pTmpDVR1
= static_cast<const
1267 formula::SingleVectorRefToken
*>(vSubArguments
[dataCol
]->
1269 ss
<< " tmp"<<dataCol
<<"=";
1270 ss
<< vSubArguments
[dataCol
]->GenSlidingWindowDeclRef()<<";\n";
1271 ss
<< " if(gid0>="<<pTmpDVR1
->GetArrayLength()<<" ||isNan(";
1272 ss
<< "tmp"<<dataCol
<<"))\n";
1273 ss
<< " tmp"<<dataCol
<<"=0;\n";
1277 int conditionCol
= 0;
1278 int conditionRow
= 0;
1279 if(vSubArguments
[dataCol
+ 1]->GetFormulaToken()->GetType() ==
1280 formula::svDoubleVectorRef
)
1282 formula::FormulaToken
*tmpCur
= vSubArguments
[dataCol
+ 1]->
1284 const formula::DoubleVectorRefToken
*pCurDVR2
= static_cast<const
1285 formula::DoubleVectorRefToken
*>(tmpCur
);
1286 conditionCol
= pCurDVR2
->GetArrays().size();
1287 conditionRow
= pCurDVR2
->GetArrayLength();
1292 if(dataCol
!=conditionCol
)
1294 if(dataCol
> 0 && dataRow
> 0)
1296 formula::FormulaToken
*tmpCur1
= vSubArguments
[0]->GetFormulaToken();
1297 formula::FormulaToken
*tmpCur2
= vSubArguments
[dataCol
+ 1]->
1299 const formula::DoubleVectorRefToken
*pCurDVR1
= static_cast<const
1300 formula::DoubleVectorRefToken
*>(tmpCur1
);
1301 const formula::DoubleVectorRefToken
*pCurDVR2
= static_cast<const
1302 formula::DoubleVectorRefToken
*>(tmpCur2
);
1304 if(pCurDVR1
->IsStartFixed() && pCurDVR1
->IsEndFixed() &&
1305 pCurDVR2
->IsStartFixed() && pCurDVR2
->IsEndFixed())
1307 ss
<< " int i,j,p;\n";
1308 ss
<< " bool flag;\n";
1310 ss
<< " for(p = 1;p < " << dataRow
<< ";++p)\n";
1313 for(int i
= 0; i
< dataCol
; ++i
){
1314 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
1315 formula::svDoubleVectorRef
)
1317 ss
<< " tmp"<<i
<<"=";
1318 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
1319 ss
<< " if(isNan(tmp"<<i
<<"))\n";
1320 ss
<<" tmp"<<i
<<" = 0;\n";
1322 ss
<< " flag = false;\n";
1323 ss
<< " for(j = 1; j < " << conditionRow
<< ";++j)\n";
1326 ss
<< " if (flag)\n";
1329 for(int i
= dataCol
+ 1; i
< dataCol
+ 1 + conditionCol
; ++i
){
1330 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
1331 formula::svDoubleVectorRef
)
1333 ss
<< " tmp"<<i
<<"=";
1334 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
1335 ss
<< " if(!isNan(tmp"<<i
<<")){\n";
1336 ss
<< " if(tmp"<<(i
-dataCol
-1)<<"!=tmp";
1338 ss
<< " continue;\n";
1342 ss
<< " flag=true;\n";
1345 ss
<< " if (flag){\n";
1346 ss
<< " count++;\n";
1347 for(int i
= 0; i
< dataCol
; ++i
){
1348 ss
<< " if(tmp"<<dataCol
<<"=="<<(i
+1)<<"){\n";
1349 ss
<< " value=tmp"<<i
<<";\n";
1352 ss
<< " mean+=value;\n";
1356 ss
<< " if(count<=0)\n";
1357 ss
<< " return 0;\n";
1359 ss
<< " mean/=count;\n";
1361 ss
<< " for(p = 1;p < " << dataRow
<< ";++p)\n";
1364 for(int i
= 0; i
< dataCol
; ++i
){
1365 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
1366 formula::svDoubleVectorRef
)
1368 ss
<< " tmp"<<i
<<"=";
1369 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
1370 ss
<< " if(isNan(tmp"<<i
<<"))\n";
1371 ss
<<" tmp"<<i
<<" = 0;\n";
1373 ss
<< " flag = false;\n";
1374 ss
<< " for(j = 1; j < " << conditionRow
<< ";++j)\n";
1377 ss
<< " if (flag)\n";
1380 for(int i
= dataCol
+ 1; i
< dataCol
+ 1 + conditionCol
; ++i
){
1381 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
1382 formula::svDoubleVectorRef
)
1384 ss
<< " tmp"<<i
<<"=";
1385 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
1386 ss
<< " if(!isNan(tmp"<<i
<<")){\n";
1387 ss
<< " if(tmp"<<(i
-dataCol
-1)<<"!=tmp";
1389 ss
<< " continue;\n";
1393 ss
<< " flag=true;\n";
1396 ss
<< " if (flag){\n";
1397 for(int i
= 0; i
< dataCol
; ++i
){
1398 ss
<< " if(tmp"<<dataCol
<<"=="<<(i
+1)<<"){\n";
1399 ss
<< " value=tmp"<<i
<<";\n";
1402 ss
<< " var+=pow(mean-value,2);\n";
1406 ss
<< " var = var/count;\n";
1409 ss
<< "var = -1;\n";
1412 ss
<< "var = -1;\n";
1413 ss
<< " return var;\n";
1417 void OpDcount::GenSlidingWindowFunction(std::stringstream
&ss
,
1418 const std::string
&sSymName
, SubArguments
&vSubArguments
)
1420 ss
<< "\ndouble " << sSymName
;
1421 ss
<< "_"<< BinFuncName() <<"(";
1422 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1426 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1429 ss
<< " int gid0=get_global_id(0);\n";
1430 ss
<< " double value=0;\n";
1431 ss
<< " int count = 0;\n";
1432 GenTmpVariables(ss
,vSubArguments
);
1435 if(vSubArguments
[0]->GetFormulaToken()->GetType() ==
1436 formula::svDoubleVectorRef
)
1438 formula::FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
1439 const formula::DoubleVectorRefToken
*pCurDVR1
= static_cast<const
1440 formula::DoubleVectorRefToken
*>(tmpCur
);
1441 dataCol
= pCurDVR1
->GetArrays().size();
1442 dataRow
= pCurDVR1
->GetArrayLength();
1446 if(vSubArguments
[dataCol
]->GetFormulaToken()->GetType() ==
1447 formula::svSingleVectorRef
)
1449 const formula::SingleVectorRefToken
*pTmpDVR1
= static_cast<const
1450 formula::SingleVectorRefToken
*>(vSubArguments
[dataCol
]
1451 ->GetFormulaToken());
1452 ss
<< " tmp"<<dataCol
<<"=";
1453 ss
<< vSubArguments
[dataCol
]->GenSlidingWindowDeclRef()<<";\n";
1454 ss
<< " if(gid0>="<<pTmpDVR1
->GetArrayLength()<<" ||isNan(";
1455 ss
<< "tmp"<<dataCol
<<"))\n";
1456 ss
<< " tmp"<<dataCol
<<"=DBL_MIN;\n";
1460 int conditionCol
= 0;
1461 int conditionRow
= 0;
1462 if(vSubArguments
[dataCol
+ 1]->GetFormulaToken()->GetType() ==
1463 formula::svDoubleVectorRef
)
1465 formula::FormulaToken
*tmpCur
= vSubArguments
[dataCol
+ 1]
1466 ->GetFormulaToken();
1467 const formula::DoubleVectorRefToken
*pCurDVR2
= static_cast<const
1468 formula::DoubleVectorRefToken
*>(tmpCur
);
1469 conditionCol
= pCurDVR2
->GetArrays().size();
1470 conditionRow
= pCurDVR2
->GetArrayLength();
1475 if(dataCol
!=conditionCol
)
1477 if(dataCol
> 0 && dataRow
> 0)
1479 formula::FormulaToken
*tmpCur1
= vSubArguments
[0]->GetFormulaToken();
1480 formula::FormulaToken
*tmpCur2
= vSubArguments
[dataCol
+ 1]
1481 ->GetFormulaToken();
1482 const formula::DoubleVectorRefToken
*pCurDVR1
= static_cast<const
1483 formula::DoubleVectorRefToken
*>(tmpCur1
);
1484 const formula::DoubleVectorRefToken
*pCurDVR2
= static_cast<const
1485 formula::DoubleVectorRefToken
*>(tmpCur2
);
1487 if(pCurDVR1
->IsStartFixed() && pCurDVR1
->IsEndFixed() &&
1488 pCurDVR2
->IsStartFixed() && pCurDVR2
->IsEndFixed())
1490 ss
<< " int i,j,p;\n";
1491 ss
<< " bool flag;\n";
1493 ss
<< " for(p = 1;p < " << dataRow
<< ";++p)\n";
1496 for(int i
= 0; i
< dataCol
; ++i
){
1497 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
1498 formula::svDoubleVectorRef
)
1500 ss
<< " tmp"<<i
<<"=";
1501 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
1502 ss
<< " if(isNan(tmp"<<i
<<"))\n";
1503 ss
<<" tmp"<<i
<<" = 0;\n";
1505 ss
<< " flag = false;\n";
1506 ss
<< " for(j = 1; j < " << conditionRow
<< ";++j)\n";
1509 ss
<< " if (flag)\n";
1512 for(int i
= dataCol
+ 1; i
< dataCol
+ 1 + conditionCol
; ++i
){
1513 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
1514 formula::svDoubleVectorRef
)
1516 ss
<< " tmp"<<i
<<"=";
1517 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
1518 ss
<< " if(!isNan(tmp"<<i
<<")){\n";
1519 ss
<< " if(tmp"<<(i
-dataCol
-1)<<"!=tmp";
1521 ss
<< " continue;\n";
1525 ss
<< " flag=true;\n";
1528 ss
<< " if (flag){\n";
1529 for(int i
= 0; i
< dataCol
; ++i
){
1530 ss
<< " if(tmp"<<dataCol
<<"=="<<(i
+1)<<"){\n";
1531 ss
<< " value=tmp"<<i
<<";\n";
1534 ss
<< " if(value > DBL_MIN)\n";
1535 ss
<< " count++;\n";
1540 ss
<< "count = -1;\n";
1543 ss
<< "count = -1;\n";
1544 ss
<< " return count;\n";
1548 void OpDcount2::GenSlidingWindowFunction(std::stringstream
&ss
,
1549 const std::string
&sSymName
, SubArguments
&vSubArguments
)
1551 ss
<< "\ndouble " << sSymName
;
1552 ss
<< "_"<< BinFuncName() <<"(";
1553 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
1557 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
1560 ss
<< " int gid0=get_global_id(0);\n";
1561 ss
<< " double value=0;\n";
1562 ss
<< " int count = 0;\n";
1563 GenTmpVariables(ss
,vSubArguments
);
1566 if(vSubArguments
[0]->GetFormulaToken()->GetType() ==
1567 formula::svDoubleVectorRef
)
1569 formula::FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
1570 const formula::DoubleVectorRefToken
*pCurDVR1
= static_cast<const
1571 formula::DoubleVectorRefToken
*>(tmpCur
);
1572 dataCol
= pCurDVR1
->GetArrays().size();
1573 dataRow
= pCurDVR1
->GetArrayLength();
1577 if(vSubArguments
[dataCol
]->GetFormulaToken()->GetType() ==
1578 formula::svSingleVectorRef
)
1580 const formula::SingleVectorRefToken
*pTmpDVR1
= static_cast<const
1581 formula::SingleVectorRefToken
*>(vSubArguments
[dataCol
]
1582 ->GetFormulaToken());
1583 ss
<< " tmp"<<dataCol
<<"=";
1584 ss
<< vSubArguments
[dataCol
]->GenSlidingWindowDeclRef()<<";\n";
1585 ss
<< " if(gid0>="<<pTmpDVR1
->GetArrayLength()<<" ||isNan(";
1586 ss
<< "tmp"<<dataCol
<<"))\n";
1587 ss
<< " tmp"<<dataCol
<<"=DBL_MIN;\n";
1591 int conditionCol
= 0;
1592 int conditionRow
= 0;
1593 if(vSubArguments
[dataCol
+ 1]->GetFormulaToken()->GetType() ==
1594 formula::svDoubleVectorRef
)
1596 formula::FormulaToken
*tmpCur
= vSubArguments
[dataCol
+ 1]->
1598 const formula::DoubleVectorRefToken
*pCurDVR2
= static_cast<const
1599 formula::DoubleVectorRefToken
*>(tmpCur
);
1600 conditionCol
= pCurDVR2
->GetArrays().size();
1601 conditionRow
= pCurDVR2
->GetArrayLength();
1606 if(dataCol
!=conditionCol
)
1608 if(dataCol
> 0 && dataRow
> 0)
1610 formula::FormulaToken
*tmpCur1
= vSubArguments
[0]->GetFormulaToken();
1611 formula::FormulaToken
*tmpCur2
= vSubArguments
[dataCol
+ 1]->
1613 const formula::DoubleVectorRefToken
*pCurDVR1
= static_cast<const
1614 formula::DoubleVectorRefToken
*>(tmpCur1
);
1615 const formula::DoubleVectorRefToken
*pCurDVR2
= static_cast<const
1616 formula::DoubleVectorRefToken
*>(tmpCur2
);
1618 if(pCurDVR1
->IsStartFixed() && pCurDVR1
->IsEndFixed() &&
1619 pCurDVR2
->IsStartFixed() && pCurDVR2
->IsEndFixed())
1621 ss
<< " int i,j,p;\n";
1622 ss
<< " bool flag;\n";
1624 ss
<< " for(p = 1;p < " << dataRow
<< ";++p)\n";
1627 for(int i
= 0; i
< dataCol
; ++i
){
1628 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
1629 formula::svDoubleVectorRef
)
1631 ss
<< " tmp"<<i
<<"=";
1632 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
1633 ss
<< " if(isNan(tmp"<<i
<<"))\n";
1634 ss
<<" tmp"<<i
<<" = 0;\n";
1636 ss
<< " flag = false;\n";
1637 ss
<< " for(j = 1; j < " << conditionRow
<< ";++j)\n";
1640 ss
<< " if (flag)\n";
1643 for(int i
= dataCol
+ 1; i
< dataCol
+ 1 + conditionCol
; ++i
){
1644 if(vSubArguments
[i
]->GetFormulaToken()->GetType() !=
1645 formula::svDoubleVectorRef
)
1647 ss
<< " tmp"<<i
<<"=";
1648 ss
<< vSubArguments
[i
]->GenSlidingWindowDeclRef()<<";\n";
1649 ss
<< " if(!isNan(tmp"<<i
<<")){\n";
1650 ss
<< " if(tmp"<<(i
-dataCol
-1)<<"!=tmp";
1652 ss
<< " continue;\n";
1656 ss
<< " flag=true;\n";
1659 ss
<< " if (flag){\n";
1660 for(int i
= 0; i
< dataCol
; ++i
){
1661 ss
<< " if(tmp"<<dataCol
<<"=="<<(i
+1)<<"){\n";
1662 ss
<< " value=tmp"<<i
<<";\n";
1665 ss
<< " if(value > DBL_MIN)\n";
1666 ss
<< " count++;\n";
1671 ss
<< "count = -1;\n";
1674 ss
<< "count = -1;\n";
1675 ss
<< " return count;\n";
1681 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */