GNU Octave  9.1.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-2024 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
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 () = default;
64 
65  FloatComplexMatrix (const FloatComplexMatrix& a) = default;
66 
67  FloatComplexMatrix& operator = (const FloatComplexMatrix& a) = default;
68 
69  ~FloatComplexMatrix () = 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 OCTAVE_API FloatComplexMatrix (const FloatMatrix& a);
93 
94  explicit OCTAVE_API FloatComplexMatrix (const FloatRowVector& rv);
95 
96  explicit OCTAVE_API FloatComplexMatrix (const FloatColumnVector& cv);
97 
98  explicit OCTAVE_API FloatComplexMatrix (const FloatDiagMatrix& a);
99 
101 
102  explicit OCTAVE_API FloatComplexMatrix (const DiagArray2<float>& a);
103 
105 
107 
109 
111 
113 
114  explicit OCTAVE_API FloatComplexMatrix (const boolMatrix& a);
115 
116  explicit OCTAVE_API FloatComplexMatrix (const charMatrix& a);
117 
118  OCTAVE_API FloatComplexMatrix (const FloatMatrix& re, const FloatMatrix& im);
119 
120  OCTAVE_API bool operator == (const FloatComplexMatrix& a) const;
121  OCTAVE_API bool operator != (const FloatComplexMatrix& a) const;
122 
123  OCTAVE_API bool ishermitian () const;
124 
125  // destructive insert/delete/reorder operations
126 
128  insert (const FloatMatrix& a, octave_idx_type r, octave_idx_type c);
130  insert (const FloatRowVector& a, octave_idx_type r, octave_idx_type c);
132  insert (const FloatColumnVector& a, octave_idx_type r, octave_idx_type c);
134  insert (const FloatDiagMatrix& a, octave_idx_type r, octave_idx_type c);
135 
137  insert (const FloatComplexMatrix& a, octave_idx_type r, octave_idx_type c);
139  insert (const FloatComplexRowVector& a, octave_idx_type r,
140  octave_idx_type c);
142  insert (const FloatComplexColumnVector& a, octave_idx_type r,
143  octave_idx_type c);
145  insert (const FloatComplexDiagMatrix& a, octave_idx_type r,
146  octave_idx_type c);
147 
148  OCTAVE_API FloatComplexMatrix& fill (float val);
149  OCTAVE_API FloatComplexMatrix& fill (const FloatComplex& val);
151  fill (float val, octave_idx_type r1, octave_idx_type c1,
154  fill (const FloatComplex& val, octave_idx_type r1, octave_idx_type c1,
156 
157  OCTAVE_API FloatComplexMatrix append (const FloatMatrix& a) const;
158  OCTAVE_API FloatComplexMatrix append (const FloatRowVector& a) const;
159  OCTAVE_API FloatComplexMatrix append (const FloatColumnVector& a) const;
160  OCTAVE_API FloatComplexMatrix append (const FloatDiagMatrix& a) const;
161 
162  OCTAVE_API FloatComplexMatrix append (const FloatComplexMatrix& a) const;
163  OCTAVE_API FloatComplexMatrix append (const FloatComplexRowVector& a) const;
165  append (const FloatComplexColumnVector& a) const;
166  OCTAVE_API FloatComplexMatrix append (const FloatComplexDiagMatrix& a) const;
167 
168  OCTAVE_API FloatComplexMatrix stack (const FloatMatrix& a) const;
169  OCTAVE_API FloatComplexMatrix stack (const FloatRowVector& a) const;
170  OCTAVE_API FloatComplexMatrix stack (const FloatColumnVector& a) const;
171  OCTAVE_API FloatComplexMatrix stack (const FloatDiagMatrix& a) const;
172 
173  OCTAVE_API FloatComplexMatrix stack (const FloatComplexMatrix& a) const;
174  OCTAVE_API FloatComplexMatrix stack (const FloatComplexRowVector& a) const;
177 
181  { return MArray<FloatComplex>::transpose (); }
182 
184 
185  // resize is the destructive equivalent for this one
186 
188  extract (octave_idx_type r1, octave_idx_type c1,
189  octave_idx_type r2, octave_idx_type c2) const;
190 
192  extract_n (octave_idx_type r1, octave_idx_type c1,
193  octave_idx_type nr, octave_idx_type nc) const;
194 
195  // extract row or column i.
196 
198 
200 
202  const FloatComplex& rfv = FloatComplex (0))
203  {
205  }
206 
207 private:
208  FloatComplexMatrix tinverse (MatrixType& mattype, octave_idx_type& info,
209  float& rcon, bool force, bool calc_cond) const;
210 
211  FloatComplexMatrix finverse (MatrixType& mattype, octave_idx_type& info,
212  float& rcon, bool force, bool calc_cond) const;
213 
214 public:
215  OCTAVE_API FloatComplexMatrix inverse () const;
216  OCTAVE_API FloatComplexMatrix inverse (octave_idx_type& info) const;
218  inverse (octave_idx_type& info, float& rcon, bool force = false,
219  bool calc_cond = true) const;
220 
221  OCTAVE_API FloatComplexMatrix inverse (MatrixType& mattype) const;
223  inverse (MatrixType& mattype, octave_idx_type& info) const;
225  inverse (MatrixType& mattype, octave_idx_type& info, float& rcon,
226  bool force = false, bool calc_cond = true) const;
227 
228  OCTAVE_API FloatComplexMatrix pseudo_inverse (float tol = 0.0) const;
229 
230  OCTAVE_API FloatComplexMatrix fourier () const;
231  OCTAVE_API FloatComplexMatrix ifourier () const;
232 
233  OCTAVE_API FloatComplexMatrix fourier2d () const;
234  OCTAVE_API FloatComplexMatrix ifourier2d () const;
235 
236  OCTAVE_API FloatComplexDET determinant () const;
237  OCTAVE_API FloatComplexDET determinant (octave_idx_type& info) const;
239  determinant (octave_idx_type& info, float& rcon,
240  bool calc_cond = true) const;
242  determinant (MatrixType& mattype, octave_idx_type& info,
243  float& rcon, bool calc_cond = true) const;
244 
245  OCTAVE_API float rcond () const;
246  OCTAVE_API float rcond (MatrixType& mattype) const;
247 
248 private:
249  // Upper triangular matrix solvers
250  FloatComplexMatrix utsolve (MatrixType& mattype, const FloatComplexMatrix& b,
251  octave_idx_type& info, float& rcon,
252  solve_singularity_handler sing_handler,
253  bool calc_cond = false,
254  blas_trans_type transt = blas_no_trans) const;
255 
256  // Lower triangular matrix solvers
257  FloatComplexMatrix ltsolve (MatrixType& mattype, const FloatComplexMatrix& b,
258  octave_idx_type& info, float& rcon,
259  solve_singularity_handler sing_handler,
260  bool calc_cond = false,
261  blas_trans_type transt = blas_no_trans) const;
262 
263  // Full matrix solvers (umfpack/cholesky)
264  FloatComplexMatrix fsolve (MatrixType& mattype, const FloatComplexMatrix& b,
265  octave_idx_type& info, float& rcon,
266  solve_singularity_handler sing_handler,
267  bool calc_cond = false) const;
268 
269 public:
270  // Generic interface to solver with no probing of type
272  solve (MatrixType& mattype, const FloatMatrix& b) const;
274  solve (MatrixType& mattype, const FloatMatrix& b,
275  octave_idx_type& info) const;
277  solve (MatrixType& mattype, const FloatMatrix& b, octave_idx_type& info,
278  float& rcon) const;
280  solve (MatrixType& mattype, const FloatMatrix& b, octave_idx_type& info,
281  float& rcon, solve_singularity_handler sing_handler,
282  bool singular_fallback = true,
283  blas_trans_type transt = blas_no_trans) const;
284 
286  solve (MatrixType& mattype, const FloatComplexMatrix& b) const;
288  solve (MatrixType& mattype, const FloatComplexMatrix& b,
289  octave_idx_type& info) const;
291  solve (MatrixType& mattype, const FloatComplexMatrix& b,
292  octave_idx_type& info, float& rcon) const;
294  solve (MatrixType& mattype, const FloatComplexMatrix& b,
295  octave_idx_type& info, float& rcon,
296  solve_singularity_handler sing_handler,
297  bool singular_fallback = true,
298  blas_trans_type transt = blas_no_trans) const;
299 
301  solve (MatrixType& mattype, const FloatColumnVector& b) const;
303  solve (MatrixType& mattype, const FloatColumnVector& b,
304  octave_idx_type& info) const;
306  solve (MatrixType& mattype, const FloatColumnVector& b,
307  octave_idx_type& info, float& rcon) const;
309  solve (MatrixType& mattype, const FloatColumnVector& b,
310  octave_idx_type& info, float& rcon,
311  solve_singularity_handler sing_handler,
312  blas_trans_type transt = blas_no_trans) const;
313 
315  solve (MatrixType& mattype, const FloatComplexColumnVector& b) const;
317  solve (MatrixType& mattype, const FloatComplexColumnVector& b,
318  octave_idx_type& info) const;
320  solve (MatrixType& mattype, const FloatComplexColumnVector& b,
321  octave_idx_type& info, float& rcon) const;
323  solve (MatrixType& mattype, const FloatComplexColumnVector& b,
324  octave_idx_type& info, float& rcon,
325  solve_singularity_handler sing_handler,
326  blas_trans_type transt = blas_no_trans) const;
327 
328  // Generic interface to solver with probing of type
329  OCTAVE_API FloatComplexMatrix solve (const FloatMatrix& b) const;
331  solve (const FloatMatrix& b, octave_idx_type& info) const;
333  solve (const FloatMatrix& b, octave_idx_type& info, float& rcon) const;
335  solve (const FloatMatrix& b, octave_idx_type& info, float& rcon,
336  solve_singularity_handler sing_handler,
337  blas_trans_type transt = blas_no_trans) const;
338 
339  OCTAVE_API FloatComplexMatrix solve (const FloatComplexMatrix& b) const;
341  solve (const FloatComplexMatrix& b, octave_idx_type& info) const;
343  solve (const FloatComplexMatrix& b, octave_idx_type& info,
344  float& rcon) const;
346  solve (const FloatComplexMatrix& b, octave_idx_type& info, float& rcon,
347  solve_singularity_handler sing_handler,
348  blas_trans_type transt = blas_no_trans) const;
349 
352  solve (const FloatColumnVector& b, octave_idx_type& info) const;
354  solve (const FloatColumnVector& b, octave_idx_type& info,
355  float& rcon) const;
357  solve (const FloatColumnVector& b, octave_idx_type& info, float& rcon,
358  solve_singularity_handler sing_handler,
359  blas_trans_type transt = blas_no_trans) const;
360 
362  solve (const FloatComplexColumnVector& b) const;
364  solve (const FloatComplexColumnVector& b, octave_idx_type& info) const;
366  solve (const FloatComplexColumnVector& b, octave_idx_type& info,
367  float& rcon) const;
369  solve (const FloatComplexColumnVector& b, octave_idx_type& info, float& rcon,
370  solve_singularity_handler sing_handler,
371  blas_trans_type transt = blas_no_trans) const;
372 
373  OCTAVE_API FloatComplexMatrix lssolve (const FloatMatrix& b) const;
375  lssolve (const FloatMatrix& b, octave_idx_type& info) const;
377  lssolve (const FloatMatrix& b, octave_idx_type& info, octave_idx_type& rank) const;
379  lssolve (const FloatMatrix& b, octave_idx_type& info, octave_idx_type& rank,
380  float& rcon) const;
381 
382  OCTAVE_API FloatComplexMatrix lssolve (const FloatComplexMatrix& b) const;
384  lssolve (const FloatComplexMatrix& b, octave_idx_type& info) const;
386  lssolve (const FloatComplexMatrix& b, octave_idx_type& info,
387  octave_idx_type& rank) const;
389  lssolve (const FloatComplexMatrix& b, octave_idx_type& info,
390  octave_idx_type& rank, float& rcon) const;
391 
393  lssolve (const FloatColumnVector& b) const;
395  lssolve (const FloatColumnVector& b, octave_idx_type& info) const;
397  lssolve (const FloatColumnVector& b, octave_idx_type& info,
398  octave_idx_type& rank) const;
400  lssolve (const FloatColumnVector& b, octave_idx_type& info,
401  octave_idx_type& rank, float& rcon) const;
402 
404  lssolve (const FloatComplexColumnVector& b) const;
406  lssolve (const FloatComplexColumnVector& b, octave_idx_type& info) const;
408  lssolve (const FloatComplexColumnVector& b, octave_idx_type& info,
409  octave_idx_type& rank) const;
411  lssolve (const FloatComplexColumnVector& b, octave_idx_type& info,
412  octave_idx_type& rank, float& rcon) const;
413 
414  // matrix by diagonal matrix -> matrix operations
415 
418 
421 
422  // matrix by matrix -> matrix operations
423 
426 
427  // unary operations
428 
430 
431  // other operations
432 
433  OCTAVE_API boolMatrix all (int dim = -1) const;
434  OCTAVE_API boolMatrix any (int dim = -1) const;
435 
436  OCTAVE_API FloatComplexMatrix cumprod (int dim = -1) const;
437  OCTAVE_API FloatComplexMatrix cumsum (int dim = -1) const;
438  OCTAVE_API FloatComplexMatrix prod (int dim = -1) const;
439  OCTAVE_API FloatComplexMatrix sum (int dim = -1) const;
440  OCTAVE_API FloatComplexMatrix sumsq (int dim = -1) const;
441  OCTAVE_API FloatMatrix abs () const;
442 
443  OCTAVE_API FloatComplexMatrix diag (octave_idx_type k = 0) const;
444 
446  diag (octave_idx_type m, octave_idx_type n) const;
447 
448  OCTAVE_API bool row_is_real_only (octave_idx_type) const;
449  OCTAVE_API bool column_is_real_only (octave_idx_type) const;
450 
451  OCTAVE_API FloatComplexColumnVector row_min () const;
452  OCTAVE_API FloatComplexColumnVector row_max () const;
453 
455  row_min (Array<octave_idx_type>& index) const;
457  row_max (Array<octave_idx_type>& index) const;
458 
459  OCTAVE_API FloatComplexRowVector column_min () const;
460  OCTAVE_API FloatComplexRowVector column_max () const;
461 
463  column_min (Array<octave_idx_type>& index) const;
465  column_max (Array<octave_idx_type>& index) const;
466 
467  // i/o
468 
469  friend OCTAVE_API std::ostream&
470  operator << (std::ostream& os, const FloatComplexMatrix& a);
471  friend OCTAVE_API std::istream&
472  operator >> (std::istream& is, FloatComplexMatrix& a);
473 };
474 
476 
477 // column vector by row vector -> matrix operations
478 
481 
484 
487 
489 Givens (const FloatComplex&, const FloatComplex&);
490 
493  const FloatComplexMatrix&);
494 
496 xgemm (const FloatComplexMatrix& a, const FloatComplexMatrix& b,
498  blas_trans_type transb = blas_no_trans);
499 
501  const FloatComplexMatrix&);
503  const FloatMatrix&);
505  const FloatComplexMatrix&);
506 
508  const FloatComplexMatrix& m);
510  const FloatComplex& c);
512  const FloatComplexMatrix& b);
513 
515  const FloatComplexMatrix& m);
517  const FloatComplex& c);
519  const FloatComplexMatrix& b);
520 
523  const FloatComplexColumnVector& x2,
525 
528 
531 
534 
536 
537 #endif
template std::ostream & operator<<(std::ostream &, const Array< bool > &)
#define MARRAY_FORWARD_DEFS(B, R, T)
Definition: MArray.h:130
std::istream & operator>>(std::istream &is, SparseBoolMatrix &a)
Definition: boolSparse.cc:279
N Dimensional Array with copy-on-write semantics.
Definition: Array.h:130
void resize(const dim_vector &dv, const T &rfv)
Definition: Array-base.cc:1023
FloatComplexMatrix hermitian() const
Definition: fCMatrix.h:178
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
FloatComplexDiagMatrix complex_diag_matrix_type
Definition: fCMatrix.h:56
FloatColumnVector real_column_vector_type
Definition: fCMatrix.h:49
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
void resize(octave_idx_type nr, octave_idx_type nc, const FloatComplex &rfv=FloatComplex(0))
Definition: fCMatrix.h:201
FloatComplex complex_elt_type
Definition: fCMatrix.h:59
FloatComplexMatrix transpose() const
Definition: fCMatrix.h:180
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()=default
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
~FloatComplexMatrix()=default
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:102
MArray< T > transpose() const
Definition: MArray.h:99
Definition: DET.h:39
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:94
bool operator!=(const dim_vector &a, const dim_vector &b)
Definition: dim-vector.h:536
bool operator==(const dim_vector &a, const dim_vector &b)
Definition: dim-vector.h:520
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:3378
FloatComplexMatrix max(const FloatComplex &c, const FloatComplexMatrix &m)
Definition: fCMatrix.cc:3585
FloatComplexMatrix linspace(const FloatComplexColumnVector &x1, const FloatComplexColumnVector &x2, octave_idx_type n)
Definition: fCMatrix.cc:3660
FloatComplexMatrix Sylvester(const FloatComplexMatrix &, const FloatComplexMatrix &, const FloatComplexMatrix &)
Definition: fCMatrix.cc:3278
FloatComplexMatrix operator+=(FloatComplexMatrix &x, const FloatComplex &y)
Definition: fCMatrix.h:535
FloatComplexMatrix operator-=(FloatComplexMatrix &x, const FloatComplex &y)
Definition: fCMatrix.h:535
FloatComplexMatrix min(const FloatComplex &c, const FloatComplexMatrix &m)
Definition: fCMatrix.cc:3513
FloatComplexMatrix conj(const FloatComplexMatrix &a)
Definition: fCMatrix.cc:678
FloatComplexMatrix operator*(const FloatColumnVector &a, const FloatComplexRowVector &b)
Definition: fCMatrix.cc:2652
FloatComplexMatrix Givens(const FloatComplex &, const FloatComplex &)
Definition: fCMatrix.cc:3259
#define OCTAVE_API
Definition: main.cc:55
blas_trans_type
Definition: mx-defs.h:80
@ blas_no_trans
Definition: mx-defs.h:81
T octave_idx_type m
Definition: mx-inlines.cc:781
octave_idx_type n
Definition: mx-inlines.cc:761
T * r
Definition: mx-inlines.cc:781
#define SM_BOOL_OP_DECLS(S, M, API)
Definition: mx-op-decl.h:122
#define MS_CMP_OP_DECLS(M, S, API)
Definition: mx-op-decl.h:89
#define SM_CMP_OP_DECLS(S, M, API)
Definition: mx-op-decl.h:114
#define MS_BOOL_OP_DECLS(M, S, API)
Definition: mx-op-decl.h:97
#define MM_CMP_OP_DECLS(M1, M2, API)
Definition: mx-op-decl.h:139
#define MM_BOOL_OP_DECLS(M1, M2, API)
Definition: mx-op-decl.h:147
std::complex< float > FloatComplex
Definition: oct-cmplx.h:34
octave_value operator!(const octave_value &a)
Definition: ov.h:1633
template int8_t abs(int8_t)