3
|
1 // Matrix manipulations. -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993 John W. Eaton |
|
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 |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
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 |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 /* |
|
25 |
|
26 Should probably say something here about why these classes are not |
|
27 represented by some sort of inheritance tree... |
|
28 |
|
29 */ |
|
30 |
|
31 #if !defined (_Matrix_h) |
|
32 #define _Matrix_h 1 |
|
33 |
|
34 // I\'m not sure how this is supposed to work if the .h file declares |
|
35 // several classes, each of which is defined in a separate file... |
|
36 // |
|
37 // #ifdef __GNUG__ |
|
38 // #pragma interface |
|
39 // #endif |
|
40 |
|
41 #include <stdlib.h> |
|
42 #include <stddef.h> |
|
43 #include <math.h> |
|
44 #include <values.h> |
|
45 #include <assert.h> |
|
46 #include <iostream.h> |
|
47 // #include <iomanip.h> // We don\'t use this yet. |
|
48 #include <Complex.h> |
|
49 |
|
50 #define FAIL assert(0) /* XXX FIXME XXX */ |
|
51 |
|
52 #ifndef MAPPER_FCN_TYPEDEFS |
|
53 #define MAPPER_FCN_TYPEDEFS 1 |
|
54 |
|
55 typedef double (*d_d_Mapper)(double); |
|
56 typedef double (*d_c_Mapper)(const Complex&); |
|
57 typedef Complex (*c_c_Mapper)(const Complex&); |
|
58 |
|
59 #endif |
|
60 |
|
61 #include "f77-uscore.h" |
|
62 |
|
63 // Fortran functions we call. |
|
64 |
|
65 extern "C" |
|
66 { |
|
67 int F77_FCN (dgemm) (const char*, const char*, const int*, |
|
68 const int*, const int*, const double*, |
|
69 const double*, const int*, const double*, |
|
70 const int*, const double*, double*, const int*, |
|
71 long, long); |
|
72 |
|
73 int F77_FCN (dgemv) (const char*, const int*, const int*, |
|
74 const double*, const double*, const int*, |
|
75 const double*, const int*, const double*, |
|
76 double*, const int*, long); |
|
77 |
|
78 int F77_FCN (dgeco) (double*, const int*, const int*, int*, double*, |
|
79 double*); |
|
80 |
|
81 int F77_FCN (dgesv) (const int*, const int*, double*, const int*, |
|
82 int*, double*, const int*, int*); |
|
83 |
|
84 int F77_FCN (dgeqrf) (const int*, const int*, double*, const int*, |
|
85 double*, double*, const int*, int*); |
|
86 |
|
87 int F77_FCN (dorgqr) (const int*, const int*, const int*, double*, |
|
88 const int*, double*, double*, const int*, int*); |
|
89 |
|
90 int F77_FCN (dgesl) (const double*, const int*, const int*, |
|
91 const int*, double*, const int*); |
|
92 |
|
93 int F77_FCN (dgedi) (double*, const int*, const int*, const int*, |
|
94 double*, double*, const int*); |
|
95 |
|
96 double F77_FCN (ddot) (const int*, const double*, const int*, |
|
97 const double*, const int*); |
|
98 |
|
99 int F77_FCN (dgeev) (const char*, const char*, const int*, double*, |
|
100 const int*, double*, double*, double*, |
|
101 const int*, double*, const int*, double*, |
|
102 const int*, int*, long, long); |
|
103 |
|
104 int F77_FCN (dgeesx) (const char*, const char*, int (*)(), const char*, |
|
105 const int*, double*, const int*, int*, double*, |
|
106 double*, double*, const int*, double*, double*, |
|
107 double*, const int*, int*, const int*, int*, |
|
108 int*, long, long); |
|
109 |
|
110 int F77_FCN (dhseqr) (const char*, const char*, const int*, |
|
111 const int*, const int*, double*, |
|
112 const int*, double*, double*, |
|
113 double*, const int*, double*, const int*, |
|
114 int*, long, long); |
|
115 |
|
116 int F77_FCN (dgebal) (const char*, const int*, double*, |
|
117 const int*, int*, int*, double*, |
|
118 int*, long, long); |
|
119 |
|
120 int F77_FCN (dgebak) (const char*, const char*, const int*, const int*, |
|
121 const int*, double*, const int*, double*, const int*, |
|
122 int*, long, long); |
|
123 |
|
124 int F77_FCN (dgehrd) (const int*, const int*, const int*, |
|
125 double*, const int*, double*, double*, |
|
126 const int*, int*, long, long); |
|
127 |
|
128 int F77_FCN (dorghr) (const int*, const int*, const int*, |
|
129 double*, const int*, double*, double*, |
|
130 const int*, int*, long, long); |
|
131 |
|
132 int F77_FCN (dgesvd) (const char*, const char*, const int*, |
|
133 const int*, double*, const int*, double*, |
|
134 double*, const int*, double*, const int*, |
|
135 double*, const int*, int*, long, long); |
|
136 |
|
137 int F77_FCN (dgelss) (const int*, const int*, const int*, double*, |
|
138 const int*, double*, const int*, double*, |
|
139 const double*, int*, double*, const int*, |
|
140 int*); |
|
141 |
21
|
142 // |
|
143 // fortran functions for generalized eigenvalue problems |
|
144 // |
|
145 int F77_FCN (reduce) (const int*, const int*, double*, |
|
146 const int*, double*, |
|
147 int*, int*, double*, double*); |
|
148 |
|
149 int F77_FCN (scaleg) (const int*, const int*, double*, |
|
150 const int*, double*, |
|
151 const int*, const int*, double*, double*, double*); |
|
152 |
|
153 int F77_FCN (gradeq) (const int*, const int*, double*, |
|
154 const int*, double*, |
|
155 int*, int*, double*, double*); |
|
156 |
3
|
157 /* |
|
158 * f2c translates complex*16 as |
|
159 * |
|
160 * typedef struct { doublereal re, im; } doublecomplex; |
|
161 * |
|
162 * and Complex.h from libg++ uses |
|
163 * |
|
164 * protected: |
|
165 * double re; |
|
166 * double im; |
|
167 * |
|
168 * as the only data members, so this should work (fingers crossed that |
|
169 * things don't change). |
|
170 */ |
|
171 |
|
172 int F77_FCN (zgemm) (const char*, const char*, const int*, |
|
173 const int*, const int*, const Complex*, |
|
174 const Complex*, const int*, const Complex*, |
|
175 const int*, const Complex*, Complex*, const int*, |
|
176 long, long); |
|
177 |
|
178 int F77_FCN (zgemv) (const char*, const int*, const int*, |
|
179 const Complex*, const Complex*, const int*, |
|
180 const Complex*, const int*, const Complex*, |
|
181 Complex*, const int*, long); |
|
182 |
|
183 int F77_FCN (zgeco) (Complex*, const int*, const int*, int*, |
|
184 double*, Complex*); |
|
185 |
|
186 int F77_FCN (zgesv) (const int*, const int*, Complex*, const int*, |
|
187 int*, Complex*, const int*, int*); |
|
188 |
|
189 int F77_FCN (zgeqrf) (const int*, const int*, Complex*, const int*, |
|
190 Complex*, Complex*, const int*, int*); |
|
191 |
|
192 int F77_FCN (zgeesx) (const char*, const char*, int (*)(), const char*, |
|
193 const int*, Complex*, const int*, int*, |
|
194 Complex*, Complex*, const int*, double*, double*, |
|
195 Complex*, const int*, double*, int*, int*, |
|
196 long, long); |
|
197 |
|
198 int F77_FCN (zhseqr) (const char*, const char*, const int*, |
|
199 const int*, const int*, Complex*, const int*, |
|
200 Complex*, Complex*, const int*, Complex*, |
|
201 const int*, int*, long, long); |
|
202 |
|
203 int F77_FCN (zgebal) (const char*, const int*, Complex*, const int*, |
|
204 int*, int*, double*, int*, long, long); |
|
205 |
|
206 int F77_FCN (zgebak) (const char*, const char*, const int*, const int*, |
|
207 const int*, double*, const int*, Complex*, |
|
208 const int*, int*, long, long); |
|
209 |
|
210 int F77_FCN (zgehrd) (const int*, const int*, const int*, Complex*, |
|
211 const int*, Complex*, Complex*, const int*, |
|
212 int*, long, long); |
|
213 |
|
214 int F77_FCN (zunghr) (const int*, const int*, const int*, Complex*, |
|
215 const int*, Complex*, Complex*, const int*, |
|
216 int*, long, long); |
|
217 |
|
218 int F77_FCN (zungqr) (const int*, const int*, const int*, Complex*, |
|
219 const int*, Complex*, Complex*, const int*, int*); |
|
220 |
|
221 int F77_FCN (zgedi) (Complex*, const int*, const int*, int*, |
|
222 Complex*, Complex*, const int*); |
|
223 |
|
224 int F77_FCN (zgesl) (Complex*, const int*, const int*, int*, |
|
225 Complex*, const int*); |
|
226 |
|
227 int F77_FCN (zgeev) (const char*, const char*, const int*, Complex*, |
|
228 const int*, Complex*, Complex*, const int*, |
|
229 Complex*, const int*, Complex*, const int*, |
|
230 double*, int*, long, long); |
|
231 |
|
232 int F77_FCN (zgesvd) (const char*, const char*, const int*, |
|
233 const int*, Complex*, const int*, double*, |
|
234 Complex*, const int*, Complex*, const int*, |
|
235 Complex*, const int*, double*, int*, long, long); |
|
236 |
|
237 int F77_FCN (zgelss) (const int*, const int*, const int*, Complex*, |
|
238 const int*, Complex*, const int*, double*, |
|
239 const double*, int*, Complex*, const int*, |
|
240 double*, int*); |
|
241 |
|
242 // Note that the original complex fft routines were not written for |
|
243 // double complex arguments. They have been modified by adding an |
|
244 // implicit double precision (a-h,o-z) statement at the beginning of |
|
245 // each subroutine. |
|
246 |
|
247 int F77_FCN (cffti) (const int*, Complex*); |
|
248 |
|
249 int F77_FCN (cfftf) (const int*, Complex*, Complex*); |
|
250 |
|
251 int F77_FCN (cfftb) (const int*, Complex*, Complex*); |
|
252 |
|
253 } |
|
254 |
|
255 // Classes we declare. |
|
256 |
|
257 class Matrix; |
|
258 class ColumnVector; |
|
259 class RowVector; |
|
260 class DiagMatrix; |
|
261 class ComplexMatrix; |
|
262 class ComplexColumnVector; |
|
263 class ComplexRowVector; |
|
264 class ComplexDiagMatrix; |
21
|
265 class AEPBALANCE; |
|
266 class ComplexAEPBALANCE; |
|
267 class GEPBALANCE; |
3
|
268 class DET; |
|
269 class ComplexDET; |
|
270 class EIG; |
|
271 class HESS; |
|
272 class ComplexHESS; |
|
273 class SCHUR; |
|
274 class ComplexSCHUR; |
|
275 class SVD; |
|
276 class ComplexSVD; |
|
277 class LU; |
|
278 class ComplexLU; |
|
279 class QR; |
|
280 class ComplexQR; |
|
281 |
|
282 /* |
|
283 * Matrix class |
|
284 */ |
|
285 |
|
286 class Matrix |
|
287 { |
|
288 friend class RowVector; |
|
289 friend class DiagMatrix; |
|
290 friend class ComplexMatrix; |
|
291 friend class ComplexDiagMatrix; |
21
|
292 friend class AEPBALANCE; |
3
|
293 friend class EIG; |
21
|
294 friend class GEPBALANCE; |
3
|
295 friend class HESS; |
|
296 friend class SCHUR; |
|
297 friend class SVD; |
|
298 friend class LU; |
|
299 friend class QR; |
|
300 |
|
301 public: |
|
302 Matrix (void); |
|
303 Matrix (int r, int c); |
|
304 Matrix (int r, int c, double val); |
|
305 Matrix (const Matrix& a); |
|
306 Matrix (const DiagMatrix& a); |
|
307 Matrix (double a); |
|
308 ~Matrix (void); |
|
309 |
|
310 #if defined (MDEBUG) |
|
311 void *operator new (size_t size) |
|
312 { |
|
313 Matrix *p = ::new Matrix; |
|
314 cerr << "Matrix::new(): " << p << "\n"; |
|
315 return p; |
|
316 } |
|
317 |
|
318 void operator delete (void *p, size_t size) |
|
319 { |
|
320 cerr << "Matrix::delete(): " << p << "\n"; |
|
321 ::delete p; |
|
322 } |
|
323 #endif |
|
324 |
|
325 Matrix& operator = (const Matrix& a); |
|
326 |
|
327 int rows (void) const; |
|
328 int cols (void) const; |
|
329 int columns (void) const; |
|
330 |
|
331 double& elem (int r, int c); |
|
332 double& checkelem (int r, int c); |
|
333 double& operator () (int r, int c); |
|
334 |
|
335 double elem (int r, int c) const; // const access |
|
336 double checkelem (int r, int c) const; |
|
337 double operator () (int r, int c) const; |
|
338 |
|
339 Matrix& resize (int r, int c); |
|
340 Matrix& resize (int r, int c, double val); |
|
341 |
|
342 int operator == (const Matrix& a) const; |
|
343 int operator != (const Matrix& a) const; |
|
344 |
|
345 // destructive insert/delete/reorder operations |
|
346 |
|
347 Matrix& insert (const Matrix& a, int r, int c); |
|
348 Matrix& insert (const RowVector& a, int r, int c); |
|
349 Matrix& insert (const ColumnVector& a, int r, int c); |
|
350 Matrix& insert (const DiagMatrix& a, int r, int c); |
|
351 |
|
352 Matrix& fill (double val); |
|
353 Matrix& fill (double val, int r1, int c1, int r2, int c2); |
|
354 |
|
355 Matrix append (const Matrix& a) const; |
|
356 Matrix append (const RowVector& a) const; |
|
357 Matrix append (const ColumnVector& a) const; |
|
358 Matrix append (const DiagMatrix& a) const; |
|
359 |
|
360 Matrix stack (const Matrix& a) const; |
|
361 Matrix stack (const RowVector& a) const; |
|
362 Matrix stack (const ColumnVector& a) const; |
|
363 Matrix stack (const DiagMatrix& a) const; |
|
364 |
|
365 Matrix transpose (void) const; |
|
366 |
|
367 // resize is the destructive equivalent for this one |
|
368 |
|
369 Matrix extract (int r1, int c1, int r2, int c2) const; |
|
370 |
|
371 // extract row or column i. |
|
372 |
|
373 RowVector row (int i) const; |
|
374 RowVector row (char *s) const; |
|
375 |
|
376 ColumnVector column (int i) const; |
|
377 ColumnVector column (char *s) const; |
|
378 |
|
379 Matrix inverse (int& info, double& rcond) const; |
|
380 Matrix inverse (int& info) const; |
|
381 Matrix inverse (void) const; |
|
382 |
|
383 ComplexMatrix fourier (void) const; |
|
384 ComplexMatrix ifourier (void) const; |
|
385 |
|
386 DET determinant (void) const; |
|
387 DET determinant (int& info) const; |
|
388 DET determinant (int& info, double& rcond) const; |
|
389 |
|
390 Matrix solve (const Matrix& b) const; |
|
391 Matrix solve (const Matrix& b, int& info) const; |
|
392 Matrix solve (const Matrix& b, int& info, double& rcond) const; |
|
393 |
|
394 ComplexMatrix solve (const ComplexMatrix& b) const; |
|
395 ComplexMatrix solve (const ComplexMatrix& b, int& info) const; |
|
396 ComplexMatrix solve (const ComplexMatrix& b, int& info, double& rcond) const; |
|
397 |
|
398 ColumnVector solve (const ColumnVector& b) const; |
|
399 ColumnVector solve (const ColumnVector& b, int& info) const; |
|
400 ColumnVector solve (const ColumnVector& b, int& info, double& rcond) const; |
|
401 |
|
402 ComplexColumnVector solve (const ComplexColumnVector& b) const; |
|
403 ComplexColumnVector solve (const ComplexColumnVector& b, int& info) const; |
|
404 ComplexColumnVector solve (const ComplexColumnVector& b, int& info, |
|
405 double& rcond) const; |
|
406 |
|
407 Matrix lssolve (const Matrix& b) const; |
|
408 Matrix lssolve (const Matrix& b, int& info) const; |
|
409 Matrix lssolve (const Matrix& b, int& info, int& rank) const; |
|
410 |
|
411 ComplexMatrix lssolve (const ComplexMatrix& b) const; |
|
412 ComplexMatrix lssolve (const ComplexMatrix& b, int& info) const; |
|
413 ComplexMatrix lssolve (const ComplexMatrix& b, int& info, |
|
414 int& rank) const; |
|
415 |
|
416 ColumnVector lssolve (const ColumnVector& b) const; |
|
417 ColumnVector lssolve (const ColumnVector& b, int& info) const; |
|
418 ColumnVector lssolve (const ColumnVector& b, int& info, int& rank) const; |
|
419 |
|
420 ComplexColumnVector lssolve (const ComplexColumnVector& b) const; |
|
421 ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info) const; |
|
422 ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info, |
|
423 int& rank) const; |
|
424 |
|
425 // matrix by scalar -> matrix operations |
|
426 |
|
427 Matrix operator + (double s) const; |
|
428 Matrix operator - (double s) const; |
|
429 Matrix operator * (double s) const; |
|
430 Matrix operator / (double s) const; |
|
431 |
|
432 ComplexMatrix operator + (Complex s) const; |
|
433 ComplexMatrix operator - (Complex s) const; |
|
434 ComplexMatrix operator * (Complex s) const; |
|
435 ComplexMatrix operator / (Complex s) const; |
|
436 |
|
437 // scalar by matrix -> matrix operations |
|
438 |
|
439 friend Matrix operator + (double s, const Matrix& a); |
|
440 friend Matrix operator - (double s, const Matrix& a); |
|
441 friend Matrix operator * (double s, const Matrix& a); |
|
442 friend Matrix operator / (double s, const Matrix& a); |
|
443 |
|
444 // matrix by column vector -> column vector operations |
|
445 |
|
446 ColumnVector operator * (const ColumnVector& a) const; |
|
447 |
|
448 ComplexColumnVector operator * (const ComplexColumnVector& a) const; |
|
449 |
|
450 // matrix by diagonal matrix -> matrix operations |
|
451 |
|
452 Matrix operator + (const DiagMatrix& a) const; |
|
453 Matrix operator - (const DiagMatrix& a) const; |
|
454 Matrix operator * (const DiagMatrix& a) const; |
|
455 |
|
456 ComplexMatrix operator + (const ComplexDiagMatrix& a) const; |
|
457 ComplexMatrix operator - (const ComplexDiagMatrix& a) const; |
|
458 ComplexMatrix operator * (const ComplexDiagMatrix& a) const; |
|
459 |
|
460 Matrix& operator += (const DiagMatrix& a); |
|
461 Matrix& operator -= (const DiagMatrix& a); |
|
462 |
|
463 // matrix by matrix -> matrix operations |
|
464 |
|
465 Matrix operator + (const Matrix& a) const; |
|
466 Matrix operator - (const Matrix& a) const; |
|
467 Matrix operator * (const Matrix& a) const; |
|
468 |
|
469 ComplexMatrix operator + (const ComplexMatrix& a) const; |
|
470 ComplexMatrix operator - (const ComplexMatrix& a) const; |
|
471 ComplexMatrix operator * (const ComplexMatrix& a) const; |
|
472 |
|
473 Matrix product (const Matrix& a) const; // element by element |
|
474 Matrix quotient (const Matrix& a) const; // element by element |
|
475 |
|
476 ComplexMatrix product (const ComplexMatrix& a) const; // element by element |
|
477 ComplexMatrix quotient (const ComplexMatrix& a) const; // element by element |
|
478 |
|
479 Matrix& operator += (const Matrix& a); |
|
480 Matrix& operator -= (const Matrix& a); |
|
481 |
|
482 // unary operations |
|
483 |
|
484 Matrix operator - (void) const; |
|
485 Matrix operator ! (void) const; |
|
486 |
|
487 // other operations |
|
488 |
|
489 friend Matrix map (d_d_Mapper f, const Matrix& a); |
|
490 void map (d_d_Mapper f); |
|
491 |
|
492 Matrix all (void) const; |
|
493 Matrix any (void) const; |
|
494 |
|
495 Matrix cumprod (void) const; |
|
496 Matrix cumsum (void) const; |
|
497 Matrix prod (void) const; |
|
498 Matrix sum (void) const; |
|
499 Matrix sumsq (void) const; |
|
500 |
|
501 ColumnVector diag (void) const; |
|
502 ColumnVector diag (int k) const; |
|
503 |
|
504 ColumnVector row_min (void) const; |
|
505 ColumnVector row_max (void) const; |
|
506 |
|
507 RowVector column_min (void) const; |
|
508 RowVector column_max (void) const; |
|
509 |
|
510 // i/o |
|
511 |
|
512 friend ostream& operator << (ostream& os, const Matrix& a); |
|
513 friend istream& operator >> (istream& is, Matrix& a); |
|
514 |
|
515 // conversions |
|
516 |
|
517 double *fortran_vec (void); |
|
518 |
|
519 private: |
|
520 int nr; |
|
521 int nc; |
|
522 int len; |
|
523 double *data; |
|
524 |
|
525 Matrix (double *d, int r, int c); |
|
526 }; |
|
527 |
|
528 inline Matrix::Matrix (void) { nr = 0; nc = 0; len = 0; data = 0; } |
|
529 |
|
530 inline Matrix::Matrix (double *d, int r, int c) |
|
531 { nr = r; nc = c; len = nr*nc; data = d; } |
|
532 |
|
533 inline Matrix::~Matrix (void) { delete [] data; data = 0; } |
|
534 |
|
535 inline int Matrix::rows (void) const { return nr; } |
|
536 inline int Matrix::cols (void) const { return nc; } |
|
537 inline int Matrix::columns (void) const { return nc; } |
|
538 |
|
539 inline double& Matrix::elem (int r, int c) { return data[nr*c+r]; } |
|
540 |
|
541 inline double& Matrix::checkelem (int r, int c) |
|
542 { |
|
543 #ifndef NO_RANGE_CHECK |
|
544 if (r < 0 || r >= nr || c < 0 || c >= nc) |
|
545 FAIL; |
|
546 #endif |
|
547 |
|
548 return elem (r, c); |
|
549 } |
|
550 |
|
551 inline double& Matrix::operator () (int r, int c) |
|
552 { return checkelem (r, c); } |
|
553 |
|
554 inline double Matrix::elem (int r, int c) const { return data[nr*c+r]; } |
|
555 |
|
556 inline double Matrix::checkelem (int r, int c) const |
|
557 { |
|
558 #ifndef NO_RANGE_CHECK |
|
559 if (r < 0 || r >= nr || c < 0 || c >= nc) |
|
560 FAIL; |
|
561 #endif |
|
562 |
|
563 return elem (r, c); |
|
564 } |
|
565 |
|
566 inline double Matrix::operator () (int r, int c) const |
|
567 { return checkelem (r, c); } |
|
568 |
|
569 inline double *Matrix::fortran_vec (void) { return data; } |
|
570 |
|
571 /* |
|
572 * Column Vector class |
|
573 */ |
|
574 |
|
575 class ColumnVector |
|
576 { |
|
577 friend class Matrix; |
|
578 friend class RowVector; |
|
579 friend class DiagMatrix; |
|
580 friend class ComplexMatrix; |
|
581 friend class ComplexColumnVector; |
|
582 friend class ComplexDiagMatrix; |
|
583 |
|
584 public: |
|
585 ColumnVector (void); |
|
586 ColumnVector (int n); |
|
587 ColumnVector (int n, double val); |
|
588 ColumnVector (const ColumnVector& a); |
|
589 ColumnVector (double a); |
|
590 ~ColumnVector (void); |
|
591 |
|
592 ColumnVector& operator = (const ColumnVector& a); |
|
593 |
|
594 int capacity (void) const; |
|
595 int length (void) const; |
|
596 |
|
597 double& elem (int n); |
|
598 double& checkelem (int n); |
|
599 double& operator () (int n); |
|
600 |
|
601 double elem (int n) const; // const access |
|
602 double checkelem (int n) const; |
|
603 double operator () (int n) const; |
|
604 |
|
605 ColumnVector& resize (int n); |
|
606 ColumnVector& resize (int n, double val); |
|
607 |
|
608 int operator == (const ColumnVector& a) const; |
|
609 int operator != (const ColumnVector& a) const; |
|
610 |
|
611 // destructive insert/delete/reorder operations |
|
612 |
|
613 ColumnVector& insert (const ColumnVector& a, int r); |
|
614 |
|
615 ColumnVector& fill (double val); |
|
616 ColumnVector& fill (double val, int r1, int r2); |
|
617 |
|
618 ColumnVector stack (const ColumnVector& a) const; |
|
619 |
|
620 RowVector transpose (void) const; |
|
621 |
|
622 // resize is the destructive equivalent for this one |
|
623 |
|
624 ColumnVector extract (int r1, int r2) const; |
|
625 |
|
626 // column vector by scalar -> column vector operations |
|
627 |
|
628 ColumnVector operator + (double s) const; |
|
629 ColumnVector operator - (double s) const; |
|
630 ColumnVector operator * (double s) const; |
|
631 ColumnVector operator / (double s) const; |
|
632 |
|
633 ComplexColumnVector operator + (Complex s) const; |
|
634 ComplexColumnVector operator - (Complex s) const; |
|
635 ComplexColumnVector operator * (Complex s) const; |
|
636 ComplexColumnVector operator / (Complex s) const; |
|
637 |
|
638 // scalar by column vector -> column vector operations |
|
639 |
|
640 friend ColumnVector operator + (double s, const ColumnVector& a); |
|
641 friend ColumnVector operator - (double s, const ColumnVector& a); |
|
642 friend ColumnVector operator * (double s, const ColumnVector& a); |
|
643 friend ColumnVector operator / (double s, const ColumnVector& a); |
|
644 |
|
645 // column vector by row vector -> matrix operations |
|
646 |
|
647 Matrix operator * (const RowVector& a) const; |
|
648 |
|
649 ComplexMatrix operator * (const ComplexRowVector& a) const; |
|
650 |
|
651 // column vector by column vector -> column vector operations |
|
652 |
|
653 ColumnVector operator + (const ColumnVector& a) const; |
|
654 ColumnVector operator - (const ColumnVector& a) const; |
|
655 |
|
656 ComplexColumnVector operator + (const ComplexColumnVector& a) const; |
|
657 ComplexColumnVector operator - (const ComplexColumnVector& a) const; |
|
658 |
|
659 ColumnVector product (const ColumnVector& a) const; // element by element |
|
660 ColumnVector quotient (const ColumnVector& a) const; // element by element |
|
661 |
|
662 ComplexColumnVector product (const ComplexColumnVector& a) const; |
|
663 ComplexColumnVector quotient (const ComplexColumnVector& a) const; |
|
664 |
|
665 ColumnVector& operator += (const ColumnVector& a); |
|
666 ColumnVector& operator -= (const ColumnVector& a); |
|
667 |
|
668 // unary operations |
|
669 |
|
670 ColumnVector operator - (void) const; |
|
671 |
|
672 friend ColumnVector map (d_d_Mapper f, const ColumnVector& a); |
|
673 void map (d_d_Mapper f); |
|
674 |
|
675 double min (void) const; |
|
676 double max (void) const; |
|
677 |
|
678 // i/o |
|
679 |
|
680 friend ostream& operator << (ostream& os, const ColumnVector& a); |
|
681 |
|
682 // conversions |
|
683 |
|
684 double *fortran_vec (void); |
|
685 |
|
686 private: |
|
687 int len; |
|
688 double *data; |
|
689 |
|
690 ColumnVector (double *d, int l); |
|
691 }; |
|
692 |
|
693 inline ColumnVector::ColumnVector (void) { len = 0; data = 0; } |
|
694 inline ColumnVector::ColumnVector (double *d, int l) { len = l; data = d; } |
|
695 inline ColumnVector::~ColumnVector (void) { delete [] data; data = 0; } |
|
696 |
|
697 inline int ColumnVector::capacity (void) const { return len; } |
|
698 inline int ColumnVector::length (void) const { return len; } |
|
699 |
|
700 inline double& ColumnVector::elem (int n) { return data[n]; } |
|
701 |
|
702 inline double& |
|
703 ColumnVector::checkelem (int n) |
|
704 { |
|
705 #ifndef NO_RANGE_CHECK |
|
706 if (n < 0 || n >= len) |
|
707 FAIL; |
|
708 #endif |
|
709 |
|
710 return elem (n); |
|
711 } |
|
712 |
|
713 inline double& ColumnVector::operator () (int n) { return checkelem (n); } |
|
714 |
|
715 inline double ColumnVector::elem (int n) const { return data[n]; } |
|
716 |
|
717 inline double |
|
718 ColumnVector::checkelem (int n) const |
|
719 { |
|
720 #ifndef NO_RANGE_CHECK |
|
721 if (n < 0 || n >= len) |
|
722 FAIL; |
|
723 #endif |
|
724 |
|
725 return elem (n); |
|
726 } |
|
727 |
|
728 inline double ColumnVector::operator () (int n) const { return checkelem (n); } |
|
729 |
|
730 inline double *ColumnVector::fortran_vec (void) { return data; } |
|
731 |
|
732 /* |
|
733 * Row Vector class |
|
734 */ |
|
735 |
|
736 class RowVector |
|
737 { |
|
738 friend class Matrix; |
|
739 friend class DiagMatrix; |
|
740 friend class ColumnVector; |
|
741 friend class ComplexMatrix; |
|
742 friend class ComplexRowVector; |
|
743 friend class ComplexDiagMatrix; |
|
744 |
|
745 public: |
|
746 RowVector (void); |
|
747 RowVector (int n); |
|
748 RowVector (int n, double val); |
|
749 RowVector (const RowVector& a); |
|
750 RowVector (double a); |
|
751 ~RowVector (void); |
|
752 |
|
753 RowVector& operator = (const RowVector& a); |
|
754 |
|
755 int capacity (void) const; |
|
756 int length (void) const; |
|
757 |
|
758 double& elem (int n); |
|
759 double& checkelem (int n); |
|
760 double& operator () (int n); |
|
761 |
|
762 double elem (int n) const; // const access |
|
763 double checkelem (int n) const; |
|
764 double operator () (int n) const; |
|
765 |
|
766 RowVector& resize (int n); |
|
767 RowVector& resize (int n, double val); |
|
768 |
|
769 int operator == (const RowVector& a) const; |
|
770 int operator != (const RowVector& a) const; |
|
771 |
|
772 // destructive insert/delete/reorder operations |
|
773 |
|
774 RowVector& insert (const RowVector& a, int c); |
|
775 |
|
776 RowVector& fill (double val); |
|
777 RowVector& fill (double val, int c1, int c2); |
|
778 |
|
779 RowVector append (const RowVector& a) const; |
|
780 |
|
781 ColumnVector transpose (void) const; |
|
782 |
|
783 // resize is the destructive equivalent for this one |
|
784 |
|
785 RowVector extract (int c1, int c2) const; |
|
786 |
|
787 // row vector by scalar -> row vector operations |
|
788 |
|
789 RowVector operator + (double s) const; |
|
790 RowVector operator - (double s) const; |
|
791 RowVector operator * (double s) const; |
|
792 RowVector operator / (double s) const; |
|
793 |
|
794 ComplexRowVector operator + (Complex s) const; |
|
795 ComplexRowVector operator - (Complex s) const; |
|
796 ComplexRowVector operator * (Complex s) const; |
|
797 ComplexRowVector operator / (Complex s) const; |
|
798 |
|
799 // scalar by row vector -> row vector operations |
|
800 |
|
801 friend RowVector operator + (double s, const RowVector& a); |
|
802 friend RowVector operator - (double s, const RowVector& a); |
|
803 friend RowVector operator * (double s, const RowVector& a); |
|
804 friend RowVector operator / (double s, const RowVector& a); |
|
805 |
|
806 // row vector by column vector -> scalar |
|
807 |
|
808 double operator * (const ColumnVector& a) const; |
|
809 |
|
810 Complex operator * (const ComplexColumnVector& a) const; |
|
811 |
|
812 // row vector by matrix -> row vector |
|
813 |
|
814 RowVector operator * (const Matrix& a) const; |
|
815 |
|
816 ComplexRowVector operator * (const ComplexMatrix& a) const; |
|
817 |
|
818 // row vector by row vector -> row vector operations |
|
819 |
|
820 RowVector operator + (const RowVector& a) const; |
|
821 RowVector operator - (const RowVector& a) const; |
|
822 |
|
823 ComplexRowVector operator + (const ComplexRowVector& a) const; |
|
824 ComplexRowVector operator - (const ComplexRowVector& a) const; |
|
825 |
|
826 RowVector product (const RowVector& a) const; // element by element |
|
827 RowVector quotient (const RowVector& a) const; // element by element |
|
828 |
|
829 ComplexRowVector product (const ComplexRowVector& a) const; // el by el |
|
830 ComplexRowVector quotient (const ComplexRowVector& a) const; // el by el |
|
831 |
|
832 RowVector& operator += (const RowVector& a); |
|
833 RowVector& operator -= (const RowVector& a); |
|
834 |
|
835 // unary operations |
|
836 |
|
837 RowVector operator - (void) const; |
|
838 |
|
839 friend RowVector map (d_d_Mapper f, const RowVector& a); |
|
840 void map (d_d_Mapper f); |
|
841 |
|
842 double min (void) const; |
|
843 double max (void) const; |
|
844 |
|
845 // i/o |
|
846 |
|
847 friend ostream& operator << (ostream& os, const RowVector& a); |
|
848 |
|
849 // conversions |
|
850 |
|
851 double *fortran_vec (void); |
|
852 |
|
853 private: |
|
854 int len; |
|
855 double *data; |
|
856 |
|
857 RowVector (double *d, int l); |
|
858 }; |
|
859 |
|
860 inline RowVector::RowVector (void) { len = 0; data = 0; } |
|
861 inline RowVector::RowVector (double *d, int l) { len = l; data = d; } |
|
862 inline RowVector::~RowVector (void) { delete [] data; data = 0; } |
|
863 |
|
864 inline int RowVector::capacity (void) const { return len; } |
|
865 inline int RowVector::length (void) const { return len; } |
|
866 |
|
867 inline double& RowVector::elem (int n) { return data[n]; } |
|
868 |
|
869 inline double& |
|
870 RowVector::checkelem (int n) |
|
871 { |
|
872 #ifndef NO_RANGE_CHECK |
|
873 if (n < 0 || n >= len) |
|
874 FAIL; |
|
875 #endif |
|
876 |
|
877 return elem (n); |
|
878 } |
|
879 |
|
880 inline double& RowVector::operator () (int n) { return checkelem (n); } |
|
881 |
|
882 inline double RowVector::elem (int n) const { return data[n]; } |
|
883 |
|
884 inline double |
|
885 RowVector::checkelem (int n) const |
|
886 { |
|
887 #ifndef NO_RANGE_CHECK |
|
888 if (n < 0 || n >= len) |
|
889 FAIL; |
|
890 #endif |
|
891 |
|
892 return elem (n); |
|
893 } |
|
894 |
|
895 inline double RowVector::operator () (int n) const { return checkelem (n); } |
|
896 |
|
897 inline double *RowVector::fortran_vec (void) { return data; } |
|
898 |
|
899 /* |
|
900 * Diagonal Matrix class |
|
901 */ |
|
902 |
|
903 class DiagMatrix |
|
904 { |
|
905 friend class Matrix; |
|
906 friend class ComplexMatrix; |
|
907 friend class ComplexDiagMatrix; |
|
908 |
|
909 public: |
|
910 DiagMatrix (void); |
|
911 DiagMatrix (int n); |
|
912 DiagMatrix (int n, double val); |
|
913 DiagMatrix (int r, int c); |
|
914 DiagMatrix (int r, int c, double val); |
|
915 DiagMatrix (const RowVector& a); |
|
916 DiagMatrix (const ColumnVector& a); |
|
917 DiagMatrix (const DiagMatrix& a); |
|
918 DiagMatrix (double a); |
|
919 ~DiagMatrix (void); |
|
920 |
|
921 DiagMatrix& operator = (const DiagMatrix& a); |
|
922 |
|
923 int rows (void) const; |
|
924 int cols (void) const; |
|
925 int columns (void) const; |
|
926 |
|
927 double& elem (int r, int c); |
|
928 double& checkelem (int r, int c); |
|
929 double& operator () (int r, int c); |
|
930 |
|
931 double elem (int r, int c) const; // const access |
|
932 double checkelem (int r, int c) const; |
|
933 double operator () (int r, int c) const; |
|
934 |
|
935 DiagMatrix& resize (int r, int c); |
|
936 DiagMatrix& resize (int r, int c, double val); |
|
937 |
|
938 int operator == (const DiagMatrix& a) const; |
|
939 int operator != (const DiagMatrix& a) const; |
|
940 |
|
941 DiagMatrix& fill (double val); |
|
942 DiagMatrix& fill (double val, int beg, int end); |
|
943 DiagMatrix& fill (const ColumnVector& a); |
|
944 DiagMatrix& fill (const RowVector& a); |
|
945 DiagMatrix& fill (const ColumnVector& a, int beg); |
|
946 DiagMatrix& fill (const RowVector& a, int beg); |
|
947 |
|
948 DiagMatrix transpose (void) const; |
|
949 |
|
950 // resize is the destructive analog for this one |
|
951 |
|
952 Matrix extract (int r1, int c1, int r2, int c2) const; |
|
953 |
|
954 // extract row or column i. |
|
955 |
|
956 RowVector row (int i) const; |
|
957 RowVector row (char *s) const; |
|
958 |
|
959 ColumnVector column (int i) const; |
|
960 ColumnVector column (char *s) const; |
|
961 |
|
962 DiagMatrix inverse (int& info) const; |
|
963 DiagMatrix inverse (void) const; |
|
964 |
|
965 // diagonal matrix by scalar -> matrix operations |
|
966 |
|
967 Matrix operator + (double s) const; |
|
968 Matrix operator - (double s) const; |
|
969 |
|
970 ComplexMatrix operator + (Complex s) const; |
|
971 ComplexMatrix operator - (Complex s) const; |
|
972 |
|
973 // diagonal matrix by scalar -> diagonal matrix operations |
|
974 |
|
975 DiagMatrix operator * (double s) const; |
|
976 DiagMatrix operator / (double s) const; |
|
977 |
|
978 ComplexDiagMatrix operator * (Complex s) const; |
|
979 ComplexDiagMatrix operator / (Complex s) const; |
|
980 |
|
981 // scalar by diagonal matrix -> matrix operations |
|
982 |
|
983 friend Matrix operator + (double s, const DiagMatrix& a); |
|
984 friend Matrix operator - (double s, const DiagMatrix& a); |
|
985 |
|
986 // scalar by diagonal matrix -> diagonal matrix operations |
|
987 |
|
988 friend DiagMatrix operator * (double s, const DiagMatrix& a); |
|
989 friend DiagMatrix operator / (double s, const DiagMatrix& a); |
|
990 |
|
991 // diagonal matrix by column vector -> column vector operations |
|
992 |
|
993 ColumnVector operator * (const ColumnVector& a) const; |
|
994 |
|
995 ComplexColumnVector operator * (const ComplexColumnVector& a) const; |
|
996 |
|
997 // diagonal matrix by diagonal matrix -> diagonal matrix operations |
|
998 |
|
999 DiagMatrix operator + (const DiagMatrix& a) const; |
|
1000 DiagMatrix operator - (const DiagMatrix& a) const; |
|
1001 DiagMatrix operator * (const DiagMatrix& a) const; |
|
1002 |
|
1003 ComplexDiagMatrix operator + (const ComplexDiagMatrix& a) const; |
|
1004 ComplexDiagMatrix operator - (const ComplexDiagMatrix& a) const; |
|
1005 ComplexDiagMatrix operator * (const ComplexDiagMatrix& a) const; |
|
1006 |
|
1007 DiagMatrix product (const DiagMatrix& a) const; // element by element |
|
1008 DiagMatrix quotient (const DiagMatrix& a) const; // element by element |
|
1009 |
|
1010 ComplexDiagMatrix product (const ComplexDiagMatrix& a) const; // el by el |
|
1011 ComplexDiagMatrix quotient (const ComplexDiagMatrix& a) const; // el by el |
|
1012 |
|
1013 DiagMatrix& operator += (const DiagMatrix& a); |
|
1014 DiagMatrix& operator -= (const DiagMatrix& a); |
|
1015 |
|
1016 // diagonal matrix by matrix -> matrix operations |
|
1017 |
|
1018 Matrix operator + (const Matrix& a) const; |
|
1019 Matrix operator - (const Matrix& a) const; |
|
1020 Matrix operator * (const Matrix& a) const; |
|
1021 |
|
1022 ComplexMatrix operator + (const ComplexMatrix& a) const; |
|
1023 ComplexMatrix operator - (const ComplexMatrix& a) const; |
|
1024 ComplexMatrix operator * (const ComplexMatrix& a) const; |
|
1025 |
|
1026 // unary operations |
|
1027 |
|
1028 DiagMatrix operator - (void) const; |
|
1029 |
|
1030 ColumnVector diag (void) const; |
|
1031 ColumnVector diag (int k) const; |
|
1032 |
|
1033 // i/o |
|
1034 |
|
1035 friend ostream& operator << (ostream& os, const DiagMatrix& a); |
|
1036 |
|
1037 private: |
|
1038 int nr; |
|
1039 int nc; |
|
1040 int len; |
|
1041 double *data; |
|
1042 |
|
1043 DiagMatrix (double *d, int nr, int nc); |
|
1044 }; |
|
1045 |
|
1046 inline DiagMatrix::DiagMatrix (void) |
|
1047 { nr = 0; nc = 0; len = 0; data = 0; } |
|
1048 |
|
1049 inline DiagMatrix::DiagMatrix (double *d, int r, int c) |
|
1050 { nr = r; nc = c; len = nr < nc ? nr : nc; data = d; } |
|
1051 |
|
1052 inline DiagMatrix::~DiagMatrix (void) { delete [] data; data = 0; } |
|
1053 |
|
1054 inline int DiagMatrix::rows (void) const { return len; } |
|
1055 inline int DiagMatrix::cols (void) const { return len; } |
|
1056 inline int DiagMatrix::columns (void) const { return len; } |
|
1057 |
|
1058 // Would be nice to be able to avoid compiler warning and make this |
|
1059 // fail on assignment. |
|
1060 inline double& DiagMatrix::elem (int r, int c) |
|
1061 { return (r == c) ? data[r] : 0; } |
|
1062 |
|
1063 inline double& DiagMatrix::checkelem (int r, int c) |
|
1064 { |
|
1065 #ifndef NO_RANGE_CHECK |
|
1066 if (r < 0 || r >= nr || c < 0 || c >= nc) |
|
1067 FAIL; |
|
1068 #endif |
|
1069 |
|
1070 return elem (r, c); |
|
1071 } |
|
1072 |
|
1073 inline double& DiagMatrix::operator () (int r, int c) |
|
1074 { return checkelem (r, c); } |
|
1075 |
|
1076 inline double DiagMatrix::elem (int r, int c) const |
|
1077 { return (r == c) ? data[r] : 0; } |
|
1078 |
|
1079 inline double DiagMatrix::checkelem (int r, int c) const |
|
1080 { |
|
1081 #ifndef NO_RANGE_CHECK |
|
1082 if (r < 0 || r >= nr || c < 0 || c >= nc) |
|
1083 FAIL; |
|
1084 #endif |
|
1085 |
|
1086 return elem (r, c); |
|
1087 } |
|
1088 |
|
1089 inline double DiagMatrix::operator () (int r, int c) const |
|
1090 { return checkelem (r, c); } |
|
1091 |
|
1092 /* |
|
1093 * Complex Matrix class |
|
1094 */ |
|
1095 |
|
1096 class ComplexMatrix |
|
1097 { |
|
1098 friend class Matrix; |
|
1099 friend class DiagMatrix; |
|
1100 friend class ComplexRowVector; |
|
1101 friend class ComplexDiagMatrix; |
21
|
1102 friend class ComplexAEPBALANCE; |
3
|
1103 friend class EIG; |
|
1104 friend class ComplexHESS; |
|
1105 friend class ComplexSVD; |
|
1106 friend class ComplexSCHUR; |
|
1107 friend class ComplexLU; |
|
1108 friend class ComplexQR; |
|
1109 |
|
1110 public: |
|
1111 ComplexMatrix (void); |
|
1112 ComplexMatrix (int r, int c); |
|
1113 ComplexMatrix (int r, int c, double val); |
|
1114 ComplexMatrix (int r, int c, Complex val); |
|
1115 ComplexMatrix (const Matrix& a); |
|
1116 ComplexMatrix (const ComplexMatrix& a); |
|
1117 ComplexMatrix (const DiagMatrix& a); |
|
1118 ComplexMatrix (const ComplexDiagMatrix& a); |
|
1119 ComplexMatrix (double a); |
|
1120 ComplexMatrix (Complex a); |
|
1121 ~ComplexMatrix (void); |
|
1122 |
|
1123 ComplexMatrix& operator = (const Matrix& a); |
|
1124 ComplexMatrix& operator = (const ComplexMatrix& a); |
|
1125 |
|
1126 int rows (void) const; |
|
1127 int cols (void) const; |
|
1128 int columns (void) const; |
|
1129 |
|
1130 Complex& elem (int r, int c); |
|
1131 Complex& checkelem (int r, int c); |
|
1132 Complex& operator () (int r, int c); |
|
1133 |
|
1134 Complex elem (int r, int c) const; // const access |
|
1135 Complex checkelem (int r, int c) const; |
|
1136 Complex operator () (int r, int c) const; |
|
1137 |
|
1138 ComplexMatrix& resize (int r, int c); |
|
1139 ComplexMatrix& resize (int r, int c, double val); |
|
1140 ComplexMatrix& resize (int r, int c, Complex val); |
|
1141 |
|
1142 int operator == (const ComplexMatrix& a) const; |
|
1143 int operator != (const ComplexMatrix& a) const; |
|
1144 |
|
1145 // destructive insert/delete/reorder operations |
|
1146 |
|
1147 ComplexMatrix& insert (const Matrix& a, int r, int c); |
|
1148 ComplexMatrix& insert (const RowVector& a, int r, int c); |
|
1149 ComplexMatrix& insert (const ColumnVector& a, int r, int c); |
|
1150 ComplexMatrix& insert (const DiagMatrix& a, int r, int c); |
|
1151 |
|
1152 ComplexMatrix& insert (const ComplexMatrix& a, int r, int c); |
|
1153 ComplexMatrix& insert (const ComplexRowVector& a, int r, int c); |
|
1154 ComplexMatrix& insert (const ComplexColumnVector& a, int r, int c); |
|
1155 ComplexMatrix& insert (const ComplexDiagMatrix& a, int r, int c); |
|
1156 |
|
1157 ComplexMatrix& fill (double val); |
|
1158 ComplexMatrix& fill (Complex val); |
|
1159 ComplexMatrix& fill (double val, int r1, int c1, int r2, int c2); |
|
1160 ComplexMatrix& fill (Complex val, int r1, int c1, int r2, int c2); |
|
1161 |
|
1162 ComplexMatrix append (const Matrix& a) const; |
|
1163 ComplexMatrix append (const RowVector& a) const; |
|
1164 ComplexMatrix append (const ColumnVector& a) const; |
|
1165 ComplexMatrix append (const DiagMatrix& a) const; |
|
1166 |
|
1167 ComplexMatrix append (const ComplexMatrix& a) const; |
|
1168 ComplexMatrix append (const ComplexRowVector& a) const; |
|
1169 ComplexMatrix append (const ComplexColumnVector& a) const; |
|
1170 ComplexMatrix append (const ComplexDiagMatrix& a) const; |
|
1171 |
|
1172 ComplexMatrix stack (const Matrix& a) const; |
|
1173 ComplexMatrix stack (const RowVector& a) const; |
|
1174 ComplexMatrix stack (const ColumnVector& a) const; |
|
1175 ComplexMatrix stack (const DiagMatrix& a) const; |
|
1176 |
|
1177 ComplexMatrix stack (const ComplexMatrix& a) const; |
|
1178 ComplexMatrix stack (const ComplexRowVector& a) const; |
|
1179 ComplexMatrix stack (const ComplexColumnVector& a) const; |
|
1180 ComplexMatrix stack (const ComplexDiagMatrix& a) const; |
|
1181 |
|
1182 ComplexMatrix hermitian (void) const; // complex conjugate transpose |
|
1183 ComplexMatrix transpose (void) const; |
|
1184 |
|
1185 friend Matrix real (const ComplexMatrix& a); |
|
1186 friend Matrix imag (const ComplexMatrix& a); |
|
1187 friend ComplexMatrix conj (const ComplexMatrix& a); |
|
1188 |
|
1189 // resize is the destructive equivalent for this one |
|
1190 |
|
1191 ComplexMatrix extract (int r1, int c1, int r2, int c2) const; |
|
1192 |
|
1193 // extract row or column i. |
|
1194 |
|
1195 ComplexRowVector row (int i) const; |
|
1196 ComplexRowVector row (char *s) const; |
|
1197 |
|
1198 ComplexColumnVector column (int i) const; |
|
1199 ComplexColumnVector column (char *s) const; |
|
1200 |
|
1201 ComplexMatrix inverse (int& info, double& rcond) const; |
|
1202 ComplexMatrix inverse (int& info) const; |
|
1203 ComplexMatrix inverse (void) const; |
|
1204 |
|
1205 ComplexMatrix fourier (void) const; |
|
1206 ComplexMatrix ifourier (void) const; |
|
1207 |
|
1208 ComplexDET determinant (void) const; |
|
1209 ComplexDET determinant (int& info) const; |
|
1210 ComplexDET determinant (int& info, double& rcond) const; |
|
1211 |
|
1212 ComplexMatrix solve (const Matrix& b) const; |
|
1213 ComplexMatrix solve (const Matrix& b, int& info) const; |
|
1214 ComplexMatrix solve (const Matrix& b, int& info, double& rcond) const; |
|
1215 |
|
1216 ComplexMatrix solve (const ComplexMatrix& b) const; |
|
1217 ComplexMatrix solve (const ComplexMatrix& b, int& info) const; |
|
1218 ComplexMatrix solve (const ComplexMatrix& b, int& info, double& rcond) const; |
|
1219 |
|
1220 ComplexColumnVector solve (const ColumnVector& b) const; |
|
1221 ComplexColumnVector solve (const ColumnVector& b, int& info) const; |
|
1222 ComplexColumnVector solve (const ColumnVector& b, int& info, |
|
1223 double& rcond) const; |
|
1224 |
|
1225 ComplexColumnVector solve (const ComplexColumnVector& b) const; |
|
1226 ComplexColumnVector solve (const ComplexColumnVector& b, int& info) const; |
|
1227 ComplexColumnVector solve (const ComplexColumnVector& b, int& info, |
|
1228 double& rcond) const; |
|
1229 |
|
1230 ComplexMatrix lssolve (const Matrix& b) const; |
|
1231 ComplexMatrix lssolve (const Matrix& b, int& info) const; |
|
1232 ComplexMatrix lssolve (const Matrix& b, int& info, int& rank) const; |
|
1233 |
|
1234 ComplexMatrix lssolve (const ComplexMatrix& b) const; |
|
1235 ComplexMatrix lssolve (const ComplexMatrix& b, int& info) const; |
|
1236 ComplexMatrix lssolve (const ComplexMatrix& b, int& info, |
|
1237 int& rank) const; |
|
1238 |
|
1239 ComplexColumnVector lssolve (const ColumnVector& b) const; |
|
1240 ComplexColumnVector lssolve (const ColumnVector& b, int& info) const; |
|
1241 ComplexColumnVector lssolve (const ColumnVector& b, int& info, |
|
1242 int& rank) const; |
|
1243 |
|
1244 ComplexColumnVector lssolve (const ComplexColumnVector& b) const; |
|
1245 ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info) const; |
|
1246 ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info, |
|
1247 int& rank) const; |
|
1248 |
|
1249 // matrix by scalar -> matrix operations |
|
1250 |
|
1251 ComplexMatrix operator + (double s) const; |
|
1252 ComplexMatrix operator - (double s) const; |
|
1253 ComplexMatrix operator * (double s) const; |
|
1254 ComplexMatrix operator / (double s) const; |
|
1255 |
|
1256 ComplexMatrix operator + (Complex s) const; |
|
1257 ComplexMatrix operator - (Complex s) const; |
|
1258 ComplexMatrix operator * (Complex s) const; |
|
1259 ComplexMatrix operator / (Complex s) const; |
|
1260 |
|
1261 // scalar by matrix -> matrix operations |
|
1262 |
|
1263 friend ComplexMatrix operator + (double s, const ComplexMatrix& a); |
|
1264 friend ComplexMatrix operator - (double s, const ComplexMatrix& a); |
|
1265 friend ComplexMatrix operator * (double s, const ComplexMatrix& a); |
|
1266 friend ComplexMatrix operator / (double s, const ComplexMatrix& a); |
|
1267 |
|
1268 friend ComplexMatrix operator + (Complex s, const ComplexMatrix& a); |
|
1269 friend ComplexMatrix operator - (Complex s, const ComplexMatrix& a); |
|
1270 friend ComplexMatrix operator * (Complex s, const ComplexMatrix& a); |
|
1271 friend ComplexMatrix operator / (Complex s, const ComplexMatrix& a); |
|
1272 |
|
1273 // matrix by column vector -> column vector operations |
|
1274 |
|
1275 ComplexColumnVector operator * (const ColumnVector& a) const; |
|
1276 |
|
1277 ComplexColumnVector operator * (const ComplexColumnVector& a) const; |
|
1278 |
|
1279 // matrix by diagonal matrix -> matrix operations |
|
1280 |
|
1281 ComplexMatrix operator + (const DiagMatrix& a) const; |
|
1282 ComplexMatrix operator - (const DiagMatrix& a) const; |
|
1283 ComplexMatrix operator * (const DiagMatrix& a) const; |
|
1284 |
|
1285 ComplexMatrix operator + (const ComplexDiagMatrix& a) const; |
|
1286 ComplexMatrix operator - (const ComplexDiagMatrix& a) const; |
|
1287 ComplexMatrix operator * (const ComplexDiagMatrix& a) const; |
|
1288 |
|
1289 ComplexMatrix& operator += (const DiagMatrix& a); |
|
1290 ComplexMatrix& operator -= (const DiagMatrix& a); |
|
1291 |
|
1292 ComplexMatrix& operator += (const ComplexDiagMatrix& a); |
|
1293 ComplexMatrix& operator -= (const ComplexDiagMatrix& a); |
|
1294 |
|
1295 // matrix by matrix -> matrix operations |
|
1296 |
|
1297 ComplexMatrix operator + (const Matrix& a) const; |
|
1298 ComplexMatrix operator - (const Matrix& a) const; |
|
1299 ComplexMatrix operator * (const Matrix& a) const; |
|
1300 |
|
1301 ComplexMatrix operator + (const ComplexMatrix& a) const; |
|
1302 ComplexMatrix operator - (const ComplexMatrix& a) const; |
|
1303 ComplexMatrix operator * (const ComplexMatrix& a) const; |
|
1304 |
|
1305 ComplexMatrix product (const Matrix& a) const; // element by element |
|
1306 ComplexMatrix quotient (const Matrix& a) const; // element by element |
|
1307 |
|
1308 ComplexMatrix product (const ComplexMatrix& a) const; // element by element |
|
1309 ComplexMatrix quotient (const ComplexMatrix& a) const; // element by element |
|
1310 |
|
1311 ComplexMatrix& operator += (const Matrix& a); |
|
1312 ComplexMatrix& operator -= (const Matrix& a); |
|
1313 |
|
1314 ComplexMatrix& operator += (const ComplexMatrix& a); |
|
1315 ComplexMatrix& operator -= (const ComplexMatrix& a); |
|
1316 |
|
1317 // unary operations |
|
1318 |
|
1319 ComplexMatrix operator - (void) const; |
|
1320 Matrix operator ! (void) const; |
|
1321 |
|
1322 // other operations |
|
1323 |
|
1324 friend ComplexMatrix map (c_c_Mapper f, const ComplexMatrix& a); |
|
1325 friend Matrix map (d_c_Mapper f, const ComplexMatrix& a); |
|
1326 void map (c_c_Mapper f); |
|
1327 |
|
1328 Matrix all (void) const; |
|
1329 Matrix any (void) const; |
|
1330 |
|
1331 ComplexMatrix cumprod (void) const; |
|
1332 ComplexMatrix cumsum (void) const; |
|
1333 ComplexMatrix prod (void) const; |
|
1334 ComplexMatrix sum (void) const; |
|
1335 ComplexMatrix sumsq (void) const; |
|
1336 |
|
1337 ComplexColumnVector diag (void) const; |
|
1338 ComplexColumnVector diag (int k) const; |
|
1339 |
|
1340 ComplexColumnVector row_min (void) const; |
|
1341 ComplexColumnVector row_max (void) const; |
|
1342 |
|
1343 ComplexRowVector column_min (void) const; |
|
1344 ComplexRowVector column_max (void) const; |
|
1345 |
|
1346 // i/o |
|
1347 |
|
1348 friend ostream& operator << (ostream& os, const ComplexMatrix& a); |
|
1349 friend istream& operator >> (istream& is, ComplexMatrix& a); |
|
1350 |
|
1351 // conversions |
|
1352 |
|
1353 Complex *fortran_vec (void); |
|
1354 |
|
1355 private: |
|
1356 int nr; |
|
1357 int nc; |
|
1358 int len; |
|
1359 Complex *data; |
|
1360 |
|
1361 ComplexMatrix (Complex *d, int r, int c); |
|
1362 }; |
|
1363 |
|
1364 inline ComplexMatrix::ComplexMatrix (void) |
|
1365 { nr = 0; nc = 0; len = 0; data = 0; } |
|
1366 |
|
1367 inline ComplexMatrix::ComplexMatrix (Complex *d, int r, int c) |
|
1368 { nr = r; nc = c; len = nr*nc; data = d; } |
|
1369 |
|
1370 inline ComplexMatrix::~ComplexMatrix (void) { delete [] data; data = 0; } |
|
1371 |
|
1372 inline int ComplexMatrix::rows (void) const { return nr; } |
|
1373 inline int ComplexMatrix::cols (void) const { return nc; } |
|
1374 inline int ComplexMatrix::columns (void) const { return nc; } |
|
1375 |
|
1376 inline Complex& ComplexMatrix::elem (int r, int c) { return data[nr*c+r]; } |
|
1377 |
|
1378 inline Complex& ComplexMatrix::checkelem (int r, int c) |
|
1379 { |
|
1380 #ifndef NO_RANGE_CHECK |
|
1381 if (r < 0 || r >= nr || c < 0 || c >= nc) |
|
1382 FAIL; |
|
1383 #endif |
|
1384 |
|
1385 return elem (r, c); |
|
1386 } |
|
1387 |
|
1388 inline Complex& ComplexMatrix::operator () (int r, int c) |
|
1389 { return checkelem (r, c); } |
|
1390 |
|
1391 inline Complex ComplexMatrix::elem (int r, int c) const |
|
1392 { return data[nr*c+r]; } |
|
1393 |
|
1394 inline Complex ComplexMatrix::checkelem (int r, int c) const |
|
1395 { |
|
1396 #ifndef NO_RANGE_CHECK |
|
1397 if (r < 0 || r >= nr || c < 0 || c >= nc) |
|
1398 FAIL; |
|
1399 #endif |
|
1400 |
|
1401 return elem (r, c); |
|
1402 } |
|
1403 |
|
1404 inline Complex ComplexMatrix::operator () (int r, int c) const |
|
1405 { return checkelem (r, c); } |
|
1406 |
|
1407 inline Complex *ComplexMatrix::fortran_vec (void) { return data; } |
|
1408 |
|
1409 /* |
|
1410 * Complex Column Vector class |
|
1411 */ |
|
1412 |
|
1413 class ComplexColumnVector |
|
1414 { |
|
1415 friend class DiagMatrix; |
|
1416 friend class ComplexMatrix; |
|
1417 friend class ColumnVector; |
|
1418 friend class ComplexDiagMatrix; |
|
1419 |
|
1420 public: |
|
1421 ComplexColumnVector (void); |
|
1422 ComplexColumnVector (int n); |
|
1423 ComplexColumnVector (int n, double val); |
|
1424 ComplexColumnVector (int n, Complex val); |
|
1425 ComplexColumnVector (const ColumnVector& a); |
|
1426 ComplexColumnVector (const ComplexColumnVector& a); |
|
1427 ComplexColumnVector (double a); |
|
1428 ComplexColumnVector (Complex a); |
|
1429 ~ComplexColumnVector (void); |
|
1430 |
|
1431 ComplexColumnVector& operator = (const ColumnVector& a); |
|
1432 ComplexColumnVector& operator = (const ComplexColumnVector& a); |
|
1433 |
|
1434 int capacity (void) const; |
|
1435 int length (void) const; |
|
1436 |
|
1437 Complex& elem (int n); |
|
1438 Complex& checkelem (int n); |
|
1439 Complex& operator () (int n); |
|
1440 |
|
1441 Complex elem (int n) const; // const access |
|
1442 Complex checkelem (int n) const; |
|
1443 Complex operator () (int n) const; |
|
1444 |
|
1445 ComplexColumnVector& resize (int n); |
|
1446 ComplexColumnVector& resize (int n, double val); |
|
1447 ComplexColumnVector& resize (int n, Complex val); |
|
1448 |
|
1449 int operator == (const ComplexColumnVector& a) const; |
|
1450 int operator != (const ComplexColumnVector& a) const; |
|
1451 |
|
1452 // destructive insert/delete/reorder operations |
|
1453 |
|
1454 ComplexColumnVector& insert (const ColumnVector& a, int r); |
|
1455 ComplexColumnVector& insert (const ComplexColumnVector& a, int r); |
|
1456 |
|
1457 ComplexColumnVector& fill (double val); |
|
1458 ComplexColumnVector& fill (Complex val); |
|
1459 ComplexColumnVector& fill (double val, int r1, int r2); |
|
1460 ComplexColumnVector& fill (Complex val, int r1, int r2); |
|
1461 |
|
1462 ComplexColumnVector stack (const ColumnVector& a) const; |
|
1463 ComplexColumnVector stack (const ComplexColumnVector& a) const; |
|
1464 |
|
1465 ComplexRowVector hermitian (void) const; // complex conjugate transpose. |
|
1466 ComplexRowVector transpose (void) const; |
|
1467 |
|
1468 friend ColumnVector real (const ComplexColumnVector& a); |
|
1469 friend ColumnVector imag (const ComplexColumnVector& a); |
|
1470 friend ComplexColumnVector conj (const ComplexColumnVector& a); |
|
1471 |
|
1472 // resize is the destructive equivalent for this one |
|
1473 |
|
1474 ComplexColumnVector extract (int r1, int r2) const; |
|
1475 |
|
1476 // column vector by scalar -> column vector operations |
|
1477 |
|
1478 ComplexColumnVector operator + (double s) const; |
|
1479 ComplexColumnVector operator - (double s) const; |
|
1480 ComplexColumnVector operator * (double s) const; |
|
1481 ComplexColumnVector operator / (double s) const; |
|
1482 |
|
1483 ComplexColumnVector operator + (Complex s) const; |
|
1484 ComplexColumnVector operator - (Complex s) const; |
|
1485 ComplexColumnVector operator * (Complex s) const; |
|
1486 ComplexColumnVector operator / (Complex s) const; |
|
1487 |
|
1488 // scalar by column vector -> column vector operations |
|
1489 |
|
1490 friend ComplexColumnVector operator + (double s, |
|
1491 const ComplexColumnVector& a); |
|
1492 friend ComplexColumnVector operator - (double s, |
|
1493 const ComplexColumnVector& a); |
|
1494 friend ComplexColumnVector operator * (double s, |
|
1495 const ComplexColumnVector& a); |
|
1496 friend ComplexColumnVector operator / (double s, |
|
1497 const ComplexColumnVector& a); |
|
1498 |
|
1499 friend ComplexColumnVector operator + (Complex s, |
|
1500 const ComplexColumnVector& a); |
|
1501 friend ComplexColumnVector operator - (Complex s, |
|
1502 const ComplexColumnVector& a); |
|
1503 friend ComplexColumnVector operator * (Complex s, |
|
1504 const ComplexColumnVector& a); |
|
1505 friend ComplexColumnVector operator / (Complex s, |
|
1506 const ComplexColumnVector& a); |
|
1507 |
|
1508 // column vector by row vector -> matrix operations |
|
1509 |
|
1510 ComplexMatrix operator * (const RowVector& a) const; |
|
1511 |
|
1512 ComplexMatrix operator * (const ComplexRowVector& a) const; |
|
1513 |
|
1514 // column vector by column vector -> column vector operations |
|
1515 |
|
1516 ComplexColumnVector operator + (const ColumnVector& a) const; |
|
1517 ComplexColumnVector operator - (const ColumnVector& a) const; |
|
1518 |
|
1519 ComplexColumnVector operator + (const ComplexColumnVector& a) const; |
|
1520 ComplexColumnVector operator - (const ComplexColumnVector& a) const; |
|
1521 |
|
1522 ComplexColumnVector product (const ColumnVector& a) const; // el by el |
|
1523 ComplexColumnVector quotient (const ColumnVector& a) const; // el by el |
|
1524 |
|
1525 ComplexColumnVector product (const ComplexColumnVector& a) const; |
|
1526 ComplexColumnVector quotient (const ComplexColumnVector& a) const; |
|
1527 |
|
1528 ComplexColumnVector& operator += (const ColumnVector& a); |
|
1529 ComplexColumnVector& operator -= (const ColumnVector& a); |
|
1530 |
|
1531 ComplexColumnVector& operator += (const ComplexColumnVector& a); |
|
1532 ComplexColumnVector& operator -= (const ComplexColumnVector& a); |
|
1533 |
|
1534 // unary operations |
|
1535 |
|
1536 ComplexColumnVector operator - (void) const; |
|
1537 |
|
1538 friend ComplexColumnVector map (c_c_Mapper f, const ComplexColumnVector& a); |
|
1539 friend ColumnVector map (d_c_Mapper f, const ComplexColumnVector& a); |
|
1540 void map (c_c_Mapper f); |
|
1541 |
|
1542 Complex min (void) const; |
|
1543 Complex max (void) const; |
|
1544 |
|
1545 // i/o |
|
1546 |
|
1547 friend ostream& operator << (ostream& os, const ComplexColumnVector& a); |
|
1548 |
|
1549 // conversions |
|
1550 |
|
1551 Complex *fortran_vec (void); |
|
1552 |
|
1553 private: |
|
1554 int len; |
|
1555 Complex *data; |
|
1556 |
|
1557 ComplexColumnVector (Complex *d, int l); |
|
1558 }; |
|
1559 |
|
1560 inline ComplexColumnVector::ComplexColumnVector (void) { len = 0; data = 0; } |
|
1561 inline ComplexColumnVector::ComplexColumnVector (Complex *d, int l) |
|
1562 { len = l; data = d; } |
|
1563 inline ComplexColumnVector::~ComplexColumnVector (void) |
|
1564 { delete [] data; data = 0; } |
|
1565 |
|
1566 inline int ComplexColumnVector::capacity (void) const { return len; } |
|
1567 inline int ComplexColumnVector::length (void) const { return len; } |
|
1568 |
|
1569 inline Complex& ComplexColumnVector::elem (int n) { return data[n]; } |
|
1570 |
|
1571 inline Complex& |
|
1572 ComplexColumnVector::checkelem (int n) |
|
1573 { |
|
1574 #ifndef NO_RANGE_CHECK |
|
1575 if (n < 0 || n >= len) |
|
1576 FAIL; |
|
1577 #endif |
|
1578 |
|
1579 return elem (n); |
|
1580 } |
|
1581 |
|
1582 inline Complex& ComplexColumnVector::operator () (int n) |
|
1583 { return checkelem (n); } |
|
1584 |
|
1585 inline Complex ComplexColumnVector::elem (int n) const { return data[n]; } |
|
1586 |
|
1587 inline Complex |
|
1588 ComplexColumnVector::checkelem (int n) const |
|
1589 { |
|
1590 #ifndef NO_RANGE_CHECK |
|
1591 if (n < 0 || n >= len) |
|
1592 FAIL; |
|
1593 #endif |
|
1594 |
|
1595 return elem (n); |
|
1596 } |
|
1597 |
|
1598 inline Complex ComplexColumnVector::operator () (int n) const |
|
1599 { return checkelem (n); } |
|
1600 |
|
1601 inline Complex *ComplexColumnVector::fortran_vec (void) { return data; } |
|
1602 |
|
1603 /* |
|
1604 * Complex Row Vector class |
|
1605 */ |
|
1606 |
|
1607 class ComplexRowVector |
|
1608 { |
|
1609 friend class RowVector; |
|
1610 friend class ComplexMatrix; |
|
1611 friend class ComplexColumnVector; |
|
1612 friend class ComplexDiagMatrix; |
|
1613 |
|
1614 public: |
|
1615 ComplexRowVector (void); |
|
1616 ComplexRowVector (int n); |
|
1617 ComplexRowVector (int n, double val); |
|
1618 ComplexRowVector (int n, Complex val); |
|
1619 ComplexRowVector (const RowVector& a); |
|
1620 ComplexRowVector (const ComplexRowVector& a); |
|
1621 ComplexRowVector (double a); |
|
1622 ComplexRowVector (Complex a); |
|
1623 ~ComplexRowVector (void); |
|
1624 |
|
1625 ComplexRowVector& operator = (const RowVector& a); |
|
1626 ComplexRowVector& operator = (const ComplexRowVector& a); |
|
1627 |
|
1628 int capacity (void) const; |
|
1629 int length (void) const; |
|
1630 |
|
1631 Complex& checkelem (int n); |
|
1632 Complex& elem (int n); |
|
1633 Complex& operator () (int n); |
|
1634 |
|
1635 Complex checkelem (int n) const; // const access |
|
1636 Complex elem (int n) const; |
|
1637 Complex operator () (int n) const; |
|
1638 |
|
1639 ComplexRowVector& resize (int n); |
|
1640 ComplexRowVector& resize (int n, double val); |
|
1641 ComplexRowVector& resize (int n, Complex val); |
|
1642 |
|
1643 int operator == (const ComplexRowVector& a) const; |
|
1644 int operator != (const ComplexRowVector& a) const; |
|
1645 |
|
1646 // destructive insert/delete/reorder operations |
|
1647 |
|
1648 ComplexRowVector& insert (const RowVector& a, int c); |
|
1649 ComplexRowVector& insert (const ComplexRowVector& a, int c); |
|
1650 |
|
1651 ComplexRowVector& fill (double val); |
|
1652 ComplexRowVector& fill (Complex val); |
|
1653 ComplexRowVector& fill (double val, int c1, int c2); |
|
1654 ComplexRowVector& fill (Complex val, int c1, int c2); |
|
1655 |
|
1656 ComplexRowVector append (const RowVector& a) const; |
|
1657 ComplexRowVector append (const ComplexRowVector& a) const; |
|
1658 |
|
1659 ComplexColumnVector hermitian (void) const; // complex conjugate transpose. |
|
1660 ComplexColumnVector transpose (void) const; |
|
1661 |
|
1662 friend RowVector real (const ComplexRowVector& a); |
|
1663 friend RowVector imag (const ComplexRowVector& a); |
|
1664 friend ComplexRowVector conj (const ComplexRowVector& a); |
|
1665 |
|
1666 // resize is the destructive equivalent for this one |
|
1667 |
|
1668 ComplexRowVector extract (int c1, int c2) const; |
|
1669 |
|
1670 // row vector by scalar -> row vector operations |
|
1671 |
|
1672 ComplexRowVector operator + (double s) const; |
|
1673 ComplexRowVector operator - (double s) const; |
|
1674 ComplexRowVector operator * (double s) const; |
|
1675 ComplexRowVector operator / (double s) const; |
|
1676 |
|
1677 ComplexRowVector operator + (Complex s) const; |
|
1678 ComplexRowVector operator - (Complex s) const; |
|
1679 ComplexRowVector operator * (Complex s) const; |
|
1680 ComplexRowVector operator / (Complex s) const; |
|
1681 |
|
1682 // scalar by row vector -> row vector operations |
|
1683 |
|
1684 friend ComplexRowVector operator + (double s, const ComplexRowVector& a); |
|
1685 friend ComplexRowVector operator - (double s, const ComplexRowVector& a); |
|
1686 friend ComplexRowVector operator * (double s, const ComplexRowVector& a); |
|
1687 friend ComplexRowVector operator / (double s, const ComplexRowVector& a); |
|
1688 |
|
1689 friend ComplexRowVector operator + (Complex s, const ComplexRowVector& a); |
|
1690 friend ComplexRowVector operator - (Complex s, const ComplexRowVector& a); |
|
1691 friend ComplexRowVector operator * (Complex s, const ComplexRowVector& a); |
|
1692 friend ComplexRowVector operator / (Complex s, const ComplexRowVector& a); |
|
1693 |
|
1694 // row vector by column vector -> scalar |
|
1695 |
|
1696 Complex operator * (const ColumnVector& a) const; |
|
1697 |
|
1698 Complex operator * (const ComplexColumnVector& a) const; |
|
1699 |
|
1700 // row vector by matrix -> row vector |
|
1701 |
|
1702 ComplexRowVector operator * (const Matrix& a) const; |
|
1703 |
|
1704 ComplexRowVector operator * (const ComplexMatrix& a) const; |
|
1705 |
|
1706 // row vector by row vector -> row vector operations |
|
1707 |
|
1708 ComplexRowVector operator + (const RowVector& a) const; |
|
1709 ComplexRowVector operator - (const RowVector& a) const; |
|
1710 |
|
1711 ComplexRowVector operator + (const ComplexRowVector& a) const; |
|
1712 ComplexRowVector operator - (const ComplexRowVector& a) const; |
|
1713 |
|
1714 ComplexRowVector product (const RowVector& a) const; // element by element |
|
1715 ComplexRowVector quotient (const RowVector& a) const; // element by element |
|
1716 |
|
1717 ComplexRowVector product (const ComplexRowVector& a) const; // el by el |
|
1718 ComplexRowVector quotient (const ComplexRowVector& a) const; // el by el |
|
1719 |
|
1720 ComplexRowVector& operator += (const RowVector& a); |
|
1721 ComplexRowVector& operator -= (const RowVector& a); |
|
1722 |
|
1723 ComplexRowVector& operator += (const ComplexRowVector& a); |
|
1724 ComplexRowVector& operator -= (const ComplexRowVector& a); |
|
1725 |
|
1726 // unary operations |
|
1727 |
|
1728 ComplexRowVector operator - (void) const; |
|
1729 |
|
1730 friend ComplexRowVector map (c_c_Mapper f, const ComplexRowVector& a); |
|
1731 friend RowVector map (d_c_Mapper f, const ComplexRowVector& a); |
|
1732 void map (c_c_Mapper f); |
|
1733 |
|
1734 Complex min (void) const; |
|
1735 Complex max (void) const; |
|
1736 |
|
1737 // i/o |
|
1738 |
|
1739 friend ostream& operator << (ostream& os, const ComplexRowVector& a); |
|
1740 |
|
1741 // conversions |
|
1742 |
|
1743 Complex *fortran_vec (void); |
|
1744 |
|
1745 private: |
|
1746 int len; |
|
1747 Complex *data; |
|
1748 |
|
1749 ComplexRowVector (Complex *d, int l); |
|
1750 }; |
|
1751 |
|
1752 inline ComplexRowVector::ComplexRowVector (void) { len = 0; data = 0; } |
|
1753 inline ComplexRowVector::ComplexRowVector (Complex *d, int l) |
|
1754 { len = l; data = d; } |
|
1755 inline ComplexRowVector::~ComplexRowVector (void) { delete [] data; data = 0; } |
|
1756 |
|
1757 inline int ComplexRowVector::capacity (void) const { return len; } |
|
1758 inline int ComplexRowVector::length (void) const { return len; } |
|
1759 |
|
1760 inline Complex& ComplexRowVector::elem (int n) { return data[n]; } |
|
1761 |
|
1762 inline Complex& |
|
1763 ComplexRowVector::checkelem (int n) |
|
1764 { |
|
1765 #ifndef NO_RANGE_CHECK |
|
1766 if (n < 0 || n >= len) |
|
1767 FAIL; |
|
1768 #endif |
|
1769 |
|
1770 return elem (n); |
|
1771 } |
|
1772 |
|
1773 inline Complex& ComplexRowVector::operator () (int n) { return checkelem (n); } |
|
1774 |
|
1775 inline Complex ComplexRowVector::elem (int n) const { return data[n]; } |
|
1776 |
|
1777 inline Complex |
|
1778 ComplexRowVector::checkelem (int n) const |
|
1779 { |
|
1780 #ifndef NO_RANGE_CHECK |
|
1781 if (n < 0 || n >= len) |
|
1782 FAIL; |
|
1783 #endif |
|
1784 |
|
1785 return elem (n); |
|
1786 } |
|
1787 |
|
1788 inline Complex ComplexRowVector::operator () (int n) const |
|
1789 { return checkelem (n); } |
|
1790 |
|
1791 inline Complex *ComplexRowVector::fortran_vec (void) { return data; } |
|
1792 |
|
1793 /* |
|
1794 * Complex Diagonal Matrix class |
|
1795 */ |
|
1796 |
|
1797 class ComplexDiagMatrix |
|
1798 { |
|
1799 friend class Matrix; |
|
1800 friend class DiagMatrix; |
|
1801 friend class ComplexMatrix; |
|
1802 |
|
1803 public: |
|
1804 ComplexDiagMatrix (void); |
|
1805 ComplexDiagMatrix (int n); |
|
1806 ComplexDiagMatrix (int n, double val); |
|
1807 ComplexDiagMatrix (int n, Complex val); |
|
1808 ComplexDiagMatrix (int r, int c); |
|
1809 ComplexDiagMatrix (int r, int c, double val); |
|
1810 ComplexDiagMatrix (int r, int c, Complex val); |
|
1811 ComplexDiagMatrix (const RowVector& a); |
|
1812 ComplexDiagMatrix (const ComplexRowVector& a); |
|
1813 ComplexDiagMatrix (const ColumnVector& a); |
|
1814 ComplexDiagMatrix (const ComplexColumnVector& a); |
|
1815 ComplexDiagMatrix (const DiagMatrix& a); |
|
1816 ComplexDiagMatrix (const ComplexDiagMatrix& a); |
|
1817 ComplexDiagMatrix (double a); |
|
1818 ComplexDiagMatrix (Complex a); |
|
1819 ~ComplexDiagMatrix (void); |
|
1820 |
|
1821 ComplexDiagMatrix& operator = (const DiagMatrix& a); |
|
1822 ComplexDiagMatrix& operator = (const ComplexDiagMatrix& a); |
|
1823 |
|
1824 int rows (void) const; |
|
1825 int cols (void) const; |
|
1826 int columns (void) const; |
|
1827 |
|
1828 Complex& checkelem (int r, int c); |
|
1829 Complex& elem (int r, int c); |
|
1830 Complex& operator () (int r, int c); |
|
1831 |
|
1832 Complex checkelem (int r, int c) const; // const access |
|
1833 Complex elem (int r, int c) const; |
|
1834 Complex operator () (int r, int c) const; |
|
1835 |
|
1836 ComplexDiagMatrix& resize (int r, int c); |
|
1837 ComplexDiagMatrix& resize (int r, int c, double val); |
|
1838 ComplexDiagMatrix& resize (int r, int c, Complex val); |
|
1839 |
|
1840 int operator == (const ComplexDiagMatrix& a) const; |
|
1841 int operator != (const ComplexDiagMatrix& a) const; |
|
1842 |
|
1843 ComplexDiagMatrix& fill (double val); |
|
1844 ComplexDiagMatrix& fill (Complex val); |
|
1845 ComplexDiagMatrix& fill (double val, int beg, int end); |
|
1846 ComplexDiagMatrix& fill (Complex val, int beg, int end); |
|
1847 ComplexDiagMatrix& fill (const ColumnVector& a); |
|
1848 ComplexDiagMatrix& fill (const ComplexColumnVector& a); |
|
1849 ComplexDiagMatrix& fill (const RowVector& a); |
|
1850 ComplexDiagMatrix& fill (const ComplexRowVector& a); |
|
1851 ComplexDiagMatrix& fill (const ColumnVector& a, int beg); |
|
1852 ComplexDiagMatrix& fill (const ComplexColumnVector& a, int beg); |
|
1853 ComplexDiagMatrix& fill (const RowVector& a, int beg); |
|
1854 ComplexDiagMatrix& fill (const ComplexRowVector& a, int beg); |
|
1855 |
|
1856 ComplexDiagMatrix hermitian (void) const; // complex conjugate transpose |
|
1857 ComplexDiagMatrix transpose (void) const; |
|
1858 |
|
1859 friend DiagMatrix real (const ComplexDiagMatrix& a); |
|
1860 friend DiagMatrix imag (const ComplexDiagMatrix& a); |
|
1861 friend ComplexDiagMatrix conj (const ComplexDiagMatrix& a); |
|
1862 |
|
1863 // resize is the destructive analog for this one |
|
1864 |
|
1865 ComplexMatrix extract (int r1, int c1, int r2, int c2) const; |
|
1866 |
|
1867 // extract row or column i. |
|
1868 |
|
1869 ComplexRowVector row (int i) const; |
|
1870 ComplexRowVector row (char *s) const; |
|
1871 |
|
1872 ComplexColumnVector column (int i) const; |
|
1873 ComplexColumnVector column (char *s) const; |
|
1874 |
|
1875 ComplexDiagMatrix inverse (int& info) const; |
|
1876 ComplexDiagMatrix inverse (void) const; |
|
1877 |
|
1878 // diagonal matrix by scalar -> matrix operations |
|
1879 |
|
1880 ComplexMatrix operator + (double s) const; |
|
1881 ComplexMatrix operator - (double s) const; |
|
1882 |
|
1883 ComplexMatrix operator + (Complex s) const; |
|
1884 ComplexMatrix operator - (Complex s) const; |
|
1885 |
|
1886 // diagonal matrix by scalar -> diagonal matrix operations |
|
1887 |
|
1888 ComplexDiagMatrix operator * (double s) const; |
|
1889 ComplexDiagMatrix operator / (double s) const; |
|
1890 |
|
1891 ComplexDiagMatrix operator * (Complex s) const; |
|
1892 ComplexDiagMatrix operator / (Complex s) const; |
|
1893 |
|
1894 // scalar by diagonal matrix -> matrix operations |
|
1895 |
|
1896 friend ComplexMatrix operator + (double s, const ComplexDiagMatrix& a); |
|
1897 friend ComplexMatrix operator - (double s, const ComplexDiagMatrix& a); |
|
1898 |
|
1899 friend ComplexMatrix operator + (Complex s, const ComplexDiagMatrix& a); |
|
1900 friend ComplexMatrix operator - (Complex s, const ComplexDiagMatrix& a); |
|
1901 |
|
1902 // scalar by diagonal matrix -> diagonal matrix operations |
|
1903 |
|
1904 friend ComplexDiagMatrix operator * (double s, const ComplexDiagMatrix& a); |
|
1905 friend ComplexDiagMatrix operator / (double s, const ComplexDiagMatrix& a); |
|
1906 |
|
1907 friend ComplexDiagMatrix operator * (Complex s, const ComplexDiagMatrix& a); |
|
1908 friend ComplexDiagMatrix operator / (Complex s, const ComplexDiagMatrix& a); |
|
1909 |
|
1910 // diagonal matrix by column vector -> column vector operations |
|
1911 |
|
1912 ComplexColumnVector operator * (const ColumnVector& a) const; |
|
1913 |
|
1914 ComplexColumnVector operator * (const ComplexColumnVector& a) const; |
|
1915 |
|
1916 // diagonal matrix by diagonal matrix -> diagonal matrix operations |
|
1917 |
|
1918 ComplexDiagMatrix operator + (const DiagMatrix& a) const; |
|
1919 ComplexDiagMatrix operator - (const DiagMatrix& a) const; |
|
1920 ComplexDiagMatrix operator * (const DiagMatrix& a) const; |
|
1921 |
|
1922 ComplexDiagMatrix operator + (const ComplexDiagMatrix& a) const; |
|
1923 ComplexDiagMatrix operator - (const ComplexDiagMatrix& a) const; |
|
1924 ComplexDiagMatrix operator * (const ComplexDiagMatrix& a) const; |
|
1925 |
|
1926 ComplexDiagMatrix product (const DiagMatrix& a) const; // element by element |
|
1927 ComplexDiagMatrix quotient (const DiagMatrix& a) const; // element by element |
|
1928 |
|
1929 ComplexDiagMatrix product (const ComplexDiagMatrix& a) const; // el by el |
|
1930 ComplexDiagMatrix quotient (const ComplexDiagMatrix& a) const; // el by el |
|
1931 |
|
1932 ComplexDiagMatrix& operator += (const DiagMatrix& a); |
|
1933 ComplexDiagMatrix& operator -= (const DiagMatrix& a); |
|
1934 |
|
1935 ComplexDiagMatrix& operator += (const ComplexDiagMatrix& a); |
|
1936 ComplexDiagMatrix& operator -= (const ComplexDiagMatrix& a); |
|
1937 |
|
1938 // diagonal matrix by matrix -> matrix operations |
|
1939 |
|
1940 ComplexMatrix operator + (const Matrix& a) const; |
|
1941 ComplexMatrix operator - (const Matrix& a) const; |
|
1942 ComplexMatrix operator * (const Matrix& a) const; |
|
1943 |
|
1944 ComplexMatrix operator + (const ComplexMatrix& a) const; |
|
1945 ComplexMatrix operator - (const ComplexMatrix& a) const; |
|
1946 ComplexMatrix operator * (const ComplexMatrix& a) const; |
|
1947 |
|
1948 // unary operations |
|
1949 |
|
1950 ComplexDiagMatrix operator - (void) const; |
|
1951 |
|
1952 ComplexColumnVector diag (void) const; |
|
1953 ComplexColumnVector diag (int k) const; |
|
1954 |
|
1955 // i/o |
|
1956 |
|
1957 friend ostream& operator << (ostream& os, const ComplexDiagMatrix& a); |
|
1958 |
|
1959 private: |
|
1960 int nr; |
|
1961 int nc; |
|
1962 int len; |
|
1963 Complex *data; |
|
1964 |
|
1965 ComplexDiagMatrix (Complex *d, int nr, int nc); |
|
1966 }; |
|
1967 |
|
1968 inline ComplexDiagMatrix::ComplexDiagMatrix (void) |
|
1969 { nr = 0; nc = 0; len = 0; data = 0; } |
|
1970 |
|
1971 inline ComplexDiagMatrix::ComplexDiagMatrix (Complex *d, int r, int c) |
|
1972 { nr = r; nc = c; len = nr < nc ? nr : nc; data = d; } |
|
1973 |
|
1974 inline ComplexDiagMatrix::~ComplexDiagMatrix (void) |
|
1975 { delete [] data; data = 0; } |
|
1976 |
|
1977 inline int ComplexDiagMatrix::rows (void) const { return len; } |
|
1978 inline int ComplexDiagMatrix::cols (void) const { return len; } |
|
1979 inline int ComplexDiagMatrix::columns (void) const { return len; } |
|
1980 |
|
1981 // Would be nice to be able to avoid compiler warning and make this |
|
1982 // fail on assignment. |
|
1983 inline Complex& ComplexDiagMatrix::elem (int r, int c) |
|
1984 { Complex czero (0.0, 0.0); return (r == c) ? data[r] : czero; } |
|
1985 |
|
1986 inline Complex& ComplexDiagMatrix::checkelem (int r, int c) |
|
1987 { |
|
1988 #ifndef NO_RANGE_CHECK |
|
1989 if (r < 0 || r >= nr || c < 0 || c >= nc) |
|
1990 FAIL; |
|
1991 #endif |
|
1992 |
|
1993 return elem (r, c); |
|
1994 } |
|
1995 |
|
1996 inline Complex& ComplexDiagMatrix::operator () (int r, int c) |
|
1997 { return checkelem (r, c); } |
|
1998 |
|
1999 inline Complex ComplexDiagMatrix::elem (int r, int c) const |
|
2000 { Complex czero (0.0, 0.0); return (r == c) ? data[r] : czero; } |
|
2001 |
|
2002 inline Complex ComplexDiagMatrix::checkelem (int r, int c) const |
|
2003 { |
|
2004 #ifndef NO_RANGE_CHECK |
|
2005 if (r < 0 || r >= nr || c < 0 || c >= nc) |
|
2006 FAIL; |
|
2007 #endif |
|
2008 |
|
2009 return elem (r, c); |
|
2010 } |
|
2011 |
|
2012 inline Complex ComplexDiagMatrix::operator () (int r, int c) const |
|
2013 { return checkelem (r, c); } |
|
2014 |
|
2015 /* |
21
|
2016 * Result of a AEP Balance operation |
|
2017 */ |
|
2018 |
|
2019 class AEPBALANCE |
|
2020 { |
|
2021 friend class Matrix; |
|
2022 |
|
2023 public: |
|
2024 AEPBALANCE (void) {} |
|
2025 |
|
2026 AEPBALANCE (const Matrix& a, const char *balance_job); |
|
2027 |
|
2028 AEPBALANCE (const AEPBALANCE& a); |
|
2029 |
|
2030 AEPBALANCE& operator = (const AEPBALANCE& a); |
|
2031 Matrix balanced_matrix (void) const; |
|
2032 Matrix balancing_matrix (void) const; |
|
2033 friend ostream& operator << (ostream& os, const AEPBALANCE& a); |
|
2034 |
|
2035 private: |
|
2036 int init (const Matrix& a, const char * balance_job); |
|
2037 |
|
2038 Matrix balanced_mat; |
|
2039 Matrix balancing_mat; |
|
2040 }; |
|
2041 |
|
2042 inline AEPBALANCE::AEPBALANCE (const Matrix& a,const char * balance_job) |
|
2043 { |
|
2044 init (a,balance_job); |
|
2045 } |
|
2046 |
|
2047 inline AEPBALANCE::AEPBALANCE (const AEPBALANCE& a) |
|
2048 { |
|
2049 balanced_mat = a.balanced_mat; |
|
2050 balancing_mat = a.balancing_mat; |
|
2051 } |
|
2052 |
|
2053 inline AEPBALANCE& |
|
2054 AEPBALANCE::operator = (const AEPBALANCE& a) |
|
2055 { |
|
2056 balanced_mat = a.balanced_mat; |
|
2057 balancing_mat = a.balancing_mat; |
|
2058 |
|
2059 return *this; |
|
2060 } |
|
2061 inline Matrix AEPBALANCE::balanced_matrix (void) const |
|
2062 { return balanced_mat; } |
|
2063 |
|
2064 inline Matrix AEPBALANCE::balancing_matrix (void) const |
|
2065 { return balancing_mat; } |
|
2066 |
|
2067 /* |
|
2068 * Result of a Complex balancing operation |
|
2069 */ |
|
2070 |
|
2071 class ComplexAEPBALANCE |
|
2072 { |
|
2073 friend class ComplexMatrix; |
|
2074 |
|
2075 public: |
|
2076 ComplexAEPBALANCE (void) {} |
|
2077 ComplexAEPBALANCE (const ComplexMatrix& a, const char *balance_job); |
|
2078 ComplexAEPBALANCE (const ComplexAEPBALANCE& a); |
|
2079 ComplexAEPBALANCE& operator = (const ComplexAEPBALANCE& a); |
|
2080 ComplexMatrix balanced_matrix (void) const; |
|
2081 ComplexMatrix balancing_matrix (void) const; |
|
2082 |
|
2083 friend ostream& operator << (ostream& os, const ComplexAEPBALANCE& a); |
|
2084 |
|
2085 private: |
|
2086 int init (const ComplexMatrix& a, const char * balance_job); |
|
2087 |
|
2088 ComplexMatrix balanced_mat; |
|
2089 ComplexMatrix balancing_mat; |
|
2090 }; |
|
2091 |
|
2092 inline ComplexAEPBALANCE::ComplexAEPBALANCE (const ComplexMatrix& a, const char * balance_job) |
|
2093 { |
|
2094 init(a,balance_job); |
|
2095 } |
|
2096 |
|
2097 inline ComplexAEPBALANCE::ComplexAEPBALANCE (const ComplexAEPBALANCE& a) |
|
2098 { |
|
2099 balanced_mat = a.balanced_mat; |
|
2100 balancing_mat = a.balancing_mat; |
|
2101 } |
|
2102 |
|
2103 inline ComplexAEPBALANCE& |
|
2104 ComplexAEPBALANCE::operator = (const ComplexAEPBALANCE& a) |
|
2105 { |
|
2106 balanced_mat = a.balanced_mat; |
|
2107 balancing_mat = a.balancing_mat; |
|
2108 |
|
2109 return *this; |
|
2110 } |
|
2111 |
|
2112 inline ComplexMatrix ComplexAEPBALANCE::balanced_matrix (void) const |
|
2113 { return balanced_mat; } |
|
2114 |
|
2115 inline ComplexMatrix ComplexAEPBALANCE::balancing_matrix (void) const |
|
2116 { return balancing_mat; } |
|
2117 |
|
2118 /* |
3
|
2119 * Result of a Determinant calculation. |
|
2120 */ |
|
2121 |
|
2122 class DET |
|
2123 { |
|
2124 public: |
|
2125 DET (void) {} |
|
2126 |
|
2127 DET (const DET& a); |
|
2128 |
|
2129 DET& operator = (const DET& a); |
|
2130 |
|
2131 int value_will_overflow (void) const; |
|
2132 int value_will_underflow (void) const; |
|
2133 double coefficient (void) const; |
|
2134 int exponent (void) const; |
|
2135 double value (void) const; |
|
2136 |
|
2137 friend ostream& operator << (ostream& os, const DET& a); |
|
2138 |
|
2139 private: |
|
2140 DET (const double *d); |
|
2141 |
|
2142 double det [2]; |
|
2143 }; |
|
2144 |
|
2145 inline DET::DET (const DET& a) { det[0] = a.det[0]; det[1] = a.det[1]; } |
|
2146 |
|
2147 inline DET& DET::operator = (const DET& a) |
|
2148 { det[0] = a.det[0]; det[1] = a.det[1]; return *this; } |
|
2149 |
|
2150 inline int DET::value_will_overflow (void) const |
|
2151 { return det[2] + 1 > log10 (MAXDOUBLE) ? 1 : 0; } |
|
2152 |
|
2153 inline int DET::value_will_underflow (void) const |
|
2154 { return det[2] - 1 < log10 (MINDOUBLE) ? 1 : 0; } |
|
2155 |
|
2156 inline double DET::coefficient (void) const { return det[0]; } |
|
2157 inline int DET::exponent (void) const { return (int) det[1]; } |
|
2158 inline double DET::value (void) const { return det[0] * pow (10.0, det[1]); } |
|
2159 |
|
2160 inline DET::DET (const double *d) { det[0] = d[0]; det[1] = d[1]; } |
|
2161 |
|
2162 /* |
|
2163 * Result of a Determinant calculation. |
|
2164 */ |
|
2165 |
|
2166 class ComplexDET |
|
2167 { |
|
2168 public: |
|
2169 ComplexDET (void) {} |
|
2170 |
|
2171 ComplexDET (const ComplexDET& a); |
|
2172 |
|
2173 ComplexDET& operator = (const ComplexDET& a); |
|
2174 |
|
2175 int value_will_overflow (void) const; |
|
2176 int value_will_underflow (void) const; |
|
2177 Complex coefficient (void) const; |
|
2178 int exponent (void) const; |
|
2179 Complex value (void) const; |
|
2180 |
|
2181 friend ostream& operator << (ostream& os, const ComplexDET& a); |
|
2182 |
|
2183 private: |
|
2184 ComplexDET (const Complex *d); |
|
2185 |
|
2186 Complex det [2]; |
|
2187 }; |
|
2188 |
|
2189 inline ComplexDET::ComplexDET (const ComplexDET& a) |
|
2190 { det[0] = a.det[0]; det[1] = a.det[1]; } |
|
2191 |
|
2192 inline ComplexDET& ComplexDET::operator = (const ComplexDET& a) |
|
2193 { det[0] = a.det[0]; det[1] = a.det[1]; return *this; } |
|
2194 |
|
2195 inline int ComplexDET::value_will_overflow (void) const |
|
2196 { return real (det[2]) + 1 > log10 (MAXDOUBLE) ? 1 : 0; } |
|
2197 |
|
2198 inline int ComplexDET::value_will_underflow (void) const |
|
2199 { return real (det[2]) - 1 < log10 (MINDOUBLE) ? 1 : 0; } |
|
2200 |
|
2201 inline Complex ComplexDET::coefficient (void) const { return det[0]; } |
|
2202 |
|
2203 inline int ComplexDET::exponent (void) const { return (int) real (det[1]); } |
|
2204 |
|
2205 inline Complex ComplexDET::value (void) const |
|
2206 { return det[0] * pow (10.0, real (det[1])); } |
|
2207 |
|
2208 inline ComplexDET::ComplexDET (const Complex *d) |
|
2209 { det[0] = d[0]; det[1] = d[1]; } |
|
2210 |
|
2211 /* |
21
|
2212 * Result of a GEP Balance operation |
|
2213 * Note: currenlty only do balancing on real data. Complex balancing |
|
2214 * done on magnitudes of complex data. |
|
2215 */ |
|
2216 |
|
2217 class GEPBALANCE |
|
2218 { |
|
2219 friend class Matrix; |
|
2220 |
|
2221 public: |
|
2222 GEPBALANCE (void) {} |
|
2223 |
|
2224 GEPBALANCE (const Matrix& a, const Matrix &, const char *balance_job); |
|
2225 |
|
2226 GEPBALANCE (const GEPBALANCE& a); |
|
2227 |
|
2228 GEPBALANCE& operator = (const GEPBALANCE& a); |
|
2229 Matrix balanced_a_matrix (void) const; |
|
2230 Matrix balanced_b_matrix (void) const; |
|
2231 Matrix left_balancing_matrix (void) const; |
|
2232 Matrix right_balancing_matrix (void) const; |
|
2233 friend ostream& operator << (ostream& os, const GEPBALANCE& a); |
|
2234 |
|
2235 private: |
|
2236 int init (const Matrix& a, const Matrix& b, const char * balance_job); |
|
2237 |
|
2238 Matrix balanced_a_mat; |
|
2239 Matrix balanced_b_mat; |
|
2240 Matrix left_balancing_mat; |
|
2241 Matrix right_balancing_mat; |
|
2242 }; |
|
2243 |
|
2244 inline GEPBALANCE::GEPBALANCE (const Matrix& a, const Matrix& b, |
|
2245 const char * balance_job) |
|
2246 { |
|
2247 init (a,b,balance_job); |
|
2248 } |
|
2249 |
|
2250 inline GEPBALANCE::GEPBALANCE (const GEPBALANCE& a) |
|
2251 { |
|
2252 balanced_a_mat = a.balanced_a_mat; |
|
2253 balanced_b_mat = a.balanced_b_mat; |
|
2254 left_balancing_mat = a.left_balancing_mat; |
|
2255 right_balancing_mat = a.right_balancing_mat; |
|
2256 } |
|
2257 |
|
2258 inline GEPBALANCE& |
|
2259 GEPBALANCE::operator = (const GEPBALANCE& a) |
|
2260 { |
|
2261 balanced_a_mat = a.balanced_a_mat; |
|
2262 balanced_b_mat = a.balanced_b_mat; |
|
2263 left_balancing_mat = a.left_balancing_mat; |
|
2264 right_balancing_mat = a.right_balancing_mat; |
|
2265 |
|
2266 return *this; |
|
2267 } |
|
2268 |
|
2269 inline Matrix GEPBALANCE::balanced_a_matrix (void) const |
|
2270 { return balanced_a_mat; } |
|
2271 |
|
2272 inline Matrix GEPBALANCE::balanced_b_matrix (void) const |
|
2273 { return balanced_b_mat; } |
|
2274 |
|
2275 inline Matrix GEPBALANCE::left_balancing_matrix (void) const |
|
2276 { return left_balancing_mat; } |
|
2277 |
|
2278 inline Matrix GEPBALANCE::right_balancing_matrix (void) const |
|
2279 { return right_balancing_mat; } |
|
2280 |
|
2281 /* |
3
|
2282 * Result of a Hessenbug Decomposition |
|
2283 */ |
|
2284 |
|
2285 class HESS |
|
2286 { |
|
2287 friend class Matrix; |
|
2288 |
|
2289 public: |
|
2290 HESS (void) {} |
|
2291 |
|
2292 HESS (const Matrix& a); |
|
2293 HESS (const Matrix&a, int& info); |
|
2294 |
|
2295 HESS (const HESS& a); |
|
2296 |
|
2297 HESS& operator = (const HESS& a); |
|
2298 Matrix hess_matrix (void) const; |
|
2299 Matrix unitary_hess_matrix (void) const; |
|
2300 friend ostream& operator << (ostream& os, const HESS& a); |
|
2301 |
|
2302 private: |
|
2303 int init (const Matrix& a); |
|
2304 |
|
2305 Matrix hess_mat; |
|
2306 Matrix unitary_hess_mat; |
|
2307 }; |
|
2308 |
|
2309 inline HESS::HESS (const Matrix& a) {init (a); } |
|
2310 inline HESS::HESS (const Matrix& a, int& info) { info = init(a); } |
|
2311 inline HESS::HESS (const HESS& a) |
|
2312 { |
|
2313 hess_mat = a.hess_mat; |
|
2314 unitary_hess_mat = a.unitary_hess_mat; |
|
2315 } |
|
2316 inline HESS& |
|
2317 HESS::operator = (const HESS& a) |
|
2318 { |
|
2319 hess_mat = a.hess_mat; |
|
2320 unitary_hess_mat = a.unitary_hess_mat; |
|
2321 |
|
2322 return *this; |
|
2323 } |
|
2324 inline Matrix HESS::hess_matrix (void) const { return hess_mat; } |
|
2325 inline Matrix HESS::unitary_hess_matrix (void) const {return unitary_hess_mat;} |
|
2326 |
|
2327 /* |
|
2328 * Result of a Hessenburg Decomposition |
|
2329 */ |
|
2330 |
|
2331 class ComplexHESS |
|
2332 { |
|
2333 friend class ComplexMatrix; |
|
2334 |
|
2335 public: |
|
2336 ComplexHESS (void) {} |
|
2337 ComplexHESS (const ComplexMatrix& a); |
|
2338 ComplexHESS (const ComplexMatrix& a, int& info); |
|
2339 ComplexHESS (const ComplexHESS& a); |
|
2340 ComplexHESS& operator = (const ComplexHESS& a); |
|
2341 ComplexMatrix hess_matrix (void) const; |
|
2342 ComplexMatrix unitary_hess_matrix (void) const; |
|
2343 |
|
2344 friend ostream& operator << (ostream& os, const ComplexHESS& a); |
|
2345 |
|
2346 private: |
|
2347 int init (const ComplexMatrix& a); |
|
2348 |
|
2349 ComplexMatrix hess_mat; |
|
2350 ComplexMatrix unitary_hess_mat; |
|
2351 }; |
|
2352 |
|
2353 inline ComplexHESS::ComplexHESS (const ComplexMatrix& a) { init(a); } |
|
2354 inline ComplexHESS::ComplexHESS (const ComplexMatrix& a, int& info) |
|
2355 { info = init(a); } |
|
2356 |
|
2357 inline ComplexHESS::ComplexHESS (const ComplexHESS& a) |
|
2358 { |
|
2359 hess_mat = a.hess_mat; |
|
2360 unitary_hess_mat = a.unitary_hess_mat; |
|
2361 } |
|
2362 |
|
2363 inline ComplexHESS& |
|
2364 ComplexHESS::operator = (const ComplexHESS& a) |
|
2365 { |
|
2366 hess_mat = a.hess_mat; |
|
2367 unitary_hess_mat = a.unitary_hess_mat; |
|
2368 |
|
2369 return *this; |
|
2370 } |
|
2371 |
|
2372 inline ComplexMatrix ComplexHESS::hess_matrix (void) const |
|
2373 { return hess_mat; } |
|
2374 |
|
2375 inline ComplexMatrix ComplexHESS::unitary_hess_matrix (void) const |
|
2376 { return unitary_hess_mat; } |
|
2377 |
|
2378 /* |
|
2379 * Result of a Schur Decomposition |
|
2380 */ |
|
2381 |
|
2382 class SCHUR |
|
2383 { |
|
2384 friend class Matrix; |
|
2385 |
|
2386 public: |
|
2387 SCHUR (void) {} |
|
2388 |
|
2389 SCHUR (const Matrix& a, const char *ord); |
|
2390 SCHUR (const Matrix& a, const char *ord, int& info); |
|
2391 |
|
2392 SCHUR (const SCHUR& a, const char *ord); |
|
2393 |
|
2394 SCHUR& operator = (const SCHUR& a, const char *ord); |
|
2395 |
|
2396 Matrix schur_matrix (void) const; |
|
2397 Matrix unitary_matrix (void) const; |
|
2398 |
|
2399 friend ostream& operator << (ostream& os, const SCHUR& a); |
|
2400 |
|
2401 private: |
|
2402 int init (const Matrix& a, const char *ord); |
|
2403 |
|
2404 Matrix schur_mat; |
|
2405 Matrix unitary_mat; |
|
2406 }; |
|
2407 |
|
2408 inline SCHUR::SCHUR (const Matrix& a, const char *ord) { init (a, ord); } |
|
2409 |
|
2410 inline SCHUR::SCHUR (const Matrix& a, const char *ord, int& info) |
|
2411 { info = init (a, ord); } |
|
2412 |
|
2413 inline SCHUR::SCHUR (const SCHUR& a, const char *ord) |
|
2414 { |
|
2415 schur_mat = a.schur_mat; |
|
2416 unitary_mat = a.unitary_mat; |
|
2417 } |
|
2418 |
|
2419 inline SCHUR& |
|
2420 SCHUR::operator = (const SCHUR& a, const char *ord) |
|
2421 { |
|
2422 schur_mat = a.schur_mat; |
|
2423 unitary_mat = a.unitary_mat; |
|
2424 |
|
2425 return *this; |
|
2426 } |
|
2427 |
|
2428 inline Matrix SCHUR::schur_matrix (void) const { return schur_mat; } |
|
2429 inline Matrix SCHUR::unitary_matrix (void) const { return unitary_mat; } |
|
2430 |
|
2431 /* |
|
2432 * Result of a Schur Decomposition |
|
2433 */ |
|
2434 |
|
2435 class ComplexSCHUR |
|
2436 { |
|
2437 friend class ComplexMatrix; |
|
2438 |
|
2439 public: |
|
2440 ComplexSCHUR (void) {} |
|
2441 |
|
2442 ComplexSCHUR (const ComplexMatrix& a, const char *ord); |
|
2443 ComplexSCHUR (const ComplexMatrix& a, const char *ord, int& info); |
|
2444 |
|
2445 ComplexSCHUR (const ComplexSCHUR& a, const char *ord); |
|
2446 |
|
2447 ComplexSCHUR& operator = (const ComplexSCHUR& a, const char *ord); |
|
2448 |
|
2449 ComplexMatrix schur_matrix (void) const; |
|
2450 ComplexMatrix unitary_matrix (void) const; |
|
2451 |
|
2452 friend ostream& operator << (ostream& os, const ComplexSCHUR& a); |
|
2453 |
|
2454 private: |
|
2455 int init (const ComplexMatrix& a, const char *ord); |
|
2456 |
|
2457 ComplexMatrix schur_mat; |
|
2458 ComplexMatrix unitary_mat; |
|
2459 }; |
|
2460 |
|
2461 inline ComplexSCHUR::ComplexSCHUR (const ComplexMatrix& a, const char *ord) |
|
2462 { init (a,ord); } |
|
2463 |
|
2464 inline ComplexSCHUR::ComplexSCHUR (const ComplexMatrix& a, const char *ord, |
|
2465 int& info) |
|
2466 { info = init (a,ord); } |
|
2467 |
|
2468 inline ComplexSCHUR::ComplexSCHUR (const ComplexSCHUR& a, const char *ord) |
|
2469 { |
|
2470 schur_mat = a.schur_mat; |
|
2471 unitary_mat = a.unitary_mat; |
|
2472 } |
|
2473 |
|
2474 inline ComplexSCHUR& |
|
2475 ComplexSCHUR::operator = (const ComplexSCHUR& a, const char *ord) |
|
2476 { |
|
2477 schur_mat = a.schur_mat; |
|
2478 unitary_mat = a.unitary_mat; |
|
2479 |
|
2480 return *this; |
|
2481 } |
|
2482 inline ComplexMatrix ComplexSCHUR::schur_matrix (void) const |
|
2483 { return schur_mat; } |
|
2484 |
|
2485 inline ComplexMatrix ComplexSCHUR::unitary_matrix (void) const |
|
2486 { return unitary_mat; } |
|
2487 |
|
2488 |
|
2489 /* |
|
2490 * Result of a Singular Value Decomposition. |
|
2491 */ |
|
2492 |
|
2493 class SVD |
|
2494 { |
|
2495 friend class Matrix; |
|
2496 |
|
2497 public: |
|
2498 SVD (void) {} |
|
2499 |
|
2500 SVD (const Matrix& a); |
|
2501 SVD (const Matrix& a, int& info); |
|
2502 |
|
2503 SVD (const SVD& a); |
|
2504 |
|
2505 SVD& operator = (const SVD& a); |
|
2506 |
|
2507 DiagMatrix singular_values (void) const; |
|
2508 Matrix left_singular_matrix (void) const; |
|
2509 Matrix right_singular_matrix (void) const; |
|
2510 |
|
2511 friend ostream& operator << (ostream& os, const SVD& a); |
|
2512 |
|
2513 private: |
|
2514 int init (const Matrix& a); |
|
2515 |
|
2516 DiagMatrix sigma; |
|
2517 Matrix left_sm; |
|
2518 Matrix right_sm; |
|
2519 }; |
|
2520 |
|
2521 inline SVD::SVD (const Matrix& a) { init (a); } |
|
2522 |
|
2523 inline SVD::SVD (const Matrix& a, int& info) { info = init (a); } |
|
2524 |
|
2525 inline SVD::SVD (const SVD& a) |
|
2526 { |
|
2527 sigma = a.sigma; |
|
2528 left_sm = a.left_sm; |
|
2529 right_sm = a.right_sm; |
|
2530 } |
|
2531 |
|
2532 inline SVD& |
|
2533 SVD::operator = (const SVD& a) |
|
2534 { |
|
2535 sigma = a.sigma; |
|
2536 left_sm = a.left_sm; |
|
2537 right_sm = a.right_sm; |
|
2538 |
|
2539 return *this; |
|
2540 } |
|
2541 |
|
2542 inline DiagMatrix SVD::singular_values (void) const { return sigma; } |
|
2543 inline Matrix SVD::left_singular_matrix (void) const { return left_sm; } |
|
2544 inline Matrix SVD::right_singular_matrix (void) const { return right_sm; } |
|
2545 |
|
2546 /* |
|
2547 * Result of a Singular Value Decomposition. |
|
2548 */ |
|
2549 |
|
2550 class ComplexSVD |
|
2551 { |
|
2552 friend class ComplexMatrix; |
|
2553 |
|
2554 public: |
|
2555 ComplexSVD (void) {} |
|
2556 |
|
2557 ComplexSVD (const ComplexMatrix& a); |
|
2558 ComplexSVD (const ComplexMatrix& a, int& info); |
|
2559 |
|
2560 ComplexSVD (const ComplexSVD& a); |
|
2561 |
|
2562 ComplexSVD& operator = (const ComplexSVD& a); |
|
2563 |
|
2564 DiagMatrix singular_values (void) const; |
|
2565 ComplexMatrix left_singular_matrix (void) const; |
|
2566 ComplexMatrix right_singular_matrix (void) const; |
|
2567 |
|
2568 friend ostream& operator << (ostream& os, const ComplexSVD& a); |
|
2569 |
|
2570 private: |
|
2571 int init (const ComplexMatrix& a); |
|
2572 |
|
2573 DiagMatrix sigma; |
|
2574 ComplexMatrix left_sm; |
|
2575 ComplexMatrix right_sm; |
|
2576 }; |
|
2577 |
|
2578 inline ComplexSVD::ComplexSVD (const ComplexMatrix& a) { init (a); } |
|
2579 inline ComplexSVD::ComplexSVD (const ComplexMatrix& a, int& info) |
|
2580 { info = init (a); } |
|
2581 |
|
2582 inline ComplexSVD::ComplexSVD (const ComplexSVD& a) |
|
2583 { |
|
2584 sigma = a.sigma; |
|
2585 left_sm = a.left_sm; |
|
2586 right_sm = a.right_sm; |
|
2587 } |
|
2588 |
|
2589 inline ComplexSVD& |
|
2590 ComplexSVD::operator = (const ComplexSVD& a) |
|
2591 { |
|
2592 sigma = a.sigma; |
|
2593 left_sm = a.left_sm; |
|
2594 right_sm = a.right_sm; |
|
2595 |
|
2596 return *this; |
|
2597 } |
|
2598 |
|
2599 inline DiagMatrix ComplexSVD::singular_values (void) const |
|
2600 { return sigma; } |
|
2601 |
|
2602 inline ComplexMatrix ComplexSVD::left_singular_matrix (void) const |
|
2603 { return left_sm; } |
|
2604 |
|
2605 inline ComplexMatrix ComplexSVD::right_singular_matrix (void) const |
|
2606 { return right_sm; } |
|
2607 |
|
2608 /* |
|
2609 * Result of an Eigenvalue computation. |
|
2610 */ |
|
2611 |
|
2612 class EIG |
|
2613 { |
|
2614 friend class Matrix; |
|
2615 friend class ComplexMatrix; |
|
2616 |
|
2617 public: |
|
2618 EIG (void) {} |
|
2619 |
|
2620 EIG (const Matrix& a); |
|
2621 EIG (const Matrix& a, int& info); |
|
2622 |
|
2623 EIG (const ComplexMatrix& a); |
|
2624 EIG (const ComplexMatrix& a, int& info); |
|
2625 |
|
2626 EIG (const EIG& a); |
|
2627 |
|
2628 EIG& operator = (const EIG& a); |
|
2629 |
|
2630 ComplexColumnVector eigenvalues (void) const; |
|
2631 ComplexMatrix eigenvectors (void) const; |
|
2632 |
|
2633 friend ostream& operator << (ostream& os, const EIG& a); |
|
2634 |
|
2635 private: |
|
2636 int init (const Matrix& a); |
|
2637 int init (const ComplexMatrix& a); |
|
2638 |
|
2639 ComplexColumnVector lambda; |
|
2640 ComplexMatrix v; |
|
2641 }; |
|
2642 |
|
2643 inline EIG::EIG (const Matrix& a) { init (a); } |
|
2644 inline EIG::EIG (const Matrix& a, int& info) { info = init (a); } |
|
2645 |
|
2646 inline EIG::EIG (const ComplexMatrix& a) { init (a); } |
|
2647 inline EIG::EIG (const ComplexMatrix& a, int& info) { info = init (a); } |
|
2648 |
|
2649 inline EIG::EIG (const EIG& a) { lambda = a.lambda; v = a.v; } |
|
2650 |
|
2651 inline EIG& EIG::operator = (const EIG& a) |
|
2652 { lambda = a.lambda; v = a.v; return *this; } |
|
2653 |
|
2654 inline ComplexColumnVector EIG::eigenvalues (void) const { return lambda; } |
|
2655 |
|
2656 inline ComplexMatrix EIG::eigenvectors (void) const { return v; } |
|
2657 |
|
2658 /* |
|
2659 * Result of an LU decomposition. |
|
2660 */ |
|
2661 |
|
2662 class LU |
|
2663 { |
|
2664 friend class Matrix; |
|
2665 |
|
2666 public: |
|
2667 LU (void) {} |
|
2668 |
|
2669 LU (const Matrix& a); |
|
2670 |
|
2671 LU (const LU& a); |
|
2672 |
|
2673 LU& operator = (const LU& a); |
|
2674 |
|
2675 Matrix L (void) const; |
|
2676 Matrix U (void) const; |
|
2677 Matrix P (void) const; |
|
2678 |
|
2679 friend ostream& operator << (ostream& os, const LU& a); |
|
2680 |
|
2681 private: |
|
2682 |
|
2683 Matrix l; |
|
2684 Matrix u; |
|
2685 Matrix p; |
|
2686 }; |
|
2687 |
|
2688 inline LU::LU (const LU& a) { l = a.l; u = a.u; p = a.p; } |
|
2689 |
|
2690 inline LU& LU::operator = (const LU& a) |
|
2691 { l = a.l; u = a.u; p = a.p; return *this; } |
|
2692 |
|
2693 inline Matrix LU::L (void) const { return l; } |
|
2694 inline Matrix LU::U (void) const { return u; } |
|
2695 inline Matrix LU::P (void) const { return p; } |
|
2696 |
|
2697 class ComplexLU |
|
2698 { |
|
2699 friend class ComplexMatrix; |
|
2700 |
|
2701 public: |
|
2702 ComplexLU (void) {} |
|
2703 |
|
2704 ComplexLU (const ComplexMatrix& a); |
|
2705 |
|
2706 ComplexLU (const ComplexLU& a); |
|
2707 |
|
2708 ComplexLU& operator = (const ComplexLU& a); |
|
2709 |
|
2710 ComplexMatrix L (void) const; |
|
2711 ComplexMatrix U (void) const; |
|
2712 Matrix P (void) const; |
|
2713 |
|
2714 friend ostream& operator << (ostream& os, const ComplexLU& a); |
|
2715 |
|
2716 private: |
|
2717 |
|
2718 ComplexMatrix l; |
|
2719 ComplexMatrix u; |
|
2720 Matrix p; |
|
2721 }; |
|
2722 |
|
2723 inline ComplexLU::ComplexLU (const ComplexLU& a) { l = a.l; u = a.u; p = a.p; } |
|
2724 |
|
2725 inline ComplexLU& ComplexLU::operator = (const ComplexLU& a) |
|
2726 { l = a.l; u = a.u; p = a.p; return *this; } |
|
2727 |
|
2728 inline ComplexMatrix ComplexLU::L (void) const { return l; } |
|
2729 inline ComplexMatrix ComplexLU::U (void) const { return u; } |
|
2730 inline Matrix ComplexLU::P (void) const { return p; } |
|
2731 |
|
2732 /* |
|
2733 * Result of a QR decomposition. |
|
2734 */ |
|
2735 |
|
2736 class QR |
|
2737 { |
|
2738 public: |
|
2739 QR (void) {} |
|
2740 |
|
2741 QR (const Matrix& A); |
|
2742 |
|
2743 QR (const QR& a); |
|
2744 |
|
2745 QR& operator = (const QR& a); |
|
2746 |
|
2747 Matrix Q (void) const; |
|
2748 Matrix R (void) const; |
|
2749 |
|
2750 friend ostream& operator << (ostream& os, const QR& a); |
|
2751 |
|
2752 private: |
|
2753 Matrix q; |
|
2754 Matrix r; |
|
2755 }; |
|
2756 |
|
2757 inline QR::QR (const QR& a) { q = a.q; r = a.r; } |
|
2758 |
|
2759 inline QR& QR::operator = (const QR& a) { q = a.q; r = a.r; return *this; } |
|
2760 |
|
2761 inline Matrix QR::Q (void) const { return q; } |
|
2762 inline Matrix QR::R (void) const { return r; } |
|
2763 |
|
2764 class ComplexQR |
|
2765 { |
|
2766 public: |
|
2767 ComplexQR (void) {} |
|
2768 |
|
2769 ComplexQR (const ComplexMatrix& A); |
|
2770 |
|
2771 ComplexQR (const ComplexQR& a); |
|
2772 |
|
2773 ComplexQR& operator = (const ComplexQR& a); |
|
2774 |
|
2775 ComplexMatrix Q (void) const; |
|
2776 ComplexMatrix R (void) const; |
|
2777 |
|
2778 friend ostream& operator << (ostream& os, const ComplexQR& a); |
|
2779 |
|
2780 private: |
|
2781 ComplexMatrix q; |
|
2782 ComplexMatrix r; |
|
2783 }; |
|
2784 |
|
2785 inline ComplexQR::ComplexQR (const ComplexQR& a) { q = a.q; r = a.r; } |
|
2786 |
|
2787 inline ComplexQR& ComplexQR::operator = (const ComplexQR& a) |
|
2788 { q = a.q; r = a.r; return *this; } |
|
2789 |
|
2790 inline ComplexMatrix ComplexQR::Q (void) const { return q; } |
|
2791 inline ComplexMatrix ComplexQR::R (void) const { return r; } |
|
2792 |
|
2793 #endif |
|
2794 |
|
2795 /* |
|
2796 ;;; Local Variables: *** |
|
2797 ;;; mode: C++ *** |
|
2798 ;;; page-delimiter: "^/\\*" *** |
|
2799 ;;; End: *** |
|
2800 */ |