1 | /*************************************************************************** |
---|
2 | * blitz/matexpr.h Matrix<P_numtype, P_structure> expression templates |
---|
3 | * |
---|
4 | * $Id: matexpr.h,v 1.4 2003/12/11 03:44:22 julianc Exp $ |
---|
5 | * |
---|
6 | * Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org> |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * Suggestions: blitz-dev@oonumerics.org |
---|
19 | * Bugs: blitz-bugs@oonumerics.org |
---|
20 | * |
---|
21 | * For more information, please see the Blitz++ Home Page: |
---|
22 | * http://oonumerics.org/blitz/ |
---|
23 | * |
---|
24 | ***************************************************************************/ |
---|
25 | |
---|
26 | #ifndef BZ_MATEXPR_H |
---|
27 | #define BZ_MATEXPR_H |
---|
28 | |
---|
29 | #ifndef BZ_MATRIX_H |
---|
30 | #error <blitz/matexpr.h> must be included via <blitz/matrix.h> |
---|
31 | #endif |
---|
32 | |
---|
33 | #include <blitz/applics.h> |
---|
34 | |
---|
35 | BZ_NAMESPACE(blitz) |
---|
36 | |
---|
37 | // BlitzMatrixExpressionsBase is a dummy class provided for users of |
---|
38 | // graphical class browsers. |
---|
39 | class BlitzMatrixExpressionsBase { }; |
---|
40 | |
---|
41 | template<typename P_expr> |
---|
42 | class _bz_MatExpr : public BlitzMatrixExpressionsBase { |
---|
43 | |
---|
44 | public: |
---|
45 | typedef P_expr T_expr; |
---|
46 | typedef _bz_typename T_expr::T_numtype T_numtype; |
---|
47 | |
---|
48 | #ifdef BZ_PASS_EXPR_BY_VALUE |
---|
49 | _bz_MatExpr(T_expr a) |
---|
50 | : iter_(a) |
---|
51 | { } |
---|
52 | #else |
---|
53 | _bz_MatExpr(const T_expr& a) |
---|
54 | : iter_(a) |
---|
55 | { } |
---|
56 | #endif |
---|
57 | |
---|
58 | T_numtype operator()(unsigned i, unsigned j) const |
---|
59 | { return iter_(i,j); } |
---|
60 | |
---|
61 | unsigned rows(unsigned recommendedRows) const |
---|
62 | { return iter_.rows(recommendedRows); } |
---|
63 | |
---|
64 | unsigned cols(unsigned recommendedCols) const |
---|
65 | { return iter_.cols(recommendedCols); } |
---|
66 | |
---|
67 | private: |
---|
68 | T_expr iter_; |
---|
69 | }; |
---|
70 | |
---|
71 | template<typename P_expr1, typename P_expr2, typename P_op> |
---|
72 | class _bz_MatExprOp : public BlitzMatrixExpressionsBase { |
---|
73 | |
---|
74 | public: |
---|
75 | typedef P_expr1 T_expr1; |
---|
76 | typedef P_expr2 T_expr2; |
---|
77 | typedef _bz_typename T_expr1::T_numtype T_numtype1; |
---|
78 | typedef _bz_typename T_expr2::T_numtype T_numtype2; |
---|
79 | typedef BZ_PROMOTE(T_numtype1, T_numtype2) T_numtype; |
---|
80 | typedef P_op T_op; |
---|
81 | |
---|
82 | #ifdef BZ_PASS_EXPR_BY_VALUE |
---|
83 | _bz_MatExprOp(T_expr1 a, T_expr2 b) |
---|
84 | : iter1_(a), iter2_(b) |
---|
85 | { } |
---|
86 | #else |
---|
87 | _bz_MatExprOp(const T_expr1& a, const T_expr2& b) |
---|
88 | : iter1_(a), iter2_(b) |
---|
89 | { } |
---|
90 | #endif |
---|
91 | |
---|
92 | T_numtype operator()(unsigned i, unsigned j) const |
---|
93 | { return T_op::apply(iter1_(i,j), iter2_(i,j)); } |
---|
94 | |
---|
95 | unsigned rows(unsigned recommendedRows) const |
---|
96 | { |
---|
97 | BZPRECONDITION(iter2_.rows(recommendedRows) == |
---|
98 | iter1_.rows(recommendedRows)); |
---|
99 | return iter1_.rows(recommendedRows); |
---|
100 | } |
---|
101 | |
---|
102 | unsigned cols(unsigned recommendedCols) const |
---|
103 | { |
---|
104 | BZPRECONDITION(iter2_.cols(recommendedCols) == |
---|
105 | iter1_.cols(recommendedCols)); |
---|
106 | return iter1_.cols(recommendedCols); |
---|
107 | } |
---|
108 | |
---|
109 | private: |
---|
110 | T_expr1 iter1_; |
---|
111 | T_expr2 iter2_; |
---|
112 | }; |
---|
113 | |
---|
114 | template<typename P_expr, typename P_unaryOp> |
---|
115 | class _bz_MatExprUnaryOp : public BlitzMatrixExpressionsBase { |
---|
116 | |
---|
117 | public: |
---|
118 | typedef P_expr T_expr; |
---|
119 | typedef P_unaryOp T_unaryOp; |
---|
120 | typedef _bz_typename T_unaryOp::T_numtype T_numtype; |
---|
121 | |
---|
122 | #ifdef BZ_PASS_EXPR_BY_VALUE |
---|
123 | _bz_MatExprUnaryOp(T_expr iter) |
---|
124 | : iter_(iter) |
---|
125 | { } |
---|
126 | #else |
---|
127 | _bz_MatExprUnaryOp(const T_expr& iter) |
---|
128 | : iter_(iter) |
---|
129 | { } |
---|
130 | #endif |
---|
131 | |
---|
132 | T_numtype operator()(unsigned i, unsigned j) const |
---|
133 | { return T_unaryOp::apply(iter_(i,j)); } |
---|
134 | |
---|
135 | unsigned rows(unsigned recommendedRows) const |
---|
136 | { return iter_.rows(recommendedRows); } |
---|
137 | |
---|
138 | unsigned cols(unsigned recommendedCols) const |
---|
139 | { return iter_.cols(recommendedCols); } |
---|
140 | |
---|
141 | private: |
---|
142 | T_expr iter_; |
---|
143 | }; |
---|
144 | |
---|
145 | template<typename P_numtype> |
---|
146 | class _bz_MatExprConstant : public BlitzMatrixExpressionsBase { |
---|
147 | public: |
---|
148 | typedef P_numtype T_numtype; |
---|
149 | |
---|
150 | _bz_MatExprConstant(P_numtype value) |
---|
151 | : value_(value) |
---|
152 | { } |
---|
153 | |
---|
154 | T_numtype operator()(unsigned i, unsigned j) const |
---|
155 | { return value_; } |
---|
156 | |
---|
157 | unsigned rows(unsigned recommendedRows) const |
---|
158 | { return recommendedRows; } |
---|
159 | |
---|
160 | unsigned cols(unsigned recommendedCols) const |
---|
161 | { return recommendedCols; } |
---|
162 | |
---|
163 | private: |
---|
164 | T_numtype value_; |
---|
165 | }; |
---|
166 | |
---|
167 | BZ_NAMESPACE_END |
---|
168 | |
---|
169 | #include <blitz/matref.h> |
---|
170 | #include <blitz/matbops.h> |
---|
171 | #include <blitz/matuops.h> |
---|
172 | |
---|
173 | #endif // BZ_MATEXPR_H |
---|