| 1 | /*************************************************************************** | 
|---|
| 2 | * blitz/matexpr.h      Matrix<P_numtype, P_structure> expression templates | 
|---|
| 3 | * | 
|---|
| 4 | * $Id: matexpr.h,v 1.1.1.1 1999-04-09 17:59:00 ansari Exp $ | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright (C) 1997,1998 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca> | 
|---|
| 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-suggest@cybervision.com | 
|---|
| 19 | * Bugs:                 blitz-bugs@cybervision.com | 
|---|
| 20 | * | 
|---|
| 21 | * For more information, please see the Blitz++ Home Page: | 
|---|
| 22 | *    http://seurat.uwaterloo.ca/blitz/ | 
|---|
| 23 | * | 
|---|
| 24 | *************************************************************************** | 
|---|
| 25 | * $Log: not supported by cvs2svn $ | 
|---|
| 26 | * Revision 1.3  1998/03/14 00:04:47  tveldhui | 
|---|
| 27 | * 0.2-alpha-05 | 
|---|
| 28 | * | 
|---|
| 29 | * Revision 1.2  1997/01/24 14:42:00  tveldhui | 
|---|
| 30 | * Periodic RCS update | 
|---|
| 31 | * | 
|---|
| 32 | * Revision 1.1  1997/01/13 22:19:58  tveldhui | 
|---|
| 33 | * Periodic RCS update | 
|---|
| 34 | * | 
|---|
| 35 | * | 
|---|
| 36 | */ | 
|---|
| 37 |  | 
|---|
| 38 | #ifndef BZ_MATEXPR_H | 
|---|
| 39 | #define BZ_MATEXPR_H | 
|---|
| 40 |  | 
|---|
| 41 | #ifndef BZ_MATRIX_H | 
|---|
| 42 | #error <blitz/matexpr.h> must be included via <blitz/matrix.h> | 
|---|
| 43 | #endif | 
|---|
| 44 |  | 
|---|
| 45 | #include <blitz/applics.h> | 
|---|
| 46 |  | 
|---|
| 47 | BZ_NAMESPACE(blitz) | 
|---|
| 48 |  | 
|---|
| 49 | // BlitzMatrixExpressionsBase is a dummy class provided for users of | 
|---|
| 50 | // graphical class browsers. | 
|---|
| 51 | class BlitzMatrixExpressionsBase { }; | 
|---|
| 52 |  | 
|---|
| 53 | template<class P_expr> | 
|---|
| 54 | class _bz_MatExpr : public BlitzMatrixExpressionsBase { | 
|---|
| 55 |  | 
|---|
| 56 | public: | 
|---|
| 57 | typedef P_expr T_expr; | 
|---|
| 58 | typedef _bz_typename T_expr::T_numtype T_numtype; | 
|---|
| 59 |  | 
|---|
| 60 | #ifdef BZ_PASS_EXPR_BY_VALUE | 
|---|
| 61 | _bz_MatExpr(T_expr a) | 
|---|
| 62 | : iter_(a) | 
|---|
| 63 | { } | 
|---|
| 64 | #else | 
|---|
| 65 | _bz_MatExpr(const T_expr& a) | 
|---|
| 66 | : iter_(a) | 
|---|
| 67 | { } | 
|---|
| 68 | #endif | 
|---|
| 69 |  | 
|---|
| 70 | T_numtype operator()(unsigned i, unsigned j) const | 
|---|
| 71 | { return iter_(i,j); } | 
|---|
| 72 |  | 
|---|
| 73 | unsigned rows(unsigned recommendedRows) const | 
|---|
| 74 | { return iter_.rows(recommendedRows); } | 
|---|
| 75 |  | 
|---|
| 76 | unsigned cols(unsigned recommendedCols) const | 
|---|
| 77 | { return iter_.cols(recommendedCols); } | 
|---|
| 78 |  | 
|---|
| 79 | private: | 
|---|
| 80 | T_expr iter_; | 
|---|
| 81 | }; | 
|---|
| 82 |  | 
|---|
| 83 | template<class P_expr1, class P_expr2, class P_op> | 
|---|
| 84 | class _bz_MatExprOp : public BlitzMatrixExpressionsBase { | 
|---|
| 85 |  | 
|---|
| 86 | public: | 
|---|
| 87 | typedef P_expr1 T_expr1; | 
|---|
| 88 | typedef P_expr2 T_expr2; | 
|---|
| 89 | typedef _bz_typename T_expr1::T_numtype T_numtype1; | 
|---|
| 90 | typedef _bz_typename T_expr2::T_numtype T_numtype2; | 
|---|
| 91 | typedef BZ_PROMOTE(T_numtype1, T_numtype2) T_numtype; | 
|---|
| 92 | typedef P_op    T_op; | 
|---|
| 93 |  | 
|---|
| 94 | #ifdef BZ_PASS_EXPR_BY_VALUE | 
|---|
| 95 | _bz_MatExprOp(T_expr1 a, T_expr2 b) | 
|---|
| 96 | : iter1_(a), iter2_(b) | 
|---|
| 97 | { } | 
|---|
| 98 | #else | 
|---|
| 99 | _bz_MatExprOp(const T_expr1& a, const T_expr2& b) | 
|---|
| 100 | : iter1_(a), iter2_(b) | 
|---|
| 101 | { } | 
|---|
| 102 | #endif | 
|---|
| 103 |  | 
|---|
| 104 | T_numtype operator()(unsigned i, unsigned j) const | 
|---|
| 105 | { return T_op::apply(iter1_(i,j), iter2_(i,j)); } | 
|---|
| 106 |  | 
|---|
| 107 | unsigned rows(unsigned recommendedRows) const | 
|---|
| 108 | { | 
|---|
| 109 | BZPRECONDITION(iter2_.rows(recommendedRows) == | 
|---|
| 110 | iter1_.rows(recommendedRows)); | 
|---|
| 111 | return iter1_.rows(recommendedRows); | 
|---|
| 112 | } | 
|---|
| 113 |  | 
|---|
| 114 | unsigned cols(unsigned recommendedCols) const | 
|---|
| 115 | { | 
|---|
| 116 | BZPRECONDITION(iter2_.cols(recommendedCols) == | 
|---|
| 117 | iter1_.cols(recommendedCols)); | 
|---|
| 118 | return iter1_.cols(recommendedCols); | 
|---|
| 119 | } | 
|---|
| 120 |  | 
|---|
| 121 | private: | 
|---|
| 122 | T_expr1 iter1_; | 
|---|
| 123 | T_expr2 iter2_; | 
|---|
| 124 | }; | 
|---|
| 125 |  | 
|---|
| 126 | template<class P_expr, class P_unaryOp> | 
|---|
| 127 | class _bz_MatExprUnaryOp : public BlitzMatrixExpressionsBase { | 
|---|
| 128 |  | 
|---|
| 129 | public: | 
|---|
| 130 | typedef P_expr T_expr; | 
|---|
| 131 | typedef P_unaryOp T_unaryOp; | 
|---|
| 132 | typedef _bz_typename T_unaryOp::T_numtype T_numtype; | 
|---|
| 133 |  | 
|---|
| 134 | #ifdef BZ_PASS_EXPR_BY_VALUE | 
|---|
| 135 | _bz_MatExprUnaryOp(T_expr iter) | 
|---|
| 136 | : iter_(iter) | 
|---|
| 137 | { } | 
|---|
| 138 | #else | 
|---|
| 139 | _bz_MatExprUnaryOp(const T_expr& iter) | 
|---|
| 140 | : iter_(iter) | 
|---|
| 141 | { } | 
|---|
| 142 | #endif | 
|---|
| 143 |  | 
|---|
| 144 | T_numtype operator()(unsigned i, unsigned j) const | 
|---|
| 145 | { return T_unaryOp::apply(iter_(i,j)); } | 
|---|
| 146 |  | 
|---|
| 147 | unsigned rows(unsigned recommendedRows) const | 
|---|
| 148 | { return iter_.rows(recommendedRows); } | 
|---|
| 149 |  | 
|---|
| 150 | unsigned cols(unsigned recommendedCols) const | 
|---|
| 151 | { return iter_.cols(recommendedCols); } | 
|---|
| 152 |  | 
|---|
| 153 | private: | 
|---|
| 154 | T_expr iter_; | 
|---|
| 155 | }; | 
|---|
| 156 |  | 
|---|
| 157 | template<class P_numtype> | 
|---|
| 158 | class _bz_MatExprConstant : public BlitzMatrixExpressionsBase { | 
|---|
| 159 | public: | 
|---|
| 160 | typedef P_numtype T_numtype; | 
|---|
| 161 |  | 
|---|
| 162 | _bz_MatExprConstant(P_numtype value) | 
|---|
| 163 | : value_(value) | 
|---|
| 164 | { } | 
|---|
| 165 |  | 
|---|
| 166 | T_numtype operator()(unsigned i, unsigned j) const | 
|---|
| 167 | { return value_; } | 
|---|
| 168 |  | 
|---|
| 169 | unsigned rows(unsigned recommendedRows) const | 
|---|
| 170 | { return recommendedRows; } | 
|---|
| 171 |  | 
|---|
| 172 | unsigned cols(unsigned recommendedCols) const | 
|---|
| 173 | { return recommendedCols; } | 
|---|
| 174 |  | 
|---|
| 175 | private: | 
|---|
| 176 | T_numtype value_; | 
|---|
| 177 | }; | 
|---|
| 178 |  | 
|---|
| 179 | BZ_NAMESPACE_END | 
|---|
| 180 |  | 
|---|
| 181 | #include <blitz/matref.h> | 
|---|
| 182 | #include <blitz/matbops.h> | 
|---|
| 183 | #include <blitz/matuops.h> | 
|---|
| 184 |  | 
|---|
| 185 | #endif // BZ_MATEXPR_H | 
|---|