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" |
458
|
29 |
|
30 #include "mx-defs.h" |
2870
|
31 #include "mx-op-defs.h" |
1650
|
32 #include "oct-cmplx.h" |
458
|
33 |
3585
|
34 class |
|
35 ComplexMatrix : public MArray2<Complex> |
458
|
36 { |
|
37 public: |
|
38 |
3480
|
39 typedef void (*solve_singularity_handler) (double rcond); |
|
40 |
1214
|
41 ComplexMatrix (void) : MArray2<Complex> () { } |
3585
|
42 |
5275
|
43 ComplexMatrix (octave_idx_type r, octave_idx_type c) : MArray2<Complex> (r, c) { } |
3585
|
44 |
5275
|
45 ComplexMatrix (octave_idx_type r, octave_idx_type c, const Complex& val) |
1214
|
46 : MArray2<Complex> (r, c, val) { } |
3585
|
47 |
1214
|
48 ComplexMatrix (const ComplexMatrix& a) : MArray2<Complex> (a) { } |
3585
|
49 |
|
50 ComplexMatrix (const MArray2<Complex>& a) : MArray2<Complex> (a) { } |
|
51 |
|
52 explicit ComplexMatrix (const Matrix& a); |
|
53 |
|
54 explicit ComplexMatrix (const RowVector& rv); |
|
55 |
|
56 explicit ComplexMatrix (const ColumnVector& cv); |
458
|
57 |
3585
|
58 explicit ComplexMatrix (const DiagMatrix& a); |
|
59 |
|
60 explicit ComplexMatrix (const ComplexRowVector& rv); |
|
61 |
|
62 explicit ComplexMatrix (const ComplexColumnVector& cv); |
|
63 |
|
64 explicit ComplexMatrix (const ComplexDiagMatrix& a); |
|
65 |
|
66 explicit ComplexMatrix (const boolMatrix& a); |
|
67 |
|
68 explicit ComplexMatrix (const charMatrix& a); |
1574
|
69 |
458
|
70 ComplexMatrix& operator = (const ComplexMatrix& a) |
|
71 { |
1214
|
72 MArray2<Complex>::operator = (a); |
458
|
73 return *this; |
|
74 } |
|
75 |
2384
|
76 bool operator == (const ComplexMatrix& a) const; |
|
77 bool operator != (const ComplexMatrix& a) const; |
458
|
78 |
2815
|
79 bool is_hermitian (void) const; |
|
80 |
1359
|
81 // destructive insert/delete/reorder operations |
458
|
82 |
5275
|
83 ComplexMatrix& insert (const Matrix& a, octave_idx_type r, octave_idx_type c); |
|
84 ComplexMatrix& insert (const RowVector& a, octave_idx_type r, octave_idx_type c); |
|
85 ComplexMatrix& insert (const ColumnVector& a, octave_idx_type r, octave_idx_type c); |
|
86 ComplexMatrix& insert (const DiagMatrix& a, octave_idx_type r, octave_idx_type c); |
458
|
87 |
5275
|
88 ComplexMatrix& insert (const ComplexMatrix& a, octave_idx_type r, octave_idx_type c); |
|
89 ComplexMatrix& insert (const ComplexRowVector& a, octave_idx_type r, octave_idx_type c); |
|
90 ComplexMatrix& insert (const ComplexColumnVector& a, octave_idx_type r, octave_idx_type c); |
|
91 ComplexMatrix& insert (const ComplexDiagMatrix& a, octave_idx_type r, octave_idx_type c); |
458
|
92 |
|
93 ComplexMatrix& fill (double val); |
|
94 ComplexMatrix& fill (const Complex& val); |
5275
|
95 ComplexMatrix& fill (double val, octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2); |
|
96 ComplexMatrix& fill (const Complex& val, octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2); |
458
|
97 |
|
98 ComplexMatrix append (const Matrix& a) const; |
|
99 ComplexMatrix append (const RowVector& a) const; |
|
100 ComplexMatrix append (const ColumnVector& a) const; |
|
101 ComplexMatrix append (const DiagMatrix& a) const; |
|
102 |
|
103 ComplexMatrix append (const ComplexMatrix& a) const; |
|
104 ComplexMatrix append (const ComplexRowVector& a) const; |
|
105 ComplexMatrix append (const ComplexColumnVector& a) const; |
|
106 ComplexMatrix append (const ComplexDiagMatrix& a) const; |
|
107 |
|
108 ComplexMatrix stack (const Matrix& a) const; |
|
109 ComplexMatrix stack (const RowVector& a) const; |
|
110 ComplexMatrix stack (const ColumnVector& a) const; |
|
111 ComplexMatrix stack (const DiagMatrix& a) const; |
|
112 |
|
113 ComplexMatrix stack (const ComplexMatrix& a) const; |
|
114 ComplexMatrix stack (const ComplexRowVector& a) const; |
|
115 ComplexMatrix stack (const ComplexColumnVector& a) const; |
|
116 ComplexMatrix stack (const ComplexDiagMatrix& a) const; |
|
117 |
|
118 ComplexMatrix hermitian (void) const; // complex conjugate transpose |
3225
|
119 ComplexMatrix transpose (void) const |
|
120 { return MArray2<Complex>::transpose (); } |
458
|
121 |
|
122 friend ComplexMatrix conj (const ComplexMatrix& a); |
|
123 |
1359
|
124 // resize is the destructive equivalent for this one |
458
|
125 |
5275
|
126 ComplexMatrix extract (octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const; |
458
|
127 |
5275
|
128 ComplexMatrix extract_n (octave_idx_type r1, octave_idx_type c1, octave_idx_type nr, octave_idx_type nc) const; |
4316
|
129 |
1359
|
130 // extract row or column i. |
458
|
131 |
5275
|
132 ComplexRowVector row (octave_idx_type i) const; |
458
|
133 |
5275
|
134 ComplexColumnVector column (octave_idx_type i) const; |
458
|
135 |
|
136 ComplexMatrix inverse (void) const; |
5275
|
137 ComplexMatrix inverse (octave_idx_type& info) const; |
|
138 ComplexMatrix inverse (octave_idx_type& info, double& rcond, int force = 0, |
4329
|
139 int calc_cond = 1) const; |
458
|
140 |
4384
|
141 ComplexMatrix pseudo_inverse (double tol = 0.0) const; |
740
|
142 |
458
|
143 ComplexMatrix fourier (void) const; |
|
144 ComplexMatrix ifourier (void) const; |
|
145 |
677
|
146 ComplexMatrix fourier2d (void) const; |
|
147 ComplexMatrix ifourier2d (void) const; |
|
148 |
458
|
149 ComplexDET determinant (void) const; |
5275
|
150 ComplexDET determinant (octave_idx_type& info) const; |
|
151 ComplexDET determinant (octave_idx_type& info, double& rcond, int calc_cond = 1) const; |
458
|
152 |
|
153 ComplexMatrix solve (const Matrix& b) const; |
5275
|
154 ComplexMatrix solve (const Matrix& b, octave_idx_type& info) const; |
|
155 ComplexMatrix solve (const Matrix& b, octave_idx_type& info, double& rcond) const; |
|
156 ComplexMatrix solve (const Matrix& b, octave_idx_type& info, double& rcond, |
3480
|
157 solve_singularity_handler sing_handler) const; |
458
|
158 |
|
159 ComplexMatrix solve (const ComplexMatrix& b) const; |
5275
|
160 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info) const; |
|
161 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info, double& rcond) const; |
|
162 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info, double& rcond, |
3480
|
163 solve_singularity_handler sing_handler) const; |
458
|
164 |
3585
|
165 ComplexColumnVector solve (const ColumnVector& b) const; |
5275
|
166 ComplexColumnVector solve (const ColumnVector& b, octave_idx_type& info) const; |
|
167 ComplexColumnVector solve (const ColumnVector& b, octave_idx_type& info, |
3585
|
168 double& rcond) const; |
5275
|
169 ComplexColumnVector solve (const ColumnVector& b, octave_idx_type& info, double& rcond, |
3585
|
170 solve_singularity_handler sing_handler) const; |
|
171 |
458
|
172 ComplexColumnVector solve (const ComplexColumnVector& b) const; |
5275
|
173 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info) const; |
|
174 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info, |
458
|
175 double& rcond) const; |
5275
|
176 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info, |
3480
|
177 double& rcond, |
|
178 solve_singularity_handler sing_handler) const; |
458
|
179 |
3585
|
180 ComplexMatrix lssolve (const Matrix& b) const; |
5275
|
181 ComplexMatrix lssolve (const Matrix& b, octave_idx_type& info) const; |
|
182 ComplexMatrix lssolve (const Matrix& b, octave_idx_type& info, octave_idx_type& rank) const; |
3585
|
183 |
458
|
184 ComplexMatrix lssolve (const ComplexMatrix& b) const; |
5275
|
185 ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info) const; |
|
186 ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info, |
|
187 octave_idx_type& rank) const; |
458
|
188 |
3585
|
189 ComplexColumnVector lssolve (const ColumnVector& b) const; |
5275
|
190 ComplexColumnVector lssolve (const ColumnVector& b, octave_idx_type& info) const; |
|
191 ComplexColumnVector lssolve (const ColumnVector& b, octave_idx_type& info, |
|
192 octave_idx_type& rank) const; |
3585
|
193 |
458
|
194 ComplexColumnVector lssolve (const ComplexColumnVector& b) const; |
5275
|
195 ComplexColumnVector lssolve (const ComplexColumnVector& b, octave_idx_type& info) const; |
|
196 ComplexColumnVector lssolve (const ComplexColumnVector& b, octave_idx_type& info, |
|
197 octave_idx_type& rank) const; |
458
|
198 |
1819
|
199 ComplexMatrix expm (void) const; |
|
200 |
1359
|
201 // matrix by diagonal matrix -> matrix operations |
458
|
202 |
|
203 ComplexMatrix& operator += (const DiagMatrix& a); |
|
204 ComplexMatrix& operator -= (const DiagMatrix& a); |
|
205 |
|
206 ComplexMatrix& operator += (const ComplexDiagMatrix& a); |
|
207 ComplexMatrix& operator -= (const ComplexDiagMatrix& a); |
|
208 |
1359
|
209 // matrix by matrix -> matrix operations |
458
|
210 |
|
211 ComplexMatrix& operator += (const Matrix& a); |
|
212 ComplexMatrix& operator -= (const Matrix& a); |
|
213 |
1359
|
214 // unary operations |
458
|
215 |
2964
|
216 boolMatrix operator ! (void) const; |
458
|
217 |
1359
|
218 // other operations |
458
|
219 |
2676
|
220 ComplexMatrix map (c_c_Mapper f) const; |
|
221 Matrix map (d_c_Mapper f) const; |
3248
|
222 boolMatrix map (b_c_Mapper f) const; |
2676
|
223 |
|
224 ComplexMatrix& apply (c_c_Mapper f); |
458
|
225 |
2384
|
226 bool any_element_is_inf_or_nan (void) const; |
2408
|
227 bool all_elements_are_real (void) const; |
2384
|
228 bool all_integers (double& max_val, double& min_val) const; |
|
229 bool too_large_for_float (void) const; |
1963
|
230 |
4017
|
231 boolMatrix all (int dim = -1) const; |
|
232 boolMatrix any (int dim = -1) const; |
458
|
233 |
4017
|
234 ComplexMatrix cumprod (int dim = -1) const; |
|
235 ComplexMatrix cumsum (int dim = -1) const; |
|
236 ComplexMatrix prod (int dim = -1) const; |
|
237 ComplexMatrix sum (int dim = -1) const; |
|
238 ComplexMatrix sumsq (int dim = -1) const; |
4329
|
239 Matrix abs (void) const; |
458
|
240 |
|
241 ComplexColumnVector diag (void) const; |
5275
|
242 ComplexColumnVector diag (octave_idx_type k) const; |
458
|
243 |
5275
|
244 bool row_is_real_only (octave_idx_type) const; |
|
245 bool column_is_real_only (octave_idx_type) const; |
458
|
246 |
2354
|
247 ComplexColumnVector row_min (void) const; |
458
|
248 ComplexColumnVector row_max (void) const; |
2354
|
249 |
5275
|
250 ComplexColumnVector row_min (Array<octave_idx_type>& index) const; |
|
251 ComplexColumnVector row_max (Array<octave_idx_type>& index) const; |
458
|
252 |
|
253 ComplexRowVector column_min (void) const; |
2354
|
254 ComplexRowVector column_max (void) const; |
458
|
255 |
5275
|
256 ComplexRowVector column_min (Array<octave_idx_type>& index) const; |
|
257 ComplexRowVector column_max (Array<octave_idx_type>& index) const; |
458
|
258 |
1359
|
259 // i/o |
458
|
260 |
3504
|
261 friend std::ostream& operator << (std::ostream& os, const ComplexMatrix& a); |
|
262 friend std::istream& operator >> (std::istream& is, ComplexMatrix& a); |
458
|
263 |
3933
|
264 static Complex resize_fill_value (void) { return Complex (0.0, 0.0); } |
|
265 |
458
|
266 private: |
|
267 |
5275
|
268 ComplexMatrix (Complex *d, octave_idx_type r, octave_idx_type c) : MArray2<Complex> (d, r, c) { } |
458
|
269 }; |
|
270 |
5508
|
271 // column vector by row vector -> matrix operations |
|
272 |
|
273 extern ComplexMatrix |
|
274 operator * (const ColumnVector& a, const ComplexRowVector& b); |
|
275 |
|
276 extern ComplexMatrix |
|
277 operator * (const ComplexColumnVector& a, const RowVector& b); |
1819
|
278 |
5508
|
279 extern ComplexMatrix |
|
280 operator * (const ComplexColumnVector& a, const ComplexRowVector& b); |
|
281 |
|
282 extern ComplexMatrix |
|
283 Givens (const Complex&, const Complex&); |
|
284 |
|
285 extern ComplexMatrix |
|
286 Sylvester (const ComplexMatrix&, const ComplexMatrix&, const ComplexMatrix&); |
1819
|
287 |
2828
|
288 extern ComplexMatrix operator * (const Matrix&, const ComplexMatrix&); |
|
289 extern ComplexMatrix operator * (const ComplexMatrix&, const Matrix&); |
|
290 extern ComplexMatrix operator * (const ComplexMatrix&, const ComplexMatrix&); |
|
291 |
4309
|
292 extern ComplexMatrix min (const Complex& c, const ComplexMatrix& m); |
|
293 extern ComplexMatrix min (const ComplexMatrix& m, const Complex& c); |
|
294 extern ComplexMatrix min (const ComplexMatrix& a, const ComplexMatrix& b); |
|
295 |
|
296 extern ComplexMatrix max (const Complex& c, const ComplexMatrix& m); |
|
297 extern ComplexMatrix max (const ComplexMatrix& m, const Complex& c); |
|
298 extern ComplexMatrix max (const ComplexMatrix& a, const ComplexMatrix& b); |
|
299 |
2870
|
300 MS_CMP_OP_DECLS (ComplexMatrix, Complex) |
|
301 MS_BOOL_OP_DECLS (ComplexMatrix, Complex) |
|
302 |
|
303 SM_CMP_OP_DECLS (Complex, ComplexMatrix) |
|
304 SM_BOOL_OP_DECLS (Complex, ComplexMatrix) |
|
305 |
|
306 MM_CMP_OP_DECLS (ComplexMatrix, ComplexMatrix) |
|
307 MM_BOOL_OP_DECLS (ComplexMatrix, ComplexMatrix) |
|
308 |
3573
|
309 MARRAY_FORWARD_DEFS (MArray2, ComplexMatrix, Complex) |
|
310 |
458
|
311 #endif |
|
312 |
|
313 /* |
|
314 ;;; Local Variables: *** |
|
315 ;;; mode: C++ *** |
|
316 ;;; End: *** |
|
317 */ |