1 | /*************************************************************************** |
---|
2 | * blitz/array/misc.cc Miscellaneous operators for arrays |
---|
3 | * |
---|
4 | * $Id$ |
---|
5 | * |
---|
6 | * Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org> |
---|
7 | * |
---|
8 | * This file is a part of Blitz. |
---|
9 | * |
---|
10 | * Blitz is free software: you can redistribute it and/or modify |
---|
11 | * it under the terms of the GNU Lesser General Public License |
---|
12 | * as published by the Free Software Foundation, either version 3 |
---|
13 | * of the License, or (at your option) any later version. |
---|
14 | * |
---|
15 | * Blitz is distributed in the hope that it will be useful, |
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 | * GNU Lesser General Public License for more details. |
---|
19 | * |
---|
20 | * You should have received a copy of the GNU Lesser General Public |
---|
21 | * License along with Blitz. If not, see <http://www.gnu.org/licenses/>. |
---|
22 | * |
---|
23 | * Suggestions: blitz-devel@lists.sourceforge.net |
---|
24 | * Bugs: blitz-support@lists.sourceforge.net |
---|
25 | * |
---|
26 | * For more information, please see the Blitz++ Home Page: |
---|
27 | * https://sourceforge.net/projects/blitz/ |
---|
28 | * |
---|
29 | ****************************************************************************/ |
---|
30 | #ifndef BZ_ARRAYMISC_CC |
---|
31 | #define BZ_ARRAYMISC_CC |
---|
32 | |
---|
33 | #ifndef BZ_ARRAY_H |
---|
34 | #error <blitz/array/misc.cc> must be included via <blitz/array.h> |
---|
35 | #endif |
---|
36 | |
---|
37 | BZ_NAMESPACE(blitz) |
---|
38 | |
---|
39 | #define BZ_ARRAY_DECLARE_UOP(fn, fnobj) \ |
---|
40 | template<typename T_numtype, int N_rank> \ |
---|
41 | inline \ |
---|
42 | _bz_ArrayExpr<_bz_ArrayExprUnaryOp<FastArrayIterator<T_numtype,N_rank>, \ |
---|
43 | fnobj<T_numtype> > > \ |
---|
44 | fn(const Array<T_numtype,N_rank>& array) \ |
---|
45 | { \ |
---|
46 | return _bz_ArrayExprUnaryOp<FastArrayIterator<T_numtype,N_rank>, \ |
---|
47 | fnobj<T_numtype> >(array.beginFast()); \ |
---|
48 | } \ |
---|
49 | \ |
---|
50 | template<typename T_expr> \ |
---|
51 | inline \ |
---|
52 | _bz_ArrayExpr<_bz_ArrayExprUnaryOp<_bz_ArrayExpr<T_expr>, \ |
---|
53 | fnobj<_bz_typename T_expr::T_numtype> > > \ |
---|
54 | fn(BZ_ETPARM(_bz_ArrayExpr<T_expr>) expr) \ |
---|
55 | { \ |
---|
56 | return _bz_ArrayExprUnaryOp<_bz_ArrayExpr<T_expr>, \ |
---|
57 | fnobj<_bz_typename T_expr::T_numtype> >(expr); \ |
---|
58 | } |
---|
59 | |
---|
60 | BZ_ARRAY_DECLARE_UOP(operator!, LogicalNot) |
---|
61 | BZ_ARRAY_DECLARE_UOP(operator~, BitwiseNot) |
---|
62 | BZ_ARRAY_DECLARE_UOP(operator-, Negate) |
---|
63 | |
---|
64 | /* |
---|
65 | * cast() functions, for explicit type casting |
---|
66 | */ |
---|
67 | |
---|
68 | template<typename T_numtype, int N_rank, typename T_cast> |
---|
69 | inline |
---|
70 | _bz_ArrayExpr<_bz_ArrayExprUnaryOp<FastArrayIterator<T_numtype,N_rank>, |
---|
71 | Cast<T_numtype, T_cast> > > |
---|
72 | cast(const Array<T_numtype,N_rank>& array, T_cast) |
---|
73 | { |
---|
74 | return _bz_ArrayExprUnaryOp<FastArrayIterator<T_numtype,N_rank>, |
---|
75 | Cast<T_numtype,T_cast> >(array.beginFast()); |
---|
76 | } |
---|
77 | |
---|
78 | template<typename T_expr, typename T_cast> |
---|
79 | inline |
---|
80 | _bz_ArrayExpr<_bz_ArrayExprUnaryOp<_bz_ArrayExpr<T_expr>, |
---|
81 | Cast<_bz_typename T_expr::T_numtype,T_cast> > > |
---|
82 | cast(BZ_ETPARM(_bz_ArrayExpr<T_expr>) expr, T_cast) |
---|
83 | { |
---|
84 | return _bz_ArrayExprUnaryOp<_bz_ArrayExpr<T_expr>, |
---|
85 | Cast<_bz_typename T_expr::T_numtype,T_cast> >(expr); |
---|
86 | } |
---|
87 | |
---|
88 | BZ_NAMESPACE_END |
---|
89 | |
---|
90 | #endif // BZ_ARRAYMISC_CC |
---|
91 | |
---|