Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if !defined (sparse_QR_h)
00024 #define sparse_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_DNAME(name) cs_dl ## name
00036 #else
00037 #define CXSPARSE_DNAME(name) cs_di ## name
00038 #endif
00039
00040 class
00041 OCTAVE_API
00042 SparseQR
00043 {
00044 protected:
00045 class SparseQR_rep
00046 {
00047 public:
00048 SparseQR_rep (const SparseMatrix& a, int order);
00049
00050 ~SparseQR_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 SparseMatrix V (void) const;
00057
00058 ColumnVector Pinv (void) const;
00059
00060 ColumnVector P (void) const;
00061
00062 SparseMatrix R (const bool econ) const;
00063
00064 Matrix C (const Matrix &b) const;
00065
00066 Matrix Q (void) const;
00067
00068 octave_refcount<int> count;
00069
00070 octave_idx_type nrows;
00071 #ifdef HAVE_CXSPARSE
00072 CXSPARSE_DNAME (s) *S;
00073
00074 CXSPARSE_DNAME (n) *N;
00075 #endif
00076
00077 private:
00078
00079
00080
00081 SparseQR_rep (const SparseQR_rep&);
00082
00083 SparseQR_rep& operator = (const SparseQR_rep&);
00084 };
00085
00086 private:
00087
00088 SparseQR_rep *rep;
00089
00090 public:
00091
00092 SparseQR (void) : rep (new SparseQR_rep (SparseMatrix(), 0)) { }
00093
00094 SparseQR (const SparseMatrix& a, int order = 0) :
00095 rep (new SparseQR_rep (a, order)) { }
00096
00097 SparseQR (const SparseQR& a) : rep (a.rep) { rep->count++; }
00098
00099 ~SparseQR (void)
00100 {
00101 if (--rep->count == 0)
00102 delete rep;
00103 }
00104
00105 SparseQR& operator = (const SparseQR& a)
00106 {
00107 if (this != &a)
00108 {
00109 if (--rep->count == 0)
00110 delete rep;
00111
00112 rep = a.rep;
00113 rep->count++;
00114 }
00115 return *this;
00116 }
00117
00118 bool ok (void) const { return rep->ok(); }
00119
00120 SparseMatrix V (void) const { return rep->V(); }
00121
00122 ColumnVector Pinv (void) const { return rep->P(); }
00123
00124 ColumnVector P (void) const { return rep->P(); }
00125
00126 SparseMatrix R (const bool econ = false) const { return rep->R(econ); }
00127
00128 Matrix C (const Matrix &b) const { return rep->C(b); }
00129
00130 Matrix Q (void) const { return rep->Q(); }
00131
00132 friend Matrix qrsolve (const SparseMatrix &a, const Matrix &b,
00133 octave_idx_type &info);
00134
00135 friend SparseMatrix qrsolve (const SparseMatrix &a, const SparseMatrix &b,
00136 octave_idx_type &info);
00137
00138 friend ComplexMatrix qrsolve (const SparseMatrix &a, const ComplexMatrix &b,
00139 octave_idx_type &info);
00140
00141 friend SparseComplexMatrix qrsolve (const SparseMatrix &a,
00142 const SparseComplexMatrix &b,
00143 octave_idx_type &info);
00144
00145 protected:
00146 #ifdef HAVE_CXSPARSE
00147 CXSPARSE_DNAME (s) * S (void) { return rep->S; }
00148
00149 CXSPARSE_DNAME (n) * N (void) { return rep->N; }
00150 #endif
00151 };
00152
00153
00154
00155
00156 extern Matrix qrsolve (const SparseMatrix &a, const Matrix &b,
00157 octave_idx_type &info);
00158
00159 extern Matrix qrsolve (const SparseMatrix &a, const MArray<double> &b,
00160 octave_idx_type &info);
00161
00162 extern SparseMatrix qrsolve (const SparseMatrix &a, const SparseMatrix &b,
00163 octave_idx_type &info);
00164
00165 extern ComplexMatrix qrsolve (const SparseMatrix &a, const ComplexMatrix &b,
00166 octave_idx_type &info);
00167
00168 extern ComplexMatrix qrsolve (const SparseMatrix &a, const MArray<Complex> &b,
00169 octave_idx_type &info);
00170
00171 extern SparseComplexMatrix qrsolve (const SparseMatrix &a,
00172 const SparseComplexMatrix &b,
00173 octave_idx_type &info);
00174
00175 #endif