5610
|
1 /* |
|
2 |
|
3 Copyright (C) 2005 David Bateman |
|
4 |
|
5 Octave is free software; you can redistribute it and/or modify it |
|
6 under the terms of the GNU General Public License as published by the |
|
7 Free Software Foundation; either version 2, or (at your option) any |
|
8 later version. |
|
9 |
|
10 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 for more details. |
|
14 |
|
15 You should have received a copy of the GNU General Public License |
|
16 along with this program; see the file COPYING. If not, write to the |
|
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
18 Boston, MA 02110-1301, USA. |
|
19 |
|
20 */ |
|
21 |
|
22 #if !defined (sparse_QR_h) |
|
23 #define sparse_QR_h 1 |
|
24 |
|
25 #include <iostream> |
|
26 |
|
27 #include "dMatrix.h" |
|
28 #include "CMatrix.h" |
|
29 #include "dSparse.h" |
|
30 #include "CSparse.h" |
|
31 #include "oct-sparse.h" |
|
32 |
|
33 #ifdef IDX_TYPE_LONG |
5648
|
34 #define CXSPARSE_DNAME(name) cs_dl ## name |
5610
|
35 #else |
5648
|
36 #define CXSPARSE_DNAME(name) cs_di ## name |
5610
|
37 #endif |
|
38 |
|
39 class |
|
40 SparseQR |
|
41 { |
|
42 protected: |
|
43 class SparseQR_rep |
|
44 { |
|
45 public: |
|
46 SparseQR_rep (const SparseMatrix& a, int order); |
|
47 |
|
48 ~SparseQR_rep (void); |
|
49 #ifdef HAVE_CXSPARSE |
|
50 bool ok (void) const { return (N && S); } |
|
51 #else |
|
52 bool ok (void) const { return false; } |
|
53 #endif |
|
54 SparseMatrix V (void) const; |
|
55 |
|
56 ColumnVector Pinv (void) const; |
|
57 |
|
58 ColumnVector P (void) const; |
|
59 |
|
60 SparseMatrix R (const bool econ) const; |
|
61 |
|
62 Matrix C (const Matrix &b) const; |
|
63 |
|
64 int count; |
|
65 |
|
66 octave_idx_type nrows; |
|
67 #ifdef HAVE_CXSPARSE |
5648
|
68 CXSPARSE_DNAME (s) *S; |
5610
|
69 |
5648
|
70 CXSPARSE_DNAME (n) *N; |
5610
|
71 #endif |
|
72 }; |
|
73 private: |
|
74 SparseQR_rep *rep; |
|
75 |
|
76 public: |
5792
|
77 SparseQR (void) : rep (new SparseQR_rep (SparseMatrix(), 0)) { } |
5610
|
78 |
5792
|
79 SparseQR (const SparseMatrix& a, int order = 0) : |
5610
|
80 rep (new SparseQR_rep (a, order)) { } |
|
81 |
|
82 SparseQR (const SparseQR& a) : rep (a.rep) { rep->count++; } |
|
83 |
|
84 ~SparseQR (void) |
|
85 { |
|
86 if (--rep->count <= 0) |
|
87 delete rep; |
|
88 } |
|
89 |
|
90 SparseQR& operator = (const SparseQR& a) |
|
91 { |
|
92 if (this != &a) |
|
93 { |
|
94 if (--rep->count <= 0) |
|
95 delete rep; |
|
96 |
|
97 rep = a.rep; |
|
98 rep->count++; |
|
99 } |
|
100 return *this; |
|
101 } |
|
102 |
|
103 bool ok (void) const { return rep->ok(); } |
|
104 |
|
105 SparseMatrix V (void) const { return rep->V(); } |
|
106 |
|
107 ColumnVector Pinv (void) const { return rep->P(); } |
|
108 |
|
109 ColumnVector P (void) const { return rep->P(); } |
|
110 |
|
111 SparseMatrix R (const bool econ = false) const { return rep->R(econ); } |
|
112 |
|
113 Matrix C (const Matrix &b) const { return rep->C(b); } |
|
114 |
|
115 friend Matrix qrsolve (const SparseMatrix &a, const Matrix &b, |
|
116 octave_idx_type &info); |
|
117 |
|
118 friend SparseMatrix qrsolve (const SparseMatrix &a, const SparseMatrix &b, |
|
119 octave_idx_type &info); |
|
120 |
|
121 friend ComplexMatrix qrsolve (const SparseMatrix &a, const ComplexMatrix &b, |
|
122 octave_idx_type &info); |
|
123 |
|
124 friend SparseComplexMatrix qrsolve (const SparseMatrix &a, |
|
125 const SparseComplexMatrix &b, |
|
126 octave_idx_type &info); |
|
127 |
|
128 protected: |
|
129 #ifdef HAVE_CXSPARSE |
5648
|
130 CXSPARSE_DNAME (s) * S (void) { return rep->S; } |
5610
|
131 |
5648
|
132 CXSPARSE_DNAME (n) * N (void) { return rep->N; } |
5610
|
133 #endif |
|
134 }; |
|
135 |
5713
|
136 |
|
137 // Publish externally used friend functions. |
|
138 |
|
139 extern Matrix qrsolve (const SparseMatrix &a, const Matrix &b, |
|
140 octave_idx_type &info); |
|
141 |
|
142 extern SparseMatrix qrsolve (const SparseMatrix &a, const SparseMatrix &b, |
|
143 octave_idx_type &info); |
|
144 |
|
145 extern ComplexMatrix qrsolve (const SparseMatrix &a, const ComplexMatrix &b, |
|
146 octave_idx_type &info); |
|
147 |
|
148 extern SparseComplexMatrix qrsolve (const SparseMatrix &a, |
|
149 const SparseComplexMatrix &b, |
|
150 octave_idx_type &info); |
|
151 |
5610
|
152 #endif |
|
153 |
|
154 /* |
|
155 ;;; Local Variables: *** |
|
156 ;;; mode: C++ *** |
|
157 ;;; End: *** |
|
158 */ |