CMatrix.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_ComplexMatrix_h)
00024 #define octave_ComplexMatrix_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 ComplexMatrix : public MArray<Complex>
00038 {
00039 public:
00040 
00041   typedef ComplexColumnVector column_vector_type;
00042   typedef ComplexRowVector row_vector_type;
00043 
00044   typedef void (*solve_singularity_handler) (double rcon);
00045 
00046   ComplexMatrix (void) : MArray<Complex> () { }
00047 
00048   ComplexMatrix (octave_idx_type r, octave_idx_type c)
00049     : MArray<Complex> (dim_vector (r, c)) { }
00050 
00051   ComplexMatrix (octave_idx_type r, octave_idx_type c, const Complex& val)
00052     : MArray<Complex> (dim_vector (r, c), val) { }
00053 
00054   ComplexMatrix (const dim_vector& dv) : MArray<Complex> (dv.redim (2)) { }
00055 
00056   ComplexMatrix (const dim_vector& dv, const Complex& val)
00057     : MArray<Complex> (dv.redim (2), val) { }
00058 
00059   ComplexMatrix (const ComplexMatrix& a) : MArray<Complex> (a) { }
00060 
00061   template <class U>
00062   ComplexMatrix (const MArray<U>& a) : MArray<Complex> (a.as_matrix ()) { }
00063 
00064   template <class U>
00065   ComplexMatrix (const Array<U>& a) : MArray<Complex> (a.as_matrix ()) { }
00066 
00067   ComplexMatrix (const Matrix& re, const Matrix& im);
00068 
00069   explicit ComplexMatrix (const Matrix& a);
00070 
00071   explicit ComplexMatrix (const RowVector& rv);
00072 
00073   explicit ComplexMatrix (const ColumnVector& cv);
00074 
00075   explicit ComplexMatrix (const DiagMatrix& a);
00076 
00077   explicit ComplexMatrix (const ComplexRowVector& rv);
00078 
00079   explicit ComplexMatrix (const ComplexColumnVector& cv);
00080 
00081   explicit ComplexMatrix (const ComplexDiagMatrix& a);
00082 
00083   explicit ComplexMatrix (const boolMatrix& a);
00084 
00085   explicit ComplexMatrix (const charMatrix& a);
00086 
00087   ComplexMatrix& operator = (const ComplexMatrix& a)
00088     {
00089       MArray<Complex>::operator = (a);
00090       return *this;
00091     }
00092 
00093   bool operator == (const ComplexMatrix& a) const;
00094   bool operator != (const ComplexMatrix& a) const;
00095 
00096   bool is_hermitian (void) const;
00097 
00098   // destructive insert/delete/reorder operations
00099 
00100   ComplexMatrix& insert (const Matrix& a, octave_idx_type r, octave_idx_type c);
00101   ComplexMatrix& insert (const RowVector& a, octave_idx_type r, octave_idx_type c);
00102   ComplexMatrix& insert (const ColumnVector& a, octave_idx_type r, octave_idx_type c);
00103   ComplexMatrix& insert (const DiagMatrix& a, octave_idx_type r, octave_idx_type c);
00104 
00105   ComplexMatrix& insert (const ComplexMatrix& a, octave_idx_type r, octave_idx_type c);
00106   ComplexMatrix& insert (const ComplexRowVector& a, octave_idx_type r, octave_idx_type c);
00107   ComplexMatrix& insert (const ComplexColumnVector& a, octave_idx_type r, octave_idx_type c);
00108   ComplexMatrix& insert (const ComplexDiagMatrix& a, octave_idx_type r, octave_idx_type c);
00109 
00110   ComplexMatrix& fill (double val);
00111   ComplexMatrix& fill (const Complex& val);
00112   ComplexMatrix& fill (double val, octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2);
00113   ComplexMatrix& fill (const Complex& val, octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2);
00114 
00115   ComplexMatrix append (const Matrix& a) const;
00116   ComplexMatrix append (const RowVector& a) const;
00117   ComplexMatrix append (const ColumnVector& a) const;
00118   ComplexMatrix append (const DiagMatrix& a) const;
00119 
00120   ComplexMatrix append (const ComplexMatrix& a) const;
00121   ComplexMatrix append (const ComplexRowVector& a) const;
00122   ComplexMatrix append (const ComplexColumnVector& a) const;
00123   ComplexMatrix append (const ComplexDiagMatrix& a) const;
00124 
00125   ComplexMatrix stack (const Matrix& a) const;
00126   ComplexMatrix stack (const RowVector& a) const;
00127   ComplexMatrix stack (const ColumnVector& a) const;
00128   ComplexMatrix stack (const DiagMatrix& a) const;
00129 
00130   ComplexMatrix stack (const ComplexMatrix& a) const;
00131   ComplexMatrix stack (const ComplexRowVector& a) const;
00132   ComplexMatrix stack (const ComplexColumnVector& a) const;
00133   ComplexMatrix stack (const ComplexDiagMatrix& a) const;
00134 
00135   ComplexMatrix hermitian (void) const
00136     { return MArray<Complex>::hermitian (std::conj); }
00137   ComplexMatrix transpose (void) const
00138     { return MArray<Complex>::transpose (); }
00139 
00140   friend OCTAVE_API ComplexMatrix conj (const ComplexMatrix& a);
00141 
00142   // resize is the destructive equivalent for this one
00143 
00144   ComplexMatrix extract (octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const;
00145 
00146   ComplexMatrix extract_n (octave_idx_type r1, octave_idx_type c1, octave_idx_type nr, octave_idx_type nc) const;
00147 
00148   // extract row or column i.
00149 
00150   ComplexRowVector row (octave_idx_type i) const;
00151 
00152   ComplexColumnVector column (octave_idx_type i) const;
00153 
00154   void resize (octave_idx_type nr, octave_idx_type nc,
00155                const Complex& rfv = resize_fill_value ())
00156   {
00157     MArray<Complex>::resize (dim_vector (nr, nc), rfv);
00158   }
00159 
00160 private:
00161   ComplexMatrix tinverse (MatrixType &mattype, octave_idx_type& info,
00162                           double& rcon, int force, int calc_cond) const;
00163 
00164   ComplexMatrix finverse (MatrixType &mattype, octave_idx_type& info,
00165                           double& rcon, int force, int calc_cond) const;
00166 
00167 public:
00168   ComplexMatrix inverse (void) const;
00169   ComplexMatrix inverse (octave_idx_type& info) const;
00170   ComplexMatrix inverse (octave_idx_type& info, double& rcon, int force = 0,
00171                          int calc_cond = 1) const;
00172 
00173   ComplexMatrix inverse (MatrixType &mattype) const;
00174   ComplexMatrix inverse (MatrixType &mattype, octave_idx_type& info) const;
00175   ComplexMatrix inverse (MatrixType &mattype, octave_idx_type& info,
00176                          double& rcon, int force = 0,
00177                          int calc_cond = 1) const;
00178 
00179   ComplexMatrix pseudo_inverse (double tol = 0.0) const;
00180 
00181   ComplexMatrix fourier (void) const;
00182   ComplexMatrix ifourier (void) const;
00183 
00184   ComplexMatrix fourier2d (void) const;
00185   ComplexMatrix ifourier2d (void) const;
00186 
00187   ComplexDET determinant (void) const;
00188   ComplexDET determinant (octave_idx_type& info) const;
00189   ComplexDET determinant (octave_idx_type& info, double& rcon, int calc_cond = 1) const;
00190   ComplexDET determinant (MatrixType &mattype, octave_idx_type& info,
00191                           double& rcon, int calc_cond = 1) const;
00192 
00193   double rcond (void) const;
00194   double rcond (MatrixType &mattype) const;
00195 
00196 private:
00197   // Upper triangular matrix solvers
00198   ComplexMatrix utsolve (MatrixType &typ, const ComplexMatrix& b,
00199                   octave_idx_type& info, double& rcon,
00200                   solve_singularity_handler sing_handler,
00201                   bool calc_cond = false,
00202                   blas_trans_type transt = blas_no_trans) const;
00203 
00204   // Lower triangular matrix solvers
00205   ComplexMatrix ltsolve (MatrixType &typ, const ComplexMatrix& b,
00206                   octave_idx_type& info, double& rcon,
00207                   solve_singularity_handler sing_handler,
00208                   bool calc_cond = false, blas_trans_type transt = blas_no_trans) const;
00209 
00210   // Full matrix solvers (umfpack/cholesky)
00211   ComplexMatrix fsolve (MatrixType &typ, const ComplexMatrix& b,
00212                  octave_idx_type& info, double& rcon,
00213                  solve_singularity_handler sing_handler,
00214                  bool calc_cond = false) const;
00215 
00216 public:
00217   // Generic interface to solver with no probing of type
00218   ComplexMatrix solve (MatrixType &typ, const Matrix& b) const;
00219   ComplexMatrix solve (MatrixType &typ, const Matrix& b,
00220                        octave_idx_type& info) const;
00221   ComplexMatrix solve (MatrixType &typ, const Matrix& b,
00222                        octave_idx_type& info, double& rcon) const;
00223   ComplexMatrix solve (MatrixType &typ, const Matrix& b, octave_idx_type& info,
00224                        double& rcon, solve_singularity_handler sing_handler,
00225                        bool singular_fallback = true,
00226                        blas_trans_type transt = blas_no_trans) const;
00227 
00228   ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b) const;
00229   ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b,
00230                        octave_idx_type& info) const;
00231   ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b,
00232                        octave_idx_type& info, double& rcon) const;
00233   ComplexMatrix solve (MatrixType &typ, const ComplexMatrix& b,
00234                        octave_idx_type& info, double& rcon,
00235                        solve_singularity_handler sing_handler,
00236                        bool singular_fallback = true,
00237                        blas_trans_type transt = blas_no_trans) const;
00238 
00239   ComplexColumnVector solve (MatrixType &typ, const ColumnVector& b) const;
00240   ComplexColumnVector solve (MatrixType &typ, const ColumnVector& b,
00241                              octave_idx_type& info) const;
00242   ComplexColumnVector solve (MatrixType &typ, const ColumnVector& b,
00243                              octave_idx_type& info, double& rcon) const;
00244   ComplexColumnVector solve (MatrixType &typ, const ColumnVector& b,
00245                              octave_idx_type& info, double& rcon,
00246                              solve_singularity_handler sing_handler,
00247                              blas_trans_type transt = blas_no_trans) const;
00248 
00249   ComplexColumnVector solve (MatrixType &typ,
00250                              const ComplexColumnVector& b) const;
00251   ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b,
00252                              octave_idx_type& info) const;
00253   ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b,
00254                              octave_idx_type& info, double& rcon) const;
00255   ComplexColumnVector solve (MatrixType &typ, const ComplexColumnVector& b,
00256                              octave_idx_type& info, double& rcon,
00257                              solve_singularity_handler sing_handler,
00258                              blas_trans_type transt = blas_no_trans) const;
00259 
00260   // Generic interface to solver with probing of type
00261   ComplexMatrix solve (const Matrix& b) const;
00262   ComplexMatrix solve (const Matrix& b, octave_idx_type& info) const;
00263   ComplexMatrix solve (const Matrix& b, octave_idx_type& info, double& rcon) const;
00264   ComplexMatrix solve (const Matrix& b, octave_idx_type& info, double& rcon,
00265                        solve_singularity_handler sing_handler,
00266                        blas_trans_type transt = blas_no_trans) const;
00267 
00268   ComplexMatrix solve (const ComplexMatrix& b) const;
00269   ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info) const;
00270   ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info, double& rcon) const;
00271   ComplexMatrix solve (const ComplexMatrix& b, octave_idx_type& info, double& rcon,
00272                        solve_singularity_handler sing_handler,
00273                        blas_trans_type transt = blas_no_trans) const;
00274 
00275   ComplexColumnVector solve (const ColumnVector& b) const;
00276   ComplexColumnVector solve (const ColumnVector& b, octave_idx_type& info) const;
00277   ComplexColumnVector solve (const ColumnVector& b, octave_idx_type& info,
00278                              double& rcon) const;
00279   ComplexColumnVector solve (const ColumnVector& b, octave_idx_type& info, double& rcon,
00280                              solve_singularity_handler sing_handler,
00281                              blas_trans_type transt = blas_no_trans) const;
00282 
00283   ComplexColumnVector solve (const ComplexColumnVector& b) const;
00284   ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info) const;
00285   ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info,
00286                              double& rcon) const;
00287   ComplexColumnVector solve (const ComplexColumnVector& b, octave_idx_type& info,
00288                              double& rcon, solve_singularity_handler sing_handler,
00289                              blas_trans_type transt = blas_no_trans) const;
00290 
00291   ComplexMatrix lssolve (const Matrix& b) const;
00292   ComplexMatrix lssolve (const Matrix& b, octave_idx_type& info) const;
00293   ComplexMatrix lssolve (const Matrix& b, octave_idx_type& info,
00294                          octave_idx_type& rank) const;
00295   ComplexMatrix lssolve (const Matrix& b, octave_idx_type& info,
00296                          octave_idx_type& rank, double& rcon) const;
00297 
00298   ComplexMatrix lssolve (const ComplexMatrix& b) const;
00299   ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info) const;
00300   ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info,
00301                          octave_idx_type& rank) const;
00302   ComplexMatrix lssolve (const ComplexMatrix& b, octave_idx_type& info,
00303                          octave_idx_type& rank, double& rcon) const;
00304 
00305   ComplexColumnVector lssolve (const ColumnVector& b) const;
00306   ComplexColumnVector lssolve (const ColumnVector& b,
00307                                octave_idx_type& info) const;
00308   ComplexColumnVector lssolve (const ColumnVector& b, octave_idx_type& info,
00309                                octave_idx_type& rank) const;
00310   ComplexColumnVector lssolve (const ColumnVector& b, octave_idx_type& info,
00311                                octave_idx_type& rank, double& rcon) const;
00312 
00313   ComplexColumnVector lssolve (const ComplexColumnVector& b) const;
00314   ComplexColumnVector lssolve (const ComplexColumnVector& b,
00315                                octave_idx_type& info) const;
00316   ComplexColumnVector lssolve (const ComplexColumnVector& b,
00317                                octave_idx_type& info,
00318                                octave_idx_type& rank) const;
00319   ComplexColumnVector lssolve (const ComplexColumnVector& b,
00320                                octave_idx_type& info,
00321                                octave_idx_type& rank, double& rcon) const;
00322 
00323   // matrix by diagonal matrix -> matrix operations
00324 
00325   ComplexMatrix& operator += (const DiagMatrix& a);
00326   ComplexMatrix& operator -= (const DiagMatrix& a);
00327 
00328   ComplexMatrix& operator += (const ComplexDiagMatrix& a);
00329   ComplexMatrix& operator -= (const ComplexDiagMatrix& a);
00330 
00331   // matrix by matrix -> matrix operations
00332 
00333   ComplexMatrix& operator += (const Matrix& a);
00334   ComplexMatrix& operator -= (const Matrix& a);
00335 
00336   // unary operations
00337 
00338   boolMatrix operator ! (void) const;
00339 
00340   // other operations
00341 
00342   bool any_element_is_nan (void) const;
00343   bool any_element_is_inf_or_nan (void) const;
00344   bool all_elements_are_real (void) const;
00345   bool all_integers (double& max_val, double& min_val) const;
00346   bool too_large_for_float (void) const;
00347 
00348   boolMatrix all (int dim = -1) const;
00349   boolMatrix any (int dim = -1) const;
00350 
00351   ComplexMatrix cumprod (int dim = -1) const;
00352   ComplexMatrix cumsum (int dim = -1) const;
00353   ComplexMatrix prod (int dim = -1) const;
00354   ComplexMatrix sum (int dim = -1) const;
00355   ComplexMatrix sumsq (int dim = -1) const;
00356   Matrix abs (void) const;
00357 
00358   ComplexMatrix diag (octave_idx_type k = 0) const;
00359 
00360   bool row_is_real_only (octave_idx_type) const;
00361   bool column_is_real_only (octave_idx_type) const;
00362 
00363   ComplexColumnVector row_min (void) const;
00364   ComplexColumnVector row_max (void) const;
00365 
00366   ComplexColumnVector row_min (Array<octave_idx_type>& index) const;
00367   ComplexColumnVector row_max (Array<octave_idx_type>& index) const;
00368 
00369   ComplexRowVector column_min (void) const;
00370   ComplexRowVector column_max (void) const;
00371 
00372   ComplexRowVector column_min (Array<octave_idx_type>& index) const;
00373   ComplexRowVector column_max (Array<octave_idx_type>& index) const;
00374 
00375   // i/o
00376 
00377   friend OCTAVE_API std::ostream& operator << (std::ostream& os, const ComplexMatrix& a);
00378   friend OCTAVE_API std::istream& operator >> (std::istream& is, ComplexMatrix& a);
00379 
00380   static Complex resize_fill_value (void) { return Complex (0.0, 0.0); }
00381 
00382 };
00383 
00384 extern OCTAVE_API ComplexMatrix conj (const ComplexMatrix& a);
00385 
00386 // column vector by row vector -> matrix operations
00387 
00388 extern OCTAVE_API ComplexMatrix
00389 operator * (const ColumnVector& a, const ComplexRowVector& b);
00390 
00391 extern OCTAVE_API ComplexMatrix
00392 operator * (const ComplexColumnVector& a, const RowVector& b);
00393 
00394 extern OCTAVE_API ComplexMatrix
00395 operator * (const ComplexColumnVector& a, const ComplexRowVector& b);
00396 
00397 extern OCTAVE_API ComplexMatrix
00398 Givens (const Complex&, const Complex&);
00399 
00400 extern OCTAVE_API ComplexMatrix
00401 Sylvester (const ComplexMatrix&, const ComplexMatrix&, const ComplexMatrix&);
00402 
00403 extern OCTAVE_API ComplexMatrix
00404 xgemm (const ComplexMatrix& a, const ComplexMatrix& b,
00405        blas_trans_type transa = blas_no_trans,
00406        blas_trans_type transb = blas_no_trans);
00407 
00408 extern OCTAVE_API ComplexMatrix operator * (const Matrix&,        const ComplexMatrix&);
00409 extern OCTAVE_API ComplexMatrix operator * (const ComplexMatrix&, const Matrix&);
00410 extern OCTAVE_API ComplexMatrix operator * (const ComplexMatrix&, const ComplexMatrix&);
00411 
00412 extern OCTAVE_API ComplexMatrix min (const Complex& c, const ComplexMatrix& m);
00413 extern OCTAVE_API ComplexMatrix min (const ComplexMatrix& m, const Complex& c);
00414 extern OCTAVE_API ComplexMatrix min (const ComplexMatrix& a, const ComplexMatrix& b);
00415 
00416 extern OCTAVE_API ComplexMatrix max (const Complex& c, const ComplexMatrix& m);
00417 extern OCTAVE_API ComplexMatrix max (const ComplexMatrix& m, const Complex& c);
00418 extern OCTAVE_API ComplexMatrix max (const ComplexMatrix& a, const ComplexMatrix& b);
00419 
00420 extern OCTAVE_API ComplexMatrix linspace (const ComplexColumnVector& x1,
00421                                           const ComplexColumnVector& x2,
00422                                           octave_idx_type n);
00423 
00424 
00425 MS_CMP_OP_DECLS (ComplexMatrix, Complex, OCTAVE_API)
00426 MS_BOOL_OP_DECLS (ComplexMatrix, Complex, OCTAVE_API)
00427 
00428 SM_CMP_OP_DECLS (Complex, ComplexMatrix, OCTAVE_API)
00429 SM_BOOL_OP_DECLS (Complex, ComplexMatrix, OCTAVE_API)
00430 
00431 MM_CMP_OP_DECLS (ComplexMatrix, ComplexMatrix, OCTAVE_API)
00432 MM_BOOL_OP_DECLS (ComplexMatrix, ComplexMatrix, OCTAVE_API)
00433 
00434 MARRAY_FORWARD_DEFS (MArray, ComplexMatrix, Complex)
00435 
00436 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines