Mercurial > hg > octave-lyh
annotate liboctave/SparseQR.h @ 10396:a0b51ac0f88a
optimize accumdim with summation
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 05 Mar 2010 12:31:30 +0100 |
parents | 12884915a8e4 |
children | fd0a3ac60b0e |
rev | line source |
---|---|
5610 | 1 /* |
2 | |
8920 | 3 Copyright (C) 2005, 2006, 2007, 2008 David Bateman |
5610 | 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 | |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
26 #include <iosfwd> |
5610 | 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 | |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
66 Matrix Q (void) const; |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
67 |
5610 | 68 int count; |
69 | |
70 octave_idx_type nrows; | |
71 #ifdef HAVE_CXSPARSE | |
5648 | 72 CXSPARSE_DNAME (s) *S; |
5610 | 73 |
5648 | 74 CXSPARSE_DNAME (n) *N; |
5610 | 75 #endif |
76 }; | |
77 private: | |
78 SparseQR_rep *rep; | |
79 | |
80 public: | |
5792 | 81 SparseQR (void) : rep (new SparseQR_rep (SparseMatrix(), 0)) { } |
5610 | 82 |
5792 | 83 SparseQR (const SparseMatrix& a, int order = 0) : |
5610 | 84 rep (new SparseQR_rep (a, order)) { } |
85 | |
86 SparseQR (const SparseQR& a) : rep (a.rep) { rep->count++; } | |
87 | |
88 ~SparseQR (void) | |
89 { | |
90 if (--rep->count <= 0) | |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
91 delete rep; |
5610 | 92 } |
93 | |
94 SparseQR& operator = (const SparseQR& a) | |
95 { | |
96 if (this != &a) | |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
97 { |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
98 if (--rep->count <= 0) |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
99 delete rep; |
5610 | 100 |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
101 rep = a.rep; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
102 rep->count++; |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
103 } |
5610 | 104 return *this; |
105 } | |
106 | |
107 bool ok (void) const { return rep->ok(); } | |
108 | |
109 SparseMatrix V (void) const { return rep->V(); } | |
110 | |
111 ColumnVector Pinv (void) const { return rep->P(); } | |
112 | |
113 ColumnVector P (void) const { return rep->P(); } | |
114 | |
115 SparseMatrix R (const bool econ = false) const { return rep->R(econ); } | |
116 | |
117 Matrix C (const Matrix &b) const { return rep->C(b); } | |
118 | |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
119 Matrix Q (void) const { return rep->Q(); } |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
120 |
5610 | 121 friend Matrix qrsolve (const SparseMatrix &a, const Matrix &b, |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
122 octave_idx_type &info); |
5610 | 123 |
124 friend SparseMatrix qrsolve (const SparseMatrix &a, const SparseMatrix &b, | |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
125 octave_idx_type &info); |
5610 | 126 |
127 friend ComplexMatrix qrsolve (const SparseMatrix &a, const ComplexMatrix &b, | |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
128 octave_idx_type &info); |
5610 | 129 |
130 friend SparseComplexMatrix qrsolve (const SparseMatrix &a, | |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
131 const SparseComplexMatrix &b, |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
132 octave_idx_type &info); |
5610 | 133 |
134 protected: | |
135 #ifdef HAVE_CXSPARSE | |
5648 | 136 CXSPARSE_DNAME (s) * S (void) { return rep->S; } |
5610 | 137 |
5648 | 138 CXSPARSE_DNAME (n) * N (void) { return rep->N; } |
5610 | 139 #endif |
140 }; | |
141 | |
5713 | 142 |
143 // Publish externally used friend functions. | |
144 | |
145 extern Matrix qrsolve (const SparseMatrix &a, const Matrix &b, | |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
146 octave_idx_type &info); |
5713 | 147 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
148 extern Matrix qrsolve (const SparseMatrix &a, const MArray<double> &b, |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
149 octave_idx_type &info); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
150 |
5713 | 151 extern SparseMatrix qrsolve (const SparseMatrix &a, const SparseMatrix &b, |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
152 octave_idx_type &info); |
5713 | 153 |
154 extern ComplexMatrix qrsolve (const SparseMatrix &a, const ComplexMatrix &b, | |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
155 octave_idx_type &info); |
5713 | 156 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10312
diff
changeset
|
157 extern ComplexMatrix qrsolve (const SparseMatrix &a, const MArray<Complex> &b, |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
158 octave_idx_type &info); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
159 |
5713 | 160 extern SparseComplexMatrix qrsolve (const SparseMatrix &a, |
10312
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
161 const SparseComplexMatrix &b, |
cbc402e64d83
untabify liboctave header files
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
162 octave_idx_type &info); |
5713 | 163 |
5610 | 164 #endif |