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