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