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; |
6207
|
147 ComplexMatrix inverse (MatrixType &mattype) const; |
|
148 ComplexMatrix inverse (MatrixType &mattype, octave_idx_type& info) const; |
|
149 ComplexMatrix inverse (MatrixType &mattype, octave_idx_type& info, |
|
150 double& rcond, int force = 0, |
4329
|
151 int calc_cond = 1) const; |
458
|
152 |
4384
|
153 ComplexMatrix pseudo_inverse (double tol = 0.0) const; |
740
|
154 |
458
|
155 ComplexMatrix fourier (void) const; |
|
156 ComplexMatrix ifourier (void) const; |
|
157 |
677
|
158 ComplexMatrix fourier2d (void) const; |
|
159 ComplexMatrix ifourier2d (void) const; |
|
160 |
458
|
161 ComplexDET determinant (void) const; |
5275
|
162 ComplexDET determinant (octave_idx_type& info) const; |
|
163 ComplexDET determinant (octave_idx_type& info, double& rcond, int calc_cond = 1) const; |
458
|
164 |
5785
|
165 private: |
|
166 // Upper triangular matrix solvers |
|
167 ComplexMatrix utsolve (MatrixType &typ, const ComplexMatrix& b, |
|
168 octave_idx_type& info, double& rcond, |
|
169 solve_singularity_handler sing_handler, |
|
170 bool calc_cond = false) const; |
|
171 |
|
172 // Lower triangular matrix solvers |
|
173 ComplexMatrix ltsolve (MatrixType &typ, const ComplexMatrix& b, |
|
174 octave_idx_type& info, double& rcond, |
|
175 solve_singularity_handler sing_handler, |
|
176 bool calc_cond = false) const; |
|
177 |
|
178 // Full matrix solvers (umfpack/cholesky) |
|
179 ComplexMatrix fsolve (MatrixType &typ, const ComplexMatrix& b, |
|
180 octave_idx_type& info, double& rcond, |
|
181 solve_singularity_handler sing_handler, |
|
182 bool calc_cond = false) const; |
|
183 |
|
184 public: |
|
185 // Generic interface to solver with no probing of type |
|
186 ComplexMatrix solve (MatrixType &typ, const Matrix& b) const; |
|
187 ComplexMatrix solve (MatrixType &typ, const Matrix& b, |
|
188 octave_idx_type& info) const; |
|
189 ComplexMatrix solve (MatrixType &typ, const Matrix& b, |
|
190 octave_idx_type& info, double& rcond) const; |
|
191 ComplexMatrix solve (MatrixType &typ, const Matrix& b, octave_idx_type& info, |
|
192 double& rcond, solve_singularity_handler sing_handler, |
|
193 bool singular_fallback = true) const; |
|
194 |
|
195 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b) const; |
|
196 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b, |
|
197 octave_idx_type& info) const; |
|
198 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b, |
|
199 octave_idx_type& info, double& rcond) const; |
|
200 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b, |
|
201 octave_idx_type& info, double& rcond, |
|
202 solve_singularity_handler sing_handler, |
|
203 bool singular_fallback = true) const; |
|
204 |
|
205 ComplexColumnVector solve (MatrixType &typ, const ColumnVector& b) const; |
|
206 ComplexColumnVector solve (MatrixType &typ, const ColumnVector& b, |
|
207 octave_idx_type& info) const; |
|
208 ComplexColumnVector solve (MatrixType &typ, const ColumnVector& b, |
|
209 octave_idx_type& info, double& rcond) const; |
|
210 ComplexColumnVector solve (MatrixType &typ, const ColumnVector& b, |
|
211 octave_idx_type& info, double& rcond, |
|
212 solve_singularity_handler sing_handler) const; |
|
213 |
|
214 ComplexColumnVector solve (MatrixType &typ, |
|
215 const ComplexColumnVector& b) const; |
|
216 ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b, |
|
217 octave_idx_type& info) const; |
|
218 ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b, |
|
219 octave_idx_type& info, double& rcond) const; |
|
220 ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b, |
|
221 octave_idx_type& info, double& rcond, |
|
222 solve_singularity_handler sing_handler) const; |
|
223 |
|
224 // Generic interface to solver with probing of type |
458
|
225 ComplexMatrix solve (const Matrix& b) const; |
5275
|
226 ComplexMatrix solve (const Matrix& b, octave_idx_type& info) const; |
|
227 ComplexMatrix solve (const Matrix& b, octave_idx_type& info, double& rcond) const; |
|
228 ComplexMatrix solve (const Matrix& b, octave_idx_type& info, double& rcond, |
3480
|
229 solve_singularity_handler sing_handler) const; |
458
|
230 |
|
231 ComplexMatrix solve (const ComplexMatrix& b) const; |
5275
|
232 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info) const; |
|
233 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info, double& rcond) const; |
|
234 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info, double& rcond, |
3480
|
235 solve_singularity_handler sing_handler) const; |
458
|
236 |
3585
|
237 ComplexColumnVector solve (const ColumnVector& b) const; |
5275
|
238 ComplexColumnVector solve (const ColumnVector& b, octave_idx_type& info) const; |
|
239 ComplexColumnVector solve (const ColumnVector& b, octave_idx_type& info, |
3585
|
240 double& rcond) const; |
5275
|
241 ComplexColumnVector solve (const ColumnVector& b, octave_idx_type& info, double& rcond, |
3585
|
242 solve_singularity_handler sing_handler) const; |
|
243 |
458
|
244 ComplexColumnVector solve (const ComplexColumnVector& b) const; |
5275
|
245 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info) const; |
|
246 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info, |
458
|
247 double& rcond) const; |
5275
|
248 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info, |
3480
|
249 double& rcond, |
|
250 solve_singularity_handler sing_handler) const; |
458
|
251 |
3585
|
252 ComplexMatrix lssolve (const Matrix& b) const; |
5275
|
253 ComplexMatrix lssolve (const Matrix& b, octave_idx_type& info) const; |
|
254 ComplexMatrix lssolve (const Matrix& b, octave_idx_type& info, octave_idx_type& rank) const; |
3585
|
255 |
458
|
256 ComplexMatrix lssolve (const ComplexMatrix& b) const; |
5275
|
257 ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info) const; |
|
258 ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info, |
|
259 octave_idx_type& rank) const; |
458
|
260 |
3585
|
261 ComplexColumnVector lssolve (const ColumnVector& b) const; |
5275
|
262 ComplexColumnVector lssolve (const ColumnVector& b, octave_idx_type& info) const; |
|
263 ComplexColumnVector lssolve (const ColumnVector& b, octave_idx_type& info, |
|
264 octave_idx_type& rank) const; |
3585
|
265 |
458
|
266 ComplexColumnVector lssolve (const ComplexColumnVector& b) const; |
5275
|
267 ComplexColumnVector lssolve (const ComplexColumnVector& b, octave_idx_type& info) const; |
|
268 ComplexColumnVector lssolve (const ComplexColumnVector& b, octave_idx_type& info, |
|
269 octave_idx_type& rank) const; |
458
|
270 |
1819
|
271 ComplexMatrix expm (void) const; |
|
272 |
1359
|
273 // matrix by diagonal matrix -> matrix operations |
458
|
274 |
|
275 ComplexMatrix& operator += (const DiagMatrix& a); |
|
276 ComplexMatrix& operator -= (const DiagMatrix& a); |
|
277 |
|
278 ComplexMatrix& operator += (const ComplexDiagMatrix& a); |
|
279 ComplexMatrix& operator -= (const ComplexDiagMatrix& a); |
|
280 |
1359
|
281 // matrix by matrix -> matrix operations |
458
|
282 |
|
283 ComplexMatrix& operator += (const Matrix& a); |
|
284 ComplexMatrix& operator -= (const Matrix& a); |
|
285 |
1359
|
286 // unary operations |
458
|
287 |
2964
|
288 boolMatrix operator ! (void) const; |
458
|
289 |
1359
|
290 // other operations |
458
|
291 |
2676
|
292 ComplexMatrix map (c_c_Mapper f) const; |
|
293 Matrix map (d_c_Mapper f) const; |
3248
|
294 boolMatrix map (b_c_Mapper f) const; |
2676
|
295 |
|
296 ComplexMatrix& apply (c_c_Mapper f); |
458
|
297 |
2384
|
298 bool any_element_is_inf_or_nan (void) const; |
2408
|
299 bool all_elements_are_real (void) const; |
2384
|
300 bool all_integers (double& max_val, double& min_val) const; |
|
301 bool too_large_for_float (void) const; |
1963
|
302 |
4017
|
303 boolMatrix all (int dim = -1) const; |
|
304 boolMatrix any (int dim = -1) const; |
458
|
305 |
4017
|
306 ComplexMatrix cumprod (int dim = -1) const; |
|
307 ComplexMatrix cumsum (int dim = -1) const; |
|
308 ComplexMatrix prod (int dim = -1) const; |
|
309 ComplexMatrix sum (int dim = -1) const; |
|
310 ComplexMatrix sumsq (int dim = -1) const; |
4329
|
311 Matrix abs (void) const; |
458
|
312 |
|
313 ComplexColumnVector diag (void) const; |
5275
|
314 ComplexColumnVector diag (octave_idx_type k) const; |
458
|
315 |
5275
|
316 bool row_is_real_only (octave_idx_type) const; |
|
317 bool column_is_real_only (octave_idx_type) const; |
458
|
318 |
2354
|
319 ComplexColumnVector row_min (void) const; |
458
|
320 ComplexColumnVector row_max (void) const; |
2354
|
321 |
5275
|
322 ComplexColumnVector row_min (Array<octave_idx_type>& index) const; |
|
323 ComplexColumnVector row_max (Array<octave_idx_type>& index) const; |
458
|
324 |
|
325 ComplexRowVector column_min (void) const; |
2354
|
326 ComplexRowVector column_max (void) const; |
458
|
327 |
5275
|
328 ComplexRowVector column_min (Array<octave_idx_type>& index) const; |
|
329 ComplexRowVector column_max (Array<octave_idx_type>& index) const; |
458
|
330 |
1359
|
331 // i/o |
458
|
332 |
6108
|
333 friend OCTAVE_API std::ostream& operator << (std::ostream& os, const ComplexMatrix& a); |
|
334 friend OCTAVE_API std::istream& operator >> (std::istream& is, ComplexMatrix& a); |
458
|
335 |
3933
|
336 static Complex resize_fill_value (void) { return Complex (0.0, 0.0); } |
|
337 |
458
|
338 private: |
|
339 |
5275
|
340 ComplexMatrix (Complex *d, octave_idx_type r, octave_idx_type c) : MArray2<Complex> (d, r, c) { } |
458
|
341 }; |
|
342 |
5508
|
343 // column vector by row vector -> matrix operations |
|
344 |
6108
|
345 extern OCTAVE_API ComplexMatrix |
5508
|
346 operator * (const ColumnVector& a, const ComplexRowVector& b); |
|
347 |
6108
|
348 extern OCTAVE_API ComplexMatrix |
5508
|
349 operator * (const ComplexColumnVector& a, const RowVector& b); |
1819
|
350 |
6108
|
351 extern OCTAVE_API ComplexMatrix |
5508
|
352 operator * (const ComplexColumnVector& a, const ComplexRowVector& b); |
|
353 |
6108
|
354 extern OCTAVE_API ComplexMatrix |
5508
|
355 Givens (const Complex&, const Complex&); |
|
356 |
6108
|
357 extern OCTAVE_API ComplexMatrix |
5508
|
358 Sylvester (const ComplexMatrix&, const ComplexMatrix&, const ComplexMatrix&); |
1819
|
359 |
6108
|
360 extern OCTAVE_API ComplexMatrix operator * (const Matrix&, const ComplexMatrix&); |
|
361 extern OCTAVE_API ComplexMatrix operator * (const ComplexMatrix&, const Matrix&); |
|
362 extern OCTAVE_API ComplexMatrix operator * (const ComplexMatrix&, const ComplexMatrix&); |
2828
|
363 |
6108
|
364 extern OCTAVE_API ComplexMatrix min (const Complex& c, const ComplexMatrix& m); |
|
365 extern OCTAVE_API ComplexMatrix min (const ComplexMatrix& m, const Complex& c); |
|
366 extern OCTAVE_API ComplexMatrix min (const ComplexMatrix& a, const ComplexMatrix& b); |
4309
|
367 |
6108
|
368 extern OCTAVE_API ComplexMatrix max (const Complex& c, const ComplexMatrix& m); |
|
369 extern OCTAVE_API ComplexMatrix max (const ComplexMatrix& m, const Complex& c); |
|
370 extern OCTAVE_API ComplexMatrix max (const ComplexMatrix& a, const ComplexMatrix& b); |
4309
|
371 |
2870
|
372 MS_CMP_OP_DECLS (ComplexMatrix, Complex) |
|
373 MS_BOOL_OP_DECLS (ComplexMatrix, Complex) |
|
374 |
|
375 SM_CMP_OP_DECLS (Complex, ComplexMatrix) |
|
376 SM_BOOL_OP_DECLS (Complex, ComplexMatrix) |
|
377 |
|
378 MM_CMP_OP_DECLS (ComplexMatrix, ComplexMatrix) |
|
379 MM_BOOL_OP_DECLS (ComplexMatrix, ComplexMatrix) |
|
380 |
3573
|
381 MARRAY_FORWARD_DEFS (MArray2, ComplexMatrix, Complex) |
|
382 |
458
|
383 #endif |
|
384 |
|
385 /* |
|
386 ;;; Local Variables: *** |
|
387 ;;; mode: C++ *** |
|
388 ;;; End: *** |
|
389 */ |