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