GNU Octave  4.0.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
fCMatrix.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1994-2015 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_fCMatrix_h)
24 #define octave_fCMatrix_h 1
25 
26 #include "fCNDArray.h"
27 #include "MArray.h"
28 #include "MDiagArray2.h"
29 #include "MatrixType.h"
30 
31 #include "mx-defs.h"
32 #include "mx-op-decl.h"
33 #include "oct-cmplx.h"
34 #include "DET.h"
35 
36 class
37 OCTAVE_API
39 {
40 public:
41 
44 
45  typedef void (*solve_singularity_handler) (float rcon);
46 
48 
50  : FloatComplexNDArray (dim_vector (r, c)) { }
51 
53  const FloatComplex& val)
54  : FloatComplexNDArray (dim_vector (r, c), val) { }
55 
57  : FloatComplexNDArray (dv.redim (2)) { }
58 
59  FloatComplexMatrix (const dim_vector& dv, const FloatComplex& val)
60  : FloatComplexNDArray (dv.redim (2), val) { }
61 
63  : FloatComplexNDArray (a) { }
64 
65  template <class U>
67  : FloatComplexNDArray (a.as_matrix ()) { }
68 
69  template <class U>
71  : FloatComplexNDArray (a.as_matrix ()) { }
72 
73  explicit FloatComplexMatrix (const FloatMatrix& a);
74 
75  explicit FloatComplexMatrix (const FloatRowVector& rv);
76 
77  explicit FloatComplexMatrix (const FloatColumnVector& cv);
78 
79  explicit FloatComplexMatrix (const FloatDiagMatrix& a);
80 
81  explicit FloatComplexMatrix (const MDiagArray2<float>& a);
82 
83  explicit FloatComplexMatrix (const DiagArray2<float>& a);
84 
85  explicit FloatComplexMatrix (const FloatComplexRowVector& rv);
86 
87  explicit FloatComplexMatrix (const FloatComplexColumnVector& cv);
88 
89  explicit FloatComplexMatrix (const FloatComplexDiagMatrix& a);
90 
92 
93  explicit FloatComplexMatrix (const DiagArray2<FloatComplex>& a);
94 
95  explicit FloatComplexMatrix (const boolMatrix& a);
96 
97  explicit FloatComplexMatrix (const charMatrix& a);
98 
99  FloatComplexMatrix (const FloatMatrix& re, const FloatMatrix& im);
100 
101  bool operator == (const FloatComplexMatrix& a) const;
102  bool operator != (const FloatComplexMatrix& a) const;
103 
104  bool is_hermitian (void) const;
105 
106  // destructive insert/delete/reorder operations
107 
116 
125 
126  FloatComplexMatrix& fill (float val);
127  FloatComplexMatrix& fill (const FloatComplex& val);
130  FloatComplexMatrix& fill (const FloatComplex& val,
133 
134  FloatComplexMatrix append (const FloatMatrix& a) const;
135  FloatComplexMatrix append (const FloatRowVector& a) const;
137  FloatComplexMatrix append (const FloatDiagMatrix& a) const;
138 
143 
144  FloatComplexMatrix stack (const FloatMatrix& a) const;
145  FloatComplexMatrix stack (const FloatRowVector& a) const;
146  FloatComplexMatrix stack (const FloatColumnVector& a) const;
147  FloatComplexMatrix stack (const FloatDiagMatrix& a) const;
148 
149  FloatComplexMatrix stack (const FloatComplexMatrix& a) const;
150  FloatComplexMatrix stack (const FloatComplexRowVector& a) const;
151  FloatComplexMatrix stack (const FloatComplexColumnVector& a) const;
152  FloatComplexMatrix stack (const FloatComplexDiagMatrix& a) const;
153 
157  { return MArray<FloatComplex>::transpose (); }
158 
159  friend OCTAVE_API FloatComplexMatrix conj (const FloatComplexMatrix& a);
160 
161  // resize is the destructive equivalent for this one
162 
165 
167  octave_idx_type nr, octave_idx_type nc) const;
168 
169  // extract row or column i.
170 
172 
174 
176  const FloatComplex& rfv = FloatComplex (0))
177  {
179  }
180 
181 private:
182  FloatComplexMatrix tinverse (MatrixType &mattype, octave_idx_type& info,
183  float& rcon, int force, int calc_cond) const;
184 
185  FloatComplexMatrix finverse (MatrixType &mattype, octave_idx_type& info,
186  float& rcon, int force, int calc_cond) const;
187 
188 public:
189  FloatComplexMatrix inverse (void) const;
190  FloatComplexMatrix inverse (octave_idx_type& info) const;
191  FloatComplexMatrix inverse (octave_idx_type& info, float& rcon,
192  int force = 0, int calc_cond = 1) const;
193 
194  FloatComplexMatrix inverse (MatrixType &mattype) const;
195  FloatComplexMatrix inverse (MatrixType &mattype, octave_idx_type& info) const;
196  FloatComplexMatrix inverse (MatrixType &mattype, octave_idx_type& info,
197  float& rcon, int force = 0,
198  int calc_cond = 1) const;
199 
200  FloatComplexMatrix pseudo_inverse (float tol = 0.0) const;
201 
202  FloatComplexMatrix fourier (void) const;
203  FloatComplexMatrix ifourier (void) const;
204 
205  FloatComplexMatrix fourier2d (void) const;
206  FloatComplexMatrix ifourier2d (void) const;
207 
208  FloatComplexDET determinant (void) const;
209  FloatComplexDET determinant (octave_idx_type& info) const;
210  FloatComplexDET determinant (octave_idx_type& info, float& rcon,
211  int calc_cond = 1) const;
212  FloatComplexDET determinant (MatrixType &mattype, octave_idx_type& info,
213  float& rcon, int calc_cond = 1) const;
214 
215  float rcond (void) const;
216  float rcond (MatrixType &mattype) const;
217 
218 private:
219  // Upper triangular matrix solvers
221  octave_idx_type& info, float& rcon,
222  solve_singularity_handler sing_handler,
223  bool calc_cond = false,
224  blas_trans_type transt = blas_no_trans) const;
225 
226  // Lower triangular matrix solvers
228  octave_idx_type& info, float& rcon,
229  solve_singularity_handler sing_handler,
230  bool calc_cond = false,
231  blas_trans_type transt = blas_no_trans) const;
232 
233  // Full matrix solvers (umfpack/cholesky)
234  FloatComplexMatrix fsolve (MatrixType &typ, const FloatComplexMatrix& b,
235  octave_idx_type& info, float& rcon,
236  solve_singularity_handler sing_handler,
237  bool calc_cond = false) const;
238 
239 public:
240  // Generic interface to solver with no probing of type
241  FloatComplexMatrix solve (MatrixType &typ, const FloatMatrix& b) const;
242  FloatComplexMatrix solve (MatrixType &typ, const FloatMatrix& b,
243  octave_idx_type& info) const;
244  FloatComplexMatrix solve (MatrixType &typ, const FloatMatrix& b,
245  octave_idx_type& info, float& rcon) const;
246  FloatComplexMatrix solve (MatrixType &typ, const FloatMatrix& b,
247  octave_idx_type& info,
248  float& rcon, solve_singularity_handler sing_handler,
249  bool singular_fallback = true,
250  blas_trans_type transt = blas_no_trans) const;
251 
252  FloatComplexMatrix solve (MatrixType &typ, const FloatComplexMatrix& b) const;
253  FloatComplexMatrix solve (MatrixType &typ, const FloatComplexMatrix& b,
254  octave_idx_type& info) const;
255  FloatComplexMatrix solve (MatrixType &typ, const FloatComplexMatrix& b,
256  octave_idx_type& info, float& rcon) const;
257  FloatComplexMatrix solve (MatrixType &typ, const FloatComplexMatrix& b,
258  octave_idx_type& info, float& rcon,
259  solve_singularity_handler sing_handler,
260  bool singular_fallback = true,
261  blas_trans_type transt = blas_no_trans) const;
262 
264  const FloatColumnVector& b) const;
266  octave_idx_type& info) const;
268  octave_idx_type& info, float& rcon) const;
270  octave_idx_type& info, float& rcon,
271  solve_singularity_handler sing_handler,
272  blas_trans_type transt = blas_no_trans) const;
273 
275  const FloatComplexColumnVector& b) const;
277  const FloatComplexColumnVector& b,
278  octave_idx_type& info) const;
280  const FloatComplexColumnVector& b,
281  octave_idx_type& info, float& rcon) const;
283  const FloatComplexColumnVector& b,
284  octave_idx_type& info, float& rcon,
285  solve_singularity_handler sing_handler,
286  blas_trans_type transt = blas_no_trans) const;
287 
288  // Generic interface to solver with probing of type
289  FloatComplexMatrix solve (const FloatMatrix& b) const;
290  FloatComplexMatrix solve (const FloatMatrix& b, octave_idx_type& info) const;
291  FloatComplexMatrix solve (const FloatMatrix& b, octave_idx_type& info,
292  float& rcon) const;
293  FloatComplexMatrix solve (const FloatMatrix& b, octave_idx_type& info,
294  float& rcon,
295  solve_singularity_handler sing_handler,
296  blas_trans_type transt = blas_no_trans) const;
297 
298  FloatComplexMatrix solve (const FloatComplexMatrix& b) const;
299  FloatComplexMatrix solve (const FloatComplexMatrix& b,
300  octave_idx_type& info) const;
302  float& rcon) const;
304  float& rcon,
305  solve_singularity_handler sing_handler,
306  blas_trans_type transt = blas_no_trans) const;
307 
308  FloatComplexColumnVector solve (const FloatColumnVector& b) const;
310  octave_idx_type& info) const;
312  octave_idx_type& info,
313  float& rcon) const;
315  octave_idx_type& info, float& rcon,
316  solve_singularity_handler sing_handler,
317  blas_trans_type transt = blas_no_trans) const;
318 
319  FloatComplexColumnVector solve (const FloatComplexColumnVector& b) const;
321  octave_idx_type& info) const;
323  octave_idx_type& info,
324  float& rcon) const;
326  octave_idx_type& info,
327  float& rcon,
328  solve_singularity_handler sing_handler,
329  blas_trans_type transt = blas_no_trans) const;
330 
331  FloatComplexMatrix lssolve (const FloatMatrix& b) const;
332  FloatComplexMatrix lssolve (const FloatMatrix& b,
333  octave_idx_type& info) const;
334  FloatComplexMatrix lssolve (const FloatMatrix& b, octave_idx_type& info,
335  octave_idx_type& rank) const;
336  FloatComplexMatrix lssolve (const FloatMatrix& b, octave_idx_type& info,
337  octave_idx_type& rank, float& rcon) const;
338 
339  FloatComplexMatrix lssolve (const FloatComplexMatrix& b) const;
340  FloatComplexMatrix lssolve (const FloatComplexMatrix& b,
341  octave_idx_type& info) const;
342  FloatComplexMatrix lssolve (const FloatComplexMatrix& b,
343  octave_idx_type& info, octave_idx_type& rank) const;
344  FloatComplexMatrix lssolve (const FloatComplexMatrix& b,
345  octave_idx_type& info, octave_idx_type& rank, float& rcon) const;
346 
347  FloatComplexColumnVector lssolve (const FloatColumnVector& b) const;
349  octave_idx_type& info) const;
351  octave_idx_type& info,
352  octave_idx_type& rank) const;
354  octave_idx_type& info,
355  octave_idx_type& rank, float& rcon) const;
356 
357  FloatComplexColumnVector lssolve (const FloatComplexColumnVector& b) const;
359  octave_idx_type& info) const;
361  octave_idx_type& info,
362  octave_idx_type& rank) const;
364  octave_idx_type& info,
365  octave_idx_type& rank, float& rcon) const;
366 
367  // matrix by diagonal matrix -> matrix operations
368 
371 
374 
375  // matrix by matrix -> matrix operations
376 
379 
380  // unary operations
381 
382  boolMatrix operator ! (void) const;
383 
384  // other operations
385 
386  boolMatrix all (int dim = -1) const;
387  boolMatrix any (int dim = -1) const;
388 
389  FloatComplexMatrix cumprod (int dim = -1) const;
390  FloatComplexMatrix cumsum (int dim = -1) const;
391  FloatComplexMatrix prod (int dim = -1) const;
392  FloatComplexMatrix sum (int dim = -1) const;
393  FloatComplexMatrix sumsq (int dim = -1) const;
394  FloatMatrix abs (void) const;
395 
397 
399 
400  bool row_is_real_only (octave_idx_type) const;
401  bool column_is_real_only (octave_idx_type) const;
402 
403  FloatComplexColumnVector row_min (void) const;
404  FloatComplexColumnVector row_max (void) const;
405 
408 
409  FloatComplexRowVector column_min (void) const;
410  FloatComplexRowVector column_max (void) const;
411 
414 
415  // i/o
416 
417  friend OCTAVE_API std::ostream& operator << (std::ostream& os,
418  const FloatComplexMatrix& a);
419  friend OCTAVE_API std::istream& operator >> (std::istream& is,
420  FloatComplexMatrix& a);
421 };
422 
423 extern OCTAVE_API FloatComplexMatrix conj (const FloatComplexMatrix& a);
424 
425 // column vector by row vector -> matrix operations
426 
427 extern OCTAVE_API FloatComplexMatrix
429 
430 extern OCTAVE_API FloatComplexMatrix
432 
433 extern OCTAVE_API FloatComplexMatrix
435 
436 extern OCTAVE_API FloatComplexMatrix
437 Givens (const FloatComplex&, const FloatComplex&);
438 
439 extern OCTAVE_API FloatComplexMatrix
441  const FloatComplexMatrix&);
442 
443 extern OCTAVE_API FloatComplexMatrix
444 xgemm (const FloatComplexMatrix& a, const FloatComplexMatrix& b,
446  blas_trans_type transb = blas_no_trans);
447 
448 extern OCTAVE_API FloatComplexMatrix operator * (const FloatMatrix&,
449  const FloatComplexMatrix&);
450 extern OCTAVE_API FloatComplexMatrix operator * (const FloatComplexMatrix&,
451  const FloatMatrix&);
452 extern OCTAVE_API FloatComplexMatrix operator * (const FloatComplexMatrix&,
453  const FloatComplexMatrix&);
454 
455 extern OCTAVE_API FloatComplexMatrix min (const FloatComplex& c,
456  const FloatComplexMatrix& m);
457 extern OCTAVE_API FloatComplexMatrix min (const FloatComplexMatrix& m,
458  const FloatComplex& c);
459 extern OCTAVE_API FloatComplexMatrix min (const FloatComplexMatrix& a,
460  const FloatComplexMatrix& b);
461 
462 extern OCTAVE_API FloatComplexMatrix max (const FloatComplex& c,
463  const FloatComplexMatrix& m);
464 extern OCTAVE_API FloatComplexMatrix max (const FloatComplexMatrix& m,
465  const FloatComplex& c);
466 extern OCTAVE_API FloatComplexMatrix max (const FloatComplexMatrix& a,
467  const FloatComplexMatrix& b);
468 
469 extern OCTAVE_API FloatComplexMatrix
471  const FloatComplexColumnVector& x2,
472  octave_idx_type n);
473 
476 
477 SM_CMP_OP_DECLS (FloatComplex, FloatComplexMatrix, OCTAVE_API)
478 SM_BOOL_OP_DECLS (FloatComplex, FloatComplexMatrix, OCTAVE_API)
479 
480 MM_CMP_OP_DECLS (FloatComplexMatrix, FloatComplexMatrix, OCTAVE_API)
481 MM_BOOL_OP_DECLS (FloatComplexMatrix, FloatComplexMatrix, OCTAVE_API)
482 
483 MARRAY_FORWARD_DEFS (MArray, FloatComplexMatrix, FloatComplex)
484 
485 #endif
FloatComplexMatrix transpose(void) const
Definition: fCMatrix.h:156
Array< FloatComplex > as_matrix(void) const
Return the array as a matrix.
Definition: Array.h:299
void resize(octave_idx_type nr, octave_idx_type nc, const FloatComplex &rfv=FloatComplex(0))
Definition: fCMatrix.h:175
FloatComplexRowVector row_vector_type
Definition: fCMatrix.h:43
FloatComplexRowVector & fill(float val)
Definition: fCRowVector.cc:122
bool operator!=(const dim_vector &a, const dim_vector &b)
Definition: dim-vector.h:548
FloatComplexMatrix(void)
Definition: fCMatrix.h:47
std::istream & operator>>(std::istream &is, SparseBoolMatrix &a)
Definition: boolSparse.cc:279
FloatComplexMatrix hermitian(void) const
Definition: fCMatrix.h:154
static ComplexMatrix ltsolve(const SparseComplexMatrix &, const ColumnVector &, const ComplexMatrix &)
OCTAVE_API FloatComplexMatrix operator*(const FloatColumnVector &a, const FloatComplexRowVector &b)
Definition: fCMatrix.cc:2960
OCTAVE_API FloatComplexMatrix linspace(const FloatComplexColumnVector &x1, const FloatComplexColumnVector &x2, octave_idx_type n)
Definition: fCMatrix.cc:4017
OCTAVE_API FloatComplexMatrix conj(const FloatComplexMatrix &a)
Definition: fCMatrix.cc:969
OCTAVE_API FloatComplexMatrix min(const FloatComplex &c, const FloatComplexMatrix &m)
Definition: fCMatrix.cc:3839
Array< FloatComplex > diag(octave_idx_type k=0) const
Get the kth super or subdiagonal.
MArray< T > transpose(void) const
Definition: MArray.h:83
FloatComplexRowVector extract_n(octave_idx_type c1, octave_idx_type n) const
Definition: fCRowVector.cc:260
Definition: MArray.h:36
#define SM_CMP_OP_DECLS(S, M, API)
Definition: mx-op-decl.h:112
OCTAVE_API FloatComplexMatrix Sylvester(const FloatComplexMatrix &, const FloatComplexMatrix &, const FloatComplexMatrix &)
Definition: fCMatrix.cc:3605
FloatComplexMatrix(const dim_vector &dv, const FloatComplex &val)
Definition: fCMatrix.h:59
static MArray< double > const octave_idx_type const octave_idx_type octave_idx_type octave_idx_type r2
FloatComplexMatrix(const MArray< U > &a)
Definition: fCMatrix.h:66
FloatComplexRowVector extract(octave_idx_type c1, octave_idx_type c2) const
Definition: fCRowVector.cc:245
#define SM_BOOL_OP_DECLS(S, M, API)
Definition: mx-op-decl.h:120
Definition: DET.h:31
#define MM_CMP_OP_DECLS(M1, M2, API)
Definition: mx-op-decl.h:137
#define MM_BOOL_OP_DECLS(M1, M2, API)
Definition: mx-op-decl.h:145
void resize(const dim_vector &dv, const T &rfv)
Definition: Array.cc:1033
Array< FloatComplex > column(octave_idx_type k) const
Extract column: A(:,k+1).
#define MARRAY_FORWARD_DEFS(B, R, T)
Definition: MArray-decl.h:236
FloatComplexMatrix(octave_idx_type r, octave_idx_type c)
Definition: fCMatrix.h:49
FloatComplexMatrix(octave_idx_type r, octave_idx_type c, const FloatComplex &val)
Definition: fCMatrix.h:52
MArray< T > hermitian(T(*fcn)(const T &)=0) const
Definition: MArray.h:86
FloatComplexMatrix operator-=(FloatComplexMatrix &x, const FloatComplex &y)
Definition: fCMatrix.h:483
FloatComplexColumnVector column_vector_type
Definition: fCMatrix.h:42
bool operator==(const dim_vector &a, const dim_vector &b)
Definition: dim-vector.h:519
FloatComplexMatrix(const FloatComplexMatrix &a)
Definition: fCMatrix.h:62
#define MS_CMP_OP_DECLS(M, S, API)
Definition: mx-op-decl.h:87
Handles the reference counting for all the derived classes.
Definition: Array.h:45
FloatComplexMatrix(const Array< U > &a)
Definition: fCMatrix.h:70
FloatComplexMatrix(const dim_vector &dv)
Definition: fCMatrix.h:56
static ComplexMatrix utsolve(const SparseComplexMatrix &, const ColumnVector &, const ComplexMatrix &)
template OCTAVE_API std::ostream & operator<<(std::ostream &, const Array< bool > &)
#define MS_BOOL_OP_DECLS(M, S, API)
Definition: mx-op-decl.h:95
std::complex< float > FloatComplex
Definition: oct-cmplx.h:30
blas_trans_type
Definition: mx-defs.h:128
static MArray< double > const octave_idx_type const octave_idx_type octave_idx_type octave_idx_type octave_idx_type c1
octave_value operator!(const octave_value &a)
Definition: ov.h:1293
FloatComplexRowVector & insert(const FloatRowVector &a, octave_idx_type c)
Definition: fCRowVector.cc:77
FloatComplexRowVector append(const FloatRowVector &a) const
Definition: fCRowVector.cc:203
static MArray< double > const octave_idx_type const octave_idx_type octave_idx_type r1
OCTAVE_API FloatComplexMatrix xgemm(const FloatComplexMatrix &a, const FloatComplexMatrix &b, blas_trans_type transa=blas_no_trans, blas_trans_type transb=blas_no_trans)
Definition: fCMatrix.cc:3705
OCTAVE_API FloatComplexMatrix Givens(const FloatComplex &, const FloatComplex &)
Definition: fCMatrix.cc:3587
FloatComplexMatrix operator+=(FloatComplexMatrix &x, const FloatComplex &y)
Definition: fCMatrix.h:483
T abs(T x)
Definition: pr-output.cc:3062
OCTAVE_API FloatComplexMatrix max(const FloatComplex &c, const FloatComplexMatrix &m)
Definition: fCMatrix.cc:3927
Array< FloatComplex > index(const idx_vector &i) const
Indexing without resizing.