LibreOffice Module sc (master)  1
op_array.cxx
Go to the documentation of this file.
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_array.hxx"
11 
12 #include <formula/vectortoken.hxx>
13 #include <sstream>
14 
15 using namespace formula;
16 
17 namespace sc::opencl {
18 
19 void OpSumX2MY2::GenSlidingWindowFunction(std::stringstream &ss,
20  const std::string &sSymName, SubArguments &vSubArguments)
21 {
22  ss << "\ndouble " << sSymName;
23  ss << "_"<< BinFuncName() <<"(";
24  for (size_t i = 0; i < vSubArguments.size(); i++)
25  {
26  if (i)
27  ss << ",";
28  vSubArguments[i]->GenSlidingWindowDecl(ss);
29  }
30  ss << ")\n {\n";
31  ss <<" int gid0=get_global_id(0);\n";
32  ss << " double tmp =0;\n";
33  GenTmpVariables(ss,vSubArguments);
34  if(vSubArguments[0]->GetFormulaToken()->GetType() ==
36  {
37  FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
38  const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
40  size_t nCurWindowSize = pCurDVR->GetArrayLength() <
41  pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
42  pCurDVR->GetRefRowSize() ;
43  ss << " int i ;\n";
44  ss << " for (i = ";
45  if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
46  ss << "gid0; i < "<< nCurWindowSize <<"; i++)\n";
47  } else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) {
48  ss << "0; i < gid0+"<< nCurWindowSize <<"; i++)\n";
49  } else {
50  ss << "0; i < "<< nCurWindowSize <<"; i++)\n";
51  }
52  ss << " {\n";
53  if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
54  {
55  ss << " int doubleIndex =i+gid0;\n";
56  }else
57  {
58  ss << " int doubleIndex =i;\n";
59  }
60 
61  CheckSubArgumentIsNan(ss,vSubArguments,0);
62  CheckSubArgumentIsNan(ss,vSubArguments,1);
63  ss << " tmp +=pow(tmp0,2) - pow(tmp1,2);\n";
64  ss <<" }\n";
65  }
66  else
67  {
68  ss << " int singleIndex =gid0;\n";
69  CheckAllSubArgumentIsNan(ss, vSubArguments);
70  ss << " tmp = pow(tmp0,2) - pow(tmp1,2);\n";
71  }
72  ss << "return tmp;\n";
73  ss << "}";
74 }
75 
76 void OpSumX2PY2::GenSlidingWindowFunction(std::stringstream &ss,
77  const std::string &sSymName, SubArguments &vSubArguments)
78 {
79  ss << "\ndouble " << sSymName;
80  ss << "_"<< BinFuncName() <<"(";
81  for (size_t i = 0; i < vSubArguments.size(); i++)
82  {
83  if (i)
84  ss << ",";
85  vSubArguments[i]->GenSlidingWindowDecl(ss);
86  }
87  ss << ")\n {\n";
88  ss << " int gid0=get_global_id(0);\n";
89  ss << " double tmp =0;\n";
90  GenTmpVariables(ss,vSubArguments);
91  if(vSubArguments[0]->GetFormulaToken()->GetType() ==
93  {
94  FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
95  const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
97  size_t nCurWindowSize = pCurDVR->GetArrayLength() <
98  pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
99  pCurDVR->GetRefRowSize() ;
100  ss << " int i ;\n";
101  ss << " for (i = ";
102  if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
103  ss << "gid0; i < "<< nCurWindowSize <<"; i++)\n";
104  } else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) {
105  ss << "0; i < gid0+"<< nCurWindowSize <<"; i++)\n";
106  } else {
107  ss << "0; i < "<< nCurWindowSize <<"; i++)\n";
108  }
109  ss << " {\n";
110  if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
111  {
112  ss << " int doubleIndex =i+gid0;\n";
113  }else
114  {
115  ss << " int doubleIndex =i;\n";
116  }
117 
118  CheckSubArgumentIsNan(ss,vSubArguments,0);
119  CheckSubArgumentIsNan(ss,vSubArguments,1);
120  ss << " tmp +=pow(tmp0,2) + pow(tmp1,2);\n";
121  ss <<" }\n";
122  }
123  else
124  {
125  ss << " int singleIndex =gid0;\n";
126  CheckAllSubArgumentIsNan(ss, vSubArguments);
127  ss << " tmp = pow(tmp0,2) + pow(tmp1,2);\n";
128  }
129  ss << " return tmp;\n";
130  ss << "}";
131 }
132 void OpSumXMY2::GenSlidingWindowFunction(std::stringstream &ss,
133  const std::string &sSymName, SubArguments &vSubArguments)
134 {
135  ss << "\ndouble " << sSymName;
136  ss << "_"<< BinFuncName() <<"(";
137  for (size_t i = 0; i < vSubArguments.size(); i++)
138  {
139  if (i)
140  ss << ",";
141  vSubArguments[i]->GenSlidingWindowDecl(ss);
142  }
143  ss << ")\n {\n";
144  ss << " int gid0=get_global_id(0);\n";
145  ss << " double tmp =0;\n";
146  GenTmpVariables(ss,vSubArguments);
147  if(vSubArguments[0]->GetFormulaToken()->GetType() ==
149  {
150  FormulaToken *tmpCur = vSubArguments[0]->GetFormulaToken();
151  const formula::DoubleVectorRefToken*pCurDVR= static_cast<const
153  size_t nCurWindowSize = pCurDVR->GetArrayLength() <
154  pCurDVR->GetRefRowSize() ? pCurDVR->GetArrayLength():
155  pCurDVR->GetRefRowSize() ;
156  ss << " int i ;\n";
157  ss << " for (i = ";
158  if (!pCurDVR->IsStartFixed() && pCurDVR->IsEndFixed()) {
159  ss << "gid0; i < "<< nCurWindowSize <<"; i++)\n";
160  } else if (pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed()) {
161  ss << "0; i < gid0+"<< nCurWindowSize <<"; i++)\n";
162  } else {
163  ss << "0; i < "<< nCurWindowSize <<"; i++)\n";
164  }
165  ss << " {\n";
166  if(!pCurDVR->IsStartFixed() && !pCurDVR->IsEndFixed())
167  {
168  ss << " int doubleIndex =i+gid0;\n";
169  }else
170  {
171  ss << " int doubleIndex =i;\n";
172  }
173 
174  CheckSubArgumentIsNan(ss,vSubArguments,0);
175  CheckSubArgumentIsNan(ss,vSubArguments,1);
176  ss << " tmp +=pow((tmp0-tmp1),2);\n";
177  ss <<" }\n";
178  }
179  else
180  {
181  ss << " int singleIndex =gid0;\n";
182  CheckAllSubArgumentIsNan(ss, vSubArguments);
183  ss << " tmp = pow((tmp0-tmp1),2);\n";
184  }
185  ss << " return tmp;\n";
186  ss << "}";
187 }
188 
189 }
190 
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
int i
std::vector< DynamicKernelArgumentRef > SubArguments
Definition: opbase.hxx:215
Arguments that are actually compile-time constant string Currently, only the hash is passed...
size_t GetArrayLength() const