Mercurial > hg > octave-nkf
annotate liboctave/CMatrix.h @ 7620:36594d5bbe13
Move diag function into the octave_value class
author | David Bateman <dbateman@free.fr> |
---|---|
date | Fri, 21 Mar 2008 00:08:24 +0100 |
parents | 8c32f95c2639 |
children | 45f5faba05a2 |
rev | line source |
---|---|
458 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, |
4 2004, 2005, 2006, 2007 John W. Eaton | |
458 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
458 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
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 |
6979 | 50 ComplexMatrix (const dim_vector& dv) : MArray2<Complex> (dv) { } |
51 | |
52 ComplexMatrix (const dim_vector& dv, const Complex& val) | |
53 : MArray2<Complex> (dv, val) { } | |
54 | |
1214 | 55 ComplexMatrix (const ComplexMatrix& a) : MArray2<Complex> (a) { } |
3585 | 56 |
57 ComplexMatrix (const MArray2<Complex>& a) : MArray2<Complex> (a) { } | |
58 | |
59 explicit ComplexMatrix (const Matrix& a); | |
60 | |
61 explicit ComplexMatrix (const RowVector& rv); | |
62 | |
63 explicit ComplexMatrix (const ColumnVector& cv); | |
458 | 64 |
3585 | 65 explicit ComplexMatrix (const DiagMatrix& a); |
66 | |
67 explicit ComplexMatrix (const ComplexRowVector& rv); | |
68 | |
69 explicit ComplexMatrix (const ComplexColumnVector& cv); | |
70 | |
71 explicit ComplexMatrix (const ComplexDiagMatrix& a); | |
72 | |
73 explicit ComplexMatrix (const boolMatrix& a); | |
74 | |
75 explicit ComplexMatrix (const charMatrix& a); | |
1574 | 76 |
458 | 77 ComplexMatrix& operator = (const ComplexMatrix& a) |
78 { | |
1214 | 79 MArray2<Complex>::operator = (a); |
458 | 80 return *this; |
81 } | |
82 | |
2384 | 83 bool operator == (const ComplexMatrix& a) const; |
84 bool operator != (const ComplexMatrix& a) const; | |
458 | 85 |
2815 | 86 bool is_hermitian (void) const; |
87 | |
1359 | 88 // destructive insert/delete/reorder operations |
458 | 89 |
5275 | 90 ComplexMatrix& insert (const Matrix& a, octave_idx_type r, octave_idx_type c); |
91 ComplexMatrix& insert (const RowVector& a, octave_idx_type r, octave_idx_type c); | |
92 ComplexMatrix& insert (const ColumnVector& a, octave_idx_type r, octave_idx_type c); | |
93 ComplexMatrix& insert (const DiagMatrix& a, octave_idx_type r, octave_idx_type c); | |
458 | 94 |
5275 | 95 ComplexMatrix& insert (const ComplexMatrix& a, octave_idx_type r, octave_idx_type c); |
96 ComplexMatrix& insert (const ComplexRowVector& a, octave_idx_type r, octave_idx_type c); | |
97 ComplexMatrix& insert (const ComplexColumnVector& a, octave_idx_type r, octave_idx_type c); | |
98 ComplexMatrix& insert (const ComplexDiagMatrix& a, octave_idx_type r, octave_idx_type c); | |
458 | 99 |
100 ComplexMatrix& fill (double val); | |
101 ComplexMatrix& fill (const Complex& val); | |
5275 | 102 ComplexMatrix& fill (double val, octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2); |
103 ComplexMatrix& fill (const Complex& val, octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2); | |
458 | 104 |
105 ComplexMatrix append (const Matrix& a) const; | |
106 ComplexMatrix append (const RowVector& a) const; | |
107 ComplexMatrix append (const ColumnVector& a) const; | |
108 ComplexMatrix append (const DiagMatrix& a) const; | |
109 | |
110 ComplexMatrix append (const ComplexMatrix& a) const; | |
111 ComplexMatrix append (const ComplexRowVector& a) const; | |
112 ComplexMatrix append (const ComplexColumnVector& a) const; | |
113 ComplexMatrix append (const ComplexDiagMatrix& a) const; | |
114 | |
115 ComplexMatrix stack (const Matrix& a) const; | |
116 ComplexMatrix stack (const RowVector& a) const; | |
117 ComplexMatrix stack (const ColumnVector& a) const; | |
118 ComplexMatrix stack (const DiagMatrix& a) const; | |
119 | |
120 ComplexMatrix stack (const ComplexMatrix& a) const; | |
121 ComplexMatrix stack (const ComplexRowVector& a) const; | |
122 ComplexMatrix stack (const ComplexColumnVector& a) const; | |
123 ComplexMatrix stack (const ComplexDiagMatrix& a) const; | |
124 | |
125 ComplexMatrix hermitian (void) const; // complex conjugate transpose | |
3225 | 126 ComplexMatrix transpose (void) const |
127 { return MArray2<Complex>::transpose (); } | |
458 | 128 |
129 friend ComplexMatrix conj (const ComplexMatrix& a); | |
130 | |
1359 | 131 // resize is the destructive equivalent for this one |
458 | 132 |
5275 | 133 ComplexMatrix extract (octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const; |
458 | 134 |
5275 | 135 ComplexMatrix extract_n (octave_idx_type r1, octave_idx_type c1, octave_idx_type nr, octave_idx_type nc) const; |
4316 | 136 |
1359 | 137 // extract row or column i. |
458 | 138 |
5275 | 139 ComplexRowVector row (octave_idx_type i) const; |
458 | 140 |
5275 | 141 ComplexColumnVector column (octave_idx_type i) const; |
458 | 142 |
6207 | 143 private: |
144 ComplexMatrix tinverse (MatrixType &mattype, octave_idx_type& info, | |
145 double& rcond, int force, int calc_cond) const; | |
146 | |
147 ComplexMatrix finverse (MatrixType &mattype, octave_idx_type& info, | |
148 double& rcond, int force, int calc_cond) const; | |
149 | |
150 public: | |
458 | 151 ComplexMatrix inverse (void) const; |
6479 | 152 ComplexMatrix inverse (octave_idx_type& info) const; |
153 ComplexMatrix inverse (octave_idx_type& info, double& rcond, int force = 0, | |
154 int calc_cond = 1) const; | |
155 | |
6207 | 156 ComplexMatrix inverse (MatrixType &mattype) const; |
157 ComplexMatrix inverse (MatrixType &mattype, octave_idx_type& info) const; | |
158 ComplexMatrix inverse (MatrixType &mattype, octave_idx_type& info, | |
159 double& rcond, int force = 0, | |
4329 | 160 int calc_cond = 1) const; |
458 | 161 |
4384 | 162 ComplexMatrix pseudo_inverse (double tol = 0.0) const; |
740 | 163 |
458 | 164 ComplexMatrix fourier (void) const; |
165 ComplexMatrix ifourier (void) const; | |
166 | |
677 | 167 ComplexMatrix fourier2d (void) const; |
168 ComplexMatrix ifourier2d (void) const; | |
169 | |
458 | 170 ComplexDET determinant (void) const; |
5275 | 171 ComplexDET determinant (octave_idx_type& info) const; |
172 ComplexDET determinant (octave_idx_type& info, double& rcond, int calc_cond = 1) const; | |
458 | 173 |
5785 | 174 private: |
175 // Upper triangular matrix solvers | |
176 ComplexMatrix utsolve (MatrixType &typ, const ComplexMatrix& b, | |
177 octave_idx_type& info, double& rcond, | |
178 solve_singularity_handler sing_handler, | |
179 bool calc_cond = false) const; | |
180 | |
181 // Lower triangular matrix solvers | |
182 ComplexMatrix ltsolve (MatrixType &typ, const ComplexMatrix& b, | |
183 octave_idx_type& info, double& rcond, | |
184 solve_singularity_handler sing_handler, | |
185 bool calc_cond = false) const; | |
186 | |
187 // Full matrix solvers (umfpack/cholesky) | |
188 ComplexMatrix fsolve (MatrixType &typ, const ComplexMatrix& b, | |
189 octave_idx_type& info, double& rcond, | |
190 solve_singularity_handler sing_handler, | |
191 bool calc_cond = false) const; | |
192 | |
193 public: | |
194 // Generic interface to solver with no probing of type | |
195 ComplexMatrix solve (MatrixType &typ, const Matrix& b) const; | |
196 ComplexMatrix solve (MatrixType &typ, const Matrix& b, | |
197 octave_idx_type& info) const; | |
198 ComplexMatrix solve (MatrixType &typ, const Matrix& b, | |
199 octave_idx_type& info, double& rcond) const; | |
200 ComplexMatrix solve (MatrixType &typ, const Matrix& b, octave_idx_type& info, | |
201 double& rcond, solve_singularity_handler sing_handler, | |
202 bool singular_fallback = true) const; | |
203 | |
204 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b) const; | |
205 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b, | |
206 octave_idx_type& info) const; | |
207 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b, | |
208 octave_idx_type& info, double& rcond) const; | |
209 ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b, | |
210 octave_idx_type& info, double& rcond, | |
211 solve_singularity_handler sing_handler, | |
212 bool singular_fallback = true) const; | |
213 | |
214 ComplexColumnVector solve (MatrixType &typ, const ColumnVector& b) const; | |
215 ComplexColumnVector solve (MatrixType &typ, const ColumnVector& b, | |
216 octave_idx_type& info) const; | |
217 ComplexColumnVector solve (MatrixType &typ, const ColumnVector& b, | |
218 octave_idx_type& info, double& rcond) const; | |
219 ComplexColumnVector solve (MatrixType &typ, const ColumnVector& b, | |
220 octave_idx_type& info, double& rcond, | |
221 solve_singularity_handler sing_handler) const; | |
222 | |
223 ComplexColumnVector solve (MatrixType &typ, | |
224 const ComplexColumnVector& b) const; | |
225 ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b, | |
226 octave_idx_type& info) const; | |
227 ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b, | |
228 octave_idx_type& info, double& rcond) const; | |
229 ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b, | |
230 octave_idx_type& info, double& rcond, | |
231 solve_singularity_handler sing_handler) const; | |
232 | |
233 // Generic interface to solver with probing of type | |
458 | 234 ComplexMatrix solve (const Matrix& b) const; |
5275 | 235 ComplexMatrix solve (const Matrix& b, octave_idx_type& info) const; |
236 ComplexMatrix solve (const Matrix& b, octave_idx_type& info, double& rcond) const; | |
237 ComplexMatrix solve (const Matrix& b, octave_idx_type& info, double& rcond, | |
3480 | 238 solve_singularity_handler sing_handler) const; |
458 | 239 |
240 ComplexMatrix solve (const ComplexMatrix& b) const; | |
5275 | 241 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info) const; |
242 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info, double& rcond) const; | |
243 ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info, double& rcond, | |
3480 | 244 solve_singularity_handler sing_handler) const; |
458 | 245 |
3585 | 246 ComplexColumnVector solve (const ColumnVector& b) const; |
5275 | 247 ComplexColumnVector solve (const ColumnVector& b, octave_idx_type& info) const; |
248 ComplexColumnVector solve (const ColumnVector& b, octave_idx_type& info, | |
3585 | 249 double& rcond) const; |
5275 | 250 ComplexColumnVector solve (const ColumnVector& b, octave_idx_type& info, double& rcond, |
3585 | 251 solve_singularity_handler sing_handler) const; |
252 | |
458 | 253 ComplexColumnVector solve (const ComplexColumnVector& b) const; |
5275 | 254 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info) const; |
255 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info, | |
458 | 256 double& rcond) const; |
5275 | 257 ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info, |
3480 | 258 double& rcond, |
259 solve_singularity_handler sing_handler) const; | |
458 | 260 |
3585 | 261 ComplexMatrix lssolve (const Matrix& b) const; |
5275 | 262 ComplexMatrix lssolve (const Matrix& b, octave_idx_type& info) const; |
7076 | 263 ComplexMatrix lssolve (const Matrix& b, octave_idx_type& info, |
264 octave_idx_type& rank) const; | |
265 ComplexMatrix lssolve (const Matrix& b, octave_idx_type& info, | |
266 octave_idx_type& rank, double& rcond) const; | |
3585 | 267 |
458 | 268 ComplexMatrix lssolve (const ComplexMatrix& b) const; |
5275 | 269 ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info) const; |
270 ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info, | |
271 octave_idx_type& rank) const; | |
7076 | 272 ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info, |
273 octave_idx_type& rank, double& rcond) const; | |
458 | 274 |
3585 | 275 ComplexColumnVector lssolve (const ColumnVector& b) const; |
7076 | 276 ComplexColumnVector lssolve (const ColumnVector& b, |
277 octave_idx_type& info) const; | |
5275 | 278 ComplexColumnVector lssolve (const ColumnVector& b, octave_idx_type& info, |
279 octave_idx_type& rank) const; | |
7076 | 280 ComplexColumnVector lssolve (const ColumnVector& b, octave_idx_type& info, |
281 octave_idx_type& rank, double& rcond) const; | |
3585 | 282 |
458 | 283 ComplexColumnVector lssolve (const ComplexColumnVector& b) const; |
7076 | 284 ComplexColumnVector lssolve (const ComplexColumnVector& b, |
285 octave_idx_type& info) const; | |
286 ComplexColumnVector lssolve (const ComplexColumnVector& b, | |
287 octave_idx_type& info, | |
5275 | 288 octave_idx_type& rank) const; |
7076 | 289 ComplexColumnVector lssolve (const ComplexColumnVector& b, |
290 octave_idx_type& info, | |
291 octave_idx_type& rank, double& rcond) const; | |
458 | 292 |
1819 | 293 ComplexMatrix expm (void) const; |
294 | |
1359 | 295 // matrix by diagonal matrix -> matrix operations |
458 | 296 |
297 ComplexMatrix& operator += (const DiagMatrix& a); | |
298 ComplexMatrix& operator -= (const DiagMatrix& a); | |
299 | |
300 ComplexMatrix& operator += (const ComplexDiagMatrix& a); | |
301 ComplexMatrix& operator -= (const ComplexDiagMatrix& a); | |
302 | |
1359 | 303 // matrix by matrix -> matrix operations |
458 | 304 |
305 ComplexMatrix& operator += (const Matrix& a); | |
306 ComplexMatrix& operator -= (const Matrix& a); | |
307 | |
1359 | 308 // unary operations |
458 | 309 |
2964 | 310 boolMatrix operator ! (void) const; |
458 | 311 |
1359 | 312 // other operations |
458 | 313 |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7076
diff
changeset
|
314 typedef double (*dmapper) (const Complex&); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7076
diff
changeset
|
315 typedef Complex (*cmapper) (const Complex&); |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7076
diff
changeset
|
316 typedef bool (*bmapper) (const Complex&); |
2676 | 317 |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7076
diff
changeset
|
318 Matrix map (dmapper fcn) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7076
diff
changeset
|
319 ComplexMatrix map (cmapper fcn) const; |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7076
diff
changeset
|
320 boolMatrix map (bmapper fcn) const; |
458 | 321 |
2384 | 322 bool any_element_is_inf_or_nan (void) const; |
2408 | 323 bool all_elements_are_real (void) const; |
2384 | 324 bool all_integers (double& max_val, double& min_val) const; |
325 bool too_large_for_float (void) const; | |
1963 | 326 |
4017 | 327 boolMatrix all (int dim = -1) const; |
328 boolMatrix any (int dim = -1) const; | |
458 | 329 |
4017 | 330 ComplexMatrix cumprod (int dim = -1) const; |
331 ComplexMatrix cumsum (int dim = -1) const; | |
332 ComplexMatrix prod (int dim = -1) const; | |
333 ComplexMatrix sum (int dim = -1) const; | |
334 ComplexMatrix sumsq (int dim = -1) const; | |
4329 | 335 Matrix abs (void) const; |
458 | 336 |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7503
diff
changeset
|
337 ComplexMatrix diag (octave_idx_type k = 0) const; |
458 | 338 |
5275 | 339 bool row_is_real_only (octave_idx_type) const; |
340 bool column_is_real_only (octave_idx_type) const; | |
458 | 341 |
2354 | 342 ComplexColumnVector row_min (void) const; |
458 | 343 ComplexColumnVector row_max (void) const; |
2354 | 344 |
5275 | 345 ComplexColumnVector row_min (Array<octave_idx_type>& index) const; |
346 ComplexColumnVector row_max (Array<octave_idx_type>& index) const; | |
458 | 347 |
348 ComplexRowVector column_min (void) const; | |
2354 | 349 ComplexRowVector column_max (void) const; |
458 | 350 |
5275 | 351 ComplexRowVector column_min (Array<octave_idx_type>& index) const; |
352 ComplexRowVector column_max (Array<octave_idx_type>& index) const; | |
458 | 353 |
1359 | 354 // i/o |
458 | 355 |
6108 | 356 friend OCTAVE_API std::ostream& operator << (std::ostream& os, const ComplexMatrix& a); |
357 friend OCTAVE_API std::istream& operator >> (std::istream& is, ComplexMatrix& a); | |
458 | 358 |
3933 | 359 static Complex resize_fill_value (void) { return Complex (0.0, 0.0); } |
360 | |
458 | 361 private: |
362 | |
5275 | 363 ComplexMatrix (Complex *d, octave_idx_type r, octave_idx_type c) : MArray2<Complex> (d, r, c) { } |
458 | 364 }; |
365 | |
5508 | 366 // column vector by row vector -> matrix operations |
367 | |
6108 | 368 extern OCTAVE_API ComplexMatrix |
5508 | 369 operator * (const ColumnVector& a, const ComplexRowVector& b); |
370 | |
6108 | 371 extern OCTAVE_API ComplexMatrix |
5508 | 372 operator * (const ComplexColumnVector& a, const RowVector& b); |
1819 | 373 |
6108 | 374 extern OCTAVE_API ComplexMatrix |
5508 | 375 operator * (const ComplexColumnVector& a, const ComplexRowVector& b); |
376 | |
6108 | 377 extern OCTAVE_API ComplexMatrix |
5508 | 378 Givens (const Complex&, const Complex&); |
379 | |
6108 | 380 extern OCTAVE_API ComplexMatrix |
5508 | 381 Sylvester (const ComplexMatrix&, const ComplexMatrix&, const ComplexMatrix&); |
1819 | 382 |
6108 | 383 extern OCTAVE_API ComplexMatrix operator * (const Matrix&, const ComplexMatrix&); |
384 extern OCTAVE_API ComplexMatrix operator * (const ComplexMatrix&, const Matrix&); | |
385 extern OCTAVE_API ComplexMatrix operator * (const ComplexMatrix&, const ComplexMatrix&); | |
2828 | 386 |
6108 | 387 extern OCTAVE_API ComplexMatrix min (const Complex& c, const ComplexMatrix& m); |
388 extern OCTAVE_API ComplexMatrix min (const ComplexMatrix& m, const Complex& c); | |
389 extern OCTAVE_API ComplexMatrix min (const ComplexMatrix& a, const ComplexMatrix& b); | |
4309 | 390 |
6108 | 391 extern OCTAVE_API ComplexMatrix max (const Complex& c, const ComplexMatrix& m); |
392 extern OCTAVE_API ComplexMatrix max (const ComplexMatrix& m, const Complex& c); | |
393 extern OCTAVE_API ComplexMatrix max (const ComplexMatrix& a, const ComplexMatrix& b); | |
4309 | 394 |
6708 | 395 MS_CMP_OP_DECLS (ComplexMatrix, Complex, OCTAVE_API) |
396 MS_BOOL_OP_DECLS (ComplexMatrix, Complex, OCTAVE_API) | |
2870 | 397 |
6708 | 398 SM_CMP_OP_DECLS (Complex, ComplexMatrix, OCTAVE_API) |
399 SM_BOOL_OP_DECLS (Complex, ComplexMatrix, OCTAVE_API) | |
2870 | 400 |
6708 | 401 MM_CMP_OP_DECLS (ComplexMatrix, ComplexMatrix, OCTAVE_API) |
402 MM_BOOL_OP_DECLS (ComplexMatrix, ComplexMatrix, OCTAVE_API) | |
2870 | 403 |
3573 | 404 MARRAY_FORWARD_DEFS (MArray2, ComplexMatrix, Complex) |
405 | |
458 | 406 #endif |
407 | |
408 /* | |
409 ;;; Local Variables: *** | |
410 ;;; mode: C++ *** | |
411 ;;; End: *** | |
412 */ |