GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CMatrix.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1994-2013 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_CMatrix_h)
24 #define octave_CMatrix_h 1
25 
26 #include "MArray.h"
27 #include "MDiagArray2.h"
28 #include "MatrixType.h"
29 
30 #include "mx-defs.h"
31 #include "mx-op-decl.h"
32 #include "oct-cmplx.h"
33 #include "DET.h"
34 
35 class
36 OCTAVE_API
38 {
39 public:
40 
43 
44  typedef void (*solve_singularity_handler) (double rcon);
45 
46  ComplexMatrix (void) : MArray<Complex> () { }
47 
49  : MArray<Complex> (dim_vector (r, c)) { }
50 
52  : MArray<Complex> (dim_vector (r, c), val) { }
53 
54  ComplexMatrix (const dim_vector& dv) : MArray<Complex> (dv.redim (2)) { }
55 
56  ComplexMatrix (const dim_vector& dv, const Complex& val)
57  : MArray<Complex> (dv.redim (2), val) { }
58 
59  ComplexMatrix (const ComplexMatrix& a) : MArray<Complex> (a) { }
60 
61  template <class U>
62  ComplexMatrix (const MArray<U>& a) : MArray<Complex> (a.as_matrix ()) { }
63 
64  template <class U>
65  ComplexMatrix (const Array<U>& a) : MArray<Complex> (a.as_matrix ()) { }
66 
67  ComplexMatrix (const Matrix& re, const Matrix& im);
68 
69  explicit ComplexMatrix (const Matrix& a);
70 
71  explicit ComplexMatrix (const RowVector& rv);
72 
73  explicit ComplexMatrix (const ColumnVector& cv);
74 
75  explicit ComplexMatrix (const DiagMatrix& a);
76 
77  explicit ComplexMatrix (const ComplexRowVector& rv);
78 
79  explicit ComplexMatrix (const ComplexColumnVector& cv);
80 
81  explicit ComplexMatrix (const ComplexDiagMatrix& a);
82 
83  explicit ComplexMatrix (const boolMatrix& a);
84 
85  explicit ComplexMatrix (const charMatrix& a);
86 
88  {
90  return *this;
91  }
92 
93  bool operator == (const ComplexMatrix& a) const;
94  bool operator != (const ComplexMatrix& a) const;
95 
96  bool is_hermitian (void) const;
97 
98  // destructive insert/delete/reorder operations
99 
101  ComplexMatrix& insert (const RowVector& a,
103  ComplexMatrix& insert (const ColumnVector& a,
105  ComplexMatrix& insert (const DiagMatrix& a,
107 
116 
117  ComplexMatrix& fill (double val);
118  ComplexMatrix& fill (const Complex& val);
119  ComplexMatrix& fill (double val,
122  ComplexMatrix& fill (const Complex& val,
125 
126  ComplexMatrix append (const Matrix& a) const;
127  ComplexMatrix append (const RowVector& a) const;
128  ComplexMatrix append (const ColumnVector& a) const;
129  ComplexMatrix append (const DiagMatrix& a) const;
130 
131  ComplexMatrix append (const ComplexMatrix& a) const;
132  ComplexMatrix append (const ComplexRowVector& a) const;
133  ComplexMatrix append (const ComplexColumnVector& a) const;
134  ComplexMatrix append (const ComplexDiagMatrix& a) const;
135 
136  ComplexMatrix stack (const Matrix& a) const;
137  ComplexMatrix stack (const RowVector& a) const;
138  ComplexMatrix stack (const ColumnVector& a) const;
139  ComplexMatrix stack (const DiagMatrix& a) const;
140 
141  ComplexMatrix stack (const ComplexMatrix& a) const;
142  ComplexMatrix stack (const ComplexRowVector& a) const;
143  ComplexMatrix stack (const ComplexColumnVector& a) const;
144  ComplexMatrix stack (const ComplexDiagMatrix& a) const;
145 
149  { return MArray<Complex>::transpose (); }
150 
151  friend OCTAVE_API ComplexMatrix conj (const ComplexMatrix& a);
152 
153  // resize is the destructive equivalent for this one
154 
157 
159  octave_idx_type nr, octave_idx_type nc) const;
160 
161  // extract row or column i.
162 
164 
166 
168  const Complex& rfv = Complex (0))
169  {
170  MArray<Complex>::resize (dim_vector (nr, nc), rfv);
171  }
172 
173 private:
175  double& rcon, int force, int calc_cond) const;
176 
178  double& rcon, int force, int calc_cond) const;
179 
180 public:
181  ComplexMatrix inverse (void) const;
182  ComplexMatrix inverse (octave_idx_type& info) const;
183  ComplexMatrix inverse (octave_idx_type& info, double& rcon, int force = 0,
184  int calc_cond = 1) const;
185 
186  ComplexMatrix inverse (MatrixType &mattype) const;
187  ComplexMatrix inverse (MatrixType &mattype, octave_idx_type& info) const;
189  double& rcon, int force = 0,
190  int calc_cond = 1) const;
191 
192  ComplexMatrix pseudo_inverse (double tol = 0.0) const;
193 
194  ComplexMatrix fourier (void) const;
195  ComplexMatrix ifourier (void) const;
196 
197  ComplexMatrix fourier2d (void) const;
198  ComplexMatrix ifourier2d (void) const;
199 
200  ComplexDET determinant (void) const;
201  ComplexDET determinant (octave_idx_type& info) const;
202  ComplexDET determinant (octave_idx_type& info, double& rcon,
203  int calc_cond = 1) const;
205  double& rcon, int calc_cond = 1) const;
206 
207  double rcond (void) const;
208  double rcond (MatrixType &mattype) const;
209 
210 private:
211  // Upper triangular matrix solvers
213  octave_idx_type& info, double& rcon,
214  solve_singularity_handler sing_handler,
215  bool calc_cond = false,
216  blas_trans_type transt = blas_no_trans) const;
217 
218  // Lower triangular matrix solvers
220  octave_idx_type& info, double& rcon,
221  solve_singularity_handler sing_handler,
222  bool calc_cond = false,
223  blas_trans_type transt = blas_no_trans) const;
224 
225  // Full matrix solvers (umfpack/cholesky)
227  octave_idx_type& info, double& rcon,
228  solve_singularity_handler sing_handler,
229  bool calc_cond = false) const;
230 
231 public:
232  // Generic interface to solver with no probing of type
233  ComplexMatrix solve (MatrixType &typ, const Matrix& b) const;
234  ComplexMatrix solve (MatrixType &typ, const Matrix& b,
235  octave_idx_type& info) const;
236  ComplexMatrix solve (MatrixType &typ, const Matrix& b,
237  octave_idx_type& info, double& rcon) const;
238  ComplexMatrix solve (MatrixType &typ, const Matrix& b, octave_idx_type& info,
239  double& rcon, solve_singularity_handler sing_handler,
240  bool singular_fallback = true,
241  blas_trans_type transt = blas_no_trans) const;
242 
243  ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b) const;
245  octave_idx_type& info) const;
247  octave_idx_type& info, double& rcon) const;
249  octave_idx_type& info, double& rcon,
250  solve_singularity_handler sing_handler,
251  bool singular_fallback = true,
252  blas_trans_type transt = blas_no_trans) const;
253 
254  ComplexColumnVector solve (MatrixType &typ, const ColumnVector& b) const;
256  octave_idx_type& info) const;
258  octave_idx_type& info, double& rcon) const;
260  octave_idx_type& info, double& rcon,
261  solve_singularity_handler sing_handler,
262  blas_trans_type transt = blas_no_trans) const;
263 
265  const ComplexColumnVector& b) const;
267  octave_idx_type& info) const;
269  octave_idx_type& info, double& rcon) const;
271  octave_idx_type& info, double& rcon,
272  solve_singularity_handler sing_handler,
273  blas_trans_type transt = blas_no_trans) const;
274 
275  // Generic interface to solver with probing of type
276  ComplexMatrix solve (const Matrix& b) const;
277  ComplexMatrix solve (const Matrix& b, octave_idx_type& info) const;
278  ComplexMatrix solve (const Matrix& b, octave_idx_type& info,
279  double& rcon) const;
280  ComplexMatrix solve (const Matrix& b, octave_idx_type& info, double& rcon,
281  solve_singularity_handler sing_handler,
282  blas_trans_type transt = blas_no_trans) const;
283 
284  ComplexMatrix solve (const ComplexMatrix& b) const;
285  ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info) const;
287  double& rcon) const;
289  double& rcon,
290  solve_singularity_handler sing_handler,
291  blas_trans_type transt = blas_no_trans) const;
292 
293  ComplexColumnVector solve (const ColumnVector& b) const;
294  ComplexColumnVector solve (const ColumnVector& b, octave_idx_type& info) const;
296  double& rcon) const;
298  double& rcon,
299  solve_singularity_handler sing_handler,
300  blas_trans_type transt = blas_no_trans) const;
301 
304  octave_idx_type& info) const;
306  octave_idx_type& info,
307  double& rcon) const;
309  octave_idx_type& info,
310  double& rcon,
311  solve_singularity_handler sing_handler,
312  blas_trans_type transt = blas_no_trans) const;
313 
314  ComplexMatrix lssolve (const Matrix& b) const;
315  ComplexMatrix lssolve (const Matrix& b, octave_idx_type& info) const;
316  ComplexMatrix lssolve (const Matrix& b, octave_idx_type& info,
317  octave_idx_type& rank) const;
318  ComplexMatrix lssolve (const Matrix& b, octave_idx_type& info,
319  octave_idx_type& rank, double& rcon) const;
320 
321  ComplexMatrix lssolve (const ComplexMatrix& b) const;
322  ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info) const;
324  octave_idx_type& rank) const;
326  octave_idx_type& rank, double& rcon) const;
327 
328  ComplexColumnVector lssolve (const ColumnVector& b) const;
330  octave_idx_type& info) const;
332  octave_idx_type& rank) const;
334  octave_idx_type& rank, double& rcon) const;
335 
338  octave_idx_type& info) const;
340  octave_idx_type& info,
341  octave_idx_type& rank) const;
343  octave_idx_type& info,
344  octave_idx_type& rank, double& rcon) const;
345 
346  // matrix by diagonal matrix -> matrix operations
347 
350 
353 
354  // matrix by matrix -> matrix operations
355 
356  ComplexMatrix& operator += (const Matrix& a);
357  ComplexMatrix& operator -= (const Matrix& a);
358 
359  // unary operations
360 
361  boolMatrix operator ! (void) const;
362 
363  // other operations
364 
365  bool any_element_is_nan (void) const;
366  bool any_element_is_inf_or_nan (void) const;
367  bool all_elements_are_real (void) const;
368  bool all_integers (double& max_val, double& min_val) const;
369  bool too_large_for_float (void) const;
370 
371  boolMatrix all (int dim = -1) const;
372  boolMatrix any (int dim = -1) const;
373 
374  ComplexMatrix cumprod (int dim = -1) const;
375  ComplexMatrix cumsum (int dim = -1) const;
376  ComplexMatrix prod (int dim = -1) const;
377  ComplexMatrix sum (int dim = -1) const;
378  ComplexMatrix sumsq (int dim = -1) const;
379  Matrix abs (void) const;
380 
381  ComplexMatrix diag (octave_idx_type k = 0) const;
382 
384 
385  bool row_is_real_only (octave_idx_type) const;
387 
388  ComplexColumnVector row_min (void) const;
389  ComplexColumnVector row_max (void) const;
390 
393 
394  ComplexRowVector column_min (void) const;
395  ComplexRowVector column_max (void) const;
396 
399 
400  // i/o
401 
402  friend OCTAVE_API std::ostream& operator << (std::ostream& os,
403  const ComplexMatrix& a);
404  friend OCTAVE_API std::istream& operator >> (std::istream& is,
405  ComplexMatrix& a);
406 };
407 
408 extern OCTAVE_API ComplexMatrix conj (const ComplexMatrix& a);
409 
410 // column vector by row vector -> matrix operations
411 
412 extern OCTAVE_API ComplexMatrix
413 operator * (const ColumnVector& a, const ComplexRowVector& b);
414 
415 extern OCTAVE_API ComplexMatrix
416 operator * (const ComplexColumnVector& a, const RowVector& b);
417 
418 extern OCTAVE_API ComplexMatrix
420 
421 extern OCTAVE_API ComplexMatrix
422 Givens (const Complex&, const Complex&);
423 
424 extern OCTAVE_API ComplexMatrix
425 Sylvester (const ComplexMatrix&, const ComplexMatrix&, const ComplexMatrix&);
426 
427 extern OCTAVE_API ComplexMatrix
428 xgemm (const ComplexMatrix& a, const ComplexMatrix& b,
430  blas_trans_type transb = blas_no_trans);
431 
432 extern OCTAVE_API ComplexMatrix operator * (const Matrix&,
433  const ComplexMatrix&);
434 extern OCTAVE_API ComplexMatrix operator * (const ComplexMatrix&,
435  const Matrix&);
436 extern OCTAVE_API ComplexMatrix operator * (const ComplexMatrix&,
437  const ComplexMatrix&);
438 
439 extern OCTAVE_API ComplexMatrix min (const Complex& c, const ComplexMatrix& m);
440 extern OCTAVE_API ComplexMatrix min (const ComplexMatrix& m, const Complex& c);
441 extern OCTAVE_API ComplexMatrix min (const ComplexMatrix& a,
442  const ComplexMatrix& b);
443 
444 extern OCTAVE_API ComplexMatrix max (const Complex& c, const ComplexMatrix& m);
445 extern OCTAVE_API ComplexMatrix max (const ComplexMatrix& m, const Complex& c);
446 extern OCTAVE_API ComplexMatrix max (const ComplexMatrix& a,
447  const ComplexMatrix& b);
448 
449 extern OCTAVE_API ComplexMatrix linspace (const ComplexColumnVector& x1,
450  const ComplexColumnVector& x2,
451  octave_idx_type n);
452 
453 
456 
457 SM_CMP_OP_DECLS (Complex, ComplexMatrix, OCTAVE_API)
458 SM_BOOL_OP_DECLS (Complex, ComplexMatrix, OCTAVE_API)
459 
460 MM_CMP_OP_DECLS (ComplexMatrix, ComplexMatrix, OCTAVE_API)
461 MM_BOOL_OP_DECLS (ComplexMatrix, ComplexMatrix, OCTAVE_API)
462 
463 MARRAY_FORWARD_DEFS (MArray, ComplexMatrix, Complex)
464 
465 #endif