1 | /***************************************************************************
|
---|
2 | * blitz/matrix.h Declaration of the Matrix<T_type, T_structure> class
|
---|
3 | *
|
---|
4 | * $Id: matrix.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.6 1998/03/14 00:04:47 tveldhui
|
---|
27 | * 0.2-alpha-05
|
---|
28 | *
|
---|
29 | * Revision 1.5 1997/07/16 14:51:20 tveldhui
|
---|
30 | * Update: Alpha release 0.2 (Arrays)
|
---|
31 | *
|
---|
32 | * Revision 1.4 1997/01/24 14:42:00 tveldhui
|
---|
33 | * Periodic RCS update
|
---|
34 | *
|
---|
35 | * Revision 1.3 1997/01/23 03:28:28 tveldhui
|
---|
36 | * Periodic RCS update
|
---|
37 | *
|
---|
38 | * Revision 1.2 1997/01/13 22:19:58 tveldhui
|
---|
39 | * Periodic RCS update
|
---|
40 | *
|
---|
41 | * Revision 1.1 1996/11/11 17:29:13 tveldhui
|
---|
42 | * Initial revision
|
---|
43 | *
|
---|
44 | * Revision 1.2 1996/10/31 21:06:54 tveldhui
|
---|
45 | * Did away with multiple template parameters. Only numeric type
|
---|
46 | * and structure parameters now.
|
---|
47 | *
|
---|
48 | *
|
---|
49 | */
|
---|
50 |
|
---|
51 | #ifndef BZ_MATRIX_H
|
---|
52 | #define BZ_MATRIX_H
|
---|
53 |
|
---|
54 | #ifndef BZ_BLITZ_H
|
---|
55 | #include <blitz/blitz.h>
|
---|
56 | #endif
|
---|
57 |
|
---|
58 | #ifndef BZ_MEMBLOCK_H
|
---|
59 | #include <blitz/memblock.h>
|
---|
60 | #endif
|
---|
61 |
|
---|
62 | #ifndef BZ_MSTRUCT_H
|
---|
63 | #include <blitz/mstruct.h>
|
---|
64 | #endif
|
---|
65 |
|
---|
66 | BZ_NAMESPACE(blitz)
|
---|
67 |
|
---|
68 | // Forward declarations
|
---|
69 | template<class P_numtype, class P_structure>
|
---|
70 | class _bz_MatrixRef;
|
---|
71 |
|
---|
72 | template<class P_expr>
|
---|
73 | class _bz_MatExpr;
|
---|
74 |
|
---|
75 | // Declaration of class Matrix
|
---|
76 | template<class P_numtype, class P_structure BZ_TEMPLATE_DEFAULT(RowMajor)>
|
---|
77 | class Matrix : protected MemoryBlockReference<P_numtype> {
|
---|
78 |
|
---|
79 | public:
|
---|
80 |
|
---|
81 | //////////////////////////////////////////////
|
---|
82 | // Public Types
|
---|
83 | //////////////////////////////////////////////
|
---|
84 |
|
---|
85 | typedef P_numtype T_numtype;
|
---|
86 | typedef P_structure T_structure;
|
---|
87 | typedef Matrix<P_numtype, P_structure> T_matrix;
|
---|
88 |
|
---|
89 | //////////////////////////////////////////////
|
---|
90 | // Constructors //
|
---|
91 | //////////////////////////////////////////////
|
---|
92 |
|
---|
93 | Matrix()
|
---|
94 | { }
|
---|
95 |
|
---|
96 | Matrix(int rows, int cols, T_structure structure = T_structure())
|
---|
97 | : structure_(structure)
|
---|
98 | {
|
---|
99 | structure_.resize(rows, cols);
|
---|
100 | MemoryBlockReference<T_numtype>::newBlock(structure_.numElements());
|
---|
101 | }
|
---|
102 |
|
---|
103 | // Matrix(int rows, int cols, T_numtype initValue,
|
---|
104 | // T_structure structure = T_structure(rows, cols));
|
---|
105 | // Matrix(int rows, int cols, Random);
|
---|
106 | // Matrix(int rows, int cols, matrix-expression);
|
---|
107 | // Matrix(int rows, int cols, T_numtype* data, int rowStride, int colStride);
|
---|
108 | // _bz_explicit Matrix(Vector<T_numtype>& matrix);
|
---|
109 | // _bz_explicit Matrix(unsigned length);
|
---|
110 |
|
---|
111 | // Create a vector view of an already allocated block of memory.
|
---|
112 | // Note that the memory will not be freed when this vector is
|
---|
113 | // destroyed.
|
---|
114 | // Matrix(unsigned length, T_numtype* data, int stride = 1);
|
---|
115 |
|
---|
116 | //////////////////////////////////////////////
|
---|
117 | // Member functions
|
---|
118 | //////////////////////////////////////////////
|
---|
119 |
|
---|
120 | //T_iterator begin() const;
|
---|
121 | //T_constIterator begin() const;
|
---|
122 | //T_vector copy() const;
|
---|
123 | //T_iterator end() const;
|
---|
124 | //T_constIterator end() const;
|
---|
125 |
|
---|
126 | unsigned cols() const
|
---|
127 | { return structure_.columns(); }
|
---|
128 |
|
---|
129 | unsigned columns() const
|
---|
130 | { return structure_.columns(); }
|
---|
131 |
|
---|
132 | void makeUnique() const;
|
---|
133 |
|
---|
134 | unsigned numElements() const
|
---|
135 | { return structure_.numElements(); }
|
---|
136 |
|
---|
137 | void reference(T_matrix&);
|
---|
138 |
|
---|
139 | void resize(unsigned rows, unsigned cols)
|
---|
140 | {
|
---|
141 | structure_.resize(rows, cols);
|
---|
142 | MemoryBlockReference<T_numtype>::newBlock(structure_.numElements());
|
---|
143 | }
|
---|
144 |
|
---|
145 | // void resizeAndPreserve(unsigned newLength);
|
---|
146 |
|
---|
147 | unsigned rows() const
|
---|
148 | { return structure_.rows(); }
|
---|
149 |
|
---|
150 | _bz_MatrixRef<T_numtype, T_structure> _bz_getRef() const
|
---|
151 | { return _bz_MatrixRef<T_numtype, T_structure>(*this); }
|
---|
152 |
|
---|
153 | //////////////////////////////////////////////
|
---|
154 | // Subscripting operators
|
---|
155 | //////////////////////////////////////////////
|
---|
156 |
|
---|
157 | T_numtype operator()(unsigned i, unsigned j) const
|
---|
158 | {
|
---|
159 | return structure_.get(data_, i, j);
|
---|
160 | }
|
---|
161 |
|
---|
162 | T_numtype& _bz_restrict operator()(unsigned i, unsigned j)
|
---|
163 | {
|
---|
164 | return structure_.get(data_, i, j);
|
---|
165 | }
|
---|
166 |
|
---|
167 | // T_matrix operator()(Range,Range);
|
---|
168 |
|
---|
169 | // T_matrixIndirect operator()(Vector<int>,Vector<int>);
|
---|
170 | // T_matrixIndirect operator()(integer-placeholder-expression, Range);
|
---|
171 | // T_matrix operator()(difference-equation-expression)
|
---|
172 |
|
---|
173 | //////////////////////////////////////////////
|
---|
174 | // Assignment operators
|
---|
175 | //////////////////////////////////////////////
|
---|
176 |
|
---|
177 | // Scalar operand
|
---|
178 | T_matrix& operator=(T_numtype);
|
---|
179 | T_matrix& operator+=(T_numtype);
|
---|
180 | T_matrix& operator-=(T_numtype);
|
---|
181 | T_matrix& operator*=(T_numtype);
|
---|
182 | T_matrix& operator/=(T_numtype);
|
---|
183 |
|
---|
184 | // Matrix operand
|
---|
185 |
|
---|
186 | template<class P_numtype2, class P_structure2>
|
---|
187 | T_matrix& operator=(const Matrix<P_numtype2, P_structure2> &);
|
---|
188 | template<class P_numtype2, class P_structure2>
|
---|
189 | T_matrix& operator+=(const Matrix<P_numtype2, P_structure2>&);
|
---|
190 | template<class P_numtype2, class P_structure2>
|
---|
191 | T_matrix& operator-=(const Matrix<P_numtype2, P_structure2> &);
|
---|
192 | template<class P_numtype2, class P_structure2>
|
---|
193 | T_matrix& operator*=(const Matrix<P_numtype2, P_structure2> &);
|
---|
194 | template<class P_numtype2, class P_structure2>
|
---|
195 | T_matrix& operator/=(const Matrix<P_numtype2, P_structure2> &);
|
---|
196 |
|
---|
197 | // Matrix expression operand
|
---|
198 | template<class P_expr>
|
---|
199 | T_matrix& operator=(_bz_MatExpr<P_expr>);
|
---|
200 |
|
---|
201 | // Integer placeholder expression operand
|
---|
202 | // MatrixPick operand
|
---|
203 |
|
---|
204 | //////////////////////////////////////////////
|
---|
205 | // Unary operators
|
---|
206 | //////////////////////////////////////////////
|
---|
207 |
|
---|
208 | T_matrix& operator++();
|
---|
209 | void operator++(int);
|
---|
210 | T_matrix& operator--();
|
---|
211 | void operator--(int);
|
---|
212 |
|
---|
213 | private:
|
---|
214 | T_structure structure_;
|
---|
215 | };
|
---|
216 |
|
---|
217 | template<class P_numtype, class P_structure>
|
---|
218 | ostream& operator<<(ostream& os, const Matrix<P_numtype, P_structure>& matrix);
|
---|
219 |
|
---|
220 | // Global operators
|
---|
221 | // +,-,*,/ with all possible combinations of:
|
---|
222 | // - scalar
|
---|
223 | // - matrix
|
---|
224 | // - matrix pick
|
---|
225 | // - matrix expression
|
---|
226 | // Pointwise Math functions: sin, cos, etc.
|
---|
227 | // Global functions
|
---|
228 |
|
---|
229 | BZ_NAMESPACE_END
|
---|
230 |
|
---|
231 | #include <blitz/matrix.cc>
|
---|
232 | #include <blitz/matexpr.h>
|
---|
233 |
|
---|
234 | #endif // BZ_MATRIX_H
|
---|