GNU Octave  4.4.1
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-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_fCMatrix_h)
24 #define octave_fCMatrix_h 1
25 
26 #include "octave-config.h"
27 
28 #include "DET.h"
29 #include "MArray.h"
30 #include "MDiagArray2.h"
31 #include "MatrixType.h"
32 #include "fCNDArray.h"
33 #include "mx-defs.h"
34 #include "mx-op-decl.h"
35 #include "oct-cmplx.h"
36 
37 class
38 OCTAVE_API
40 {
41 public:
42 
45 
48 
51 
54 
55  typedef float real_elt_type;
57 
58  typedef void (*solve_singularity_handler) (float rcon);
59 
61 
63  : FloatComplexNDArray (dim_vector (r, c)) { }
64 
66  const FloatComplex& val)
67  : FloatComplexNDArray (dim_vector (r, c), val) { }
68 
70  : FloatComplexNDArray (dv.redim (2)) { }
71 
73  : FloatComplexNDArray (dv.redim (2), val) { }
74 
76  : FloatComplexNDArray (a) { }
77 
78  template <typename U>
81 
82  template <typename U>
85 
86  explicit FloatComplexMatrix (const FloatMatrix& a);
87 
88  explicit FloatComplexMatrix (const FloatRowVector& rv);
89 
90  explicit FloatComplexMatrix (const FloatColumnVector& cv);
91 
92  explicit FloatComplexMatrix (const FloatDiagMatrix& a);
93 
94  explicit FloatComplexMatrix (const MDiagArray2<float>& a);
95 
96  explicit FloatComplexMatrix (const DiagArray2<float>& a);
97 
98  explicit FloatComplexMatrix (const FloatComplexRowVector& rv);
99 
100  explicit FloatComplexMatrix (const FloatComplexColumnVector& cv);
101 
102  explicit FloatComplexMatrix (const FloatComplexDiagMatrix& a);
103 
105 
107 
108  explicit FloatComplexMatrix (const boolMatrix& a);
109 
110  explicit FloatComplexMatrix (const charMatrix& a);
111 
112  FloatComplexMatrix (const FloatMatrix& re, const FloatMatrix& im);
113 
114  bool operator == (const FloatComplexMatrix& a) const;
115  bool operator != (const FloatComplexMatrix& a) const;
116 
117  bool ishermitian (void) const;
118 
119  OCTAVE_DEPRECATED (4.4, "use 'ishermitian' instead")
120  bool is_hermitian (void) const
121  { return ishermitian (); }
122 
123  // destructive insert/delete/reorder operations
124 
133 
142 
143  FloatComplexMatrix& fill (float val);
150 
151  FloatComplexMatrix append (const FloatMatrix& a) const;
152  FloatComplexMatrix append (const FloatRowVector& a) const;
155 
160 
161  FloatComplexMatrix stack (const FloatMatrix& a) const;
162  FloatComplexMatrix stack (const FloatRowVector& a) const;
163  FloatComplexMatrix stack (const FloatColumnVector& a) const;
164  FloatComplexMatrix stack (const FloatDiagMatrix& a) const;
165 
166  FloatComplexMatrix stack (const FloatComplexMatrix& a) const;
167  FloatComplexMatrix stack (const FloatComplexRowVector& a) const;
168  FloatComplexMatrix stack (const FloatComplexColumnVector& a) const;
169  FloatComplexMatrix stack (const FloatComplexDiagMatrix& a) const;
170 
174  { return MArray<FloatComplex>::transpose (); }
175 
176  friend OCTAVE_API FloatComplexMatrix conj (const FloatComplexMatrix& a);
177 
178  // resize is the destructive equivalent for this one
179 
181  octave_idx_type r2, octave_idx_type c2) const;
182 
184  octave_idx_type nr, octave_idx_type nc) const;
185 
186  // extract row or column i.
187 
189 
191 
193  const FloatComplex& rfv = FloatComplex (0))
194  {
196  }
197 
198 private:
199  FloatComplexMatrix tinverse (MatrixType& mattype, octave_idx_type& info,
200  float& rcon, bool force, bool calc_cond) const;
201 
202  FloatComplexMatrix finverse (MatrixType& mattype, octave_idx_type& info,
203  float& rcon, bool force, bool calc_cond) const;
204 
205 public:
206  FloatComplexMatrix inverse (void) const;
207  FloatComplexMatrix inverse (octave_idx_type& info) const;
208  FloatComplexMatrix inverse (octave_idx_type& info, float& rcon,
209  bool force = false, bool calc_cond = true) const;
210 
211  FloatComplexMatrix inverse (MatrixType& mattype) const;
212  FloatComplexMatrix inverse (MatrixType& mattype, octave_idx_type& info) const;
213  FloatComplexMatrix inverse (MatrixType& mattype, octave_idx_type& info,
214  float& rcon, bool force = false,
215  bool calc_cond = true) const;
216 
217  FloatComplexMatrix pseudo_inverse (float tol = 0.0) const;
218 
219  FloatComplexMatrix fourier (void) const;
220  FloatComplexMatrix ifourier (void) const;
221 
222  FloatComplexMatrix fourier2d (void) const;
223  FloatComplexMatrix ifourier2d (void) const;
224 
225  FloatComplexDET determinant (void) const;
226  FloatComplexDET determinant (octave_idx_type& info) const;
227  FloatComplexDET determinant (octave_idx_type& info, float& rcon,
228  bool calc_cond = true) const;
229  FloatComplexDET determinant (MatrixType& mattype, octave_idx_type& info,
230  float& rcon, bool calc_cond = true) const;
231 
232  float rcond (void) const;
233  float rcond (MatrixType& mattype) const;
234 
235 private:
236  // Upper triangular matrix solvers
238  octave_idx_type& info, float& rcon,
239  solve_singularity_handler sing_handler,
240  bool calc_cond = false,
241  blas_trans_type transt = blas_no_trans) const;
242 
243  // Lower triangular matrix solvers
245  octave_idx_type& info, float& rcon,
246  solve_singularity_handler sing_handler,
247  bool calc_cond = false,
248  blas_trans_type transt = blas_no_trans) const;
249 
250  // Full matrix solvers (umfpack/cholesky)
251  FloatComplexMatrix fsolve (MatrixType& mattype, const FloatComplexMatrix& b,
252  octave_idx_type& info, float& rcon,
253  solve_singularity_handler sing_handler,
254  bool calc_cond = false) const;
255 
256 public:
257  // Generic interface to solver with no probing of type
258  FloatComplexMatrix solve (MatrixType& mattype, const FloatMatrix& b) const;
259  FloatComplexMatrix solve (MatrixType& mattype, const FloatMatrix& b,
260  octave_idx_type& info) const;
261  FloatComplexMatrix solve (MatrixType& mattype, const FloatMatrix& b,
262  octave_idx_type& info, float& rcon) const;
263  FloatComplexMatrix solve (MatrixType& mattype, const FloatMatrix& b,
264  octave_idx_type& info,
265  float& rcon, solve_singularity_handler sing_handler,
266  bool singular_fallback = true,
267  blas_trans_type transt = blas_no_trans) const;
268 
269  FloatComplexMatrix solve (MatrixType& mattype,
270  const FloatComplexMatrix& b) const;
271  FloatComplexMatrix solve (MatrixType& mattype, const FloatComplexMatrix& b,
272  octave_idx_type& info) const;
273  FloatComplexMatrix solve (MatrixType& mattype, const FloatComplexMatrix& b,
274  octave_idx_type& info, float& rcon) const;
275  FloatComplexMatrix solve (MatrixType& mattype, const FloatComplexMatrix& b,
276  octave_idx_type& info, float& rcon,
277  solve_singularity_handler sing_handler,
278  bool singular_fallback = true,
279  blas_trans_type transt = blas_no_trans) const;
280 
281  FloatComplexColumnVector solve (MatrixType& mattype,
282  const FloatColumnVector& b) const;
283  FloatComplexColumnVector solve (MatrixType& mattype, const FloatColumnVector& b,
284  octave_idx_type& info) const;
285  FloatComplexColumnVector solve (MatrixType& mattype, const FloatColumnVector& b,
286  octave_idx_type& info, float& rcon) const;
287  FloatComplexColumnVector solve (MatrixType& mattype, const FloatColumnVector& b,
288  octave_idx_type& info, float& rcon,
289  solve_singularity_handler sing_handler,
290  blas_trans_type transt = blas_no_trans) const;
291 
292  FloatComplexColumnVector solve (MatrixType& mattype,
293  const FloatComplexColumnVector& b) const;
294  FloatComplexColumnVector solve (MatrixType& mattype,
296  octave_idx_type& info) const;
297  FloatComplexColumnVector solve (MatrixType& mattype,
299  octave_idx_type& info, float& rcon) const;
300  FloatComplexColumnVector solve (MatrixType& mattype,
302  octave_idx_type& info, float& rcon,
303  solve_singularity_handler sing_handler,
304  blas_trans_type transt = blas_no_trans) const;
305 
306  // Generic interface to solver with probing of type
307  FloatComplexMatrix solve (const FloatMatrix& b) const;
308  FloatComplexMatrix solve (const FloatMatrix& b, octave_idx_type& info) const;
309  FloatComplexMatrix solve (const FloatMatrix& b, octave_idx_type& info,
310  float& rcon) const;
311  FloatComplexMatrix solve (const FloatMatrix& b, octave_idx_type& info,
312  float& rcon,
313  solve_singularity_handler sing_handler,
314  blas_trans_type transt = blas_no_trans) const;
315 
316  FloatComplexMatrix solve (const FloatComplexMatrix& b) const;
318  octave_idx_type& info) const;
320  float& rcon) const;
322  float& rcon,
323  solve_singularity_handler sing_handler,
324  blas_trans_type transt = blas_no_trans) const;
325 
326  FloatComplexColumnVector solve (const FloatColumnVector& b) const;
328  octave_idx_type& info) const;
330  octave_idx_type& info,
331  float& rcon) const;
333  octave_idx_type& info, float& rcon,
334  solve_singularity_handler sing_handler,
335  blas_trans_type transt = blas_no_trans) const;
336 
339  octave_idx_type& info) const;
341  octave_idx_type& info,
342  float& rcon) const;
344  octave_idx_type& info,
345  float& rcon,
346  solve_singularity_handler sing_handler,
347  blas_trans_type transt = blas_no_trans) const;
348 
349  FloatComplexMatrix lssolve (const FloatMatrix& b) const;
350  FloatComplexMatrix lssolve (const FloatMatrix& b,
351  octave_idx_type& info) const;
352  FloatComplexMatrix lssolve (const FloatMatrix& b, octave_idx_type& info,
353  octave_idx_type& rank) const;
354  FloatComplexMatrix lssolve (const FloatMatrix& b, octave_idx_type& info,
355  octave_idx_type& rank, float& rcon) const;
356 
357  FloatComplexMatrix lssolve (const FloatComplexMatrix& b) const;
358  FloatComplexMatrix lssolve (const FloatComplexMatrix& b,
359  octave_idx_type& info) const;
360  FloatComplexMatrix lssolve (const FloatComplexMatrix& b,
361  octave_idx_type& info, octave_idx_type& rank) const;
362  FloatComplexMatrix lssolve (const FloatComplexMatrix& b,
363  octave_idx_type& info, octave_idx_type& rank, float& rcon) const;
364 
365  FloatComplexColumnVector lssolve (const FloatColumnVector& b) const;
367  octave_idx_type& info) const;
369  octave_idx_type& info,
370  octave_idx_type& rank) const;
372  octave_idx_type& info,
373  octave_idx_type& rank, float& rcon) const;
374 
375  FloatComplexColumnVector lssolve (const FloatComplexColumnVector& b) const;
377  octave_idx_type& info) const;
379  octave_idx_type& info,
380  octave_idx_type& rank) const;
382  octave_idx_type& info,
383  octave_idx_type& rank, float& rcon) const;
384 
385  // matrix by diagonal matrix -> matrix operations
386 
389 
392 
393  // matrix by matrix -> matrix operations
394 
397 
398  // unary operations
399 
400  boolMatrix operator ! (void) const;
401 
402  // other operations
403 
404  boolMatrix all (int dim = -1) const;
405  boolMatrix any (int dim = -1) const;
406 
407  FloatComplexMatrix cumprod (int dim = -1) const;
408  FloatComplexMatrix cumsum (int dim = -1) const;
409  FloatComplexMatrix prod (int dim = -1) const;
410  FloatComplexMatrix sum (int dim = -1) const;
411  FloatComplexMatrix sumsq (int dim = -1) const;
412  FloatMatrix abs (void) const;
413 
415 
417 
418  bool row_is_real_only (octave_idx_type) const;
419  bool column_is_real_only (octave_idx_type) const;
420 
421  FloatComplexColumnVector row_min (void) const;
422  FloatComplexColumnVector row_max (void) const;
423 
426 
427  FloatComplexRowVector column_min (void) const;
428  FloatComplexRowVector column_max (void) const;
429 
432 
433  // i/o
434 
435  friend OCTAVE_API std::ostream& operator << (std::ostream& os,
436  const FloatComplexMatrix& a);
437  friend OCTAVE_API std::istream& operator >> (std::istream& is,
439 };
440 
441 extern OCTAVE_API FloatComplexMatrix conj (const FloatComplexMatrix& a);
442 
443 // column vector by row vector -> matrix operations
444 
445 extern OCTAVE_API FloatComplexMatrix
447 
448 extern OCTAVE_API FloatComplexMatrix
450 
451 extern OCTAVE_API FloatComplexMatrix
453 
454 extern OCTAVE_API FloatComplexMatrix
455 Givens (const FloatComplex&, const FloatComplex&);
456 
457 extern OCTAVE_API FloatComplexMatrix
459  const FloatComplexMatrix&);
460 
461 extern OCTAVE_API FloatComplexMatrix
464  blas_trans_type transb = blas_no_trans);
465 
466 extern OCTAVE_API FloatComplexMatrix operator * (const FloatMatrix&,
467  const FloatComplexMatrix&);
468 extern OCTAVE_API FloatComplexMatrix operator * (const FloatComplexMatrix&,
469  const FloatMatrix&);
470 extern OCTAVE_API FloatComplexMatrix operator * (const FloatComplexMatrix&,
471  const FloatComplexMatrix&);
472 
473 extern OCTAVE_API FloatComplexMatrix min (const FloatComplex& c,
474  const FloatComplexMatrix& m);
475 extern OCTAVE_API FloatComplexMatrix min (const FloatComplexMatrix& m,
476  const FloatComplex& c);
477 extern OCTAVE_API FloatComplexMatrix min (const FloatComplexMatrix& a,
478  const FloatComplexMatrix& b);
479 
480 extern OCTAVE_API FloatComplexMatrix max (const FloatComplex& c,
481  const FloatComplexMatrix& m);
482 extern OCTAVE_API FloatComplexMatrix max (const FloatComplexMatrix& m,
483  const FloatComplex& c);
484 extern OCTAVE_API FloatComplexMatrix max (const FloatComplexMatrix& a,
485  const FloatComplexMatrix& b);
486 
487 extern OCTAVE_API FloatComplexMatrix
489  const FloatComplexColumnVector& x2,
490  octave_idx_type n);
491 
494 
497 
500 
502 
503 #endif
FloatComplexMatrix complex_matrix_type
Definition: fCMatrix.h:50
void resize(octave_idx_type nr, octave_idx_type nc, const FloatComplex &rfv=FloatComplex(0))
Definition: fCMatrix.h:192
FloatComplexMatrix transpose(void) const
Definition: fCMatrix.h:173
FloatRowVector real_row_vector_type
Definition: fCMatrix.h:47
OCTAVE_EXPORT octave_value_list column
Definition: sparse.cc:123
FloatComplexRowVector row_vector_type
Definition: fCMatrix.h:44
Template for N-dimensional array classes with like-type math operators.
Definition: MArray.h:32
FloatComplexRowVector & fill(float val)
Definition: fCRowVector.cc:96
bool operator!=(const dim_vector &a, const dim_vector &b)
Definition: dim-vector.h:566
FloatComplexMatrix(void)
Definition: fCMatrix.h:60
std::istream & operator>>(std::istream &is, SparseBoolMatrix &a)
Definition: boolSparse.cc:279
OCTAVE_API FloatComplexMatrix operator*(const FloatColumnVector &a, const FloatComplexRowVector &b)
Definition: fCMatrix.cc:2819
MArray< T > hermitian(T(*fcn)(const T &)=nullptr) const
Definition: MArray.h:106
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:4986
OCTAVE_API FloatComplexMatrix linspace(const FloatComplexColumnVector &x1, const FloatComplexColumnVector &x2, octave_idx_type n)
Definition: fCMatrix.cc:3825
OCTAVE_API FloatComplexMatrix conj(const FloatComplexMatrix &a)
Definition: fCMatrix.cc:677
OCTAVE_API FloatComplexMatrix min(const FloatComplex &c, const FloatComplexMatrix &m)
Definition: fCMatrix.cc:3679
for large enough k
Definition: lu.cc:617
FloatComplex complex_elt_type
Definition: fCMatrix.h:56
static T abs(T x)
Definition: pr-output.cc:1696
the second is matched to the second specifier and placed in the second column and so forth If there are more words than specifiers then the process is repeated until all words have been processed or the limit imposed by any(non-whitespace) text in the format that is not one of these specifiers is considered a literal. If there is a literal between two format specifiers then that same literal must appear in the input stream between the matching words. The following specifiers are valid
Definition: file-io.cc:1499
#define SM_CMP_OP_DECLS(S, M, API)
Definition: mx-op-decl.h:114
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
MArray< T > transpose(void) const
Definition: MArray.h:103
Array< FloatComplex > as_matrix(void) const
Return the array as a matrix.
Definition: Array.h:390
OCTAVE_API FloatComplexMatrix Sylvester(const FloatComplexMatrix &, const FloatComplexMatrix &, const FloatComplexMatrix &)
Definition: fCMatrix.cc:3444
#define MARRAY_FORWARD_DEFS(B, R, T)
Definition: MArray.h:126
FloatComplexMatrix hermitian(void) const
Definition: fCMatrix.h:171
FloatComplexMatrix(const dim_vector &dv, const FloatComplex &val)
Definition: fCMatrix.h:72
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:400
FloatComplexMatrix(const MArray< U > &a)
Definition: fCMatrix.h:79
Array< FloatComplex > index(const idx_vector &i) const
Indexing without resizing.
Definition: Array.cc:697
#define SM_BOOL_OP_DECLS(S, M, API)
Definition: mx-op-decl.h:122
Definition: DET.h:34
#define MM_CMP_OP_DECLS(M1, M2, API)
Definition: mx-op-decl.h:139
FloatColumnVector real_column_vector_type
Definition: fCMatrix.h:46
#define MM_BOOL_OP_DECLS(M1, M2, API)
Definition: mx-op-decl.h:147
void resize(const dim_vector &dv, const T &rfv)
Resizing (with fill).
Definition: Array.cc:1010
bool append
Definition: load-save.cc:1618
static M ltsolve(const SM &L, const ColumnVector &Q, const M &m)
Definition: eigs-base.cc:80
float real_elt_type
Definition: fCMatrix.h:55
FloatComplexMatrix(octave_idx_type r, octave_idx_type c)
Definition: fCMatrix.h:62
FloatComplexMatrix(octave_idx_type r, octave_idx_type c, const FloatComplex &val)
Definition: fCMatrix.h:65
FloatComplexMatrix operator-=(FloatComplexMatrix &x, const FloatComplex &y)
Definition: fCMatrix.h:501
FloatComplexColumnVector column_vector_type
Definition: fCMatrix.h:43
bool operator==(const dim_vector &a, const dim_vector &b)
Definition: dim-vector.h:550
FloatComplexMatrix(const FloatComplexMatrix &a)
Definition: fCMatrix.h:75
#define MS_CMP_OP_DECLS(M, S, API)
Definition: mx-op-decl.h:89
FloatDiagMatrix real_diag_matrix_type
Definition: fCMatrix.h:52
N Dimensional Array with copy-on-write semantics.
Definition: Array.h:125
FloatComplexMatrix(const Array< U > &a)
Definition: fCMatrix.h:83
FloatComplexMatrix(const dim_vector &dv)
Definition: fCMatrix.h:69
Array< FloatComplex > diag(octave_idx_type k=0) const
Get the kth super or subdiagonal.
Definition: Array.cc:2530
FloatMatrix real_matrix_type
Definition: fCMatrix.h:49
template OCTAVE_API std::ostream & operator<<(std::ostream &, const Array< bool > &)
FloatComplexRowVector extract_n(octave_idx_type c1, octave_idx_type n) const
Definition: fCRowVector.cc:228
#define MS_BOOL_OP_DECLS(M, S, API)
Definition: mx-op-decl.h:97
b
Definition: cellfun.cc:400
static M utsolve(const SM &U, const ColumnVector &Q, const M &m)
Definition: eigs-base.cc:100
for i
Definition: data.cc:5264
std::complex< float > FloatComplex
Definition: oct-cmplx.h:32
FloatComplexDiagMatrix complex_diag_matrix_type
Definition: fCMatrix.h:53
blas_trans_type
Definition: mx-defs.h:105
octave_value operator!(const octave_value &a)
Definition: ov.h:1573
FloatComplexRowVector & insert(const FloatRowVector &a, octave_idx_type c)
Definition: fCRowVector.cc:57
write the output to stdout if nargout is
Definition: load-save.cc:1612
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:3544
OCTAVE_API FloatComplexMatrix Givens(const FloatComplex &, const FloatComplex &)
Definition: fCMatrix.cc:3425
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
FloatComplexMatrix operator+=(FloatComplexMatrix &x, const FloatComplex &y)
Definition: fCMatrix.h:501
FloatComplexRowVector extract(octave_idx_type c1, octave_idx_type c2) const
Definition: fCRowVector.cc:213
OCTAVE_API FloatComplexMatrix max(const FloatComplex &c, const FloatComplexMatrix &m)
Definition: fCMatrix.cc:3751
dim_vector dv
Definition: sub2ind.cc:263
octave::stream os
Definition: file-io.cc:627
where the brackets indicate optional arguments and and character or cell array For character arrays the conversion is repeated for every row
Definition: str2double.cc:342