1 | // -*- C++ -*- |
---|
2 | /*************************************************************************** |
---|
3 | * blitz/array/zip.h "zip" scalar arrays into a multicomponent array expr |
---|
4 | * |
---|
5 | * $Id$ |
---|
6 | * |
---|
7 | * Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org> |
---|
8 | * |
---|
9 | * This file is a part of Blitz. |
---|
10 | * |
---|
11 | * Blitz is free software: you can redistribute it and/or modify |
---|
12 | * it under the terms of the GNU Lesser General Public License |
---|
13 | * as published by the Free Software Foundation, either version 3 |
---|
14 | * of the License, or (at your option) any later version. |
---|
15 | * |
---|
16 | * Blitz is distributed in the hope that it will be useful, |
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
19 | * GNU Lesser General Public License for more details. |
---|
20 | * |
---|
21 | * You should have received a copy of the GNU Lesser General Public |
---|
22 | * License along with Blitz. If not, see <http://www.gnu.org/licenses/>. |
---|
23 | * |
---|
24 | * Suggestions: blitz-devel@lists.sourceforge.net |
---|
25 | * Bugs: blitz-support@lists.sourceforge.net |
---|
26 | * |
---|
27 | * For more information, please see the Blitz++ Home Page: |
---|
28 | * https://sourceforge.net/projects/blitz/ |
---|
29 | * |
---|
30 | ****************************************************************************/ |
---|
31 | #ifndef BZ_ARRAYZIP_H |
---|
32 | #define BZ_ARRAYZIP_H |
---|
33 | |
---|
34 | #ifndef BZ_ARRAY_H |
---|
35 | #error <blitz/array/zip.h> must be included via <blitz/array.h> |
---|
36 | #endif |
---|
37 | |
---|
38 | BZ_NAMESPACE(blitz) |
---|
39 | |
---|
40 | template<typename P_component, typename T1, typename T2> |
---|
41 | struct Zip2 { |
---|
42 | typedef P_component T_numtype; |
---|
43 | |
---|
44 | static inline T_numtype apply(T1 a, T2 b) |
---|
45 | { return T_numtype(a,b); } |
---|
46 | |
---|
47 | template<typename T_left, typename T_right> |
---|
48 | static inline void prettyPrint(BZ_STD_SCOPE(string) &str, |
---|
49 | prettyPrintFormat& format, const T_left& t1, |
---|
50 | const T_right& t2) |
---|
51 | { |
---|
52 | str += "zip("; |
---|
53 | t1.prettyPrint(str, format); |
---|
54 | str += ","; |
---|
55 | t2.prettyPrint(str, format); |
---|
56 | str += ")"; |
---|
57 | } |
---|
58 | }; |
---|
59 | |
---|
60 | template<typename T_component, typename T1, typename T2> |
---|
61 | inline _bz_ArrayExpr<_bz_ArrayExprBinaryOp< |
---|
62 | _bz_typename asExpr<T1>::T_expr, |
---|
63 | _bz_typename asExpr<T2>::T_expr, |
---|
64 | Zip2<T_component, |
---|
65 | _bz_typename asExpr<T1>::T_expr::T_numtype, |
---|
66 | _bz_typename asExpr<T2>::T_expr::T_numtype> > > |
---|
67 | zip(const T1& a, const T2& b, T_component) |
---|
68 | { |
---|
69 | return _bz_ArrayExpr<_bz_ArrayExprBinaryOp< |
---|
70 | _bz_typename asExpr<T1>::T_expr, |
---|
71 | _bz_typename asExpr<T2>::T_expr, |
---|
72 | Zip2<T_component, |
---|
73 | _bz_typename asExpr<T1>::T_expr::T_numtype, |
---|
74 | _bz_typename asExpr<T2>::T_expr::T_numtype> > >(a,b); |
---|
75 | } |
---|
76 | |
---|
77 | BZ_NAMESPACE_END |
---|
78 | |
---|
79 | #endif // BZ_ARRAYZIP_H |
---|
80 | |
---|