source: XMLIO_V2/external/include/blitz/array/newet-macros.h @ 80

Last change on this file since 80 was 80, checked in by ymipsl, 14 years ago

ajout lib externe

  • Property svn:eol-style set to native
File size: 18.1 KB
Line 
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
29BZ_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                                                                          \
39template <typename T1>                                                    \
40_bz_inline_et                                                             \
41typename BzUnaryExprResult<functor,T1>::T_result                          \
42name(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                                                                          \
57template <typename T1,typename T2>                                        \
58_bz_inline_et                                                             \
59typename BzBinaryExprResult<applic,T1,T2>::T_result                       \
60name(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                                                                          \
69template <typename T1, typename T2, int N>                                \
70_bz_inline_et                                                             \
71typename BzBinaryExprResult<applic,TinyVector<T2,N>,T1>::T_result         \
72name(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                                                                          \
80template <typename T1, typename T2, int N>                                \
81_bz_inline_et                                                             \
82typename BzBinaryExprResult<applic,T1,TinyVector<T2,N> >::T_result        \
83name(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                                                                          \
93template<typename T>                                                      \
94_bz_inline_et                                                             \
95typename BzBinaryExprResult<applic,sca,T>::T_result                       \
96name(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                                                                          \
103template<typename T>                                                      \
104_bz_inline_et                                                             \
105typename BzBinaryExprResult<applic,T,sca >::T_result                      \
106name(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                                                                              \
122template <typename T1, typename T2, typename T3>                              \
123_bz_inline_et                                                                 \
124typename BzTernaryExprResult<applic, T1, T2, T3>::T_result                    \
125name(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                                                                          \
141template<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> > >               \
146name(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                                                                          \
163template<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> > >                \
170name(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                                                                          \
183template <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> >                         \
190name(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                                                                          \
201template <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> > >                                                  \
208name(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                                                                          \
221template<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> >               \
227name(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                                                                          \
237template<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 > >              \
243name(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                                                                          \
262template<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> > >                \
271name(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)                                        \
292BZ_DEFINE_UNARY_FUNC(name ## _impl,name)                                 \
293BZ_DECLARE_ARRAY_ET_UNARY(name,name ## _impl)
294
295#define BZ_DECLARE_FUNCTION_RET(name,return_type)                        \
296BZ_DEFINE_UNARY_FUNC_RET(name ## _impl,name,return_type)                 \
297BZ_DECLARE_ARRAY_ET_UNARY(name,name ## _impl)
298
299#define BZ_DECLARE_FUNCTION2(name)                                       \
300BZ_DEFINE_BINARY_FUNC(name ## _impl,name)                                \
301BZ_DECLARE_ARRAY_ET_BINARY(name, name ## _impl)
302
303#define BZ_DECLARE_FUNCTION2_RET(name,return_type)                       \
304BZ_DEFINE_BINARY_FUNC_RET(name ## _impl,name,return_type)                \
305BZ_DECLARE_ARRAY_ET_BINARY(name, name ## _impl)
306
307#define BZ_DECLARE_FUNCTION2_SCALAR(name, sca)                           \
308BZ_DECLARE_ARRAY_ET_BINARY_SCALAR(name, name ## _impl, sca)
309
310#define BZ_DECLARE_FUNCTION3(name)                                       \
311BZ_DEFINE_TERNARY_FUNC(name ## _impl,name)                               \
312BZ_DECLARE_ARRAY_ET_TERNARY(name, name ## _impl)
313   
314#define BZ_DECLARE_FUNCTION3_RET(name,return_type)                       \
315BZ_DEFINE_TERNARY_FUNC_RET(name ## _impl,name,return_type)               \
316BZ_DECLARE_ARRAY_ET_TERNARY(name, name ## _impl)
317
318BZ_NAMESPACE_END
319
320#endif
Note: See TracBrowser for help on using the repository browser.