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