1 | #ifndef __XIOS_OPERATOR_EXPR_HPP__ |
---|
2 | #define __XIOS_OPERATOR_EXPR_HPP__ |
---|
3 | |
---|
4 | #include <map> |
---|
5 | #include <string> |
---|
6 | #include <cmath> |
---|
7 | #include "exception.hpp" |
---|
8 | #include "array_new.hpp" |
---|
9 | #include "utils.hpp" |
---|
10 | |
---|
11 | using namespace std; |
---|
12 | |
---|
13 | namespace xios |
---|
14 | { |
---|
15 | class COperatorExpr |
---|
16 | { |
---|
17 | public: |
---|
18 | typedef double (*functionScalar)(double); |
---|
19 | typedef double (*functionScalarScalar)(double, double); |
---|
20 | typedef double (*functionScalarScalarScalar)(double, double,double); |
---|
21 | typedef CArray<double,1> (*functionField)(const CArray<double,1>&); |
---|
22 | typedef CArray<double,1> (*functionFieldField)(const CArray<double,1>&, const CArray<double,1>&); |
---|
23 | typedef CArray<double,1> (*functionFieldScalar)(const CArray<double,1>&, double); |
---|
24 | typedef CArray<double,1> (*functionScalarField)(double, const CArray<double,1>&); |
---|
25 | typedef CArray<double,1> (*functionScalarScalarField)(double, double, const CArray<double,1>&); |
---|
26 | typedef CArray<double,1> (*functionScalarFieldScalar)(double, const CArray<double,1>&, double); |
---|
27 | typedef CArray<double,1> (*functionScalarFieldField)(double, const CArray<double,1>&, const CArray<double,1>&); |
---|
28 | typedef CArray<double,1> (*functionFieldScalarScalar)(const CArray<double,1>&, double, double); |
---|
29 | typedef CArray<double,1> (*functionFieldScalarField)(const CArray<double,1>&, double, const CArray<double,1>&); |
---|
30 | typedef CArray<double,1> (*functionFieldFieldScalar)(const CArray<double,1>&, const CArray<double,1>&, double); |
---|
31 | typedef CArray<double,1> (*functionFieldFieldField)(const CArray<double,1>&, const CArray<double,1>&, const CArray<double,1>&); |
---|
32 | |
---|
33 | COperatorExpr(void) |
---|
34 | { |
---|
35 | opScalar[string("neg")] = neg_s; |
---|
36 | opScalar[string("cos")] = cos_s; |
---|
37 | opScalar[string("sin")] = sin_s; |
---|
38 | opScalar[string("tan")] = tan_s; |
---|
39 | opScalar[string("exp")] = exp_s; |
---|
40 | opScalar[string("log")] = log_s; |
---|
41 | opScalar[string("log10")] = log10_s; |
---|
42 | opScalar[string("sqrt")] = sqrt_s; |
---|
43 | |
---|
44 | opScalarScalar[string("add")] = add_ss; |
---|
45 | opScalarScalar[string("minus")] = minus_ss; |
---|
46 | opScalarScalar[string("mult")] = mult_ss; |
---|
47 | opScalarScalar[string("div")] = div_ss; |
---|
48 | opScalarScalar[string("pow")] = pow_ss; |
---|
49 | opScalarScalar[string("eq")] = eq_ss; |
---|
50 | opScalarScalar[string("lt")] = lt_ss; |
---|
51 | opScalarScalar[string("gt")] = gt_ss; |
---|
52 | opScalarScalar[string("le")] = le_ss; |
---|
53 | opScalarScalar[string("ge")] = ge_ss; |
---|
54 | opScalarScalar[string("ne")] = ne_ss; |
---|
55 | opScalarScalarScalar[string("cond")] = cond_sss; |
---|
56 | |
---|
57 | opField[string("neg")] = neg_f; |
---|
58 | opField[string("cos")] = cos_f; |
---|
59 | opField[string("sin")] = sin_f; |
---|
60 | opField[string("tan")] = tan_f; |
---|
61 | opField[string("exp")] = exp_f; |
---|
62 | opField[string("log")] = log_f; |
---|
63 | opField[string("log10")] = log10_f; |
---|
64 | opField[string("sqrt")] = sqrt_f; |
---|
65 | |
---|
66 | opFieldField[string("add")] = add_ff; |
---|
67 | opFieldField[string("minus")] = minus_ff; |
---|
68 | opFieldField[string("mult")] = mult_ff; |
---|
69 | opFieldField[string("div")] = div_ff; |
---|
70 | opFieldField[string("pow")] = pow_ff; |
---|
71 | opFieldField[string("eq")] = eq_ff; |
---|
72 | opFieldField[string("lt")] = lt_ff; |
---|
73 | opFieldField[string("gt")] = gt_ff; |
---|
74 | opFieldField[string("le")] = le_ff; |
---|
75 | opFieldField[string("ge")] = ge_ff; |
---|
76 | opFieldField[string("ne")] = ne_ff; |
---|
77 | |
---|
78 | opFieldScalar[string("add")] = add_fs; |
---|
79 | opFieldScalar[string("minus")] = minus_fs; |
---|
80 | opFieldScalar[string("mult")] = mult_fs; |
---|
81 | opFieldScalar[string("div")] = div_fs; |
---|
82 | opFieldScalar[string("pow")] = pow_fs; |
---|
83 | opFieldScalar[string("eq")] = eq_fs; |
---|
84 | opFieldScalar[string("lt")] = lt_fs; |
---|
85 | opFieldScalar[string("gt")] = gt_fs; |
---|
86 | opFieldScalar[string("le")] = le_fs; |
---|
87 | opFieldScalar[string("ge")] = ge_fs; |
---|
88 | opFieldScalar[string("ne")] = ne_fs; |
---|
89 | |
---|
90 | opScalarField[string("add")] = add_sf; |
---|
91 | opScalarField[string("minus")] = minus_sf; |
---|
92 | opScalarField[string("mult")] = mult_sf; |
---|
93 | opScalarField[string("div")] = div_sf; |
---|
94 | opScalarField[string("eq")] = eq_sf; |
---|
95 | opScalarField[string("lt")] = lt_sf; |
---|
96 | opScalarField[string("gt")] = gt_sf; |
---|
97 | opScalarField[string("le")] = le_sf; |
---|
98 | opScalarField[string("ge")] = ge_sf; |
---|
99 | opScalarField[string("ne")] = ne_sf; |
---|
100 | |
---|
101 | opScalarScalarField[string("cond")] = cond_ssf; |
---|
102 | opScalarFieldScalar[string("cond")] = cond_sfs; |
---|
103 | opScalarFieldField[string("cond")] = cond_sff; |
---|
104 | opFieldScalarScalar[string("cond")] = cond_fss; |
---|
105 | opFieldScalarField[string("cond")] = cond_fsf; |
---|
106 | opFieldFieldScalar[string("cond")] = cond_ffs; |
---|
107 | opFieldFieldField[string("cond")] = cond_fff; |
---|
108 | |
---|
109 | |
---|
110 | } |
---|
111 | |
---|
112 | functionScalar getOpScalar(const string& id) |
---|
113 | { |
---|
114 | map<string,double (*)(double)>::iterator it; |
---|
115 | it = opScalar.find(id); |
---|
116 | if (it == opScalar.end()) ERROR("functionScalar COperatorExpr::getOpScalar(const string& id)", << "unknown operator : " << id) |
---|
117 | return it->second; |
---|
118 | } |
---|
119 | |
---|
120 | functionScalarScalar getOpScalarScalar(const string& id) |
---|
121 | { |
---|
122 | map<string,double (*)(double,double)>::iterator it; |
---|
123 | it = opScalarScalar.find(id); |
---|
124 | if (it == opScalarScalar.end()) ERROR("functionScalarScalar COperatorExpr::getOpScalarScalar(const string& id)", << "unknown operator : " << id) |
---|
125 | return it->second; |
---|
126 | } |
---|
127 | |
---|
128 | functionScalarScalarScalar getOpScalarScalarScalar(const string& id) |
---|
129 | { |
---|
130 | map<string,double (*)(double,double,double)>::iterator it; |
---|
131 | it = opScalarScalarScalar.find(id); |
---|
132 | if (it == opScalarScalarScalar.end()) ERROR("functionScalarScalarScalar getOpScalarScalarScalar(const string& id)", << "unknown operator : " << id) |
---|
133 | return it->second; |
---|
134 | } |
---|
135 | |
---|
136 | functionField getOpField(const string& id) |
---|
137 | { |
---|
138 | map<string,functionField>::iterator it; |
---|
139 | it = opField.find(id); |
---|
140 | if (it == opField.end()) ERROR("functionField COperatorExpr::getOpField(const string& id)", << "unknown operator : " << id) |
---|
141 | return it->second; |
---|
142 | } |
---|
143 | |
---|
144 | functionFieldField getOpFieldField(const string& id) |
---|
145 | { |
---|
146 | map<string,functionFieldField>::iterator it; |
---|
147 | it = opFieldField.find(id); |
---|
148 | if (it == opFieldField.end()) ERROR("dfunctionFieldField COperatorExpr::getOpFieldField(const string& id)", << "unknown operator : " << id) |
---|
149 | return it->second; |
---|
150 | } |
---|
151 | |
---|
152 | functionFieldScalar getOpFieldScalar(const string& id) |
---|
153 | { |
---|
154 | map<string,functionFieldScalar>::iterator it; |
---|
155 | it = opFieldScalar.find(id); |
---|
156 | if (it == opFieldScalar.end()) ERROR("functionFieldScalar COperatorExpr::getOpFieldScalar(const string& id)", << "unknown operator : " << id) |
---|
157 | return it->second; |
---|
158 | } |
---|
159 | |
---|
160 | functionScalarField getOpScalarField(const string& id) |
---|
161 | { |
---|
162 | map<string,functionScalarField>::iterator it; |
---|
163 | it = opScalarField.find(id); |
---|
164 | if (it == opScalarField.end()) ERROR("functionScalarField COperatorExpr::getOpFieldField(const string& id)", << "unknown operator : " << id) |
---|
165 | return it->second; |
---|
166 | } |
---|
167 | |
---|
168 | functionScalarScalarField getOpScalarScalarField(const string& id) |
---|
169 | { |
---|
170 | map<string,functionScalarScalarField>::iterator it; |
---|
171 | it = opScalarScalarField.find(id); |
---|
172 | if (it == opScalarScalarField.end()) ERROR("functionScalarScalarField getOpScalarScalarField(const string& id)", << "unknown operator : " << id) |
---|
173 | return it->second; |
---|
174 | } |
---|
175 | |
---|
176 | functionScalarFieldScalar getOpScalarFieldScalar(const string& id) |
---|
177 | { |
---|
178 | map<string,functionScalarFieldScalar>::iterator it; |
---|
179 | it = opScalarFieldScalar.find(id); |
---|
180 | if (it == opScalarFieldScalar.end()) ERROR("functionScalarFieldScalar getOpScalarScalarField(const string& id)", << "unknown operator : " << id) |
---|
181 | return it->second; |
---|
182 | } |
---|
183 | |
---|
184 | functionScalarFieldField getOpScalarFieldField(const string& id) |
---|
185 | { |
---|
186 | map<string,functionScalarFieldField>::iterator it; |
---|
187 | it = opScalarFieldField.find(id); |
---|
188 | if (it == opScalarFieldField.end()) ERROR("functionScalarFieldField getOpScalarFieldField(const string& id)", << "unknown operator : " << id) |
---|
189 | return it->second; |
---|
190 | } |
---|
191 | |
---|
192 | functionFieldScalarScalar getOpFieldScalarScalar(const string& id) |
---|
193 | { |
---|
194 | map<string,functionFieldScalarScalar>::iterator it; |
---|
195 | it = opFieldScalarScalar.find(id); |
---|
196 | if (it == opFieldScalarScalar.end()) ERROR("functionFieldScalarScalar getOpFieldScalarScalar(const string& id)", << "unknown operator : " << id) |
---|
197 | return it->second; |
---|
198 | } |
---|
199 | |
---|
200 | functionFieldScalarField getOpFieldScalarField(const string& id) |
---|
201 | { |
---|
202 | map<string,functionFieldScalarField>::iterator it; |
---|
203 | it = opFieldScalarField.find(id); |
---|
204 | if (it == opFieldScalarField.end()) ERROR("functionFieldScalarField getOpFieldScalarField(const string& id)", << "unknown operator : " << id) |
---|
205 | return it->second; |
---|
206 | } |
---|
207 | |
---|
208 | functionFieldFieldScalar getOpFieldFieldScalar(const string& id) |
---|
209 | { |
---|
210 | map<string,functionFieldFieldScalar>::iterator it; |
---|
211 | it = opFieldFieldScalar.find(id); |
---|
212 | if (it == opFieldFieldScalar.end()) ERROR("functionFieldFieldScalar getOpFieldFieldScalar(const string& id)", << "unknown operator : " << id) |
---|
213 | return it->second; |
---|
214 | } |
---|
215 | |
---|
216 | functionFieldFieldField getOpFieldFieldField(const string& id) |
---|
217 | { |
---|
218 | map<string,functionFieldFieldField>::iterator it; |
---|
219 | it = opFieldFieldField.find(id); |
---|
220 | if (it == opFieldFieldField.end()) ERROR("functionFieldFieldField getOpFieldFieldField(const string& id)", << "unknown operator : " << id) |
---|
221 | return it->second; |
---|
222 | } |
---|
223 | |
---|
224 | |
---|
225 | map<string,functionScalar> opScalar; |
---|
226 | map<string,functionScalarScalar> opScalarScalar; |
---|
227 | map<string,functionScalarScalarScalar> opScalarScalarScalar; |
---|
228 | map<string,functionField> opField; |
---|
229 | map<string,functionFieldField> opFieldField; |
---|
230 | map<string,functionFieldScalar> opFieldScalar; |
---|
231 | map<string,functionScalarField> opScalarField; |
---|
232 | map<string,functionScalarScalarField> opScalarScalarField; |
---|
233 | map<string,functionScalarFieldScalar> opScalarFieldScalar; |
---|
234 | map<string,functionScalarFieldField> opScalarFieldField; |
---|
235 | map<string,functionFieldScalarScalar> opFieldScalarScalar; |
---|
236 | map<string,functionFieldScalarField> opFieldScalarField; |
---|
237 | map<string,functionFieldFieldScalar> opFieldFieldScalar; |
---|
238 | map<string,functionFieldFieldField> opFieldFieldField; |
---|
239 | |
---|
240 | |
---|
241 | |
---|
242 | static inline double neg_s(double x) { return -x; } |
---|
243 | static inline double cos_s(double x) { return std::cos(x); } |
---|
244 | static inline double sin_s(double x) { return std::sin(x); } |
---|
245 | static inline double tan_s(double x) { return std::tan(x); } |
---|
246 | static inline double exp_s(double x) { return std::exp(x); } |
---|
247 | static inline double log_s(double x) { return std::log(x); } |
---|
248 | static inline double log10_s(double x) { return std::log10(x); } |
---|
249 | static inline double sqrt_s(double x) { return std::sqrt(x); } |
---|
250 | |
---|
251 | static inline double add_ss(double x, double y) { return x + y; } |
---|
252 | static inline double minus_ss(double x, double y) { return x - y; } |
---|
253 | static inline double mult_ss(double x, double y) { return x * y; } |
---|
254 | static inline double div_ss(double x, double y) { return x / y; } |
---|
255 | static inline double pow_ss(double x, double y) { return std::pow(x,y); } |
---|
256 | |
---|
257 | static inline double eq_ss(double x, double y) // specific check for NaN |
---|
258 | { |
---|
259 | bool xNan=NumTraits<double>::isNan(x) ; |
---|
260 | bool yNan=NumTraits<double>::isNan(y) ; |
---|
261 | if (xNan && yNan) return true ; |
---|
262 | else if (xNan) return false ; |
---|
263 | else if (yNan) return false ; |
---|
264 | else return x == y; |
---|
265 | } |
---|
266 | |
---|
267 | static inline double lt_ss(double x, double y) { return x < y; } |
---|
268 | static inline double gt_ss(double x, double y) { return x > y; } |
---|
269 | static inline double le_ss(double x, double y) { return x <= y; } |
---|
270 | static inline double ge_ss(double x, double y) { return x >= y; } |
---|
271 | |
---|
272 | static inline double ne_ss(double x, double y) // specific check for NaN |
---|
273 | { |
---|
274 | bool xNan=NumTraits<double>::isNan(x) ; |
---|
275 | bool yNan=NumTraits<double>::isNan(y) ; |
---|
276 | if (xNan && yNan) return false ; |
---|
277 | else if (xNan) return true ; |
---|
278 | else if (yNan) return true ; |
---|
279 | else return x != y; |
---|
280 | } |
---|
281 | |
---|
282 | static inline CArray<double,1> neg_f(const CArray<double,1>& x) { return Array<double,1>(-x); } |
---|
283 | static inline CArray<double,1> cos_f(const CArray<double,1>& x) { return Array<double,1>(cos(x)); } |
---|
284 | static inline CArray<double,1> sin_f(const CArray<double,1>& x) { return Array<double,1>(sin(x)); } |
---|
285 | static inline CArray<double,1> tan_f(const CArray<double,1>& x) { return Array<double,1>(tan(x)); } |
---|
286 | static inline CArray<double,1> exp_f(const CArray<double,1>& x) { return Array<double,1>(exp(x)); } |
---|
287 | static inline CArray<double,1> log_f(const CArray<double,1>& x) { return Array<double,1>(log(x)); } |
---|
288 | static inline CArray<double,1> log10_f(const CArray<double,1>& x) { return Array<double,1>(log10(x)); } |
---|
289 | static inline CArray<double,1> sqrt_f(const CArray<double,1>& x) { return Array<double,1>(sqrt(x)); } |
---|
290 | |
---|
291 | static inline CArray<double,1> add_ff(const CArray<double,1>& x, const CArray<double,1>& y) { return Array<double,1>(x + y); } |
---|
292 | static inline CArray<double,1> minus_ff(const CArray<double,1>& x, const CArray<double,1>& y) { return Array<double,1>(x - y); } |
---|
293 | static inline CArray<double,1> mult_ff(const CArray<double,1>& x, const CArray<double,1>& y) { return Array<double,1>(x * y); } |
---|
294 | static inline CArray<double,1> div_ff(const CArray<double,1>& x, const CArray<double,1>& y) { return Array<double,1>(x / y); } |
---|
295 | static inline CArray<double,1> pow_ff(const CArray<double,1>& x, const CArray<double,1>& y) { return Array<double,1>(pow(x,y)); } |
---|
296 | static inline CArray<double,1> eq_ff(const CArray<double,1>& x, const CArray<double,1>& y) { return Array<double,1>(x == y); } |
---|
297 | static inline CArray<double,1> lt_ff(const CArray<double,1>& x, const CArray<double,1>& y) { return Array<double,1>(x < y); } |
---|
298 | static inline CArray<double,1> gt_ff(const CArray<double,1>& x, const CArray<double,1>& y) { return Array<double,1>(x > y); } |
---|
299 | static inline CArray<double,1> le_ff(const CArray<double,1>& x, const CArray<double,1>& y) { return Array<double,1>(x <= y); } |
---|
300 | static inline CArray<double,1> ge_ff(const CArray<double,1>& x, const CArray<double,1>& y) { return Array<double,1>(x >= y); } |
---|
301 | static inline CArray<double,1> ne_ff(const CArray<double,1>& x, const CArray<double,1>& y) { return Array<double,1>(x != y); } |
---|
302 | |
---|
303 | static inline CArray<double,1> add_fs(const CArray<double,1>& x, double y) { return Array<double,1>(x + y); } |
---|
304 | static inline CArray<double,1> minus_fs(const CArray<double,1>& x, double y) { return Array<double,1>(x - y); } |
---|
305 | static inline CArray<double,1> mult_fs(const CArray<double,1>& x, double y) { return Array<double,1>(x * y); } |
---|
306 | static inline CArray<double,1> div_fs(const CArray<double,1>& x, double y) { return Array<double,1>(x / y); } |
---|
307 | static inline CArray<double,1> pow_fs(const CArray<double,1>& x, double y) { return Array<double,1>(pow(x,y)); } |
---|
308 | |
---|
309 | static inline CArray<double,1> eq_fs(const CArray<double,1>& x, double y) // specific check for NaN |
---|
310 | { |
---|
311 | if (NumTraits<double>::isNan(y)) |
---|
312 | { |
---|
313 | CArray<double,1> ret(x.numElements()) ; |
---|
314 | Array<double,1>::const_iterator itx=x.begin(),itxe=x.end(); |
---|
315 | Array<double,1>::iterator itret=ret.begin() ; |
---|
316 | for(;itx!=itxe;++itx,++itret) *itret=NumTraits<double>::isNan(*itx) ; |
---|
317 | return ret ; |
---|
318 | } |
---|
319 | else return Array<double,1>(x == y); |
---|
320 | } |
---|
321 | |
---|
322 | static inline CArray<double,1> lt_fs(const CArray<double,1>& x, double y) { return Array<double,1>(x < y); } |
---|
323 | static inline CArray<double,1> gt_fs(const CArray<double,1>& x, double y) { return Array<double,1>(x > y); } |
---|
324 | static inline CArray<double,1> le_fs(const CArray<double,1>& x, double y) { return Array<double,1>(x <= y); } |
---|
325 | static inline CArray<double,1> ge_fs(const CArray<double,1>& x, double y) { return Array<double,1>(x >= y); } |
---|
326 | |
---|
327 | static inline CArray<double,1> ne_fs(const CArray<double,1>& x, double y) // specific check for NaN |
---|
328 | { |
---|
329 | if (NumTraits<double>::isNan(y)) |
---|
330 | { |
---|
331 | CArray<double,1> ret(x.numElements()) ; |
---|
332 | Array<double,1>::const_iterator itx=x.begin(),itxe=x.end(); |
---|
333 | Array<double,1>::iterator itret=ret.begin() ; |
---|
334 | for(;itx!=itxe;++itx,++itret) *itret = !NumTraits<double>::isNan(*itx) ; |
---|
335 | return ret ; |
---|
336 | } |
---|
337 | else return Array<double,1>(x != y); |
---|
338 | } |
---|
339 | |
---|
340 | static inline CArray<double,1> add_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x + y); } |
---|
341 | static inline CArray<double,1> minus_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x - y); } |
---|
342 | static inline CArray<double,1> mult_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x * y); } |
---|
343 | static inline CArray<double,1> div_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x / y); } |
---|
344 | |
---|
345 | static inline CArray<double,1> eq_sf(double x, const CArray<double,1>& y) // specific check for NaN |
---|
346 | { |
---|
347 | if (NumTraits<double>::isNan(x)) |
---|
348 | { |
---|
349 | CArray<double,1> ret(y.numElements()) ; |
---|
350 | Array<double,1>::const_iterator ity=y.begin(),itye=y.end(); |
---|
351 | Array<double,1>::iterator itret=ret.begin() ; |
---|
352 | for(;ity!=itye;++ity,++itret) *itret=NumTraits<double>::isNan(*ity) ; |
---|
353 | return ret ; |
---|
354 | } |
---|
355 | else return Array<double,1>(x == y); |
---|
356 | } |
---|
357 | static inline CArray<double,1> lt_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x < y); } |
---|
358 | static inline CArray<double,1> gt_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x > y); } |
---|
359 | static inline CArray<double,1> le_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x <= y); } |
---|
360 | static inline CArray<double,1> ge_sf(double x, const CArray<double,1>& y) { return Array<double,1>(x >= y); } |
---|
361 | |
---|
362 | static inline CArray<double,1> ne_sf(double x, const CArray<double,1>& y) // specific check for NaN |
---|
363 | { |
---|
364 | if (NumTraits<double>::isNan(x)) |
---|
365 | { |
---|
366 | CArray<double,1> ret(y.numElements()) ; |
---|
367 | Array<double,1>::const_iterator ity=y.begin(),itye=y.end(); |
---|
368 | Array<double,1>::iterator itret=ret.begin() ; |
---|
369 | for(;ity!=itye;++ity,++itret) *itret=!NumTraits<double>::isNan(*ity) ; |
---|
370 | return ret ; |
---|
371 | } |
---|
372 | else return Array<double,1>(x != y); |
---|
373 | } |
---|
374 | static inline double cond_sss(double x, double y, double z) { return (x==0) ? z : y ; } |
---|
375 | |
---|
376 | static inline CArray<double,1> cond_ssf(double x, double y, const CArray<double,1>& z) |
---|
377 | { |
---|
378 | CArray<double,1> ret(z.numElements()) ; |
---|
379 | if (x==0) ret=z ; |
---|
380 | else ret=y ; |
---|
381 | return ret ; |
---|
382 | } |
---|
383 | |
---|
384 | static inline CArray<double,1> cond_sfs(double x, const CArray<double,1>& y, double z) |
---|
385 | { |
---|
386 | CArray<double,1> ret(y.numElements()) ; |
---|
387 | if (x==0) ret=z ; |
---|
388 | else ret=y ; |
---|
389 | return ret ; |
---|
390 | } |
---|
391 | |
---|
392 | static inline CArray<double,1> cond_sff(double x, const CArray<double,1>& y, const CArray<double,1>& z) |
---|
393 | { |
---|
394 | CArray<double,1> ret(y.numElements()) ; |
---|
395 | if (x==0) ret=z ; |
---|
396 | else ret=y ; |
---|
397 | return ret ; |
---|
398 | } |
---|
399 | |
---|
400 | static inline CArray<double,1> cond_fss(const CArray<double,1>& x, double y, double z) |
---|
401 | { |
---|
402 | CArray<double,1> ret(x.numElements()) ; |
---|
403 | Array<double,1>::const_iterator itx=x.begin(),itxe=x.end(); |
---|
404 | Array<double,1>::iterator itret=ret.begin() ; |
---|
405 | |
---|
406 | for(;itx!=itxe;++itx,++itret) *itret=( (*itx==0)?z:y) ; |
---|
407 | return ret ; |
---|
408 | } |
---|
409 | |
---|
410 | static inline CArray<double,1> cond_fsf(const CArray<double,1>& x, double y, const CArray<double,1>& z) |
---|
411 | { |
---|
412 | CArray<double,1> ret(x.numElements()) ; |
---|
413 | Array<double,1>::const_iterator itx=x.begin(), itxe=x.end(), itz=z.begin(); |
---|
414 | Array<double,1>::iterator itret=ret.begin() ; |
---|
415 | for(;itx!=itxe;++itx,++itz,++itret) *itret=( (*itx==0)?*itz:y) ; |
---|
416 | return ret ; |
---|
417 | } |
---|
418 | |
---|
419 | static inline CArray<double,1> cond_ffs(const CArray<double,1>& x, const CArray<double,1>& y, double z) |
---|
420 | { |
---|
421 | CArray<double,1> ret(x.numElements()) ; |
---|
422 | Array<double,1>::const_iterator itx=x.begin(), itxe=x.end(), ity=y.begin() ; |
---|
423 | Array<double,1>::iterator itret=ret.begin() ; |
---|
424 | for(;itx!=itxe;++itx,++ity,++itret) *itret=( (*itx==0)?z:*ity) ; |
---|
425 | return ret ; |
---|
426 | } |
---|
427 | |
---|
428 | static inline CArray<double,1> cond_fff(const CArray<double,1>& x, const CArray<double,1>& y, const CArray<double,1>& z) |
---|
429 | { |
---|
430 | CArray<double,1> ret(x.numElements()) ; |
---|
431 | Array<double,1>::const_iterator itx=x.begin(), itxe=x.end(), ity=y.begin(), itz=z.begin() ; |
---|
432 | Array<double,1>::iterator itret=ret.begin() ; |
---|
433 | for(;itx!=itxe;++itx,++ity,++itz,++itret) *itret=( (*itx==0)?*itz:*ity) ; |
---|
434 | return ret ; |
---|
435 | } |
---|
436 | |
---|
437 | void release(void) |
---|
438 | { |
---|
439 | opScalar.clear(); |
---|
440 | opScalarScalar.clear(); |
---|
441 | opScalarScalarScalar.clear(); |
---|
442 | opField.clear(); |
---|
443 | opFieldField.clear(); |
---|
444 | opFieldScalar.clear(); |
---|
445 | opScalarField.clear(); |
---|
446 | opScalarScalarField.clear(); |
---|
447 | opScalarFieldScalar.clear(); |
---|
448 | opScalarFieldField.clear(); |
---|
449 | opFieldScalarScalar.clear(); |
---|
450 | opFieldScalarField.clear(); |
---|
451 | opFieldFieldScalar.clear(); |
---|
452 | opFieldFieldField.clear(); |
---|
453 | } |
---|
454 | }; |
---|
455 | |
---|
456 | extern COperatorExpr operatorExpr; |
---|
457 | |
---|
458 | } |
---|
459 | |
---|
460 | #endif |
---|
461 | |
---|