Mercurial > hg > octave-nkf
annotate liboctave/sparse-dmsolve.cc @ 15104:093961d9ebed gui
Fixed self-assignment bug found by Torsten.
* find-dialog.cc: Fixed self-assignment in constructor.
author | Jacob Dawid <jacob.dawid@gmail.com> |
---|---|
date | Sat, 04 Aug 2012 10:53:58 +0200 |
parents | 4328e28414aa |
children |
rev | line source |
---|---|
5683 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
3 Copyright (C) 2006-2012 David Bateman |
5683 | 4 |
7016 | 5 This file is part of Octave. |
6 | |
5683 | 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. | |
5683 | 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/>. | |
5683 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
5797 | 27 #include <vector> |
5794 | 28 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
29 #include "MArray.h" |
5683 | 30 #include "MSparse.h" |
31 #include "SparseQR.h" | |
32 #include "SparseCmplxQR.h" | |
5785 | 33 #include "MatrixType.h" |
5683 | 34 #include "oct-sort.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
7520
diff
changeset
|
35 #include "oct-locbuf.h" |
14888
4315a39da4c9
Do computations with octave_uint64 to avoid overflow
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
36 #include "oct-inttypes.h" |
5683 | 37 |
38 template <class T> | |
39 static MSparse<T> | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
40 dmsolve_extract (const MSparse<T> &A, const octave_idx_type *Pinv, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
41 const octave_idx_type *Q, octave_idx_type rst, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
42 octave_idx_type rend, octave_idx_type cst, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
43 octave_idx_type cend, octave_idx_type maxnz = -1, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
44 bool lazy = false) |
5683 | 45 { |
14888
4315a39da4c9
Do computations with octave_uint64 to avoid overflow
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
46 octave_idx_type nr = rend - rst, nc = cend - cst; |
5683 | 47 maxnz = (maxnz < 0 ? A.nnz () : maxnz); |
14888
4315a39da4c9
Do computations with octave_uint64 to avoid overflow
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
48 octave_idx_type nz; |
4315a39da4c9
Do computations with octave_uint64 to avoid overflow
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
49 |
4315a39da4c9
Do computations with octave_uint64 to avoid overflow
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
50 // Cast to uint64 to handle overflow in this multiplication |
4315a39da4c9
Do computations with octave_uint64 to avoid overflow
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
51 if (octave_uint64 (nr)*octave_uint64 (nc) < octave_uint64 (maxnz)) |
14999
1316bfc6e260
Fix think-o in 4315a39da4c9
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14888
diff
changeset
|
52 nz = nr*nc; |
14888
4315a39da4c9
Do computations with octave_uint64 to avoid overflow
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
53 else |
4315a39da4c9
Do computations with octave_uint64 to avoid overflow
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
54 nz = maxnz; |
4315a39da4c9
Do computations with octave_uint64 to avoid overflow
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
55 |
4315a39da4c9
Do computations with octave_uint64 to avoid overflow
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
56 MSparse<T> B (nr, nc, (nz < maxnz ? nz : maxnz)); |
5683 | 57 // Some sparse functions can support lazy indexing (where elements |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
58 // in the row are in no particular order), even though octave in |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
59 // general can't. For those functions that can using it is a big |
5683 | 60 // win here in terms of speed. |
61 if (lazy) | |
62 { | |
63 nz = 0; | |
64 for (octave_idx_type j = cst ; j < cend ; j++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
65 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
66 octave_idx_type qq = (Q ? Q[j] : j); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
67 B.xcidx (j - cst) = nz; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
68 for (octave_idx_type p = A.cidx (qq) ; p < A.cidx (qq+1) ; p++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
69 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
70 octave_quit (); |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
71 octave_idx_type r = (Pinv ? Pinv[A.ridx (p)] : A.ridx (p)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
72 if (r >= rst && r < rend) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
73 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
74 B.xdata (nz) = A.data (p); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
75 B.xridx (nz++) = r - rst ; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
76 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
77 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
78 } |
5683 | 79 B.xcidx (cend - cst) = nz ; |
80 } | |
81 else | |
82 { | |
83 OCTAVE_LOCAL_BUFFER (T, X, rend - rst); | |
84 octave_sort<octave_idx_type> sort; | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
85 octave_idx_type *ri = B.xridx (); |
5683 | 86 nz = 0; |
87 for (octave_idx_type j = cst ; j < cend ; j++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
88 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
89 octave_idx_type qq = (Q ? Q[j] : j); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
90 B.xcidx (j - cst) = nz; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
91 for (octave_idx_type p = A.cidx (qq) ; p < A.cidx (qq+1) ; p++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
92 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
93 octave_quit (); |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
94 octave_idx_type r = (Pinv ? Pinv[A.ridx (p)] : A.ridx (p)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
95 if (r >= rst && r < rend) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
96 { |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
97 X[r-rst] = A.data (p); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
98 B.xridx (nz++) = r - rst ; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
99 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
100 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
101 sort.sort (ri + B.xcidx (j - cst), nz - B.xcidx (j - cst)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
102 for (octave_idx_type p = B.cidx (j - cst); p < nz; p++) |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
103 B.xdata (p) = X[B.xridx (p)]; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
104 } |
5683 | 105 B.xcidx (cend - cst) = nz ; |
106 } | |
107 | |
108 return B; | |
109 } | |
110 | |
111 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) | |
112 static MSparse<double> | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
113 dmsolve_extract (const MSparse<double> &A, const octave_idx_type *Pinv, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
114 const octave_idx_type *Q, octave_idx_type rst, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
115 octave_idx_type rend, octave_idx_type cst, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
116 octave_idx_type cend, octave_idx_type maxnz, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
117 bool lazy); |
5683 | 118 |
119 static MSparse<Complex> | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
120 dmsolve_extract (const MSparse<Complex> &A, const octave_idx_type *Pinv, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
121 const octave_idx_type *Q, octave_idx_type rst, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
122 octave_idx_type rend, octave_idx_type cst, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
123 octave_idx_type cend, octave_idx_type maxnz, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
124 bool lazy); |
5683 | 125 #endif |
126 | |
127 template <class T> | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
128 static MArray<T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
129 dmsolve_extract (const MArray<T> &m, const octave_idx_type *, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
130 const octave_idx_type *, octave_idx_type r1, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
131 octave_idx_type r2, octave_idx_type c1, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
132 octave_idx_type c2) |
5683 | 133 { |
134 r2 -= 1; | |
135 c2 -= 1; | |
136 if (r1 > r2) { octave_idx_type tmp = r1; r1 = r2; r2 = tmp; } | |
137 if (c1 > c2) { octave_idx_type tmp = c1; c1 = c2; c2 = tmp; } | |
138 | |
139 octave_idx_type new_r = r2 - r1 + 1; | |
140 octave_idx_type new_c = c2 - c1 + 1; | |
141 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
142 MArray<T> result (dim_vector (new_r, new_c)); |
5683 | 143 |
144 for (octave_idx_type j = 0; j < new_c; j++) | |
145 for (octave_idx_type i = 0; i < new_r; i++) | |
146 result.xelem (i, j) = m.elem (r1+i, c1+j); | |
147 | |
148 return result; | |
149 } | |
150 | |
151 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
152 static MArray<double> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
153 dmsolve_extract (const MArray<double> &m, const octave_idx_type *, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
154 const octave_idx_type *, octave_idx_type r1, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
155 octave_idx_type r2, octave_idx_type c1, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
156 octave_idx_type c2) |
5683 | 157 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
158 static MArray<Complex> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
159 dmsolve_extract (const MArray<Complex> &m, const octave_idx_type *, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
160 const octave_idx_type *, octave_idx_type r1, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
161 octave_idx_type r2, octave_idx_type c1, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
162 octave_idx_type c2) |
5683 | 163 #endif |
164 | |
165 template <class T> | |
166 static void | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
167 dmsolve_insert (MArray<T> &a, const MArray<T> &b, const octave_idx_type *Q, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
168 octave_idx_type r, octave_idx_type c) |
5683 | 169 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
170 T *ax = a.fortran_vec (); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
171 const T *bx = b.fortran_vec (); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
172 octave_idx_type anr = a.rows (); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
173 octave_idx_type nr = b.rows (); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
174 octave_idx_type nc = b.cols (); |
5683 | 175 for (octave_idx_type j = 0; j < nc; j++) |
176 { | |
177 octave_idx_type aoff = (c + j) * anr; | |
178 octave_idx_type boff = j * nr; | |
179 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
|
180 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
181 octave_quit (); |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
182 ax[Q[r + i] + aoff] = bx[i + boff]; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
183 } |
5683 | 184 } |
185 } | |
186 | |
187 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) | |
188 static void | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
189 dmsolve_insert (MArray<double> &a, const MArray<double> &b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
190 const octave_idx_type *Q, octave_idx_type r, octave_idx_type c); |
5683 | 191 |
192 static void | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
193 dmsolve_insert (MArray<Complex> &a, const MArray<Complex> &b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
194 const octave_idx_type *Q, octave_idx_type r, octave_idx_type c); |
5683 | 195 #endif |
196 | |
197 template <class T> | |
198 static void | |
199 dmsolve_insert (MSparse<T> &a, const MSparse<T> &b, const octave_idx_type *Q, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
200 octave_idx_type r, octave_idx_type c) |
5683 | 201 { |
202 octave_idx_type b_rows = b.rows (); | |
203 octave_idx_type b_cols = b.cols (); | |
204 octave_idx_type nr = a.rows (); | |
205 octave_idx_type nc = a.cols (); | |
206 | |
207 OCTAVE_LOCAL_BUFFER (octave_idx_type, Qinv, nr); | |
208 for (octave_idx_type i = 0; i < nr; i++) | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
209 Qinv[Q[i]] = i; |
5683 | 210 |
211 // First count the number of elements in the final array | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
212 octave_idx_type nel = a.xcidx (c) + b.nnz (); |
5683 | 213 |
214 if (c + b_cols < nc) | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
215 nel += a.xcidx (nc) - a.xcidx (c + b_cols); |
5683 | 216 |
217 for (octave_idx_type i = c; i < c + b_cols; i++) | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
218 for (octave_idx_type j = a.xcidx (i); j < a.xcidx (i+1); j++) |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
219 if (Qinv[a.xridx (j)] < r || Qinv[a.xridx (j)] >= r + b_rows) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
220 nel++; |
5683 | 221 |
222 OCTAVE_LOCAL_BUFFER (T, X, nr); | |
223 octave_sort<octave_idx_type> sort; | |
224 MSparse<T> tmp (a); | |
225 a = MSparse<T> (nr, nc, nel); | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
226 octave_idx_type *ri = a.xridx (); |
5683 | 227 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
228 for (octave_idx_type i = 0; i < tmp.cidx (c); i++) |
5683 | 229 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
230 a.xdata (i) = tmp.xdata (i); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
231 a.xridx (i) = tmp.xridx (i); |
5683 | 232 } |
233 for (octave_idx_type i = 0; i < c + 1; i++) | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
234 a.xcidx (i) = tmp.xcidx (i); |
5683 | 235 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
236 octave_idx_type ii = a.xcidx (c); |
5683 | 237 |
238 for (octave_idx_type i = c; i < c + b_cols; i++) | |
239 { | |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
240 octave_quit (); |
5683 | 241 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
242 for (octave_idx_type j = tmp.xcidx (i); j < tmp.xcidx (i+1); j++) |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
243 if (Qinv[tmp.xridx (j)] < r || Qinv[tmp.xridx (j)] >= r + b_rows) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
244 { |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
245 X[tmp.xridx (j)] = tmp.xdata (j); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
246 a.xridx (ii++) = tmp.xridx (j); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
247 } |
5683 | 248 |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
249 octave_quit (); |
5683 | 250 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
251 for (octave_idx_type j = b.cidx (i-c); j < b.cidx (i-c+1); j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
252 { |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
253 X[Q[r + b.ridx (j)]] = b.data (j); |
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
254 a.xridx (ii++) = Q[r + b.ridx (j)]; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
255 } |
5683 | 256 |
257 sort.sort (ri + a.xcidx (i), ii - a.xcidx (i)); | |
258 for (octave_idx_type p = a.xcidx (i); p < ii; p++) | |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
259 a.xdata (p) = X[a.xridx (p)]; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
260 a.xcidx (i+1) = ii; |
5683 | 261 } |
262 | |
263 for (octave_idx_type i = c + b_cols; i < nc; i++) | |
264 { | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
265 for (octave_idx_type j = tmp.xcidx (i); j < tmp.cidx (i+1); j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
266 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
267 a.xdata (ii) = tmp.xdata (j); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
268 a.xridx (ii++) = tmp.xridx (j); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
269 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
270 a.xcidx (i+1) = ii; |
5683 | 271 } |
272 } | |
273 | |
274 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) | |
275 static void | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
276 dmsolve_insert (MSparse<double> &a, const SparseMatrix &b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
277 const octave_idx_type *Q, octave_idx_type r, octave_idx_type c); |
5683 | 278 |
279 static void | |
280 dmsolve_insert (MSparse<Complex> &a, const MSparse<Complex> &b, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
281 const octave_idx_type *Q, octave_idx_type r, octave_idx_type c); |
5683 | 282 #endif |
283 | |
284 template <class T, class RT> | |
285 static void | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
286 dmsolve_permute (MArray<RT> &a, const MArray<T>& b, const octave_idx_type *p) |
5683 | 287 { |
288 octave_idx_type b_nr = b.rows (); | |
289 octave_idx_type b_nc = b.cols (); | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
290 const T *Bx = b.fortran_vec (); |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
291 a.resize (dim_vector (b_nr, b_nc)); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
292 RT *Btx = a.fortran_vec (); |
5683 | 293 for (octave_idx_type j = 0; j < b_nc; j++) |
294 { | |
295 octave_idx_type off = j * b_nr; | |
296 for (octave_idx_type i = 0; i < b_nr; i++) | |
10314
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 (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
299 Btx[p[i] + off] = Bx[ i + off]; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
300 } |
5683 | 301 } |
302 } | |
303 | |
304 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) | |
305 static void | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
306 dmsolve_permute (MArray<double> &a, const MArray<double>& b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
307 const octave_idx_type *p); |
5683 | 308 |
309 static void | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
310 dmsolve_permute (MArray<Complex> &a, const MArray<double>& b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
311 const octave_idx_type *p); |
5683 | 312 |
313 static void | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
314 dmsolve_permute (MArray<Complex> &a, const MArray<Complex>& b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
315 const octave_idx_type *p); |
5683 | 316 #endif |
317 | |
318 template <class T, class RT> | |
319 static void | |
320 dmsolve_permute (MSparse<RT> &a, const MSparse<T>& b, const octave_idx_type *p) | |
321 { | |
322 octave_idx_type b_nr = b.rows (); | |
323 octave_idx_type b_nc = b.cols (); | |
324 octave_idx_type b_nz = b.nnz (); | |
325 octave_idx_type nz = 0; | |
326 a = MSparse<RT> (b_nr, b_nc, b_nz); | |
327 octave_sort<octave_idx_type> sort; | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
328 octave_idx_type *ri = a.xridx (); |
5683 | 329 OCTAVE_LOCAL_BUFFER (RT, X, b_nr); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
330 a.xcidx (0) = 0; |
5683 | 331 for (octave_idx_type j = 0; j < b_nc; j++) |
332 { | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
333 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
334 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
335 octave_quit (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
336 octave_idx_type r = p[b.ridx (i)]; |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
337 X[r] = b.data (i); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
338 a.xridx (nz++) = p[b.ridx (i)]; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
339 } |
5683 | 340 sort.sort (ri + a.xcidx (j), nz - a.xcidx (j)); |
341 for (octave_idx_type i = a.cidx (j); i < nz; i++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
342 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
343 octave_quit (); |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
344 a.xdata (i) = X[a.xridx (i)]; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
345 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
346 a.xcidx (j+1) = nz; |
5683 | 347 } |
348 } | |
349 | |
350 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) | |
351 static void | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
352 dmsolve_permute (MSparse<double> &a, const MSparse<double>& b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
353 const octave_idx_type *p); |
5683 | 354 |
355 static void | |
356 dmsolve_permute (MSparse<Complex> &a, const MSparse<double>& b, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
357 const octave_idx_type *p); |
5683 | 358 |
359 static void | |
360 dmsolve_permute (MSparse<Complex> &a, const MSparse<Complex>& b, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
361 const octave_idx_type *p); |
5683 | 362 #endif |
363 | |
364 static void | |
365 solve_singularity_warning (double) | |
366 { | |
367 // Dummy singularity handler so that LU solver doesn't flag | |
368 // an error for numerically rank defficient matrices | |
369 } | |
370 | |
371 template <class RT, class ST, class T> | |
372 RT | |
373 dmsolve (const ST &a, const T &b, octave_idx_type &info) | |
374 { | |
5684 | 375 #ifdef HAVE_CXSPARSE |
5683 | 376 octave_idx_type nr = a.rows (); |
377 octave_idx_type nc = a.cols (); | |
378 octave_idx_type b_nr = b.rows (); | |
379 octave_idx_type b_nc = b.cols (); | |
380 RT retval; | |
381 | |
6924 | 382 if (nr < 0 || nc < 0 || nr != b_nr) |
5683 | 383 (*current_liboctave_error_handler) |
384 ("matrix dimension mismatch in solution of minimum norm problem"); | |
6924 | 385 else if (nr == 0 || nc == 0 || b_nc == 0) |
386 retval = RT (nc, b_nc, 0.0); | |
5683 | 387 else |
388 { | |
389 octave_idx_type nnz_remaining = a.nnz (); | |
390 CXSPARSE_DNAME () csm; | |
391 csm.m = nr; | |
392 csm.n = nc; | |
7520 | 393 csm.x = 0; |
5683 | 394 csm.nz = -1; |
395 csm.nzmax = a.nnz (); | |
396 // Cast away const on A, with full knowledge that CSparse won't touch it. | |
397 // Prevents the methods below making a copy of the data. | |
398 csm.p = const_cast<octave_idx_type *>(a.cidx ()); | |
399 csm.i = const_cast<octave_idx_type *>(a.ridx ()); | |
400 | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
401 #if defined (CS_VER) && (CS_VER >= 2) |
5792 | 402 CXSPARSE_DNAME (d) *dm = CXSPARSE_DNAME(_dmperm) (&csm, 0); |
403 octave_idx_type *p = dm->p; | |
404 octave_idx_type *q = dm->q; | |
405 #else | |
5683 | 406 CXSPARSE_DNAME (d) *dm = CXSPARSE_DNAME(_dmperm) (&csm); |
407 octave_idx_type *p = dm->P; | |
408 octave_idx_type *q = dm->Q; | |
5792 | 409 #endif |
5683 | 410 OCTAVE_LOCAL_BUFFER (octave_idx_type, pinv, nr); |
411 for (octave_idx_type i = 0; i < nr; i++) | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
412 pinv[p[i]] = i; |
5683 | 413 RT btmp; |
414 dmsolve_permute (btmp, b, pinv); | |
415 info = 0; | |
416 retval.resize (nc, b_nc); | |
417 | |
418 // Leading over-determined block | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
419 if (dm->rr[2] < nr && dm->cc[3] < nc) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
420 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
421 ST m = dmsolve_extract (a, pinv, q, dm->rr[2], nr, dm->cc[3], nc, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
422 nnz_remaining, true); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
423 nnz_remaining -= m.nnz (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
424 RT mtmp = |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
425 qrsolve (m, dmsolve_extract (btmp, 0, 0, dm->rr[2], b_nr, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
426 b_nc), info); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
427 dmsolve_insert (retval, mtmp, q, dm->cc[3], 0); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
428 if (dm->rr[2] > 0 && !info) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
429 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
430 m = dmsolve_extract (a, pinv, q, 0, dm->rr[2], |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
431 dm->cc[3], nc, nnz_remaining, true); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
432 nnz_remaining -= m.nnz (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
433 RT ctmp = dmsolve_extract (btmp, 0, 0, 0, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
434 dm->rr[2], 0, b_nc); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
435 btmp.insert (ctmp - m * mtmp, 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 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
438 |
5683 | 439 // Structurally non-singular blocks |
5775 | 440 // FIXME Should use fine Dulmange-Mendelsohn decomposition here. |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
441 if (dm->rr[1] < dm->rr[2] && dm->cc[2] < dm->cc[3] && !info) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
442 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
443 ST m = dmsolve_extract (a, pinv, q, dm->rr[1], dm->rr[2], |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
444 dm->cc[2], dm->cc[3], nnz_remaining, false); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
445 nnz_remaining -= m.nnz (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
446 RT btmp2 = dmsolve_extract (btmp, 0, 0, dm->rr[1], dm->rr[2], |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
447 0, b_nc); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
448 double rcond = 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
449 MatrixType mtyp (MatrixType::Full); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
450 RT mtmp = m.solve (mtyp, btmp2, info, rcond, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
451 solve_singularity_warning, false); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
452 if (info != 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
453 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
454 info = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
455 mtmp = qrsolve (m, btmp2, info); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
456 } |
5683 | 457 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
458 dmsolve_insert (retval, mtmp, q, dm->cc[2], 0); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
459 if (dm->rr[1] > 0 && !info) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
460 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
461 m = dmsolve_extract (a, pinv, q, 0, dm->rr[1], dm->cc[2], |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
462 dm->cc[3], nnz_remaining, true); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
463 nnz_remaining -= m.nnz (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
464 RT ctmp = dmsolve_extract (btmp, 0, 0, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
465 dm->rr[1], 0, b_nc); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
466 btmp.insert (ctmp - m * mtmp, 0, 0); |
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 } |
5683 | 469 |
470 // Trailing under-determined block | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
471 if (dm->rr[1] > 0 && dm->cc[2] > 0 && !info) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
472 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
473 ST m = dmsolve_extract (a, pinv, q, 0, dm->rr[1], 0, |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
474 dm->cc[2], nnz_remaining, true); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
475 RT mtmp = |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
476 qrsolve (m, dmsolve_extract (btmp, 0, 0, 0, dm->rr[1] , 0, |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
477 b_nc), info); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
478 dmsolve_insert (retval, mtmp, q, 0, 0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
479 } |
5683 | 480 |
481 CXSPARSE_DNAME (_dfree) (dm); | |
482 } | |
483 return retval; | |
5684 | 484 #else |
485 return RT (); | |
486 #endif | |
5683 | 487 } |
488 | |
489 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) | |
490 extern Matrix | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
491 dmsolve (const SparseMatrix &a, const Matrix &b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
492 octave_idx_type &info); |
5683 | 493 |
494 extern ComplexMatrix | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
495 dmsolve (const SparseMatrix &a, const ComplexMatrix &b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
496 octave_idx_type &info); |
5683 | 497 |
498 extern ComplexMatrix | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
499 dmsolve (const SparseComplexMatrix &a, const Matrix &b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
500 octave_idx_type &info); |
5683 | 501 |
502 extern ComplexMatrix | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
503 dmsolve (const SparseComplexMatrix &a, const ComplexMatrix &b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
504 octave_idx_type &info); |
5683 | 505 |
506 extern SparseMatrix | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
507 dmsolve (const SparseMatrix &a, const SparseMatrix &b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
508 octave_idx_type &info); |
5683 | 509 |
510 extern SparseComplexMatrix | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
511 dmsolve (const SparseMatrix &a, const SparseComplexMatrix &b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
512 octave_idx_type &info); |
5683 | 513 |
514 extern SparseComplexMatrix | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
515 dmsolve (const SparseComplexMatrix &a, const SparseMatrix &b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
516 octave_idx_type &info); |
5683 | 517 |
518 extern SparseComplexMatrix | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
519 dmsolve (const SparseComplexMatrix &a, const SparseComplexMatrix &b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
520 octave_idx_type &info); |
5683 | 521 #endif |