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_cmplx_QR_h) |
|
24 #define sparse_cmplx_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_ZNAME(name) cs_cl ## name |
5610
|
36 #else |
5648
|
37 #define CXSPARSE_ZNAME(name) cs_ci ## name |
5610
|
38 #endif |
|
39 |
|
40 class |
6108
|
41 OCTAVE_API |
5610
|
42 SparseComplexQR |
|
43 { |
|
44 protected: |
|
45 class SparseComplexQR_rep |
|
46 { |
|
47 public: |
|
48 SparseComplexQR_rep (const SparseComplexMatrix& a, int order); |
|
49 |
|
50 ~SparseComplexQR_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 SparseComplexMatrix V (void) const; |
|
57 |
|
58 ColumnVector Pinv (void) const; |
|
59 |
|
60 ColumnVector P (void) const; |
|
61 |
|
62 SparseComplexMatrix R (const bool econ) const; |
|
63 |
|
64 ComplexMatrix C (const ComplexMatrix &b) const; |
|
65 |
|
66 int count; |
|
67 |
|
68 octave_idx_type nrows; |
|
69 #ifdef HAVE_CXSPARSE |
5648
|
70 CXSPARSE_ZNAME (s) *S; |
5610
|
71 |
5648
|
72 CXSPARSE_ZNAME (n) *N; |
5610
|
73 #endif |
|
74 }; |
|
75 private: |
|
76 SparseComplexQR_rep *rep; |
|
77 |
|
78 public: |
|
79 SparseComplexQR (void) : |
5792
|
80 rep (new SparseComplexQR_rep (SparseComplexMatrix(), 0)) { } |
5610
|
81 |
5792
|
82 SparseComplexQR (const SparseComplexMatrix& a, int order = 0) : |
5610
|
83 rep (new SparseComplexQR_rep (a, order)) { } |
|
84 |
|
85 SparseComplexQR (const SparseComplexQR& a) : rep (a.rep) { rep->count++; } |
|
86 |
|
87 ~SparseComplexQR (void) |
|
88 { |
|
89 if (--rep->count <= 0) |
|
90 delete rep; |
|
91 } |
|
92 |
|
93 SparseComplexQR& operator = (const SparseComplexQR& a) |
|
94 { |
|
95 if (this != &a) |
|
96 { |
|
97 if (--rep->count <= 0) |
|
98 delete rep; |
|
99 |
|
100 rep = a.rep; |
|
101 rep->count++; |
|
102 } |
|
103 return *this; |
|
104 } |
|
105 |
|
106 bool ok (void) const { return rep->ok(); } |
|
107 |
|
108 SparseComplexMatrix V (void) const { return rep->V(); } |
|
109 |
|
110 ColumnVector Pinv (void) const { return rep->P(); } |
|
111 |
|
112 ColumnVector P (void) const { return rep->P(); } |
|
113 |
|
114 SparseComplexMatrix R (const bool econ = false) const |
|
115 { return rep->R(econ); } |
|
116 |
|
117 ComplexMatrix C (const ComplexMatrix &b) const { return rep->C(b); } |
|
118 |
|
119 friend ComplexMatrix qrsolve (const SparseComplexMatrix &a, const Matrix &b, |
|
120 octave_idx_type &info); |
|
121 |
|
122 friend SparseComplexMatrix qrsolve (const SparseComplexMatrix &a, |
|
123 const SparseMatrix &b, |
|
124 octave_idx_type &info); |
|
125 |
|
126 friend ComplexMatrix qrsolve (const SparseComplexMatrix &a, |
|
127 const ComplexMatrix &b, |
|
128 octave_idx_type &info); |
|
129 |
|
130 friend SparseComplexMatrix qrsolve (const SparseComplexMatrix &a, |
|
131 const SparseComplexMatrix &b, |
|
132 octave_idx_type &info); |
|
133 |
|
134 protected: |
|
135 #ifdef HAVE_CXSPARSE |
5648
|
136 CXSPARSE_ZNAME (s) * S (void) { return rep->S; } |
5610
|
137 |
5648
|
138 CXSPARSE_ZNAME (n) * N (void) { return rep->N; } |
5610
|
139 #endif |
|
140 }; |
|
141 |
5713
|
142 |
|
143 // Publish externally used friend functions. |
|
144 |
|
145 extern ComplexMatrix qrsolve (const SparseComplexMatrix &a, const Matrix &b, |
|
146 octave_idx_type &info); |
|
147 |
|
148 extern SparseComplexMatrix qrsolve (const SparseComplexMatrix &a, |
|
149 const SparseMatrix &b, |
|
150 octave_idx_type &info); |
|
151 |
|
152 extern ComplexMatrix qrsolve (const SparseComplexMatrix &a, |
|
153 const ComplexMatrix &b, |
|
154 octave_idx_type &info); |
|
155 |
|
156 extern SparseComplexMatrix qrsolve (const SparseComplexMatrix &a, |
|
157 const SparseComplexMatrix &b, |
|
158 octave_idx_type &info); |
5610
|
159 #endif |
|
160 |
|
161 /* |
|
162 ;;; Local Variables: *** |
|
163 ;;; mode: C++ *** |
|
164 ;;; End: *** |
|
165 */ |