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