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