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 |
6108
|
36 OCTAVE_API |
3585
|
37 ComplexMatrix : public MArray2<Complex> |
458
|
38 { |
|
39 public: |
|
40 |
3480
|
41 typedef void (*solve_singularity_handler) (double rcond); |
|
42 |
1214
|
43 ComplexMatrix (void) : MArray2<Complex> () { } |
3585
|
44 |
5275
|
45 ComplexMatrix (octave_idx_type r, octave_idx_type c) : MArray2<Complex> (r, c) { } |
3585
|
46 |
5275
|
47 ComplexMatrix (octave_idx_type r, octave_idx_type c, const Complex& val) |
1214
|
48 : MArray2<Complex> (r, c, val) { } |
3585
|
49 |
1214
|
50 ComplexMatrix (const ComplexMatrix& a) : MArray2<Complex> (a) { } |
3585
|
51 |
|
52 ComplexMatrix (const MArray2<Complex>& a) : MArray2<Complex> (a) { } |
|
53 |
|
54 explicit ComplexMatrix (const Matrix& a); |
|
55 |
|
56 explicit ComplexMatrix (const RowVector& rv); |
|
57 |
|
58 explicit ComplexMatrix (const ColumnVector& cv); |
458
|
59 |
3585
|
60 explicit ComplexMatrix (const DiagMatrix& a); |
|
61 |
|
62 explicit ComplexMatrix (const ComplexRowVector& rv); |
|
63 |
|
64 explicit ComplexMatrix (const ComplexColumnVector& cv); |
|
65 |
|
66 explicit ComplexMatrix (const ComplexDiagMatrix& a); |
|
67 |
|
68 explicit ComplexMatrix (const boolMatrix& a); |
|
69 |
|
70 explicit ComplexMatrix (const charMatrix& a); |
1574
|
71 |
458
|
72 ComplexMatrix& operator = (const ComplexMatrix& a) |
|
73 { |
1214
|
74 MArray2<Complex>::operator = (a); |
458
|
75 return *this; |
|
76 } |
|
77 |
2384
|
78 bool operator == (const ComplexMatrix& a) const; |
|
79 bool operator != (const ComplexMatrix& a) const; |
458
|
80 |
2815
|
81 bool is_hermitian (void) const; |
|
82 |
1359
|
83 // destructive insert/delete/reorder operations |
458
|
84 |
5275
|
85 ComplexMatrix& insert (const Matrix& a, octave_idx_type r, octave_idx_type c); |
|
86 ComplexMatrix& insert (const RowVector& a, octave_idx_type r, octave_idx_type c); |
|
87 ComplexMatrix& insert (const ColumnVector& a, octave_idx_type r, octave_idx_type c); |
|
88 ComplexMatrix& insert (const DiagMatrix& a, octave_idx_type r, octave_idx_type c); |
458
|
89 |
5275
|
90 ComplexMatrix& insert (const ComplexMatrix& a, octave_idx_type r, octave_idx_type c); |
|
91 ComplexMatrix& insert (const ComplexRowVector& a, octave_idx_type r, octave_idx_type c); |
|
92 ComplexMatrix& insert (const ComplexColumnVector& a, octave_idx_type r, octave_idx_type c); |
|
93 ComplexMatrix& insert (const ComplexDiagMatrix& a, octave_idx_type r, octave_idx_type c); |
458
|
94 |
|
95 ComplexMatrix& fill (double val); |
|
96 ComplexMatrix& fill (const Complex& val); |
5275
|
97 ComplexMatrix& fill (double val, octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2); |
|
98 ComplexMatrix& fill (const Complex& val, octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2); |
458
|
99 |
|
100 ComplexMatrix append (const Matrix& a) const; |
|
101 ComplexMatrix append (const RowVector& a) const; |
|
102 ComplexMatrix append (const ColumnVector& a) const; |
|
103 ComplexMatrix append (const DiagMatrix& a) const; |
|
104 |
|
105 ComplexMatrix append (const ComplexMatrix& a) const; |
|
106 ComplexMatrix append (const ComplexRowVector& a) const; |
|
107 ComplexMatrix append (const ComplexColumnVector& a) const; |
|
108 ComplexMatrix append (const ComplexDiagMatrix& a) const; |
|
109 |
|
110 ComplexMatrix stack (const Matrix& a) const; |
|
111 ComplexMatrix stack (const RowVector& a) const; |
|
112 ComplexMatrix stack (const ColumnVector& a) const; |
|
113 ComplexMatrix stack (const DiagMatrix& a) const; |
|
114 |
|
115 ComplexMatrix stack (const ComplexMatrix& a) const; |
|
116 ComplexMatrix stack (const ComplexRowVector& a) const; |
|
117 ComplexMatrix stack (const ComplexColumnVector& a) const; |
|
118 ComplexMatrix stack (const ComplexDiagMatrix& a) const; |
|
119 |
|
120 ComplexMatrix hermitian (void) const; // complex conjugate transpose |
3225
|
121 ComplexMatrix transpose (void) const |
|
122 { return MArray2<Complex>::transpose (); } |
458
|
123 |
|
124 friend ComplexMatrix conj (const ComplexMatrix& a); |
|
125 |
1359
|
126 // resize is the destructive equivalent for this one |
458
|
127 |
5275
|
128 ComplexMatrix extract (octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const; |
458
|
129 |
5275
|
130 ComplexMatrix extract_n (octave_idx_type r1, octave_idx_type c1, octave_idx_type nr, octave_idx_type nc) const; |
4316
|
131 |
1359
|
132 // extract row or column i. |
458
|
133 |
5275
|
134 ComplexRowVector row (octave_idx_type i) const; |
458
|
135 |
5275
|
136 ComplexColumnVector column (octave_idx_type i) const; |
458
|
137 |
6207
|
138 private: |
|
139 ComplexMatrix tinverse (MatrixType &mattype, octave_idx_type& info, |
|
140 double& rcond, int force, int calc_cond) const; |
|
141 |
|
142 ComplexMatrix finverse (MatrixType &mattype, octave_idx_type& info, |
|
143 double& rcond, int force, int calc_cond) const; |
|
144 |
|
145 public: |
458
|
146 ComplexMatrix inverse (void) const; |
6479
|
147 ComplexMatrix inverse (octave_idx_type& info) const; |
|
148 ComplexMatrix inverse (octave_idx_type& info, double& rcond, int force = 0, |
|
149 int calc_cond = 1) const; |
|
150 |
6207
|
151 ComplexMatrix inverse (MatrixType &mattype) const; |
|
152 ComplexMatrix inverse (MatrixType &mattype, octave_idx_type& info) const; |
|
153 ComplexMatrix inverse (MatrixType &mattype, octave_idx_type& info, |
|
154 double& rcond, int force = 0, |
4329
|
155 int calc_cond = 1) const; |
458
|
156 |
4384
|
157 ComplexMatrix pseudo_inverse (double tol = 0.0) const; |
740
|
158 |
458
|
159 ComplexMatrix fourier (void) const; |
|
160 ComplexMatrix ifourier (void) const; |
|
161 |
677
|
162 ComplexMatrix fourier2d (void) const; |
|
163 ComplexMatrix ifourier2d (void) const; |
|
164 |
458
|
165 ComplexDET determinant (void) const; |
5275
|
166 ComplexDET determinant (octave_idx_type& info) const; |
|
167 ComplexDET determinant (octave_idx_type& info, double& rcond, int calc_cond = 1) const; |
458
|
168 |
5785
|
169 private: |
|
170 // Upper triangular matrix solvers |
|
171 ComplexMatrix utsolve (MatrixType &typ, const ComplexMatrix& b, |
|
172 octave_idx_type& info, double& rcond, |
|
173 solve_singularity_handler sing_handler, |
|
174 bool calc_cond = false) const; |
|
175 |
|
176 // Lower triangular matrix solvers |
|
177 ComplexMatrix ltsolve (MatrixType &typ, const ComplexMatrix& b, |
|
178 octave_idx_type& info, double& rcond, |
|
179 solve_singularity_handler sing_handler, |
|
180 bool calc_cond = false) const; |
|
181 |
|
182 // Full matrix solvers (umfpack/cholesky) |
|
183 ComplexMatrix fsolve (MatrixType &typ, const ComplexMatrix& b, |
|
184 octave_idx_type& info, double& rcond, |
|
185 solve_singularity_handler sing_handler, |
|
186 bool calc_cond = false) const; |
|
187 |
|
188 public: |
|
189 // Generic interface to solver with no probing of type |
|
190 ComplexMatrix solve (MatrixType &typ, const Matrix& b) const; |
|
191 ComplexMatrix solve (MatrixType &typ, const Matrix& b, |
|
192 octave_idx_type& info) const; |
|
193 ComplexMatrix solve (MatrixType &typ, const Matrix& b, |
|
194 octave_idx_type& info, double& rcond) const; |
|
195 ComplexMatrix solve (MatrixType &typ, const Matrix& b, octave_idx_type& info, |
|
196 double& rcond, solve_singularity_handler sing_handler, |
|
197 bool singular_fallback = true) const; |
|
198 |
|
199 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b) const; |
|
200 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b, |
|
201 octave_idx_type& info) const; |
|
202 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b, |
|
203 octave_idx_type& info, double& rcond) const; |
|
204 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b, |
|
205 octave_idx_type& info, double& rcond, |
|
206 solve_singularity_handler sing_handler, |
|
207 bool singular_fallback = true) const; |
|
208 |
|
209 ComplexColumnVector solve (MatrixType &typ, const ColumnVector& b) const; |
|
210 ComplexColumnVector solve (MatrixType &typ, const ColumnVector& b, |
|
211 octave_idx_type& info) const; |
|
212 ComplexColumnVector solve (MatrixType &typ, const ColumnVector& b, |
|
213 octave_idx_type& info, double& rcond) const; |
|
214 ComplexColumnVector solve (MatrixType &typ, const ColumnVector& b, |
|
215 octave_idx_type& info, double& rcond, |
|
216 solve_singularity_handler sing_handler) const; |
|
217 |
|
218 ComplexColumnVector solve (MatrixType &typ, |
|
219 const ComplexColumnVector& b) const; |
|
220 ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b, |
|
221 octave_idx_type& info) const; |
|
222 ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b, |
|
223 octave_idx_type& info, double& rcond) const; |
|
224 ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b, |
|
225 octave_idx_type& info, double& rcond, |
|
226 solve_singularity_handler sing_handler) const; |
|
227 |
|
228 // Generic interface to solver with probing of type |
458
|
229 ComplexMatrix solve (const Matrix& b) const; |
5275
|
230 ComplexMatrix solve (const Matrix& b, octave_idx_type& info) const; |
|
231 ComplexMatrix solve (const Matrix& b, octave_idx_type& info, double& rcond) const; |
|
232 ComplexMatrix solve (const Matrix& b, octave_idx_type& info, double& rcond, |
3480
|
233 solve_singularity_handler sing_handler) const; |
458
|
234 |
|
235 ComplexMatrix solve (const ComplexMatrix& b) const; |
5275
|
236 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info) const; |
|
237 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info, double& rcond) const; |
|
238 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info, double& rcond, |
3480
|
239 solve_singularity_handler sing_handler) const; |
458
|
240 |
3585
|
241 ComplexColumnVector solve (const ColumnVector& b) const; |
5275
|
242 ComplexColumnVector solve (const ColumnVector& b, octave_idx_type& info) const; |
|
243 ComplexColumnVector solve (const ColumnVector& b, octave_idx_type& info, |
3585
|
244 double& rcond) const; |
5275
|
245 ComplexColumnVector solve (const ColumnVector& b, octave_idx_type& info, double& rcond, |
3585
|
246 solve_singularity_handler sing_handler) const; |
|
247 |
458
|
248 ComplexColumnVector solve (const ComplexColumnVector& b) const; |
5275
|
249 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info) const; |
|
250 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info, |
458
|
251 double& rcond) const; |
5275
|
252 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info, |
3480
|
253 double& rcond, |
|
254 solve_singularity_handler sing_handler) const; |
458
|
255 |
3585
|
256 ComplexMatrix lssolve (const Matrix& b) const; |
5275
|
257 ComplexMatrix lssolve (const Matrix& b, octave_idx_type& info) const; |
|
258 ComplexMatrix lssolve (const Matrix& b, octave_idx_type& info, octave_idx_type& rank) const; |
3585
|
259 |
458
|
260 ComplexMatrix lssolve (const ComplexMatrix& b) const; |
5275
|
261 ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info) const; |
|
262 ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info, |
|
263 octave_idx_type& rank) const; |
458
|
264 |
3585
|
265 ComplexColumnVector lssolve (const ColumnVector& b) const; |
5275
|
266 ComplexColumnVector lssolve (const ColumnVector& b, octave_idx_type& info) const; |
|
267 ComplexColumnVector lssolve (const ColumnVector& b, octave_idx_type& info, |
|
268 octave_idx_type& rank) const; |
3585
|
269 |
458
|
270 ComplexColumnVector lssolve (const ComplexColumnVector& b) const; |
5275
|
271 ComplexColumnVector lssolve (const ComplexColumnVector& b, octave_idx_type& info) const; |
|
272 ComplexColumnVector lssolve (const ComplexColumnVector& b, octave_idx_type& info, |
|
273 octave_idx_type& rank) const; |
458
|
274 |
1819
|
275 ComplexMatrix expm (void) const; |
|
276 |
1359
|
277 // matrix by diagonal matrix -> matrix operations |
458
|
278 |
|
279 ComplexMatrix& operator += (const DiagMatrix& a); |
|
280 ComplexMatrix& operator -= (const DiagMatrix& a); |
|
281 |
|
282 ComplexMatrix& operator += (const ComplexDiagMatrix& a); |
|
283 ComplexMatrix& operator -= (const ComplexDiagMatrix& a); |
|
284 |
1359
|
285 // matrix by matrix -> matrix operations |
458
|
286 |
|
287 ComplexMatrix& operator += (const Matrix& a); |
|
288 ComplexMatrix& operator -= (const Matrix& a); |
|
289 |
1359
|
290 // unary operations |
458
|
291 |
2964
|
292 boolMatrix operator ! (void) const; |
458
|
293 |
1359
|
294 // other operations |
458
|
295 |
2676
|
296 ComplexMatrix map (c_c_Mapper f) const; |
|
297 Matrix map (d_c_Mapper f) const; |
3248
|
298 boolMatrix map (b_c_Mapper f) const; |
2676
|
299 |
|
300 ComplexMatrix& apply (c_c_Mapper f); |
458
|
301 |
2384
|
302 bool any_element_is_inf_or_nan (void) const; |
2408
|
303 bool all_elements_are_real (void) const; |
2384
|
304 bool all_integers (double& max_val, double& min_val) const; |
|
305 bool too_large_for_float (void) const; |
1963
|
306 |
4017
|
307 boolMatrix all (int dim = -1) const; |
|
308 boolMatrix any (int dim = -1) const; |
458
|
309 |
4017
|
310 ComplexMatrix cumprod (int dim = -1) const; |
|
311 ComplexMatrix cumsum (int dim = -1) const; |
|
312 ComplexMatrix prod (int dim = -1) const; |
|
313 ComplexMatrix sum (int dim = -1) const; |
|
314 ComplexMatrix sumsq (int dim = -1) const; |
4329
|
315 Matrix abs (void) const; |
458
|
316 |
|
317 ComplexColumnVector diag (void) const; |
5275
|
318 ComplexColumnVector diag (octave_idx_type k) const; |
458
|
319 |
5275
|
320 bool row_is_real_only (octave_idx_type) const; |
|
321 bool column_is_real_only (octave_idx_type) const; |
458
|
322 |
2354
|
323 ComplexColumnVector row_min (void) const; |
458
|
324 ComplexColumnVector row_max (void) const; |
2354
|
325 |
5275
|
326 ComplexColumnVector row_min (Array<octave_idx_type>& index) const; |
|
327 ComplexColumnVector row_max (Array<octave_idx_type>& index) const; |
458
|
328 |
|
329 ComplexRowVector column_min (void) const; |
2354
|
330 ComplexRowVector column_max (void) const; |
458
|
331 |
5275
|
332 ComplexRowVector column_min (Array<octave_idx_type>& index) const; |
|
333 ComplexRowVector column_max (Array<octave_idx_type>& index) const; |
458
|
334 |
1359
|
335 // i/o |
458
|
336 |
6108
|
337 friend OCTAVE_API std::ostream& operator << (std::ostream& os, const ComplexMatrix& a); |
|
338 friend OCTAVE_API std::istream& operator >> (std::istream& is, ComplexMatrix& a); |
458
|
339 |
3933
|
340 static Complex resize_fill_value (void) { return Complex (0.0, 0.0); } |
|
341 |
458
|
342 private: |
|
343 |
5275
|
344 ComplexMatrix (Complex *d, octave_idx_type r, octave_idx_type c) : MArray2<Complex> (d, r, c) { } |
458
|
345 }; |
|
346 |
5508
|
347 // column vector by row vector -> matrix operations |
|
348 |
6108
|
349 extern OCTAVE_API ComplexMatrix |
5508
|
350 operator * (const ColumnVector& a, const ComplexRowVector& b); |
|
351 |
6108
|
352 extern OCTAVE_API ComplexMatrix |
5508
|
353 operator * (const ComplexColumnVector& a, const RowVector& b); |
1819
|
354 |
6108
|
355 extern OCTAVE_API ComplexMatrix |
5508
|
356 operator * (const ComplexColumnVector& a, const ComplexRowVector& b); |
|
357 |
6108
|
358 extern OCTAVE_API ComplexMatrix |
5508
|
359 Givens (const Complex&, const Complex&); |
|
360 |
6108
|
361 extern OCTAVE_API ComplexMatrix |
5508
|
362 Sylvester (const ComplexMatrix&, const ComplexMatrix&, const ComplexMatrix&); |
1819
|
363 |
6108
|
364 extern OCTAVE_API ComplexMatrix operator * (const Matrix&, const ComplexMatrix&); |
|
365 extern OCTAVE_API ComplexMatrix operator * (const ComplexMatrix&, const Matrix&); |
|
366 extern OCTAVE_API ComplexMatrix operator * (const ComplexMatrix&, const ComplexMatrix&); |
2828
|
367 |
6108
|
368 extern OCTAVE_API ComplexMatrix min (const Complex& c, const ComplexMatrix& m); |
|
369 extern OCTAVE_API ComplexMatrix min (const ComplexMatrix& m, const Complex& c); |
|
370 extern OCTAVE_API ComplexMatrix min (const ComplexMatrix& a, const ComplexMatrix& b); |
4309
|
371 |
6108
|
372 extern OCTAVE_API ComplexMatrix max (const Complex& c, const ComplexMatrix& m); |
|
373 extern OCTAVE_API ComplexMatrix max (const ComplexMatrix& m, const Complex& c); |
|
374 extern OCTAVE_API ComplexMatrix max (const ComplexMatrix& a, const ComplexMatrix& b); |
4309
|
375 |
2870
|
376 MS_CMP_OP_DECLS (ComplexMatrix, Complex) |
|
377 MS_BOOL_OP_DECLS (ComplexMatrix, Complex) |
|
378 |
|
379 SM_CMP_OP_DECLS (Complex, ComplexMatrix) |
|
380 SM_BOOL_OP_DECLS (Complex, ComplexMatrix) |
|
381 |
|
382 MM_CMP_OP_DECLS (ComplexMatrix, ComplexMatrix) |
|
383 MM_BOOL_OP_DECLS (ComplexMatrix, ComplexMatrix) |
|
384 |
3573
|
385 MARRAY_FORWARD_DEFS (MArray2, ComplexMatrix, Complex) |
|
386 |
458
|
387 #endif |
|
388 |
|
389 /* |
|
390 ;;; Local Variables: *** |
|
391 ;;; mode: C++ *** |
|
392 ;;; End: *** |
|
393 */ |