1 | /***************************************************************************
|
---|
2 | * blitz/matgen.h Declarations for RowMajor and ColumnMajor matrices
|
---|
3 | *
|
---|
4 | * $Id: matgen.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_MATGEN_H
|
---|
39 | #define BZ_MATGEN_H
|
---|
40 |
|
---|
41 | #ifndef BZ_MSTRUCT_H
|
---|
42 | #error <blitz/matgen.h> must be included via <blitz/mstruct.h>
|
---|
43 | #endif // BZ_MSTRUCT_H
|
---|
44 |
|
---|
45 | BZ_NAMESPACE(blitz)
|
---|
46 |
|
---|
47 | class GeneralMatrix : public AsymmetricMatrix {
|
---|
48 |
|
---|
49 | public:
|
---|
50 | GeneralMatrix()
|
---|
51 | { }
|
---|
52 |
|
---|
53 | GeneralMatrix(unsigned rows, unsigned cols)
|
---|
54 | : AsymmetricMatrix(rows, cols)
|
---|
55 | {
|
---|
56 | }
|
---|
57 |
|
---|
58 | unsigned firstInRow(unsigned i) const
|
---|
59 | { return 0; }
|
---|
60 |
|
---|
61 | unsigned lastInRow(unsigned i) const
|
---|
62 | { return cols_ - 1; }
|
---|
63 |
|
---|
64 | unsigned firstInCol(unsigned j) const
|
---|
65 | { return 0; }
|
---|
66 |
|
---|
67 | unsigned lastInCol(unsigned j) const
|
---|
68 | { return rows_ - 1; }
|
---|
69 |
|
---|
70 | unsigned numElements() const
|
---|
71 | { return rows_ * cols_; }
|
---|
72 | };
|
---|
73 |
|
---|
74 | class GeneralIterator {
|
---|
75 | public:
|
---|
76 | GeneralIterator(unsigned rows, unsigned cols)
|
---|
77 | {
|
---|
78 | rows_ = rows;
|
---|
79 | cols_ = cols;
|
---|
80 | i_ = 0;
|
---|
81 | j_ = 0;
|
---|
82 | offset_ = 0;
|
---|
83 | good_ = true;
|
---|
84 | }
|
---|
85 |
|
---|
86 | unsigned offset() const
|
---|
87 | { return offset_; }
|
---|
88 |
|
---|
89 | operator _bz_bool() const
|
---|
90 | { return good_; }
|
---|
91 |
|
---|
92 | unsigned row() const
|
---|
93 | { return i_; }
|
---|
94 |
|
---|
95 | unsigned col() const
|
---|
96 | { return j_; }
|
---|
97 |
|
---|
98 | protected:
|
---|
99 | unsigned rows_, cols_;
|
---|
100 | unsigned offset_;
|
---|
101 | unsigned i_, j_;
|
---|
102 | _bz_bool good_;
|
---|
103 | };
|
---|
104 |
|
---|
105 | class RowMajorIterator : public GeneralIterator {
|
---|
106 | public:
|
---|
107 | RowMajorIterator(unsigned rows, unsigned cols)
|
---|
108 | : GeneralIterator(rows, cols)
|
---|
109 | { }
|
---|
110 |
|
---|
111 | void operator++()
|
---|
112 | {
|
---|
113 | ++offset_;
|
---|
114 | ++j_;
|
---|
115 | if (j_ == cols_)
|
---|
116 | {
|
---|
117 | j_ = 0;
|
---|
118 | ++i_;
|
---|
119 | if (i_ == rows_)
|
---|
120 | good_ = false;
|
---|
121 | }
|
---|
122 | }
|
---|
123 | };
|
---|
124 |
|
---|
125 | class RowMajor : public GeneralMatrix {
|
---|
126 |
|
---|
127 | public:
|
---|
128 | typedef RowMajorIterator T_iterator;
|
---|
129 |
|
---|
130 | RowMajor()
|
---|
131 | { }
|
---|
132 |
|
---|
133 | RowMajor(unsigned rows, unsigned cols)
|
---|
134 | : GeneralMatrix(rows, cols)
|
---|
135 | { }
|
---|
136 |
|
---|
137 | unsigned coordToOffset(unsigned i, unsigned j) const
|
---|
138 | {
|
---|
139 | return i*cols_+j;
|
---|
140 | }
|
---|
141 |
|
---|
142 | template<class T_numtype>
|
---|
143 | T_numtype get(const T_numtype * _bz_restrict data,
|
---|
144 | unsigned i, unsigned j) const
|
---|
145 | {
|
---|
146 | BZPRECONDITION(inRange(i,j));
|
---|
147 | return data[coordToOffset(i,j)];
|
---|
148 | }
|
---|
149 |
|
---|
150 | template<class T_numtype>
|
---|
151 | T_numtype& get(T_numtype * _bz_restrict data, unsigned i, unsigned j)
|
---|
152 | {
|
---|
153 | BZPRECONDITION(inRange(i,j));
|
---|
154 | return data[coordToOffset(i,j)];
|
---|
155 | }
|
---|
156 | };
|
---|
157 |
|
---|
158 | class ColumnMajorIterator : public GeneralIterator {
|
---|
159 | public:
|
---|
160 | ColumnMajorIterator(unsigned rows, unsigned cols)
|
---|
161 | : GeneralIterator(rows, cols)
|
---|
162 | {
|
---|
163 | }
|
---|
164 |
|
---|
165 | void operator++()
|
---|
166 | {
|
---|
167 | ++offset_;
|
---|
168 | ++i_;
|
---|
169 | if (i_ == rows_)
|
---|
170 | {
|
---|
171 | i_ = 0;
|
---|
172 | ++j_;
|
---|
173 | if (j_ == cols_)
|
---|
174 | good_ = false;
|
---|
175 | }
|
---|
176 | }
|
---|
177 | };
|
---|
178 |
|
---|
179 | class ColumnMajor : public GeneralMatrix {
|
---|
180 |
|
---|
181 | public:
|
---|
182 | ColumnMajor()
|
---|
183 | { }
|
---|
184 |
|
---|
185 | ColumnMajor(unsigned rows, unsigned cols)
|
---|
186 | : GeneralMatrix(rows, cols)
|
---|
187 | { }
|
---|
188 |
|
---|
189 | unsigned coordToOffset(unsigned i, unsigned j) const
|
---|
190 | {
|
---|
191 | return j*rows_ + i;
|
---|
192 | }
|
---|
193 |
|
---|
194 | template<class T_numtype>
|
---|
195 | T_numtype get(const T_numtype * _bz_restrict data,
|
---|
196 | unsigned i, unsigned j) const
|
---|
197 | {
|
---|
198 | BZPRECONDITION(inRange(i,j));
|
---|
199 | return data[coordToOffset(i,j)];
|
---|
200 | }
|
---|
201 |
|
---|
202 | template<class T_numtype>
|
---|
203 | T_numtype& get(T_numtype * _bz_restrict data, unsigned i, unsigned j)
|
---|
204 | {
|
---|
205 | BZPRECONDITION(inRange(i,j));
|
---|
206 | return data[coordToOffset(i,j)];
|
---|
207 | }
|
---|
208 | };
|
---|
209 |
|
---|
210 | BZ_NAMESPACE_END
|
---|
211 |
|
---|
212 | #endif // BZ_MATGEN_H
|
---|
213 |
|
---|