1 | // -*- C++ -*- |
---|
2 | /*************************************************************************** |
---|
3 | * blitz/array/newet-macros.h Macros for new e.t. implementation |
---|
4 | * |
---|
5 | * Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org> |
---|
6 | * |
---|
7 | * This program is free software; you can redistribute it and/or |
---|
8 | * modify it under the terms of the GNU General Public License |
---|
9 | * as published by the Free Software Foundation; either version 2 |
---|
10 | * of the License, or (at your option) any later version. |
---|
11 | * |
---|
12 | * This program is distributed in the hope that it will be useful, |
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | * GNU General Public License for more details. |
---|
16 | * |
---|
17 | * Suggestions: blitz-dev@oonumerics.org |
---|
18 | * Bugs: blitz-bugs@oonumerics.org |
---|
19 | * |
---|
20 | * For more information, please see the Blitz++ Home Page: |
---|
21 | * http://oonumerics.org/blitz/ |
---|
22 | * |
---|
23 | ****************************************************************************/ |
---|
24 | #ifndef BZ_NEWET_MACROS_H |
---|
25 | #define BZ_NEWET_MACROS_H |
---|
26 | |
---|
27 | #include <blitz/array/asexpr.h> |
---|
28 | |
---|
29 | BZ_NAMESPACE(blitz) |
---|
30 | |
---|
31 | #ifdef BZ_HAVE_TEMPLATES_AS_TEMPLATE_ARGUMENTS |
---|
32 | |
---|
33 | /* |
---|
34 | * Unary functions and operators |
---|
35 | */ |
---|
36 | |
---|
37 | #define BZ_DECLARE_ARRAY_ET_UNARY(name,functor) \ |
---|
38 | \ |
---|
39 | template <typename T1> \ |
---|
40 | _bz_inline_et \ |
---|
41 | typename BzUnaryExprResult<functor,T1>::T_result \ |
---|
42 | name(const ETBase<T1>& d1) \ |
---|
43 | { \ |
---|
44 | typedef typename BzUnaryExprResult<functor,T1>::T_result result; \ |
---|
45 | return result(asExpr<T1>::getExpr(d1.unwrap())); \ |
---|
46 | } |
---|
47 | |
---|
48 | /* |
---|
49 | * Array expression templates: the macro BZ_DECLARE_ARRAY_ET_BINARY(X,Y) |
---|
50 | * declares a function or operator which takes two operands. |
---|
51 | * X is the function name (or operator), and Y is the functor object |
---|
52 | * which implements the operation. |
---|
53 | */ |
---|
54 | |
---|
55 | #define BZ_DECLARE_ARRAY_ET_BINARY(name, applic) \ |
---|
56 | \ |
---|
57 | template <typename T1,typename T2> \ |
---|
58 | _bz_inline_et \ |
---|
59 | typename BzBinaryExprResult<applic,T1,T2>::T_result \ |
---|
60 | name(const ETBase<T1>& d1,const ETBase<T2>& d2) \ |
---|
61 | { \ |
---|
62 | typedef typename BzBinaryExprResult<applic,T1,T2>::T_result result; \ |
---|
63 | return result(asExpr<T1>::getExpr(d1.unwrap()), \ |
---|
64 | asExpr<T2>::getExpr(d2.unwrap())); \ |
---|
65 | } |
---|
66 | |
---|
67 | #define BZ_DECLARE_ARRAY_ET_BINARY_TINYVEC(name, applic) \ |
---|
68 | \ |
---|
69 | template <typename T1, typename T2, int N> \ |
---|
70 | _bz_inline_et \ |
---|
71 | typename BzBinaryExprResult<applic,TinyVector<T2,N>,T1>::T_result \ |
---|
72 | name(const TinyVector<T2,N> d1, const ETBase<T1>& d2) \ |
---|
73 | { \ |
---|
74 | typedef typename \ |
---|
75 | BzBinaryExprResult<applic,TinyVector<T2,N>,T1>::T_result result; \ |
---|
76 | return result(asExpr<TinyVector<T2,N> >::getExpr(d1), \ |
---|
77 | asExpr<T1>::getExpr(d2.unwrap())); \ |
---|
78 | } \ |
---|
79 | \ |
---|
80 | template <typename T1, typename T2, int N> \ |
---|
81 | _bz_inline_et \ |
---|
82 | typename BzBinaryExprResult<applic,T1,TinyVector<T2,N> >::T_result \ |
---|
83 | name(const ETBase<T1>& d1, const TinyVector<T2,N> d2) \ |
---|
84 | { \ |
---|
85 | typedef typename \ |
---|
86 | BzBinaryExprResult<applic,T1,TinyVector<T2,N> >::T_result result; \ |
---|
87 | return result(asExpr<T1>::getExpr(d1.unwrap()), \ |
---|
88 | asExpr<TinyVector<T2,N> >::getExpr(d2)); \ |
---|
89 | } |
---|
90 | |
---|
91 | #define BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(name, applic, sca) \ |
---|
92 | \ |
---|
93 | template<typename T> \ |
---|
94 | _bz_inline_et \ |
---|
95 | typename BzBinaryExprResult<applic,sca,T>::T_result \ |
---|
96 | name(const sca d1, const ETBase<T>& d2) \ |
---|
97 | { \ |
---|
98 | typedef typename BzBinaryExprResult<applic,sca,T>::T_result result; \ |
---|
99 | return result(asExpr<sca >::getExpr(d1), \ |
---|
100 | asExpr<T>::getExpr(d2.unwrap())); \ |
---|
101 | } \ |
---|
102 | \ |
---|
103 | template<typename T> \ |
---|
104 | _bz_inline_et \ |
---|
105 | typename BzBinaryExprResult<applic,T,sca >::T_result \ |
---|
106 | name(const ETBase<T>& d1, const sca d2) \ |
---|
107 | { \ |
---|
108 | typedef typename BzBinaryExprResult<applic,T,sca >::T_result result; \ |
---|
109 | return result(asExpr<T>::getExpr(d1.unwrap()), \ |
---|
110 | asExpr<sca >::getExpr(d2)); \ |
---|
111 | } |
---|
112 | |
---|
113 | /* |
---|
114 | * Array expression templates: the macro BZ_DECLARE_ARRAY_ET_TERNARY(X,Y) |
---|
115 | * declares a function or operator which takes three operands. |
---|
116 | * X is the function name (or operator), and Y is the functor object |
---|
117 | * which implements the operation. |
---|
118 | */ |
---|
119 | |
---|
120 | #define BZ_DECLARE_ARRAY_ET_TERNARY(name, applic) \ |
---|
121 | \ |
---|
122 | template <typename T1, typename T2, typename T3> \ |
---|
123 | _bz_inline_et \ |
---|
124 | typename BzTernaryExprResult<applic, T1, T2, T3>::T_result \ |
---|
125 | name(const ETBase<T1>& d1, const ETBase<T2>& d2, const ETBase<T3>& d3) \ |
---|
126 | { \ |
---|
127 | typedef typename BzTernaryExprResult<applic,T1,T2,T3>::T_result result; \ |
---|
128 | return result(asExpr<T1>::getExpr(d1.unwrap()), \ |
---|
129 | asExpr<T2>::getExpr(d2.unwrap()), \ |
---|
130 | asExpr<T3>::getExpr(d3.unwrap())); \ |
---|
131 | } |
---|
132 | |
---|
133 | #else /* !BZ_HAVE_TEMPLATES_AS_TEMPLATE_ARGUMENTS */ |
---|
134 | |
---|
135 | /* |
---|
136 | * Unary functions and operators |
---|
137 | */ |
---|
138 | |
---|
139 | #define BZ_DECLARE_ARRAY_ET_UNARY(name, functor) \ |
---|
140 | \ |
---|
141 | template<typename T1> \ |
---|
142 | _bz_inline_et \ |
---|
143 | _bz_ArrayExpr<_bz_ArrayExprUnaryOp< \ |
---|
144 | _bz_typename asExpr<T1>::T_expr, \ |
---|
145 | functor<_bz_typename asExpr<T1>::T_expr::T_numtype> > > \ |
---|
146 | name(const ETBase<T1>& d1) \ |
---|
147 | { \ |
---|
148 | return _bz_ArrayExpr<_bz_ArrayExprUnaryOp< \ |
---|
149 | _bz_typename asExpr<T1>::T_expr, \ |
---|
150 | functor<_bz_typename asExpr<T1>::T_expr::T_numtype> > > \ |
---|
151 | (asExpr<T1>::getExpr(d1.unwrap())); \ |
---|
152 | } |
---|
153 | |
---|
154 | /* |
---|
155 | * Array expression templates: the macro BZ_DECLARE_ARRAY_ET_BINARY(X,Y) |
---|
156 | * declares a function or operator which takes two operands. |
---|
157 | * X is the function name (or operator), and Y is the functor object |
---|
158 | * which implements the operation. |
---|
159 | */ |
---|
160 | |
---|
161 | #define BZ_DECLARE_ARRAY_ET_BINARY(name, applic) \ |
---|
162 | \ |
---|
163 | template<typename T1, typename T2> \ |
---|
164 | _bz_inline_et \ |
---|
165 | _bz_ArrayExpr<_bz_ArrayExprBinaryOp< \ |
---|
166 | _bz_typename asExpr<T1>::T_expr, \ |
---|
167 | _bz_typename asExpr<T2>::T_expr, \ |
---|
168 | applic<_bz_typename asExpr<T1>::T_expr::T_numtype, \ |
---|
169 | _bz_typename asExpr<T2>::T_expr::T_numtype> > > \ |
---|
170 | name(const ETBase<T1>& d1, const ETBase<T2>& d2) \ |
---|
171 | { \ |
---|
172 | return _bz_ArrayExpr<_bz_ArrayExprBinaryOp< \ |
---|
173 | _bz_typename asExpr<T1>::T_expr, \ |
---|
174 | _bz_typename asExpr<T2>::T_expr, \ |
---|
175 | applic<_bz_typename asExpr<T1>::T_expr::T_numtype, \ |
---|
176 | _bz_typename asExpr<T2>::T_expr::T_numtype> > > \ |
---|
177 | (asExpr<T1>::getExpr(d1.unwrap()), \ |
---|
178 | asExpr<T2>::getExpr(d2.unwrap())); \ |
---|
179 | } |
---|
180 | |
---|
181 | #define BZ_DECLARE_ARRAY_ET_BINARY_TINYVEC(name, applic) \ |
---|
182 | \ |
---|
183 | template <typename T1, typename T2, int N> \ |
---|
184 | _bz_inline_et \ |
---|
185 | _bz_ArrayExprBinaryOp< \ |
---|
186 | _bz_typename asExpr<TinyVector<T2,N> >::T_expr, \ |
---|
187 | _bz_typename asExpr<T1>::T_expr, \ |
---|
188 | applic<TinyVector<T2,N>, \ |
---|
189 | _bz_typename asExpr<T1>::T_expr::T_numtype> > \ |
---|
190 | name(const TinyVector<T2,N> d1, const ETBase<T1>& d2) \ |
---|
191 | { \ |
---|
192 | return _bz_ArrayExprBinaryOp< \ |
---|
193 | _bz_typename asExpr<TinyVector<T2,N> >::T_expr, \ |
---|
194 | _bz_typename asExpr<T1>::T_expr, \ |
---|
195 | applic<TinyVector<T2,N>, \ |
---|
196 | _bz_typename asExpr<T1>::T_expr::T_numtype> > \ |
---|
197 | (asExpr<TinyVector<T2,N> >::getExpr(d1), \ |
---|
198 | asExpr<T1>::getExpr(d2.unwrap())); \ |
---|
199 | } \ |
---|
200 | \ |
---|
201 | template <typename T1, typename T2, int N> \ |
---|
202 | _bz_inline_et \ |
---|
203 | _bz_ArrayExprBinaryOp< \ |
---|
204 | _bz_typename asExpr<T1>::T_expr, \ |
---|
205 | _bz_typename asExpr<TinyVector<T2,N> >::T_expr, \ |
---|
206 | applic<_bz_typename asExpr<T1>::T_expr::T_numtype, \ |
---|
207 | TinyVector<T2,N> > > \ |
---|
208 | name(const ETBase<T1>& d1, const TinyVector<T2,N> d2) \ |
---|
209 | { \ |
---|
210 | return _bz_ArrayExprBinaryOp< \ |
---|
211 | _bz_typename asExpr<T1>::T_expr, \ |
---|
212 | _bz_typename asExpr<TinyVector<T2,N> >::T_expr, \ |
---|
213 | applic<_bz_typename asExpr<T1>::T_expr::T_numtype, \ |
---|
214 | TinyVector<T2,N> > > \ |
---|
215 | (asExpr<T1>::getExpr(d1.unwrap()), \ |
---|
216 | asExpr<TinyVector<T2,N> >::getExpr(d2)); \ |
---|
217 | } |
---|
218 | |
---|
219 | #define BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(name, applic, sca) \ |
---|
220 | \ |
---|
221 | template<typename T> \ |
---|
222 | _bz_inline_et \ |
---|
223 | _bz_ArrayExprBinaryOp< \ |
---|
224 | asExpr<sca >::T_expr, \ |
---|
225 | _bz_typename asExpr<T>::T_expr, \ |
---|
226 | applic<sca,_bz_typename asExpr<T>::T_expr::T_numtype> > \ |
---|
227 | name(const sca d1, const ETBase<T>& d2) \ |
---|
228 | { \ |
---|
229 | return _bz_ArrayExprBinaryOp< \ |
---|
230 | asExpr<sca >::T_expr, \ |
---|
231 | _bz_typename asExpr<T>::T_expr, \ |
---|
232 | applic<sca,_bz_typename asExpr<T>::T_expr::T_numtype> > \ |
---|
233 | (asExpr<sca >::getExpr(d1), \ |
---|
234 | asExpr<T>::getExpr(d2.unwrap())); \ |
---|
235 | } \ |
---|
236 | \ |
---|
237 | template<typename T> \ |
---|
238 | _bz_inline_et \ |
---|
239 | _bz_ArrayExprBinaryOp< \ |
---|
240 | _bz_typename asExpr<T>::T_expr, \ |
---|
241 | asExpr<sca >::T_expr, \ |
---|
242 | applic<_bz_typename asExpr<T>::T_expr::T_numtype,sca > > \ |
---|
243 | name(const ETBase<T>& d1, const sca d2) \ |
---|
244 | { \ |
---|
245 | return _bz_ArrayExprBinaryOp< \ |
---|
246 | _bz_typename asExpr<T>::T_expr, \ |
---|
247 | asExpr<sca >::T_expr, \ |
---|
248 | applic<_bz_typename asExpr<T>::T_expr::T_numtype,sca > > \ |
---|
249 | (asExpr<T>::getExpr(d1.unwrap()), \ |
---|
250 | asExpr<sca >::getExpr(d2)); \ |
---|
251 | } |
---|
252 | |
---|
253 | /* |
---|
254 | * Array expression templates: the macro BZ_DECLARE_ARRAY_ET_TERNARY(X,Y) |
---|
255 | * declares a function or operator which takes three operands. |
---|
256 | * X is the function name (or operator), and Y is the functor object |
---|
257 | * which implements the operation. |
---|
258 | */ |
---|
259 | |
---|
260 | #define BZ_DECLARE_ARRAY_ET_TERNARY(name, applic) \ |
---|
261 | \ |
---|
262 | template<typename T1, typename T2, typename T3> \ |
---|
263 | _bz_inline_et \ |
---|
264 | _bz_ArrayExpr<_bz_ArrayExprTernaryOp< \ |
---|
265 | _bz_typename asExpr<T1>::T_expr, \ |
---|
266 | _bz_typename asExpr<T2>::T_expr, \ |
---|
267 | _bz_typename asExpr<T3>::T_expr, \ |
---|
268 | applic<_bz_typename asExpr<T1>::T_expr::T_numtype, \ |
---|
269 | _bz_typename asExpr<T2>::T_expr::T_numtype, \ |
---|
270 | _bz_typename asExpr<T3>::T_expr::T_numtype> > > \ |
---|
271 | name(const ETBase<T1>& d1, const ETBase<T2>& d2, const ETBase<T3>& d3) \ |
---|
272 | { \ |
---|
273 | return _bz_ArrayExpr<_bz_ArrayExprTernaryOp< \ |
---|
274 | _bz_typename asExpr<T1>::T_expr, \ |
---|
275 | _bz_typename asExpr<T2>::T_expr, \ |
---|
276 | _bz_typename asExpr<T3>::T_expr, \ |
---|
277 | applic<_bz_typename asExpr<T1>::T_expr::T_numtype, \ |
---|
278 | _bz_typename asExpr<T2>::T_expr::T_numtype, \ |
---|
279 | _bz_typename asExpr<T3>::T_expr::T_numtype> > > \ |
---|
280 | (asExpr<T1>::getExpr(d1.unwrap()), \ |
---|
281 | asExpr<T2>::getExpr(d2.unwrap()), \ |
---|
282 | asExpr<T3>::getExpr(d3.unwrap())); \ |
---|
283 | } |
---|
284 | |
---|
285 | #endif /* BZ_HAVE_TEMPLATES_AS_TEMPLATE_ARGUMENTS */ |
---|
286 | |
---|
287 | /* |
---|
288 | * User-defined expression template routines |
---|
289 | */ |
---|
290 | |
---|
291 | #define BZ_DECLARE_FUNCTION(name) \ |
---|
292 | BZ_DEFINE_UNARY_FUNC(name ## _impl,name) \ |
---|
293 | BZ_DECLARE_ARRAY_ET_UNARY(name,name ## _impl) |
---|
294 | |
---|
295 | #define BZ_DECLARE_FUNCTION_RET(name,return_type) \ |
---|
296 | BZ_DEFINE_UNARY_FUNC_RET(name ## _impl,name,return_type) \ |
---|
297 | BZ_DECLARE_ARRAY_ET_UNARY(name,name ## _impl) |
---|
298 | |
---|
299 | #define BZ_DECLARE_FUNCTION2(name) \ |
---|
300 | BZ_DEFINE_BINARY_FUNC(name ## _impl,name) \ |
---|
301 | BZ_DECLARE_ARRAY_ET_BINARY(name, name ## _impl) |
---|
302 | |
---|
303 | #define BZ_DECLARE_FUNCTION2_RET(name,return_type) \ |
---|
304 | BZ_DEFINE_BINARY_FUNC_RET(name ## _impl,name,return_type) \ |
---|
305 | BZ_DECLARE_ARRAY_ET_BINARY(name, name ## _impl) |
---|
306 | |
---|
307 | #define BZ_DECLARE_FUNCTION2_SCALAR(name, sca) \ |
---|
308 | BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(name, name ## _impl, sca) |
---|
309 | |
---|
310 | #define BZ_DECLARE_FUNCTION3(name) \ |
---|
311 | BZ_DEFINE_TERNARY_FUNC(name ## _impl,name) \ |
---|
312 | BZ_DECLARE_ARRAY_ET_TERNARY(name, name ## _impl) |
---|
313 | |
---|
314 | #define BZ_DECLARE_FUNCTION3_RET(name,return_type) \ |
---|
315 | BZ_DEFINE_TERNARY_FUNC_RET(name ## _impl,name,return_type) \ |
---|
316 | BZ_DECLARE_ARRAY_ET_TERNARY(name, name ## _impl) |
---|
317 | |
---|
318 | BZ_NAMESPACE_END |
---|
319 | |
---|
320 | #endif |
---|