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_array.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 using namespace formula
;
23 namespace sc
{ namespace opencl
{
25 void OpSumX2MY2::GenSlidingWindowFunction(std::stringstream
&ss
,
26 const std::string
&sSymName
, SubArguments
&vSubArguments
)
28 ss
<< "\ndouble " << sSymName
;
29 ss
<< "_"<< BinFuncName() <<"(";
30 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
34 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
37 ss
<<" int gid0=get_global_id(0);\n";
38 ss
<< " double tmp =0;\n";
39 GenTmpVariables(ss
,vSubArguments
);
40 if(vSubArguments
[0]->GetFormulaToken()->GetType() ==
41 formula::svDoubleVectorRef
)
43 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
44 const formula::DoubleVectorRefToken
*pCurDVR
= static_cast<const
45 formula::DoubleVectorRefToken
*>(tmpCur
);
46 size_t nCurWindowSize
= pCurDVR
->GetArrayLength() <
47 pCurDVR
->GetRefRowSize() ? pCurDVR
->GetArrayLength():
48 pCurDVR
->GetRefRowSize() ;
51 if (!pCurDVR
->IsStartFixed() && pCurDVR
->IsEndFixed()) {
52 ss
<< "gid0; i < "<< nCurWindowSize
<<"; i++)\n";
53 } else if (pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed()) {
54 ss
<< "0; i < gid0+"<< nCurWindowSize
<<"; i++)\n";
56 ss
<< "0; i < "<< nCurWindowSize
<<"; i++)\n";
59 if(!pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed())
61 ss
<< " int doubleIndex =i+gid0;\n";
64 ss
<< " int doubleIndex =i;\n";
67 CheckSubArgumentIsNan(ss
,vSubArguments
,0);
68 CheckSubArgumentIsNan(ss
,vSubArguments
,1);
69 ss
<< " tmp +=pow(tmp0,2) - pow(tmp1,2);\n";
74 ss
<< " int singleIndex =gid0;\n";
75 CheckAllSubArgumentIsNan(ss
, vSubArguments
);
76 ss
<< " tmp = pow(tmp0,2) - pow(tmp1,2);\n";
78 ss
<< "return tmp;\n";
82 void OpSumX2PY2::GenSlidingWindowFunction(std::stringstream
&ss
,
83 const std::string
&sSymName
, SubArguments
&vSubArguments
)
85 ss
<< "\ndouble " << sSymName
;
86 ss
<< "_"<< BinFuncName() <<"(";
87 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
91 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
94 ss
<< " int gid0=get_global_id(0);\n";
95 ss
<< " double tmp =0;\n";
96 GenTmpVariables(ss
,vSubArguments
);
97 if(vSubArguments
[0]->GetFormulaToken()->GetType() ==
98 formula::svDoubleVectorRef
)
100 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
101 const formula::DoubleVectorRefToken
*pCurDVR
= static_cast<const
102 formula::DoubleVectorRefToken
*>(tmpCur
);
103 size_t nCurWindowSize
= pCurDVR
->GetArrayLength() <
104 pCurDVR
->GetRefRowSize() ? pCurDVR
->GetArrayLength():
105 pCurDVR
->GetRefRowSize() ;
108 if (!pCurDVR
->IsStartFixed() && pCurDVR
->IsEndFixed()) {
109 ss
<< "gid0; i < "<< nCurWindowSize
<<"; i++)\n";
110 } else if (pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed()) {
111 ss
<< "0; i < gid0+"<< nCurWindowSize
<<"; i++)\n";
113 ss
<< "0; i < "<< nCurWindowSize
<<"; i++)\n";
116 if(!pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed())
118 ss
<< " int doubleIndex =i+gid0;\n";
121 ss
<< " int doubleIndex =i;\n";
124 CheckSubArgumentIsNan(ss
,vSubArguments
,0);
125 CheckSubArgumentIsNan(ss
,vSubArguments
,1);
126 ss
<< " tmp +=pow(tmp0,2) + pow(tmp1,2);\n";
131 ss
<< " int singleIndex =gid0;\n";
132 CheckAllSubArgumentIsNan(ss
, vSubArguments
);
133 ss
<< " tmp = pow(tmp0,2) + pow(tmp1,2);\n";
135 ss
<< " return tmp;\n";
138 void OpSumXMY2::GenSlidingWindowFunction(std::stringstream
&ss
,
139 const std::string
&sSymName
, SubArguments
&vSubArguments
)
141 ss
<< "\ndouble " << sSymName
;
142 ss
<< "_"<< BinFuncName() <<"(";
143 for (unsigned i
= 0; i
< vSubArguments
.size(); i
++)
147 vSubArguments
[i
]->GenSlidingWindowDecl(ss
);
150 ss
<< " int gid0=get_global_id(0);\n";
151 ss
<< " double tmp =0;\n";
152 GenTmpVariables(ss
,vSubArguments
);
153 if(vSubArguments
[0]->GetFormulaToken()->GetType() ==
154 formula::svDoubleVectorRef
)
156 FormulaToken
*tmpCur
= vSubArguments
[0]->GetFormulaToken();
157 const formula::DoubleVectorRefToken
*pCurDVR
= static_cast<const
158 formula::DoubleVectorRefToken
*>(tmpCur
);
159 size_t nCurWindowSize
= pCurDVR
->GetArrayLength() <
160 pCurDVR
->GetRefRowSize() ? pCurDVR
->GetArrayLength():
161 pCurDVR
->GetRefRowSize() ;
164 if (!pCurDVR
->IsStartFixed() && pCurDVR
->IsEndFixed()) {
165 ss
<< "gid0; i < "<< nCurWindowSize
<<"; i++)\n";
166 } else if (pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed()) {
167 ss
<< "0; i < gid0+"<< nCurWindowSize
<<"; i++)\n";
169 ss
<< "0; i < "<< nCurWindowSize
<<"; i++)\n";
172 if(!pCurDVR
->IsStartFixed() && !pCurDVR
->IsEndFixed())
174 ss
<< " int doubleIndex =i+gid0;\n";
177 ss
<< " int doubleIndex =i;\n";
180 CheckSubArgumentIsNan(ss
,vSubArguments
,0);
181 CheckSubArgumentIsNan(ss
,vSubArguments
,1);
182 ss
<< " tmp +=pow((tmp0-tmp1),2);\n";
187 ss
<< " int singleIndex =gid0;\n";
188 CheckAllSubArgumentIsNan(ss
, vSubArguments
);
189 ss
<< " tmp = pow((tmp0-tmp1),2);\n";
191 ss
<< " return tmp;\n";
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */