fCMatrix.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1994-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #if !defined (octave_FloatComplexMatrix_h)
00024 #define octave_FloatComplexMatrix_h 1
00025 
00026 #include "MArray.h"
00027 #include "MDiagArray2.h"
00028 #include "MatrixType.h"
00029 
00030 #include "mx-defs.h"
00031 #include "mx-op-decl.h"
00032 #include "oct-cmplx.h"
00033 #include "DET.h"
00034 
00035 class
00036 OCTAVE_API
00037 FloatComplexMatrix : public MArray<FloatComplex>
00038 {
00039 public:
00040 
00041   typedef FloatComplexColumnVector column_vector_type;
00042   typedef FloatComplexRowVector row_vector_type;
00043 
00044   typedef void (*solve_singularity_handler) (float rcon);
00045 
00046   FloatComplexMatrix (void) : MArray<FloatComplex> () { }
00047 
00048   FloatComplexMatrix (octave_idx_type r, octave_idx_type c)
00049     : MArray<FloatComplex> (dim_vector (r, c)) { }
00050 
00051   FloatComplexMatrix (octave_idx_type r, octave_idx_type c,
00052                       const FloatComplex& val)
00053     : MArray<FloatComplex> (dim_vector (r, c), val) { }
00054 
00055   FloatComplexMatrix (const dim_vector& dv)
00056     : MArray<FloatComplex> (dv.redim (2)) { }
00057 
00058   FloatComplexMatrix (const dim_vector& dv, const FloatComplex& val)
00059     : MArray<FloatComplex> (dv.redim (2), val) { }
00060 
00061   FloatComplexMatrix (const FloatComplexMatrix& a)
00062     : MArray<FloatComplex> (a) { }
00063 
00064   template <class U>
00065   FloatComplexMatrix (const MArray<U>& a)
00066     : MArray<FloatComplex> (a.as_matrix ()) { }
00067 
00068   template <class U>
00069   FloatComplexMatrix (const Array<U>& a)
00070     : MArray<FloatComplex> (a.as_matrix ()) { }
00071 
00072   explicit FloatComplexMatrix (const FloatMatrix& a);
00073 
00074   explicit FloatComplexMatrix (const FloatRowVector& rv);
00075 
00076   explicit FloatComplexMatrix (const FloatColumnVector& cv);
00077 
00078   explicit FloatComplexMatrix (const FloatDiagMatrix& a);
00079 
00080   explicit FloatComplexMatrix (const FloatComplexRowVector& rv);
00081 
00082   explicit FloatComplexMatrix (const FloatComplexColumnVector& cv);
00083 
00084   explicit FloatComplexMatrix (const FloatComplexDiagMatrix& a);
00085 
00086   explicit FloatComplexMatrix (const boolMatrix& a);
00087 
00088   explicit FloatComplexMatrix (const charMatrix& a);
00089 
00090   FloatComplexMatrix (const FloatMatrix& re, const FloatMatrix& im);
00091 
00092   FloatComplexMatrix& operator = (const FloatComplexMatrix& a)
00093     {
00094       MArray<FloatComplex>::operator = (a);
00095       return *this;
00096     }
00097 
00098   bool operator == (const FloatComplexMatrix& a) const;
00099   bool operator != (const FloatComplexMatrix& a) const;
00100 
00101   bool is_hermitian (void) const;
00102 
00103   // destructive insert/delete/reorder operations
00104 
00105   FloatComplexMatrix& insert (const FloatMatrix& a, octave_idx_type r, octave_idx_type c);
00106   FloatComplexMatrix& insert (const FloatRowVector& a, octave_idx_type r, octave_idx_type c);
00107   FloatComplexMatrix& insert (const FloatColumnVector& a, octave_idx_type r, octave_idx_type c);
00108   FloatComplexMatrix& insert (const FloatDiagMatrix& a, octave_idx_type r, octave_idx_type c);
00109 
00110   FloatComplexMatrix& insert (const FloatComplexMatrix& a, octave_idx_type r, octave_idx_type c);
00111   FloatComplexMatrix& insert (const FloatComplexRowVector& a, octave_idx_type r, octave_idx_type c);
00112   FloatComplexMatrix& insert (const FloatComplexColumnVector& a, octave_idx_type r, octave_idx_type c);
00113   FloatComplexMatrix& insert (const FloatComplexDiagMatrix& a, octave_idx_type r, octave_idx_type c);
00114 
00115   FloatComplexMatrix& fill (float val);
00116   FloatComplexMatrix& fill (const FloatComplex& val);
00117   FloatComplexMatrix& fill (float val, octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2);
00118   FloatComplexMatrix& fill (const FloatComplex& val, octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2);
00119 
00120   FloatComplexMatrix append (const FloatMatrix& a) const;
00121   FloatComplexMatrix append (const FloatRowVector& a) const;
00122   FloatComplexMatrix append (const FloatColumnVector& a) const;
00123   FloatComplexMatrix append (const FloatDiagMatrix& a) const;
00124 
00125   FloatComplexMatrix append (const FloatComplexMatrix& a) const;
00126   FloatComplexMatrix append (const FloatComplexRowVector& a) const;
00127   FloatComplexMatrix append (const FloatComplexColumnVector& a) const;
00128   FloatComplexMatrix append (const FloatComplexDiagMatrix& a) const;
00129 
00130   FloatComplexMatrix stack (const FloatMatrix& a) const;
00131   FloatComplexMatrix stack (const FloatRowVector& a) const;
00132   FloatComplexMatrix stack (const FloatColumnVector& a) const;
00133   FloatComplexMatrix stack (const FloatDiagMatrix& a) const;
00134 
00135   FloatComplexMatrix stack (const FloatComplexMatrix& a) const;
00136   FloatComplexMatrix stack (const FloatComplexRowVector& a) const;
00137   FloatComplexMatrix stack (const FloatComplexColumnVector& a) const;
00138   FloatComplexMatrix stack (const FloatComplexDiagMatrix& a) const;
00139 
00140   FloatComplexMatrix hermitian (void) const
00141     { return MArray<FloatComplex>::hermitian (std::conj); }
00142   FloatComplexMatrix transpose (void) const
00143     { return MArray<FloatComplex>::transpose (); }
00144 
00145   friend OCTAVE_API FloatComplexMatrix conj (const FloatComplexMatrix& a);
00146 
00147   // resize is the destructive equivalent for this one
00148 
00149   FloatComplexMatrix extract (octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const;
00150 
00151   FloatComplexMatrix extract_n (octave_idx_type r1, octave_idx_type c1, octave_idx_type nr, octave_idx_type nc) const;
00152 
00153   // extract row or column i.
00154 
00155   FloatComplexRowVector row (octave_idx_type i) const;
00156 
00157   FloatComplexColumnVector column (octave_idx_type i) const;
00158 
00159   void resize (octave_idx_type nr, octave_idx_type nc,
00160                const FloatComplex& rfv = resize_fill_value ())
00161   {
00162     MArray<FloatComplex>::resize (dim_vector (nr, nc), rfv);
00163   }
00164 
00165 private:
00166   FloatComplexMatrix tinverse (MatrixType &mattype, octave_idx_type& info,
00167                           float& rcon, int force, int calc_cond) const;
00168 
00169   FloatComplexMatrix finverse (MatrixType &mattype, octave_idx_type& info,
00170                           float& rcon, int force, int calc_cond) const;
00171 
00172 public:
00173   FloatComplexMatrix inverse (void) const;
00174   FloatComplexMatrix inverse (octave_idx_type& info) const;
00175   FloatComplexMatrix inverse (octave_idx_type& info, float& rcon, int force = 0,
00176                          int calc_cond = 1) const;
00177 
00178   FloatComplexMatrix inverse (MatrixType &mattype) const;
00179   FloatComplexMatrix inverse (MatrixType &mattype, octave_idx_type& info) const;
00180   FloatComplexMatrix inverse (MatrixType &mattype, octave_idx_type& info,
00181                          float& rcon, int force = 0,
00182                          int calc_cond = 1) const;
00183 
00184   FloatComplexMatrix pseudo_inverse (float tol = 0.0) const;
00185 
00186   FloatComplexMatrix fourier (void) const;
00187   FloatComplexMatrix ifourier (void) const;
00188 
00189   FloatComplexMatrix fourier2d (void) const;
00190   FloatComplexMatrix ifourier2d (void) const;
00191 
00192   FloatComplexDET determinant (void) const;
00193   FloatComplexDET determinant (octave_idx_type& info) const;
00194   FloatComplexDET determinant (octave_idx_type& info, float& rcon, int calc_cond = 1) const;
00195   FloatComplexDET determinant (MatrixType &mattype, octave_idx_type& info,
00196                                float& rcon, int calc_cond = 1) const;
00197 
00198   float rcond (void) const;
00199   float rcond (MatrixType &mattype) const;
00200 
00201 private:
00202   // Upper triangular matrix solvers
00203   FloatComplexMatrix utsolve (MatrixType &typ, const FloatComplexMatrix& b,
00204                   octave_idx_type& info, float& rcon,
00205                   solve_singularity_handler sing_handler,
00206                   bool calc_cond = false, blas_trans_type transt = blas_no_trans) const;
00207 
00208   // Lower triangular matrix solvers
00209   FloatComplexMatrix ltsolve (MatrixType &typ, const FloatComplexMatrix& b,
00210                   octave_idx_type& info, float& rcon,
00211                   solve_singularity_handler sing_handler,
00212                   bool calc_cond = false, blas_trans_type transt = blas_no_trans) const;
00213 
00214   // Full matrix solvers (umfpack/cholesky)
00215   FloatComplexMatrix fsolve (MatrixType &typ, const FloatComplexMatrix& b,
00216                  octave_idx_type& info, float& rcon,
00217                  solve_singularity_handler sing_handler,
00218                  bool calc_cond = false) const;
00219 
00220 public:
00221   // Generic interface to solver with no probing of type
00222   FloatComplexMatrix solve (MatrixType &typ, const FloatMatrix& b) const;
00223   FloatComplexMatrix solve (MatrixType &typ, const FloatMatrix& b,
00224                        octave_idx_type& info) const;
00225   FloatComplexMatrix solve (MatrixType &typ, const FloatMatrix& b,
00226                        octave_idx_type& info, float& rcon) const;
00227   FloatComplexMatrix solve (MatrixType &typ, const FloatMatrix& b, octave_idx_type& info,
00228                        float& rcon, solve_singularity_handler sing_handler,
00229                        bool singular_fallback = true,
00230                        blas_trans_type transt = blas_no_trans) const;
00231 
00232   FloatComplexMatrix solve (MatrixType &typ, const FloatComplexMatrix& b) const;
00233   FloatComplexMatrix solve (MatrixType &typ, const FloatComplexMatrix& b,
00234                        octave_idx_type& info) const;
00235   FloatComplexMatrix solve (MatrixType &typ, const FloatComplexMatrix& b,
00236                        octave_idx_type& info, float& rcon) const;
00237   FloatComplexMatrix solve (MatrixType &typ, const FloatComplexMatrix& b,
00238                        octave_idx_type& info, float& rcon,
00239                        solve_singularity_handler sing_handler,
00240                        bool singular_fallback = true,
00241                        blas_trans_type transt = blas_no_trans) const;
00242 
00243   FloatComplexColumnVector solve (MatrixType &typ, const FloatColumnVector& b) const;
00244   FloatComplexColumnVector solve (MatrixType &typ, const FloatColumnVector& b,
00245                              octave_idx_type& info) const;
00246   FloatComplexColumnVector solve (MatrixType &typ, const FloatColumnVector& b,
00247                              octave_idx_type& info, float& rcon) const;
00248   FloatComplexColumnVector solve (MatrixType &typ, const FloatColumnVector& b,
00249                              octave_idx_type& info, float& rcon,
00250                              solve_singularity_handler sing_handler,
00251                              blas_trans_type transt = blas_no_trans) const;
00252 
00253   FloatComplexColumnVector solve (MatrixType &typ,
00254                              const FloatComplexColumnVector& b) const;
00255   FloatComplexColumnVector solve (MatrixType &typ, const FloatComplexColumnVector& b,
00256                              octave_idx_type& info) const;
00257   FloatComplexColumnVector solve (MatrixType &typ, const FloatComplexColumnVector& b,
00258                              octave_idx_type& info, float& rcon) const;
00259   FloatComplexColumnVector solve (MatrixType &typ, const FloatComplexColumnVector& b,
00260                              octave_idx_type& info, float& rcon,
00261                              solve_singularity_handler sing_handler,
00262                              blas_trans_type transt = blas_no_trans) const;
00263 
00264   // Generic interface to solver with probing of type
00265   FloatComplexMatrix solve (const FloatMatrix& b) const;
00266   FloatComplexMatrix solve (const FloatMatrix& b, octave_idx_type& info) const;
00267   FloatComplexMatrix solve (const FloatMatrix& b, octave_idx_type& info, float& rcon) const;
00268   FloatComplexMatrix solve (const FloatMatrix& b, octave_idx_type& info, float& rcon,
00269                        solve_singularity_handler sing_handler,
00270                        blas_trans_type transt = blas_no_trans) const;
00271 
00272   FloatComplexMatrix solve (const FloatComplexMatrix& b) const;
00273   FloatComplexMatrix solve (const FloatComplexMatrix& b, octave_idx_type& info) const;
00274   FloatComplexMatrix solve (const FloatComplexMatrix& b, octave_idx_type& info, float& rcon) const;
00275   FloatComplexMatrix solve (const FloatComplexMatrix& b, octave_idx_type& info, float& rcon,
00276                        solve_singularity_handler sing_handler,
00277                        blas_trans_type transt = blas_no_trans) const;
00278 
00279   FloatComplexColumnVector solve (const FloatColumnVector& b) const;
00280   FloatComplexColumnVector solve (const FloatColumnVector& b, octave_idx_type& info) const;
00281   FloatComplexColumnVector solve (const FloatColumnVector& b, octave_idx_type& info,
00282                              float& rcon) const;
00283   FloatComplexColumnVector solve (const FloatColumnVector& b, octave_idx_type& info, float& rcon,
00284                              solve_singularity_handler sing_handler,
00285                              blas_trans_type transt = blas_no_trans) const;
00286 
00287   FloatComplexColumnVector solve (const FloatComplexColumnVector& b) const;
00288   FloatComplexColumnVector solve (const FloatComplexColumnVector& b, octave_idx_type& info) const;
00289   FloatComplexColumnVector solve (const FloatComplexColumnVector& b, octave_idx_type& info,
00290                              float& rcon) const;
00291   FloatComplexColumnVector solve (const FloatComplexColumnVector& b, octave_idx_type& info,
00292                              float& rcon,
00293                              solve_singularity_handler sing_handler,
00294                              blas_trans_type transt = blas_no_trans) const;
00295 
00296   FloatComplexMatrix lssolve (const FloatMatrix& b) const;
00297   FloatComplexMatrix lssolve (const FloatMatrix& b, octave_idx_type& info) const;
00298   FloatComplexMatrix lssolve (const FloatMatrix& b, octave_idx_type& info,
00299                          octave_idx_type& rank) const;
00300   FloatComplexMatrix lssolve (const FloatMatrix& b, octave_idx_type& info,
00301                          octave_idx_type& rank, float& rcon) const;
00302 
00303   FloatComplexMatrix lssolve (const FloatComplexMatrix& b) const;
00304   FloatComplexMatrix lssolve (const FloatComplexMatrix& b, octave_idx_type& info) const;
00305   FloatComplexMatrix lssolve (const FloatComplexMatrix& b, octave_idx_type& info,
00306                          octave_idx_type& rank) const;
00307   FloatComplexMatrix lssolve (const FloatComplexMatrix& b, octave_idx_type& info,
00308                          octave_idx_type& rank, float& rcon) const;
00309 
00310   FloatComplexColumnVector lssolve (const FloatColumnVector& b) const;
00311   FloatComplexColumnVector lssolve (const FloatColumnVector& b,
00312                                octave_idx_type& info) const;
00313   FloatComplexColumnVector lssolve (const FloatColumnVector& b, octave_idx_type& info,
00314                                octave_idx_type& rank) const;
00315   FloatComplexColumnVector lssolve (const FloatColumnVector& b, octave_idx_type& info,
00316                                octave_idx_type& rank, float& rcon) const;
00317 
00318   FloatComplexColumnVector lssolve (const FloatComplexColumnVector& b) const;
00319   FloatComplexColumnVector lssolve (const FloatComplexColumnVector& b,
00320                                octave_idx_type& info) const;
00321   FloatComplexColumnVector lssolve (const FloatComplexColumnVector& b,
00322                                octave_idx_type& info,
00323                                octave_idx_type& rank) const;
00324   FloatComplexColumnVector lssolve (const FloatComplexColumnVector& b,
00325                                octave_idx_type& info,
00326                                octave_idx_type& rank, float& rcon) const;
00327 
00328   // matrix by diagonal matrix -> matrix operations
00329 
00330   FloatComplexMatrix& operator += (const FloatDiagMatrix& a);
00331   FloatComplexMatrix& operator -= (const FloatDiagMatrix& a);
00332 
00333   FloatComplexMatrix& operator += (const FloatComplexDiagMatrix& a);
00334   FloatComplexMatrix& operator -= (const FloatComplexDiagMatrix& a);
00335 
00336   // matrix by matrix -> matrix operations
00337 
00338   FloatComplexMatrix& operator += (const FloatMatrix& a);
00339   FloatComplexMatrix& operator -= (const FloatMatrix& a);
00340 
00341   // unary operations
00342 
00343   boolMatrix operator ! (void) const;
00344 
00345   // other operations
00346 
00347   bool any_element_is_nan (void) const;
00348   bool any_element_is_inf_or_nan (void) const;
00349   bool all_elements_are_real (void) const;
00350   bool all_integers (float& max_val, float& min_val) const;
00351   bool too_large_for_float (void) const;
00352 
00353   boolMatrix all (int dim = -1) const;
00354   boolMatrix any (int dim = -1) const;
00355 
00356   FloatComplexMatrix cumprod (int dim = -1) const;
00357   FloatComplexMatrix cumsum (int dim = -1) const;
00358   FloatComplexMatrix prod (int dim = -1) const;
00359   FloatComplexMatrix sum (int dim = -1) const;
00360   FloatComplexMatrix sumsq (int dim = -1) const;
00361   FloatMatrix abs (void) const;
00362 
00363   FloatComplexMatrix diag (octave_idx_type k = 0) const;
00364 
00365   bool row_is_real_only (octave_idx_type) const;
00366   bool column_is_real_only (octave_idx_type) const;
00367 
00368   FloatComplexColumnVector row_min (void) const;
00369   FloatComplexColumnVector row_max (void) const;
00370 
00371   FloatComplexColumnVector row_min (Array<octave_idx_type>& index) const;
00372   FloatComplexColumnVector row_max (Array<octave_idx_type>& index) const;
00373 
00374   FloatComplexRowVector column_min (void) const;
00375   FloatComplexRowVector column_max (void) const;
00376 
00377   FloatComplexRowVector column_min (Array<octave_idx_type>& index) const;
00378   FloatComplexRowVector column_max (Array<octave_idx_type>& index) const;
00379 
00380   // i/o
00381 
00382   friend OCTAVE_API std::ostream& operator << (std::ostream& os, const FloatComplexMatrix& a);
00383   friend OCTAVE_API std::istream& operator >> (std::istream& is, FloatComplexMatrix& a);
00384 
00385   static FloatComplex resize_fill_value (void) { return FloatComplex (0.0, 0.0); }
00386 
00387 };
00388 
00389 extern OCTAVE_API FloatComplexMatrix conj (const FloatComplexMatrix& a);
00390 
00391 // column vector by row vector -> matrix operations
00392 
00393 extern OCTAVE_API FloatComplexMatrix
00394 operator * (const FloatColumnVector& a, const FloatComplexRowVector& b);
00395 
00396 extern OCTAVE_API FloatComplexMatrix
00397 operator * (const FloatComplexColumnVector& a, const FloatRowVector& b);
00398 
00399 extern OCTAVE_API FloatComplexMatrix
00400 operator * (const FloatComplexColumnVector& a, const FloatComplexRowVector& b);
00401 
00402 extern OCTAVE_API FloatComplexMatrix
00403 Givens (const FloatComplex&, const FloatComplex&);
00404 
00405 extern OCTAVE_API FloatComplexMatrix
00406 Sylvester (const FloatComplexMatrix&, const FloatComplexMatrix&, const FloatComplexMatrix&);
00407 
00408 extern OCTAVE_API FloatComplexMatrix
00409 xgemm (const FloatComplexMatrix& a, const FloatComplexMatrix& b,
00410        blas_trans_type transa = blas_no_trans,
00411        blas_trans_type transb = blas_no_trans);
00412 
00413 extern OCTAVE_API FloatComplexMatrix operator * (const FloatMatrix&,        const FloatComplexMatrix&);
00414 extern OCTAVE_API FloatComplexMatrix operator * (const FloatComplexMatrix&, const FloatMatrix&);
00415 extern OCTAVE_API FloatComplexMatrix operator * (const FloatComplexMatrix&, const FloatComplexMatrix&);
00416 
00417 extern OCTAVE_API FloatComplexMatrix min (const FloatComplex& c, const FloatComplexMatrix& m);
00418 extern OCTAVE_API FloatComplexMatrix min (const FloatComplexMatrix& m, const FloatComplex& c);
00419 extern OCTAVE_API FloatComplexMatrix min (const FloatComplexMatrix& a, const FloatComplexMatrix& b);
00420 
00421 extern OCTAVE_API FloatComplexMatrix max (const FloatComplex& c, const FloatComplexMatrix& m);
00422 extern OCTAVE_API FloatComplexMatrix max (const FloatComplexMatrix& m, const FloatComplex& c);
00423 extern OCTAVE_API FloatComplexMatrix max (const FloatComplexMatrix& a, const FloatComplexMatrix& b);
00424 
00425 extern OCTAVE_API FloatComplexMatrix linspace (const FloatComplexColumnVector& x1,
00426                                                const FloatComplexColumnVector& x2,
00427                                                octave_idx_type n);
00428 
00429 MS_CMP_OP_DECLS (FloatComplexMatrix, FloatComplex, OCTAVE_API)
00430 MS_BOOL_OP_DECLS (FloatComplexMatrix, FloatComplex, OCTAVE_API)
00431 
00432 SM_CMP_OP_DECLS (FloatComplex, FloatComplexMatrix, OCTAVE_API)
00433 SM_BOOL_OP_DECLS (FloatComplex, FloatComplexMatrix, OCTAVE_API)
00434 
00435 MM_CMP_OP_DECLS (FloatComplexMatrix, FloatComplexMatrix, OCTAVE_API)
00436 MM_BOOL_OP_DECLS (FloatComplexMatrix, FloatComplexMatrix, OCTAVE_API)
00437 
00438 MARRAY_FORWARD_DEFS (MArray, FloatComplexMatrix, FloatComplex)
00439 
00440 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines