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