GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
fCMatrix.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1994-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_fCMatrix_h)
27 #define octave_fCMatrix_h 1
28 
29 #include "octave-config.h"
30 
31 #include "DET.h"
32 #include "MArray.h"
33 #include "MDiagArray2.h"
34 #include "MatrixType.h"
35 #include "fCNDArray.h"
36 #include "mx-defs.h"
37 #include "mx-op-decl.h"
38 #include "oct-cmplx.h"
39 
40 class
41 OCTAVE_API
43 {
44 public:
45 
48 
51 
54 
57 
58  typedef float real_elt_type;
60 
61  typedef void (*solve_singularity_handler) (float rcon);
62 
63  FloatComplexMatrix (void) = default;
64 
65  FloatComplexMatrix (const FloatComplexMatrix& a) = default;
66 
67  FloatComplexMatrix& operator = (const FloatComplexMatrix& a) = default;
68 
69  ~FloatComplexMatrix (void) = default;
70 
72  : FloatComplexNDArray (dim_vector (r, c)) { }
73 
75  const FloatComplex& val)
76  : FloatComplexNDArray (dim_vector (r, c), val) { }
77 
79  : FloatComplexNDArray (dv.redim (2)) { }
80 
81  FloatComplexMatrix (const dim_vector& dv, const FloatComplex& val)
82  : FloatComplexNDArray (dv.redim (2), val) { }
83 
84  template <typename U>
86  : FloatComplexNDArray (a.as_matrix ()) { }
87 
88  template <typename U>
90  : FloatComplexNDArray (a.as_matrix ()) { }
91 
92  explicit FloatComplexMatrix (const FloatMatrix& a);
93 
94  explicit FloatComplexMatrix (const FloatRowVector& rv);
95 
96  explicit FloatComplexMatrix (const FloatColumnVector& cv);
97 
98  explicit FloatComplexMatrix (const FloatDiagMatrix& a);
99 
100  explicit FloatComplexMatrix (const MDiagArray2<float>& a);
101 
102  explicit FloatComplexMatrix (const DiagArray2<float>& a);
103 
104  explicit FloatComplexMatrix (const FloatComplexRowVector& rv);
105 
106  explicit FloatComplexMatrix (const FloatComplexColumnVector& cv);
107 
108  explicit FloatComplexMatrix (const FloatComplexDiagMatrix& a);
109 
110  explicit FloatComplexMatrix (const MDiagArray2<FloatComplex>& a);
111 
112  explicit FloatComplexMatrix (const DiagArray2<FloatComplex>& a);
113 
114  explicit FloatComplexMatrix (const boolMatrix& a);
115 
116  explicit FloatComplexMatrix (const charMatrix& a);
117 
118  FloatComplexMatrix (const FloatMatrix& re, const FloatMatrix& im);
119 
120  bool operator == (const FloatComplexMatrix& a) const;
121  bool operator != (const FloatComplexMatrix& a) const;
122 
123  bool ishermitian (void) const;
124 
125  // destructive insert/delete/reorder operations
126 
127  FloatComplexMatrix& insert (const FloatMatrix& a,
129  FloatComplexMatrix& insert (const FloatRowVector& a,
131  FloatComplexMatrix& insert (const FloatColumnVector& a,
133  FloatComplexMatrix& insert (const FloatDiagMatrix& a,
135 
136  FloatComplexMatrix& insert (const FloatComplexMatrix& a,
138  FloatComplexMatrix& insert (const FloatComplexRowVector& a,
142  FloatComplexMatrix& insert (const FloatComplexDiagMatrix& a,
144 
145  FloatComplexMatrix& fill (float val);
146  FloatComplexMatrix& fill (const FloatComplex& val);
147  FloatComplexMatrix& fill (float val, octave_idx_type r1, octave_idx_type c1,
149  FloatComplexMatrix& fill (const FloatComplex& val,
152 
153  FloatComplexMatrix append (const FloatMatrix& a) const;
154  FloatComplexMatrix append (const FloatRowVector& a) const;
155  FloatComplexMatrix append (const FloatColumnVector& a) const;
156  FloatComplexMatrix append (const FloatDiagMatrix& a) const;
157 
158  FloatComplexMatrix append (const FloatComplexMatrix& a) const;
159  FloatComplexMatrix append (const FloatComplexRowVector& a) const;
160  FloatComplexMatrix append (const FloatComplexColumnVector& a) const;
161  FloatComplexMatrix append (const FloatComplexDiagMatrix& a) const;
162 
163  FloatComplexMatrix stack (const FloatMatrix& a) const;
164  FloatComplexMatrix stack (const FloatRowVector& a) const;
165  FloatComplexMatrix stack (const FloatColumnVector& a) const;
166  FloatComplexMatrix stack (const FloatDiagMatrix& a) const;
167 
168  FloatComplexMatrix stack (const FloatComplexMatrix& a) const;
169  FloatComplexMatrix stack (const FloatComplexRowVector& a) const;
170  FloatComplexMatrix stack (const FloatComplexColumnVector& a) const;
171  FloatComplexMatrix stack (const FloatComplexDiagMatrix& a) const;
172 
176  { return MArray<FloatComplex>::transpose (); }
177 
178  friend OCTAVE_API FloatComplexMatrix conj (const FloatComplexMatrix& a);
179 
180  // resize is the destructive equivalent for this one
181 
183  octave_idx_type r2, octave_idx_type c2) const;
184 
186  octave_idx_type nr, octave_idx_type nc) const;
187 
188  // extract row or column i.
189 
191 
192  FloatComplexColumnVector column (octave_idx_type i) const;
193 
195  const FloatComplex& rfv = FloatComplex (0))
196  {
198  }
199 
200 private:
201  FloatComplexMatrix tinverse (MatrixType& mattype, octave_idx_type& info,
202  float& rcon, bool force, bool calc_cond) const;
203 
204  FloatComplexMatrix finverse (MatrixType& mattype, octave_idx_type& info,
205  float& rcon, bool force, bool calc_cond) const;
206 
207 public:
208  FloatComplexMatrix inverse (void) const;
209  FloatComplexMatrix inverse (octave_idx_type& info) const;
210  FloatComplexMatrix inverse (octave_idx_type& info, float& rcon,
211  bool force = false, bool calc_cond = true) const;
212 
213  FloatComplexMatrix inverse (MatrixType& mattype) const;
214  FloatComplexMatrix inverse (MatrixType& mattype, octave_idx_type& info) const;
215  FloatComplexMatrix inverse (MatrixType& mattype, octave_idx_type& info,
216  float& rcon, bool force = false,
217  bool calc_cond = true) const;
218 
219  FloatComplexMatrix pseudo_inverse (float tol = 0.0) const;
220 
221  FloatComplexMatrix fourier (void) const;
222  FloatComplexMatrix ifourier (void) const;
223 
224  FloatComplexMatrix fourier2d (void) const;
225  FloatComplexMatrix ifourier2d (void) const;
226 
227  FloatComplexDET determinant (void) const;
228  FloatComplexDET determinant (octave_idx_type& info) const;
229  FloatComplexDET determinant (octave_idx_type& info, float& rcon,
230  bool calc_cond = true) const;
231  FloatComplexDET determinant (MatrixType& mattype, octave_idx_type& info,
232  float& rcon, bool calc_cond = true) const;
233 
234  float rcond (void) const;
235  float rcond (MatrixType& mattype) const;
236 
237 private:
238  // Upper triangular matrix solvers
240  octave_idx_type& info, float& rcon,
241  solve_singularity_handler sing_handler,
242  bool calc_cond = false,
243  blas_trans_type transt = blas_no_trans) const;
244 
245  // Lower triangular matrix solvers
247  octave_idx_type& info, float& rcon,
248  solve_singularity_handler sing_handler,
249  bool calc_cond = false,
250  blas_trans_type transt = blas_no_trans) const;
251 
252  // Full matrix solvers (umfpack/cholesky)
253  FloatComplexMatrix fsolve (MatrixType& mattype, const FloatComplexMatrix& b,
254  octave_idx_type& info, float& rcon,
255  solve_singularity_handler sing_handler,
256  bool calc_cond = false) const;
257 
258 public:
259  // Generic interface to solver with no probing of type
260  FloatComplexMatrix solve (MatrixType& mattype, const FloatMatrix& b) const;
261  FloatComplexMatrix solve (MatrixType& mattype, const FloatMatrix& b,
262  octave_idx_type& info) const;
263  FloatComplexMatrix solve (MatrixType& mattype, const FloatMatrix& b,
264  octave_idx_type& info, float& rcon) const;
265  FloatComplexMatrix solve (MatrixType& mattype, const FloatMatrix& b,
266  octave_idx_type& info,
267  float& rcon, solve_singularity_handler sing_handler,
268  bool singular_fallback = true,
269  blas_trans_type transt = blas_no_trans) const;
270 
271  FloatComplexMatrix solve (MatrixType& mattype,
272  const FloatComplexMatrix& b) const;
273  FloatComplexMatrix solve (MatrixType& mattype, const FloatComplexMatrix& b,
274  octave_idx_type& info) const;
275  FloatComplexMatrix solve (MatrixType& mattype, const FloatComplexMatrix& b,
276  octave_idx_type& info, float& rcon) const;
277  FloatComplexMatrix solve (MatrixType& mattype, const FloatComplexMatrix& b,
278  octave_idx_type& info, float& rcon,
279  solve_singularity_handler sing_handler,
280  bool singular_fallback = true,
281  blas_trans_type transt = blas_no_trans) const;
282 
283  FloatComplexColumnVector solve (MatrixType& mattype,
284  const FloatColumnVector& b) const;
285  FloatComplexColumnVector solve (MatrixType& mattype, const FloatColumnVector& b,
286  octave_idx_type& info) const;
287  FloatComplexColumnVector solve (MatrixType& mattype, const FloatColumnVector& b,
288  octave_idx_type& info, float& rcon) const;
289  FloatComplexColumnVector solve (MatrixType& mattype, const FloatColumnVector& b,
290  octave_idx_type& info, float& rcon,
291  solve_singularity_handler sing_handler,
292  blas_trans_type transt = blas_no_trans) const;
293 
294  FloatComplexColumnVector solve (MatrixType& mattype,
295  const FloatComplexColumnVector& b) const;
296  FloatComplexColumnVector solve (MatrixType& mattype,
297  const FloatComplexColumnVector& b,
298  octave_idx_type& info) const;
299  FloatComplexColumnVector solve (MatrixType& mattype,
300  const FloatComplexColumnVector& b,
301  octave_idx_type& info, float& rcon) const;
302  FloatComplexColumnVector solve (MatrixType& mattype,
303  const FloatComplexColumnVector& b,
304  octave_idx_type& info, float& rcon,
305  solve_singularity_handler sing_handler,
306  blas_trans_type transt = blas_no_trans) const;
307 
308  // Generic interface to solver with probing of type
309  FloatComplexMatrix solve (const FloatMatrix& b) const;
310  FloatComplexMatrix solve (const FloatMatrix& b, octave_idx_type& info) const;
311  FloatComplexMatrix solve (const FloatMatrix& b, octave_idx_type& info,
312  float& rcon) const;
313  FloatComplexMatrix solve (const FloatMatrix& b, octave_idx_type& info,
314  float& rcon,
315  solve_singularity_handler sing_handler,
316  blas_trans_type transt = blas_no_trans) const;
317 
318  FloatComplexMatrix solve (const FloatComplexMatrix& b) const;
319  FloatComplexMatrix solve (const FloatComplexMatrix& b,
320  octave_idx_type& info) const;
322  float& rcon) const;
324  float& rcon,
325  solve_singularity_handler sing_handler,
326  blas_trans_type transt = blas_no_trans) const;
327 
328  FloatComplexColumnVector solve (const FloatColumnVector& b) const;
330  octave_idx_type& info) const;
332  octave_idx_type& info,
333  float& rcon) const;
335  octave_idx_type& info, float& rcon,
336  solve_singularity_handler sing_handler,
337  blas_trans_type transt = blas_no_trans) const;
338 
339  FloatComplexColumnVector solve (const FloatComplexColumnVector& b) const;
341  octave_idx_type& info) const;
343  octave_idx_type& info,
344  float& rcon) const;
346  octave_idx_type& info,
347  float& rcon,
348  solve_singularity_handler sing_handler,
349  blas_trans_type transt = blas_no_trans) const;
350 
351  FloatComplexMatrix lssolve (const FloatMatrix& b) const;
352  FloatComplexMatrix lssolve (const FloatMatrix& b,
353  octave_idx_type& info) const;
354  FloatComplexMatrix lssolve (const FloatMatrix& b, octave_idx_type& info,
355  octave_idx_type& rank) const;
356  FloatComplexMatrix lssolve (const FloatMatrix& b, octave_idx_type& info,
357  octave_idx_type& rank, float& rcon) const;
358 
359  FloatComplexMatrix lssolve (const FloatComplexMatrix& b) const;
360  FloatComplexMatrix lssolve (const FloatComplexMatrix& b,
361  octave_idx_type& info) const;
362  FloatComplexMatrix lssolve (const FloatComplexMatrix& b,
363  octave_idx_type& info, octave_idx_type& rank) const;
364  FloatComplexMatrix lssolve (const FloatComplexMatrix& b,
365  octave_idx_type& info, octave_idx_type& rank, float& rcon) const;
366 
367  FloatComplexColumnVector lssolve (const FloatColumnVector& b) const;
369  octave_idx_type& info) const;
371  octave_idx_type& info,
372  octave_idx_type& rank) const;
374  octave_idx_type& info,
375  octave_idx_type& rank, float& rcon) const;
376 
377  FloatComplexColumnVector lssolve (const FloatComplexColumnVector& b) const;
379  octave_idx_type& info) const;
381  octave_idx_type& info,
382  octave_idx_type& rank) const;
384  octave_idx_type& info,
385  octave_idx_type& rank, float& rcon) const;
386 
387  // matrix by diagonal matrix -> matrix operations
388 
391 
394 
395  // matrix by matrix -> matrix operations
396 
399 
400  // unary operations
401 
402  boolMatrix operator ! (void) const;
403 
404  // other operations
405 
406  boolMatrix all (int dim = -1) const;
407  boolMatrix any (int dim = -1) const;
408 
409  FloatComplexMatrix cumprod (int dim = -1) const;
410  FloatComplexMatrix cumsum (int dim = -1) const;
411  FloatComplexMatrix prod (int dim = -1) const;
412  FloatComplexMatrix sum (int dim = -1) const;
413  FloatComplexMatrix sumsq (int dim = -1) const;
414  FloatMatrix abs (void) const;
415 
416  FloatComplexMatrix diag (octave_idx_type k = 0) const;
417 
419 
420  bool row_is_real_only (octave_idx_type) const;
421  bool column_is_real_only (octave_idx_type) const;
422 
423  FloatComplexColumnVector row_min (void) const;
424  FloatComplexColumnVector row_max (void) const;
425 
426  FloatComplexColumnVector row_min (Array<octave_idx_type>& index) const;
427  FloatComplexColumnVector row_max (Array<octave_idx_type>& index) const;
428 
429  FloatComplexRowVector column_min (void) const;
430  FloatComplexRowVector column_max (void) const;
431 
432  FloatComplexRowVector column_min (Array<octave_idx_type>& index) const;
433  FloatComplexRowVector column_max (Array<octave_idx_type>& index) const;
434 
435  // i/o
436 
437  friend OCTAVE_API std::ostream& operator << (std::ostream& os,
438  const FloatComplexMatrix& a);
439  friend OCTAVE_API std::istream& operator >> (std::istream& is,
440  FloatComplexMatrix& a);
441 };
442 
443 extern OCTAVE_API FloatComplexMatrix conj (const FloatComplexMatrix& a);
444 
445 // column vector by row vector -> matrix operations
446 
447 extern OCTAVE_API FloatComplexMatrix
449 
450 extern OCTAVE_API FloatComplexMatrix
452 
453 extern OCTAVE_API FloatComplexMatrix
455 
456 extern OCTAVE_API FloatComplexMatrix
457 Givens (const FloatComplex&, const FloatComplex&);
458 
459 extern OCTAVE_API FloatComplexMatrix
461  const FloatComplexMatrix&);
462 
463 extern OCTAVE_API FloatComplexMatrix
464 xgemm (const FloatComplexMatrix& a, const FloatComplexMatrix& b,
466  blas_trans_type transb = blas_no_trans);
467 
468 extern OCTAVE_API FloatComplexMatrix operator * (const FloatMatrix&,
469  const FloatComplexMatrix&);
470 extern OCTAVE_API FloatComplexMatrix operator * (const FloatComplexMatrix&,
471  const FloatMatrix&);
472 extern OCTAVE_API FloatComplexMatrix operator * (const FloatComplexMatrix&,
473  const FloatComplexMatrix&);
474 
475 extern OCTAVE_API FloatComplexMatrix min (const FloatComplex& c,
476  const FloatComplexMatrix& m);
477 extern OCTAVE_API FloatComplexMatrix min (const FloatComplexMatrix& m,
478  const FloatComplex& c);
479 extern OCTAVE_API FloatComplexMatrix min (const FloatComplexMatrix& a,
480  const FloatComplexMatrix& b);
481 
482 extern OCTAVE_API FloatComplexMatrix max (const FloatComplex& c,
483  const FloatComplexMatrix& m);
484 extern OCTAVE_API FloatComplexMatrix max (const FloatComplexMatrix& m,
485  const FloatComplex& c);
486 extern OCTAVE_API FloatComplexMatrix max (const FloatComplexMatrix& a,
487  const FloatComplexMatrix& b);
488 
489 extern OCTAVE_API FloatComplexMatrix
491  const FloatComplexColumnVector& x2,
493 
496 
499 
502 
504 
505 #endif
template OCTAVE_API std::ostream & operator<<(std::ostream &, const Array< bool > &)
#define MARRAY_FORWARD_DEFS(B, R, T)
Definition: MArray.h:128
std::istream & operator>>(std::istream &is, SparseBoolMatrix &a)
Definition: boolSparse.cc:281
N Dimensional Array with copy-on-write semantics.
Definition: Array.h:128
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
Definition: Array.cc:1011
FloatComplexMatrix(const dim_vector &dv, const FloatComplex &val)
Definition: fCMatrix.h:81
FloatComplexMatrix(const FloatComplexMatrix &a)=default
FloatComplexMatrix(const dim_vector &dv)
Definition: fCMatrix.h:78
FloatComplexMatrix(void)=default
FloatComplexDiagMatrix complex_diag_matrix_type
Definition: fCMatrix.h:56
FloatColumnVector real_column_vector_type
Definition: fCMatrix.h:49
FloatComplexMatrix hermitian(void) const
Definition: fCMatrix.h:173
FloatRowVector real_row_vector_type
Definition: fCMatrix.h:50
FloatComplexMatrix complex_matrix_type
Definition: fCMatrix.h:53
FloatComplexMatrix(const Array< U > &a)
Definition: fCMatrix.h:89
FloatMatrix real_matrix_type
Definition: fCMatrix.h:52
FloatComplexMatrix transpose(void) const
Definition: fCMatrix.h:175
~FloatComplexMatrix(void)=default
void resize(octave_idx_type nr, octave_idx_type nc, const FloatComplex &rfv=FloatComplex(0))
Definition: fCMatrix.h:194
FloatComplex complex_elt_type
Definition: fCMatrix.h:59
FloatComplexMatrix(octave_idx_type r, octave_idx_type c, const FloatComplex &val)
Definition: fCMatrix.h:74
FloatComplexRowVector row_vector_type
Definition: fCMatrix.h:47
float real_elt_type
Definition: fCMatrix.h:58
FloatComplexMatrix(octave_idx_type r, octave_idx_type c)
Definition: fCMatrix.h:71
FloatDiagMatrix real_diag_matrix_type
Definition: fCMatrix.h:55
FloatComplexColumnVector column_vector_type
Definition: fCMatrix.h:46
FloatComplexMatrix(const MArray< U > &a)
Definition: fCMatrix.h:85
Template for N-dimensional array classes with like-type math operators.
Definition: MArray.h:63
MArray< T > hermitian(T(*fcn)(const T &)=nullptr) const
Definition: MArray.h:108
MArray< T > transpose(void) const
Definition: MArray.h:105
Definition: DET.h:39
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:95
bool operator!=(const dim_vector &a, const dim_vector &b)
Definition: dim-vector.h:601
bool operator==(const dim_vector &a, const dim_vector &b)
Definition: dim-vector.h:585
static M utsolve(const SM &U, const ColumnVector &Q, const M &m)
Definition: eigs-base.cc:258
static M ltsolve(const SM &L, const ColumnVector &Q, const M &m)
Definition: eigs-base.cc:238
OCTAVE_API FloatComplexMatrix linspace(const FloatComplexColumnVector &x1, const FloatComplexColumnVector &x2, octave_idx_type n)
Definition: fCMatrix.cc:3634
OCTAVE_API FloatComplexMatrix max(const FloatComplex &c, const FloatComplexMatrix &m)
Definition: fCMatrix.cc:3560
OCTAVE_API FloatComplexMatrix Sylvester(const FloatComplexMatrix &, const FloatComplexMatrix &, const FloatComplexMatrix &)
Definition: fCMatrix.cc:3253
OCTAVE_API FloatComplexMatrix min(const FloatComplex &c, const FloatComplexMatrix &m)
Definition: fCMatrix.cc:3488
FloatComplexMatrix operator+=(FloatComplexMatrix &x, const FloatComplex &y)
Definition: fCMatrix.h:503
FloatComplexMatrix operator-=(FloatComplexMatrix &x, const FloatComplex &y)
Definition: fCMatrix.h:503
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:3353
OCTAVE_API FloatComplexMatrix Givens(const FloatComplex &, const FloatComplex &)
Definition: fCMatrix.cc:3234
OCTAVE_API FloatComplexMatrix conj(const FloatComplexMatrix &a)
Definition: fCMatrix.cc:678
OCTAVE_API FloatComplexMatrix operator*(const FloatColumnVector &a, const FloatComplexRowVector &b)
Definition: fCMatrix.cc:2628
blas_trans_type
Definition: mx-defs.h:109
@ blas_no_trans
Definition: mx-defs.h:110
T octave_idx_type m
Definition: mx-inlines.cc:773
octave_idx_type n
Definition: mx-inlines.cc:753
T * r
Definition: mx-inlines.cc:773
#define SM_BOOL_OP_DECLS(S, M, API)
Definition: mx-op-decl.h:123
#define MS_CMP_OP_DECLS(M, S, API)
Definition: mx-op-decl.h:90
#define SM_CMP_OP_DECLS(S, M, API)
Definition: mx-op-decl.h:115
#define MS_BOOL_OP_DECLS(M, S, API)
Definition: mx-op-decl.h:98
#define MM_CMP_OP_DECLS(M1, M2, API)
Definition: mx-op-decl.h:140
#define MM_BOOL_OP_DECLS(M1, M2, API)
Definition: mx-op-decl.h:148
std::complex< float > FloatComplex
Definition: oct-cmplx.h:34
octave_value operator!(const octave_value &a)
Definition: ov.h:1536
static T abs(T x)
Definition: pr-output.cc:1678