SparseCmplxQR.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2005-2012 David Bateman
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 (sparse_cmplx_QR_h)
00024 #define sparse_cmplx_QR_h 1
00025 
00026 #include <iosfwd>
00027 
00028 #include "dMatrix.h"
00029 #include "CMatrix.h"
00030 #include "dSparse.h"
00031 #include "CSparse.h"
00032 #include "oct-sparse.h"
00033 
00034 #ifdef IDX_TYPE_LONG
00035 #define CXSPARSE_ZNAME(name) cs_cl ## name
00036 #else
00037 #define CXSPARSE_ZNAME(name) cs_ci ## name
00038 #endif
00039 
00040 class
00041 OCTAVE_API
00042 SparseComplexQR
00043 {
00044 protected:
00045   class SparseComplexQR_rep
00046   {
00047   public:
00048     SparseComplexQR_rep (const SparseComplexMatrix& a, int order);
00049 
00050     ~SparseComplexQR_rep (void);
00051 #ifdef HAVE_CXSPARSE
00052     bool ok (void) const { return (N && S); }
00053 #else
00054     bool ok (void) const { return false; }
00055 #endif
00056     SparseComplexMatrix V (void) const;
00057 
00058     ColumnVector Pinv (void) const;
00059 
00060     ColumnVector P (void) const;
00061 
00062     SparseComplexMatrix R (const bool econ) const;
00063 
00064     ComplexMatrix C (const ComplexMatrix &b) const;
00065 
00066     ComplexMatrix Q (void) const;
00067 
00068     octave_refcount<int> count;
00069 
00070     octave_idx_type nrows;
00071 #ifdef HAVE_CXSPARSE
00072     CXSPARSE_ZNAME (s) *S;
00073 
00074     CXSPARSE_ZNAME (n) *N;
00075 #endif
00076   private:
00077 
00078     // No copying!
00079 
00080     SparseComplexQR_rep (const SparseComplexQR_rep&);
00081 
00082     SparseComplexQR_rep operator = (const SparseComplexQR_rep&);
00083 
00084   };
00085 private:
00086   SparseComplexQR_rep *rep;
00087 
00088 public:
00089   SparseComplexQR (void) :
00090     rep (new SparseComplexQR_rep (SparseComplexMatrix(), 0)) { }
00091 
00092   SparseComplexQR (const SparseComplexMatrix& a, int order = 0) :
00093     rep (new SparseComplexQR_rep (a, order)) { }
00094 
00095   SparseComplexQR (const SparseComplexQR& a) : rep (a.rep) { rep->count++; }
00096 
00097   ~SparseComplexQR (void)
00098     {
00099       if (--rep->count == 0)
00100         delete rep;
00101     }
00102 
00103   SparseComplexQR& operator = (const SparseComplexQR& a)
00104     {
00105       if (this != &a)
00106         {
00107           if (--rep->count == 0)
00108             delete rep;
00109 
00110           rep = a.rep;
00111           rep->count++;
00112         }
00113       return *this;
00114     }
00115 
00116   bool ok (void) const { return rep->ok(); }
00117 
00118   SparseComplexMatrix V (void) const { return rep->V(); }
00119 
00120   ColumnVector Pinv (void) const { return rep->P(); }
00121 
00122   ColumnVector P (void) const { return rep->P(); }
00123 
00124   SparseComplexMatrix R (const bool econ = false) const
00125     { return rep->R(econ); }
00126 
00127   ComplexMatrix C (const ComplexMatrix &b) const { return rep->C(b); }
00128 
00129   ComplexMatrix Q (void) const { return rep->Q(); }
00130 
00131   friend ComplexMatrix qrsolve (const SparseComplexMatrix &a, const Matrix &b,
00132                                 octave_idx_type &info);
00133 
00134   friend SparseComplexMatrix qrsolve (const SparseComplexMatrix &a,
00135                                       const SparseMatrix &b,
00136                                       octave_idx_type &info);
00137 
00138   friend ComplexMatrix qrsolve (const SparseComplexMatrix &a,
00139                                 const ComplexMatrix &b,
00140                                 octave_idx_type &info);
00141 
00142   friend SparseComplexMatrix qrsolve (const SparseComplexMatrix &a,
00143                                       const SparseComplexMatrix &b,
00144                                       octave_idx_type &info);
00145 
00146 protected:
00147 #ifdef HAVE_CXSPARSE
00148   CXSPARSE_ZNAME (s) * S (void) { return rep->S; }
00149 
00150   CXSPARSE_ZNAME (n) * N (void) { return rep->N; }
00151 #endif
00152 };
00153 
00154 
00155 // Publish externally used friend functions.
00156 
00157 extern ComplexMatrix qrsolve (const SparseComplexMatrix &a, const Matrix &b,
00158                               octave_idx_type &info);
00159 
00160 extern ComplexMatrix qrsolve (const SparseComplexMatrix &a,
00161                               const MArray<double> &b,
00162                               octave_idx_type &info);
00163 
00164 extern SparseComplexMatrix qrsolve (const SparseComplexMatrix &a,
00165                                     const SparseMatrix &b,
00166                                     octave_idx_type &info);
00167 
00168 extern ComplexMatrix qrsolve (const SparseComplexMatrix &a,
00169                               const ComplexMatrix &b,
00170                               octave_idx_type &info);
00171 
00172 extern ComplexMatrix qrsolve (const SparseComplexMatrix &a,
00173                               const MArray<Complex> &b,
00174                               octave_idx_type &info);
00175 
00176 extern SparseComplexMatrix qrsolve (const SparseComplexMatrix &a,
00177                                     const SparseComplexMatrix &b,
00178                                     octave_idx_type &info);
00179 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines