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