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