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; |
|
49 friend class SCHUR; |
458
|
50 friend class SVD; |
532
|
51 friend class ComplexMatrix; |
458
|
52 |
|
53 public: |
|
54 |
|
55 Matrix (void) : Array2<double> () { } |
|
56 Matrix (int r, int c) : Array2<double> (r, c) { } |
|
57 Matrix (int r, int c, double val) : Array2<double> (r, c, val) { } |
|
58 Matrix (const Array2<double>& a) : Array2<double> (a) { } |
|
59 Matrix (const Matrix& a) : Array2<double> (a) { } |
|
60 Matrix (const DiagArray<double>& a) : Array2<double> (a) { } |
|
61 Matrix (const DiagMatrix& a); |
|
62 // Matrix (double a) : Array2<double> (1, 1, a) { } |
|
63 |
|
64 Matrix& operator = (const Matrix& a) |
|
65 { |
|
66 Array2<double>::operator = (a); |
|
67 return *this; |
|
68 } |
|
69 |
|
70 int operator == (const Matrix& a) const; |
|
71 int operator != (const Matrix& a) const; |
|
72 |
|
73 // destructive insert/delete/reorder operations |
|
74 |
|
75 Matrix& insert (const Matrix& a, int r, int c); |
|
76 Matrix& insert (const RowVector& a, int r, int c); |
|
77 Matrix& insert (const ColumnVector& a, int r, int c); |
|
78 Matrix& insert (const DiagMatrix& a, int r, int c); |
|
79 |
|
80 Matrix& fill (double val); |
|
81 Matrix& fill (double val, int r1, int c1, int r2, int c2); |
|
82 |
|
83 Matrix append (const Matrix& a) const; |
|
84 Matrix append (const RowVector& a) const; |
|
85 Matrix append (const ColumnVector& a) const; |
|
86 Matrix append (const DiagMatrix& a) const; |
|
87 |
|
88 Matrix stack (const Matrix& a) const; |
|
89 Matrix stack (const RowVector& a) const; |
|
90 Matrix stack (const ColumnVector& a) const; |
|
91 Matrix stack (const DiagMatrix& a) const; |
|
92 |
|
93 Matrix transpose (void) const; |
|
94 |
|
95 // resize is the destructive equivalent for this one |
|
96 |
|
97 Matrix extract (int r1, int c1, int r2, int c2) const; |
|
98 |
|
99 // extract row or column i. |
|
100 |
|
101 RowVector row (int i) const; |
|
102 RowVector row (char *s) const; |
|
103 |
|
104 ColumnVector column (int i) const; |
|
105 ColumnVector column (char *s) const; |
|
106 |
|
107 Matrix inverse (void) const; |
|
108 Matrix inverse (int& info) const; |
|
109 Matrix inverse (int& info, double& rcond) const; |
|
110 |
|
111 ComplexMatrix fourier (void) const; |
|
112 ComplexMatrix ifourier (void) const; |
|
113 |
|
114 DET determinant (void) const; |
|
115 DET determinant (int& info) const; |
|
116 DET determinant (int& info, double& rcond) const; |
|
117 |
|
118 Matrix solve (const Matrix& b) const; |
|
119 Matrix solve (const Matrix& b, int& info) const; |
|
120 Matrix solve (const Matrix& b, int& info, double& rcond) const; |
|
121 |
|
122 ComplexMatrix solve (const ComplexMatrix& b) const; |
|
123 ComplexMatrix solve (const ComplexMatrix& b, int& info) const; |
|
124 ComplexMatrix solve (const ComplexMatrix& b, int& info, double& rcond) const; |
|
125 |
|
126 ColumnVector solve (const ColumnVector& b) const; |
|
127 ColumnVector solve (const ColumnVector& b, int& info) const; |
|
128 ColumnVector solve (const ColumnVector& b, int& info, double& rcond) const; |
|
129 |
|
130 ComplexColumnVector solve (const ComplexColumnVector& b) const; |
|
131 ComplexColumnVector solve (const ComplexColumnVector& b, int& info) const; |
|
132 ComplexColumnVector solve (const ComplexColumnVector& b, int& info, |
|
133 double& rcond) const; |
|
134 |
|
135 Matrix lssolve (const Matrix& b) const; |
|
136 Matrix lssolve (const Matrix& b, int& info) const; |
|
137 Matrix lssolve (const Matrix& b, int& info, int& rank) const; |
|
138 |
|
139 ComplexMatrix lssolve (const ComplexMatrix& b) const; |
|
140 ComplexMatrix lssolve (const ComplexMatrix& b, int& info) const; |
|
141 ComplexMatrix lssolve (const ComplexMatrix& b, int& info, |
|
142 int& rank) const; |
|
143 |
|
144 ColumnVector lssolve (const ColumnVector& b) const; |
|
145 ColumnVector lssolve (const ColumnVector& b, int& info) const; |
|
146 ColumnVector lssolve (const ColumnVector& b, int& info, int& rank) const; |
|
147 |
|
148 ComplexColumnVector lssolve (const ComplexColumnVector& b) const; |
|
149 ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info) const; |
|
150 ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info, |
|
151 int& rank) const; |
|
152 |
|
153 Matrix& operator += (const Matrix& a); |
|
154 Matrix& operator -= (const Matrix& a); |
|
155 |
|
156 Matrix& operator += (const DiagMatrix& a); |
|
157 Matrix& operator -= (const DiagMatrix& a); |
|
158 |
|
159 // unary operations |
|
160 |
|
161 Matrix operator ! (void) const; |
|
162 |
|
163 // matrix by scalar -> matrix operations |
|
164 |
|
165 friend ComplexMatrix operator + (const Matrix& a, const Complex& s); |
|
166 friend ComplexMatrix operator - (const Matrix& a, const Complex& s); |
|
167 friend ComplexMatrix operator * (const Matrix& a, const Complex& s); |
|
168 friend ComplexMatrix operator / (const Matrix& a, const Complex& s); |
|
169 |
|
170 // scalar by matrix -> matrix operations |
|
171 |
|
172 friend ComplexMatrix operator + (const Complex& s, const Matrix& a); |
|
173 friend ComplexMatrix operator - (const Complex& s, const Matrix& a); |
|
174 friend ComplexMatrix operator * (const Complex& s, const Matrix& a); |
|
175 friend ComplexMatrix operator / (const Complex& s, const Matrix& a); |
|
176 |
|
177 // matrix by column vector -> column vector operations |
|
178 |
|
179 friend ColumnVector operator * (const Matrix& a, const ColumnVector& b); |
|
180 friend ComplexColumnVector operator * (const Matrix& a, |
|
181 const ComplexColumnVector& b); |
|
182 |
|
183 // matrix by diagonal matrix -> matrix operations |
|
184 |
|
185 friend Matrix operator + (const Matrix& a, const DiagMatrix& b); |
|
186 friend Matrix operator - (const Matrix& a, const DiagMatrix& b); |
|
187 friend Matrix operator * (const Matrix& a, const DiagMatrix& b); |
|
188 |
|
189 friend ComplexMatrix operator + (const Matrix& a, |
|
190 const ComplexDiagMatrix& b); |
|
191 friend ComplexMatrix operator - (const Matrix& a, |
|
192 const ComplexDiagMatrix& b); |
|
193 friend ComplexMatrix operator * (const Matrix& a, |
|
194 const ComplexDiagMatrix& b); |
|
195 |
|
196 // matrix by matrix -> matrix operations |
|
197 |
|
198 friend Matrix operator * (const Matrix& a, const Matrix& b); |
|
199 friend ComplexMatrix operator * (const Matrix& a, const ComplexMatrix& b); |
|
200 |
|
201 friend ComplexMatrix operator + (const Matrix& a, const ComplexMatrix& b); |
|
202 friend ComplexMatrix operator - (const Matrix& a, const ComplexMatrix& b); |
|
203 |
|
204 friend ComplexMatrix product (const Matrix& a, const ComplexMatrix& b); |
|
205 friend ComplexMatrix quotient (const Matrix& a, const ComplexMatrix& b); |
|
206 |
|
207 // other operations |
|
208 |
|
209 friend Matrix map (d_d_Mapper f, const Matrix& a); |
|
210 void map (d_d_Mapper f); |
|
211 |
|
212 Matrix all (void) const; |
|
213 Matrix any (void) const; |
|
214 |
|
215 Matrix cumprod (void) const; |
|
216 Matrix cumsum (void) const; |
|
217 Matrix prod (void) const; |
|
218 Matrix sum (void) const; |
|
219 Matrix sumsq (void) const; |
|
220 |
|
221 ColumnVector diag (void) const; |
|
222 ColumnVector diag (int k) const; |
|
223 |
|
224 ColumnVector row_min (void) const; |
|
225 ColumnVector row_min_loc (void) const; |
|
226 |
|
227 ColumnVector row_max (void) const; |
|
228 ColumnVector row_max_loc (void) const; |
|
229 |
|
230 RowVector column_min (void) const; |
|
231 RowVector column_min_loc (void) const; |
|
232 |
|
233 RowVector column_max (void) const; |
|
234 RowVector column_max_loc (void) const; |
|
235 |
|
236 // i/o |
|
237 |
|
238 friend ostream& operator << (ostream& os, const Matrix& a); |
|
239 friend istream& operator >> (istream& is, Matrix& a); |
|
240 |
471
|
241 int read (FILE *fptr, char *type); |
|
242 int write (FILE *fptr, char *type); |
458
|
243 |
|
244 // Until templates really work with g++: |
|
245 |
|
246 #define KLUDGE_MATRICES |
|
247 #define TYPE double |
|
248 #define KL_MAT_TYPE Matrix |
|
249 #include "mx-kludge.h" |
|
250 #undef KLUDGE_MATRICES |
|
251 #undef TYPE |
|
252 #undef KL_MAT_TYPE |
|
253 |
|
254 private: |
|
255 |
|
256 Matrix (double *d, int r, int c) : Array2<double> (d, r, c) { } |
|
257 }; |
|
258 |
|
259 } // extern "C++" |
|
260 |
|
261 #endif |
|
262 |
|
263 /* |
|
264 ;;; Local Variables: *** |
|
265 ;;; mode: C++ *** |
|
266 ;;; page-delimiter: "^/\\*" *** |
|
267 ;;; End: *** |
|
268 */ |