458
|
1 // -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993, 1994 John W. Eaton |
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_Matrix_int_h) |
|
25 #define octave_Matrix_int_h 1 |
|
26 |
|
27 #if defined (__GNUG__) |
|
28 #pragma interface |
|
29 #endif |
|
30 |
532
|
31 // For FILE... |
|
32 #include <stdio.h> |
|
33 |
458
|
34 #include "Array.h" |
|
35 |
|
36 #include "mx-defs.h" |
|
37 |
|
38 extern "C++" { |
|
39 |
|
40 class Matrix : public Array2<double> |
|
41 { |
532
|
42 friend class ColumnVector; |
|
43 friend class AEPBAL; |
|
44 friend class CHOL; |
|
45 friend class GEPBAL; |
|
46 friend class HESS; |
458
|
47 friend class LU; |
532
|
48 friend class QR; |
536
|
49 friend class QRP; |
532
|
50 friend class SCHUR; |
458
|
51 friend class SVD; |
532
|
52 friend class ComplexMatrix; |
458
|
53 |
|
54 public: |
|
55 |
|
56 Matrix (void) : Array2<double> () { } |
|
57 Matrix (int r, int c) : Array2<double> (r, c) { } |
|
58 Matrix (int r, int c, double val) : Array2<double> (r, c, val) { } |
|
59 Matrix (const Array2<double>& a) : Array2<double> (a) { } |
|
60 Matrix (const Matrix& a) : Array2<double> (a) { } |
|
61 Matrix (const DiagArray<double>& a) : Array2<double> (a) { } |
|
62 Matrix (const DiagMatrix& a); |
|
63 // Matrix (double a) : Array2<double> (1, 1, a) { } |
|
64 |
|
65 Matrix& operator = (const Matrix& a) |
|
66 { |
|
67 Array2<double>::operator = (a); |
|
68 return *this; |
|
69 } |
|
70 |
|
71 int operator == (const Matrix& a) const; |
|
72 int operator != (const Matrix& a) const; |
|
73 |
|
74 // destructive insert/delete/reorder operations |
|
75 |
|
76 Matrix& insert (const Matrix& a, int r, int c); |
|
77 Matrix& insert (const RowVector& a, int r, int c); |
|
78 Matrix& insert (const ColumnVector& a, int r, int c); |
|
79 Matrix& insert (const DiagMatrix& a, int r, int c); |
|
80 |
|
81 Matrix& fill (double val); |
|
82 Matrix& fill (double val, int r1, int c1, int r2, int c2); |
|
83 |
|
84 Matrix append (const Matrix& a) const; |
|
85 Matrix append (const RowVector& a) const; |
|
86 Matrix append (const ColumnVector& a) const; |
|
87 Matrix append (const DiagMatrix& a) const; |
|
88 |
|
89 Matrix stack (const Matrix& a) const; |
|
90 Matrix stack (const RowVector& a) const; |
|
91 Matrix stack (const ColumnVector& a) const; |
|
92 Matrix stack (const DiagMatrix& a) const; |
|
93 |
|
94 Matrix transpose (void) const; |
|
95 |
|
96 // resize is the destructive equivalent for this one |
|
97 |
|
98 Matrix extract (int r1, int c1, int r2, int c2) const; |
|
99 |
|
100 // extract row or column i. |
|
101 |
|
102 RowVector row (int i) const; |
|
103 RowVector row (char *s) const; |
|
104 |
|
105 ColumnVector column (int i) const; |
|
106 ColumnVector column (char *s) const; |
|
107 |
|
108 Matrix inverse (void) const; |
|
109 Matrix inverse (int& info) const; |
|
110 Matrix inverse (int& info, double& rcond) const; |
|
111 |
|
112 ComplexMatrix fourier (void) const; |
|
113 ComplexMatrix ifourier (void) const; |
|
114 |
677
|
115 ComplexMatrix fourier2d (void) const; |
|
116 ComplexMatrix ifourier2d (void) const; |
|
117 |
458
|
118 DET determinant (void) const; |
|
119 DET determinant (int& info) const; |
|
120 DET determinant (int& info, double& rcond) const; |
|
121 |
|
122 Matrix solve (const Matrix& b) const; |
|
123 Matrix solve (const Matrix& b, int& info) const; |
|
124 Matrix solve (const Matrix& b, int& info, double& rcond) const; |
|
125 |
|
126 ComplexMatrix solve (const ComplexMatrix& b) const; |
|
127 ComplexMatrix solve (const ComplexMatrix& b, int& info) const; |
|
128 ComplexMatrix solve (const ComplexMatrix& b, int& info, double& rcond) const; |
|
129 |
|
130 ColumnVector solve (const ColumnVector& b) const; |
|
131 ColumnVector solve (const ColumnVector& b, int& info) const; |
|
132 ColumnVector solve (const ColumnVector& b, int& info, double& rcond) const; |
|
133 |
|
134 ComplexColumnVector solve (const ComplexColumnVector& b) const; |
|
135 ComplexColumnVector solve (const ComplexColumnVector& b, int& info) const; |
|
136 ComplexColumnVector solve (const ComplexColumnVector& b, int& info, |
|
137 double& rcond) const; |
|
138 |
|
139 Matrix lssolve (const Matrix& b) const; |
|
140 Matrix lssolve (const Matrix& b, int& info) const; |
|
141 Matrix lssolve (const Matrix& b, int& info, int& rank) const; |
|
142 |
|
143 ComplexMatrix lssolve (const ComplexMatrix& b) const; |
|
144 ComplexMatrix lssolve (const ComplexMatrix& b, int& info) const; |
|
145 ComplexMatrix lssolve (const ComplexMatrix& b, int& info, |
|
146 int& rank) const; |
|
147 |
|
148 ColumnVector lssolve (const ColumnVector& b) const; |
|
149 ColumnVector lssolve (const ColumnVector& b, int& info) const; |
|
150 ColumnVector lssolve (const ColumnVector& b, int& info, int& rank) const; |
|
151 |
|
152 ComplexColumnVector lssolve (const ComplexColumnVector& b) const; |
|
153 ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info) const; |
|
154 ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info, |
|
155 int& rank) const; |
|
156 |
|
157 Matrix& operator += (const Matrix& a); |
|
158 Matrix& operator -= (const Matrix& a); |
|
159 |
|
160 Matrix& operator += (const DiagMatrix& a); |
|
161 Matrix& operator -= (const DiagMatrix& a); |
|
162 |
|
163 // unary operations |
|
164 |
|
165 Matrix operator ! (void) const; |
|
166 |
|
167 // matrix by scalar -> matrix operations |
|
168 |
|
169 friend ComplexMatrix operator + (const Matrix& a, const Complex& s); |
|
170 friend ComplexMatrix operator - (const Matrix& a, const Complex& s); |
|
171 friend ComplexMatrix operator * (const Matrix& a, const Complex& s); |
|
172 friend ComplexMatrix operator / (const Matrix& a, const Complex& s); |
|
173 |
|
174 // scalar by matrix -> matrix operations |
|
175 |
|
176 friend ComplexMatrix operator + (const Complex& s, const Matrix& a); |
|
177 friend ComplexMatrix operator - (const Complex& s, const Matrix& a); |
|
178 friend ComplexMatrix operator * (const Complex& s, const Matrix& a); |
|
179 friend ComplexMatrix operator / (const Complex& s, const Matrix& a); |
|
180 |
|
181 // matrix by column vector -> column vector operations |
|
182 |
|
183 friend ColumnVector operator * (const Matrix& a, const ColumnVector& b); |
|
184 friend ComplexColumnVector operator * (const Matrix& a, |
|
185 const ComplexColumnVector& b); |
|
186 |
|
187 // matrix by diagonal matrix -> matrix operations |
|
188 |
|
189 friend Matrix operator + (const Matrix& a, const DiagMatrix& b); |
|
190 friend Matrix operator - (const Matrix& a, const DiagMatrix& b); |
|
191 friend Matrix operator * (const Matrix& a, const DiagMatrix& b); |
|
192 |
|
193 friend ComplexMatrix operator + (const Matrix& a, |
|
194 const ComplexDiagMatrix& b); |
|
195 friend ComplexMatrix operator - (const Matrix& a, |
|
196 const ComplexDiagMatrix& b); |
|
197 friend ComplexMatrix operator * (const Matrix& a, |
|
198 const ComplexDiagMatrix& b); |
|
199 |
|
200 // matrix by matrix -> matrix operations |
|
201 |
|
202 friend Matrix operator * (const Matrix& a, const Matrix& b); |
|
203 friend ComplexMatrix operator * (const Matrix& a, const ComplexMatrix& b); |
|
204 |
|
205 friend ComplexMatrix operator + (const Matrix& a, const ComplexMatrix& b); |
|
206 friend ComplexMatrix operator - (const Matrix& a, const ComplexMatrix& b); |
|
207 |
|
208 friend ComplexMatrix product (const Matrix& a, const ComplexMatrix& b); |
|
209 friend ComplexMatrix quotient (const Matrix& a, const ComplexMatrix& b); |
|
210 |
|
211 // other operations |
|
212 |
|
213 friend Matrix map (d_d_Mapper f, const Matrix& a); |
|
214 void map (d_d_Mapper f); |
|
215 |
|
216 Matrix all (void) const; |
|
217 Matrix any (void) const; |
|
218 |
|
219 Matrix cumprod (void) const; |
|
220 Matrix cumsum (void) const; |
|
221 Matrix prod (void) const; |
|
222 Matrix sum (void) const; |
|
223 Matrix sumsq (void) const; |
|
224 |
|
225 ColumnVector diag (void) const; |
|
226 ColumnVector diag (int k) const; |
|
227 |
|
228 ColumnVector row_min (void) const; |
|
229 ColumnVector row_min_loc (void) const; |
|
230 |
|
231 ColumnVector row_max (void) const; |
|
232 ColumnVector row_max_loc (void) const; |
|
233 |
|
234 RowVector column_min (void) const; |
|
235 RowVector column_min_loc (void) const; |
|
236 |
|
237 RowVector column_max (void) const; |
|
238 RowVector column_max_loc (void) const; |
|
239 |
|
240 // i/o |
|
241 |
|
242 friend ostream& operator << (ostream& os, const Matrix& a); |
|
243 friend istream& operator >> (istream& is, Matrix& a); |
|
244 |
471
|
245 int read (FILE *fptr, char *type); |
|
246 int write (FILE *fptr, char *type); |
458
|
247 |
|
248 // Until templates really work with g++: |
|
249 |
|
250 #define KLUDGE_MATRICES |
|
251 #define TYPE double |
|
252 #define KL_MAT_TYPE Matrix |
|
253 #include "mx-kludge.h" |
|
254 #undef KLUDGE_MATRICES |
|
255 #undef TYPE |
|
256 #undef KL_MAT_TYPE |
|
257 |
|
258 private: |
|
259 |
|
260 Matrix (double *d, int r, int c) : Array2<double> (d, r, c) { } |
|
261 }; |
|
262 |
|
263 } // extern "C++" |
|
264 |
|
265 #endif |
|
266 |
|
267 /* |
|
268 ;;; Local Variables: *** |
|
269 ;;; mode: C++ *** |
|
270 ;;; page-delimiter: "^/\\*" *** |
|
271 ;;; End: *** |
|
272 */ |