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