source: XMLIO_V2/external/include/blitz/matexpr.h @ 73

Last change on this file since 73 was 73, checked in by ymipsl, 14 years ago
  • Property svn:eol-style set to native
File size: 4.5 KB
Line 
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
35BZ_NAMESPACE(blitz)
36
37// BlitzMatrixExpressionsBase is a dummy class provided for users of
38// graphical class browsers. 
39class BlitzMatrixExpressionsBase { };
40
41template<typename P_expr>
42class _bz_MatExpr : public BlitzMatrixExpressionsBase {
43
44public:
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
67private:
68    T_expr iter_;
69};
70
71template<typename P_expr1, typename P_expr2, typename P_op>
72class _bz_MatExprOp : public BlitzMatrixExpressionsBase {
73
74public:
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
109private:
110    T_expr1 iter1_;
111    T_expr2 iter2_;
112};
113
114template<typename P_expr, typename P_unaryOp>
115class _bz_MatExprUnaryOp : public BlitzMatrixExpressionsBase {
116
117public:
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
141private:
142    T_expr iter_;   
143};
144
145template<typename P_numtype>
146class _bz_MatExprConstant : public BlitzMatrixExpressionsBase {
147public:
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
163private:
164    T_numtype value_;
165};
166
167BZ_NAMESPACE_END
168
169#include <blitz/matref.h>
170#include <blitz/matbops.h>
171#include <blitz/matuops.h>
172
173#endif // BZ_MATEXPR_H
Note: See TracBrowser for help on using the repository browser.