Mercurial > octave
annotate liboctave/SparseQR.cc @ 11523:fd0a3ac60b0e
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 14 Jan 2011 05:47:45 -0500 |
parents | f3d0b69c4628 |
children | feb90c7cfc16 |
rev | line source |
---|---|
5610 | 1 /* |
2 | |
11523 | 3 Copyright (C) 2005-2011 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 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 #include <vector> | |
27 | |
28 #include "lo-error.h" | |
29 #include "SparseQR.h" | |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
30 #include "oct-locbuf.h" |
5610 | 31 |
32 SparseQR::SparseQR_rep::SparseQR_rep (const SparseMatrix& a, int order) | |
11510
f3d0b69c4628
SparseQR.cc, SparseCmplxQR.cc: fix member initialization order
John W. Eaton <jwe@octave.org>
parents:
11498
diff
changeset
|
33 : count (1), nrows (0), S (0), N (0) |
5610 | 34 { |
35 #ifdef HAVE_CXSPARSE | |
5648 | 36 CXSPARSE_DNAME () A; |
10506
bdf5d85cfc5e
replace nzmax by nnz where appropriate in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
37 A.nzmax = a.nnz (); |
5610 | 38 A.m = a.rows (); |
39 A.n = a.cols (); | |
40 nrows = A.m; | |
41 // Cast away const on A, with full knowledge that CSparse won't touch it | |
42 // Prevents the methods below making a copy of the data. | |
43 A.p = const_cast<octave_idx_type *>(a.cidx ()); | |
44 A.i = const_cast<octave_idx_type *>(a.ridx ()); | |
45 A.x = const_cast<double *>(a.data ()); | |
46 A.nz = -1; | |
47 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; | |
5792 | 48 #if defined(CS_VER) && (CS_VER >= 2) |
49 S = CXSPARSE_DNAME (_sqr) (order, &A, 1); | |
50 #else | |
51 S = CXSPARSE_DNAME (_sqr) (&A, order - 1, 1); | |
52 #endif | |
53 | |
5648 | 54 N = CXSPARSE_DNAME (_qr) (&A, S); |
5610 | 55 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
56 if (!N) | |
57 (*current_liboctave_error_handler) | |
58 ("SparseQR: sparse matrix QR factorization filled"); | |
59 count = 1; | |
60 #else | |
61 (*current_liboctave_error_handler) | |
62 ("SparseQR: sparse matrix QR factorization not implemented"); | |
63 #endif | |
64 } | |
65 | |
66 SparseQR::SparseQR_rep::~SparseQR_rep (void) | |
67 { | |
68 #ifdef HAVE_CXSPARSE | |
5648 | 69 CXSPARSE_DNAME (_sfree) (S); |
70 CXSPARSE_DNAME (_nfree) (N); | |
5610 | 71 #endif |
72 } | |
73 | |
74 SparseMatrix | |
75 SparseQR::SparseQR_rep::V (void) const | |
76 { | |
77 #ifdef HAVE_CXSPARSE | |
78 // Drop zeros from V and sort | |
5775 | 79 // FIXME Is the double transpose to sort necessary? |
5610 | 80 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5648 | 81 CXSPARSE_DNAME (_dropzeros) (N->L); |
82 CXSPARSE_DNAME () *D = CXSPARSE_DNAME (_transpose) (N->L, 1); | |
83 CXSPARSE_DNAME (_spfree) (N->L); | |
84 N->L = CXSPARSE_DNAME (_transpose) (D, 1); | |
85 CXSPARSE_DNAME (_spfree) (D); | |
5610 | 86 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
87 | |
88 octave_idx_type nc = N->L->n; | |
89 octave_idx_type nz = N->L->nzmax; | |
90 SparseMatrix ret (N->L->m, nc, nz); | |
91 for (octave_idx_type j = 0; j < nc+1; j++) | |
92 ret.xcidx (j) = N->L->p[j]; | |
93 for (octave_idx_type j = 0; j < nz; j++) | |
94 { | |
95 ret.xridx (j) = N->L->i[j]; | |
96 ret.xdata (j) = N->L->x[j]; | |
97 } | |
98 return ret; | |
99 #else | |
100 return SparseMatrix (); | |
101 #endif | |
102 } | |
103 | |
104 ColumnVector | |
105 SparseQR::SparseQR_rep::Pinv (void) const | |
106 { | |
107 #ifdef HAVE_CXSPARSE | |
108 ColumnVector ret(N->L->m); | |
109 for (octave_idx_type i = 0; i < N->L->m; i++) | |
5792 | 110 #if defined(CS_VER) && (CS_VER >= 2) |
111 ret.xelem(i) = S->pinv[i]; | |
112 #else | |
5610 | 113 ret.xelem(i) = S->Pinv[i]; |
5792 | 114 #endif |
5610 | 115 return ret; |
116 #else | |
117 return ColumnVector (); | |
118 #endif | |
119 } | |
120 | |
121 ColumnVector | |
122 SparseQR::SparseQR_rep::P (void) const | |
123 { | |
124 #ifdef HAVE_CXSPARSE | |
125 ColumnVector ret(N->L->m); | |
126 for (octave_idx_type i = 0; i < N->L->m; i++) | |
5792 | 127 #if defined(CS_VER) && (CS_VER >= 2) |
128 ret.xelem(S->pinv[i]) = i; | |
129 #else | |
5610 | 130 ret.xelem(S->Pinv[i]) = i; |
5792 | 131 #endif |
5610 | 132 return ret; |
133 #else | |
134 return ColumnVector (); | |
135 #endif | |
136 } | |
137 | |
138 SparseMatrix | |
139 SparseQR::SparseQR_rep::R (const bool econ) const | |
140 { | |
141 #ifdef HAVE_CXSPARSE | |
142 // Drop zeros from R and sort | |
5775 | 143 // FIXME Is the double transpose to sort necessary? |
5610 | 144 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5648 | 145 CXSPARSE_DNAME (_dropzeros) (N->U); |
146 CXSPARSE_DNAME () *D = CXSPARSE_DNAME (_transpose) (N->U, 1); | |
147 CXSPARSE_DNAME (_spfree) (N->U); | |
148 N->U = CXSPARSE_DNAME (_transpose) (D, 1); | |
149 CXSPARSE_DNAME (_spfree) (D); | |
5610 | 150 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
151 | |
152 octave_idx_type nc = N->U->n; | |
153 octave_idx_type nz = N->U->nzmax; | |
154 | |
155 SparseMatrix ret ((econ ? (nc > nrows ? nrows : nc) : nrows), nc, nz); | |
156 | |
157 for (octave_idx_type j = 0; j < nc+1; j++) | |
158 ret.xcidx (j) = N->U->p[j]; | |
159 for (octave_idx_type j = 0; j < nz; j++) | |
160 { | |
161 ret.xridx (j) = N->U->i[j]; | |
162 ret.xdata (j) = N->U->x[j]; | |
163 } | |
164 return ret; | |
165 #else | |
166 return SparseMatrix (); | |
167 #endif | |
168 } | |
169 | |
170 Matrix | |
171 SparseQR::SparseQR_rep::C (const Matrix &b) const | |
172 { | |
173 #ifdef HAVE_CXSPARSE | |
174 octave_idx_type b_nr = b.rows(); | |
175 octave_idx_type b_nc = b.cols(); | |
176 octave_idx_type nc = N->L->n; | |
177 octave_idx_type nr = nrows; | |
178 const double *bvec = b.fortran_vec(); | |
6924 | 179 Matrix ret (b_nr, b_nc); |
5610 | 180 double *vec = ret.fortran_vec(); |
6924 | 181 if (nr < 0 || nc < 0 || nr != b_nr) |
5610 | 182 (*current_liboctave_error_handler) ("matrix dimension mismatch"); |
6924 | 183 else if (nr == 0 || nc == 0 || b_nc == 0) |
184 ret = Matrix (nc, b_nc, 0.0); | |
5610 | 185 else |
186 { | |
187 OCTAVE_LOCAL_BUFFER (double, buf, S->m2); | |
188 for (volatile octave_idx_type j = 0, idx = 0; j < b_nc; j++, idx+=b_nr) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
189 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
190 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
191 for (octave_idx_type i = nr; i < S->m2; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
192 buf[i] = 0.; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
193 volatile octave_idx_type nm = (nr < nc ? nr : nc); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
194 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5792 | 195 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
196 CXSPARSE_DNAME (_ipvec) (S->pinv, bvec + idx, buf, b_nr); |
5792 | 197 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
198 CXSPARSE_DNAME (_ipvec) (b_nr, S->Pinv, bvec + idx, buf); |
5792 | 199 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
200 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5610 | 201 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
202 for (volatile octave_idx_type i = 0; i < nm; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
203 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
204 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
205 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
206 CXSPARSE_DNAME (_happly) (N->L, i, N->B[i], buf); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
207 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
208 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
209 for (octave_idx_type i = 0; i < b_nr; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
210 vec[i+idx] = buf[i]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
211 } |
5610 | 212 } |
213 return ret; | |
214 #else | |
215 return Matrix (); | |
216 #endif | |
217 } | |
218 | |
219 Matrix | |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
220 SparseQR::SparseQR_rep::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
|
221 { |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
222 #ifdef HAVE_CXSPARSE |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
223 octave_idx_type nc = N->L->n; |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
224 octave_idx_type nr = nrows; |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
225 Matrix ret (nr, nr); |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
226 double *vec = ret.fortran_vec(); |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
227 if (nr < 0 || nc < 0) |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
228 (*current_liboctave_error_handler) ("matrix dimension mismatch"); |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
229 else if (nr == 0 || nc == 0) |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
230 ret = Matrix (nc, nr, 0.0); |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
231 else |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
232 { |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
233 OCTAVE_LOCAL_BUFFER (double, bvec, nr + 1); |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
234 for (octave_idx_type i = 0; i < nr; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
235 bvec[i] = 0.; |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
236 OCTAVE_LOCAL_BUFFER (double, buf, S->m2); |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
237 for (volatile octave_idx_type j = 0, idx = 0; j < nr; j++, idx+=nr) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
238 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
239 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
240 bvec[j] = 1.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
241 for (octave_idx_type i = nr; i < S->m2; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
242 buf[i] = 0.; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
243 volatile octave_idx_type nm = (nr < nc ? nr : nc); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
244 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
245 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
246 CXSPARSE_DNAME (_ipvec) (S->pinv, bvec, buf, nr); |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
247 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
248 CXSPARSE_DNAME (_ipvec) (nr, S->Pinv, bvec, buf); |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
249 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
250 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
251 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
252 for (volatile octave_idx_type i = 0; i < nm; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
253 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
254 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
255 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
256 CXSPARSE_DNAME (_happly) (N->L, i, N->B[i], buf); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
257 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
258 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
259 for (octave_idx_type i = 0; i < nr; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
260 vec[i+idx] = buf[i]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
261 bvec[j] = 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
262 } |
7505
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
263 } |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
264 return ret.transpose (); |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
265 #else |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
266 return Matrix (); |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
267 #endif |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
268 } |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
269 |
f5005d9510f4
Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
270 Matrix |
5610 | 271 qrsolve(const SparseMatrix&a, const Matrix &b, octave_idx_type& info) |
272 { | |
5797 | 273 info = -1; |
5610 | 274 #ifdef HAVE_CXSPARSE |
275 octave_idx_type nr = a.rows(); | |
276 octave_idx_type nc = a.cols(); | |
277 octave_idx_type b_nc = b.cols(); | |
278 octave_idx_type b_nr = b.rows(); | |
279 const double *bvec = b.fortran_vec(); | |
280 Matrix x; | |
281 | |
6924 | 282 if (nr < 0 || nc < 0 || nr != b_nr) |
5610 | 283 (*current_liboctave_error_handler) |
284 ("matrix dimension mismatch in solution of minimum norm problem"); | |
6924 | 285 else if (nr == 0 || nc == 0 || b_nc == 0) |
286 x = Matrix (nc, b_nc, 0.0); | |
5610 | 287 else if (nr >= nc) |
288 { | |
5792 | 289 SparseQR q (a, 3); |
5610 | 290 if (! q.ok ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
291 return Matrix(); |
5610 | 292 x.resize(nc, b_nc); |
293 double *vec = x.fortran_vec(); | |
294 OCTAVE_LOCAL_BUFFER (double, buf, q.S()->m2); | |
295 for (volatile octave_idx_type i = 0, idx = 0, bidx = 0; i < b_nc; | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
296 i++, idx+=nc, bidx+=b_nr) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
297 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
298 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
299 for (octave_idx_type j = nr; j < q.S()->m2; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
300 buf[j] = 0.; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
301 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5792 | 302 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
303 CXSPARSE_DNAME (_ipvec) (q.S()->pinv, bvec + bidx, buf, nr); |
5792 | 304 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
305 CXSPARSE_DNAME (_ipvec) (nr, q.S()->Pinv, bvec + bidx, buf); |
5792 | 306 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
307 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
308 for (volatile octave_idx_type j = 0; j < nc; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
309 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
310 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
311 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
312 CXSPARSE_DNAME (_happly) (q.N()->L, j, q.N()->B[j], buf); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
313 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
314 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
315 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
316 CXSPARSE_DNAME (_usolve) (q.N()->U, buf); |
5792 | 317 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
318 CXSPARSE_DNAME (_ipvec) (q.S()->q, buf, vec + idx, nc); |
5792 | 319 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
320 CXSPARSE_DNAME (_ipvec) (nc, q.S()->Q, buf, vec + idx); |
5792 | 321 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
322 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
323 } |
5797 | 324 info = 0; |
5610 | 325 } |
326 else | |
327 { | |
328 SparseMatrix at = a.hermitian(); | |
5792 | 329 SparseQR q (at, 3); |
5610 | 330 if (! q.ok ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
331 return Matrix(); |
5610 | 332 x.resize(nc, b_nc); |
333 double *vec = x.fortran_vec(); | |
5681 | 334 volatile octave_idx_type nbuf = (nc > q.S()->m2 ? nc : q.S()->m2); |
335 OCTAVE_LOCAL_BUFFER (double, buf, nbuf); | |
5610 | 336 for (volatile octave_idx_type i = 0, idx = 0, bidx = 0; i < b_nc; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
337 i++, idx+=nc, bidx+=b_nr) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
338 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
339 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
340 for (octave_idx_type j = nr; j < nbuf; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
341 buf[j] = 0.; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
342 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5792 | 343 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
344 CXSPARSE_DNAME (_pvec) (q.S()->q, bvec + bidx, buf, nr); |
5792 | 345 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
346 CXSPARSE_DNAME (_pvec) (nr, q.S()->Q, bvec + bidx, buf); |
5792 | 347 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
348 CXSPARSE_DNAME (_utsolve) (q.N()->U, buf); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
349 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
350 for (volatile octave_idx_type j = nr-1; j >= 0; j--) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
351 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
352 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
353 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
354 CXSPARSE_DNAME (_happly) (q.N()->L, j, q.N()->B[j], buf); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
355 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
356 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
357 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5792 | 358 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
359 CXSPARSE_DNAME (_pvec) (q.S()->pinv, buf, vec + idx, nc); |
5792 | 360 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
361 CXSPARSE_DNAME (_pvec) (nc, q.S()->Pinv, buf, vec + idx); |
5792 | 362 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
363 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
364 } |
5797 | 365 info = 0; |
5610 | 366 } |
367 | |
368 return x; | |
369 #else | |
370 return Matrix (); | |
371 #endif | |
372 } | |
373 | |
374 SparseMatrix | |
375 qrsolve(const SparseMatrix&a, const SparseMatrix &b, octave_idx_type &info) | |
376 { | |
5797 | 377 info = -1; |
5610 | 378 #ifdef HAVE_CXSPARSE |
379 octave_idx_type nr = a.rows(); | |
380 octave_idx_type nc = a.cols(); | |
381 octave_idx_type b_nr = b.rows(); | |
382 octave_idx_type b_nc = b.cols(); | |
383 SparseMatrix x; | |
384 volatile octave_idx_type ii, x_nz; | |
385 | |
6924 | 386 if (nr < 0 || nc < 0 || nr != b_nr) |
5610 | 387 (*current_liboctave_error_handler) |
388 ("matrix dimension mismatch in solution of minimum norm problem"); | |
6924 | 389 else if (nr == 0 || nc == 0 || b_nc == 0) |
390 x = SparseMatrix (nc, b_nc); | |
5610 | 391 else if (nr >= nc) |
392 { | |
5792 | 393 SparseQR q (a, 3); |
5610 | 394 if (! q.ok ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
395 return SparseMatrix(); |
10506
bdf5d85cfc5e
replace nzmax by nnz where appropriate in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
396 x = SparseMatrix (nc, b_nc, b.nnz()); |
5610 | 397 x.xcidx(0) = 0; |
10506
bdf5d85cfc5e
replace nzmax by nnz where appropriate in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
398 x_nz = b.nnz(); |
5610 | 399 ii = 0; |
400 OCTAVE_LOCAL_BUFFER (double, Xx, (b_nr > nc ? b_nr : nc)); | |
401 OCTAVE_LOCAL_BUFFER (double, buf, q.S()->m2); | |
402 for (volatile octave_idx_type i = 0, idx = 0; i < b_nc; i++, idx+=nc) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
403 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
404 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
405 for (octave_idx_type j = 0; j < b_nr; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
406 Xx[j] = b.xelem(j,i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
407 for (octave_idx_type j = nr; j < q.S()->m2; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
408 buf[j] = 0.; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
409 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5792 | 410 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
411 CXSPARSE_DNAME (_ipvec) (q.S()->pinv, Xx, buf, nr); |
5792 | 412 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
413 CXSPARSE_DNAME (_ipvec) (nr, q.S()->Pinv, Xx, buf); |
5792 | 414 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
415 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
416 for (volatile octave_idx_type j = 0; j < nc; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
417 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
418 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
419 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
420 CXSPARSE_DNAME (_happly) (q.N()->L, j, q.N()->B[j], buf); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
421 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
422 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
423 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
424 CXSPARSE_DNAME (_usolve) (q.N()->U, buf); |
5792 | 425 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
426 CXSPARSE_DNAME (_ipvec) (q.S()->q, buf, Xx, nc); |
5792 | 427 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
428 CXSPARSE_DNAME (_ipvec) (nc, q.S()->Q, buf, Xx); |
5792 | 429 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
430 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5610 | 431 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
432 for (octave_idx_type j = 0; j < nc; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
433 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
434 double tmp = Xx[j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
435 if (tmp != 0.0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
436 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
437 if (ii == x_nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
438 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
439 // Resize the sparse matrix |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
440 octave_idx_type sz = x_nz * (b_nc - i) / b_nc; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
441 sz = (sz > 10 ? sz : 10) + x_nz; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
442 x.change_capacity (sz); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
443 x_nz = sz; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
444 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
445 x.xdata(ii) = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
446 x.xridx(ii++) = j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
447 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
448 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
449 x.xcidx(i+1) = ii; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
450 } |
5797 | 451 info = 0; |
5610 | 452 } |
453 else | |
454 { | |
455 SparseMatrix at = a.hermitian(); | |
5792 | 456 SparseQR q (at, 3); |
5610 | 457 if (! q.ok ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
458 return SparseMatrix(); |
10506
bdf5d85cfc5e
replace nzmax by nnz where appropriate in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
459 x = SparseMatrix (nc, b_nc, b.nnz()); |
5610 | 460 x.xcidx(0) = 0; |
10506
bdf5d85cfc5e
replace nzmax by nnz where appropriate in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
461 x_nz = b.nnz(); |
5610 | 462 ii = 0; |
5681 | 463 volatile octave_idx_type nbuf = (nc > q.S()->m2 ? nc : q.S()->m2); |
5610 | 464 OCTAVE_LOCAL_BUFFER (double, Xx, (b_nr > nc ? b_nr : nc)); |
5681 | 465 OCTAVE_LOCAL_BUFFER (double, buf, nbuf); |
5610 | 466 for (volatile octave_idx_type i = 0, idx = 0; i < b_nc; i++, idx+=nc) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
467 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
468 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
469 for (octave_idx_type j = 0; j < b_nr; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
470 Xx[j] = b.xelem(j,i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
471 for (octave_idx_type j = nr; j < nbuf; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
472 buf[j] = 0.; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
473 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5792 | 474 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
475 CXSPARSE_DNAME (_pvec) (q.S()->q, Xx, buf, nr); |
5792 | 476 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
477 CXSPARSE_DNAME (_pvec) (nr, q.S()->Q, Xx, buf); |
5792 | 478 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
479 CXSPARSE_DNAME (_utsolve) (q.N()->U, buf); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
480 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
481 for (volatile octave_idx_type j = nr-1; j >= 0; j--) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
482 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
483 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
484 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
485 CXSPARSE_DNAME (_happly) (q.N()->L, j, q.N()->B[j], buf); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
486 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
487 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
488 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5792 | 489 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
490 CXSPARSE_DNAME (_pvec) (q.S()->pinv, buf, Xx, nc); |
5792 | 491 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
492 CXSPARSE_DNAME (_pvec) (nc, q.S()->Pinv, buf, Xx); |
5792 | 493 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
494 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5610 | 495 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
496 for (octave_idx_type j = 0; j < nc; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
497 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
498 double tmp = Xx[j]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
499 if (tmp != 0.0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
500 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
501 if (ii == x_nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
502 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
503 // Resize the sparse matrix |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
504 octave_idx_type sz = x_nz * (b_nc - i) / b_nc; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
505 sz = (sz > 10 ? sz : 10) + x_nz; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
506 x.change_capacity (sz); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
507 x_nz = sz; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
508 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
509 x.xdata(ii) = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
510 x.xridx(ii++) = j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
511 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
512 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
513 x.xcidx(i+1) = ii; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
514 } |
5797 | 515 info = 0; |
5610 | 516 } |
517 | |
518 x.maybe_compress (); | |
519 return x; | |
520 #else | |
521 return SparseMatrix (); | |
522 #endif | |
523 } | |
524 | |
525 ComplexMatrix | |
526 qrsolve(const SparseMatrix&a, const ComplexMatrix &b, octave_idx_type &info) | |
527 { | |
5797 | 528 info = -1; |
5610 | 529 #ifdef HAVE_CXSPARSE |
530 octave_idx_type nr = a.rows(); | |
531 octave_idx_type nc = a.cols(); | |
532 octave_idx_type b_nc = b.cols(); | |
533 octave_idx_type b_nr = b.rows(); | |
534 ComplexMatrix x; | |
535 | |
6924 | 536 if (nr < 0 || nc < 0 || nr != b_nr) |
5610 | 537 (*current_liboctave_error_handler) |
538 ("matrix dimension mismatch in solution of minimum norm problem"); | |
6924 | 539 else if (nr == 0 || nc == 0 || b_nc == 0) |
540 x = ComplexMatrix (nc, b_nc, Complex (0.0, 0.0)); | |
5610 | 541 else if (nr >= nc) |
542 { | |
5792 | 543 SparseQR q (a, 3); |
5610 | 544 if (! q.ok ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
545 return ComplexMatrix(); |
5610 | 546 x.resize(nc, b_nc); |
547 Complex *vec = x.fortran_vec(); | |
548 OCTAVE_LOCAL_BUFFER (double, Xx, (b_nr > nc ? b_nr : nc)); | |
549 OCTAVE_LOCAL_BUFFER (double, Xz, (b_nr > nc ? b_nr : nc)); | |
550 OCTAVE_LOCAL_BUFFER (double, buf, q.S()->m2); | |
551 for (volatile octave_idx_type i = 0, idx = 0; i < b_nc; i++, idx+=nc) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
552 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
553 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
554 for (octave_idx_type j = 0; j < b_nr; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
555 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
556 Complex c = b.xelem (j,i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
557 Xx[j] = std::real (c); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
558 Xz[j] = std::imag (c); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
559 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
560 for (octave_idx_type j = nr; j < q.S()->m2; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
561 buf[j] = 0.; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
562 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5792 | 563 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
564 CXSPARSE_DNAME (_ipvec) (q.S()->pinv, Xx, buf, nr); |
5792 | 565 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
566 CXSPARSE_DNAME (_ipvec) (nr, q.S()->Pinv, Xx, buf); |
5792 | 567 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
568 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
569 for (volatile octave_idx_type j = 0; j < nc; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
570 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
571 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
572 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
573 CXSPARSE_DNAME (_happly) (q.N()->L, j, q.N()->B[j], buf); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
574 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
575 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
576 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
577 CXSPARSE_DNAME (_usolve) (q.N()->U, buf); |
5792 | 578 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
579 CXSPARSE_DNAME (_ipvec) (q.S()->q, buf, Xx, nc); |
5792 | 580 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
581 CXSPARSE_DNAME (_ipvec) (nc, q.S()->Q, buf, Xx); |
5792 | 582 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
583 for (octave_idx_type j = nr; j < q.S()->m2; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
584 buf[j] = 0.; |
5792 | 585 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
586 CXSPARSE_DNAME (_ipvec) (q.S()->pinv, Xz, buf, nr); |
5792 | 587 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
588 CXSPARSE_DNAME (_ipvec) (nr, q.S()->Pinv, Xz, buf); |
5792 | 589 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
590 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
591 for (volatile octave_idx_type j = 0; j < nc; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
592 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
593 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
594 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
595 CXSPARSE_DNAME (_happly) (q.N()->L, j, q.N()->B[j], buf); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
596 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
597 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
598 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
599 CXSPARSE_DNAME (_usolve) (q.N()->U, buf); |
5792 | 600 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
601 CXSPARSE_DNAME (_ipvec) (q.S()->q, buf, Xz, nc); |
5792 | 602 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
603 CXSPARSE_DNAME (_ipvec) (nc, q.S()->Q, buf, Xz); |
5792 | 604 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
605 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
606 for (octave_idx_type j = 0; j < nc; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
607 vec[j+idx] = Complex (Xx[j], Xz[j]); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
608 } |
5797 | 609 info = 0; |
5610 | 610 } |
611 else | |
612 { | |
613 SparseMatrix at = a.hermitian(); | |
5792 | 614 SparseQR q (at, 3); |
5610 | 615 if (! q.ok ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
616 return ComplexMatrix(); |
5610 | 617 x.resize(nc, b_nc); |
618 Complex *vec = x.fortran_vec(); | |
5681 | 619 volatile octave_idx_type nbuf = (nc > q.S()->m2 ? nc : q.S()->m2); |
5610 | 620 OCTAVE_LOCAL_BUFFER (double, Xx, (b_nr > nc ? b_nr : nc)); |
621 OCTAVE_LOCAL_BUFFER (double, Xz, (b_nr > nc ? b_nr : nc)); | |
5681 | 622 OCTAVE_LOCAL_BUFFER (double, buf, nbuf); |
5610 | 623 for (volatile octave_idx_type i = 0, idx = 0; i < b_nc; i++, idx+=nc) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
624 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
625 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
626 for (octave_idx_type j = 0; j < b_nr; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
627 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
628 Complex c = b.xelem (j,i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
629 Xx[j] = std::real (c); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
630 Xz[j] = std::imag (c); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
631 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
632 for (octave_idx_type j = nr; j < nbuf; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
633 buf[j] = 0.; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
634 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5792 | 635 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
636 CXSPARSE_DNAME (_pvec) (q.S()->q, Xx, buf, nr); |
5792 | 637 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
638 CXSPARSE_DNAME (_pvec) (nr, q.S()->Q, Xx, buf); |
5792 | 639 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
640 CXSPARSE_DNAME (_utsolve) (q.N()->U, buf); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
641 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
642 for (volatile octave_idx_type j = nr-1; j >= 0; j--) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
643 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
644 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
645 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
646 CXSPARSE_DNAME (_happly) (q.N()->L, j, q.N()->B[j], buf); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
647 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
648 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
649 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5792 | 650 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
651 CXSPARSE_DNAME (_pvec) (q.S()->pinv, buf, Xx, nc); |
5792 | 652 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
653 CXSPARSE_DNAME (_pvec) (nc, q.S()->Pinv, buf, Xx); |
5792 | 654 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
655 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
656 for (octave_idx_type j = nr; j < nbuf; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
657 buf[j] = 0.; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
658 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5792 | 659 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
660 CXSPARSE_DNAME (_pvec) (q.S()->q, Xz, buf, nr); |
5792 | 661 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
662 CXSPARSE_DNAME (_pvec) (nr, q.S()->Q, Xz, buf); |
5792 | 663 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
664 CXSPARSE_DNAME (_utsolve) (q.N()->U, buf); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
665 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
666 for (volatile octave_idx_type j = nr-1; j >= 0; j--) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
667 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
668 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
669 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
670 CXSPARSE_DNAME (_happly) (q.N()->L, j, q.N()->B[j], buf); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
671 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
672 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
673 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5792 | 674 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
675 CXSPARSE_DNAME (_pvec) (q.S()->pinv, buf, Xz, nc); |
5792 | 676 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
677 CXSPARSE_DNAME (_pvec) (nc, q.S()->Pinv, buf, Xz); |
5792 | 678 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
679 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
680 for (octave_idx_type j = 0; j < nc; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
681 vec[j+idx] = Complex (Xx[j], Xz[j]); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
682 } |
5797 | 683 info = 0; |
5610 | 684 } |
685 | |
686 return x; | |
687 #else | |
688 return ComplexMatrix (); | |
689 #endif | |
690 } | |
691 | |
692 SparseComplexMatrix | |
693 qrsolve(const SparseMatrix&a, const SparseComplexMatrix &b, octave_idx_type &info) | |
694 { | |
5797 | 695 info = -1; |
5610 | 696 #ifdef HAVE_CXSPARSE |
697 octave_idx_type nr = a.rows(); | |
698 octave_idx_type nc = a.cols(); | |
699 octave_idx_type b_nr = b.rows(); | |
700 octave_idx_type b_nc = b.cols(); | |
701 SparseComplexMatrix x; | |
702 volatile octave_idx_type ii, x_nz; | |
703 | |
6924 | 704 if (nr < 0 || nc < 0 || nr != b_nr) |
5610 | 705 (*current_liboctave_error_handler) |
706 ("matrix dimension mismatch in solution of minimum norm problem"); | |
6924 | 707 else if (nr == 0 || nc == 0 || b_nc == 0) |
708 x = SparseComplexMatrix (nc, b_nc); | |
5610 | 709 else if (nr >= nc) |
710 { | |
5792 | 711 SparseQR q (a, 3); |
5610 | 712 if (! q.ok ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
713 return SparseComplexMatrix(); |
10506
bdf5d85cfc5e
replace nzmax by nnz where appropriate in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
714 x = SparseComplexMatrix (nc, b_nc, b.nnz()); |
5610 | 715 x.xcidx(0) = 0; |
10506
bdf5d85cfc5e
replace nzmax by nnz where appropriate in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
716 x_nz = b.nnz(); |
5610 | 717 ii = 0; |
718 OCTAVE_LOCAL_BUFFER (double, Xx, (b_nr > nc ? b_nr : nc)); | |
719 OCTAVE_LOCAL_BUFFER (double, Xz, (b_nr > nc ? b_nr : nc)); | |
720 OCTAVE_LOCAL_BUFFER (double, buf, q.S()->m2); | |
721 for (volatile octave_idx_type i = 0, idx = 0; i < b_nc; i++, idx+=nc) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
722 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
723 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
724 for (octave_idx_type j = 0; j < b_nr; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
725 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
726 Complex c = b.xelem (j,i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
727 Xx[j] = std::real (c); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
728 Xz[j] = std::imag (c); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
729 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
730 for (octave_idx_type j = nr; j < q.S()->m2; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
731 buf[j] = 0.; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
732 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5792 | 733 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
734 CXSPARSE_DNAME (_ipvec) (q.S()->pinv, Xx, buf, nr); |
5792 | 735 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
736 CXSPARSE_DNAME (_ipvec) (nr, q.S()->Pinv, Xx, buf); |
5792 | 737 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
738 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
739 for (volatile octave_idx_type j = 0; j < nc; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
740 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
741 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
742 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
743 CXSPARSE_DNAME (_happly) (q.N()->L, j, q.N()->B[j], buf); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
744 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
745 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
746 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
747 CXSPARSE_DNAME (_usolve) (q.N()->U, buf); |
5792 | 748 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
749 CXSPARSE_DNAME (_ipvec) (q.S()->q, buf, Xx, nc); |
5792 | 750 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
751 CXSPARSE_DNAME (_ipvec) (nc, q.S()->Q, buf, Xx); |
5792 | 752 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
753 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
754 for (octave_idx_type j = nr; j < q.S()->m2; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
755 buf[j] = 0.; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
756 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5792 | 757 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
758 CXSPARSE_DNAME (_ipvec) (q.S()->pinv, Xz, buf, nr); |
5792 | 759 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
760 CXSPARSE_DNAME (_ipvec) (nr, q.S()->Pinv, Xz, buf); |
5792 | 761 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
762 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
763 for (volatile octave_idx_type j = 0; j < nc; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
764 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
765 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
766 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
767 CXSPARSE_DNAME (_happly) (q.N()->L, j, q.N()->B[j], buf); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
768 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
769 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
770 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
771 CXSPARSE_DNAME (_usolve) (q.N()->U, buf); |
5792 | 772 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
773 CXSPARSE_DNAME (_ipvec) (q.S()->q, buf, Xz, nc); |
5792 | 774 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
775 CXSPARSE_DNAME (_ipvec) (nc, q.S()->Q, buf, Xz); |
5792 | 776 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
777 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5610 | 778 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
779 for (octave_idx_type j = 0; j < nc; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
780 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
781 Complex tmp = Complex (Xx[j], Xz[j]); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
782 if (tmp != 0.0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
783 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
784 if (ii == x_nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
785 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
786 // Resize the sparse matrix |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
787 octave_idx_type sz = x_nz * (b_nc - i) / b_nc; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
788 sz = (sz > 10 ? sz : 10) + x_nz; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
789 x.change_capacity (sz); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
790 x_nz = sz; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
791 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
792 x.xdata(ii) = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
793 x.xridx(ii++) = j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
794 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
795 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
796 x.xcidx(i+1) = ii; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
797 } |
5797 | 798 info = 0; |
5610 | 799 } |
800 else | |
801 { | |
802 SparseMatrix at = a.hermitian(); | |
5792 | 803 SparseQR q (at, 3); |
5610 | 804 if (! q.ok ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
805 return SparseComplexMatrix(); |
10506
bdf5d85cfc5e
replace nzmax by nnz where appropriate in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
806 x = SparseComplexMatrix (nc, b_nc, b.nnz()); |
5610 | 807 x.xcidx(0) = 0; |
10506
bdf5d85cfc5e
replace nzmax by nnz where appropriate in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
808 x_nz = b.nnz(); |
5610 | 809 ii = 0; |
5681 | 810 volatile octave_idx_type nbuf = (nc > q.S()->m2 ? nc : q.S()->m2); |
5610 | 811 OCTAVE_LOCAL_BUFFER (double, Xx, (b_nr > nc ? b_nr : nc)); |
812 OCTAVE_LOCAL_BUFFER (double, Xz, (b_nr > nc ? b_nr : nc)); | |
5681 | 813 OCTAVE_LOCAL_BUFFER (double, buf, nbuf); |
5610 | 814 for (volatile octave_idx_type i = 0, idx = 0; i < b_nc; i++, idx+=nc) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
815 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
816 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
817 for (octave_idx_type j = 0; j < b_nr; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
818 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
819 Complex c = b.xelem (j,i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
820 Xx[j] = std::real (c); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
821 Xz[j] = std::imag (c); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
822 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
823 for (octave_idx_type j = nr; j < nbuf; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
824 buf[j] = 0.; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
825 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5792 | 826 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
827 CXSPARSE_DNAME (_pvec) (q.S()->q, Xx, buf, nr); |
5792 | 828 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
829 CXSPARSE_DNAME (_pvec) (nr, q.S()->Q, Xx, buf); |
5792 | 830 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
831 CXSPARSE_DNAME (_utsolve) (q.N()->U, buf); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
832 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
833 for (volatile octave_idx_type j = nr-1; j >= 0; j--) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
834 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
835 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
836 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
837 CXSPARSE_DNAME (_happly) (q.N()->L, j, q.N()->B[j], buf); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
838 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
839 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
840 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5792 | 841 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
842 CXSPARSE_DNAME (_pvec) (q.S()->pinv, buf, Xx, nc); |
5792 | 843 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
844 CXSPARSE_DNAME (_pvec) (nc, q.S()->Pinv, buf, Xx); |
5792 | 845 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
846 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
847 for (octave_idx_type j = nr; j < nbuf; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
848 buf[j] = 0.; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
849 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5792 | 850 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
851 CXSPARSE_DNAME (_pvec) (q.S()->q, Xz, buf, nr); |
5792 | 852 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
853 CXSPARSE_DNAME (_pvec) (nr, q.S()->Q, Xz, buf); |
5792 | 854 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
855 CXSPARSE_DNAME (_utsolve) (q.N()->U, buf); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
856 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
857 for (volatile octave_idx_type j = nr-1; j >= 0; j--) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
858 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
859 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
860 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
861 CXSPARSE_DNAME (_happly) (q.N()->L, j, q.N()->B[j], buf); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
862 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
863 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
864 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5792 | 865 #if defined(CS_VER) && (CS_VER >= 2) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
866 CXSPARSE_DNAME (_pvec) (q.S()->pinv, buf, Xz, nc); |
5792 | 867 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
868 CXSPARSE_DNAME (_pvec) (nc, q.S()->Pinv, buf, Xz); |
5792 | 869 #endif |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
870 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5610 | 871 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
872 for (octave_idx_type j = 0; j < nc; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
873 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
874 Complex tmp = Complex (Xx[j], Xz[j]); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
875 if (tmp != 0.0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
876 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
877 if (ii == x_nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
878 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
879 // Resize the sparse matrix |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
880 octave_idx_type sz = x_nz * (b_nc - i) / b_nc; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
881 sz = (sz > 10 ? sz : 10) + x_nz; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
882 x.change_capacity (sz); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
883 x_nz = sz; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
884 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
885 x.xdata(ii) = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
886 x.xridx(ii++) = j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
887 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
888 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
889 x.xcidx(i+1) = ii; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
890 } |
5797 | 891 info = 0; |
5610 | 892 } |
893 | |
894 x.maybe_compress (); | |
895 return x; | |
896 #else | |
897 return SparseComplexMatrix (); | |
898 #endif | |
899 } | |
900 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
901 Matrix |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
902 qrsolve(const SparseMatrix &a, const MArray<double> &b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
903 octave_idx_type &info) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
904 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
905 return qrsolve (a, Matrix (b), info); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
906 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
907 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
908 ComplexMatrix |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
909 qrsolve(const SparseMatrix &a, const MArray<Complex> &b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
910 octave_idx_type &info) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
911 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
912 return qrsolve (a, ComplexMatrix (b), info); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7505
diff
changeset
|
913 } |