458
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
458
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
458
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_ComplexMatrix_h) |
|
25 #define octave_ComplexMatrix_h 1 |
|
26 |
1989
|
27 #include "MArray2.h" |
|
28 #include "MDiagArray2.h" |
5785
|
29 #include "MatrixType.h" |
458
|
30 |
|
31 #include "mx-defs.h" |
2870
|
32 #include "mx-op-defs.h" |
1650
|
33 #include "oct-cmplx.h" |
458
|
34 |
3585
|
35 class |
|
36 ComplexMatrix : public MArray2<Complex> |
458
|
37 { |
|
38 public: |
|
39 |
3480
|
40 typedef void (*solve_singularity_handler) (double rcond); |
|
41 |
1214
|
42 ComplexMatrix (void) : MArray2<Complex> () { } |
3585
|
43 |
5275
|
44 ComplexMatrix (octave_idx_type r, octave_idx_type c) : MArray2<Complex> (r, c) { } |
3585
|
45 |
5275
|
46 ComplexMatrix (octave_idx_type r, octave_idx_type c, const Complex& val) |
1214
|
47 : MArray2<Complex> (r, c, val) { } |
3585
|
48 |
1214
|
49 ComplexMatrix (const ComplexMatrix& a) : MArray2<Complex> (a) { } |
3585
|
50 |
|
51 ComplexMatrix (const MArray2<Complex>& a) : MArray2<Complex> (a) { } |
|
52 |
|
53 explicit ComplexMatrix (const Matrix& a); |
|
54 |
|
55 explicit ComplexMatrix (const RowVector& rv); |
|
56 |
|
57 explicit ComplexMatrix (const ColumnVector& cv); |
458
|
58 |
3585
|
59 explicit ComplexMatrix (const DiagMatrix& a); |
|
60 |
|
61 explicit ComplexMatrix (const ComplexRowVector& rv); |
|
62 |
|
63 explicit ComplexMatrix (const ComplexColumnVector& cv); |
|
64 |
|
65 explicit ComplexMatrix (const ComplexDiagMatrix& a); |
|
66 |
|
67 explicit ComplexMatrix (const boolMatrix& a); |
|
68 |
|
69 explicit ComplexMatrix (const charMatrix& a); |
1574
|
70 |
458
|
71 ComplexMatrix& operator = (const ComplexMatrix& a) |
|
72 { |
1214
|
73 MArray2<Complex>::operator = (a); |
458
|
74 return *this; |
|
75 } |
|
76 |
2384
|
77 bool operator == (const ComplexMatrix& a) const; |
|
78 bool operator != (const ComplexMatrix& a) const; |
458
|
79 |
2815
|
80 bool is_hermitian (void) const; |
|
81 |
1359
|
82 // destructive insert/delete/reorder operations |
458
|
83 |
5275
|
84 ComplexMatrix& insert (const Matrix& a, octave_idx_type r, octave_idx_type c); |
|
85 ComplexMatrix& insert (const RowVector& a, octave_idx_type r, octave_idx_type c); |
|
86 ComplexMatrix& insert (const ColumnVector& a, octave_idx_type r, octave_idx_type c); |
|
87 ComplexMatrix& insert (const DiagMatrix& a, octave_idx_type r, octave_idx_type c); |
458
|
88 |
5275
|
89 ComplexMatrix& insert (const ComplexMatrix& a, octave_idx_type r, octave_idx_type c); |
|
90 ComplexMatrix& insert (const ComplexRowVector& a, octave_idx_type r, octave_idx_type c); |
|
91 ComplexMatrix& insert (const ComplexColumnVector& a, octave_idx_type r, octave_idx_type c); |
|
92 ComplexMatrix& insert (const ComplexDiagMatrix& a, octave_idx_type r, octave_idx_type c); |
458
|
93 |
|
94 ComplexMatrix& fill (double val); |
|
95 ComplexMatrix& fill (const Complex& val); |
5275
|
96 ComplexMatrix& fill (double val, octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2); |
|
97 ComplexMatrix& fill (const Complex& val, octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2); |
458
|
98 |
|
99 ComplexMatrix append (const Matrix& a) const; |
|
100 ComplexMatrix append (const RowVector& a) const; |
|
101 ComplexMatrix append (const ColumnVector& a) const; |
|
102 ComplexMatrix append (const DiagMatrix& a) const; |
|
103 |
|
104 ComplexMatrix append (const ComplexMatrix& a) const; |
|
105 ComplexMatrix append (const ComplexRowVector& a) const; |
|
106 ComplexMatrix append (const ComplexColumnVector& a) const; |
|
107 ComplexMatrix append (const ComplexDiagMatrix& a) const; |
|
108 |
|
109 ComplexMatrix stack (const Matrix& a) const; |
|
110 ComplexMatrix stack (const RowVector& a) const; |
|
111 ComplexMatrix stack (const ColumnVector& a) const; |
|
112 ComplexMatrix stack (const DiagMatrix& a) const; |
|
113 |
|
114 ComplexMatrix stack (const ComplexMatrix& a) const; |
|
115 ComplexMatrix stack (const ComplexRowVector& a) const; |
|
116 ComplexMatrix stack (const ComplexColumnVector& a) const; |
|
117 ComplexMatrix stack (const ComplexDiagMatrix& a) const; |
|
118 |
|
119 ComplexMatrix hermitian (void) const; // complex conjugate transpose |
3225
|
120 ComplexMatrix transpose (void) const |
|
121 { return MArray2<Complex>::transpose (); } |
458
|
122 |
|
123 friend ComplexMatrix conj (const ComplexMatrix& a); |
|
124 |
1359
|
125 // resize is the destructive equivalent for this one |
458
|
126 |
5275
|
127 ComplexMatrix extract (octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const; |
458
|
128 |
5275
|
129 ComplexMatrix extract_n (octave_idx_type r1, octave_idx_type c1, octave_idx_type nr, octave_idx_type nc) const; |
4316
|
130 |
1359
|
131 // extract row or column i. |
458
|
132 |
5275
|
133 ComplexRowVector row (octave_idx_type i) const; |
458
|
134 |
5275
|
135 ComplexColumnVector column (octave_idx_type i) const; |
458
|
136 |
|
137 ComplexMatrix inverse (void) const; |
5275
|
138 ComplexMatrix inverse (octave_idx_type& info) const; |
|
139 ComplexMatrix inverse (octave_idx_type& info, double& rcond, int force = 0, |
4329
|
140 int calc_cond = 1) const; |
458
|
141 |
4384
|
142 ComplexMatrix pseudo_inverse (double tol = 0.0) const; |
740
|
143 |
458
|
144 ComplexMatrix fourier (void) const; |
|
145 ComplexMatrix ifourier (void) const; |
|
146 |
677
|
147 ComplexMatrix fourier2d (void) const; |
|
148 ComplexMatrix ifourier2d (void) const; |
|
149 |
458
|
150 ComplexDET determinant (void) const; |
5275
|
151 ComplexDET determinant (octave_idx_type& info) const; |
|
152 ComplexDET determinant (octave_idx_type& info, double& rcond, int calc_cond = 1) const; |
458
|
153 |
5785
|
154 private: |
|
155 // Upper triangular matrix solvers |
|
156 ComplexMatrix utsolve (MatrixType &typ, const ComplexMatrix& b, |
|
157 octave_idx_type& info, double& rcond, |
|
158 solve_singularity_handler sing_handler, |
|
159 bool calc_cond = false) const; |
|
160 |
|
161 // Lower triangular matrix solvers |
|
162 ComplexMatrix ltsolve (MatrixType &typ, const ComplexMatrix& b, |
|
163 octave_idx_type& info, double& rcond, |
|
164 solve_singularity_handler sing_handler, |
|
165 bool calc_cond = false) const; |
|
166 |
|
167 // Full matrix solvers (umfpack/cholesky) |
|
168 ComplexMatrix fsolve (MatrixType &typ, const ComplexMatrix& b, |
|
169 octave_idx_type& info, double& rcond, |
|
170 solve_singularity_handler sing_handler, |
|
171 bool calc_cond = false) const; |
|
172 |
|
173 public: |
|
174 // Generic interface to solver with no probing of type |
|
175 ComplexMatrix solve (MatrixType &typ, const Matrix& b) const; |
|
176 ComplexMatrix solve (MatrixType &typ, const Matrix& b, |
|
177 octave_idx_type& info) const; |
|
178 ComplexMatrix solve (MatrixType &typ, const Matrix& b, |
|
179 octave_idx_type& info, double& rcond) const; |
|
180 ComplexMatrix solve (MatrixType &typ, const Matrix& b, octave_idx_type& info, |
|
181 double& rcond, solve_singularity_handler sing_handler, |
|
182 bool singular_fallback = true) const; |
|
183 |
|
184 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b) const; |
|
185 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b, |
|
186 octave_idx_type& info) const; |
|
187 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b, |
|
188 octave_idx_type& info, double& rcond) const; |
|
189 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b, |
|
190 octave_idx_type& info, double& rcond, |
|
191 solve_singularity_handler sing_handler, |
|
192 bool singular_fallback = true) const; |
|
193 |
|
194 ComplexColumnVector solve (MatrixType &typ, const ColumnVector& b) const; |
|
195 ComplexColumnVector solve (MatrixType &typ, const ColumnVector& b, |
|
196 octave_idx_type& info) const; |
|
197 ComplexColumnVector solve (MatrixType &typ, const ColumnVector& b, |
|
198 octave_idx_type& info, double& rcond) const; |
|
199 ComplexColumnVector solve (MatrixType &typ, const ColumnVector& b, |
|
200 octave_idx_type& info, double& rcond, |
|
201 solve_singularity_handler sing_handler) const; |
|
202 |
|
203 ComplexColumnVector solve (MatrixType &typ, |
|
204 const ComplexColumnVector& b) const; |
|
205 ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b, |
|
206 octave_idx_type& info) const; |
|
207 ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b, |
|
208 octave_idx_type& info, double& rcond) const; |
|
209 ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b, |
|
210 octave_idx_type& info, double& rcond, |
|
211 solve_singularity_handler sing_handler) const; |
|
212 |
|
213 // Generic interface to solver with probing of type |
458
|
214 ComplexMatrix solve (const Matrix& b) const; |
5275
|
215 ComplexMatrix solve (const Matrix& b, octave_idx_type& info) const; |
|
216 ComplexMatrix solve (const Matrix& b, octave_idx_type& info, double& rcond) const; |
|
217 ComplexMatrix solve (const Matrix& b, octave_idx_type& info, double& rcond, |
3480
|
218 solve_singularity_handler sing_handler) const; |
458
|
219 |
|
220 ComplexMatrix solve (const ComplexMatrix& b) const; |
5275
|
221 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info) const; |
|
222 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info, double& rcond) const; |
|
223 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info, double& rcond, |
3480
|
224 solve_singularity_handler sing_handler) const; |
458
|
225 |
3585
|
226 ComplexColumnVector solve (const ColumnVector& b) const; |
5275
|
227 ComplexColumnVector solve (const ColumnVector& b, octave_idx_type& info) const; |
|
228 ComplexColumnVector solve (const ColumnVector& b, octave_idx_type& info, |
3585
|
229 double& rcond) const; |
5275
|
230 ComplexColumnVector solve (const ColumnVector& b, octave_idx_type& info, double& rcond, |
3585
|
231 solve_singularity_handler sing_handler) const; |
|
232 |
458
|
233 ComplexColumnVector solve (const ComplexColumnVector& b) const; |
5275
|
234 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info) const; |
|
235 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info, |
458
|
236 double& rcond) const; |
5275
|
237 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info, |
3480
|
238 double& rcond, |
|
239 solve_singularity_handler sing_handler) const; |
458
|
240 |
3585
|
241 ComplexMatrix lssolve (const Matrix& b) const; |
5275
|
242 ComplexMatrix lssolve (const Matrix& b, octave_idx_type& info) const; |
|
243 ComplexMatrix lssolve (const Matrix& b, octave_idx_type& info, octave_idx_type& rank) const; |
3585
|
244 |
458
|
245 ComplexMatrix lssolve (const ComplexMatrix& b) const; |
5275
|
246 ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info) const; |
|
247 ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info, |
|
248 octave_idx_type& rank) const; |
458
|
249 |
3585
|
250 ComplexColumnVector lssolve (const ColumnVector& b) const; |
5275
|
251 ComplexColumnVector lssolve (const ColumnVector& b, octave_idx_type& info) const; |
|
252 ComplexColumnVector lssolve (const ColumnVector& b, octave_idx_type& info, |
|
253 octave_idx_type& rank) const; |
3585
|
254 |
458
|
255 ComplexColumnVector lssolve (const ComplexColumnVector& b) const; |
5275
|
256 ComplexColumnVector lssolve (const ComplexColumnVector& b, octave_idx_type& info) const; |
|
257 ComplexColumnVector lssolve (const ComplexColumnVector& b, octave_idx_type& info, |
|
258 octave_idx_type& rank) const; |
458
|
259 |
1819
|
260 ComplexMatrix expm (void) const; |
|
261 |
1359
|
262 // matrix by diagonal matrix -> matrix operations |
458
|
263 |
|
264 ComplexMatrix& operator += (const DiagMatrix& a); |
|
265 ComplexMatrix& operator -= (const DiagMatrix& a); |
|
266 |
|
267 ComplexMatrix& operator += (const ComplexDiagMatrix& a); |
|
268 ComplexMatrix& operator -= (const ComplexDiagMatrix& a); |
|
269 |
1359
|
270 // matrix by matrix -> matrix operations |
458
|
271 |
|
272 ComplexMatrix& operator += (const Matrix& a); |
|
273 ComplexMatrix& operator -= (const Matrix& a); |
|
274 |
1359
|
275 // unary operations |
458
|
276 |
2964
|
277 boolMatrix operator ! (void) const; |
458
|
278 |
1359
|
279 // other operations |
458
|
280 |
2676
|
281 ComplexMatrix map (c_c_Mapper f) const; |
|
282 Matrix map (d_c_Mapper f) const; |
3248
|
283 boolMatrix map (b_c_Mapper f) const; |
2676
|
284 |
|
285 ComplexMatrix& apply (c_c_Mapper f); |
458
|
286 |
2384
|
287 bool any_element_is_inf_or_nan (void) const; |
2408
|
288 bool all_elements_are_real (void) const; |
2384
|
289 bool all_integers (double& max_val, double& min_val) const; |
|
290 bool too_large_for_float (void) const; |
1963
|
291 |
4017
|
292 boolMatrix all (int dim = -1) const; |
|
293 boolMatrix any (int dim = -1) const; |
458
|
294 |
4017
|
295 ComplexMatrix cumprod (int dim = -1) const; |
|
296 ComplexMatrix cumsum (int dim = -1) const; |
|
297 ComplexMatrix prod (int dim = -1) const; |
|
298 ComplexMatrix sum (int dim = -1) const; |
|
299 ComplexMatrix sumsq (int dim = -1) const; |
4329
|
300 Matrix abs (void) const; |
458
|
301 |
|
302 ComplexColumnVector diag (void) const; |
5275
|
303 ComplexColumnVector diag (octave_idx_type k) const; |
458
|
304 |
5275
|
305 bool row_is_real_only (octave_idx_type) const; |
|
306 bool column_is_real_only (octave_idx_type) const; |
458
|
307 |
2354
|
308 ComplexColumnVector row_min (void) const; |
458
|
309 ComplexColumnVector row_max (void) const; |
2354
|
310 |
5275
|
311 ComplexColumnVector row_min (Array<octave_idx_type>& index) const; |
|
312 ComplexColumnVector row_max (Array<octave_idx_type>& index) const; |
458
|
313 |
|
314 ComplexRowVector column_min (void) const; |
2354
|
315 ComplexRowVector column_max (void) const; |
458
|
316 |
5275
|
317 ComplexRowVector column_min (Array<octave_idx_type>& index) const; |
|
318 ComplexRowVector column_max (Array<octave_idx_type>& index) const; |
458
|
319 |
1359
|
320 // i/o |
458
|
321 |
5956
|
322 std::ostream& save_ascii (std::ostream& os, bool& infnan_warned, |
|
323 int strip_nan_and_inf); |
|
324 |
3504
|
325 friend std::ostream& operator << (std::ostream& os, const ComplexMatrix& a); |
|
326 friend std::istream& operator >> (std::istream& is, ComplexMatrix& a); |
458
|
327 |
3933
|
328 static Complex resize_fill_value (void) { return Complex (0.0, 0.0); } |
|
329 |
458
|
330 private: |
|
331 |
5275
|
332 ComplexMatrix (Complex *d, octave_idx_type r, octave_idx_type c) : MArray2<Complex> (d, r, c) { } |
458
|
333 }; |
|
334 |
5508
|
335 // column vector by row vector -> matrix operations |
|
336 |
|
337 extern ComplexMatrix |
|
338 operator * (const ColumnVector& a, const ComplexRowVector& b); |
|
339 |
|
340 extern ComplexMatrix |
|
341 operator * (const ComplexColumnVector& a, const RowVector& b); |
1819
|
342 |
5508
|
343 extern ComplexMatrix |
|
344 operator * (const ComplexColumnVector& a, const ComplexRowVector& b); |
|
345 |
|
346 extern ComplexMatrix |
|
347 Givens (const Complex&, const Complex&); |
|
348 |
|
349 extern ComplexMatrix |
|
350 Sylvester (const ComplexMatrix&, const ComplexMatrix&, const ComplexMatrix&); |
1819
|
351 |
2828
|
352 extern ComplexMatrix operator * (const Matrix&, const ComplexMatrix&); |
|
353 extern ComplexMatrix operator * (const ComplexMatrix&, const Matrix&); |
|
354 extern ComplexMatrix operator * (const ComplexMatrix&, const ComplexMatrix&); |
|
355 |
4309
|
356 extern ComplexMatrix min (const Complex& c, const ComplexMatrix& m); |
|
357 extern ComplexMatrix min (const ComplexMatrix& m, const Complex& c); |
|
358 extern ComplexMatrix min (const ComplexMatrix& a, const ComplexMatrix& b); |
|
359 |
|
360 extern ComplexMatrix max (const Complex& c, const ComplexMatrix& m); |
|
361 extern ComplexMatrix max (const ComplexMatrix& m, const Complex& c); |
|
362 extern ComplexMatrix max (const ComplexMatrix& a, const ComplexMatrix& b); |
|
363 |
2870
|
364 MS_CMP_OP_DECLS (ComplexMatrix, Complex) |
|
365 MS_BOOL_OP_DECLS (ComplexMatrix, Complex) |
|
366 |
|
367 SM_CMP_OP_DECLS (Complex, ComplexMatrix) |
|
368 SM_BOOL_OP_DECLS (Complex, ComplexMatrix) |
|
369 |
|
370 MM_CMP_OP_DECLS (ComplexMatrix, ComplexMatrix) |
|
371 MM_BOOL_OP_DECLS (ComplexMatrix, ComplexMatrix) |
|
372 |
3573
|
373 MARRAY_FORWARD_DEFS (MArray2, ComplexMatrix, Complex) |
|
374 |
458
|
375 #endif |
|
376 |
|
377 /* |
|
378 ;;; Local Variables: *** |
|
379 ;;; mode: C++ *** |
|
380 ;;; End: *** |
|
381 */ |