Mercurial > octave
annotate liboctave/numeric/sparse-dmsolve.cc @ 21602:47c76e56a1de
maint: Remove extra space between end of statement and semicolon.
* bsxfun.cc, data.cc, gl-render.cc, graphics.cc, ls-mat4.h, amd.cc,
audioread.cc, ccolamd.cc, colamd.cc, eigs-base.cc, sparse-chol.cc,
sparse-dmsolve.cc, Sparse-op-defs.h, bicubic.m, sprandsym.m:
maint: Remove extra space between end of statement and semicolon.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 10 Apr 2016 20:45:01 -0700 |
parents | 40de9f8f23a6 |
children | 263d18409fdf |
rev | line source |
---|---|
5683 | 1 /* |
2 | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
3 Copyright (C) 2016 John W. Eaton |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
18084
diff
changeset
|
4 Copyright (C) 2006-2015 David Bateman |
5683 | 5 |
7016 | 6 This file is part of Octave. |
7 | |
5683 | 8 Octave is free software; you can redistribute it and/or modify it |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
5683 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
5683 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21219
diff
changeset
|
25 # include "config.h" |
5683 | 26 #endif |
27 | |
5797 | 28 #include <vector> |
5794 | 29 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
30 #include "MArray.h" |
5683 | 31 #include "MSparse.h" |
5785 | 32 #include "MatrixType.h" |
21186
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
33 #include "oct-inttypes.h" |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
34 #include "oct-locbuf.h" |
5683 | 35 #include "oct-sort.h" |
21186
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
36 #include "oct-sparse.h" |
7f35125714b4
don't install some internal headers and template sources
John W. Eaton <jwe@octave.org>
parents:
21177
diff
changeset
|
37 #include "sparse-qr.h" |
5683 | 38 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21136
diff
changeset
|
39 template <typename T> |
5683 | 40 static MSparse<T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
41 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
|
42 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
|
43 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
|
44 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
|
45 bool lazy = false) |
5683 | 46 { |
18084
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 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
|
48 octave_idx_type nc = cend - cst; |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
49 |
5683 | 50 maxnz = (maxnz < 0 ? A.nnz () : maxnz); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
51 |
14888
4315a39da4c9
Do computations with octave_uint64 to avoid overflow
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
52 octave_idx_type nz; |
4315a39da4c9
Do computations with octave_uint64 to avoid overflow
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
53 |
4315a39da4c9
Do computations with octave_uint64 to avoid overflow
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
54 // 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
|
55 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
|
56 nz = nr*nc; |
14888
4315a39da4c9
Do computations with octave_uint64 to avoid overflow
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
57 else |
4315a39da4c9
Do computations with octave_uint64 to avoid overflow
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
58 nz = maxnz; |
4315a39da4c9
Do computations with octave_uint64 to avoid overflow
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
59 |
4315a39da4c9
Do computations with octave_uint64 to avoid overflow
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
60 MSparse<T> B (nr, nc, (nz < maxnz ? nz : maxnz)); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
61 |
5683 | 62 // 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
|
63 // 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
|
64 // general can't. For those functions that can using it is a big |
5683 | 65 // win here in terms of speed. |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
66 |
5683 | 67 if (lazy) |
68 { | |
69 nz = 0; | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
70 |
5683 | 71 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
|
72 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
73 octave_idx_type qq = (Q ? Q[j] : j); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
74 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
75 B.xcidx (j - cst) = nz; |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
76 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
77 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
|
78 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
79 octave_quit (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
80 |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
81 octave_idx_type r = (Pinv ? Pinv[A.ridx (p)] : A.ridx (p)); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
82 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
83 if (r >= rst && r < rend) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
84 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
85 B.xdata (nz) = A.data (p); |
21602
47c76e56a1de
maint: Remove extra space between end of statement and semicolon.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
86 B.xridx (nz++) = r - rst; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
87 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
88 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
89 } |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
90 |
21602
47c76e56a1de
maint: Remove extra space between end of statement and semicolon.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
91 B.xcidx (cend - cst) = nz; |
5683 | 92 } |
93 else | |
94 { | |
95 OCTAVE_LOCAL_BUFFER (T, X, rend - rst); | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
96 |
5683 | 97 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
|
98 octave_idx_type *ri = B.xridx (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
99 |
5683 | 100 nz = 0; |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
101 |
5683 | 102 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
|
103 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
104 octave_idx_type qq = (Q ? Q[j] : j); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
105 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
106 B.xcidx (j - cst) = nz; |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
107 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
108 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
|
109 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
110 octave_quit (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
111 |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
112 octave_idx_type r = (Pinv ? Pinv[A.ridx (p)] : A.ridx (p)); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
113 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
114 if (r >= rst && r < rend) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
115 { |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
116 X[r-rst] = A.data (p); |
21602
47c76e56a1de
maint: Remove extra space between end of statement and semicolon.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
117 B.xridx (nz++) = r - rst; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
118 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
119 } |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
120 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
121 sort.sort (ri + B.xcidx (j - cst), nz - B.xcidx (j - cst)); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
122 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
123 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
|
124 B.xdata (p) = X[B.xridx (p)]; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
125 } |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
126 |
21602
47c76e56a1de
maint: Remove extra space between end of statement and semicolon.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
127 B.xcidx (cend - cst) = nz; |
5683 | 128 } |
129 | |
130 return B; | |
131 } | |
132 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21136
diff
changeset
|
133 template <typename T> |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
134 static MArray<T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
135 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
|
136 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
|
137 octave_idx_type r2, octave_idx_type c1, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
138 octave_idx_type c2) |
5683 | 139 { |
140 r2 -= 1; | |
141 c2 -= 1; | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
142 |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
143 if (r1 > r2) |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
144 std::swap (r1, r2); |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
145 |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
146 if (c1 > c2) |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
147 std::swap (c1, c2); |
5683 | 148 |
149 octave_idx_type new_r = r2 - r1 + 1; | |
150 octave_idx_type new_c = c2 - c1 + 1; | |
151 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
152 MArray<T> result (dim_vector (new_r, new_c)); |
5683 | 153 |
154 for (octave_idx_type j = 0; j < new_c; j++) | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
155 { |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
156 for (octave_idx_type i = 0; i < new_r; i++) |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
157 result.xelem (i, j) = m.elem (r1+i, c1+j); |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
158 } |
5683 | 159 |
160 return result; | |
161 } | |
162 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21136
diff
changeset
|
163 template <typename T> |
5683 | 164 static void |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
165 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
|
166 octave_idx_type r, octave_idx_type c) |
5683 | 167 { |
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
|
168 T *ax = a.fortran_vec (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
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 const T *bx = b.fortran_vec (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
171 |
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
|
172 octave_idx_type anr = a.rows (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
173 |
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
|
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 (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
176 |
5683 | 177 for (octave_idx_type j = 0; j < nc; j++) |
178 { | |
179 octave_idx_type aoff = (c + j) * anr; | |
180 octave_idx_type boff = j * nr; | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
181 |
5683 | 182 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
|
183 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
184 octave_quit (); |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
185 ax[Q[r + i] + aoff] = bx[i + boff]; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
186 } |
5683 | 187 } |
188 } | |
189 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21136
diff
changeset
|
190 template <typename T> |
5683 | 191 static void |
192 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
|
193 octave_idx_type r, octave_idx_type c) |
5683 | 194 { |
195 octave_idx_type b_rows = b.rows (); | |
196 octave_idx_type b_cols = b.cols (); | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
197 |
5683 | 198 octave_idx_type nr = a.rows (); |
199 octave_idx_type nc = a.cols (); | |
200 | |
201 OCTAVE_LOCAL_BUFFER (octave_idx_type, Qinv, nr); | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
202 |
5683 | 203 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
|
204 Qinv[Q[i]] = i; |
5683 | 205 |
206 // 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
|
207 octave_idx_type nel = a.xcidx (c) + b.nnz (); |
5683 | 208 |
209 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
|
210 nel += a.xcidx (nc) - a.xcidx (c + b_cols); |
5683 | 211 |
212 for (octave_idx_type i = c; i < c + b_cols; i++) | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
213 { |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
214 for (octave_idx_type j = a.xcidx (i); j < a.xcidx (i+1); j++) |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
215 { |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
216 if (Qinv[a.xridx (j)] < r || Qinv[a.xridx (j)] >= r + b_rows) |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
217 nel++; |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
218 } |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
219 } |
5683 | 220 |
221 OCTAVE_LOCAL_BUFFER (T, X, nr); | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
222 |
5683 | 223 octave_sort<octave_idx_type> sort; |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
224 |
5683 | 225 MSparse<T> tmp (a); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
226 |
5683 | 227 a = MSparse<T> (nr, nc, nel); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
228 |
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
|
229 octave_idx_type *ri = a.xridx (); |
5683 | 230 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
231 for (octave_idx_type i = 0; i < tmp.cidx (c); i++) |
5683 | 232 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
233 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
|
234 a.xridx (i) = tmp.xridx (i); |
5683 | 235 } |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
236 |
5683 | 237 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
|
238 a.xcidx (i) = tmp.xcidx (i); |
5683 | 239 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
240 octave_idx_type ii = a.xcidx (c); |
5683 | 241 |
242 for (octave_idx_type i = c; i < c + b_cols; i++) | |
243 { | |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
244 octave_quit (); |
5683 | 245 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
246 for (octave_idx_type j = tmp.xcidx (i); j < tmp.xcidx (i+1); j++) |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
247 { |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
248 if (Qinv[tmp.xridx (j)] < r || Qinv[tmp.xridx (j)] >= r + b_rows) |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
249 { |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
250 X[tmp.xridx (j)] = tmp.xdata (j); |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
251 a.xridx (ii++) = tmp.xridx (j); |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
252 } |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
253 } |
5683 | 254 |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
255 octave_quit (); |
5683 | 256 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
257 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
|
258 { |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
259 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
|
260 a.xridx (ii++) = Q[r + b.ridx (j)]; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
261 } |
5683 | 262 |
263 sort.sort (ri + a.xcidx (i), ii - a.xcidx (i)); | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
264 |
5683 | 265 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
|
266 a.xdata (p) = X[a.xridx (p)]; |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
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.xcidx (i+1) = ii; |
5683 | 269 } |
270 | |
271 for (octave_idx_type i = c + b_cols; i < nc; i++) | |
272 { | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
273 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
|
274 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
275 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
|
276 a.xridx (ii++) = tmp.xridx (j); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
277 } |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
278 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
279 a.xcidx (i+1) = ii; |
5683 | 280 } |
281 } | |
282 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21136
diff
changeset
|
283 template <typename T, typename RT> |
5683 | 284 static void |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
285 dmsolve_permute (MArray<RT> &a, const MArray<T>& b, const octave_idx_type *p) |
5683 | 286 { |
287 octave_idx_type b_nr = b.rows (); | |
288 octave_idx_type b_nc = b.cols (); | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
289 |
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 (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
291 |
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)); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
293 |
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
|
294 RT *Btx = a.fortran_vec (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
295 |
5683 | 296 for (octave_idx_type j = 0; j < b_nc; j++) |
297 { | |
298 octave_idx_type off = j * b_nr; | |
299 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
|
300 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
301 octave_quit (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
302 Btx[p[i] + off] = Bx[ i + off]; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
303 } |
5683 | 304 } |
305 } | |
306 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21136
diff
changeset
|
307 template <typename T, typename RT> |
5683 | 308 static void |
309 dmsolve_permute (MSparse<RT> &a, const MSparse<T>& b, const octave_idx_type *p) | |
310 { | |
311 octave_idx_type b_nr = b.rows (); | |
312 octave_idx_type b_nc = b.cols (); | |
313 octave_idx_type b_nz = b.nnz (); | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
314 |
5683 | 315 octave_idx_type nz = 0; |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
316 |
5683 | 317 a = MSparse<RT> (b_nr, b_nc, b_nz); |
318 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
|
319 octave_idx_type *ri = a.xridx (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
320 |
5683 | 321 OCTAVE_LOCAL_BUFFER (RT, X, b_nr); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
322 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
323 a.xcidx (0) = 0; |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
324 |
5683 | 325 for (octave_idx_type j = 0; j < b_nc; j++) |
326 { | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
327 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
|
328 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
329 octave_quit (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
330 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
|
331 X[r] = b.data (i); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
332 a.xridx (nz++) = p[b.ridx (i)]; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
333 } |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
334 |
5683 | 335 sort.sort (ri + a.xcidx (j), nz - a.xcidx (j)); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
336 |
5683 | 337 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
|
338 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
339 octave_quit (); |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
340 a.xdata (i) = X[a.xridx (i)]; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
341 } |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
342 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
343 a.xcidx (j+1) = nz; |
5683 | 344 } |
345 } | |
346 | |
347 static void | |
348 solve_singularity_warning (double) | |
349 { | |
350 // Dummy singularity handler so that LU solver doesn't flag | |
351 // an error for numerically rank defficient matrices | |
352 } | |
353 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21136
diff
changeset
|
354 template <typename RT, typename ST, typename T> |
5683 | 355 RT |
356 dmsolve (const ST &a, const T &b, octave_idx_type &info) | |
357 { | |
5684 | 358 #ifdef HAVE_CXSPARSE |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
359 |
5683 | 360 octave_idx_type nr = a.rows (); |
361 octave_idx_type nc = a.cols (); | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
362 |
5683 | 363 octave_idx_type b_nr = b.rows (); |
364 octave_idx_type b_nc = b.cols (); | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
365 |
5683 | 366 RT retval; |
367 | |
6924 | 368 if (nr < 0 || nc < 0 || nr != b_nr) |
5683 | 369 (*current_liboctave_error_handler) |
370 ("matrix dimension mismatch in solution of minimum norm problem"); | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
371 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21109
diff
changeset
|
372 if (nr == 0 || nc == 0 || b_nc == 0) |
6924 | 373 retval = RT (nc, b_nc, 0.0); |
5683 | 374 else |
375 { | |
376 octave_idx_type nnz_remaining = a.nnz (); | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
377 |
5683 | 378 CXSPARSE_DNAME () csm; |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
379 |
5683 | 380 csm.m = nr; |
381 csm.n = nc; | |
7520 | 382 csm.x = 0; |
5683 | 383 csm.nz = -1; |
384 csm.nzmax = a.nnz (); | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
385 |
5683 | 386 // Cast away const on A, with full knowledge that CSparse won't touch it. |
387 // Prevents the methods below making a copy of the data. | |
388 csm.p = const_cast<octave_idx_type *>(a.cidx ()); | |
389 csm.i = const_cast<octave_idx_type *>(a.ridx ()); | |
390 | |
5792 | 391 CXSPARSE_DNAME (d) *dm = CXSPARSE_DNAME(_dmperm) (&csm, 0); |
392 octave_idx_type *p = dm->p; | |
393 octave_idx_type *q = dm->q; | |
21152
8ad3907b8fad
require CXSparse 2.2 or later
John W. Eaton <jwe@octave.org>
parents:
21149
diff
changeset
|
394 |
5683 | 395 OCTAVE_LOCAL_BUFFER (octave_idx_type, pinv, nr); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
396 |
5683 | 397 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
|
398 pinv[p[i]] = i; |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
399 |
5683 | 400 RT btmp; |
401 dmsolve_permute (btmp, b, pinv); | |
402 info = 0; | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
403 |
5683 | 404 retval.resize (nc, b_nc); |
405 | |
406 // Leading over-determined block | |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
407 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
|
408 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
409 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
|
410 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
|
411 nnz_remaining -= m.nnz (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
412 RT mtmp = qrsolve (m, dmsolve_extract (btmp, 0, 0, dm->rr[2], |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
413 b_nr, 0, b_nc), info); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
414 dmsolve_insert (retval, mtmp, q, dm->cc[3], 0); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
415 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
416 if (dm->rr[2] > 0 && ! info) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
417 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
418 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
|
419 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
|
420 nnz_remaining -= m.nnz (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
421 RT ctmp = dmsolve_extract (btmp, 0, 0, 0, dm->rr[2], 0, b_nc); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
422 btmp.insert (ctmp - m * mtmp, 0, 0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
423 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
424 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
425 |
5683 | 426 // Structurally non-singular blocks |
17861
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
427 // FIXME: Should use fine Dulmange-Mendelsohn decomposition here. |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
428 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
|
429 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
430 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
|
431 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
|
432 nnz_remaining -= m.nnz (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
433 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
|
434 0, b_nc); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
435 double rcond = 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
436 MatrixType mtyp (MatrixType::Full); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
437 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
|
438 solve_singularity_warning, false); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
439 if (info != 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
440 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
441 info = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
442 mtmp = qrsolve (m, btmp2, info); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
443 } |
5683 | 444 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
445 dmsolve_insert (retval, mtmp, q, dm->cc[2], 0); |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
446 if (dm->rr[1] > 0 && ! info) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
447 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
448 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
|
449 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
|
450 nnz_remaining -= m.nnz (); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
451 RT ctmp = dmsolve_extract (btmp, 0, 0, 0, dm->rr[1], 0, b_nc); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
452 btmp.insert (ctmp - m * mtmp, 0, 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 } |
5683 | 455 |
456 // Trailing under-determined block | |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
457 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
|
458 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
459 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
|
460 dm->cc[2], nnz_remaining, true); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
461 RT mtmp = qrsolve (m, dmsolve_extract (btmp, 0, 0, 0, dm->rr[1], |
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
462 0, b_nc), info); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
463 dmsolve_insert (retval, mtmp, q, 0, 0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
464 } |
5683 | 465 |
466 CXSPARSE_DNAME (_dfree) (dm); | |
467 } | |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
468 |
5683 | 469 return retval; |
21109
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
470 |
5684 | 471 #else |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
472 |
15493
9ccf4ffb9fa2
error out when attempting sparse minimum solution and CXSparse is unavailable
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15271
diff
changeset
|
473 (*current_liboctave_error_handler) |
21109
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
474 ("support for CXSparse was unavailable or disabled when liboctave was built"); |
21177
a10f60e13243
style fixes in liboctave/numeric directory
John W. Eaton <jwe@octave.org>
parents:
21176
diff
changeset
|
475 |
5684 | 476 #endif |
5683 | 477 } |
21219
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
478 |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
479 // Instantiations we need. |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
480 |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
481 template ComplexMatrix |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
482 dmsolve<ComplexMatrix, SparseComplexMatrix, Matrix> |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
483 (const SparseComplexMatrix&, const Matrix&, octave_idx_type&); |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
484 |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
485 template SparseComplexMatrix |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
486 dmsolve<SparseComplexMatrix, SparseComplexMatrix, SparseMatrix> |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
487 (const SparseComplexMatrix&, const SparseMatrix&, octave_idx_type&); |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
488 |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
489 template ComplexMatrix |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
490 dmsolve<ComplexMatrix, SparseComplexMatrix, ComplexMatrix> |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
491 (const SparseComplexMatrix&, const ComplexMatrix&, octave_idx_type&); |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
492 |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
493 template SparseComplexMatrix |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
494 dmsolve<SparseComplexMatrix, SparseComplexMatrix, SparseComplexMatrix> |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
495 (const SparseComplexMatrix&, const SparseComplexMatrix&, octave_idx_type&); |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
496 |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
497 template Matrix |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
498 dmsolve<Matrix, SparseMatrix, Matrix> |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
499 (const SparseMatrix&, const Matrix&, octave_idx_type&); |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
500 |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
501 template SparseMatrix |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
502 dmsolve<SparseMatrix, SparseMatrix, SparseMatrix> |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
503 (const SparseMatrix&, const SparseMatrix&, octave_idx_type&); |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
504 |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
505 template ComplexMatrix |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
506 dmsolve<ComplexMatrix, SparseMatrix, ComplexMatrix> |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
507 (const SparseMatrix&, const ComplexMatrix&, octave_idx_type&); |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
508 |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
509 template SparseComplexMatrix |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
510 dmsolve<SparseComplexMatrix, SparseMatrix, SparseComplexMatrix> |
ddf0a5f3a967
split interface and implementation for dmsolve
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
511 (const SparseMatrix&, const SparseComplexMatrix&, octave_idx_type&); |