annotate liboctave/array/CSparse.cc @ 33634:4a70f390c85e default tip @

maint: Merge stable to default.
author Markus Mützel <markus.muetzel@gmx.de>
date Tue, 28 May 2024 15:25:54 +0200
parents 7f73e4805a1f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
32632
2e484f9f1f18 maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 32590
diff changeset
3 // Copyright (C) 1998-2024 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21723
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21229
diff changeset
27 # include "config.h"
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
28 #endif
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
29
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
30 #include <cmath>
23443
3f1bf237908b maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents: 23433
diff changeset
31 #include <complex>
25438
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
32 #include <istream>
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
33 #include <limits>
25438
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
34 #include <ostream>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
35
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
36 #include "quit.h"
33248
7f73e4805a1f replace calls to assert with liboctave_panic functions liboctave
John W. Eaton <jwe@octave.org>
parents: 33203
diff changeset
37 #include "lo-error.h"
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
38 #include "lo-ieee.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
39 #include "lo-mappers.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
40 #include "f77-fcn.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
41 #include "dRowVector.h"
22322
93b3cdd36854 move most f77 function decls to separate header files
John W. Eaton <jwe@octave.org>
parents: 22317
diff changeset
42 #include "lo-lapack-proto.h"
19269
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 19139
diff changeset
43 #include "mx-m-cs.h"
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 19139
diff changeset
44 #include "mx-cs-m.h"
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 19139
diff changeset
45 #include "mx-cm-s.h"
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 19139
diff changeset
46 #include "mx-fcm-fs.h"
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 19139
diff changeset
47 #include "mx-s-cm.h"
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 19139
diff changeset
48 #include "mx-fs-fcm.h"
8377
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 8366
diff changeset
49 #include "oct-locbuf.h"
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
50
8964
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
51 #include "dDiagMatrix.h"
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
52 #include "CDiagMatrix.h"
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
53 #include "CSparse.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
54 #include "boolSparse.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
55 #include "dSparse.h"
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
56 #include "oct-spparms.h"
21146
ea9c05014809 revamp sparse LU factorization classes
John W. Eaton <jwe@octave.org>
parents: 21145
diff changeset
57 #include "sparse-lu.h"
5451
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5429
diff changeset
58 #include "oct-sparse.h"
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
59 #include "sparse-util.h"
21145
307096fb67e1 revamp sparse Cholesky factorization classes
John W. Eaton <jwe@octave.org>
parents: 21140
diff changeset
60 #include "sparse-chol.h"
21176
791dcb32b657 revamp sparse QR factorizatino classes
John W. Eaton <jwe@octave.org>
parents: 21146
diff changeset
61 #include "sparse-qr.h"
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
62
19269
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 19139
diff changeset
63 #include "Sparse-op-defs.h"
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 19139
diff changeset
64
8964
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
65 #include "Sparse-diag-op-defs.h"
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
66
8968
91d53dc37f79 Add perm * sparse, perm \ sparse, sparse * perm, and sparse / perm operations.
Jason Riedy <jason@acm.org>
parents: 8967
diff changeset
67 #include "Sparse-perm-op-defs.h"
91d53dc37f79 Add perm * sparse, perm \ sparse, sparse * perm, and sparse / perm operations.
Jason Riedy <jason@acm.org>
parents: 8967
diff changeset
68
32723
6539de546690 maint: Remove conditional compilation for unused define USE_QRSOLVE.
Rik <rik@octave.org>
parents: 32660
diff changeset
69 #include "sparse-dmsolve.h"
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
70
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
71 SparseComplexMatrix::SparseComplexMatrix (const SparseMatrix& a)
10515
189274f6c7c4 omissions from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 10431
diff changeset
72 : MSparse<Complex> (a)
22417
48c00363dc74 maint: Use '{ }' for empty function bodies in C++.
Rik <rik@octave.org>
parents: 22402
diff changeset
73 { }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
74
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
75 SparseComplexMatrix::SparseComplexMatrix (const SparseBoolMatrix& a)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
76 : MSparse<Complex> (a.rows (), a.cols (), a.nnz ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
77 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
78 octave_idx_type nc = cols ();
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
79 octave_idx_type nz = a.nnz ();
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
80
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
81 for (octave_idx_type i = 0; i < nc + 1; i++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
82 cidx (i) = a.cidx (i);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
83
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
84 for (octave_idx_type i = 0; i < nz; i++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
85 {
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
86 data (i) = Complex (a.data (i));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
87 ridx (i) = a.ridx (i);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
88 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
89 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
90
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
91 SparseComplexMatrix::SparseComplexMatrix (const ComplexDiagMatrix& a)
8910
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8377
diff changeset
92 : MSparse<Complex> (a.rows (), a.cols (), a.length ())
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8377
diff changeset
93 {
18084
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
94 octave_idx_type j = 0;
8e056300994b Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents: 18083
diff changeset
95 octave_idx_type l = a.length ();
8910
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8377
diff changeset
96 for (octave_idx_type i = 0; i < l; i++)
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
97 {
8910
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8377
diff changeset
98 cidx (i) = j;
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8377
diff changeset
99 if (a(i, i) != 0.0)
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
100 {
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
101 data (j) = a(i, i);
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
102 ridx (j) = i;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
103 j++;
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
104 }
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
105 }
8910
6e9f26506804 optimize diag -> sparse and perm -> sparse conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 8377
diff changeset
106 for (octave_idx_type i = l; i <= a.cols (); i++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
107 cidx (i) = j;
8366
8b1a2555c4e2 implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents: 8335
diff changeset
108 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
109 bool
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
110 SparseComplexMatrix::operator == (const SparseComplexMatrix& a) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
111 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
112 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
113 octave_idx_type nc = cols ();
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
114 octave_idx_type nz = nnz ();
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
115 octave_idx_type nr_a = a.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
116 octave_idx_type nc_a = a.cols ();
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
117 octave_idx_type nz_a = a.nnz ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
118
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
119 if (nr != nr_a || nc != nc_a || nz != nz_a)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
120 return false;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
121
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
122 for (octave_idx_type i = 0; i < nc + 1; i++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
123 if (cidx (i) != a.cidx (i))
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
124 return false;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
125
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
126 for (octave_idx_type i = 0; i < nz; i++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
127 if (data (i) != a.data (i) || ridx (i) != a.ridx (i))
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
128 return false;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
129
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
130 return true;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
131 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
132
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
133 bool
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
134 SparseComplexMatrix::operator != (const SparseComplexMatrix& a) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
135 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
136 return !(*this == a);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
137 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
138
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
139 bool
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
140 SparseComplexMatrix::ishermitian () const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
141 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
142 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
143 octave_idx_type nc = cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
144
6207
3c92b8d892dd [project @ 2006-12-06 20:19:14 by dbateman]
dbateman
parents: 6185
diff changeset
145 if (nr == nc && nr > 0)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
146 {
6207
3c92b8d892dd [project @ 2006-12-06 20:19:14 by dbateman]
dbateman
parents: 6185
diff changeset
147 for (octave_idx_type j = 0; j < nc; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
148 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
149 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
150 {
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
151 octave_idx_type ri = ridx (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
152
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
153 if (ri != j)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
154 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
155 bool found = false;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
156
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
157 for (octave_idx_type k = cidx (ri); k < cidx (ri+1); k++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
158 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
159 if (ridx (k) == j)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
160 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
161 if (data (i) == conj (data (k)))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
162 found = true;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
163 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
164 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
165 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
166
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
167 if (! found)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
168 return false;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
169 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
170 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
171 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
172
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
173 return true;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
174 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
175
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
176 return false;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
177 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
178
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22327
diff changeset
179 static const Complex
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
180 Complex_NaN_result (octave::numeric_limits<double>::NaN (),
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
181 octave::numeric_limits<double>::NaN ());
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
182
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
183 SparseComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
184 SparseComplexMatrix::max (int dim) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
185 {
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
186 Array<octave_idx_type> dummy_idx;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
187 return max (dummy_idx, dim);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
188 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
189
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
190 SparseComplexMatrix
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
191 SparseComplexMatrix::max (Array<octave_idx_type>& idx_arg, int dim) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
192 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
193 SparseComplexMatrix result;
32598
2f3b54f81947 avoid dim_vector copies in more places where possible (bug #64962)
John W. Eaton <jwe@octave.org>
parents: 32590
diff changeset
194 const dim_vector& dv = dims ();
17679
c81debf315e0 Avoid use of numel in sparse matrix min/max functions
David Bateman <dbateman@free.fr>
parents: 16313
diff changeset
195 octave_idx_type nr = dv(0);
c81debf315e0 Avoid use of numel in sparse matrix min/max functions
David Bateman <dbateman@free.fr>
parents: 16313
diff changeset
196 octave_idx_type nc = dv(1);
c81debf315e0 Avoid use of numel in sparse matrix min/max functions
David Bateman <dbateman@free.fr>
parents: 16313
diff changeset
197
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21562
diff changeset
198 if (dim >= dv.ndims ())
17682
93e272018df2 Correct dimesion of return values form sparse min/max function with empty
David Bateman <dbateman@free.fr>
parents: 17679
diff changeset
199 {
93e272018df2 Correct dimesion of return values form sparse min/max function with empty
David Bateman <dbateman@free.fr>
parents: 17679
diff changeset
200 idx_arg.resize (dim_vector (nr, nc), 0);
93e272018df2 Correct dimesion of return values form sparse min/max function with empty
David Bateman <dbateman@free.fr>
parents: 17679
diff changeset
201 return *this;
93e272018df2 Correct dimesion of return values form sparse min/max function with empty
David Bateman <dbateman@free.fr>
parents: 17679
diff changeset
202 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
203
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
204 if (dim < 0)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
205 dim = dv.first_non_singleton ();
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
206
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
207 if (dim == 0)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
208 {
17682
93e272018df2 Correct dimesion of return values form sparse min/max function with empty
David Bateman <dbateman@free.fr>
parents: 17679
diff changeset
209 idx_arg.resize (dim_vector (nr == 0 ? 0 : 1, nc), 0);
93e272018df2 Correct dimesion of return values form sparse min/max function with empty
David Bateman <dbateman@free.fr>
parents: 17679
diff changeset
210
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21562
diff changeset
211 if (nr == 0 || nc == 0 || dim >= dv.ndims ())
17682
93e272018df2 Correct dimesion of return values form sparse min/max function with empty
David Bateman <dbateman@free.fr>
parents: 17679
diff changeset
212 return SparseComplexMatrix (nr == 0 ? 0 : 1, nc);
93e272018df2 Correct dimesion of return values form sparse min/max function with empty
David Bateman <dbateman@free.fr>
parents: 17679
diff changeset
213
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
214 octave_idx_type nel = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
215 for (octave_idx_type j = 0; j < nc; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
216 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
217 Complex tmp_max;
21723
bae585228161 use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents: 21721
diff changeset
218 double abs_max = octave::numeric_limits<double>::NaN ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
219 octave_idx_type idx_j = 0;
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
220 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
221 {
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
222 if (ridx (i) != idx_j)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
223 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
224 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
225 idx_j++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
226 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
227
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
228 if (idx_j != nr)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
229 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
230 tmp_max = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
231 abs_max = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
232 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
233
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
234 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
235 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
236 Complex tmp = data (i);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
237
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
238 if (octave::math::isnan (tmp))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
239 continue;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
240
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
241 double abs_tmp = std::abs (tmp);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
242
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
243 if (octave::math::isnan (abs_max) || abs_tmp > abs_max)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
244 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
245 idx_j = ridx (i);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
246 tmp_max = tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
247 abs_max = abs_tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
248 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
249 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
250
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23443
diff changeset
251 idx_arg.elem (j) = (octave::math::isnan (tmp_max) ? 0 : idx_j);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
252 if (abs_max != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
253 nel++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
254 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
255
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
256 result = SparseComplexMatrix (1, nc, nel);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
257
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
258 octave_idx_type ii = 0;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
259 result.xcidx (0) = 0;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
260 for (octave_idx_type j = 0; j < nc; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
261 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
262 Complex tmp = elem (idx_arg(j), j);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
263 if (tmp != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
264 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
265 result.xdata (ii) = tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
266 result.xridx (ii++) = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
267 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
268 result.xcidx (j+1) = ii;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
269 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
270 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
271 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
272 {
17682
93e272018df2 Correct dimesion of return values form sparse min/max function with empty
David Bateman <dbateman@free.fr>
parents: 17679
diff changeset
273 idx_arg.resize (dim_vector (nr, nc == 0 ? 0 : 1), 0);
93e272018df2 Correct dimesion of return values form sparse min/max function with empty
David Bateman <dbateman@free.fr>
parents: 17679
diff changeset
274
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21562
diff changeset
275 if (nr == 0 || nc == 0 || dim >= dv.ndims ())
17682
93e272018df2 Correct dimesion of return values form sparse min/max function with empty
David Bateman <dbateman@free.fr>
parents: 17679
diff changeset
276 return SparseComplexMatrix (nr, nc == 0 ? 0 : 1);
93e272018df2 Correct dimesion of return values form sparse min/max function with empty
David Bateman <dbateman@free.fr>
parents: 17679
diff changeset
277
17691
8a54a481ecb5 Massive speed improvement in sparse min/max functions for calls like
David Bateman <dbateman@free.fr>
parents: 17682
diff changeset
278 OCTAVE_LOCAL_BUFFER (octave_idx_type, found, nr);
8a54a481ecb5 Massive speed improvement in sparse min/max functions for calls like
David Bateman <dbateman@free.fr>
parents: 17682
diff changeset
279
8a54a481ecb5 Massive speed improvement in sparse min/max functions for calls like
David Bateman <dbateman@free.fr>
parents: 17682
diff changeset
280 for (octave_idx_type i = 0; i < nr; i++)
17812
fffd0c0ca2dc maint: A few Octave coding convention tweaks
Rik <rik@octave.org>
parents: 17769
diff changeset
281 found[i] = 0;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
282
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
283 for (octave_idx_type j = 0; j < nc; j++)
18083
938f01339043 maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents: 18080
diff changeset
284 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
17812
fffd0c0ca2dc maint: A few Octave coding convention tweaks
Rik <rik@octave.org>
parents: 17769
diff changeset
285 if (found[ridx (i)] == -j)
fffd0c0ca2dc maint: A few Octave coding convention tweaks
Rik <rik@octave.org>
parents: 17769
diff changeset
286 found[ridx (i)] = -j - 1;
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
287
17691
8a54a481ecb5 Massive speed improvement in sparse min/max functions for calls like
David Bateman <dbateman@free.fr>
parents: 17682
diff changeset
288 for (octave_idx_type i = 0; i < nr; i++)
17812
fffd0c0ca2dc maint: A few Octave coding convention tweaks
Rik <rik@octave.org>
parents: 17769
diff changeset
289 if (found[i] > -nc && found[i] < 0)
fffd0c0ca2dc maint: A few Octave coding convention tweaks
Rik <rik@octave.org>
parents: 17769
diff changeset
290 idx_arg.elem (i) = -found[i];
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
291
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
292 for (octave_idx_type j = 0; j < nc; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
293 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
294 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
295 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
296 octave_idx_type ir = ridx (i);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
297 octave_idx_type ix = idx_arg.elem (ir);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
298 Complex tmp = data (i);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
299
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
300 if (octave::math::isnan (tmp))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
301 continue;
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
302 else if (ix == -1 || std::abs (tmp) > std::abs (elem (ir, ix)))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
303 idx_arg.elem (ir) = j;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
304 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
305 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
306
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
307 octave_idx_type nel = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
308 for (octave_idx_type j = 0; j < nr; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
309 if (idx_arg.elem (j) == -1 || elem (j, idx_arg.elem (j)) != 0.)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
310 nel++;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
311
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
312 result = SparseComplexMatrix (nr, 1, nel);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
313
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
314 octave_idx_type ii = 0;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
315 result.xcidx (0) = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
316 result.xcidx (1) = nel;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
317 for (octave_idx_type j = 0; j < nr; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
318 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
319 if (idx_arg(j) == -1)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
320 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
321 idx_arg(j) = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
322 result.xdata (ii) = Complex_NaN_result;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
323 result.xridx (ii++) = j;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
324 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
325 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
326 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
327 Complex tmp = elem (j, idx_arg(j));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
328 if (tmp != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
329 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
330 result.xdata (ii) = tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
331 result.xridx (ii++) = j;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
332 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
333 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
334 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
335 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
336
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
337 return result;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
338 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
339
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
340 SparseComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
341 SparseComplexMatrix::min (int dim) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
342 {
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
343 Array<octave_idx_type> dummy_idx;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
344 return min (dummy_idx, dim);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
345 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
346
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
347 SparseComplexMatrix
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
348 SparseComplexMatrix::min (Array<octave_idx_type>& idx_arg, int dim) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
349 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
350 SparseComplexMatrix result;
32598
2f3b54f81947 avoid dim_vector copies in more places where possible (bug #64962)
John W. Eaton <jwe@octave.org>
parents: 32590
diff changeset
351 const dim_vector& dv = dims ();
17679
c81debf315e0 Avoid use of numel in sparse matrix min/max functions
David Bateman <dbateman@free.fr>
parents: 16313
diff changeset
352 octave_idx_type nr = dv(0);
c81debf315e0 Avoid use of numel in sparse matrix min/max functions
David Bateman <dbateman@free.fr>
parents: 16313
diff changeset
353 octave_idx_type nc = dv(1);
c81debf315e0 Avoid use of numel in sparse matrix min/max functions
David Bateman <dbateman@free.fr>
parents: 16313
diff changeset
354
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21562
diff changeset
355 if (dim >= dv.ndims ())
17682
93e272018df2 Correct dimesion of return values form sparse min/max function with empty
David Bateman <dbateman@free.fr>
parents: 17679
diff changeset
356 {
93e272018df2 Correct dimesion of return values form sparse min/max function with empty
David Bateman <dbateman@free.fr>
parents: 17679
diff changeset
357 idx_arg.resize (dim_vector (nr, nc), 0);
93e272018df2 Correct dimesion of return values form sparse min/max function with empty
David Bateman <dbateman@free.fr>
parents: 17679
diff changeset
358 return *this;
93e272018df2 Correct dimesion of return values form sparse min/max function with empty
David Bateman <dbateman@free.fr>
parents: 17679
diff changeset
359 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
360
9790
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
361 if (dim < 0)
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
362 dim = dv.first_non_singleton ();
a5035bc7fbfb rewrite dispatch part & slightly improve min,max,cummin,cummax
Jaroslav Hajek <highegg@gmail.com>
parents: 9469
diff changeset
363
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
364 if (dim == 0)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
365 {
17682
93e272018df2 Correct dimesion of return values form sparse min/max function with empty
David Bateman <dbateman@free.fr>
parents: 17679
diff changeset
366 idx_arg.resize (dim_vector (nr == 0 ? 0 : 1, nc), 0);
93e272018df2 Correct dimesion of return values form sparse min/max function with empty
David Bateman <dbateman@free.fr>
parents: 17679
diff changeset
367
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21562
diff changeset
368 if (nr == 0 || nc == 0 || dim >= dv.ndims ())
17682
93e272018df2 Correct dimesion of return values form sparse min/max function with empty
David Bateman <dbateman@free.fr>
parents: 17679
diff changeset
369 return SparseComplexMatrix (nr == 0 ? 0 : 1, nc);
93e272018df2 Correct dimesion of return values form sparse min/max function with empty
David Bateman <dbateman@free.fr>
parents: 17679
diff changeset
370
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
371 octave_idx_type nel = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
372 for (octave_idx_type j = 0; j < nc; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
373 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
374 Complex tmp_min;
21723
bae585228161 use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents: 21721
diff changeset
375 double abs_min = octave::numeric_limits<double>::NaN ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
376 octave_idx_type idx_j = 0;
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
377 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
378 {
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
379 if (ridx (i) != idx_j)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
380 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
381 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
382 idx_j++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
383 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
384
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
385 if (idx_j != nr)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
386 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
387 tmp_min = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
388 abs_min = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
389 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
390
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
391 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
392 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
393 Complex tmp = data (i);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
394
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
395 if (octave::math::isnan (tmp))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
396 continue;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
397
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
398 double abs_tmp = std::abs (tmp);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
399
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
400 if (octave::math::isnan (abs_min) || abs_tmp < abs_min)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
401 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
402 idx_j = ridx (i);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
403 tmp_min = tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
404 abs_min = abs_tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
405 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
406 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
407
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23443
diff changeset
408 idx_arg.elem (j) = (octave::math::isnan (tmp_min) ? 0 : idx_j);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
409 if (abs_min != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
410 nel++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
411 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
412
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
413 result = SparseComplexMatrix (1, nc, nel);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
414
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
415 octave_idx_type ii = 0;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
416 result.xcidx (0) = 0;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
417 for (octave_idx_type j = 0; j < nc; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
418 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
419 Complex tmp = elem (idx_arg(j), j);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
420 if (tmp != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
421 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
422 result.xdata (ii) = tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
423 result.xridx (ii++) = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
424 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
425 result.xcidx (j+1) = ii;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
426 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
427 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
428 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
429 {
17682
93e272018df2 Correct dimesion of return values form sparse min/max function with empty
David Bateman <dbateman@free.fr>
parents: 17679
diff changeset
430 idx_arg.resize (dim_vector (nr, nc == 0 ? 0 : 1), 0);
93e272018df2 Correct dimesion of return values form sparse min/max function with empty
David Bateman <dbateman@free.fr>
parents: 17679
diff changeset
431
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21562
diff changeset
432 if (nr == 0 || nc == 0 || dim >= dv.ndims ())
17682
93e272018df2 Correct dimesion of return values form sparse min/max function with empty
David Bateman <dbateman@free.fr>
parents: 17679
diff changeset
433 return SparseComplexMatrix (nr, nc == 0 ? 0 : 1);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
434
17691
8a54a481ecb5 Massive speed improvement in sparse min/max functions for calls like
David Bateman <dbateman@free.fr>
parents: 17682
diff changeset
435 OCTAVE_LOCAL_BUFFER (octave_idx_type, found, nr);
8a54a481ecb5 Massive speed improvement in sparse min/max functions for calls like
David Bateman <dbateman@free.fr>
parents: 17682
diff changeset
436
8a54a481ecb5 Massive speed improvement in sparse min/max functions for calls like
David Bateman <dbateman@free.fr>
parents: 17682
diff changeset
437 for (octave_idx_type i = 0; i < nr; i++)
17812
fffd0c0ca2dc maint: A few Octave coding convention tweaks
Rik <rik@octave.org>
parents: 17769
diff changeset
438 found[i] = 0;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
439
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
440 for (octave_idx_type j = 0; j < nc; j++)
18083
938f01339043 maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents: 18080
diff changeset
441 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
17812
fffd0c0ca2dc maint: A few Octave coding convention tweaks
Rik <rik@octave.org>
parents: 17769
diff changeset
442 if (found[ridx (i)] == -j)
fffd0c0ca2dc maint: A few Octave coding convention tweaks
Rik <rik@octave.org>
parents: 17769
diff changeset
443 found[ridx (i)] = -j - 1;
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
444
17691
8a54a481ecb5 Massive speed improvement in sparse min/max functions for calls like
David Bateman <dbateman@free.fr>
parents: 17682
diff changeset
445 for (octave_idx_type i = 0; i < nr; i++)
17812
fffd0c0ca2dc maint: A few Octave coding convention tweaks
Rik <rik@octave.org>
parents: 17769
diff changeset
446 if (found[i] > -nc && found[i] < 0)
fffd0c0ca2dc maint: A few Octave coding convention tweaks
Rik <rik@octave.org>
parents: 17769
diff changeset
447 idx_arg.elem (i) = -found[i];
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
448
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
449 for (octave_idx_type j = 0; j < nc; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
450 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
451 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
452 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
453 octave_idx_type ir = ridx (i);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
454 octave_idx_type ix = idx_arg.elem (ir);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
455 Complex tmp = data (i);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
456
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
457 if (octave::math::isnan (tmp))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
458 continue;
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
459 else if (ix == -1 || std::abs (tmp) < std::abs (elem (ir, ix)))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
460 idx_arg.elem (ir) = j;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
461 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
462 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
463
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
464 octave_idx_type nel = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
465 for (octave_idx_type j = 0; j < nr; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
466 if (idx_arg.elem (j) == -1 || elem (j, idx_arg.elem (j)) != 0.)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
467 nel++;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
468
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
469 result = SparseComplexMatrix (nr, 1, nel);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
470
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
471 octave_idx_type ii = 0;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
472 result.xcidx (0) = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
473 result.xcidx (1) = nel;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
474 for (octave_idx_type j = 0; j < nr; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
475 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
476 if (idx_arg(j) == -1)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
477 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
478 idx_arg(j) = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
479 result.xdata (ii) = Complex_NaN_result;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
480 result.xridx (ii++) = j;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
481 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
482 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
483 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
484 Complex tmp = elem (j, idx_arg(j));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
485 if (tmp != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
486 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
487 result.xdata (ii) = tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
488 result.xridx (ii++) = j;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
489 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
490 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
491 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
492 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
493
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
494 return result;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
495 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
496
17679
c81debf315e0 Avoid use of numel in sparse matrix min/max functions
David Bateman <dbateman@free.fr>
parents: 16313
diff changeset
497 /*
c81debf315e0 Avoid use of numel in sparse matrix min/max functions
David Bateman <dbateman@free.fr>
parents: 16313
diff changeset
498
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
499 %!assert (max (max (speye (65536) * 1i)), sparse (1i))
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
500 %!assert (min (min (speye (65536) * 1i)), sparse (0))
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
501 %!assert (size (max (sparse (8, 0), [], 1)), [1, 0])
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
502 %!assert (size (max (sparse (8, 0), [], 2)), [8, 0])
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
503 %!assert (size (max (sparse (0, 8), [], 1)), [0, 8])
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
504 %!assert (size (max (sparse (0, 8), [], 2)), [0, 1])
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
505 %!assert (size (min (sparse (8, 0), [], 1)), [1, 0])
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
506 %!assert (size (min (sparse (8, 0), [], 2)), [8, 0])
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
507 %!assert (size (min (sparse (0, 8), [], 1)), [0, 8])
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
508 %!assert (size (min (sparse (0, 8), [], 2)), [0, 1])
17679
c81debf315e0 Avoid use of numel in sparse matrix min/max functions
David Bateman <dbateman@free.fr>
parents: 16313
diff changeset
509
c81debf315e0 Avoid use of numel in sparse matrix min/max functions
David Bateman <dbateman@free.fr>
parents: 16313
diff changeset
510 */
c81debf315e0 Avoid use of numel in sparse matrix min/max functions
David Bateman <dbateman@free.fr>
parents: 16313
diff changeset
511
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
512 ComplexRowVector
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
513 SparseComplexMatrix::row (octave_idx_type i) const
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
514 {
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
515 octave_idx_type nc = columns ();
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
516 ComplexRowVector retval (nc, 0);
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
517
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
518 for (octave_idx_type j = 0; j < nc; j++)
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
519 for (octave_idx_type k = cidx (j); k < cidx (j+1); k++)
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
520 {
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
521 if (ridx (k) == i)
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
522 {
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
523 retval(j) = data (k);
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
524 break;
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
525 }
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
526 }
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
527
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
528 return retval;
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
529 }
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
530
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
531 ComplexColumnVector
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
532 SparseComplexMatrix::column (octave_idx_type i) const
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
533 {
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
534 octave_idx_type nr = rows ();
13948
a3676380e841 Fix for CSparse.cc corresponding to cset d672edef956e
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
535 ComplexColumnVector retval (nr, 0);
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
536
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
537 for (octave_idx_type k = cidx (i); k < cidx (i+1); k++)
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
538 retval(ridx (k)) = data (k);
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
539
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
540 return retval;
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
541 }
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 7922
diff changeset
542
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
543 // destructive insert/delete/reorder operations
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
544
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
545 SparseComplexMatrix&
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
546 SparseComplexMatrix::insert (const SparseMatrix& a,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
547 octave_idx_type r, octave_idx_type c)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
548 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
549 SparseComplexMatrix tmp (a);
6060
ced23ae2b5cc [project @ 2006-10-18 02:56:22 by jwe]
jwe
parents: 5893
diff changeset
550 return insert (tmp /*a*/, r, c);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
551 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
552
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
553 SparseComplexMatrix&
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
554 SparseComplexMatrix::insert (const SparseComplexMatrix& a,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
555 octave_idx_type r, octave_idx_type c)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
556 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
557 MSparse<Complex>::insert (a, r, c);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
558 return *this;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
559 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
560
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents: 6482
diff changeset
561 SparseComplexMatrix&
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
562 SparseComplexMatrix::insert (const SparseMatrix& a,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
563 const Array<octave_idx_type>& indx)
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents: 6482
diff changeset
564 {
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents: 6482
diff changeset
565 SparseComplexMatrix tmp (a);
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents: 6482
diff changeset
566 return insert (tmp /*a*/, indx);
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents: 6482
diff changeset
567 }
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents: 6482
diff changeset
568
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents: 6482
diff changeset
569 SparseComplexMatrix&
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
570 SparseComplexMatrix::insert (const SparseComplexMatrix& a,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
571 const Array<octave_idx_type>& indx)
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents: 6482
diff changeset
572 {
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents: 6482
diff changeset
573 MSparse<Complex>::insert (a, indx);
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents: 6482
diff changeset
574 return *this;
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents: 6482
diff changeset
575 }
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents: 6482
diff changeset
576
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
577 SparseComplexMatrix
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
578 SparseComplexMatrix::concat (const SparseComplexMatrix& rb,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
579 const Array<octave_idx_type>& ra_idx)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
580 {
27956
2310164737b3 fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
581 // Don't use numel to avoid all possibility of an overflow
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
582 if (rb.rows () > 0 && rb.cols () > 0)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
583 insert (rb, ra_idx(0), ra_idx(1));
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
584 return *this;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
585 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
586
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
587 SparseComplexMatrix
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
588 SparseComplexMatrix::concat (const SparseMatrix& rb,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
589 const Array<octave_idx_type>& ra_idx)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
590 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
591 SparseComplexMatrix tmp (rb);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
592 if (rb.rows () > 0 && rb.cols () > 0)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
593 insert (tmp, ra_idx(0), ra_idx(1));
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
594 return *this;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
595 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
596
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
597 ComplexMatrix
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
598 SparseComplexMatrix::matrix_value () const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
599 {
10431
5dd7a7bf4950 simplify sparse->full conversions in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 10421
diff changeset
600 return Sparse<Complex>::array_value ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
601 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
602
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
603 SparseComplexMatrix
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
604 SparseComplexMatrix::hermitian () const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
605 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
606 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
607 octave_idx_type nc = cols ();
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
608 octave_idx_type nz = nnz ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
609 SparseComplexMatrix retval (nc, nr, nz);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
610
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5630
diff changeset
611 for (octave_idx_type i = 0; i < nz; i++)
8987
542015fada9e Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents: 8968
diff changeset
612 retval.xcidx (ridx (i) + 1)++;
542015fada9e Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents: 8968
diff changeset
613 // retval.xcidx[1:nr] holds the row degrees for rows 0:(nr-1)
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5630
diff changeset
614 nz = 0;
8987
542015fada9e Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents: 8968
diff changeset
615 for (octave_idx_type i = 1; i <= nr; i++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
616 {
8987
542015fada9e Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents: 8968
diff changeset
617 const octave_idx_type tmp = retval.xcidx (i);
542015fada9e Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents: 8968
diff changeset
618 retval.xcidx (i) = nz;
542015fada9e Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents: 8968
diff changeset
619 nz += tmp;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
620 }
8987
542015fada9e Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents: 8968
diff changeset
621 // retval.xcidx[1:nr] holds row entry *start* offsets for rows 0:(nr-1)
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5630
diff changeset
622
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5630
diff changeset
623 for (octave_idx_type j = 0; j < nc; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
624 for (octave_idx_type k = cidx (j); k < cidx (j+1); k++)
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5630
diff changeset
625 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
626 octave_idx_type q = retval.xcidx (ridx (k) + 1)++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
627 retval.xridx (q) = j;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
628 retval.xdata (q) = conj (data (k));
5648
69a4f320d95a [project @ 2006-03-08 20:17:37 by dbateman]
dbateman
parents: 5630
diff changeset
629 }
33248
7f73e4805a1f replace calls to assert with liboctave_panic functions liboctave
John W. Eaton <jwe@octave.org>
parents: 33203
diff changeset
630 liboctave_panic_unless (nnz () == retval.xcidx (nr));
8987
542015fada9e Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents: 8968
diff changeset
631 // retval.xcidx[1:nr] holds row entry *end* offsets for rows 0:(nr-1)
542015fada9e Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents: 8968
diff changeset
632 // and retval.xcidx[0:(nr-1)] holds their row entry *start* offsets
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
633
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
634 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
635 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
636
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
637 SparseComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
638 conj (const SparseComplexMatrix& a)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
639 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
640 octave_idx_type nr = a.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
641 octave_idx_type nc = a.cols ();
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
642 octave_idx_type nz = a.nnz ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
643 SparseComplexMatrix retval (nc, nr, nz);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
644
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
645 for (octave_idx_type i = 0; i < nc + 1; i++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
646 retval.cidx (i) = a.cidx (i);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
647
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
648 for (octave_idx_type i = 0; i < nz; i++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
649 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
650 retval.data (i) = conj (a.data (i));
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
651 retval.ridx (i) = a.ridx (i);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
652 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
653
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
654 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
655 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
656
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
657 // Local function to check if matrix is singular based on rcond.
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
658 static inline
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
659 bool
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
660 is_singular (const double rcond)
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
661 {
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
662 return (std::abs (rcond) <= std::numeric_limits<double>::epsilon ());
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
663 }
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
664
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
665 SparseComplexMatrix
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
666 SparseComplexMatrix::inverse () const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
667 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
668 octave_idx_type info;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
669 double rcond;
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
670 MatrixType mattype (*this);
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
671 return inverse (mattype, info, rcond, 0, 0);
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
672 }
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
673
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
674 SparseComplexMatrix
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
675 SparseComplexMatrix::inverse (MatrixType& mattype) const
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
676 {
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
677 octave_idx_type info;
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
678 double rcond;
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
679 return inverse (mattype, info, rcond, 0, 0);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
680 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
681
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
682 SparseComplexMatrix
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
683 SparseComplexMatrix::inverse (MatrixType& mattype, octave_idx_type& info) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
684 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
685 double rcond;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
686 return inverse (mattype, info, rcond, 0, 0);
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
687 }
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
688
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
689 SparseComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
690 SparseComplexMatrix::dinverse (MatrixType& mattype, octave_idx_type& info,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
691 double& rcond, const bool,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
692 const bool calccond) const
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
693 {
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
694 SparseComplexMatrix retval;
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
695
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
696 octave_idx_type nr = rows ();
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
697 octave_idx_type nc = cols ();
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
698 info = 0;
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
699
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
700 if (nr == 0 || nc == 0 || nr != nc)
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
701 (*current_liboctave_error_handler) ("inverse requires square matrix");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
702
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
703 // Print spparms("spumoni") info if requested
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
704 int typ = mattype.type ();
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
705 mattype.info ();
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
706
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
707 if (typ != MatrixType::Diagonal && typ != MatrixType::Permuted_Diagonal)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
708 (*current_liboctave_error_handler) ("incorrect matrix type");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
709
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
710 if (typ == MatrixType::Permuted_Diagonal)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
711 retval = transpose ();
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
712 else
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
713 retval = *this;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
714
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
715 // Force make_unique to be called
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
716 Complex *v = retval.data ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
717
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
718 if (calccond)
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
719 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
720 double dmax = 0.;
21723
bae585228161 use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents: 21721
diff changeset
721 double dmin = octave::numeric_limits<double>::Inf ();
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
722 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
723 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
724 double tmp = std::abs (v[i]);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
725 if (tmp > dmax)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
726 dmax = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
727 if (tmp < dmin)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
728 dmin = tmp;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
729 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
730 rcond = dmin / dmax;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
731 }
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
732
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
733 for (octave_idx_type i = 0; i < nr; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
734 v[i] = 1.0 / v[i];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
735
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
736 return retval;
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
737 }
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
738
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
739 SparseComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
740 SparseComplexMatrix::tinverse (MatrixType& mattype, octave_idx_type& info,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
741 double& rcond, const bool,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
742 const bool calccond) const
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
743 {
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
744 SparseComplexMatrix retval;
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
745
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
746 octave_idx_type nr = rows ();
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
747 octave_idx_type nc = cols ();
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
748 info = 0;
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
749
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
750 if (nr == 0 || nc == 0 || nr != nc)
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
751 (*current_liboctave_error_handler) ("inverse requires square matrix");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
752
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
753 // Print spparms("spumoni") info if requested
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
754 int typ = mattype.type ();
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
755 mattype.info ();
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
756
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
757 if (typ != MatrixType::Upper && typ != MatrixType::Permuted_Upper
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
758 && typ != MatrixType::Lower && typ != MatrixType::Permuted_Lower)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
759 (*current_liboctave_error_handler) ("incorrect matrix type");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
760
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
761 double anorm = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
762 double ainvnorm = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
763
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
764 if (calccond)
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
765 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
766 // Calculate the 1-norm of matrix for rcond calculation
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
767 for (octave_idx_type j = 0; j < nr; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
768 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
769 double atmp = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
770 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
771 atmp += std::abs (data (i));
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
772 if (atmp > anorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
773 anorm = atmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
774 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
775 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
776
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
777 if (typ == MatrixType::Upper || typ == MatrixType::Lower)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
778 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
779 octave_idx_type nz = nnz ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
780 octave_idx_type cx = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
781 octave_idx_type nz2 = nz;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
782 retval = SparseComplexMatrix (nr, nc, nz2);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
783
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
784 for (octave_idx_type i = 0; i < nr; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
785 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
786 octave_quit ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
787 // place the 1 in the identity position
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
788 octave_idx_type cx_colstart = cx;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
789
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
790 if (cx == nz2)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
791 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
792 nz2 *= 2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
793 retval.change_capacity (nz2);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
794 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
795
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
796 retval.xcidx (i) = cx;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
797 retval.xridx (cx) = i;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
798 retval.xdata (cx) = 1.0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
799 cx++;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
800
27956
2310164737b3 fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
801 // iterate across columns of input matrix
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
802 for (octave_idx_type j = i+1; j < nr; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
803 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
804 Complex v = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
805 // iterate to calculate sum
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
806 octave_idx_type colXp = retval.xcidx (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
807 octave_idx_type colUp = cidx (j);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
808 octave_idx_type rpX, rpU;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
809
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
810 if (cidx (j) == cidx (j+1))
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
811 (*current_liboctave_error_handler) ("division by zero");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
812
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
813 do
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
814 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
815 octave_quit ();
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
816 rpX = retval.xridx (colXp);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
817 rpU = ridx (colUp);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
818
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
819 if (rpX < rpU)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
820 colXp++;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
821 else if (rpX > rpU)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
822 colUp++;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
823 else
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
824 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
825 v -= retval.xdata (colXp) * data (colUp);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
826 colXp++;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
827 colUp++;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
828 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
829 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
830 while (rpX < j && rpU < j && colXp < cx && colUp < nz);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
831
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
832 // get A(m,m)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
833 if (typ == MatrixType::Upper)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
834 colUp = cidx (j+1) - 1;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
835 else
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
836 colUp = cidx (j);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
837 Complex pivot = data (colUp);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
838 if (pivot == 0. || ridx (colUp) != j)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
839 (*current_liboctave_error_handler) ("division by zero");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
840
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
841 if (v != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
842 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
843 if (cx == nz2)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
844 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
845 nz2 *= 2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
846 retval.change_capacity (nz2);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
847 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
848
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
849 retval.xridx (cx) = j;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
850 retval.xdata (cx) = v / pivot;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
851 cx++;
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
852 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
853 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
854
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
855 // get A(m,m)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
856 octave_idx_type colUp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
857 if (typ == MatrixType::Upper)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
858 colUp = cidx (i+1) - 1;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
859 else
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
860 colUp = cidx (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
861 Complex pivot = data (colUp);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
862 if (pivot == 0. || ridx (colUp) != i)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
863 (*current_liboctave_error_handler) ("division by zero");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
864
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
865 if (pivot != 1.0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
866 for (octave_idx_type j = cx_colstart; j < cx; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
867 retval.xdata (j) /= pivot;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
868 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
869 retval.xcidx (nr) = cx;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
870 retval.maybe_compress ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
871 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
872 else
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
873 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
874 octave_idx_type nz = nnz ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
875 octave_idx_type cx = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
876 octave_idx_type nz2 = nz;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
877 retval = SparseComplexMatrix (nr, nc, nz2);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
878
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
879 OCTAVE_LOCAL_BUFFER (Complex, work, nr);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
880 OCTAVE_LOCAL_BUFFER (octave_idx_type, rperm, nr);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
881
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
882 octave_idx_type *perm = mattype.triangular_perm ();
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
883 if (typ == MatrixType::Permuted_Upper)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
884 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
885 for (octave_idx_type i = 0; i < nr; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
886 rperm[perm[i]] = i;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
887 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
888 else
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
889 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
890 for (octave_idx_type i = 0; i < nr; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
891 rperm[i] = perm[i];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
892 for (octave_idx_type i = 0; i < nr; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
893 perm[rperm[i]] = i;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
894 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
895
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
896 for (octave_idx_type i = 0; i < nr; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
897 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
898 octave_quit ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
899 octave_idx_type iidx = rperm[i];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
900
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
901 for (octave_idx_type j = 0; j < nr; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
902 work[j] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
903
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
904 // place the 1 in the identity position
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
905 work[iidx] = 1.0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
906
27956
2310164737b3 fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
907 // iterate across columns of input matrix
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
908 for (octave_idx_type j = iidx+1; j < nr; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
909 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
910 Complex v = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
911 octave_idx_type jidx = perm[j];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
912 // iterate to calculate sum
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
913 for (octave_idx_type k = cidx (jidx);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
914 k < cidx (jidx+1); k++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
915 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
916 octave_quit ();
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
917 v -= work[ridx (k)] * data (k);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
918 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
919
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
920 // get A(m,m)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
921 Complex pivot;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
922 if (typ == MatrixType::Permuted_Upper)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
923 pivot = data (cidx (jidx+1) - 1);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
924 else
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
925 pivot = data (cidx (jidx));
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
926 if (pivot == 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
927 (*current_liboctave_error_handler) ("division by zero");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
928
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
929 work[j] = v / pivot;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
930 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
931
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
932 // get A(m,m)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
933 octave_idx_type colUp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
934 if (typ == MatrixType::Permuted_Upper)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
935 colUp = cidx (perm[iidx]+1) - 1;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
936 else
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
937 colUp = cidx (perm[iidx]);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
938
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
939 Complex pivot = data (colUp);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
940 if (pivot == 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
941 (*current_liboctave_error_handler) ("division by zero");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
942
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
943 octave_idx_type new_cx = cx;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
944 for (octave_idx_type j = iidx; j < nr; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
945 if (work[j] != 0.0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
946 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
947 new_cx++;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
948 if (pivot != 1.0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
949 work[j] /= pivot;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
950 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
951
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
952 if (cx < new_cx)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
953 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
954 nz2 = (2*nz2 < new_cx ? new_cx : 2*nz2);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
955 retval.change_capacity (nz2);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
956 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
957
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
958 retval.xcidx (i) = cx;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
959 for (octave_idx_type j = iidx; j < nr; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
960 if (work[j] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
961 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
962 retval.xridx (cx) = j;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
963 retval.xdata (cx++) = work[j];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
964 }
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
965 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
966
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
967 retval.xcidx (nr) = cx;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
968 retval.maybe_compress ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
969 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
970
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
971 if (calccond)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
972 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
973 // Calculate the 1-norm of inverse matrix for rcond calculation
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
974 for (octave_idx_type j = 0; j < nr; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
975 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
976 double atmp = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
977 for (octave_idx_type i = retval.cidx (j);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
978 i < retval.cidx (j+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
979 atmp += std::abs (retval.data (i));
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
980 if (atmp > ainvnorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
981 ainvnorm = atmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
982 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
983
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
984 rcond = 1. / ainvnorm / anorm;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
985 }
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
986
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
987 return retval;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
988 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
989
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
990 SparseComplexMatrix
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
991 SparseComplexMatrix::inverse (MatrixType& mattype, octave_idx_type& info,
21719
ff054947d132 use bool instead of int for some logical flags
John W. Eaton <jwe@octave.org>
parents: 21691
diff changeset
992 double& rcond, bool, bool calc_cond) const
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
993 {
27093
6e18f0ce268c Inverse of a sparse/diagonal singular matrix should be a sparse/diagonal matrix of Infs.
marco.caliari@univr.it
parents: 27084
diff changeset
994 if (nnz () == 0)
6e18f0ce268c Inverse of a sparse/diagonal singular matrix should be a sparse/diagonal matrix of Infs.
marco.caliari@univr.it
parents: 27084
diff changeset
995 {
6e18f0ce268c Inverse of a sparse/diagonal singular matrix should be a sparse/diagonal matrix of Infs.
marco.caliari@univr.it
parents: 27084
diff changeset
996 (*current_liboctave_error_handler)
6e18f0ce268c Inverse of a sparse/diagonal singular matrix should be a sparse/diagonal matrix of Infs.
marco.caliari@univr.it
parents: 27084
diff changeset
997 ("inverse of the null matrix not defined");
6e18f0ce268c Inverse of a sparse/diagonal singular matrix should be a sparse/diagonal matrix of Infs.
marco.caliari@univr.it
parents: 27084
diff changeset
998 }
6e18f0ce268c Inverse of a sparse/diagonal singular matrix should be a sparse/diagonal matrix of Infs.
marco.caliari@univr.it
parents: 27084
diff changeset
999
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
1000 int typ = mattype.type (false);
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
1001 SparseComplexMatrix ret;
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
1002
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
1003 if (typ == MatrixType::Unknown)
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
1004 typ = mattype.type (*this);
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
1005
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
1006 if (typ == MatrixType::Diagonal || typ == MatrixType::Permuted_Diagonal)
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
1007 ret = dinverse (mattype, info, rcond, true, calc_cond);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
1008 else if (typ == MatrixType::Upper || typ == MatrixType::Permuted_Upper)
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
1009 ret = tinverse (mattype, info, rcond, true, calc_cond).transpose ();
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
1010 else if (typ == MatrixType::Lower || typ == MatrixType::Permuted_Lower)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1011 {
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
1012 MatrixType newtype = mattype.transpose ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
1013 ret = transpose ().tinverse (newtype, info, rcond, true, calc_cond);
6185
da5a11b3d13e [project @ 2006-11-22 18:57:26 by dbateman]
dbateman
parents: 6060
diff changeset
1014 }
6840
2f17d5556756 [project @ 2007-08-29 08:37:47 by dbateman]
dbateman
parents: 6823
diff changeset
1015 else
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
1016 {
23594
af5b813503cb maint: Deprecate is_hermitian and replace with ishermitian.
Rik <rik@octave.org>
parents: 23457
diff changeset
1017 if (mattype.ishermitian ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1018 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1019 MatrixType tmp_typ (MatrixType::Upper);
22317
6ca3acf5fad8 move some new numeric classes to namespace octave::math
John W. Eaton <jwe@octave.org>
parents: 22274
diff changeset
1020 octave::math::sparse_chol<SparseComplexMatrix> fact (*this, info, false);
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
1021 rcond = fact.rcond ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1022 if (info == 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1023 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1024 double rcond2;
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
1025 SparseMatrix Q = fact.Q ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
1026 SparseComplexMatrix InvL = fact.L ().transpose ().
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1027 tinverse (tmp_typ, info, rcond2,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1028 true, false);
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
1029 ret = Q * InvL.hermitian () * InvL * Q.transpose ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1030 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1031 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1032 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1033 // Matrix is either singular or not positive definite
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1034 mattype.mark_as_unsymmetric ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1035 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1036 }
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
1037
23594
af5b813503cb maint: Deprecate is_hermitian and replace with ishermitian.
Rik <rik@octave.org>
parents: 23457
diff changeset
1038 if (! mattype.ishermitian ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1039 {
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
1040 octave_idx_type n = rows ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1041 ColumnVector Qinit(n);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1042 for (octave_idx_type i = 0; i < n; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1043 Qinit(i) = i;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1044
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1045 MatrixType tmp_typ (MatrixType::Upper);
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22327
diff changeset
1046 octave::math::sparse_lu<SparseComplexMatrix> fact (*this,
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22327
diff changeset
1047 Qinit, Matrix (),
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22327
diff changeset
1048 false, false);
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
1049 rcond = fact.rcond ();
27093
6e18f0ce268c Inverse of a sparse/diagonal singular matrix should be a sparse/diagonal matrix of Infs.
marco.caliari@univr.it
parents: 27084
diff changeset
1050 if (rcond == 0.0)
6e18f0ce268c Inverse of a sparse/diagonal singular matrix should be a sparse/diagonal matrix of Infs.
marco.caliari@univr.it
parents: 27084
diff changeset
1051 {
6e18f0ce268c Inverse of a sparse/diagonal singular matrix should be a sparse/diagonal matrix of Infs.
marco.caliari@univr.it
parents: 27084
diff changeset
1052 // Return all Inf matrix with sparsity pattern of input.
6e18f0ce268c Inverse of a sparse/diagonal singular matrix should be a sparse/diagonal matrix of Infs.
marco.caliari@univr.it
parents: 27084
diff changeset
1053 octave_idx_type nz = nnz ();
6e18f0ce268c Inverse of a sparse/diagonal singular matrix should be a sparse/diagonal matrix of Infs.
marco.caliari@univr.it
parents: 27084
diff changeset
1054 ret = SparseComplexMatrix (rows (), cols (), nz);
6e18f0ce268c Inverse of a sparse/diagonal singular matrix should be a sparse/diagonal matrix of Infs.
marco.caliari@univr.it
parents: 27084
diff changeset
1055 std::fill (ret.xdata (), ret.xdata () + nz,
6e18f0ce268c Inverse of a sparse/diagonal singular matrix should be a sparse/diagonal matrix of Infs.
marco.caliari@univr.it
parents: 27084
diff changeset
1056 octave::numeric_limits<double>::Inf ());
6e18f0ce268c Inverse of a sparse/diagonal singular matrix should be a sparse/diagonal matrix of Infs.
marco.caliari@univr.it
parents: 27084
diff changeset
1057 std::copy_n (ridx (), nz, ret.xridx ());
6e18f0ce268c Inverse of a sparse/diagonal singular matrix should be a sparse/diagonal matrix of Infs.
marco.caliari@univr.it
parents: 27084
diff changeset
1058 std::copy_n (cidx (), cols () + 1, ret.xcidx ());
6e18f0ce268c Inverse of a sparse/diagonal singular matrix should be a sparse/diagonal matrix of Infs.
marco.caliari@univr.it
parents: 27084
diff changeset
1059
6e18f0ce268c Inverse of a sparse/diagonal singular matrix should be a sparse/diagonal matrix of Infs.
marco.caliari@univr.it
parents: 27084
diff changeset
1060 return ret;
6e18f0ce268c Inverse of a sparse/diagonal singular matrix should be a sparse/diagonal matrix of Infs.
marco.caliari@univr.it
parents: 27084
diff changeset
1061 }
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1062 double rcond2;
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
1063 SparseComplexMatrix InvL = fact.L ().transpose ().
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1064 tinverse (tmp_typ, info, rcond2,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1065 true, false);
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
1066 SparseComplexMatrix InvU = fact.U ().
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1067 tinverse (tmp_typ, info, rcond2,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1068 true, false).transpose ();
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
1069 ret = fact.Pc ().transpose () * InvU * InvL * fact.Pr ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1070 }
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
1071 }
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
1072
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
1073 return ret;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1074 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1075
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1076 ComplexDET
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
1077 SparseComplexMatrix::determinant () const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1078 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
1079 octave_idx_type info;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1080 double rcond;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1081 return determinant (info, rcond, 0);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1082 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1083
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1084 ComplexDET
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
1085 SparseComplexMatrix::determinant (octave_idx_type& info) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1086 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1087 double rcond;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1088 return determinant (info, rcond, 0);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1089 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1090
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1091 ComplexDET
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1092 SparseComplexMatrix::determinant (octave_idx_type& err, double& rcond,
21719
ff054947d132 use bool instead of int for some logical flags
John W. Eaton <jwe@octave.org>
parents: 21691
diff changeset
1093 bool) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1094 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1095 ComplexDET retval;
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
1096
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21723
diff changeset
1097 #if defined (HAVE_UMFPACK)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1098
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
1099 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
1100 octave_idx_type nc = cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1101
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1102 if (nr == 0 || nc == 0 || nr != nc)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1103 {
8335
64cf956a109c templatize & fix DET
Jaroslav Hajek <highegg@gmail.com>
parents: 8303
diff changeset
1104 retval = ComplexDET (1.0);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1105 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1106 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1107 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1108 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1109
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1110 // Setup the control parameters
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1111 Matrix Control (UMFPACK_CONTROL, 1);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
1112 double *control = Control.rwdata ();
5322
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5307
diff changeset
1113 UMFPACK_ZNAME (defaults) (control);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1114
29872
df2cdf42a909 update coding style for octave_sparse_params class
John W. Eaton <jwe@octave.org>
parents: 29399
diff changeset
1115 double tmp = octave::sparse_params::get_key ("spumoni");
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1116 if (! octave::math::isnan (tmp))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1117 Control (UMFPACK_PRL) = tmp;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1118
29872
df2cdf42a909 update coding style for octave_sparse_params class
John W. Eaton <jwe@octave.org>
parents: 29399
diff changeset
1119 tmp = octave::sparse_params::get_key ("piv_tol");
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1120 if (! octave::math::isnan (tmp))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1121 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1122 Control (UMFPACK_SYM_PIVOT_TOLERANCE) = tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1123 Control (UMFPACK_PIVOT_TOLERANCE) = tmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1124 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1125
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1126 // Set whether we are allowed to modify Q or not
29872
df2cdf42a909 update coding style for octave_sparse_params class
John W. Eaton <jwe@octave.org>
parents: 29399
diff changeset
1127 tmp = octave::sparse_params::get_key ("autoamd");
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
1128 if (! octave::math::isnan (tmp))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1129 Control (UMFPACK_FIXQ) = tmp;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1130
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1131 // Turn-off UMFPACK scaling for LU
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1132 Control (UMFPACK_SCALE) = UMFPACK_SCALE_NONE;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1133
5322
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5307
diff changeset
1134 UMFPACK_ZNAME (report_control) (control);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1135
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
1136 const octave_idx_type *Ap = cidx ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
1137 const octave_idx_type *Ai = ridx ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1138 const Complex *Ax = data ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1139
23391
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
1140 UMFPACK_ZNAME (report_matrix) (nr, nc,
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
1141 octave::to_suitesparse_intptr (Ap),
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
1142 octave::to_suitesparse_intptr (Ai),
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1143 reinterpret_cast<const double *> (Ax),
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
1144 nullptr, 1, control);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1145
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1146 void *Symbolic;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1147 Matrix Info (1, UMFPACK_INFO);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
1148 double *info = Info.rwdata ();
23391
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
1149 int status = UMFPACK_ZNAME (qsymbolic) (nr, nc,
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
1150 octave::to_suitesparse_intptr (Ap),
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
1151 octave::to_suitesparse_intptr (Ai),
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
1152 reinterpret_cast<const double *> (Ax),
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
1153 nullptr, nullptr, &Symbolic, control, info);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1154
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1155 if (status < 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1156 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1157 UMFPACK_ZNAME (report_status) (control, status);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1158 UMFPACK_ZNAME (report_info) (control, info);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1159
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1160 UMFPACK_ZNAME (free_symbolic) (&Symbolic);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1161
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1162 (*current_liboctave_error_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1163 ("SparseComplexMatrix::determinant symbolic factorization failed");
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1164 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1165 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1166 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1167 UMFPACK_ZNAME (report_symbolic) (Symbolic, control);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1168
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1169 void *Numeric;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1170 status
23391
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
1171 = UMFPACK_ZNAME (numeric) (octave::to_suitesparse_intptr (Ap),
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
1172 octave::to_suitesparse_intptr (Ai),
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1173 reinterpret_cast<const double *> (Ax),
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
1174 nullptr, Symbolic, &Numeric, control, info);
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
1175 UMFPACK_ZNAME (free_symbolic) (&Symbolic);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1176
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1177 rcond = Info (UMFPACK_RCOND);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1178
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1179 if (status < 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1180 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1181 UMFPACK_ZNAME (report_status) (control, status);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1182 UMFPACK_ZNAME (report_info) (control, info);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1183
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1184 UMFPACK_ZNAME (free_numeric) (&Numeric);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1185
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1186 (*current_liboctave_error_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1187 ("SparseComplexMatrix::determinant numeric factorization failed");
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1188 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1189 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1190 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1191 UMFPACK_ZNAME (report_numeric) (Numeric, control);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1192
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1193 double c10[2], e10;
8335
64cf956a109c templatize & fix DET
Jaroslav Hajek <highegg@gmail.com>
parents: 8303
diff changeset
1194
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
1195 status = UMFPACK_ZNAME (get_determinant) (c10, nullptr, &e10,
8335
64cf956a109c templatize & fix DET
Jaroslav Hajek <highegg@gmail.com>
parents: 8303
diff changeset
1196 Numeric, info);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1197
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1198 if (status < 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1199 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1200 UMFPACK_ZNAME (report_status) (control, status);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1201 UMFPACK_ZNAME (report_info) (control, info);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1202
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1203 (*current_liboctave_error_handler)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1204 ("SparseComplexMatrix::determinant error calculating determinant");
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1205 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1206 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1207 retval = ComplexDET (Complex (c10[0], c10[1]), e10, 10);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1208
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1209 UMFPACK_ZNAME (free_numeric) (&Numeric);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1210 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1211 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1212 }
21109
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
1213
5203
dbeafbc0ff64 [project @ 2005-03-15 00:58:55 by jwe]
jwe
parents: 5164
diff changeset
1214 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
1215
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
1216 octave_unused_parameter (err);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
1217 octave_unused_parameter (rcond);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
1218
21109
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
1219 (*current_liboctave_error_handler)
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
1220 ("support for UMFPACK was unavailable or disabled when liboctave was built");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
1221
5203
dbeafbc0ff64 [project @ 2005-03-15 00:58:55 by jwe]
jwe
parents: 5164
diff changeset
1222 #endif
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
1223
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
1224 return retval;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1225 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1226
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1227 ComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
1228 SparseComplexMatrix::dsolve (MatrixType& mattype, const Matrix& b,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1229 octave_idx_type& err, double& rcond,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1230 solve_singularity_handler, bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1231 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1232 ComplexMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1233
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
1234 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
1235 octave_idx_type nc = cols ();
5630
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
1236 octave_idx_type nm = (nc < nr ? nc : nr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1237 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1238
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
1239 if (nr != b.rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1240 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1241 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1242
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1243 if (nr == 0 || nc == 0 || b.cols () == 0)
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
1244 retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1245 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1246 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1247 // Print spparms("spumoni") info if requested
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1248 int typ = mattype.type ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1249 mattype.info ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1250
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1251 if (typ != MatrixType::Diagonal && typ != MatrixType::Permuted_Diagonal)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1252 (*current_liboctave_error_handler) ("incorrect matrix type");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1253
30394
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29937
diff changeset
1254 retval.resize (nc, b.cols (), Complex (0., 0.));
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1255 if (typ == MatrixType::Diagonal)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1256 for (octave_idx_type j = 0; j < b.cols (); j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1257 for (octave_idx_type i = 0; i < nm; i++)
30394
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29937
diff changeset
1258 retval(i, j) = b(i, j) / data (i);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1259 else
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1260 for (octave_idx_type j = 0; j < b.cols (); j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1261 for (octave_idx_type k = 0; k < nc; k++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1262 for (octave_idx_type i = cidx (k); i < cidx (k+1); i++)
30394
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29937
diff changeset
1263 retval(k, j) = b(ridx (i), j) / data (i);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1264
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1265 if (calc_cond)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1266 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1267 double dmax = 0.;
21723
bae585228161 use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents: 21721
diff changeset
1268 double dmin = octave::numeric_limits<double>::Inf ();
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1269 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1270 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1271 double tmp = std::abs (data (i));
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1272 if (tmp > dmax)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1273 dmax = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1274 if (tmp < dmin)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1275 dmin = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1276 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1277 rcond = dmin / dmax;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1278 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1279 else
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1280 rcond = 1.0;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1281 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1282
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1283 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1284 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1285
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1286 SparseComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
1287 SparseComplexMatrix::dsolve (MatrixType& mattype, const SparseMatrix& b,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1288 octave_idx_type& err, double& rcond,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1289 solve_singularity_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1290 bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1291 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1292 SparseComplexMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1293
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
1294 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
1295 octave_idx_type nc = cols ();
5630
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
1296 octave_idx_type nm = (nc < nr ? nc : nr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1297 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1298
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
1299 if (nr != b.rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1300 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1301 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1302
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1303 if (nr == 0 || nc == 0 || b.cols () == 0)
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
1304 retval = SparseComplexMatrix (nc, b.cols ());
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1305 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1306 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1307 // Print spparms("spumoni") info if requested
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1308 int typ = mattype.type ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1309 mattype.info ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1310
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1311 if (typ != MatrixType::Diagonal && typ != MatrixType::Permuted_Diagonal)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1312 (*current_liboctave_error_handler) ("incorrect matrix type");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1313
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1314 octave_idx_type b_nc = b.cols ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1315 octave_idx_type b_nz = b.nnz ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1316 retval = SparseComplexMatrix (nc, b_nc, b_nz);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1317
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1318 retval.xcidx (0) = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1319 octave_idx_type ii = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1320 if (typ == MatrixType::Diagonal)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1321 for (octave_idx_type j = 0; j < b.cols (); j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1322 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1323 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
1324 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1325 if (b.ridx (i) >= nm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1326 break;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1327 retval.xridx (ii) = b.ridx (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1328 retval.xdata (ii++) = b.data (i) / data (b.ridx (i));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1329 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1330 retval.xcidx (j+1) = ii;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1331 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1332 else
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1333 for (octave_idx_type j = 0; j < b.cols (); j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1334 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1335 for (octave_idx_type l = 0; l < nc; l++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1336 for (octave_idx_type i = cidx (l); i < cidx (l+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1337 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1338 bool found = false;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1339 octave_idx_type k;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1340 for (k = b.cidx (j); k < b.cidx (j+1); k++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1341 if (ridx (i) == b.ridx (k))
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1342 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1343 found = true;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1344 break;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1345 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1346 if (found)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1347 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1348 retval.xridx (ii) = l;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1349 retval.xdata (ii++) = b.data (k) / data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1350 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1351 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1352 retval.xcidx (j+1) = ii;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1353 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1354
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1355 if (calc_cond)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1356 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1357 double dmax = 0.;
21723
bae585228161 use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents: 21721
diff changeset
1358 double dmin = octave::numeric_limits<double>::Inf ();
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1359 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1360 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1361 double tmp = std::abs (data (i));
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1362 if (tmp > dmax)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1363 dmax = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1364 if (tmp < dmin)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1365 dmin = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1366 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1367 rcond = dmin / dmax;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1368 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1369 else
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1370 rcond = 1.0;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1371 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1372
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1373 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1374 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1375
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1376 ComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
1377 SparseComplexMatrix::dsolve (MatrixType& mattype, const ComplexMatrix& b,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1378 octave_idx_type& err, double& rcond,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1379 solve_singularity_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1380 bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1381 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1382 ComplexMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1383
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
1384 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
1385 octave_idx_type nc = cols ();
5630
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
1386 octave_idx_type nm = (nc < nr ? nc : nr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1387 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1388
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
1389 if (nr != b.rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1390 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1391 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1392
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1393 if (nr == 0 || nc == 0 || b.cols () == 0)
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
1394 retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1395 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1396 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1397 // Print spparms("spumoni") info if requested
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1398 int typ = mattype.type ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1399 mattype.info ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1400
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1401 if (typ != MatrixType::Diagonal && typ != MatrixType::Permuted_Diagonal)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1402 (*current_liboctave_error_handler) ("incorrect matrix type");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1403
30394
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29937
diff changeset
1404 retval.resize (nc, b.cols (), Complex (0., 0.));
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1405 if (typ == MatrixType::Diagonal)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1406 for (octave_idx_type j = 0; j < b.cols (); j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1407 for (octave_idx_type i = 0; i < nm; i++)
30394
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29937
diff changeset
1408 retval(i, j) = b(i, j) / data (i);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1409 else
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1410 for (octave_idx_type j = 0; j < b.cols (); j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1411 for (octave_idx_type k = 0; k < nc; k++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1412 for (octave_idx_type i = cidx (k); i < cidx (k+1); i++)
30394
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29937
diff changeset
1413 retval(k, j) = b(ridx (i), j) / data (i);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1414
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1415 if (calc_cond)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1416 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1417 double dmax = 0.;
21723
bae585228161 use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents: 21721
diff changeset
1418 double dmin = octave::numeric_limits<double>::Inf ();
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1419 for (octave_idx_type i = 0; i < nr; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1420 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1421 double tmp = std::abs (data (i));
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1422 if (tmp > dmax)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1423 dmax = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1424 if (tmp < dmin)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1425 dmin = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1426 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1427 rcond = dmin / dmax;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1428 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1429 else
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1430 rcond = 1.0;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1431 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1432
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1433 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1434 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1435
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1436 SparseComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
1437 SparseComplexMatrix::dsolve (MatrixType& mattype, const SparseComplexMatrix& b,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1438 octave_idx_type& err, double& rcond,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1439 solve_singularity_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1440 bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1441 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1442 SparseComplexMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1443
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
1444 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
1445 octave_idx_type nc = cols ();
5630
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
1446 octave_idx_type nm = (nc < nr ? nc : nr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1447 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1448
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
1449 if (nr != b.rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1450 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1451 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1452
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1453 if (nr == 0 || nc == 0 || b.cols () == 0)
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
1454 retval = SparseComplexMatrix (nc, b.cols ());
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1455 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1456 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1457 // Print spparms("spumoni") info if requested
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1458 int typ = mattype.type ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1459 mattype.info ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1460
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1461 if (typ != MatrixType::Diagonal && typ != MatrixType::Permuted_Diagonal)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1462 (*current_liboctave_error_handler) ("incorrect matrix type");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1463
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1464 octave_idx_type b_nc = b.cols ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1465 octave_idx_type b_nz = b.nnz ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1466 retval = SparseComplexMatrix (nc, b_nc, b_nz);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1467
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1468 retval.xcidx (0) = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1469 octave_idx_type ii = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1470 if (typ == MatrixType::Diagonal)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1471 for (octave_idx_type j = 0; j < b.cols (); j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1472 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1473 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
1474 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1475 if (b.ridx (i) >= nm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1476 break;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1477 retval.xridx (ii) = b.ridx (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1478 retval.xdata (ii++) = b.data (i) / data (b.ridx (i));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1479 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1480 retval.xcidx (j+1) = ii;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1481 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1482 else
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1483 for (octave_idx_type j = 0; j < b.cols (); j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1484 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1485 for (octave_idx_type l = 0; l < nc; l++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1486 for (octave_idx_type i = cidx (l); i < cidx (l+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1487 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1488 bool found = false;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1489 octave_idx_type k;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1490 for (k = b.cidx (j); k < b.cidx (j+1); k++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1491 if (ridx (i) == b.ridx (k))
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1492 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1493 found = true;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1494 break;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1495 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1496 if (found)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1497 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1498 retval.xridx (ii) = l;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1499 retval.xdata (ii++) = b.data (k) / data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1500 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1501 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1502 retval.xcidx (j+1) = ii;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1503 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1504
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1505 if (calc_cond)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1506 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1507 double dmax = 0.;
21723
bae585228161 use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents: 21721
diff changeset
1508 double dmin = octave::numeric_limits<double>::Inf ();
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1509 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1510 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1511 double tmp = std::abs (data (i));
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1512 if (tmp > dmax)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1513 dmax = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1514 if (tmp < dmin)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1515 dmin = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1516 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1517 rcond = dmin / dmax;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1518 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1519 else
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1520 rcond = 1.0;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1521 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1522
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1523 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1524 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1525
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1526 ComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
1527 SparseComplexMatrix::utsolve (MatrixType& mattype, const Matrix& b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1528 octave_idx_type& err, double& rcond,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1529 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1530 bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1531 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1532 ComplexMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1533
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
1534 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
1535 octave_idx_type nc = cols ();
5630
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
1536 octave_idx_type nm = (nc > nr ? nc : nr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1537 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1538
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
1539 if (nr != b.rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1540 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1541 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1542
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1543 if (nr == 0 || nc == 0 || b.cols () == 0)
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
1544 retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1545 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1546 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1547 // Print spparms("spumoni") info if requested
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1548 int typ = mattype.type ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1549 mattype.info ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1550
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1551 if (typ != MatrixType::Permuted_Upper && typ != MatrixType::Upper)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1552 (*current_liboctave_error_handler) ("incorrect matrix type");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1553
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1554 double anorm = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1555 double ainvnorm = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1556 octave_idx_type b_nc = b.cols ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1557 rcond = 1.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1558
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1559 if (calc_cond)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1560 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1561 // Calculate the 1-norm of matrix for rcond calculation
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1562 for (octave_idx_type j = 0; j < nc; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1563 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1564 double atmp = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1565 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1566 atmp += std::abs (data (i));
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1567 if (atmp > anorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1568 anorm = atmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1569 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1570 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1571
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1572 if (typ == MatrixType::Permuted_Upper)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1573 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1574 retval.resize (nc, b_nc);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1575 octave_idx_type *perm = mattype.triangular_perm ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1576 OCTAVE_LOCAL_BUFFER (Complex, work, nm);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1577
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1578 for (octave_idx_type j = 0; j < b_nc; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1579 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1580 for (octave_idx_type i = 0; i < nr; i++)
30394
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29937
diff changeset
1581 work[i] = b(i, j);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1582 for (octave_idx_type i = nr; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1583 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1584
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1585 for (octave_idx_type k = nc-1; k >= 0; k--)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1586 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1587 octave_idx_type kidx = perm[k];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1588
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1589 if (work[k] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1590 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1591 if (ridx (cidx (kidx+1)-1) != k
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1592 || data (cidx (kidx+1)-1) == 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1593 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1594 err = -2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1595 goto triangular_error;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1596 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1597
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1598 Complex tmp = work[k] / data (cidx (kidx+1)-1);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1599 work[k] = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1600 for (octave_idx_type i = cidx (kidx);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1601 i < cidx (kidx+1)-1; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1602 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1603 octave_idx_type iidx = ridx (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1604 work[iidx] = work[iidx] - tmp * data (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1605 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1606 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1607 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1608
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1609 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1610 retval(perm[i], j) = work[i];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1611 }
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1612
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1613 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1614 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1615 // Calculation of 1-norm of inv(*this)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1616 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1617 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1618
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1619 for (octave_idx_type j = 0; j < nr; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1620 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1621 work[j] = 1.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1622
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1623 for (octave_idx_type k = j; k >= 0; k--)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1624 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1625 octave_idx_type iidx = perm[k];
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1626
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1627 if (work[k] != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1628 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1629 Complex tmp = work[k] / data (cidx (iidx+1)-1);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1630 work[k] = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1631 for (octave_idx_type i = cidx (iidx);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1632 i < cidx (iidx+1)-1; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1633 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1634 octave_idx_type idx2 = ridx (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1635 work[idx2] = work[idx2] - tmp * data (i);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1636 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1637 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1638 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1639 double atmp = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1640 for (octave_idx_type i = 0; i < j+1; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1641 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1642 atmp += std::abs (work[i]);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1643 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1644 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1645 if (atmp > ainvnorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1646 ainvnorm = atmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1647 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1648 rcond = 1. / ainvnorm / anorm;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1649 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1650 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1651 else
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1652 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1653 OCTAVE_LOCAL_BUFFER (Complex, work, nm);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1654 retval.resize (nc, b_nc);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1655
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1656 for (octave_idx_type j = 0; j < b_nc; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1657 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1658 for (octave_idx_type i = 0; i < nr; i++)
30394
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29937
diff changeset
1659 work[i] = b(i, j);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1660 for (octave_idx_type i = nr; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1661 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1662
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1663 for (octave_idx_type k = nc-1; k >= 0; k--)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1664 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1665 if (work[k] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1666 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1667 if (ridx (cidx (k+1)-1) != k
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1668 || data (cidx (k+1)-1) == 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1669 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1670 err = -2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1671 goto triangular_error;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1672 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1673
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1674 Complex tmp = work[k] / data (cidx (k+1)-1);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1675 work[k] = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1676 for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1677 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1678 octave_idx_type iidx = ridx (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1679 work[iidx] = work[iidx] - tmp * data (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1680 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1681 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1682 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1683
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1684 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1685 retval.xelem (i, j) = work[i];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1686 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1687
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1688 if (calc_cond)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1689 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1690 // Calculation of 1-norm of inv(*this)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1691 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1692 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1693
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1694 for (octave_idx_type j = 0; j < nr; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1695 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1696 work[j] = 1.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1697
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1698 for (octave_idx_type k = j; k >= 0; k--)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1699 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1700 if (work[k] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1701 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1702 Complex tmp = work[k] / data (cidx (k+1)-1);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1703 work[k] = tmp;
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1704 for (octave_idx_type i = cidx (k);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1705 i < cidx (k+1)-1; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1706 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1707 octave_idx_type iidx = ridx (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1708 work[iidx] = work[iidx] - tmp * data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1709 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1710 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1711 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1712 double atmp = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1713 for (octave_idx_type i = 0; i < j+1; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1714 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1715 atmp += std::abs (work[i]);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1716 work[i] = 0.;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1717 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1718 if (atmp > ainvnorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1719 ainvnorm = atmp;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1720 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1721 rcond = 1. / ainvnorm / anorm;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1722 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1723 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1724
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1725 triangular_error:
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1726 if (err != 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1727 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1728 if (sing_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1729 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1730 sing_handler (rcond);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1731 mattype.mark_as_rectangular ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1732 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1733 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1734 octave::warn_singular_matrix (rcond);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1735 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1736
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
1737 if (is_singular (rcond) || octave::math::isnan (rcond))
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1738 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1739 err = -2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1740
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1741 if (sing_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1742 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1743 sing_handler (rcond);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1744 mattype.mark_as_rectangular ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1745 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1746 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
1747 octave::warn_singular_matrix (rcond);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1748 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1749 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1750
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1751 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1752 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1753
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1754 SparseComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
1755 SparseComplexMatrix::utsolve (MatrixType& mattype, const SparseMatrix& b,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1756 octave_idx_type& err, double& rcond,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1757 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1758 bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1759 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1760 SparseComplexMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1761
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
1762 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
1763 octave_idx_type nc = cols ();
5630
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
1764 octave_idx_type nm = (nc > nr ? nc : nr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1765 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1766
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
1767 if (nr != b.rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1768 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1769 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1770
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1771 if (nr == 0 || nc == 0 || b.cols () == 0)
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
1772 retval = SparseComplexMatrix (nc, b.cols ());
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1773 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1774 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1775 // Print spparms("spumoni") info if requested
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1776 int typ = mattype.type ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1777 mattype.info ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1778
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1779 if (typ != MatrixType::Permuted_Upper && typ != MatrixType::Upper)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1780 (*current_liboctave_error_handler) ("incorrect matrix type");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1781
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1782 double anorm = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1783 double ainvnorm = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1784 rcond = 1.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1785
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1786 if (calc_cond)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1787 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1788 // Calculate the 1-norm of matrix for rcond calculation
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1789 for (octave_idx_type j = 0; j < nc; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1790 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1791 double atmp = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1792 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1793 atmp += std::abs (data (i));
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1794 if (atmp > anorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1795 anorm = atmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1796 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1797 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1798
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1799 octave_idx_type b_nc = b.cols ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1800 octave_idx_type b_nz = b.nnz ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1801 retval = SparseComplexMatrix (nc, b_nc, b_nz);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1802 retval.xcidx (0) = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1803 octave_idx_type ii = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1804 octave_idx_type x_nz = b_nz;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1805
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1806 if (typ == MatrixType::Permuted_Upper)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1807 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1808 octave_idx_type *perm = mattype.triangular_perm ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1809 OCTAVE_LOCAL_BUFFER (Complex, work, nm);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1810
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1811 OCTAVE_LOCAL_BUFFER (octave_idx_type, rperm, nc);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1812 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1813 rperm[perm[i]] = i;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1814
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1815 for (octave_idx_type j = 0; j < b_nc; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1816 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1817 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1818 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1819 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1820 work[b.ridx (i)] = b.data (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1821
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1822 for (octave_idx_type k = nc-1; k >= 0; k--)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1823 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1824 octave_idx_type kidx = perm[k];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1825
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1826 if (work[k] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1827 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1828 if (ridx (cidx (kidx+1)-1) != k
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1829 || data (cidx (kidx+1)-1) == 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1830 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1831 err = -2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1832 goto triangular_error;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1833 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1834
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1835 Complex tmp = work[k] / data (cidx (kidx+1)-1);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1836 work[k] = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1837 for (octave_idx_type i = cidx (kidx);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1838 i < cidx (kidx+1)-1; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1839 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1840 octave_idx_type iidx = ridx (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1841 work[iidx] = work[iidx] - tmp * data (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1842 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1843 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1844 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1845
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1846 // Count nonzeros in work vector and adjust space in
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1847 // retval if needed
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1848 octave_idx_type new_nnz = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1849 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1850 if (work[i] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1851 new_nnz++;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1852
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1853 if (ii + new_nnz > x_nz)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1854 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1855 // Resize the sparse matrix
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1856 octave_idx_type sz = new_nnz * (b_nc - j) + x_nz;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1857 retval.change_capacity (sz);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1858 x_nz = sz;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1859 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1860
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1861 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1862 if (work[rperm[i]] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1863 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1864 retval.xridx (ii) = i;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1865 retval.xdata (ii++) = work[rperm[i]];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1866 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1867 retval.xcidx (j+1) = ii;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1868 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1869
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1870 retval.maybe_compress ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1871
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1872 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1873 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1874 // Calculation of 1-norm of inv(*this)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1875 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1876 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1877
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1878 for (octave_idx_type j = 0; j < nr; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1879 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1880 work[j] = 1.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1881
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1882 for (octave_idx_type k = j; k >= 0; k--)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1883 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1884 octave_idx_type iidx = perm[k];
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1885
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1886 if (work[k] != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1887 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1888 Complex tmp = work[k] / data (cidx (iidx+1)-1);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1889 work[k] = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1890 for (octave_idx_type i = cidx (iidx);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1891 i < cidx (iidx+1)-1; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1892 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1893 octave_idx_type idx2 = ridx (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1894 work[idx2] = work[idx2] - tmp * data (i);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
1895 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1896 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1897 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1898 double atmp = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1899 for (octave_idx_type i = 0; i < j+1; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1900 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1901 atmp += std::abs (work[i]);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1902 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1903 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1904 if (atmp > ainvnorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1905 ainvnorm = atmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1906 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1907 rcond = 1. / ainvnorm / anorm;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1908 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1909 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1910 else
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1911 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1912 OCTAVE_LOCAL_BUFFER (Complex, work, nm);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1913
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1914 for (octave_idx_type j = 0; j < b_nc; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1915 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1916 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1917 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1918 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1919 work[b.ridx (i)] = b.data (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1920
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1921 for (octave_idx_type k = nc-1; k >= 0; k--)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1922 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1923 if (work[k] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1924 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1925 if (ridx (cidx (k+1)-1) != k
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1926 || data (cidx (k+1)-1) == 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1927 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1928 err = -2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1929 goto triangular_error;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1930 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1931
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1932 Complex tmp = work[k] / data (cidx (k+1)-1);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1933 work[k] = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1934 for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1935 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1936 octave_idx_type iidx = ridx (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1937 work[iidx] = work[iidx] - tmp * data (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1938 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1939 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1940 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1941
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1942 // Count nonzeros in work vector and adjust space in
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1943 // retval if needed
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1944 octave_idx_type new_nnz = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1945 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1946 if (work[i] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1947 new_nnz++;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1948
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1949 if (ii + new_nnz > x_nz)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1950 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1951 // Resize the sparse matrix
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1952 octave_idx_type sz = new_nnz * (b_nc - j) + x_nz;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1953 retval.change_capacity (sz);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1954 x_nz = sz;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1955 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1956
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1957 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1958 if (work[i] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1959 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1960 retval.xridx (ii) = i;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1961 retval.xdata (ii++) = work[i];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1962 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1963 retval.xcidx (j+1) = ii;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1964 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1965
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1966 retval.maybe_compress ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1967
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1968 if (calc_cond)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1969 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1970 // Calculation of 1-norm of inv(*this)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1971 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1972 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1973
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1974 for (octave_idx_type j = 0; j < nr; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1975 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1976 work[j] = 1.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1977
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1978 for (octave_idx_type k = j; k >= 0; k--)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1979 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1980 if (work[k] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1981 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1982 Complex tmp = work[k] / data (cidx (k+1)-1);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1983 work[k] = tmp;
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1984 for (octave_idx_type i = cidx (k);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1985 i < cidx (k+1)-1; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1986 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1987 octave_idx_type iidx = ridx (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
1988 work[iidx] = work[iidx] - tmp * data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1989 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1990 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1991 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1992 double atmp = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1993 for (octave_idx_type i = 0; i < j+1; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1994 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1995 atmp += std::abs (work[i]);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1996 work[i] = 0.;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
1997 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1998 if (atmp > ainvnorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
1999 ainvnorm = atmp;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2000 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2001 rcond = 1. / ainvnorm / anorm;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2002 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2003 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2004
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2005 triangular_error:
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2006 if (err != 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2007 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2008 if (sing_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2009 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2010 sing_handler (rcond);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2011 mattype.mark_as_rectangular ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2012 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2013 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2014 octave::warn_singular_matrix (rcond);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2015 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2016
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
2017 if (is_singular (rcond) || octave::math::isnan (rcond))
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2018 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2019 err = -2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2020
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2021 if (sing_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2022 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2023 sing_handler (rcond);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2024 mattype.mark_as_rectangular ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2025 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2026 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2027 octave::warn_singular_matrix (rcond);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2028 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2029 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2030 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2031 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2032
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2033 ComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
2034 SparseComplexMatrix::utsolve (MatrixType& mattype, const ComplexMatrix& b,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2035 octave_idx_type& err, double& rcond,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2036 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2037 bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2038 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2039 ComplexMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2040
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
2041 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
2042 octave_idx_type nc = cols ();
5630
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
2043 octave_idx_type nm = (nc > nr ? nc : nr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2044 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2045
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
2046 if (nr != b.rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2047 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2048 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2049
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2050 if (nr == 0 || nc == 0 || b.cols () == 0)
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
2051 retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2052 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2053 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2054 // Print spparms("spumoni") info if requested
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2055 int typ = mattype.type ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2056 mattype.info ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2057
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2058 if (typ != MatrixType::Permuted_Upper && typ != MatrixType::Upper)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2059 (*current_liboctave_error_handler) ("incorrect matrix type");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2060
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2061 double anorm = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2062 double ainvnorm = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2063 octave_idx_type b_nc = b.cols ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2064 rcond = 1.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2065
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2066 if (calc_cond)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2067 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2068 // Calculate the 1-norm of matrix for rcond calculation
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2069 for (octave_idx_type j = 0; j < nc; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2070 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2071 double atmp = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2072 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2073 atmp += std::abs (data (i));
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2074 if (atmp > anorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2075 anorm = atmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2076 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2077 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2078
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2079 if (typ == MatrixType::Permuted_Upper)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2080 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2081 retval.resize (nc, b_nc);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2082 octave_idx_type *perm = mattype.triangular_perm ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2083 OCTAVE_LOCAL_BUFFER (Complex, work, nm);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2084
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2085 for (octave_idx_type j = 0; j < b_nc; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2086 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2087 for (octave_idx_type i = 0; i < nr; i++)
30394
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29937
diff changeset
2088 work[i] = b(i, j);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2089 for (octave_idx_type i = nr; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2090 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2091
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2092 for (octave_idx_type k = nc-1; k >= 0; k--)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2093 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2094 octave_idx_type kidx = perm[k];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2095
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2096 if (work[k] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2097 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2098 if (ridx (cidx (kidx+1)-1) != k
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2099 || data (cidx (kidx+1)-1) == 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2100 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2101 err = -2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2102 goto triangular_error;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2103 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2104
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2105 Complex tmp = work[k] / data (cidx (kidx+1)-1);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2106 work[k] = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2107 for (octave_idx_type i = cidx (kidx);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2108 i < cidx (kidx+1)-1; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2109 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2110 octave_idx_type iidx = ridx (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2111 work[iidx] = work[iidx] - tmp * data (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2112 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2113 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2114 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2115
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2116 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2117 retval(perm[i], j) = work[i];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2118 }
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2119
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2120 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2121 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2122 // Calculation of 1-norm of inv(*this)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2123 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2124 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2125
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2126 for (octave_idx_type j = 0; j < nr; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2127 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2128 work[j] = 1.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2129
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2130 for (octave_idx_type k = j; k >= 0; k--)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2131 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2132 octave_idx_type iidx = perm[k];
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2133
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2134 if (work[k] != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2135 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2136 Complex tmp = work[k] / data (cidx (iidx+1)-1);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2137 work[k] = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2138 for (octave_idx_type i = cidx (iidx);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2139 i < cidx (iidx+1)-1; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2140 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2141 octave_idx_type idx2 = ridx (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2142 work[idx2] = work[idx2] - tmp * data (i);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2143 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2144 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2145 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2146 double atmp = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2147 for (octave_idx_type i = 0; i < j+1; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2148 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2149 atmp += std::abs (work[i]);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2150 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2151 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2152 if (atmp > ainvnorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2153 ainvnorm = atmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2154 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2155 rcond = 1. / ainvnorm / anorm;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2156 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2157 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2158 else
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2159 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2160 OCTAVE_LOCAL_BUFFER (Complex, work, nm);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2161 retval.resize (nc, b_nc);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2162
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2163 for (octave_idx_type j = 0; j < b_nc; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2164 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2165 for (octave_idx_type i = 0; i < nr; i++)
30394
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29937
diff changeset
2166 work[i] = b(i, j);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2167 for (octave_idx_type i = nr; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2168 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2169
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2170 for (octave_idx_type k = nc-1; k >= 0; k--)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2171 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2172 if (work[k] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2173 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2174 if (ridx (cidx (k+1)-1) != k
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2175 || data (cidx (k+1)-1) == 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2176 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2177 err = -2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2178 goto triangular_error;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2179 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2180
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2181 Complex tmp = work[k] / data (cidx (k+1)-1);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2182 work[k] = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2183 for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2184 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2185 octave_idx_type iidx = ridx (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2186 work[iidx] = work[iidx] - tmp * data (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2187 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2188 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2189 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2190
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2191 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2192 retval.xelem (i, j) = work[i];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2193 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2194
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2195 if (calc_cond)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2196 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2197 // Calculation of 1-norm of inv(*this)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2198 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2199 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2200
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2201 for (octave_idx_type j = 0; j < nr; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2202 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2203 work[j] = 1.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2204
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2205 for (octave_idx_type k = j; k >= 0; k--)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2206 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2207 if (work[k] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2208 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2209 Complex tmp = work[k] / data (cidx (k+1)-1);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2210 work[k] = tmp;
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2211 for (octave_idx_type i = cidx (k);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2212 i < cidx (k+1)-1; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2213 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2214 octave_idx_type iidx = ridx (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2215 work[iidx] = work[iidx] - tmp * data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2216 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2217 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2218 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2219 double atmp = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2220 for (octave_idx_type i = 0; i < j+1; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2221 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2222 atmp += std::abs (work[i]);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2223 work[i] = 0.;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2224 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2225 if (atmp > ainvnorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2226 ainvnorm = atmp;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2227 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2228 rcond = 1. / ainvnorm / anorm;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2229 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2230 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2231
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2232 triangular_error:
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2233 if (err != 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2234 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2235 if (sing_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2236 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2237 sing_handler (rcond);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2238 mattype.mark_as_rectangular ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2239 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2240 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2241 octave::warn_singular_matrix (rcond);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2242 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2243
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
2244 if (is_singular (rcond) || octave::math::isnan (rcond))
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2245 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2246 err = -2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2247
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2248 if (sing_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2249 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2250 sing_handler (rcond);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2251 mattype.mark_as_rectangular ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2252 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2253 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2254 octave::warn_singular_matrix (rcond);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2255 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2256 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2257
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2258 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2259 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2260
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2261 SparseComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
2262 SparseComplexMatrix::utsolve (MatrixType& mattype, const SparseComplexMatrix& b,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2263 octave_idx_type& err, double& rcond,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2264 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2265 bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2266 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2267 SparseComplexMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2268
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
2269 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
2270 octave_idx_type nc = cols ();
5630
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
2271 octave_idx_type nm = (nc > nr ? nc : nr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2272 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2273
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
2274 if (nr != b.rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2275 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2276 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2277
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2278 if (nr == 0 || nc == 0 || b.cols () == 0)
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
2279 retval = SparseComplexMatrix (nc, b.cols ());
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2280 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2281 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2282 // Print spparms("spumoni") info if requested
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2283 int typ = mattype.type ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2284 mattype.info ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2285
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2286 if (typ != MatrixType::Permuted_Upper && typ != MatrixType::Upper)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2287 (*current_liboctave_error_handler) ("incorrect matrix type");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2288
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2289 double anorm = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2290 double ainvnorm = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2291 rcond = 1.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2292
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2293 if (calc_cond)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2294 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2295 // Calculate the 1-norm of matrix for rcond calculation
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2296 for (octave_idx_type j = 0; j < nc; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2297 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2298 double atmp = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2299 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2300 atmp += std::abs (data (i));
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2301 if (atmp > anorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2302 anorm = atmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2303 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2304 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2305
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2306 octave_idx_type b_nc = b.cols ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2307 octave_idx_type b_nz = b.nnz ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2308 retval = SparseComplexMatrix (nc, b_nc, b_nz);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2309 retval.xcidx (0) = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2310 octave_idx_type ii = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2311 octave_idx_type x_nz = b_nz;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2312
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2313 if (typ == MatrixType::Permuted_Upper)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2314 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2315 octave_idx_type *perm = mattype.triangular_perm ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2316 OCTAVE_LOCAL_BUFFER (Complex, work, nm);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2317
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2318 OCTAVE_LOCAL_BUFFER (octave_idx_type, rperm, nc);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2319 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2320 rperm[perm[i]] = i;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2321
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2322 for (octave_idx_type j = 0; j < b_nc; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2323 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2324 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2325 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2326 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2327 work[b.ridx (i)] = b.data (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2328
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2329 for (octave_idx_type k = nc-1; k >= 0; k--)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2330 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2331 octave_idx_type kidx = perm[k];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2332
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2333 if (work[k] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2334 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2335 if (ridx (cidx (kidx+1)-1) != k
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2336 || data (cidx (kidx+1)-1) == 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2337 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2338 err = -2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2339 goto triangular_error;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2340 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2341
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2342 Complex tmp = work[k] / data (cidx (kidx+1)-1);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2343 work[k] = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2344 for (octave_idx_type i = cidx (kidx);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2345 i < cidx (kidx+1)-1; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2346 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2347 octave_idx_type iidx = ridx (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2348 work[iidx] = work[iidx] - tmp * data (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2349 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2350 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2351 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2352
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2353 // Count nonzeros in work vector and adjust space in
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2354 // retval if needed
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2355 octave_idx_type new_nnz = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2356 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2357 if (work[i] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2358 new_nnz++;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2359
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2360 if (ii + new_nnz > x_nz)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2361 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2362 // Resize the sparse matrix
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2363 octave_idx_type sz = new_nnz * (b_nc - j) + x_nz;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2364 retval.change_capacity (sz);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2365 x_nz = sz;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2366 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2367
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2368 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2369 if (work[rperm[i]] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2370 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2371 retval.xridx (ii) = i;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2372 retval.xdata (ii++) = work[rperm[i]];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2373 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2374 retval.xcidx (j+1) = ii;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2375 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2376
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2377 retval.maybe_compress ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2378
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2379 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2380 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2381 // Calculation of 1-norm of inv(*this)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2382 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2383 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2384
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2385 for (octave_idx_type j = 0; j < nr; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2386 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2387 work[j] = 1.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2388
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2389 for (octave_idx_type k = j; k >= 0; k--)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2390 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2391 octave_idx_type iidx = perm[k];
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2392
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2393 if (work[k] != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2394 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2395 Complex tmp = work[k] / data (cidx (iidx+1)-1);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2396 work[k] = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2397 for (octave_idx_type i = cidx (iidx);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2398 i < cidx (iidx+1)-1; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2399 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2400 octave_idx_type idx2 = ridx (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2401 work[idx2] = work[idx2] - tmp * data (i);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2402 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2403 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2404 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2405 double atmp = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2406 for (octave_idx_type i = 0; i < j+1; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2407 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2408 atmp += std::abs (work[i]);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2409 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2410 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2411 if (atmp > ainvnorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2412 ainvnorm = atmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2413 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2414 rcond = 1. / ainvnorm / anorm;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2415 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2416 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2417 else
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2418 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2419 OCTAVE_LOCAL_BUFFER (Complex, work, nm);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2420
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2421 for (octave_idx_type j = 0; j < b_nc; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2422 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2423 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2424 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2425 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2426 work[b.ridx (i)] = b.data (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2427
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2428 for (octave_idx_type k = nr-1; k >= 0; k--)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2429 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2430 if (work[k] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2431 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2432 if (ridx (cidx (k+1)-1) != k
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2433 || data (cidx (k+1)-1) == 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2434 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2435 err = -2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2436 goto triangular_error;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2437 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2438
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2439 Complex tmp = work[k] / data (cidx (k+1)-1);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2440 work[k] = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2441 for (octave_idx_type i = cidx (k); i < cidx (k+1)-1; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2442 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2443 octave_idx_type iidx = ridx (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2444 work[iidx] = work[iidx] - tmp * data (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2445 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2446 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2447 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2448
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2449 // Count nonzeros in work vector and adjust space in
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2450 // retval if needed
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2451 octave_idx_type new_nnz = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2452 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2453 if (work[i] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2454 new_nnz++;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2455
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2456 if (ii + new_nnz > x_nz)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2457 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2458 // Resize the sparse matrix
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2459 octave_idx_type sz = new_nnz * (b_nc - j) + x_nz;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2460 retval.change_capacity (sz);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2461 x_nz = sz;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2462 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2463
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2464 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2465 if (work[i] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2466 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2467 retval.xridx (ii) = i;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2468 retval.xdata (ii++) = work[i];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2469 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2470 retval.xcidx (j+1) = ii;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2471 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2472
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2473 retval.maybe_compress ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2474
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2475 if (calc_cond)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2476 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2477 // Calculation of 1-norm of inv(*this)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2478 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2479 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2480
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2481 for (octave_idx_type j = 0; j < nr; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2482 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2483 work[j] = 1.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2484
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2485 for (octave_idx_type k = j; k >= 0; k--)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2486 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2487 if (work[k] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2488 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2489 Complex tmp = work[k] / data (cidx (k+1)-1);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2490 work[k] = tmp;
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2491 for (octave_idx_type i = cidx (k);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2492 i < cidx (k+1)-1; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2493 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2494 octave_idx_type iidx = ridx (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2495 work[iidx] = work[iidx] - tmp * data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2496 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2497 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2498 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2499 double atmp = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2500 for (octave_idx_type i = 0; i < j+1; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2501 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2502 atmp += std::abs (work[i]);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2503 work[i] = 0.;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2504 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2505 if (atmp > ainvnorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2506 ainvnorm = atmp;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2507 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2508 rcond = 1. / ainvnorm / anorm;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2509 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2510 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2511
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2512 triangular_error:
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2513 if (err != 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2514 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2515 if (sing_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2516 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2517 sing_handler (rcond);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2518 mattype.mark_as_rectangular ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2519 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2520 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2521 octave::warn_singular_matrix (rcond);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2522 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2523
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
2524 if (is_singular (rcond) || octave::math::isnan (rcond))
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2525 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2526 err = -2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2527
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2528 if (sing_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2529 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2530 sing_handler (rcond);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2531 mattype.mark_as_rectangular ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2532 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2533 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2534 octave::warn_singular_matrix (rcond);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2535 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2536 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2537
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2538 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2539 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2540
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2541 ComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
2542 SparseComplexMatrix::ltsolve (MatrixType& mattype, const Matrix& b,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2543 octave_idx_type& err, double& rcond,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2544 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2545 bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2546 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2547 ComplexMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2548
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
2549 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
2550 octave_idx_type nc = cols ();
5630
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
2551 octave_idx_type nm = (nc > nr ? nc : nr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2552 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2553
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
2554 if (nr != b.rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2555 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2556 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2557
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2558 if (nr == 0 || nc == 0 || b.cols () == 0)
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
2559 retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2560 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2561 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2562 // Print spparms("spumoni") info if requested
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2563 int typ = mattype.type ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2564 mattype.info ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2565
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2566 if (typ != MatrixType::Permuted_Lower && typ != MatrixType::Lower)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2567 (*current_liboctave_error_handler) ("incorrect matrix type");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2568
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2569 double anorm = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2570 double ainvnorm = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2571 octave_idx_type b_nc = b.cols ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2572 rcond = 1.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2573
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2574 if (calc_cond)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2575 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2576 // Calculate the 1-norm of matrix for rcond calculation
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2577 for (octave_idx_type j = 0; j < nc; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2578 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2579 double atmp = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2580 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2581 atmp += std::abs (data (i));
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2582 if (atmp > anorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2583 anorm = atmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2584 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2585 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2586
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2587 if (typ == MatrixType::Permuted_Lower)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2588 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2589 retval.resize (nc, b_nc);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2590 OCTAVE_LOCAL_BUFFER (Complex, work, nm);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2591 octave_idx_type *perm = mattype.triangular_perm ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2592
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2593 for (octave_idx_type j = 0; j < b_nc; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2594 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2595 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2596 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2597 for (octave_idx_type i = 0; i < nr; i++)
30394
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29937
diff changeset
2598 work[perm[i]] = b(i, j);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2599
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2600 for (octave_idx_type k = 0; k < nc; k++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2601 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2602 if (work[k] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2603 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2604 octave_idx_type minr = nr;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2605 octave_idx_type mini = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2606
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2607 for (octave_idx_type i = cidx (k); i < cidx (k+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2608 if (perm[ridx (i)] < minr)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2609 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2610 minr = perm[ridx (i)];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2611 mini = i;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2612 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2613
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2614 if (minr != k || data (mini) == 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2615 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2616 err = -2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2617 goto triangular_error;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2618 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2619
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2620 Complex tmp = work[k] / data (mini);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2621 work[k] = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2622 for (octave_idx_type i = cidx (k); i < cidx (k+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2623 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2624 if (i == mini)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2625 continue;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2626
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2627 octave_idx_type iidx = perm[ridx (i)];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2628 work[iidx] = work[iidx] - tmp * data (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2629 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2630 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2631 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2632
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2633 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2634 retval(i, j) = work[i];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2635 }
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2636
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2637 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2638 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2639 // Calculation of 1-norm of inv(*this)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2640 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2641 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2642
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2643 for (octave_idx_type j = 0; j < nr; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2644 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2645 work[j] = 1.;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2646
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2647 for (octave_idx_type k = 0; k < nc; k++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2648 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2649 if (work[k] != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2650 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2651 octave_idx_type minr = nr;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2652 octave_idx_type mini = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2653
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2654 for (octave_idx_type i = cidx (k);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2655 i < cidx (k+1); i++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2656 if (perm[ridx (i)] < minr)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2657 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2658 minr = perm[ridx (i)];
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2659 mini = i;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2660 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2661
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2662 Complex tmp = work[k] / data (mini);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2663 work[k] = tmp;
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2664 for (octave_idx_type i = cidx (k);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2665 i < cidx (k+1); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2666 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2667 if (i == mini)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2668 continue;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2669
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2670 octave_idx_type iidx = perm[ridx (i)];
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2671 work[iidx] = work[iidx] - tmp * data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2672 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2673 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2674 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2675
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2676 double atmp = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2677 for (octave_idx_type i = j; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2678 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2679 atmp += std::abs (work[i]);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2680 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2681 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2682 if (atmp > ainvnorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2683 ainvnorm = atmp;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2684 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2685 rcond = 1. / ainvnorm / anorm;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2686 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2687 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2688 else
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2689 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2690 OCTAVE_LOCAL_BUFFER (Complex, work, nm);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2691 retval.resize (nc, b_nc, 0.);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2692
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2693 for (octave_idx_type j = 0; j < b_nc; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2694 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2695 for (octave_idx_type i = 0; i < nr; i++)
30394
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29937
diff changeset
2696 work[i] = b(i, j);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2697 for (octave_idx_type i = nr; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2698 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2699 for (octave_idx_type k = 0; k < nc; k++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2700 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2701 if (work[k] != 0.)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2702 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2703 if (ridx (cidx (k)) != k || data (cidx (k)) == 0.)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2704 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2705 err = -2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2706 goto triangular_error;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2707 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2708
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2709 Complex tmp = work[k] / data (cidx (k));
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2710 work[k] = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2711 for (octave_idx_type i = cidx (k)+1; i < cidx (k+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2712 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2713 octave_idx_type iidx = ridx (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2714 work[iidx] = work[iidx] - tmp * data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2715 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2716 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2717 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2718 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2719 retval.xelem (i, j) = work[i];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2720 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2721
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2722 if (calc_cond)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2723 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2724 // Calculation of 1-norm of inv(*this)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2725 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2726 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2727
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2728 for (octave_idx_type j = 0; j < nr; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2729 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2730 work[j] = 1.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2731
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2732 for (octave_idx_type k = j; k < nc; k++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2733 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2734
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2735 if (work[k] != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2736 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2737 Complex tmp = work[k] / data (cidx (k));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2738 work[k] = tmp;
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2739 for (octave_idx_type i = cidx (k)+1;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2740 i < cidx (k+1); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2741 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2742 octave_idx_type iidx = ridx (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2743 work[iidx] = work[iidx] - tmp * data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2744 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2745 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2746 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2747 double atmp = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2748 for (octave_idx_type i = j; i < nc; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2749 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2750 atmp += std::abs (work[i]);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2751 work[i] = 0.;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2752 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2753 if (atmp > ainvnorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2754 ainvnorm = atmp;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2755 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2756 rcond = 1. / ainvnorm / anorm;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2757 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2758 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2759 triangular_error:
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2760 if (err != 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2761 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2762 if (sing_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2763 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2764 sing_handler (rcond);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2765 mattype.mark_as_rectangular ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2766 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2767 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2768 octave::warn_singular_matrix (rcond);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2769 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2770
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
2771 if (is_singular (rcond) || octave::math::isnan (rcond))
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2772 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2773 err = -2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2774
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2775 if (sing_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2776 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2777 sing_handler (rcond);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2778 mattype.mark_as_rectangular ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2779 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2780 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2781 octave::warn_singular_matrix (rcond);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2782 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2783 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2784
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2785 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2786 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2787
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2788 SparseComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
2789 SparseComplexMatrix::ltsolve (MatrixType& mattype, const SparseMatrix& b,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2790 octave_idx_type& err, double& rcond,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2791 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2792 bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2793 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2794 SparseComplexMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2795
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
2796 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
2797 octave_idx_type nc = cols ();
5630
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
2798 octave_idx_type nm = (nc > nr ? nc : nr);
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
2799
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2800 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2801
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
2802 if (nr != b.rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2803 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2804 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2805
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2806 if (nr == 0 || nc == 0 || b.cols () == 0)
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
2807 retval = SparseComplexMatrix (nc, b.cols ());
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2808 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2809 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2810 // Print spparms("spumoni") info if requested
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2811 int typ = mattype.type ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2812 mattype.info ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
2813
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2814 if (typ != MatrixType::Permuted_Lower && typ != MatrixType::Lower)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2815 (*current_liboctave_error_handler) ("incorrect matrix type");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2816
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2817 double anorm = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2818 double ainvnorm = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2819 rcond = 1.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2820
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2821 if (calc_cond)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2822 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2823 // Calculate the 1-norm of matrix for rcond calculation
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2824 for (octave_idx_type j = 0; j < nc; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2825 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2826 double atmp = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2827 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2828 atmp += std::abs (data (i));
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2829 if (atmp > anorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2830 anorm = atmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2831 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2832 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2833
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2834 octave_idx_type b_nc = b.cols ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2835 octave_idx_type b_nz = b.nnz ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2836 retval = SparseComplexMatrix (nc, b_nc, b_nz);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2837 retval.xcidx (0) = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2838 octave_idx_type ii = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2839 octave_idx_type x_nz = b_nz;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2840
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2841 if (typ == MatrixType::Permuted_Lower)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2842 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2843 OCTAVE_LOCAL_BUFFER (Complex, work, nm);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2844 octave_idx_type *perm = mattype.triangular_perm ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2845
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2846 for (octave_idx_type j = 0; j < b_nc; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2847 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2848 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2849 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2850 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2851 work[perm[b.ridx (i)]] = b.data (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2852
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2853 for (octave_idx_type k = 0; k < nc; k++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2854 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2855 if (work[k] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2856 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2857 octave_idx_type minr = nr;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2858 octave_idx_type mini = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2859
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2860 for (octave_idx_type i = cidx (k); i < cidx (k+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2861 if (perm[ridx (i)] < minr)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2862 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2863 minr = perm[ridx (i)];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2864 mini = i;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2865 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2866
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2867 if (minr != k || data (mini) == 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2868 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2869 err = -2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2870 goto triangular_error;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2871 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2872
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2873 Complex tmp = work[k] / data (mini);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2874 work[k] = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2875 for (octave_idx_type i = cidx (k); i < cidx (k+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2876 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2877 if (i == mini)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2878 continue;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2879
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2880 octave_idx_type iidx = perm[ridx (i)];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2881 work[iidx] = work[iidx] - tmp * data (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2882 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2883 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2884 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2885
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2886 // Count nonzeros in work vector and adjust space in
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2887 // retval if needed
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2888 octave_idx_type new_nnz = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2889 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2890 if (work[i] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2891 new_nnz++;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2892
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2893 if (ii + new_nnz > x_nz)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2894 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2895 // Resize the sparse matrix
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2896 octave_idx_type sz = new_nnz * (b_nc - j) + x_nz;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2897 retval.change_capacity (sz);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2898 x_nz = sz;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2899 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2900
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2901 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2902 if (work[i] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2903 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2904 retval.xridx (ii) = i;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2905 retval.xdata (ii++) = work[i];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2906 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2907 retval.xcidx (j+1) = ii;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2908 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2909
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2910 retval.maybe_compress ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2911
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2912 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2913 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2914 // Calculation of 1-norm of inv(*this)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2915 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2916 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2917
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2918 for (octave_idx_type j = 0; j < nr; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2919 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2920 work[j] = 1.;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2921
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2922 for (octave_idx_type k = 0; k < nc; k++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2923 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2924 if (work[k] != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2925 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2926 octave_idx_type minr = nr;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2927 octave_idx_type mini = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2928
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2929 for (octave_idx_type i = cidx (k);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2930 i < cidx (k+1); i++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2931 if (perm[ridx (i)] < minr)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2932 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2933 minr = perm[ridx (i)];
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2934 mini = i;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2935 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2936
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2937 Complex tmp = work[k] / data (mini);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2938 work[k] = tmp;
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2939 for (octave_idx_type i = cidx (k);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2940 i < cidx (k+1); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2941 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2942 if (i == mini)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2943 continue;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2944
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2945 octave_idx_type iidx = perm[ridx (i)];
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
2946 work[iidx] = work[iidx] - tmp * data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2947 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2948 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2949 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2950
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2951 double atmp = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2952 for (octave_idx_type i = j; i < nc; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2953 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2954 atmp += std::abs (work[i]);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2955 work[i] = 0.;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2956 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2957 if (atmp > ainvnorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2958 ainvnorm = atmp;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2959 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2960 rcond = 1. / ainvnorm / anorm;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2961 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2962 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2963 else
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2964 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2965 OCTAVE_LOCAL_BUFFER (Complex, work, nm);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2966
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2967 for (octave_idx_type j = 0; j < b_nc; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2968 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2969 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2970 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2971 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2972 work[b.ridx (i)] = b.data (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2973
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2974 for (octave_idx_type k = 0; k < nc; k++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2975 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2976 if (work[k] != 0.)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2977 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2978 if (ridx (cidx (k)) != k || data (cidx (k)) == 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2979 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2980 err = -2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2981 goto triangular_error;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2982 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2983
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2984 Complex tmp = work[k] / data (cidx (k));
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2985 work[k] = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2986 for (octave_idx_type i = cidx (k)+1; i < cidx (k+1); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2987 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2988 octave_idx_type iidx = ridx (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2989 work[iidx] = work[iidx] - tmp * data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2990 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
2991 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2992 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2993
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2994 // Count nonzeros in work vector and adjust space in
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2995 // retval if needed
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2996 octave_idx_type new_nnz = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2997 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2998 if (work[i] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
2999 new_nnz++;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3000
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3001 if (ii + new_nnz > x_nz)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3002 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3003 // Resize the sparse matrix
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3004 octave_idx_type sz = new_nnz * (b_nc - j) + x_nz;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3005 retval.change_capacity (sz);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3006 x_nz = sz;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3007 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3008
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3009 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3010 if (work[i] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3011 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3012 retval.xridx (ii) = i;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3013 retval.xdata (ii++) = work[i];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3014 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3015 retval.xcidx (j+1) = ii;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3016 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3017
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3018 retval.maybe_compress ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3019
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3020 if (calc_cond)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3021 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3022 // Calculation of 1-norm of inv(*this)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3023 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3024 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3025
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3026 for (octave_idx_type j = 0; j < nr; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3027 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3028 work[j] = 1.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3029
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3030 for (octave_idx_type k = j; k < nc; k++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3031 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3032
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3033 if (work[k] != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3034 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3035 Complex tmp = work[k] / data (cidx (k));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3036 work[k] = tmp;
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3037 for (octave_idx_type i = cidx (k)+1;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3038 i < cidx (k+1); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3039 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3040 octave_idx_type iidx = ridx (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3041 work[iidx] = work[iidx] - tmp * data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3042 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3043 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3044 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3045 double atmp = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3046 for (octave_idx_type i = j; i < nc; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3047 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3048 atmp += std::abs (work[i]);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3049 work[i] = 0.;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3050 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3051 if (atmp > ainvnorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3052 ainvnorm = atmp;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3053 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3054 rcond = 1. / ainvnorm / anorm;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3055 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3056 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3057
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3058 triangular_error:
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3059 if (err != 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3060 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3061 if (sing_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3062 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3063 sing_handler (rcond);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3064 mattype.mark_as_rectangular ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3065 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3066 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3067 octave::warn_singular_matrix (rcond);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3068 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3069
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
3070 if (is_singular (rcond) || octave::math::isnan (rcond))
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3071 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3072 err = -2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3073
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3074 if (sing_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3075 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3076 sing_handler (rcond);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3077 mattype.mark_as_rectangular ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3078 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3079 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3080 octave::warn_singular_matrix (rcond);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3081 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3082 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3083
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3084 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3085 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3086
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3087 ComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
3088 SparseComplexMatrix::ltsolve (MatrixType& mattype, const ComplexMatrix& b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3089 octave_idx_type& err, double& rcond,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3090 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3091 bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3092 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3093 ComplexMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3094
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
3095 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
3096 octave_idx_type nc = cols ();
5630
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
3097 octave_idx_type nm = (nc > nr ? nc : nr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3098 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3099
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
3100 if (nr != b.rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3101 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3102 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3103
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3104 if (nr == 0 || nc == 0 || b.cols () == 0)
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
3105 retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3106 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3107 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3108 // Print spparms("spumoni") info if requested
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3109 int typ = mattype.type ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3110 mattype.info ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
3111
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3112 if (typ != MatrixType::Permuted_Lower && typ != MatrixType::Lower)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3113 (*current_liboctave_error_handler) ("incorrect matrix type");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3114
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3115 double anorm = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3116 double ainvnorm = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3117 octave_idx_type b_nc = b.cols ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3118 rcond = 1.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3119
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3120 if (calc_cond)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3121 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3122 // Calculate the 1-norm of matrix for rcond calculation
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3123 for (octave_idx_type j = 0; j < nc; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3124 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3125 double atmp = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3126 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3127 atmp += std::abs (data (i));
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3128 if (atmp > anorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3129 anorm = atmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3130 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3131 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3132
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3133 if (typ == MatrixType::Permuted_Lower)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3134 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3135 retval.resize (nc, b_nc);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3136 OCTAVE_LOCAL_BUFFER (Complex, work, nm);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3137 octave_idx_type *perm = mattype.triangular_perm ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3138
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3139 for (octave_idx_type j = 0; j < b_nc; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3140 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3141 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3142 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3143 for (octave_idx_type i = 0; i < nr; i++)
30394
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29937
diff changeset
3144 work[perm[i]] = b(i, j);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3145
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3146 for (octave_idx_type k = 0; k < nc; k++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3147 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3148 if (work[k] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3149 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3150 octave_idx_type minr = nr;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3151 octave_idx_type mini = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3152
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3153 for (octave_idx_type i = cidx (k); i < cidx (k+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3154 if (perm[ridx (i)] < minr)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3155 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3156 minr = perm[ridx (i)];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3157 mini = i;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3158 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3159
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3160 if (minr != k || data (mini) == 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3161 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3162 err = -2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3163 goto triangular_error;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3164 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3165
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3166 Complex tmp = work[k] / data (mini);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3167 work[k] = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3168 for (octave_idx_type i = cidx (k); i < cidx (k+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3169 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3170 if (i == mini)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3171 continue;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3172
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3173 octave_idx_type iidx = perm[ridx (i)];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3174 work[iidx] = work[iidx] - tmp * data (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3175 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3176 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3177 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3178
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3179 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3180 retval(i, j) = work[i];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3181 }
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3182
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3183 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3184 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3185 // Calculation of 1-norm of inv(*this)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3186 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3187 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3188
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3189 for (octave_idx_type j = 0; j < nr; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3190 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3191 work[j] = 1.;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3192
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3193 for (octave_idx_type k = 0; k < nc; k++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3194 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3195 if (work[k] != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3196 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3197 octave_idx_type minr = nr;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3198 octave_idx_type mini = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3199
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3200 for (octave_idx_type i = cidx (k);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3201 i < cidx (k+1); i++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3202 if (perm[ridx (i)] < minr)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3203 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3204 minr = perm[ridx (i)];
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3205 mini = i;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3206 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3207
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3208 Complex tmp = work[k] / data (mini);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3209 work[k] = tmp;
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3210 for (octave_idx_type i = cidx (k);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3211 i < cidx (k+1); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3212 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3213 if (i == mini)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3214 continue;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3215
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3216 octave_idx_type iidx = perm[ridx (i)];
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3217 work[iidx] = work[iidx] - tmp * data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3218 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3219 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3220 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3221
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3222 double atmp = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3223 for (octave_idx_type i = j; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3224 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3225 atmp += std::abs (work[i]);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3226 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3227 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3228 if (atmp > ainvnorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3229 ainvnorm = atmp;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3230 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3231 rcond = 1. / ainvnorm / anorm;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3232 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3233 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3234 else
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3235 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3236 OCTAVE_LOCAL_BUFFER (Complex, work, nm);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3237 retval.resize (nc, b_nc, 0.);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3238
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3239 for (octave_idx_type j = 0; j < b_nc; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3240 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3241 for (octave_idx_type i = 0; i < nr; i++)
30394
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29937
diff changeset
3242 work[i] = b(i, j);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3243 for (octave_idx_type i = nr; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3244 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3245
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3246 for (octave_idx_type k = 0; k < nc; k++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3247 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3248 if (work[k] != 0.)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3249 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3250 if (ridx (cidx (k)) != k || data (cidx (k)) == 0.)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3251 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3252 err = -2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3253 goto triangular_error;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3254 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3255
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3256 Complex tmp = work[k] / data (cidx (k));
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3257 work[k] = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3258 for (octave_idx_type i = cidx (k)+1; i < cidx (k+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3259 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3260 octave_idx_type iidx = ridx (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3261 work[iidx] = work[iidx] - tmp * data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3262 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3263 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3264 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3265
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3266 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3267 retval.xelem (i, j) = work[i];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3268 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3269
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3270 if (calc_cond)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3271 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3272 // Calculation of 1-norm of inv(*this)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3273 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3274 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3275
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3276 for (octave_idx_type j = 0; j < nr; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3277 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3278 work[j] = 1.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3279
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3280 for (octave_idx_type k = j; k < nc; k++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3281 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3282
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3283 if (work[k] != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3284 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3285 Complex tmp = work[k] / data (cidx (k));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3286 work[k] = tmp;
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3287 for (octave_idx_type i = cidx (k)+1;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3288 i < cidx (k+1); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3289 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3290 octave_idx_type iidx = ridx (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3291 work[iidx] = work[iidx] - tmp * data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3292 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3293 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3294 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3295 double atmp = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3296 for (octave_idx_type i = j; i < nc; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3297 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3298 atmp += std::abs (work[i]);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3299 work[i] = 0.;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3300 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3301 if (atmp > ainvnorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3302 ainvnorm = atmp;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3303 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3304 rcond = 1. / ainvnorm / anorm;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3305 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3306 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3307
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3308 triangular_error:
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3309 if (err != 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3310 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3311 if (sing_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3312 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3313 sing_handler (rcond);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3314 mattype.mark_as_rectangular ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3315 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3316 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3317 octave::warn_singular_matrix (rcond);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3318 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3319
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
3320 if (is_singular (rcond) || octave::math::isnan (rcond))
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3321 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3322 err = -2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3323
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3324 if (sing_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3325 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3326 sing_handler (rcond);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3327 mattype.mark_as_rectangular ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3328 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3329 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3330 octave::warn_singular_matrix (rcond);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3331 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3332 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3333
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3334 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3335 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3336
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3337 SparseComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
3338 SparseComplexMatrix::ltsolve (MatrixType& mattype, const SparseComplexMatrix& b,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
3339 octave_idx_type& err, double& rcond,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3340 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3341 bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3342 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3343 SparseComplexMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3344
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
3345 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
3346 octave_idx_type nc = cols ();
5630
512d0d11ae39 [project @ 2006-02-20 22:05:30 by dbateman]
dbateman
parents: 5610
diff changeset
3347 octave_idx_type nm = (nc > nr ? nc : nr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3348 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3349
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
3350 if (nr != b.rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3351 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3352 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3353
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3354 if (nr == 0 || nc == 0 || b.cols () == 0)
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
3355 retval = SparseComplexMatrix (nc, b.cols ());
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3356 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3357 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3358 // Print spparms("spumoni") info if requested
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3359 int typ = mattype.type ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3360 mattype.info ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
3361
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3362 if (typ != MatrixType::Permuted_Lower && typ != MatrixType::Lower)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3363 (*current_liboctave_error_handler) ("incorrect matrix type");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3364
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3365 double anorm = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3366 double ainvnorm = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3367 rcond = 1.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3368
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3369 if (calc_cond)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3370 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3371 // Calculate the 1-norm of matrix for rcond calculation
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3372 for (octave_idx_type j = 0; j < nc; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3373 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3374 double atmp = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3375 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3376 atmp += std::abs (data (i));
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3377 if (atmp > anorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3378 anorm = atmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3379 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3380 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3381
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3382 octave_idx_type b_nc = b.cols ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3383 octave_idx_type b_nz = b.nnz ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3384 retval = SparseComplexMatrix (nc, b_nc, b_nz);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3385 retval.xcidx (0) = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3386 octave_idx_type ii = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3387 octave_idx_type x_nz = b_nz;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3388
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3389 if (typ == MatrixType::Permuted_Lower)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3390 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3391 OCTAVE_LOCAL_BUFFER (Complex, work, nm);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3392 octave_idx_type *perm = mattype.triangular_perm ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3393
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3394 for (octave_idx_type j = 0; j < b_nc; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3395 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3396 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3397 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3398 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3399 work[perm[b.ridx (i)]] = b.data (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3400
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3401 for (octave_idx_type k = 0; k < nc; k++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3402 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3403 if (work[k] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3404 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3405 octave_idx_type minr = nr;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3406 octave_idx_type mini = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3407
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3408 for (octave_idx_type i = cidx (k); i < cidx (k+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3409 if (perm[ridx (i)] < minr)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3410 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3411 minr = perm[ridx (i)];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3412 mini = i;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3413 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3414
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3415 if (minr != k || data (mini) == 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3416 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3417 err = -2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3418 goto triangular_error;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3419 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3420
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3421 Complex tmp = work[k] / data (mini);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3422 work[k] = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3423 for (octave_idx_type i = cidx (k); i < cidx (k+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3424 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3425 if (i == mini)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3426 continue;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3427
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3428 octave_idx_type iidx = perm[ridx (i)];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3429 work[iidx] = work[iidx] - tmp * data (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3430 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3431 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3432 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3433
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3434 // Count nonzeros in work vector and adjust space in
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3435 // retval if needed
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3436 octave_idx_type new_nnz = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3437 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3438 if (work[i] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3439 new_nnz++;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3440
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3441 if (ii + new_nnz > x_nz)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3442 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3443 // Resize the sparse matrix
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3444 octave_idx_type sz = new_nnz * (b_nc - j) + x_nz;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3445 retval.change_capacity (sz);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3446 x_nz = sz;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3447 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3448
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3449 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3450 if (work[i] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3451 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3452 retval.xridx (ii) = i;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3453 retval.xdata (ii++) = work[i];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3454 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3455 retval.xcidx (j+1) = ii;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3456 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3457
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3458 retval.maybe_compress ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3459
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3460 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3461 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3462 // Calculation of 1-norm of inv(*this)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3463 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3464 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3465
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3466 for (octave_idx_type j = 0; j < nr; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3467 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3468 work[j] = 1.;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3469
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3470 for (octave_idx_type k = 0; k < nc; k++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3471 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3472 if (work[k] != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3473 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3474 octave_idx_type minr = nr;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3475 octave_idx_type mini = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3476
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3477 for (octave_idx_type i = cidx (k);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3478 i < cidx (k+1); i++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3479 if (perm[ridx (i)] < minr)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3480 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3481 minr = perm[ridx (i)];
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3482 mini = i;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3483 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3484
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3485 Complex tmp = work[k] / data (mini);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3486 work[k] = tmp;
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3487 for (octave_idx_type i = cidx (k);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3488 i < cidx (k+1); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3489 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3490 if (i == mini)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3491 continue;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3492
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3493 octave_idx_type iidx = perm[ridx (i)];
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3494 work[iidx] = work[iidx] - tmp * data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3495 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3496 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3497 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3498
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3499 double atmp = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3500 for (octave_idx_type i = j; i < nc; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3501 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3502 atmp += std::abs (work[i]);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3503 work[i] = 0.;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3504 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3505 if (atmp > ainvnorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3506 ainvnorm = atmp;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3507 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3508 rcond = 1. / ainvnorm / anorm;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3509 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3510 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3511 else
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3512 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3513 OCTAVE_LOCAL_BUFFER (Complex, work, nm);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3514
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3515 for (octave_idx_type j = 0; j < b_nc; j++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3516 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3517 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3518 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3519 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3520 work[b.ridx (i)] = b.data (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3521
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3522 for (octave_idx_type k = 0; k < nc; k++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3523 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3524 if (work[k] != 0.)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3525 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3526 if (ridx (cidx (k)) != k || data (cidx (k)) == 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3527 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3528 err = -2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3529 goto triangular_error;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3530 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3531
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3532 Complex tmp = work[k] / data (cidx (k));
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3533 work[k] = tmp;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3534 for (octave_idx_type i = cidx (k)+1; i < cidx (k+1); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3535 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3536 octave_idx_type iidx = ridx (i);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3537 work[iidx] = work[iidx] - tmp * data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3538 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3539 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3540 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3541
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3542 // Count nonzeros in work vector and adjust space in
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3543 // retval if needed
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3544 octave_idx_type new_nnz = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3545 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3546 if (work[i] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3547 new_nnz++;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3548
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3549 if (ii + new_nnz > x_nz)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3550 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3551 // Resize the sparse matrix
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3552 octave_idx_type sz = new_nnz * (b_nc - j) + x_nz;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3553 retval.change_capacity (sz);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3554 x_nz = sz;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3555 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3556
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3557 for (octave_idx_type i = 0; i < nc; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3558 if (work[i] != 0.)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3559 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3560 retval.xridx (ii) = i;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3561 retval.xdata (ii++) = work[i];
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3562 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3563 retval.xcidx (j+1) = ii;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3564 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3565
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3566 retval.maybe_compress ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3567
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3568 if (calc_cond)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3569 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3570 // Calculation of 1-norm of inv(*this)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3571 for (octave_idx_type i = 0; i < nm; i++)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3572 work[i] = 0.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3573
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3574 for (octave_idx_type j = 0; j < nr; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3575 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3576 work[j] = 1.;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3577
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3578 for (octave_idx_type k = j; k < nc; k++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3579 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3580
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3581 if (work[k] != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3582 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3583 Complex tmp = work[k] / data (cidx (k));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3584 work[k] = tmp;
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3585 for (octave_idx_type i = cidx (k)+1;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3586 i < cidx (k+1); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3587 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3588 octave_idx_type iidx = ridx (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3589 work[iidx] = work[iidx] - tmp * data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3590 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3591 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3592 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3593 double atmp = 0;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3594 for (octave_idx_type i = j; i < nc; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3595 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3596 atmp += std::abs (work[i]);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3597 work[i] = 0.;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3598 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3599 if (atmp > ainvnorm)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3600 ainvnorm = atmp;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3601 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3602 rcond = 1. / ainvnorm / anorm;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3603 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3604 }
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3605
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3606 triangular_error:
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3607 if (err != 0)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3608 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3609 if (sing_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3610 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3611 sing_handler (rcond);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3612 mattype.mark_as_rectangular ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3613 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3614 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3615 octave::warn_singular_matrix (rcond);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3616 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3617
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
3618 if (is_singular (rcond) || octave::math::isnan (rcond))
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3619 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3620 err = -2;
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3621
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3622 if (sing_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3623 {
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3624 sing_handler (rcond);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3625 mattype.mark_as_rectangular ();
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3626 }
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3627 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3628 octave::warn_singular_matrix (rcond);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3629 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3630 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3631
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3632 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3633 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3634
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3635 ComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
3636 SparseComplexMatrix::trisolve (MatrixType& mattype, const Matrix& b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3637 octave_idx_type& err, double& rcond,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3638 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3639 bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3640 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3641 ComplexMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3642
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
3643 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
3644 octave_idx_type nc = cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3645 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3646
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
3647 if (nr != nc || nr != b.rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3648 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3649 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3650
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3651 if (nr == 0 || b.cols () == 0)
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
3652 retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0));
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
3653 else if (calc_cond)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
3654 (*current_liboctave_error_handler)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
3655 ("calculation of condition number not implemented");
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3656 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3657 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3658 // Print spparms("spumoni") info if requested
33041
ebc26cef3096 eliminate more obsolete volatile declarations
John W. Eaton <jwe@octave.org>
parents: 33037
diff changeset
3659 int typ = mattype.type ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3660 mattype.info ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
3661
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
3662 if (typ == MatrixType::Tridiagonal_Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3663 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3664 OCTAVE_LOCAL_BUFFER (double, D, nr);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3665 OCTAVE_LOCAL_BUFFER (Complex, DL, nr - 1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3666
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3667 if (mattype.is_dense ())
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3668 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3669 octave_idx_type ii = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3670
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3671 for (octave_idx_type j = 0; j < nc-1; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3672 {
23708
750e42a35adc Use imag, real, arg from std library for Complex types.
Rik <rik@octave.org>
parents: 23594
diff changeset
3673 D[j] = std::real (data (ii++));
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3674 DL[j] = data (ii);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3675 ii += 2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3676 }
23708
750e42a35adc Use imag, real, arg from std library for Complex types.
Rik <rik@octave.org>
parents: 23594
diff changeset
3677 D[nc-1] = std::real (data (ii));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3678 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3679 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3680 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3681 D[0] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3682 for (octave_idx_type i = 0; i < nr - 1; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3683 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3684 D[i+1] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3685 DL[i] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3686 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3687
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3688 for (octave_idx_type j = 0; j < nc; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3689 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3690 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3691 if (ridx (i) == j)
23708
750e42a35adc Use imag, real, arg from std library for Complex types.
Rik <rik@octave.org>
parents: 23594
diff changeset
3692 D[j] = std::real (data (i));
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3693 else if (ridx (i) == j + 1)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3694 DL[j] = data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3695 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3696 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
3697
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
3698 F77_INT b_nr = octave::to_f77_int (b.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
3699 F77_INT b_nc = octave::to_f77_int (b.cols ());
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3700
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3701 retval = ComplexMatrix (b);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
3702 Complex *result = retval.rwdata ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3703
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
3704 F77_INT tmp_nr = octave::to_f77_int (nr);
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3705
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3706 F77_INT tmp_err = 0;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3707
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3708 F77_XFCN (zptsv, ZPTSV, (tmp_nr, b_nc, D, F77_DBLE_CMPLX_ARG (DL),
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22327
diff changeset
3709 F77_DBLE_CMPLX_ARG (result),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3710 b_nr, tmp_err));
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3711
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3712 err = tmp_err;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3713
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3714 if (err != 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3715 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3716 err = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3717 mattype.mark_as_unsymmetric ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3718 typ = MatrixType::Tridiagonal;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3719 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
3720 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3721 rcond = 1.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3722 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3723
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
3724 if (typ == MatrixType::Tridiagonal)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3725 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3726 OCTAVE_LOCAL_BUFFER (Complex, DU, nr - 1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3727 OCTAVE_LOCAL_BUFFER (Complex, D, nr);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3728 OCTAVE_LOCAL_BUFFER (Complex, DL, nr - 1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3729
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3730 if (mattype.is_dense ())
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3731 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3732 octave_idx_type ii = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3733
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3734 for (octave_idx_type j = 0; j < nc-1; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3735 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3736 D[j] = data (ii++);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3737 DL[j] = data (ii++);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3738 DU[j] = data (ii++);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3739 }
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3740 D[nc-1] = data (ii);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3741 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3742 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3743 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3744 D[0] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3745 for (octave_idx_type i = 0; i < nr - 1; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3746 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3747 D[i+1] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3748 DL[i] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3749 DU[i] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3750 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3751
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3752 for (octave_idx_type j = 0; j < nc; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3753 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3754 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3755 if (ridx (i) == j)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3756 D[j] = data (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3757 else if (ridx (i) == j + 1)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3758 DL[j] = data (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3759 else if (ridx (i) == j - 1)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3760 DU[j-1] = data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3761 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3762 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3763
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
3764 F77_INT b_nr = octave::to_f77_int (b.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
3765 F77_INT b_nc = octave::to_f77_int (b.cols ());
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3766
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3767 retval = ComplexMatrix (b);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
3768 Complex *result = retval.rwdata ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3769
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
3770 F77_INT tmp_nr = octave::to_f77_int (nr);
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3771
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3772 F77_INT tmp_err = 0;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3773
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3774 F77_XFCN (zgtsv, ZGTSV, (tmp_nr, b_nc, F77_DBLE_CMPLX_ARG (DL),
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22327
diff changeset
3775 F77_DBLE_CMPLX_ARG (D), F77_DBLE_CMPLX_ARG (DU), F77_DBLE_CMPLX_ARG (result),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3776 b_nr, tmp_err));
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3777
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3778 err = tmp_err;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3779
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3780 if (err != 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3781 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3782 rcond = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3783 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3784
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3785 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3786 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3787 sing_handler (rcond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3788 mattype.mark_as_rectangular ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3789 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3790 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3791 octave::warn_singular_matrix ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3792
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
3793 }
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
3794 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3795 rcond = 1.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3796 }
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
3797 else if (typ != MatrixType::Tridiagonal_Hermitian)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
3798 (*current_liboctave_error_handler) ("incorrect matrix type");
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3799 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3800
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3801 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3802 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3803
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3804 SparseComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
3805 SparseComplexMatrix::trisolve (MatrixType& mattype, const SparseMatrix& b,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
3806 octave_idx_type& err, double& rcond,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3807 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3808 bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3809 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3810 SparseComplexMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3811
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
3812 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
3813 octave_idx_type nc = cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3814 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3815
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
3816 if (nr != nc || nr != b.rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3817 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3818 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3819
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3820 if (nr == 0 || b.cols () == 0)
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
3821 retval = SparseComplexMatrix (nc, b.cols ());
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
3822 else if (calc_cond)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
3823 (*current_liboctave_error_handler)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
3824 ("calculation of condition number not implemented");
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3825 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3826 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3827 // Print spparms("spumoni") info if requested
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3828 int typ = mattype.type ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3829 mattype.info ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
3830
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3831 // Note can't treat symmetric case as there is no dpttrf function
19864
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
3832 if (typ == MatrixType::Tridiagonal
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
3833 || typ == MatrixType::Tridiagonal_Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3834 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3835 OCTAVE_LOCAL_BUFFER (Complex, DU2, nr - 2);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3836 OCTAVE_LOCAL_BUFFER (Complex, DU, nr - 1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3837 OCTAVE_LOCAL_BUFFER (Complex, D, nr);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3838 OCTAVE_LOCAL_BUFFER (Complex, DL, nr - 1);
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3839 Array<F77_INT> ipvt (dim_vector (nr, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
3840 F77_INT *pipvt = ipvt.rwdata ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3841
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3842 if (mattype.is_dense ())
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3843 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3844 octave_idx_type ii = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3845
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3846 for (octave_idx_type j = 0; j < nc-1; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3847 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3848 D[j] = data (ii++);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3849 DL[j] = data (ii++);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3850 DU[j] = data (ii++);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3851 }
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3852 D[nc-1] = data (ii);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3853 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3854 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3855 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3856 D[0] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3857 for (octave_idx_type i = 0; i < nr - 1; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3858 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3859 D[i+1] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3860 DL[i] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3861 DU[i] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3862 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3863
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3864 for (octave_idx_type j = 0; j < nc; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3865 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3866 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3867 if (ridx (i) == j)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3868 D[j] = data (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3869 else if (ridx (i) == j + 1)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3870 DL[j] = data (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3871 else if (ridx (i) == j - 1)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3872 DU[j-1] = data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3873 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3874 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3875
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
3876 F77_INT tmp_nr = octave::to_f77_int (nr);
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3877
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3878 F77_INT tmp_err = 0;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3879
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
3880 F77_XFCN (zgttrf, ZGTTRF, (tmp_nr, F77_DBLE_CMPLX_ARG (DL),
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
3881 F77_DBLE_CMPLX_ARG (D),
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
3882 F77_DBLE_CMPLX_ARG (DU),
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
3883 F77_DBLE_CMPLX_ARG (DU2),
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
3884 pipvt, tmp_err));
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3885
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3886 err = tmp_err;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3887
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
3888 if (err != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3889 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3890 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3891 rcond = 0.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3892
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3893 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3894 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3895 sing_handler (rcond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3896 mattype.mark_as_rectangular ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3897 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3898 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
3899 octave::warn_singular_matrix ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
3900 }
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
3901 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3902 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3903 char job = 'N';
33037
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
3904 octave_idx_type x_nz = b.nnz ();
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
3905 F77_INT b_nr = octave::to_f77_int (b.rows ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3906 octave_idx_type b_nc = b.cols ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3907 retval = SparseComplexMatrix (nr, b_nc, x_nz);
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3908 retval.xcidx (0) = 0;
33037
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
3909 octave_idx_type ii = 0;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3910 rcond = 1.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3911
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3912 OCTAVE_LOCAL_BUFFER (Complex, work, nr);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3913
33037
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
3914 for (octave_idx_type j = 0; j < b_nc; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3915 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3916 for (octave_idx_type i = 0; i < nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3917 work[i] = 0.;
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3918 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3919 work[b.ridx (i)] = b.data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3920
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
3921 F77_XFCN (zgttrs, ZGTTRS,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3922 (F77_CONST_CHAR_ARG2 (&job, 1),
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
3923 tmp_nr, 1, F77_DBLE_CMPLX_ARG (DL),
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
3924 F77_DBLE_CMPLX_ARG (D),
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
3925 F77_DBLE_CMPLX_ARG (DU),
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22327
diff changeset
3926 F77_DBLE_CMPLX_ARG (DU2), pipvt,
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3927 F77_DBLE_CMPLX_ARG (work), b_nr, tmp_err
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3928 F77_CHAR_ARG_LEN (1)));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3929
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3930 err = tmp_err;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
3931
18812
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18678
diff changeset
3932 // Count nonzeros in work vector and adjust
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3933 // space in retval if needed
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3934 octave_idx_type new_nnz = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3935 for (octave_idx_type i = 0; i < nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3936 if (work[i] != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3937 new_nnz++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3938
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3939 if (ii + new_nnz > x_nz)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3940 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3941 // Resize the sparse matrix
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3942 octave_idx_type sz = new_nnz * (b_nc - j) + x_nz;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3943 retval.change_capacity (sz);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3944 x_nz = sz;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3945 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3946
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3947 for (octave_idx_type i = 0; i < nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3948 if (work[i] != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3949 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3950 retval.xridx (ii) = i;
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3951 retval.xdata (ii++) = work[i];
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3952 }
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
3953 retval.xcidx (j+1) = ii;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3954 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3955
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3956 retval.maybe_compress ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3957 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3958 }
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
3959 else if (typ != MatrixType::Tridiagonal_Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3960 (*current_liboctave_error_handler) ("incorrect matrix type");
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3961 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3962
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3963 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3964 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3965
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3966 ComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
3967 SparseComplexMatrix::trisolve (MatrixType& mattype, const ComplexMatrix& b,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
3968 octave_idx_type& err, double& rcond,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3969 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3970 bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3971 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3972 ComplexMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3973
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
3974 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
3975 octave_idx_type nc = cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3976 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3977
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
3978 if (nr != nc || nr != b.rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3979 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3980 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3981
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
3982 if (nr == 0 || b.cols () == 0)
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
3983 retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0));
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
3984 else if (calc_cond)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
3985 (*current_liboctave_error_handler)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
3986 ("calculation of condition number not implemented");
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3987 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3988 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3989 // Print spparms("spumoni") info if requested
33037
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
3990 int typ = mattype.type ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
3991 mattype.info ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
3992
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
3993 if (typ == MatrixType::Tridiagonal_Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3994 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3995 OCTAVE_LOCAL_BUFFER (double, D, nr);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3996 OCTAVE_LOCAL_BUFFER (Complex, DL, nr - 1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3997
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3998 if (mattype.is_dense ())
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
3999 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4000 octave_idx_type ii = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4001
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4002 for (octave_idx_type j = 0; j < nc-1; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4003 {
23708
750e42a35adc Use imag, real, arg from std library for Complex types.
Rik <rik@octave.org>
parents: 23594
diff changeset
4004 D[j] = std::real (data (ii++));
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4005 DL[j] = data (ii);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4006 ii += 2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4007 }
23708
750e42a35adc Use imag, real, arg from std library for Complex types.
Rik <rik@octave.org>
parents: 23594
diff changeset
4008 D[nc-1] = std::real (data (ii));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4009 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4010 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4011 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4012 D[0] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4013 for (octave_idx_type i = 0; i < nr - 1; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4014 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4015 D[i+1] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4016 DL[i] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4017 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4018
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4019 for (octave_idx_type j = 0; j < nc; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4020 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4021 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4022 if (ridx (i) == j)
23708
750e42a35adc Use imag, real, arg from std library for Complex types.
Rik <rik@octave.org>
parents: 23594
diff changeset
4023 D[j] = std::real (data (i));
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4024 else if (ridx (i) == j + 1)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4025 DL[j] = data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4026 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4027 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4028
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4029 F77_INT b_nr = octave::to_f77_int (b.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4030 F77_INT b_nc = octave::to_f77_int (b.cols ());
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4031
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4032 rcond = 1.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4033
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4034 retval = ComplexMatrix (b);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
4035 Complex *result = retval.rwdata ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4036
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4037 F77_INT tmp_nr = octave::to_f77_int (nr);
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4038
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4039 F77_INT tmp_err = 0;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4040
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4041 F77_XFCN (zptsv, ZPTSV, (tmp_nr, b_nc, D, F77_DBLE_CMPLX_ARG (DL),
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22327
diff changeset
4042 F77_DBLE_CMPLX_ARG (result),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4043 b_nr, tmp_err));
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4044
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4045 err = tmp_err;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4046
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4047 if (err != 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4048 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4049 err = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4050 mattype.mark_as_unsymmetric ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4051 typ = MatrixType::Tridiagonal;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4052 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4053 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4054
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
4055 if (typ == MatrixType::Tridiagonal)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4056 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4057 OCTAVE_LOCAL_BUFFER (Complex, DU, nr - 1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4058 OCTAVE_LOCAL_BUFFER (Complex, D, nr);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4059 OCTAVE_LOCAL_BUFFER (Complex, DL, nr - 1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4060
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4061 if (mattype.is_dense ())
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4062 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4063 octave_idx_type ii = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4064
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4065 for (octave_idx_type j = 0; j < nc-1; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4066 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4067 D[j] = data (ii++);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4068 DL[j] = data (ii++);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4069 DU[j] = data (ii++);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4070 }
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4071 D[nc-1] = data (ii);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4072 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4073 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4074 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4075 D[0] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4076 for (octave_idx_type i = 0; i < nr - 1; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4077 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4078 D[i+1] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4079 DL[i] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4080 DU[i] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4081 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4082
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4083 for (octave_idx_type j = 0; j < nc; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4084 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4085 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4086 if (ridx (i) == j)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4087 D[j] = data (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4088 else if (ridx (i) == j + 1)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4089 DL[j] = data (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4090 else if (ridx (i) == j - 1)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4091 DU[j-1] = data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4092 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4093 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4094
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4095 F77_INT b_nr = octave::to_f77_int (b.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4096 F77_INT b_nc = octave::to_f77_int (b.cols ());
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4097
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4098 rcond = 1.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4099
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4100 retval = ComplexMatrix (b);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
4101 Complex *result = retval.rwdata ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4102
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4103 F77_INT tmp_nr = octave::to_f77_int (nr);
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4104
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4105 F77_INT tmp_err = 0;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4106
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4107 F77_XFCN (zgtsv, ZGTSV, (tmp_nr, b_nc, F77_DBLE_CMPLX_ARG (DL),
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22327
diff changeset
4108 F77_DBLE_CMPLX_ARG (D), F77_DBLE_CMPLX_ARG (DU), F77_DBLE_CMPLX_ARG (result),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4109 b_nr, tmp_err));
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4110
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4111 err = tmp_err;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4112
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4113 if (err != 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4114 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4115 rcond = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4116 err = -2;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4117
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4118 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4119 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4120 sing_handler (rcond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4121 mattype.mark_as_rectangular ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4122 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4123 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
4124 octave::warn_singular_matrix ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4125 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4126 }
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
4127 else if (typ != MatrixType::Tridiagonal_Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4128 (*current_liboctave_error_handler) ("incorrect matrix type");
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4129 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4130
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4131 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4132 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4133
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4134 SparseComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
4135 SparseComplexMatrix::trisolve (MatrixType& mattype,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4136 const SparseComplexMatrix& b,
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4137 octave_idx_type& err, double& rcond,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4138 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4139 bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4140 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4141 SparseComplexMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4142
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
4143 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
4144 octave_idx_type nc = cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4145 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4146
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
4147 if (nr != nc || nr != b.rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4148 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4149 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
4150
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
4151 if (nr == 0 || b.cols () == 0)
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
4152 retval = SparseComplexMatrix (nc, b.cols ());
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
4153 else if (calc_cond)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4154 (*current_liboctave_error_handler)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
4155 ("calculation of condition number not implemented");
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4156 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4157 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4158 // Print spparms("spumoni") info if requested
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4159 int typ = mattype.type ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4160 mattype.info ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4161
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4162 // Note can't treat symmetric case as there is no dpttrf function
19864
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
4163 if (typ == MatrixType::Tridiagonal
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
4164 || typ == MatrixType::Tridiagonal_Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4165 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4166 OCTAVE_LOCAL_BUFFER (Complex, DU2, nr - 2);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4167 OCTAVE_LOCAL_BUFFER (Complex, DU, nr - 1);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4168 OCTAVE_LOCAL_BUFFER (Complex, D, nr);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4169 OCTAVE_LOCAL_BUFFER (Complex, DL, nr - 1);
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4170 Array<F77_INT> ipvt (dim_vector (nr, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
4171 F77_INT *pipvt = ipvt.rwdata ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4172
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4173 if (mattype.is_dense ())
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4174 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4175 octave_idx_type ii = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4176
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4177 for (octave_idx_type j = 0; j < nc-1; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4178 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4179 D[j] = data (ii++);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4180 DL[j] = data (ii++);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4181 DU[j] = data (ii++);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4182 }
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4183 D[nc-1] = data (ii);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4184 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4185 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4186 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4187 D[0] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4188 for (octave_idx_type i = 0; i < nr - 1; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4189 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4190 D[i+1] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4191 DL[i] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4192 DU[i] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4193 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4194
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4195 for (octave_idx_type j = 0; j < nc; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4196 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4197 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4198 if (ridx (i) == j)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4199 D[j] = data (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4200 else if (ridx (i) == j + 1)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4201 DL[j] = data (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4202 else if (ridx (i) == j - 1)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4203 DU[j-1] = data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4204 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4205 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4206
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4207 F77_INT tmp_nr = octave::to_f77_int (nr);
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4208
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4209 F77_INT tmp_err = 0;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4210
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
4211 F77_XFCN (zgttrf, ZGTTRF, (tmp_nr, F77_DBLE_CMPLX_ARG (DL),
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
4212 F77_DBLE_CMPLX_ARG (D),
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
4213 F77_DBLE_CMPLX_ARG (DU),
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
4214 F77_DBLE_CMPLX_ARG (DU2),
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
4215 pipvt, tmp_err));
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4216
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4217 err = tmp_err;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4218
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4219 if (err != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4220 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4221 rcond = 0.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4222 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4223
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4224 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4225 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4226 sing_handler (rcond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4227 mattype.mark_as_rectangular ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4228 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4229 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
4230 octave::warn_singular_matrix ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4231 }
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4232 else
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4233 {
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4234 rcond = 1.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4235 char job = 'N';
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4236 F77_INT b_nr = octave::to_f77_int (b.rows ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4237 octave_idx_type b_nc = b.cols ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4238 OCTAVE_LOCAL_BUFFER (Complex, Bx, b_nr);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4239
18812
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18678
diff changeset
4240 // Take a first guess that the number of nonzero terms
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4241 // will be as many as in b
33037
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
4242 octave_idx_type x_nz = b.nnz ();
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
4243 octave_idx_type ii = 0;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4244 retval = SparseComplexMatrix (b_nr, b_nc, x_nz);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4245
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4246 retval.xcidx (0) = 0;
33037
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
4247 for (octave_idx_type j = 0; j < b_nc; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4248 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4249
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4250 for (F77_INT i = 0; i < b_nr; i++)
30394
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29937
diff changeset
4251 Bx[i] = b(i, j);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4252
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4253 F77_XFCN (zgttrs, ZGTTRS,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4254 (F77_CONST_CHAR_ARG2 (&job, 1),
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
4255 tmp_nr, 1, F77_DBLE_CMPLX_ARG (DL),
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
4256 F77_DBLE_CMPLX_ARG (D),
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
4257 F77_DBLE_CMPLX_ARG (DU),
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22327
diff changeset
4258 F77_DBLE_CMPLX_ARG (DU2), pipvt,
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4259 F77_DBLE_CMPLX_ARG (Bx), b_nr, tmp_err
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4260 F77_CHAR_ARG_LEN (1)));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4261
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4262 err = tmp_err;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4263
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4264 if (err != 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4265 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
4266 // FIXME: This should probably be a warning so that
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
4267 // error value can be passed back.
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4268 (*current_liboctave_error_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4269 ("SparseComplexMatrix::solve solve failed");
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4270
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4271 err = -1;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4272 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4273 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4274
18812
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18678
diff changeset
4275 // Count nonzeros in work vector and adjust
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4276 // space in retval if needed
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4277 octave_idx_type new_nnz = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4278 for (octave_idx_type i = 0; i < nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4279 if (Bx[i] != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4280 new_nnz++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4281
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4282 if (ii + new_nnz > x_nz)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4283 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4284 // Resize the sparse matrix
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4285 octave_idx_type sz = new_nnz * (b_nc - j) + x_nz;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4286 retval.change_capacity (sz);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4287 x_nz = sz;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4288 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4289
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4290 for (octave_idx_type i = 0; i < nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4291 if (Bx[i] != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4292 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4293 retval.xridx (ii) = i;
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4294 retval.xdata (ii++) = Bx[i];
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4295 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4296
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4297 retval.xcidx (j+1) = ii;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4298 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4299
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4300 retval.maybe_compress ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4301 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4302 }
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
4303 else if (typ != MatrixType::Tridiagonal_Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4304 (*current_liboctave_error_handler) ("incorrect matrix type");
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4305 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4306
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4307 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4308 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4309
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4310 ComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
4311 SparseComplexMatrix::bsolve (MatrixType& mattype, const Matrix& b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4312 octave_idx_type& err, double& rcond,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4313 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4314 bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4315 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4316 ComplexMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4317
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
4318 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
4319 octave_idx_type nc = cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4320 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4321
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
4322 if (nr != nc || nr != b.rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4323 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4324 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
4325
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
4326 if (nr == 0 || b.cols () == 0)
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
4327 retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4328 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4329 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4330 // Print spparms("spumoni") info if requested
33037
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
4331 int typ = mattype.type ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4332 mattype.info ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4333
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
4334 if (typ == MatrixType::Banded_Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4335 {
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4336 F77_INT n_lower = octave::to_f77_int (mattype.nlower ());
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4337 F77_INT ldm = n_lower + 1;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4338 ComplexMatrix m_band (ldm, nc);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
4339 Complex *tmp_data = m_band.rwdata ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4340
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4341 if (! mattype.is_dense ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4342 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4343 octave_idx_type ii = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4344
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4345 for (F77_INT j = 0; j < ldm; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4346 for (octave_idx_type i = 0; i < nc; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4347 tmp_data[ii++] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4348 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4349
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4350 for (octave_idx_type j = 0; j < nc; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4351 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4352 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4353 octave_idx_type ri = ridx (i);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4354 if (ri >= j)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4355 m_band(ri - j, j) = data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4356 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4357
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4358 // Calculate the norm of the matrix, for later use.
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4359 double anorm;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4360 if (calc_cond)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4361 anorm = m_band.abs ().sum ().row (0).max ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4362
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4363 F77_INT tmp_nr = octave::to_f77_int (nr);
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4364
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4365 F77_INT tmp_err = 0;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4366
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4367 char job = 'L';
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4368 F77_XFCN (zpbtrf, ZPBTRF, (F77_CONST_CHAR_ARG2 (&job, 1),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4369 tmp_nr, n_lower, F77_DBLE_CMPLX_ARG (tmp_data), ldm, tmp_err
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4370 F77_CHAR_ARG_LEN (1)));
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4371
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4372 err = tmp_err;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4373
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4374 if (err != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4375 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4376 rcond = 0.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4377 // Matrix is not positive definite!! Fall through to
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4378 // unsymmetric banded solver.
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4379 mattype.mark_as_unsymmetric ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4380 typ = MatrixType::Banded;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4381 err = 0;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4382 }
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4383 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4384 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4385 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4386 {
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
4387 Array<Complex> z (dim_vector (2 * nr, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
4388 Complex *pz = z.rwdata ();
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
4389 Array<double> iz (dim_vector (nr, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
4390 double *piz = iz.rwdata ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4391
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4392 F77_XFCN (zpbcon, ZPBCON,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
4393 (F77_CONST_CHAR_ARG2 (&job, 1),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4394 tmp_nr, n_lower, F77_DBLE_CMPLX_ARG (tmp_data), ldm,
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4395 anorm, rcond, F77_DBLE_CMPLX_ARG (pz), piz, tmp_err
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
4396 F77_CHAR_ARG_LEN (1)));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4397
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4398 err = tmp_err;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4399
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4400 if (err != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4401 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4402
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
4403 if (is_singular (rcond) || octave::math::isnan (rcond))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4404 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4405 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4406
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4407 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4408 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4409 sing_handler (rcond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4410 mattype.mark_as_rectangular ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4411 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4412 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
4413 octave::warn_singular_matrix (rcond);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4414 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4415 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4416 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4417 rcond = 1.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4418
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4419 if (err == 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4420 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4421 retval = ComplexMatrix (b);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
4422 Complex *result = retval.rwdata ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4423
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4424 F77_INT b_nr = octave::to_f77_int (b.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4425 F77_INT b_nc = octave::to_f77_int (b.cols ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4426
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4427 F77_XFCN (zpbtrs, ZPBTRS,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4428 (F77_CONST_CHAR_ARG2 (&job, 1),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4429 tmp_nr, n_lower, b_nc, F77_DBLE_CMPLX_ARG (tmp_data),
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4430 ldm, F77_DBLE_CMPLX_ARG (result), b_nr, tmp_err
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4431 F77_CHAR_ARG_LEN (1)));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4432
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4433 err = tmp_err;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4434
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4435 if (err != 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4436 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
4437 // FIXME: Probably should be a warning.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4438 (*current_liboctave_error_handler)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4439 ("SparseMatrix::solve solve failed");
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4440 err = -1;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4441 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4442 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4443 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4444 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4445
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
4446 if (typ == MatrixType::Banded)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4447 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4448 // Create the storage for the banded form of the sparse matrix
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4449 F77_INT n_upper = octave::to_f77_int (mattype.nupper ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4450 F77_INT n_lower = octave::to_f77_int (mattype.nlower ());
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4451 F77_INT ldm = n_upper + 2 * n_lower + 1;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4452
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4453 ComplexMatrix m_band (ldm, nc);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
4454 Complex *tmp_data = m_band.rwdata ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4455
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4456 if (! mattype.is_dense ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4457 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4458 octave_idx_type ii = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4459
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4460 for (F77_INT j = 0; j < ldm; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4461 for (octave_idx_type i = 0; i < nc; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4462 tmp_data[ii++] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4463 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4464
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4465 for (octave_idx_type j = 0; j < nc; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4466 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4467 m_band(ridx (i) - j + n_lower + n_upper, j) = data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4468
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4469 // Calculate the norm of the matrix, for later use.
18676
5bd1ca29c5f0 Clean up questionable code bits identified by clang sanitize.
Rik <rik@octave.org>
parents: 18110
diff changeset
4470 double anorm = 0.0;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4471 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4472 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4473 for (octave_idx_type j = 0; j < nr; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4474 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4475 double atmp = 0.;
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4476 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4477 atmp += std::abs (data (i));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4478 if (atmp > anorm)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4479 anorm = atmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4480 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4481 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4482
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4483 Array<F77_INT> ipvt (dim_vector (nr, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
4484 F77_INT *pipvt = ipvt.rwdata ();
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4485
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4486 F77_INT tmp_nr = octave::to_f77_int (nr);
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4487
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4488 F77_INT tmp_err = 0;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4489
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4490 F77_XFCN (zgbtrf, ZGBTRF, (tmp_nr, tmp_nr, n_lower, n_upper,
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22327
diff changeset
4491 F77_DBLE_CMPLX_ARG (tmp_data),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4492 ldm, pipvt, tmp_err));
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4493
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4494 err = tmp_err;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4495
24291
cf33c1b910b7 maint: Correct typo in comment "Throw-away" => "Throw away"
Rik <rik@octave.org>
parents: 24257
diff changeset
4496 // Throw away extra info LAPACK gives so as to not
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4497 // change output.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4498 if (err != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4499 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4500 rcond = 0.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4501 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4502
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4503 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4504 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4505 sing_handler (rcond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4506 mattype.mark_as_rectangular ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4507 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4508 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
4509 octave::warn_singular_matrix ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4510 }
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4511 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4512 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4513 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4514 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4515 char job = '1';
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
4516 Array<Complex> z (dim_vector (2 * nr, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
4517 Complex *pz = z.rwdata ();
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
4518 Array<double> iz (dim_vector (nr, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
4519 double *piz = iz.rwdata ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4520
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4521 F77_INT tmp_nc = octave::to_f77_int (nc);
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4522
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4523 F77_XFCN (zgbcon, ZGBCON,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
4524 (F77_CONST_CHAR_ARG2 (&job, 1),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4525 tmp_nc, n_lower, n_upper, F77_DBLE_CMPLX_ARG (tmp_data), ldm, pipvt,
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4526 anorm, rcond, F77_DBLE_CMPLX_ARG (pz), piz, tmp_err
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
4527 F77_CHAR_ARG_LEN (1)));
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
4528
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4529 err = tmp_err;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4530
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
4531 if (err != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4532 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4533
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
4534 if (is_singular (rcond) || octave::math::isnan (rcond))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4535 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4536 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4537
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4538 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4539 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4540 sing_handler (rcond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4541 mattype.mark_as_rectangular ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4542 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4543 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
4544 octave::warn_singular_matrix (rcond);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4545 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4546 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4547 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4548 rcond = 1.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4549
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4550 if (err == 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4551 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4552 retval = ComplexMatrix (b);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
4553 Complex *result = retval.rwdata ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4554
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4555 F77_INT b_nr = octave::to_f77_int (b.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4556 F77_INT b_nc = octave::to_f77_int (b.cols ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4557
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4558 char job = 'N';
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4559 F77_XFCN (zgbtrs, ZGBTRS,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4560 (F77_CONST_CHAR_ARG2 (&job, 1),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4561 tmp_nr, n_lower, n_upper, b_nc, F77_DBLE_CMPLX_ARG (tmp_data),
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4562 ldm, pipvt, F77_DBLE_CMPLX_ARG (result), b_nr, tmp_err
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4563 F77_CHAR_ARG_LEN (1)));
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4564
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4565 err = tmp_err;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4566 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4567 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4568 }
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
4569 else if (typ != MatrixType::Banded_Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4570 (*current_liboctave_error_handler) ("incorrect matrix type");
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4571 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4572
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4573 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4574 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4575
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4576 SparseComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
4577 SparseComplexMatrix::bsolve (MatrixType& mattype, const SparseMatrix& b,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4578 octave_idx_type& err, double& rcond,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4579 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4580 bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4581 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4582 SparseComplexMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4583
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
4584 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
4585 octave_idx_type nc = cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4586 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4587
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
4588 if (nr != nc || nr != b.rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4589 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4590 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
4591
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
4592 if (nr == 0 || b.cols () == 0)
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
4593 retval = SparseComplexMatrix (nc, b.cols ());
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4594 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4595 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4596 // Print spparms("spumoni") info if requested
33037
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
4597 int typ = mattype.type ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4598 mattype.info ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4599
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
4600 if (typ == MatrixType::Banded_Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4601 {
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4602 F77_INT n_lower = octave::to_f77_int (mattype.nlower ());
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4603 F77_INT ldm = n_lower + 1;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4604
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4605 ComplexMatrix m_band (ldm, nc);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
4606 Complex *tmp_data = m_band.rwdata ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4607
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4608 if (! mattype.is_dense ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4609 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4610 octave_idx_type ii = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4611
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4612 for (F77_INT j = 0; j < ldm; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4613 for (octave_idx_type i = 0; i < nc; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4614 tmp_data[ii++] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4615 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4616
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4617 for (octave_idx_type j = 0; j < nc; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4618 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4619 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4620 octave_idx_type ri = ridx (i);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4621 if (ri >= j)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4622 m_band(ri - j, j) = data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4623 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4624
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4625 // Calculate the norm of the matrix, for later use.
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4626 double anorm;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4627 if (calc_cond)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4628 anorm = m_band.abs ().sum ().row (0).max ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4629
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4630 F77_INT tmp_nr = octave::to_f77_int (nr);
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4631
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4632 F77_INT tmp_err = 0;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4633
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4634 char job = 'L';
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4635 F77_XFCN (zpbtrf, ZPBTRF, (F77_CONST_CHAR_ARG2 (&job, 1),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4636 tmp_nr, n_lower, F77_DBLE_CMPLX_ARG (tmp_data), ldm, tmp_err
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4637 F77_CHAR_ARG_LEN (1)));
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4638
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4639 err = tmp_err;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4640
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4641 if (err != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4642 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4643 rcond = 0.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4644 mattype.mark_as_unsymmetric ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4645 typ = MatrixType::Banded;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4646 err = 0;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4647 }
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4648 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4649 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4650 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4651 {
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
4652 Array<Complex> z (dim_vector (2 * nr, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
4653 Complex *pz = z.rwdata ();
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
4654 Array<double> iz (dim_vector (nr, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
4655 double *piz = iz.rwdata ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4656
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4657 F77_XFCN (zpbcon, ZPBCON,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
4658 (F77_CONST_CHAR_ARG2 (&job, 1),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4659 tmp_nr, n_lower, F77_DBLE_CMPLX_ARG (tmp_data), ldm,
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4660 anorm, rcond, F77_DBLE_CMPLX_ARG (pz), piz, tmp_err
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
4661 F77_CHAR_ARG_LEN (1)));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4662
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4663 err = tmp_err;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4664
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4665 if (err != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4666 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4667
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
4668 if (is_singular (rcond) || octave::math::isnan (rcond))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4669 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4670 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4671
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4672 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4673 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4674 sing_handler (rcond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4675 mattype.mark_as_rectangular ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4676 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4677 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
4678 octave::warn_singular_matrix (rcond);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4679 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4680 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4681 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4682 rcond = 1.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4683
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4684 if (err == 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4685 {
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4686 F77_INT b_nr = octave::to_f77_int (b.rows ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4687 octave_idx_type b_nc = b.cols ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4688 OCTAVE_LOCAL_BUFFER (Complex, Bx, b_nr);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4689
18812
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18678
diff changeset
4690 // Take a first guess that the number of nonzero terms
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4691 // will be as many as in b
33037
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
4692 octave_idx_type x_nz = b.nnz ();
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
4693 octave_idx_type ii = 0;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4694 retval = SparseComplexMatrix (b_nr, b_nc, x_nz);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4695
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4696 retval.xcidx (0) = 0;
33037
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
4697 for (octave_idx_type j = 0; j < b_nc; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4698 {
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4699 for (F77_INT i = 0; i < b_nr; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4700 Bx[i] = b.elem (i, j);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4701
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4702 F77_XFCN (zpbtrs, ZPBTRS,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4703 (F77_CONST_CHAR_ARG2 (&job, 1),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4704 tmp_nr, n_lower, 1, F77_DBLE_CMPLX_ARG (tmp_data),
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4705 ldm, F77_DBLE_CMPLX_ARG (Bx), b_nr, tmp_err
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4706 F77_CHAR_ARG_LEN (1)));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4707
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4708 err = tmp_err;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4709
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4710 if (err != 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4711 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
4712 // FIXME: Probably should be a warning.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4713 (*current_liboctave_error_handler)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4714 ("SparseComplexMatrix::solve solve failed");
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4715 err = -1;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4716 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4717 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4718
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4719 for (octave_idx_type i = 0; i < b_nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4720 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4721 Complex tmp = Bx[i];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4722 if (tmp != 0.0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4723 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4724 if (ii == x_nz)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4725 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4726 // Resize the sparse matrix
24796
d3a79cb734d2 Fix performance of Sparse fsolve for complex sparse matrices (bug #53140).
Rik <rik@octave.org>
parents: 24255
diff changeset
4727 octave_idx_type sz;
d3a79cb734d2 Fix performance of Sparse fsolve for complex sparse matrices (bug #53140).
Rik <rik@octave.org>
parents: 24255
diff changeset
4728 sz = (static_cast<double> (b_nc) - j) / b_nc
d3a79cb734d2 Fix performance of Sparse fsolve for complex sparse matrices (bug #53140).
Rik <rik@octave.org>
parents: 24255
diff changeset
4729 * x_nz;
d3a79cb734d2 Fix performance of Sparse fsolve for complex sparse matrices (bug #53140).
Rik <rik@octave.org>
parents: 24255
diff changeset
4730 sz = x_nz + (sz > 100 ? sz : 100);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4731 retval.change_capacity (sz);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4732 x_nz = sz;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4733 }
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4734 retval.xdata (ii) = tmp;
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4735 retval.xridx (ii++) = i;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4736 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4737 }
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4738 retval.xcidx (j+1) = ii;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4739 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4740
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4741 retval.maybe_compress ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4742 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4743 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4744 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4745
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
4746 if (typ == MatrixType::Banded)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4747 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4748 // Create the storage for the banded form of the sparse matrix
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4749 F77_INT n_upper = octave::to_f77_int (mattype.nupper ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4750 F77_INT n_lower = octave::to_f77_int (mattype.nlower ());
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4751 F77_INT ldm = n_upper + 2 * n_lower + 1;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4752
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4753 ComplexMatrix m_band (ldm, nc);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
4754 Complex *tmp_data = m_band.rwdata ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4755
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4756 if (! mattype.is_dense ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4757 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4758 octave_idx_type ii = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4759
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4760 for (F77_INT j = 0; j < ldm; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4761 for (octave_idx_type i = 0; i < nc; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4762 tmp_data[ii++] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4763 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4764
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4765 for (octave_idx_type j = 0; j < nc; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4766 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4767 m_band(ridx (i) - j + n_lower + n_upper, j) = data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4768
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4769 // Calculate the norm of the matrix, for later use.
18676
5bd1ca29c5f0 Clean up questionable code bits identified by clang sanitize.
Rik <rik@octave.org>
parents: 18110
diff changeset
4770 double anorm = 0.0;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4771 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4772 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4773 for (octave_idx_type j = 0; j < nr; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4774 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4775 double atmp = 0.;
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4776 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4777 atmp += std::abs (data (i));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4778 if (atmp > anorm)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4779 anorm = atmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4780 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4781 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4782
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4783 Array<F77_INT> ipvt (dim_vector (nr, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
4784 F77_INT *pipvt = ipvt.rwdata ();
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4785
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4786 F77_INT tmp_nr = octave::to_f77_int (nr);
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4787
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4788 F77_INT tmp_err = 0;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4789
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4790 F77_XFCN (zgbtrf, ZGBTRF, (tmp_nr, tmp_nr, n_lower, n_upper,
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22327
diff changeset
4791 F77_DBLE_CMPLX_ARG (tmp_data),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4792 ldm, pipvt, tmp_err));
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4793
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4794 err = tmp_err;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4795
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4796 if (err != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4797 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4798 rcond = 0.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4799 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4800
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4801 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4802 {
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
4803 sing_handler (rcond);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
4804 mattype.mark_as_rectangular ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4805 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4806 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
4807 octave::warn_singular_matrix ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4808 }
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4809 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4810 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4811 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4812 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4813 char job = '1';
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
4814 Array<Complex> z (dim_vector (2 * nr, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
4815 Complex *pz = z.rwdata ();
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
4816 Array<double> iz (dim_vector (nr, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
4817 double *piz = iz.rwdata ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4818
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4819 F77_INT tmp_nc = octave::to_f77_int (nc);
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4820
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4821 F77_XFCN (zgbcon, ZGBCON,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
4822 (F77_CONST_CHAR_ARG2 (&job, 1),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4823 tmp_nc, n_lower, n_upper, F77_DBLE_CMPLX_ARG (tmp_data), ldm, pipvt,
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4824 anorm, rcond, F77_DBLE_CMPLX_ARG (pz), piz, tmp_err
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
4825 F77_CHAR_ARG_LEN (1)));
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
4826
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4827 err = tmp_err;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4828
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
4829 if (err != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4830 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4831
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
4832 if (is_singular (rcond) || octave::math::isnan (rcond))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4833 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4834 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4835
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4836 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4837 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4838 sing_handler (rcond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4839 mattype.mark_as_rectangular ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4840 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4841 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
4842 octave::warn_singular_matrix (rcond);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4843 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4844 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4845 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4846 rcond = 1.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4847
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4848 if (err == 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4849 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4850 char job = 'N';
33037
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
4851 octave_idx_type x_nz = b.nnz ();
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4852 F77_INT b_nr = octave::to_f77_int (b.rows ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4853 octave_idx_type b_nc = b.cols ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4854 retval = SparseComplexMatrix (nr, b_nc, x_nz);
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4855 retval.xcidx (0) = 0;
33037
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
4856 octave_idx_type ii = 0;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4857
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4858 OCTAVE_LOCAL_BUFFER (Complex, work, nr);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4859
33037
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
4860 for (octave_idx_type j = 0; j < b_nc; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4861 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4862 for (octave_idx_type i = 0; i < nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4863 work[i] = 0.;
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4864 for (octave_idx_type i = b.cidx (j);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4865 i < b.cidx (j+1); i++)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4866 work[b.ridx (i)] = b.data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4867
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4868 F77_XFCN (zgbtrs, ZGBTRS,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4869 (F77_CONST_CHAR_ARG2 (&job, 1),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4870 tmp_nr, n_lower, n_upper, 1, F77_DBLE_CMPLX_ARG (tmp_data),
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4871 ldm, pipvt, F77_DBLE_CMPLX_ARG (work), b_nr, tmp_err
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4872 F77_CHAR_ARG_LEN (1)));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4873
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4874 err = tmp_err;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4875
18812
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18678
diff changeset
4876 // Count nonzeros in work vector and adjust
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4877 // space in retval if needed
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4878 octave_idx_type new_nnz = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4879 for (octave_idx_type i = 0; i < nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4880 if (work[i] != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4881 new_nnz++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4882
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4883 if (ii + new_nnz > x_nz)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4884 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4885 // Resize the sparse matrix
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4886 octave_idx_type sz = new_nnz * (b_nc - j) + x_nz;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4887 retval.change_capacity (sz);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4888 x_nz = sz;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4889 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4890
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4891 for (octave_idx_type i = 0; i < nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4892 if (work[i] != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4893 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4894 retval.xridx (ii) = i;
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4895 retval.xdata (ii++) = work[i];
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4896 }
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4897 retval.xcidx (j+1) = ii;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4898 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4899
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4900 retval.maybe_compress ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4901 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4902 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4903 }
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
4904 else if (typ != MatrixType::Banded_Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4905 (*current_liboctave_error_handler) ("incorrect matrix type");
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4906 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4907
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4908 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4909 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4910
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4911 ComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
4912 SparseComplexMatrix::bsolve (MatrixType& mattype, const ComplexMatrix& b,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4913 octave_idx_type& err, double& rcond,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4914 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4915 bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4916 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4917 ComplexMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4918
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
4919 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
4920 octave_idx_type nc = cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4921 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4922
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
4923 if (nr != nc || nr != b.rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4924 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4925 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
4926
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
4927 if (nr == 0 || b.cols () == 0)
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
4928 retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4929 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4930 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4931 // Print spparms("spumoni") info if requested
33037
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
4932 int typ = mattype.type ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4933 mattype.info ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
4934
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
4935 if (typ == MatrixType::Banded_Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4936 {
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4937 F77_INT n_lower = octave::to_f77_int (mattype.nlower ());
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4938 F77_INT ldm = n_lower + 1;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4939
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4940 ComplexMatrix m_band (ldm, nc);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
4941 Complex *tmp_data = m_band.rwdata ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4942
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4943 if (! mattype.is_dense ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4944 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4945 octave_idx_type ii = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4946
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4947 for (F77_INT j = 0; j < ldm; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4948 for (octave_idx_type i = 0; i < nc; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4949 tmp_data[ii++] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4950 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4951
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4952 for (octave_idx_type j = 0; j < nc; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4953 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4954 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4955 octave_idx_type ri = ridx (i);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4956 if (ri >= j)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4957 m_band(ri - j, j) = data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4958 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4959
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4960 // Calculate the norm of the matrix, for later use.
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4961 double anorm;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4962 if (calc_cond)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
4963 anorm = m_band.abs ().sum ().row (0).max ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4964
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
4965 F77_INT tmp_nr = octave::to_f77_int (nr);
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4966
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4967 F77_INT tmp_err = 0;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4968
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4969 char job = 'L';
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4970 F77_XFCN (zpbtrf, ZPBTRF, (F77_CONST_CHAR_ARG2 (&job, 1),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4971 tmp_nr, n_lower, F77_DBLE_CMPLX_ARG (tmp_data), ldm, tmp_err
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4972 F77_CHAR_ARG_LEN (1)));
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4973
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4974 err = tmp_err;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4975
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4976 if (err != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4977 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4978 // Matrix is not positive definite!! Fall through to
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4979 // unsymmetric banded solver.
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4980 rcond = 0.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4981 mattype.mark_as_unsymmetric ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4982 typ = MatrixType::Banded;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4983 err = 0;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4984 }
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4985 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4986 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4987 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4988 {
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
4989 Array<Complex> z (dim_vector (2 * nr, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
4990 Complex *pz = z.rwdata ();
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
4991 Array<double> iz (dim_vector (nr, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
4992 double *piz = iz.rwdata ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4993
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
4994 F77_XFCN (zpbcon, ZPBCON,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
4995 (F77_CONST_CHAR_ARG2 (&job, 1),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4996 tmp_nr, n_lower, F77_DBLE_CMPLX_ARG (tmp_data), ldm,
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
4997 anorm, rcond, F77_DBLE_CMPLX_ARG (pz), piz, tmp_err
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
4998 F77_CHAR_ARG_LEN (1)));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
4999
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5000 err = tmp_err;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5001
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5002 if (err != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5003 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5004
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
5005 if (is_singular (rcond) || octave::math::isnan (rcond))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5006 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5007 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5008
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5009 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5010 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5011 sing_handler (rcond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5012 mattype.mark_as_rectangular ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5013 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5014 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
5015 octave::warn_singular_matrix (rcond);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5016 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5017 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5018 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5019 rcond = 1.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5020
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5021 if (err == 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5022 {
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
5023 F77_INT b_nr = octave::to_f77_int (b.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
5024 F77_INT b_nc = octave::to_f77_int (b.cols ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5025 retval = ComplexMatrix (b);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
5026 Complex *result = retval.rwdata ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5027
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5028 F77_XFCN (zpbtrs, ZPBTRS,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5029 (F77_CONST_CHAR_ARG2 (&job, 1),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5030 tmp_nr, n_lower, b_nc, F77_DBLE_CMPLX_ARG (tmp_data),
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5031 ldm, F77_DBLE_CMPLX_ARG (result), b_nr, tmp_err
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5032 F77_CHAR_ARG_LEN (1)));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5033
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5034 err = tmp_err;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5035
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5036 if (err != 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5037 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
5038 // FIXME: Probably should be a warning.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5039 (*current_liboctave_error_handler)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5040 ("SparseComplexMatrix::solve solve failed");
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5041 err = -1;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5042 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5043 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5044 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5045 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5046
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
5047 if (typ == MatrixType::Banded)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5048 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5049 // Create the storage for the banded form of the sparse matrix
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
5050 F77_INT n_upper = octave::to_f77_int (mattype.nupper ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
5051 F77_INT n_lower = octave::to_f77_int (mattype.nlower ());
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5052 F77_INT ldm = n_upper + 2 * n_lower + 1;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5053
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5054 ComplexMatrix m_band (ldm, nc);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
5055 Complex *tmp_data = m_band.rwdata ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5056
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5057 if (! mattype.is_dense ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5058 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5059 octave_idx_type ii = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5060
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5061 for (F77_INT j = 0; j < ldm; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5062 for (octave_idx_type i = 0; i < nc; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5063 tmp_data[ii++] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5064 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5065
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5066 for (octave_idx_type j = 0; j < nc; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
5067 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
5068 m_band(ridx (i) - j + n_lower + n_upper, j) = data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5069
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5070 // Calculate the norm of the matrix, for later use.
18676
5bd1ca29c5f0 Clean up questionable code bits identified by clang sanitize.
Rik <rik@octave.org>
parents: 18110
diff changeset
5071 double anorm = 0.0;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5072 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5073 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5074 for (octave_idx_type j = 0; j < nr; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5075 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5076 double atmp = 0.;
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
5077 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
5078 atmp += std::abs (data (i));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5079 if (atmp > anorm)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5080 anorm = atmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5081 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5082 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5083
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5084 Array<F77_INT> ipvt (dim_vector (nr, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
5085 F77_INT *pipvt = ipvt.rwdata ();
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5086
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
5087 F77_INT tmp_nr = octave::to_f77_int (nr);
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5088
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5089 F77_INT tmp_err = 0;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5090
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5091 F77_XFCN (zgbtrf, ZGBTRF, (tmp_nr, tmp_nr, n_lower, n_upper,
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22327
diff changeset
5092 F77_DBLE_CMPLX_ARG (tmp_data),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5093 ldm, pipvt, tmp_err));
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5094
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5095 err = tmp_err;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5096
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5097 if (err != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5098 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5099 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5100 rcond = 0.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5101
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5102 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5103 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5104 sing_handler (rcond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5105 mattype.mark_as_rectangular ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5106 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5107 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
5108 octave::warn_singular_matrix ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5109 }
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5110 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5111 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5112 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5113 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5114 char job = '1';
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
5115 Array<Complex> z (dim_vector (2 * nr, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
5116 Complex *pz = z.rwdata ();
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
5117 Array<double> iz (dim_vector (nr, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
5118 double *piz = iz.rwdata ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5119
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
5120 F77_INT tmp_nc = octave::to_f77_int (nc);
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5121
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5122 F77_XFCN (zgbcon, ZGBCON,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5123 (F77_CONST_CHAR_ARG2 (&job, 1),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5124 tmp_nc, n_lower, n_upper, F77_DBLE_CMPLX_ARG (tmp_data), ldm, pipvt,
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5125 anorm, rcond, F77_DBLE_CMPLX_ARG (pz), piz, tmp_err
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5126 F77_CHAR_ARG_LEN (1)));
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5127
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5128 err = tmp_err;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5129
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5130 if (err != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5131 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5132
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
5133 if (is_singular (rcond) || octave::math::isnan (rcond))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5134 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5135 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5136
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5137 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5138 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5139 sing_handler (rcond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5140 mattype.mark_as_rectangular ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5141 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5142 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
5143 octave::warn_singular_matrix (rcond);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5144 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5145 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5146 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5147 rcond = 1.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5148
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5149 if (err == 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5150 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5151 char job = 'N';
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
5152 F77_INT b_nr = octave::to_f77_int (b.rows ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
5153 F77_INT b_nc = octave::to_f77_int (b.cols ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5154 retval = ComplexMatrix (b);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
5155 Complex *result = retval.rwdata ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5156
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5157 F77_XFCN (zgbtrs, ZGBTRS,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5158 (F77_CONST_CHAR_ARG2 (&job, 1),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5159 tmp_nr, n_lower, n_upper, b_nc, F77_DBLE_CMPLX_ARG (tmp_data),
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5160 ldm, pipvt, F77_DBLE_CMPLX_ARG (result), b_nr, tmp_err
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5161 F77_CHAR_ARG_LEN (1)));
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5162
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5163 err = tmp_err;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5164 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5165 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5166 }
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
5167 else if (typ != MatrixType::Banded_Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5168 (*current_liboctave_error_handler) ("incorrect matrix type");
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5169 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5170
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5171 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5172 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5173
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5174 SparseComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
5175 SparseComplexMatrix::bsolve (MatrixType& mattype, const SparseComplexMatrix& b,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5176 octave_idx_type& err, double& rcond,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5177 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5178 bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5179 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5180 SparseComplexMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5181
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
5182 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
5183 octave_idx_type nc = cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5184 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5185
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
5186 if (nr != nc || nr != b.rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5187 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5188 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
5189
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
5190 if (nr == 0 || b.cols () == 0)
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
5191 retval = SparseComplexMatrix (nc, b.cols ());
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5192 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5193 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5194 // Print spparms("spumoni") info if requested
33037
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
5195 int typ = mattype.type ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5196 mattype.info ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5197
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
5198 if (typ == MatrixType::Banded_Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5199 {
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
5200 F77_INT n_lower = octave::to_f77_int (mattype.nlower ());
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5201 F77_INT ldm = n_lower + 1;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5202
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5203 ComplexMatrix m_band (ldm, nc);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
5204 Complex *tmp_data = m_band.rwdata ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5205
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5206 if (! mattype.is_dense ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5207 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5208 octave_idx_type ii = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5209
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5210 for (F77_INT j = 0; j < ldm; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5211 for (octave_idx_type i = 0; i < nc; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5212 tmp_data[ii++] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5213 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5214
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5215 for (octave_idx_type j = 0; j < nc; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
5216 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5217 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5218 octave_idx_type ri = ridx (i);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5219 if (ri >= j)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
5220 m_band(ri - j, j) = data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5221 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5222
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5223 // Calculate the norm of the matrix, for later use.
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5224 double anorm;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5225 if (calc_cond)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
5226 anorm = m_band.abs ().sum ().row (0).max ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5227
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
5228 F77_INT tmp_nr = octave::to_f77_int (nr);
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5229
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5230 F77_INT tmp_err = 0;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5231
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5232 char job = 'L';
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5233 F77_XFCN (zpbtrf, ZPBTRF, (F77_CONST_CHAR_ARG2 (&job, 1),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5234 tmp_nr, n_lower, F77_DBLE_CMPLX_ARG (tmp_data), ldm, tmp_err
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5235 F77_CHAR_ARG_LEN (1)));
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5236
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5237 err = tmp_err;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5238
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5239 if (err != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5240 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5241 // Matrix is not positive definite!! Fall through to
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5242 // unsymmetric banded solver.
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5243 mattype.mark_as_unsymmetric ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5244 typ = MatrixType::Banded;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5245
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5246 rcond = 0.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5247 err = 0;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5248 }
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5249 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5250 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5251 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5252 {
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
5253 Array<Complex> z (dim_vector (2 * nr, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
5254 Complex *pz = z.rwdata ();
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
5255 Array<double> iz (dim_vector (nr, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
5256 double *piz = iz.rwdata ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5257
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5258 F77_XFCN (zpbcon, ZPBCON,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5259 (F77_CONST_CHAR_ARG2 (&job, 1),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5260 tmp_nr, n_lower, F77_DBLE_CMPLX_ARG (tmp_data), ldm,
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5261 anorm, rcond, F77_DBLE_CMPLX_ARG (pz), piz, tmp_err
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5262 F77_CHAR_ARG_LEN (1)));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5263
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5264 err = tmp_err;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5265
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5266 if (err != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5267 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5268
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
5269 if (is_singular (rcond) || octave::math::isnan (rcond))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5270 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5271 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5272
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5273 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5274 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5275 sing_handler (rcond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5276 mattype.mark_as_rectangular ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5277 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5278 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
5279 octave::warn_singular_matrix (rcond);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5280 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5281 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5282 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5283 rcond = 1.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5284
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5285 if (err == 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5286 {
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
5287 F77_INT b_nr = octave::to_f77_int (b.rows ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5288 octave_idx_type b_nc = b.cols ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5289 OCTAVE_LOCAL_BUFFER (Complex, Bx, b_nr);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5290
18812
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18678
diff changeset
5291 // Take a first guess that the number of nonzero terms
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5292 // will be as many as in b
33037
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
5293 octave_idx_type x_nz = b.nnz ();
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
5294 octave_idx_type ii = 0;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5295 retval = SparseComplexMatrix (b_nr, b_nc, x_nz);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5296
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
5297 retval.xcidx (0) = 0;
33037
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
5298 for (octave_idx_type j = 0; j < b_nc; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5299 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5300
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5301 for (F77_INT i = 0; i < b_nr; i++)
30394
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29937
diff changeset
5302 Bx[i] = b(i, j);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5303
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5304 F77_XFCN (zpbtrs, ZPBTRS,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5305 (F77_CONST_CHAR_ARG2 (&job, 1),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5306 tmp_nr, n_lower, 1, F77_DBLE_CMPLX_ARG (tmp_data),
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5307 ldm, F77_DBLE_CMPLX_ARG (Bx), b_nr, tmp_err
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5308 F77_CHAR_ARG_LEN (1)));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5309
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5310 err = tmp_err;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5311
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5312 if (err != 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5313 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
5314 // FIXME: Probably should be a warning.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5315 (*current_liboctave_error_handler)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5316 ("SparseMatrix::solve solve failed");
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5317 err = -1;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5318 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5319 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5320
18812
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18678
diff changeset
5321 // Count nonzeros in work vector and adjust
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5322 // space in retval if needed
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5323 octave_idx_type new_nnz = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5324 for (octave_idx_type i = 0; i < nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5325 if (Bx[i] != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5326 new_nnz++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5327
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5328 if (ii + new_nnz > x_nz)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5329 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5330 // Resize the sparse matrix
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5331 octave_idx_type sz = new_nnz * (b_nc - j) + x_nz;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5332 retval.change_capacity (sz);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5333 x_nz = sz;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5334 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5335
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5336 for (octave_idx_type i = 0; i < nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5337 if (Bx[i] != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5338 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
5339 retval.xridx (ii) = i;
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
5340 retval.xdata (ii++) = Bx[i];
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5341 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5342
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
5343 retval.xcidx (j+1) = ii;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5344 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5345
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5346 retval.maybe_compress ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5347 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5348 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5349 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5350
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
5351 if (typ == MatrixType::Banded)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5352 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5353 // Create the storage for the banded form of the sparse matrix
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
5354 F77_INT n_upper = octave::to_f77_int (mattype.nupper ());
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
5355 F77_INT n_lower = octave::to_f77_int (mattype.nlower ());
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5356 F77_INT ldm = n_upper + 2 * n_lower + 1;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5357
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5358 ComplexMatrix m_band (ldm, nc);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
5359 Complex *tmp_data = m_band.rwdata ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5360
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5361 if (! mattype.is_dense ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5362 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5363 octave_idx_type ii = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5364
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5365 for (F77_INT j = 0; j < ldm; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5366 for (octave_idx_type i = 0; i < nc; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5367 tmp_data[ii++] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5368 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5369
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5370 for (octave_idx_type j = 0; j < nc; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
5371 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
5372 m_band(ridx (i) - j + n_lower + n_upper, j) = data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5373
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5374 // Calculate the norm of the matrix, for later use.
18676
5bd1ca29c5f0 Clean up questionable code bits identified by clang sanitize.
Rik <rik@octave.org>
parents: 18110
diff changeset
5375 double anorm = 0.0;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5376 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5377 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5378 for (octave_idx_type j = 0; j < nr; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5379 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5380 double atmp = 0.;
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
5381 for (octave_idx_type i = cidx (j); i < cidx (j+1); i++)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
5382 atmp += std::abs (data (i));
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5383 if (atmp > anorm)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5384 anorm = atmp;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5385 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5386 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5387
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5388 Array<F77_INT> ipvt (dim_vector (nr, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
5389 F77_INT *pipvt = ipvt.rwdata ();
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5390
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
5391 F77_INT tmp_nr = octave::to_f77_int (nr);
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5392
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5393 F77_INT tmp_err = 0;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5394
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5395 F77_XFCN (zgbtrf, ZGBTRF, (tmp_nr, tmp_nr, n_lower, n_upper,
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22327
diff changeset
5396 F77_DBLE_CMPLX_ARG (tmp_data),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5397 ldm, pipvt, tmp_err));
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5398
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5399 err = tmp_err;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5400
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5401 if (err != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5402 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5403 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5404 rcond = 0.0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5405
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5406 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5407 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5408 sing_handler (rcond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5409 mattype.mark_as_rectangular ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5410 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5411 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
5412 octave::warn_singular_matrix ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5413 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5414 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5415 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5416 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5417 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5418 char job = '1';
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
5419 Array<Complex> z (dim_vector (2 * nr, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
5420 Complex *pz = z.rwdata ();
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
5421 Array<double> iz (dim_vector (nr, 1));
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
5422 double *piz = iz.rwdata ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5423
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
5424 F77_INT tmp_nc = octave::to_f77_int (nc);
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5425
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5426 F77_XFCN (zgbcon, ZGBCON,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5427 (F77_CONST_CHAR_ARG2 (&job, 1),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5428 tmp_nc, n_lower, n_upper, F77_DBLE_CMPLX_ARG (tmp_data), ldm, pipvt,
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5429 anorm, rcond, F77_DBLE_CMPLX_ARG (pz), piz, tmp_err
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5430 F77_CHAR_ARG_LEN (1)));
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5431
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5432 err = tmp_err;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5433
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5434 if (err != 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5435 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5436
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
5437 if (is_singular (rcond) || octave::math::isnan (rcond))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5438 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5439 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5440
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5441 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5442 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5443 sing_handler (rcond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5444 mattype.mark_as_rectangular ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5445 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5446 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
5447 octave::warn_singular_matrix (rcond);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5448 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5449 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5450 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5451 rcond = 1.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5452
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5453 if (err == 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5454 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5455 char job = 'N';
33037
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
5456 octave_idx_type x_nz = b.nnz ();
22988
cd33c785e80e put to_f77_int inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22973
diff changeset
5457 F77_INT b_nr = octave::to_f77_int (b.rows ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5458 octave_idx_type b_nc = b.cols ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5459 retval = SparseComplexMatrix (nr, b_nc, x_nz);
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
5460 retval.xcidx (0) = 0;
33037
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
5461 octave_idx_type ii = 0;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5462
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5463 OCTAVE_LOCAL_BUFFER (Complex, Bx, nr);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5464
33037
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
5465 for (octave_idx_type j = 0; j < b_nc; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5466 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5467 for (octave_idx_type i = 0; i < nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5468 Bx[i] = 0.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5469
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
5470 for (octave_idx_type i = b.cidx (j);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
5471 i < b.cidx (j+1); i++)
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
5472 Bx[b.ridx (i)] = b.data (i);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5473
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5474 F77_XFCN (zgbtrs, ZGBTRS,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5475 (F77_CONST_CHAR_ARG2 (&job, 1),
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5476 tmp_nr, n_lower, n_upper, 1, F77_DBLE_CMPLX_ARG (tmp_data),
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5477 ldm, pipvt, F77_DBLE_CMPLX_ARG (Bx), b_nr, tmp_err
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5478 F77_CHAR_ARG_LEN (1)));
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5479
22973
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5480 err = tmp_err;
aa55d32100c9 use F77_INT instead of octave_idx_type for liboctave sparse matrix classes
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
5481
18812
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18678
diff changeset
5482 // Count nonzeros in work vector and adjust
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5483 // space in retval if needed
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5484 octave_idx_type new_nnz = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5485 for (octave_idx_type i = 0; i < nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5486 if (Bx[i] != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5487 new_nnz++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5488
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5489 if (ii + new_nnz > x_nz)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5490 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5491 // Resize the sparse matrix
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5492 octave_idx_type sz = new_nnz * (b_nc - j) + x_nz;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5493 retval.change_capacity (sz);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5494 x_nz = sz;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5495 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5496
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5497 for (octave_idx_type i = 0; i < nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5498 if (Bx[i] != 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5499 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
5500 retval.xridx (ii) = i;
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
5501 retval.xdata (ii++) = Bx[i];
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5502 }
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
5503 retval.xcidx (j+1) = ii;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5504 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5505
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5506 retval.maybe_compress ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5507 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5508 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5509 }
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
5510 else if (typ != MatrixType::Banded_Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5511 (*current_liboctave_error_handler) ("incorrect matrix type");
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5512 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5513
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5514 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5515 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5516
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5517 void *
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
5518 SparseComplexMatrix::factorize (octave_idx_type& err, double& rcond,
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
5519 Matrix& Control, Matrix& Info,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5520 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5521 bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5522 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5523 // The return values
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23450
diff changeset
5524 void *Numeric = nullptr;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5525 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5526
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21723
diff changeset
5527 #if defined (HAVE_UMFPACK)
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
5528
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5529 // Setup the control parameters
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5530 Control = Matrix (UMFPACK_CONTROL, 1);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
5531 double *control = Control.rwdata ();
5322
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5307
diff changeset
5532 UMFPACK_ZNAME (defaults) (control);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5533
29872
df2cdf42a909 update coding style for octave_sparse_params class
John W. Eaton <jwe@octave.org>
parents: 29399
diff changeset
5534 double tmp = octave::sparse_params::get_key ("spumoni");
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
5535 if (! octave::math::isnan (tmp))
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5536 Control (UMFPACK_PRL) = tmp;
29872
df2cdf42a909 update coding style for octave_sparse_params class
John W. Eaton <jwe@octave.org>
parents: 29399
diff changeset
5537 tmp = octave::sparse_params::get_key ("piv_tol");
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
5538 if (! octave::math::isnan (tmp))
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5539 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5540 Control (UMFPACK_SYM_PIVOT_TOLERANCE) = tmp;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5541 Control (UMFPACK_PIVOT_TOLERANCE) = tmp;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5542 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5543
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5544 // Set whether we are allowed to modify Q or not
29872
df2cdf42a909 update coding style for octave_sparse_params class
John W. Eaton <jwe@octave.org>
parents: 29399
diff changeset
5545 tmp = octave::sparse_params::get_key ("autoamd");
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
5546 if (! octave::math::isnan (tmp))
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5547 Control (UMFPACK_FIXQ) = tmp;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5548
5322
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5307
diff changeset
5549 UMFPACK_ZNAME (report_control) (control);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5550
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
5551 const octave_idx_type *Ap = cidx ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
5552 const octave_idx_type *Ai = ridx ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5553 const Complex *Ax = data ();
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
5554 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
5555 octave_idx_type nc = cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5556
23391
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
5557 UMFPACK_ZNAME (report_matrix) (nr, nc,
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
5558 octave::to_suitesparse_intptr (Ap),
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
5559 octave::to_suitesparse_intptr (Ai),
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5560 reinterpret_cast<const double *> (Ax),
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
5561 nullptr, 1, control);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5562
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5563 void *Symbolic;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5564 Info = Matrix (1, UMFPACK_INFO);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
5565 double *info = Info.rwdata ();
23391
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
5566 int status = UMFPACK_ZNAME (qsymbolic) (nr, nc,
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
5567 octave::to_suitesparse_intptr (Ap),
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
5568 octave::to_suitesparse_intptr (Ai),
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5569 reinterpret_cast<const double *> (Ax),
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
5570 nullptr, nullptr, &Symbolic, control, info);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5571
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5572 if (status < 0)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5573 {
5322
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5307
diff changeset
5574 UMFPACK_ZNAME (report_status) (control, status);
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5307
diff changeset
5575 UMFPACK_ZNAME (report_info) (control, info);
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5307
diff changeset
5576
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5577 UMFPACK_ZNAME (free_symbolic) (&Symbolic);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
5578
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
5579 // FIXME: Should this be a warning?
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
5580 (*current_liboctave_error_handler)
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
5581 ("SparseComplexMatrix::solve symbolic factorization failed");
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
5582 err = -1;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5583 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5584 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5585 {
5322
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5307
diff changeset
5586 UMFPACK_ZNAME (report_symbolic) (Symbolic, control);
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5307
diff changeset
5587
23391
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
5588 status = UMFPACK_ZNAME (numeric) (octave::to_suitesparse_intptr (Ap),
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
5589 octave::to_suitesparse_intptr (Ai),
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5590 reinterpret_cast<const double *> (Ax),
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
5591 nullptr, Symbolic, &Numeric, control, info);
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5592 UMFPACK_ZNAME (free_symbolic) (&Symbolic);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5593
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
5594 if (calc_cond)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5595 rcond = Info (UMFPACK_RCOND);
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
5596 else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5597 rcond = 1.;
33062
406c7ef068af Eliminate more instances of volatile keywoard missed in cset 147c69ad945d (bug #65321).
Rik <rik@octave.org>
parents: 33043
diff changeset
5598
19864
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
5599 if (status == UMFPACK_WARNING_singular_matrix
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
5600 || is_singular (rcond) || octave::math::isnan (rcond))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5601 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5602 UMFPACK_ZNAME (report_numeric) (Numeric, control);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5603
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5604 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5605
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5606 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5607 sing_handler (rcond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5608 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
5609 octave::warn_singular_matrix (rcond);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5610 }
5610
9761b7d24e9e [project @ 2006-02-09 09:12:02 by dbateman]
dbateman
parents: 5604
diff changeset
5611 else if (status < 0)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5612 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
5613 UMFPACK_ZNAME (report_status) (control, status);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
5614 UMFPACK_ZNAME (report_info) (control, info);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
5615
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
5616 // FIXME: Should this be a warning?
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5617 (*current_liboctave_error_handler)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5618 ("SparseComplexMatrix::solve numeric factorization failed");
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5619
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5620 err = -1;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5621 }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5622 else
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5623 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5624 UMFPACK_ZNAME (report_numeric) (Numeric, control);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5625 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5626 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5627
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5628 if (err != 0)
5322
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5307
diff changeset
5629 UMFPACK_ZNAME (free_numeric) (&Numeric);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5630
21109
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
5631 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
5632
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
5633 octave_unused_parameter (rcond);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
5634 octave_unused_parameter (Control);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
5635 octave_unused_parameter (Info);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
5636 octave_unused_parameter (sing_handler);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
5637 octave_unused_parameter (calc_cond);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
5638
21109
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
5639 (*current_liboctave_error_handler)
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
5640 ("support for UMFPACK was unavailable or disabled when liboctave was built");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
5641
21109
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
5642 #endif
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
5643
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
5644 return Numeric;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5645 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5646
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5647 ComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
5648 SparseComplexMatrix::fsolve (MatrixType& mattype, const Matrix& b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5649 octave_idx_type& err, double& rcond,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5650 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5651 bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5652 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5653 ComplexMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5654
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
5655 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
5656 octave_idx_type nc = cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5657 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5658
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
5659 if (nr != nc || nr != b.rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5660 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5661 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
5662
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
5663 if (nr == 0 || b.cols () == 0)
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
5664 retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5665 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5666 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5667 // Print spparms("spumoni") info if requested
33037
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
5668 int typ = mattype.type ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5669 mattype.info ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5670
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
5671 if (typ == MatrixType::Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5672 {
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21723
diff changeset
5673 #if defined (HAVE_CHOLMOD)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5674 cholmod_common Common;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5675 cholmod_common *cm = &Common;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5676
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5677 // Setup initial parameters
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5678 CHOLMOD_NAME(start) (cm);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5679 cm->prefer_zomplex = false;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5680
29872
df2cdf42a909 update coding style for octave_sparse_params class
John W. Eaton <jwe@octave.org>
parents: 29399
diff changeset
5681 double spu = octave::sparse_params::get_key ("spumoni");
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5682 if (spu == 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5683 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5684 cm->print = -1;
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23708
diff changeset
5685 SUITESPARSE_ASSIGN_FPTR (printf_func, cm->print_function, nullptr);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5686 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5687 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5688 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5689 cm->print = static_cast<int> (spu) + 2;
19139
afd6179d2616 allow building with new version of SuiteSparse (bug #43063)
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
5690 SUITESPARSE_ASSIGN_FPTR (printf_func, cm->print_function, &SparseCholPrint);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5691 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5692
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5693 cm->error_handler = &SparseCholError;
19139
afd6179d2616 allow building with new version of SuiteSparse (bug #43063)
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
5694 SUITESPARSE_ASSIGN_FPTR2 (divcomplex_func, cm->complex_divide, divcomplex);
afd6179d2616 allow building with new version of SuiteSparse (bug #43063)
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
5695 SUITESPARSE_ASSIGN_FPTR2 (hypot_func, cm->hypotenuse, hypot);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5696
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5697 cm->final_ll = true;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5698
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5699 cholmod_sparse Astore;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5700 cholmod_sparse *A = &Astore;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5701 A->nrow = nr;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5702 A->ncol = nc;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5703
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
5704 A->p = cidx ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
5705 A->i = ridx ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
5706 A->nzmax = nnz ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5707 A->packed = true;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5708 A->sorted = true;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
5709 A->nz = nullptr;
21229
a83e7a384ee0 create and install a subset of config.h in octave-config.h
John W. Eaton <jwe@octave.org>
parents: 21219
diff changeset
5710 #if defined (OCTAVE_ENABLE_64)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5711 A->itype = CHOLMOD_LONG;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
5712 #else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5713 A->itype = CHOLMOD_INT;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
5714 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5715 A->dtype = CHOLMOD_DOUBLE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5716 A->stype = 1;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5717 A->xtype = CHOLMOD_COMPLEX;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5718
24255
4283c4c2fcb6 Fix segfault with CHOLMOD library and empty matrices (bug #52365).
Rik <rik@octave.org>
parents: 23219
diff changeset
5719 A->x = data ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5720
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5721 cholmod_dense Bstore;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5722 cholmod_dense *B = &Bstore;
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
5723 B->nrow = b.rows ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
5724 B->ncol = b.cols ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5725 B->d = B->nrow;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5726 B->nzmax = B->nrow * B->ncol;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5727 B->dtype = CHOLMOD_DOUBLE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5728 B->xtype = CHOLMOD_REAL;
24255
4283c4c2fcb6 Fix segfault with CHOLMOD library and empty matrices (bug #52365).
Rik <rik@octave.org>
parents: 23219
diff changeset
5729
29931
7faff48840eb prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents: 29872
diff changeset
5730 B->x = const_cast<double *> (b.data ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5731
29399
019130bd4a3d eliminate last uses of BEGIN/END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
5732 cholmod_factor *L = CHOLMOD_NAME(analyze) (A, cm);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5733 CHOLMOD_NAME(factorize) (A, L, cm);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5734 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5735 rcond = CHOLMOD_NAME(rcond)(L, cm);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5736 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5737 rcond = 1.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5738
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5739 if (rcond == 0.0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5740 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
5741 // Either its indefinite or singular. Try UMFPACK
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5742 mattype.mark_as_unsymmetric ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5743 typ = MatrixType::Full;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5744 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5745 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5746 {
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
5747 if (is_singular (rcond) || octave::math::isnan (rcond))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5748 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5749 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5750
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5751 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5752 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5753 sing_handler (rcond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5754 mattype.mark_as_rectangular ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5755 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5756 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
5757 octave::warn_singular_matrix (rcond);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5758
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5759 return retval;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5760 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5761
29399
019130bd4a3d eliminate last uses of BEGIN/END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
5762 cholmod_dense *X = CHOLMOD_NAME(solve) (CHOLMOD_A, L, B, cm);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5763
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
5764 retval.resize (b.rows (), b.cols ());
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
5765 for (octave_idx_type j = 0; j < b.cols (); j++)
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
5766 {
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
5767 octave_idx_type jr = j * b.rows ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
5768 for (octave_idx_type i = 0; i < b.rows (); i++)
32513
1de97b475564 maint: Add space " " between C++ cast and argument.
Markus Mützel <markus.muetzel@gmx.de>
parents: 32290
diff changeset
5769 retval.xelem (i, j) = static_cast<Complex *> (X->x)[jr + i];
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5770 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5771
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5772 CHOLMOD_NAME(free_dense) (&X, cm);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5773 CHOLMOD_NAME(free_factor) (&L, cm);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5774 CHOLMOD_NAME(finish) (cm);
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23796
diff changeset
5775 static char blank_name[] = " ";
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23796
diff changeset
5776 CHOLMOD_NAME(print_common) (blank_name, cm);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5777 }
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
5778 #else
19410
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 19408
diff changeset
5779 (*current_liboctave_warning_with_id_handler)
21109
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
5780 ("Octave:missing-dependency",
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
5781 "support for CHOLMOD was unavailable or disabled "
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
5782 "when liboctave was built");
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5783
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5784 mattype.mark_as_unsymmetric ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5785 typ = MatrixType::Full;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
5786 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5787 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5788
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
5789 if (typ == MatrixType::Full)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5790 {
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21723
diff changeset
5791 #if defined (HAVE_UMFPACK)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5792 Matrix Control, Info;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5793 void *Numeric = factorize (err, rcond, Control, Info,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5794 sing_handler, calc_cond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5795
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5796 if (err == 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5797 {
24961
ed8090ee632c Make only one iterative refinement after solving sparse systems (bug #53140).
Marco Caliari <marco.caliari@univr.it>
parents: 24797
diff changeset
5798 // one iterative refinement instead of the default two in UMFPACK
ed8090ee632c Make only one iterative refinement after solving sparse systems (bug #53140).
Marco Caliari <marco.caliari@univr.it>
parents: 24797
diff changeset
5799 Control (UMFPACK_IRSTEP) = 1;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5800 octave_idx_type b_nr = b.rows ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5801 octave_idx_type b_nc = b.cols ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5802 int status = 0;
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
5803 double *control = Control.rwdata ();
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
5804 double *info = Info.rwdata ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5805 const octave_idx_type *Ap = cidx ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5806 const octave_idx_type *Ai = ridx ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5807 const Complex *Ax = data ();
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21723
diff changeset
5808 #if defined (UMFPACK_SEPARATE_SPLIT)
29931
7faff48840eb prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents: 29872
diff changeset
5809 const double *Bx = b.data ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5810 OCTAVE_LOCAL_BUFFER (double, Bz, b_nr);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5811 for (octave_idx_type i = 0; i < b_nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5812 Bz[i] = 0.;
5203
dbeafbc0ff64 [project @ 2005-03-15 00:58:55 by jwe]
jwe
parents: 5164
diff changeset
5813 #else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5814 OCTAVE_LOCAL_BUFFER (Complex, Bz, b_nr);
5203
dbeafbc0ff64 [project @ 2005-03-15 00:58:55 by jwe]
jwe
parents: 5164
diff changeset
5815 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5816 retval.resize (b_nr, b_nc);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
5817 Complex *Xx = retval.rwdata ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5818
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5819 for (octave_idx_type j = 0, iidx = 0; j < b_nc; j++, iidx += b_nr)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5820 {
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21723
diff changeset
5821 #if defined (UMFPACK_SEPARATE_SPLIT)
23391
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
5822 status = UMFPACK_ZNAME (solve) (UMFPACK_A,
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
5823 octave::to_suitesparse_intptr (Ap),
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
5824 octave::to_suitesparse_intptr (Ai),
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5825 reinterpret_cast<const double *> (Ax),
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
5826 nullptr,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5827 reinterpret_cast<double *> (&Xx[iidx]),
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
5828 nullptr,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5829 &Bx[iidx], Bz, Numeric,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5830 control, info);
5203
dbeafbc0ff64 [project @ 2005-03-15 00:58:55 by jwe]
jwe
parents: 5164
diff changeset
5831 #else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5832 for (octave_idx_type i = 0; i < b_nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5833 Bz[i] = b.elem (i, j);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5834
23391
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
5835 status = UMFPACK_ZNAME (solve) (UMFPACK_A,
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
5836 octave::to_suitesparse_intptr (Ap),
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
5837 octave::to_suitesparse_intptr (Ai),
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5838 reinterpret_cast<const double *> (Ax),
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5839 0,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5840 reinterpret_cast<double *> (&Xx[iidx]),
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5841 0,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5842 reinterpret_cast<const double *> (Bz),
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5843 0, Numeric,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
5844 control, info);
5203
dbeafbc0ff64 [project @ 2005-03-15 00:58:55 by jwe]
jwe
parents: 5164
diff changeset
5845 #endif
dbeafbc0ff64 [project @ 2005-03-15 00:58:55 by jwe]
jwe
parents: 5164
diff changeset
5846
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5847 if (status < 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5848 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
5849 UMFPACK_ZNAME (report_status) (control, status);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
5850
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
5851 // FIXME: Should this be a warning?
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5852 (*current_liboctave_error_handler)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5853 ("SparseComplexMatrix::solve solve failed");
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5854
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5855 err = -1;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5856 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5857 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5858 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5859
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5860 UMFPACK_ZNAME (report_info) (control, info);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5861
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5862 UMFPACK_ZNAME (free_numeric) (&Numeric);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5863 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5864 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5865 mattype.mark_as_rectangular ();
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
5866
5203
dbeafbc0ff64 [project @ 2005-03-15 00:58:55 by jwe]
jwe
parents: 5164
diff changeset
5867 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
5868 octave_unused_parameter (rcond);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
5869 octave_unused_parameter (sing_handler);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
5870 octave_unused_parameter (calc_cond);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
5871
21109
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
5872 (*current_liboctave_error_handler)
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
5873 ("support for UMFPACK was unavailable or disabled "
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
5874 "when liboctave was built");
5203
dbeafbc0ff64 [project @ 2005-03-15 00:58:55 by jwe]
jwe
parents: 5164
diff changeset
5875 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5876 }
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
5877 else if (typ != MatrixType::Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5878 (*current_liboctave_error_handler) ("incorrect matrix type");
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5879 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
5880
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5881 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5882 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5883
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5884 SparseComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
5885 SparseComplexMatrix::fsolve (MatrixType& mattype, const SparseMatrix& b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5886 octave_idx_type& err, double& rcond,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5887 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5888 bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5889 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5890 SparseComplexMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5891
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
5892 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
5893 octave_idx_type nc = cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5894 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5895
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
5896 if (nr != nc || nr != b.rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5897 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5898 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
5899
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
5900 if (nr == 0 || b.cols () == 0)
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
5901 retval = SparseComplexMatrix (nc, b.cols ());
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5902 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5903 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5904 // Print spparms("spumoni") info if requested
33037
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
5905 int typ = mattype.type ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5906 mattype.info ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
5907
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
5908 if (typ == MatrixType::Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5909 {
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21723
diff changeset
5910 #if defined (HAVE_CHOLMOD)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5911 cholmod_common Common;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5912 cholmod_common *cm = &Common;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5913
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5914 // Setup initial parameters
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5915 CHOLMOD_NAME(start) (cm);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5916 cm->prefer_zomplex = false;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5917
29872
df2cdf42a909 update coding style for octave_sparse_params class
John W. Eaton <jwe@octave.org>
parents: 29399
diff changeset
5918 double spu = octave::sparse_params::get_key ("spumoni");
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5919 if (spu == 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5920 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5921 cm->print = -1;
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23708
diff changeset
5922 SUITESPARSE_ASSIGN_FPTR (printf_func, cm->print_function, nullptr);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5923 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5924 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5925 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5926 cm->print = static_cast<int> (spu) + 2;
19139
afd6179d2616 allow building with new version of SuiteSparse (bug #43063)
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
5927 SUITESPARSE_ASSIGN_FPTR (printf_func, cm->print_function, &SparseCholPrint);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5928 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5929
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5930 cm->error_handler = &SparseCholError;
19139
afd6179d2616 allow building with new version of SuiteSparse (bug #43063)
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
5931 SUITESPARSE_ASSIGN_FPTR2 (divcomplex_func, cm->complex_divide, divcomplex);
afd6179d2616 allow building with new version of SuiteSparse (bug #43063)
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
5932 SUITESPARSE_ASSIGN_FPTR2 (hypot_func, cm->hypotenuse, hypot);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5933
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5934 cm->final_ll = true;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5935
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5936 cholmod_sparse Astore;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5937 cholmod_sparse *A = &Astore;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5938 A->nrow = nr;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5939 A->ncol = nc;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5940
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
5941 A->p = cidx ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
5942 A->i = ridx ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
5943 A->nzmax = nnz ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5944 A->packed = true;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5945 A->sorted = true;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
5946 A->nz = nullptr;
21229
a83e7a384ee0 create and install a subset of config.h in octave-config.h
John W. Eaton <jwe@octave.org>
parents: 21219
diff changeset
5947 #if defined (OCTAVE_ENABLE_64)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5948 A->itype = CHOLMOD_LONG;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
5949 #else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5950 A->itype = CHOLMOD_INT;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
5951 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5952 A->dtype = CHOLMOD_DOUBLE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5953 A->stype = 1;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5954 A->xtype = CHOLMOD_COMPLEX;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5955
24255
4283c4c2fcb6 Fix segfault with CHOLMOD library and empty matrices (bug #52365).
Rik <rik@octave.org>
parents: 23219
diff changeset
5956 A->x = data ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5957
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5958 cholmod_sparse Bstore;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5959 cholmod_sparse *B = &Bstore;
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
5960 B->nrow = b.rows ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
5961 B->ncol = b.cols ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
5962 B->p = b.cidx ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
5963 B->i = b.ridx ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
5964 B->nzmax = b.nnz ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5965 B->packed = true;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5966 B->sorted = true;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
5967 B->nz = nullptr;
21229
a83e7a384ee0 create and install a subset of config.h in octave-config.h
John W. Eaton <jwe@octave.org>
parents: 21219
diff changeset
5968 #if defined (OCTAVE_ENABLE_64)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5969 B->itype = CHOLMOD_LONG;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
5970 #else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5971 B->itype = CHOLMOD_INT;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
5972 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5973 B->dtype = CHOLMOD_DOUBLE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5974 B->stype = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5975 B->xtype = CHOLMOD_REAL;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5976
24255
4283c4c2fcb6 Fix segfault with CHOLMOD library and empty matrices (bug #52365).
Rik <rik@octave.org>
parents: 23219
diff changeset
5977 B->x = b.data ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5978
29399
019130bd4a3d eliminate last uses of BEGIN/END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
5979 cholmod_factor *L = CHOLMOD_NAME(analyze) (A, cm);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5980 CHOLMOD_NAME(factorize) (A, L, cm);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5981 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5982 rcond = CHOLMOD_NAME(rcond)(L, cm);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5983 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5984 rcond = 1.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5985
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5986 if (rcond == 0.0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5987 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
5988 // Either its indefinite or singular. Try UMFPACK
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5989 mattype.mark_as_unsymmetric ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5990 typ = MatrixType::Full;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5991 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5992 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5993 {
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
5994 if (is_singular (rcond) || octave::math::isnan (rcond))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5995 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5996 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5997
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5998 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
5999 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6000 sing_handler (rcond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6001 mattype.mark_as_rectangular ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6002 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6003 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
6004 octave::warn_singular_matrix (rcond);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
6005
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6006 return retval;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6007 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6008
29399
019130bd4a3d eliminate last uses of BEGIN/END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
6009 cholmod_sparse *X = CHOLMOD_NAME(spsolve) (CHOLMOD_A, L, B, cm);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6010
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
6011 retval = SparseComplexMatrix
32290
a81a6fb82c0e Check for integer overflow when copying sizes from SuiteSparse matrices.
Markus Mützel <markus.muetzel@gmx.de>
parents: 32288
diff changeset
6012 (octave::from_size_t (X->nrow),
a81a6fb82c0e Check for integer overflow when copying sizes from SuiteSparse matrices.
Markus Mützel <markus.muetzel@gmx.de>
parents: 32288
diff changeset
6013 octave::from_size_t (X->ncol),
32287
dde186dc7b4c Fix getting number of non-zero elements in SuiteSparse matrices.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
6014 octave::from_suitesparse_long (CHOLMOD_NAME(nnz)
dde186dc7b4c Fix getting number of non-zero elements in SuiteSparse matrices.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
6015 (X, cm)));
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
6016 for (octave_idx_type j = 0;
25688
b2917b7858ba maint: Use Octave convention for spacing of C++ cast statements.
Rik <rik@octave.org>
parents: 25665
diff changeset
6017 j <= static_cast<octave_idx_type> (X->ncol); j++)
32513
1de97b475564 maint: Add space " " between C++ cast and argument.
Markus Mützel <markus.muetzel@gmx.de>
parents: 32290
diff changeset
6018 retval.xcidx (j) = static_cast<octave_idx_type *> (X->p)[j];
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
6019 for (octave_idx_type j = 0;
32287
dde186dc7b4c Fix getting number of non-zero elements in SuiteSparse matrices.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
6020 j < octave::from_suitesparse_long (CHOLMOD_NAME(nnz) (X, cm));
dde186dc7b4c Fix getting number of non-zero elements in SuiteSparse matrices.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
6021 j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6022 {
32513
1de97b475564 maint: Add space " " between C++ cast and argument.
Markus Mützel <markus.muetzel@gmx.de>
parents: 32290
diff changeset
6023 retval.xridx (j) = static_cast<octave_idx_type *> (X->i)[j];
1de97b475564 maint: Add space " " between C++ cast and argument.
Markus Mützel <markus.muetzel@gmx.de>
parents: 32290
diff changeset
6024 retval.xdata (j) = static_cast<Complex *> (X->x)[j];
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6025 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6026
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6027 CHOLMOD_NAME(free_sparse) (&X, cm);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6028 CHOLMOD_NAME(free_factor) (&L, cm);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6029 CHOLMOD_NAME(finish) (cm);
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23796
diff changeset
6030 static char blank_name[] = " ";
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23796
diff changeset
6031 CHOLMOD_NAME(print_common) (blank_name, cm);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6032 }
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
6033 #else
19410
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 19408
diff changeset
6034 (*current_liboctave_warning_with_id_handler)
21109
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
6035 ("Octave:missing-dependency",
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
6036 "support for CHOLMOD was unavailable or disabled "
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
6037 "when liboctave was built");
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6038
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6039 mattype.mark_as_unsymmetric ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6040 typ = MatrixType::Full;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
6041 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6042 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6043
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6044 if (typ == MatrixType::Full)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6045 {
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21723
diff changeset
6046 #if defined (HAVE_UMFPACK)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6047 Matrix Control, Info;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
6048 void *Numeric = factorize (err, rcond, Control, Info,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6049 sing_handler, calc_cond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6050
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6051 if (err == 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6052 {
24961
ed8090ee632c Make only one iterative refinement after solving sparse systems (bug #53140).
Marco Caliari <marco.caliari@univr.it>
parents: 24797
diff changeset
6053 // one iterative refinement instead of the default two in UMFPACK
ed8090ee632c Make only one iterative refinement after solving sparse systems (bug #53140).
Marco Caliari <marco.caliari@univr.it>
parents: 24797
diff changeset
6054 Control (UMFPACK_IRSTEP) = 1;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6055 octave_idx_type b_nr = b.rows ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6056 octave_idx_type b_nc = b.cols ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6057 int status = 0;
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
6058 double *control = Control.rwdata ();
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
6059 double *info = Info.rwdata ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6060 const octave_idx_type *Ap = cidx ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6061 const octave_idx_type *Ai = ridx ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6062 const Complex *Ax = data ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6063
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21723
diff changeset
6064 #if defined (UMFPACK_SEPARATE_SPLIT)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6065 OCTAVE_LOCAL_BUFFER (double, Bx, b_nr);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6066 OCTAVE_LOCAL_BUFFER (double, Bz, b_nr);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6067 for (octave_idx_type i = 0; i < b_nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6068 Bz[i] = 0.;
5203
dbeafbc0ff64 [project @ 2005-03-15 00:58:55 by jwe]
jwe
parents: 5164
diff changeset
6069 #else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6070 OCTAVE_LOCAL_BUFFER (Complex, Bz, b_nr);
5203
dbeafbc0ff64 [project @ 2005-03-15 00:58:55 by jwe]
jwe
parents: 5164
diff changeset
6071 #endif
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6072
18812
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18678
diff changeset
6073 // Take a first guess that the number of nonzero terms
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6074 // will be as many as in b
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6075 octave_idx_type x_nz = b.nnz ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6076 octave_idx_type ii = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6077 retval = SparseComplexMatrix (b_nr, b_nc, x_nz);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6078
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6079 OCTAVE_LOCAL_BUFFER (Complex, Xx, b_nr);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
6080
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
6081 retval.xcidx (0) = 0;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6082 for (octave_idx_type j = 0; j < b_nc; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6083 {
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6084
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21723
diff changeset
6085 #if defined (UMFPACK_SEPARATE_SPLIT)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6086 for (octave_idx_type i = 0; i < b_nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6087 Bx[i] = b.elem (i, j);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6088
23391
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
6089 status = UMFPACK_ZNAME (solve) (UMFPACK_A,
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
6090 octave::to_suitesparse_intptr (Ap),
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
6091 octave::to_suitesparse_intptr (Ai),
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6092 reinterpret_cast<const double *> (Ax),
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6093 nullptr,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6094 reinterpret_cast<double *> (Xx),
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6095 nullptr,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6096 Bx, Bz, Numeric, control,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6097 info);
5203
dbeafbc0ff64 [project @ 2005-03-15 00:58:55 by jwe]
jwe
parents: 5164
diff changeset
6098 #else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6099 for (octave_idx_type i = 0; i < b_nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6100 Bz[i] = b.elem (i, j);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6101
23391
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
6102 status = UMFPACK_ZNAME (solve) (UMFPACK_A,
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
6103 octave::to_suitesparse_intptr (Ap),
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
6104 octave::to_suitesparse_intptr (Ai),
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6105 reinterpret_cast<const double *> (Ax),
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6106 0,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6107 reinterpret_cast<double *> (Xx),
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6108 0,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6109 reinterpret_cast<double *> (Bz),
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6110 0,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6111 Numeric, control,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6112 info);
5203
dbeafbc0ff64 [project @ 2005-03-15 00:58:55 by jwe]
jwe
parents: 5164
diff changeset
6113 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6114 if (status < 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6115 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
6116 UMFPACK_ZNAME (report_status) (control, status);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
6117
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
6118 // FIXME: Should this be a warning?
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
6119 (*current_liboctave_error_handler)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6120 ("SparseComplexMatrix::solve solve failed");
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6121
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6122 err = -1;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6123 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6124 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6125
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6126 for (octave_idx_type i = 0; i < b_nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6127 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6128 Complex tmp = Xx[i];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6129 if (tmp != 0.0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6130 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6131 if (ii == x_nz)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6132 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6133 // Resize the sparse matrix
24796
d3a79cb734d2 Fix performance of Sparse fsolve for complex sparse matrices (bug #53140).
Rik <rik@octave.org>
parents: 24255
diff changeset
6134 octave_idx_type sz;
d3a79cb734d2 Fix performance of Sparse fsolve for complex sparse matrices (bug #53140).
Rik <rik@octave.org>
parents: 24255
diff changeset
6135 sz = (static_cast<double> (b_nc) - j) / b_nc
d3a79cb734d2 Fix performance of Sparse fsolve for complex sparse matrices (bug #53140).
Rik <rik@octave.org>
parents: 24255
diff changeset
6136 * x_nz;
d3a79cb734d2 Fix performance of Sparse fsolve for complex sparse matrices (bug #53140).
Rik <rik@octave.org>
parents: 24255
diff changeset
6137 sz = x_nz + (sz > 100 ? sz : 100);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6138 retval.change_capacity (sz);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6139 x_nz = sz;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6140 }
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
6141 retval.xdata (ii) = tmp;
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
6142 retval.xridx (ii++) = i;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6143 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6144 }
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
6145 retval.xcidx (j+1) = ii;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6146 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6147
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6148 retval.maybe_compress ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6149
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6150 UMFPACK_ZNAME (report_info) (control, info);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6151
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6152 UMFPACK_ZNAME (free_numeric) (&Numeric);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6153 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6154 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6155 mattype.mark_as_rectangular ();
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6156
5203
dbeafbc0ff64 [project @ 2005-03-15 00:58:55 by jwe]
jwe
parents: 5164
diff changeset
6157 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
6158 octave_unused_parameter (rcond);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
6159 octave_unused_parameter (sing_handler);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
6160 octave_unused_parameter (calc_cond);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
6161
21109
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
6162 (*current_liboctave_error_handler)
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
6163 ("support for UMFPACK was unavailable or disabled "
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
6164 "when liboctave was built");
5203
dbeafbc0ff64 [project @ 2005-03-15 00:58:55 by jwe]
jwe
parents: 5164
diff changeset
6165 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6166 }
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6167 else if (typ != MatrixType::Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6168 (*current_liboctave_error_handler) ("incorrect matrix type");
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6169 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
6170
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6171 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6172 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6173
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6174 ComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6175 SparseComplexMatrix::fsolve (MatrixType& mattype, const ComplexMatrix& b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6176 octave_idx_type& err, double& rcond,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6177 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6178 bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6179 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6180 ComplexMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6181
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
6182 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
6183 octave_idx_type nc = cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6184 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6185
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
6186 if (nr != nc || nr != b.rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6187 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6188 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
6189
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
6190 if (nr == 0 || b.cols () == 0)
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
6191 retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6192 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6193 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6194 // Print spparms("spumoni") info if requested
33037
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
6195 int typ = mattype.type ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6196 mattype.info ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6197
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6198 if (typ == MatrixType::Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6199 {
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21723
diff changeset
6200 #if defined (HAVE_CHOLMOD)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6201 cholmod_common Common;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6202 cholmod_common *cm = &Common;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6203
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6204 // Setup initial parameters
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6205 CHOLMOD_NAME(start) (cm);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6206 cm->prefer_zomplex = false;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6207
29872
df2cdf42a909 update coding style for octave_sparse_params class
John W. Eaton <jwe@octave.org>
parents: 29399
diff changeset
6208 double spu = octave::sparse_params::get_key ("spumoni");
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6209 if (spu == 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6210 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6211 cm->print = -1;
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23708
diff changeset
6212 SUITESPARSE_ASSIGN_FPTR (printf_func, cm->print_function, nullptr);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6213 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6214 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6215 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6216 cm->print = static_cast<int> (spu) + 2;
19139
afd6179d2616 allow building with new version of SuiteSparse (bug #43063)
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
6217 SUITESPARSE_ASSIGN_FPTR (printf_func, cm->print_function, &SparseCholPrint);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6218 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6219
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6220 cm->error_handler = &SparseCholError;
19139
afd6179d2616 allow building with new version of SuiteSparse (bug #43063)
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
6221 SUITESPARSE_ASSIGN_FPTR2 (divcomplex_func, cm->complex_divide, divcomplex);
afd6179d2616 allow building with new version of SuiteSparse (bug #43063)
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
6222 SUITESPARSE_ASSIGN_FPTR2 (hypot_func, cm->hypotenuse, hypot);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6223
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6224 cm->final_ll = true;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6225
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6226 cholmod_sparse Astore;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6227 cholmod_sparse *A = &Astore;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6228 A->nrow = nr;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6229 A->ncol = nc;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6230
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
6231 A->p = cidx ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
6232 A->i = ridx ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
6233 A->nzmax = nnz ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6234 A->packed = true;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6235 A->sorted = true;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6236 A->nz = nullptr;
21229
a83e7a384ee0 create and install a subset of config.h in octave-config.h
John W. Eaton <jwe@octave.org>
parents: 21219
diff changeset
6237 #if defined (OCTAVE_ENABLE_64)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6238 A->itype = CHOLMOD_LONG;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
6239 #else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6240 A->itype = CHOLMOD_INT;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
6241 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6242 A->dtype = CHOLMOD_DOUBLE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6243 A->stype = 1;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6244 A->xtype = CHOLMOD_COMPLEX;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6245
24255
4283c4c2fcb6 Fix segfault with CHOLMOD library and empty matrices (bug #52365).
Rik <rik@octave.org>
parents: 23219
diff changeset
6246 A->x = data ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6247
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6248 cholmod_dense Bstore;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6249 cholmod_dense *B = &Bstore;
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
6250 B->nrow = b.rows ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
6251 B->ncol = b.cols ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6252 B->d = B->nrow;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6253 B->nzmax = B->nrow * B->ncol;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6254 B->dtype = CHOLMOD_DOUBLE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6255 B->xtype = CHOLMOD_COMPLEX;
24255
4283c4c2fcb6 Fix segfault with CHOLMOD library and empty matrices (bug #52365).
Rik <rik@octave.org>
parents: 23219
diff changeset
6256
29931
7faff48840eb prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents: 29872
diff changeset
6257 B->x = const_cast<Complex *> (b.data ());
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6258
29399
019130bd4a3d eliminate last uses of BEGIN/END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
6259 cholmod_factor *L = CHOLMOD_NAME(analyze) (A, cm);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6260 CHOLMOD_NAME(factorize) (A, L, cm);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6261 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6262 rcond = CHOLMOD_NAME(rcond)(L, cm);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6263 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6264 rcond = 1.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6265
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6266 if (rcond == 0.0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6267 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
6268 // Either its indefinite or singular. Try UMFPACK
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6269 mattype.mark_as_unsymmetric ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6270 typ = MatrixType::Full;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6271 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6272 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6273 {
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
6274 if (is_singular (rcond) || octave::math::isnan (rcond))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6275 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6276 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6277
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6278 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6279 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6280 sing_handler (rcond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6281 mattype.mark_as_rectangular ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6282 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6283 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
6284 octave::warn_singular_matrix (rcond);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
6285
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6286 return retval;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6287 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6288
29399
019130bd4a3d eliminate last uses of BEGIN/END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
6289 cholmod_dense *X = CHOLMOD_NAME(solve) (CHOLMOD_A, L, B, cm);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6290
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
6291 retval.resize (b.rows (), b.cols ());
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
6292 for (octave_idx_type j = 0; j < b.cols (); j++)
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
6293 {
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
6294 octave_idx_type jr = j * b.rows ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
6295 for (octave_idx_type i = 0; i < b.rows (); i++)
32513
1de97b475564 maint: Add space " " between C++ cast and argument.
Markus Mützel <markus.muetzel@gmx.de>
parents: 32290
diff changeset
6296 retval.xelem (i, j) = static_cast<Complex *> (X->x)[jr + i];
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6297 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6298
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6299 CHOLMOD_NAME(free_dense) (&X, cm);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6300 CHOLMOD_NAME(free_factor) (&L, cm);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6301 CHOLMOD_NAME(finish) (cm);
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23796
diff changeset
6302 static char blank_name[] = " ";
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23796
diff changeset
6303 CHOLMOD_NAME(print_common) (blank_name, cm);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6304 }
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
6305 #else
19410
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 19408
diff changeset
6306 (*current_liboctave_warning_with_id_handler)
21109
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
6307 ("Octave:missing-dependency",
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
6308 "support for CHOLMOD was unavailable or disabled "
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
6309 "when liboctave was built");
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6310
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6311 mattype.mark_as_unsymmetric ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6312 typ = MatrixType::Full;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
6313 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6314 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6315
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6316 if (typ == MatrixType::Full)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6317 {
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21723
diff changeset
6318 #if defined (HAVE_UMFPACK)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6319 Matrix Control, Info;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6320 void *Numeric = factorize (err, rcond, Control, Info,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6321 sing_handler, calc_cond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6322
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6323 if (err == 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6324 {
24961
ed8090ee632c Make only one iterative refinement after solving sparse systems (bug #53140).
Marco Caliari <marco.caliari@univr.it>
parents: 24797
diff changeset
6325 // one iterative refinement instead of the default two in UMFPACK
ed8090ee632c Make only one iterative refinement after solving sparse systems (bug #53140).
Marco Caliari <marco.caliari@univr.it>
parents: 24797
diff changeset
6326 Control (UMFPACK_IRSTEP) = 1;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6327 octave_idx_type b_nr = b.rows ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6328 octave_idx_type b_nc = b.cols ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6329 int status = 0;
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
6330 double *control = Control.rwdata ();
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
6331 double *info = Info.rwdata ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6332 const octave_idx_type *Ap = cidx ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6333 const octave_idx_type *Ai = ridx ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6334 const Complex *Ax = data ();
29931
7faff48840eb prefer data over fortran_vec for read-only access to data
John W. Eaton <jwe@octave.org>
parents: 29872
diff changeset
6335 const Complex *Bx = b.data ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6336
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6337 retval.resize (b_nr, b_nc);
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
6338 Complex *Xx = retval.rwdata ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
6339
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6340 for (octave_idx_type j = 0, iidx = 0; j < b_nc; j++, iidx += b_nr)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6341 {
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27180
diff changeset
6342 status
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27180
diff changeset
6343 = UMFPACK_ZNAME (solve) (UMFPACK_A,
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27180
diff changeset
6344 octave::to_suitesparse_intptr (Ap),
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27180
diff changeset
6345 octave::to_suitesparse_intptr (Ai),
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27180
diff changeset
6346 reinterpret_cast<const double *> (Ax),
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27180
diff changeset
6347 nullptr,
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27180
diff changeset
6348 reinterpret_cast<double *> (&Xx[iidx]),
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27180
diff changeset
6349 nullptr,
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27180
diff changeset
6350 reinterpret_cast<const double *> (&Bx[iidx]),
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27180
diff changeset
6351 nullptr, Numeric, control, info);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
6352
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6353 if (status < 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6354 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
6355 UMFPACK_ZNAME (report_status) (control, status);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
6356
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
6357 // FIXME: Should this be a warning?
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
6358 (*current_liboctave_error_handler)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6359 ("SparseComplexMatrix::solve solve failed");
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6360
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6361 err = -1;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6362 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6363 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6364 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6365
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6366 UMFPACK_ZNAME (report_info) (control, info);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6367
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6368 UMFPACK_ZNAME (free_numeric) (&Numeric);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6369 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6370 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6371 mattype.mark_as_rectangular ();
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6372
5203
dbeafbc0ff64 [project @ 2005-03-15 00:58:55 by jwe]
jwe
parents: 5164
diff changeset
6373 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
6374 octave_unused_parameter (rcond);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
6375 octave_unused_parameter (sing_handler);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
6376 octave_unused_parameter (calc_cond);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
6377
21109
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
6378 (*current_liboctave_error_handler)
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
6379 ("support for UMFPACK was unavailable or disabled "
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
6380 "when liboctave was built");
5203
dbeafbc0ff64 [project @ 2005-03-15 00:58:55 by jwe]
jwe
parents: 5164
diff changeset
6381 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6382 }
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6383 else if (typ != MatrixType::Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6384 (*current_liboctave_error_handler) ("incorrect matrix type");
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6385 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
6386
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6387 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6388 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6389
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6390 SparseComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6391 SparseComplexMatrix::fsolve (MatrixType& mattype, const SparseComplexMatrix& b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6392 octave_idx_type& err, double& rcond,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6393 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6394 bool calc_cond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6395 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6396 SparseComplexMatrix retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6397
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
6398 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
6399 octave_idx_type nc = cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6400 err = 0;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6401
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
6402 if (nr != nc || nr != b.rows ())
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6403 (*current_liboctave_error_handler)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6404 ("matrix dimension mismatch solution of linear equations");
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
6405
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
6406 if (nr == 0 || b.cols () == 0)
6924
be176b7e110a [project @ 2007-09-25 19:08:19 by dbateman]
dbateman
parents: 6840
diff changeset
6407 retval = SparseComplexMatrix (nc, b.cols ());
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6408 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6409 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6410 // Print spparms("spumoni") info if requested
33037
7d5a531a058a eliminate obsolete volatile declarations on integer variables (bug #65321)
John W. Eaton <jwe@octave.org>
parents: 32723
diff changeset
6411 int typ = mattype.type ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6412 mattype.info ();
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6413
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6414 if (typ == MatrixType::Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6415 {
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21723
diff changeset
6416 #if defined (HAVE_CHOLMOD)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6417 cholmod_common Common;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6418 cholmod_common *cm = &Common;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6419
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6420 // Setup initial parameters
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6421 CHOLMOD_NAME(start) (cm);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6422 cm->prefer_zomplex = false;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6423
29872
df2cdf42a909 update coding style for octave_sparse_params class
John W. Eaton <jwe@octave.org>
parents: 29399
diff changeset
6424 double spu = octave::sparse_params::get_key ("spumoni");
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6425 if (spu == 0.)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6426 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6427 cm->print = -1;
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23708
diff changeset
6428 SUITESPARSE_ASSIGN_FPTR (printf_func, cm->print_function, nullptr);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6429 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6430 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6431 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6432 cm->print = static_cast<int> (spu) + 2;
19139
afd6179d2616 allow building with new version of SuiteSparse (bug #43063)
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
6433 SUITESPARSE_ASSIGN_FPTR (printf_func, cm->print_function, &SparseCholPrint);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6434 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6435
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6436 cm->error_handler = &SparseCholError;
19139
afd6179d2616 allow building with new version of SuiteSparse (bug #43063)
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
6437 SUITESPARSE_ASSIGN_FPTR2 (divcomplex_func, cm->complex_divide, divcomplex);
afd6179d2616 allow building with new version of SuiteSparse (bug #43063)
John W. Eaton <jwe@octave.org>
parents: 18812
diff changeset
6438 SUITESPARSE_ASSIGN_FPTR2 (hypot_func, cm->hypotenuse, hypot);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6439
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6440 cm->final_ll = true;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6441
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6442 cholmod_sparse Astore;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6443 cholmod_sparse *A = &Astore;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6444 A->nrow = nr;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6445 A->ncol = nc;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6446
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
6447 A->p = cidx ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
6448 A->i = ridx ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
6449 A->nzmax = nnz ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6450 A->packed = true;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6451 A->sorted = true;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6452 A->nz = nullptr;
21229
a83e7a384ee0 create and install a subset of config.h in octave-config.h
John W. Eaton <jwe@octave.org>
parents: 21219
diff changeset
6453 #if defined (OCTAVE_ENABLE_64)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6454 A->itype = CHOLMOD_LONG;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
6455 #else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6456 A->itype = CHOLMOD_INT;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
6457 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6458 A->dtype = CHOLMOD_DOUBLE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6459 A->stype = 1;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6460 A->xtype = CHOLMOD_COMPLEX;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6461
24255
4283c4c2fcb6 Fix segfault with CHOLMOD library and empty matrices (bug #52365).
Rik <rik@octave.org>
parents: 23219
diff changeset
6462 A->x = data ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6463
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6464 cholmod_sparse Bstore;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6465 cholmod_sparse *B = &Bstore;
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
6466 B->nrow = b.rows ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
6467 B->ncol = b.cols ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
6468 B->p = b.cidx ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
6469 B->i = b.ridx ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
6470 B->nzmax = b.nnz ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6471 B->packed = true;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6472 B->sorted = true;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6473 B->nz = nullptr;
21229
a83e7a384ee0 create and install a subset of config.h in octave-config.h
John W. Eaton <jwe@octave.org>
parents: 21219
diff changeset
6474 #if defined (OCTAVE_ENABLE_64)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6475 B->itype = CHOLMOD_LONG;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
6476 #else
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6477 B->itype = CHOLMOD_INT;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
6478 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6479 B->dtype = CHOLMOD_DOUBLE;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6480 B->stype = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6481 B->xtype = CHOLMOD_COMPLEX;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6482
24255
4283c4c2fcb6 Fix segfault with CHOLMOD library and empty matrices (bug #52365).
Rik <rik@octave.org>
parents: 23219
diff changeset
6483 B->x = b.data ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6484
29399
019130bd4a3d eliminate last uses of BEGIN/END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
6485 cholmod_factor *L = CHOLMOD_NAME(analyze) (A, cm);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6486 CHOLMOD_NAME(factorize) (A, L, cm);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6487 if (calc_cond)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6488 rcond = CHOLMOD_NAME(rcond)(L, cm);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6489 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6490 rcond = 1.;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6491
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6492 if (rcond == 0.0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6493 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
6494 // Either its indefinite or singular. Try UMFPACK
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6495 mattype.mark_as_unsymmetric ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6496 typ = MatrixType::Full;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6497 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6498 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6499 {
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
6500 if (is_singular (rcond) || octave::math::isnan (rcond))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6501 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6502 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6503
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6504 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6505 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6506 sing_handler (rcond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6507 mattype.mark_as_rectangular ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6508 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6509 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
6510 octave::warn_singular_matrix (rcond);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
6511
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6512 return retval;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6513 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6514
29399
019130bd4a3d eliminate last uses of BEGIN/END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
6515 cholmod_sparse *X = CHOLMOD_NAME(spsolve) (CHOLMOD_A, L, B, cm);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6516
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
6517 retval = SparseComplexMatrix
32290
a81a6fb82c0e Check for integer overflow when copying sizes from SuiteSparse matrices.
Markus Mützel <markus.muetzel@gmx.de>
parents: 32288
diff changeset
6518 (octave::from_size_t (X->nrow),
a81a6fb82c0e Check for integer overflow when copying sizes from SuiteSparse matrices.
Markus Mützel <markus.muetzel@gmx.de>
parents: 32288
diff changeset
6519 octave::from_size_t (X->ncol),
32287
dde186dc7b4c Fix getting number of non-zero elements in SuiteSparse matrices.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
6520 octave::from_suitesparse_long (CHOLMOD_NAME(nnz)
dde186dc7b4c Fix getting number of non-zero elements in SuiteSparse matrices.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
6521 (X, cm)));
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
6522 for (octave_idx_type j = 0;
25688
b2917b7858ba maint: Use Octave convention for spacing of C++ cast statements.
Rik <rik@octave.org>
parents: 25665
diff changeset
6523 j <= static_cast<octave_idx_type> (X->ncol); j++)
32513
1de97b475564 maint: Add space " " between C++ cast and argument.
Markus Mützel <markus.muetzel@gmx.de>
parents: 32290
diff changeset
6524 retval.xcidx (j) = static_cast<octave_idx_type *> (X->p)[j];
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
6525 for (octave_idx_type j = 0;
32287
dde186dc7b4c Fix getting number of non-zero elements in SuiteSparse matrices.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
6526 j < octave::from_suitesparse_long (CHOLMOD_NAME(nnz) (X, cm));
dde186dc7b4c Fix getting number of non-zero elements in SuiteSparse matrices.
Markus Mützel <markus.muetzel@gmx.de>
parents: 31706
diff changeset
6527 j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6528 {
32513
1de97b475564 maint: Add space " " between C++ cast and argument.
Markus Mützel <markus.muetzel@gmx.de>
parents: 32290
diff changeset
6529 retval.xridx (j) = static_cast<octave_idx_type *> (X->i)[j];
1de97b475564 maint: Add space " " between C++ cast and argument.
Markus Mützel <markus.muetzel@gmx.de>
parents: 32290
diff changeset
6530 retval.xdata (j) = static_cast<Complex *> (X->x)[j];
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6531 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6532
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6533 CHOLMOD_NAME(free_sparse) (&X, cm);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6534 CHOLMOD_NAME(free_factor) (&L, cm);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6535 CHOLMOD_NAME(finish) (cm);
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23796
diff changeset
6536 static char blank_name[] = " ";
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23796
diff changeset
6537 CHOLMOD_NAME(print_common) (blank_name, cm);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6538 }
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
6539 #else
19410
95c533ed464b use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents: 19408
diff changeset
6540 (*current_liboctave_warning_with_id_handler)
21109
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
6541 ("Octave:missing-dependency",
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
6542 "support for CHOLMOD was unavailable or disabled "
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
6543 "when liboctave was built");
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6544
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6545 mattype.mark_as_unsymmetric ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6546 typ = MatrixType::Full;
5506
b4cfbb0ec8c4 [project @ 2005-10-23 19:09:32 by dbateman]
dbateman
parents: 5451
diff changeset
6547 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6548 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6549
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6550 if (typ == MatrixType::Full)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6551 {
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21723
diff changeset
6552 #if defined (HAVE_UMFPACK)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6553 Matrix Control, Info;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6554 void *Numeric = factorize (err, rcond, Control, Info,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6555 sing_handler, calc_cond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6556
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6557 if (err == 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6558 {
24961
ed8090ee632c Make only one iterative refinement after solving sparse systems (bug #53140).
Marco Caliari <marco.caliari@univr.it>
parents: 24797
diff changeset
6559 // one iterative refinement instead of the default two in UMFPACK
ed8090ee632c Make only one iterative refinement after solving sparse systems (bug #53140).
Marco Caliari <marco.caliari@univr.it>
parents: 24797
diff changeset
6560 Control (UMFPACK_IRSTEP) = 1;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6561 octave_idx_type b_nr = b.rows ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6562 octave_idx_type b_nc = b.cols ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6563 int status = 0;
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
6564 double *control = Control.rwdata ();
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
6565 double *info = Info.rwdata ();
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6566 const octave_idx_type *Ap = cidx ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6567 const octave_idx_type *Ai = ridx ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6568 const Complex *Ax = data ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6569
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6570 OCTAVE_LOCAL_BUFFER (Complex, Bx, b_nr);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6571
18812
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18678
diff changeset
6572 // Take a first guess that the number of nonzero terms
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6573 // will be as many as in b
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6574 octave_idx_type x_nz = b.nnz ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6575 octave_idx_type ii = 0;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6576 retval = SparseComplexMatrix (b_nr, b_nc, x_nz);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6577
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6578 OCTAVE_LOCAL_BUFFER (Complex, Xx, b_nr);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
6579
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
6580 retval.xcidx (0) = 0;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6581 for (octave_idx_type j = 0; j < b_nc; j++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6582 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6583 for (octave_idx_type i = 0; i < b_nr; i++)
30394
f3f3e3793fb5 maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29937
diff changeset
6584 Bx[i] = b(i, j);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6585
23391
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
6586 status = UMFPACK_ZNAME (solve) (UMFPACK_A,
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
6587 octave::to_suitesparse_intptr (Ap),
209e749363a2 safe cast between SuiteSparse_long and octave_idx_type pointers (bug #50510)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
6588 octave::to_suitesparse_intptr (Ai),
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6589 reinterpret_cast<const double *> (Ax),
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6590 nullptr,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6591 reinterpret_cast<double *> (Xx),
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6592 nullptr,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6593 reinterpret_cast<double *> (Bx),
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6594 nullptr, Numeric, control, info);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
6595
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6596 if (status < 0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6597 {
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
6598 UMFPACK_ZNAME (report_status) (control, status);
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
6599
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
6600 // FIXME: Should this be a warning?
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
6601 (*current_liboctave_error_handler)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6602 ("SparseComplexMatrix::solve solve failed");
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6603
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6604 err = -1;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6605 break;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6606 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6607
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6608 for (octave_idx_type i = 0; i < b_nr; i++)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6609 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6610 Complex tmp = Xx[i];
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6611 if (tmp != 0.0)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6612 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6613 if (ii == x_nz)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6614 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6615 // Resize the sparse matrix
24796
d3a79cb734d2 Fix performance of Sparse fsolve for complex sparse matrices (bug #53140).
Rik <rik@octave.org>
parents: 24255
diff changeset
6616 octave_idx_type sz;
d3a79cb734d2 Fix performance of Sparse fsolve for complex sparse matrices (bug #53140).
Rik <rik@octave.org>
parents: 24255
diff changeset
6617 sz = (static_cast<double> (b_nc) - j) / b_nc
d3a79cb734d2 Fix performance of Sparse fsolve for complex sparse matrices (bug #53140).
Rik <rik@octave.org>
parents: 24255
diff changeset
6618 * x_nz;
d3a79cb734d2 Fix performance of Sparse fsolve for complex sparse matrices (bug #53140).
Rik <rik@octave.org>
parents: 24255
diff changeset
6619 sz = x_nz + (sz > 100 ? sz : 100);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6620 retval.change_capacity (sz);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6621 x_nz = sz;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6622 }
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
6623 retval.xdata (ii) = tmp;
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
6624 retval.xridx (ii++) = i;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6625 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6626 }
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
6627 retval.xcidx (j+1) = ii;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6628 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6629
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6630 retval.maybe_compress ();
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6631
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6632 rcond = Info (UMFPACK_RCOND);
19864
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
6633 if (status == UMFPACK_WARNING_singular_matrix
33203
371217bc9733 Replace obscure Fortran coding pattern in liboctave with modern C++ (bug #65343)
Rik <rik@octave.org>
parents: 33062
diff changeset
6634 || is_singular (rcond) || octave::math::isnan (rcond))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6635 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6636 err = -2;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6637
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6638 if (sing_handler)
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6639 sing_handler (rcond);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6640 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
6641 octave::warn_singular_matrix (rcond);
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6642 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6643
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6644 UMFPACK_ZNAME (report_info) (control, info);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6645
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6646 UMFPACK_ZNAME (free_numeric) (&Numeric);
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6647 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6648 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6649 mattype.mark_as_rectangular ();
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6650
5203
dbeafbc0ff64 [project @ 2005-03-15 00:58:55 by jwe]
jwe
parents: 5164
diff changeset
6651 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
6652 octave_unused_parameter (rcond);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
6653 octave_unused_parameter (sing_handler);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
6654 octave_unused_parameter (calc_cond);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
6655
21109
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
6656 (*current_liboctave_error_handler)
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
6657 ("support for UMFPACK was unavailable or disabled "
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 21100
diff changeset
6658 "when liboctave was built");
5203
dbeafbc0ff64 [project @ 2005-03-15 00:58:55 by jwe]
jwe
parents: 5164
diff changeset
6659 #endif
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6660 }
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6661 else if (typ != MatrixType::Hermitian)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6662 (*current_liboctave_error_handler) ("incorrect matrix type");
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6663 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
6664
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6665 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6666 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6667
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6668 ComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6669 SparseComplexMatrix::solve (MatrixType& mattype, const Matrix& b) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6670 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
6671 octave_idx_type info;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6672 double rcond;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6673 return solve (mattype, b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6674 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6675
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6676 ComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6677 SparseComplexMatrix::solve (MatrixType& mattype, const Matrix& b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6678 octave_idx_type& info) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6679 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6680 double rcond;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6681 return solve (mattype, b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6682 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6683
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6684 ComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6685 SparseComplexMatrix::solve (MatrixType& mattype, const Matrix& b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6686 octave_idx_type& info, double& rcond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6687 {
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6688 return solve (mattype, b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6689 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6690
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6691 ComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6692 SparseComplexMatrix::solve (MatrixType& mattype, const Matrix& b,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
6693 octave_idx_type& err, double& rcond,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6694 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6695 bool singular_fallback) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6696 {
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6697 ComplexMatrix retval;
5322
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5307
diff changeset
6698 int typ = mattype.type (false);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6699
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6700 if (typ == MatrixType::Unknown)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6701 typ = mattype.type (*this);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6702
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6703 if (typ == MatrixType::Diagonal || typ == MatrixType::Permuted_Diagonal)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6704 retval = dsolve (mattype, b, err, rcond, sing_handler, false);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6705 else if (typ == MatrixType::Upper || typ == MatrixType::Permuted_Upper)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6706 retval = utsolve (mattype, b, err, rcond, sing_handler, false);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6707 else if (typ == MatrixType::Lower || typ == MatrixType::Permuted_Lower)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6708 retval = ltsolve (mattype, b, err, rcond, sing_handler, false);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6709 else if (typ == MatrixType::Banded || typ == MatrixType::Banded_Hermitian)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6710 retval = bsolve (mattype, b, err, rcond, sing_handler, false);
19864
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
6711 else if (typ == MatrixType::Tridiagonal
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
6712 || typ == MatrixType::Tridiagonal_Hermitian)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6713 retval = trisolve (mattype, b, err, rcond, sing_handler, false);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6714 else if (typ == MatrixType::Full || typ == MatrixType::Hermitian)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6715 retval = fsolve (mattype, b, err, rcond, sing_handler, true);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6716 else if (typ != MatrixType::Rectangular)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
6717 (*current_liboctave_error_handler) ("unknown matrix type");
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6718
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
6719 if (singular_fallback && mattype.type (false) == MatrixType::Rectangular)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6720 {
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6721 rcond = 1.;
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6722 retval = dmsolve<ComplexMatrix, SparseComplexMatrix, Matrix>
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6723 (*this, b, err);
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6724 }
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6725
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6726 return retval;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6727 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6728
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6729 SparseComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6730 SparseComplexMatrix::solve (MatrixType& mattype, const SparseMatrix& b) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6731 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
6732 octave_idx_type info;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6733 double rcond;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6734 return solve (mattype, b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6735 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6736
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6737 SparseComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6738 SparseComplexMatrix::solve (MatrixType& mattype, const SparseMatrix& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6739 octave_idx_type& info) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6740 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6741 double rcond;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6742 return solve (mattype, b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6743 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6744
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6745 SparseComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6746 SparseComplexMatrix::solve (MatrixType& mattype, const SparseMatrix& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6747 octave_idx_type& info, double& rcond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6748 {
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6749 return solve (mattype, b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6750 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6751
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6752 SparseComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6753 SparseComplexMatrix::solve (MatrixType& mattype, const SparseMatrix& b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6754 octave_idx_type& err, double& rcond,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6755 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6756 bool singular_fallback) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6757 {
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6758 SparseComplexMatrix retval;
5322
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5307
diff changeset
6759 int typ = mattype.type (false);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6760
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6761 if (typ == MatrixType::Unknown)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6762 typ = mattype.type (*this);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6763
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6764 if (typ == MatrixType::Diagonal || typ == MatrixType::Permuted_Diagonal)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6765 retval = dsolve (mattype, b, err, rcond, sing_handler, false);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6766 else if (typ == MatrixType::Upper || typ == MatrixType::Permuted_Upper)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6767 retval = utsolve (mattype, b, err, rcond, sing_handler, false);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6768 else if (typ == MatrixType::Lower || typ == MatrixType::Permuted_Lower)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6769 retval = ltsolve (mattype, b, err, rcond, sing_handler, false);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6770 else if (typ == MatrixType::Banded || typ == MatrixType::Banded_Hermitian)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6771 retval = bsolve (mattype, b, err, rcond, sing_handler, false);
19864
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
6772 else if (typ == MatrixType::Tridiagonal
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
6773 || typ == MatrixType::Tridiagonal_Hermitian)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6774 retval = trisolve (mattype, b, err, rcond, sing_handler, false);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6775 else if (typ == MatrixType::Full || typ == MatrixType::Hermitian)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6776 retval = fsolve (mattype, b, err, rcond, sing_handler, true);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6777 else if (typ != MatrixType::Rectangular)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
6778 (*current_liboctave_error_handler) ("unknown matrix type");
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6779
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
6780 if (singular_fallback && mattype.type (false) == MatrixType::Rectangular)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6781 {
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6782 rcond = 1.;
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6783 retval = dmsolve<SparseComplexMatrix, SparseComplexMatrix, SparseMatrix>
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6784 (*this, b, err);
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6785 }
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6786
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6787 return retval;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6788 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6789
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6790 ComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6791 SparseComplexMatrix::solve (MatrixType& mattype, const ComplexMatrix& b) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6792 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
6793 octave_idx_type info;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6794 double rcond;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6795 return solve (mattype, b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6796 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6797
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6798 ComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6799 SparseComplexMatrix::solve (MatrixType& mattype, const ComplexMatrix& b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6800 octave_idx_type& info) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6801 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6802 double rcond;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6803 return solve (mattype, b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6804 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6805
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6806 ComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6807 SparseComplexMatrix::solve (MatrixType& mattype, const ComplexMatrix& b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6808 octave_idx_type& info, double& rcond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6809 {
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6810 return solve (mattype, b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6811 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6812
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6813 ComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6814 SparseComplexMatrix::solve (MatrixType& mattype, const ComplexMatrix& b,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
6815 octave_idx_type& err, double& rcond,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6816 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6817 bool singular_fallback) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6818 {
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6819 ComplexMatrix retval;
5322
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5307
diff changeset
6820 int typ = mattype.type (false);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6821
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6822 if (typ == MatrixType::Unknown)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6823 typ = mattype.type (*this);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6824
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6825 if (typ == MatrixType::Diagonal || typ == MatrixType::Permuted_Diagonal)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6826 retval = dsolve (mattype, b, err, rcond, sing_handler, false);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6827 else if (typ == MatrixType::Upper || typ == MatrixType::Permuted_Upper)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6828 retval = utsolve (mattype, b, err, rcond, sing_handler, false);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6829 else if (typ == MatrixType::Lower || typ == MatrixType::Permuted_Lower)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6830 retval = ltsolve (mattype, b, err, rcond, sing_handler, false);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6831 else if (typ == MatrixType::Banded || typ == MatrixType::Banded_Hermitian)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6832 retval = bsolve (mattype, b, err, rcond, sing_handler, false);
19864
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
6833 else if (typ == MatrixType::Tridiagonal
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
6834 || typ == MatrixType::Tridiagonal_Hermitian)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6835 retval = trisolve (mattype, b, err, rcond, sing_handler, false);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6836 else if (typ == MatrixType::Full || typ == MatrixType::Hermitian)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6837 retval = fsolve (mattype, b, err, rcond, sing_handler, true);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6838 else if (typ != MatrixType::Rectangular)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
6839 (*current_liboctave_error_handler) ("unknown matrix type");
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6840
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
6841 if (singular_fallback && mattype.type (false) == MatrixType::Rectangular)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6842 {
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6843 rcond = 1.;
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6844 retval = dmsolve<ComplexMatrix, SparseComplexMatrix, ComplexMatrix>
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6845 (*this, b, err);
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6846 }
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6847
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6848 return retval;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6849 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6850
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6851 SparseComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6852 SparseComplexMatrix::solve (MatrixType& mattype,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6853 const SparseComplexMatrix& b) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6854 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
6855 octave_idx_type info;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6856 double rcond;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6857 return solve (mattype, b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6858 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6859
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6860 SparseComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6861 SparseComplexMatrix::solve (MatrixType& mattype, const SparseComplexMatrix& b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6862 octave_idx_type& info) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6863 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6864 double rcond;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6865 return solve (mattype, b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6866 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6867
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6868 SparseComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6869 SparseComplexMatrix::solve (MatrixType& mattype, const SparseComplexMatrix& b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6870 octave_idx_type& info, double& rcond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6871 {
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6872 return solve (mattype, b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6873 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6874
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6875 SparseComplexMatrix
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6876 SparseComplexMatrix::solve (MatrixType& mattype, const SparseComplexMatrix& b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6877 octave_idx_type& err, double& rcond,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6878 solve_singularity_handler sing_handler,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6879 bool singular_fallback) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6880 {
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6881 SparseComplexMatrix retval;
5322
22994a5730f9 [project @ 2005-04-29 13:04:24 by dbateman]
dbateman
parents: 5307
diff changeset
6882 int typ = mattype.type (false);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6883
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6884 if (typ == MatrixType::Unknown)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6885 typ = mattype.type (*this);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6886
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6887 if (typ == MatrixType::Diagonal || typ == MatrixType::Permuted_Diagonal)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6888 retval = dsolve (mattype, b, err, rcond, sing_handler, false);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6889 else if (typ == MatrixType::Upper || typ == MatrixType::Permuted_Upper)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6890 retval = utsolve (mattype, b, err, rcond, sing_handler, false);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6891 else if (typ == MatrixType::Lower || typ == MatrixType::Permuted_Lower)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6892 retval = ltsolve (mattype, b, err, rcond, sing_handler, false);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6893 else if (typ == MatrixType::Banded || typ == MatrixType::Banded_Hermitian)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6894 retval = bsolve (mattype, b, err, rcond, sing_handler, false);
19864
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
6895 else if (typ == MatrixType::Tridiagonal
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
6896 || typ == MatrixType::Tridiagonal_Hermitian)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6897 retval = trisolve (mattype, b, err, rcond, sing_handler, false);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6898 else if (typ == MatrixType::Full || typ == MatrixType::Hermitian)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6899 retval = fsolve (mattype, b, err, rcond, sing_handler, true);
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
6900 else if (typ != MatrixType::Rectangular)
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 21112
diff changeset
6901 (*current_liboctave_error_handler) ("unknown matrix type");
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6902
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
6903 if (singular_fallback && mattype.type (false) == MatrixType::Rectangular)
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6904 {
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6905 rcond = 1.;
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6906 retval = dmsolve<SparseComplexMatrix, SparseComplexMatrix,
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22327
diff changeset
6907 SparseComplexMatrix> (*this, b, err);
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6908 }
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6909
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
6910 return retval;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6911 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6912
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6913 ComplexColumnVector
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6914 SparseComplexMatrix::solve (MatrixType& mattype, const ColumnVector& b) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6915 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
6916 octave_idx_type info; double rcond;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6917 return solve (mattype, b, info, rcond);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6918 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6919
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6920 ComplexColumnVector
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6921 SparseComplexMatrix::solve (MatrixType& mattype, const ColumnVector& b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6922 octave_idx_type& info) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6923 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6924 double rcond;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6925 return solve (mattype, b, info, rcond);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6926 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6927
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6928 ComplexColumnVector
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6929 SparseComplexMatrix::solve (MatrixType& mattype, const ColumnVector& b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6930 octave_idx_type& info, double& rcond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6931 {
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6932 return solve (mattype, b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6933 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6934
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6935 ComplexColumnVector
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6936 SparseComplexMatrix::solve (MatrixType& mattype, const ColumnVector& b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6937 octave_idx_type& info, double& rcond,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6938 solve_singularity_handler sing_handler) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6939 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6940 Matrix tmp (b);
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6941 return solve (mattype, tmp, info, rcond,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6942 sing_handler).column (static_cast<octave_idx_type> (0));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6943 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6944
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6945 ComplexColumnVector
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6946 SparseComplexMatrix::solve (MatrixType& mattype,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6947 const ComplexColumnVector& b) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6948 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
6949 octave_idx_type info;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6950 double rcond;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6951 return solve (mattype, b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6952 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6953
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6954 ComplexColumnVector
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6955 SparseComplexMatrix::solve (MatrixType& mattype, const ComplexColumnVector& b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6956 octave_idx_type& info) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6957 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6958 double rcond;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6959 return solve (mattype, b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6960 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6961
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6962 ComplexColumnVector
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6963 SparseComplexMatrix::solve (MatrixType& mattype, const ComplexColumnVector& b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6964 octave_idx_type& info, double& rcond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6965 {
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6966 return solve (mattype, b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6967 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6968
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6969 ComplexColumnVector
23433
c9fab0bc983e maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents: 23391
diff changeset
6970 SparseComplexMatrix::solve (MatrixType& mattype, const ComplexColumnVector& b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6971 octave_idx_type& info, double& rcond,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
6972 solve_singularity_handler sing_handler) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6973 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6974 ComplexMatrix tmp (b);
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6975 return solve (mattype, tmp, info, rcond,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6976 sing_handler).column (static_cast<octave_idx_type> (0));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6977 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6978
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6979 ComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6980 SparseComplexMatrix::solve (const Matrix& b) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6981 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
6982 octave_idx_type info;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6983 double rcond;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6984 return solve (b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6985 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6986
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6987 ComplexMatrix
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
6988 SparseComplexMatrix::solve (const Matrix& b, octave_idx_type& info) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6989 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6990 double rcond;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6991 return solve (b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6992 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6993
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6994 ComplexMatrix
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
6995 SparseComplexMatrix::solve (const Matrix& b, octave_idx_type& info,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
6996 double& rcond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6997 {
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
6998 return solve (b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
6999 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7000
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7001 ComplexMatrix
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
7002 SparseComplexMatrix::solve (const Matrix& b, octave_idx_type& err,
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
7003 double& rcond,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7004 solve_singularity_handler sing_handler) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7005 {
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
7006 MatrixType mattype (*this);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7007 return solve (mattype, b, err, rcond, sing_handler);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7008 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7009
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7010 SparseComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7011 SparseComplexMatrix::solve (const SparseMatrix& b) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7012 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7013 octave_idx_type info;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7014 double rcond;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
7015 return solve (b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7016 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7017
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7018 SparseComplexMatrix
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
7019 SparseComplexMatrix::solve (const SparseMatrix& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7020 octave_idx_type& info) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7021 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7022 double rcond;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
7023 return solve (b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7024 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7025
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7026 SparseComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7027 SparseComplexMatrix::solve (const SparseMatrix& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7028 octave_idx_type& info, double& rcond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7029 {
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
7030 return solve (b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7031 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7032
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7033 SparseComplexMatrix
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
7034 SparseComplexMatrix::solve (const SparseMatrix& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7035 octave_idx_type& err, double& rcond,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7036 solve_singularity_handler sing_handler) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7037 {
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
7038 MatrixType mattype (*this);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7039 return solve (mattype, b, err, rcond, sing_handler);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7040 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7041
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7042 ComplexMatrix
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
7043 SparseComplexMatrix::solve (const ComplexMatrix& b,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7044 octave_idx_type& info) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7045 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7046 double rcond;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
7047 return solve (b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7048 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7049
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7050 ComplexMatrix
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
7051 SparseComplexMatrix::solve (const ComplexMatrix& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7052 octave_idx_type& info, double& rcond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7053 {
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
7054 return solve (b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7055 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7056
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7057 ComplexMatrix
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
7058 SparseComplexMatrix::solve (const ComplexMatrix& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7059 octave_idx_type& err, double& rcond,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7060 solve_singularity_handler sing_handler) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7061 {
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
7062 MatrixType mattype (*this);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7063 return solve (mattype, b, err, rcond, sing_handler);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7064 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7065
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7066 SparseComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7067 SparseComplexMatrix::solve (const SparseComplexMatrix& b) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7068 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7069 octave_idx_type info;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7070 double rcond;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
7071 return solve (b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7072 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7073
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7074 SparseComplexMatrix
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
7075 SparseComplexMatrix::solve (const SparseComplexMatrix& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7076 octave_idx_type& info) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7077 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7078 double rcond;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
7079 return solve (b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7080 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7081
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7082 SparseComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7083 SparseComplexMatrix::solve (const SparseComplexMatrix& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7084 octave_idx_type& info, double& rcond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7085 {
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
7086 return solve (b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7087 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7088
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7089 SparseComplexMatrix
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
7090 SparseComplexMatrix::solve (const SparseComplexMatrix& b,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7091 octave_idx_type& err, double& rcond,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7092 solve_singularity_handler sing_handler) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7093 {
5785
6b9cec830d72 [project @ 2006-05-03 19:32:46 by dbateman]
dbateman
parents: 5780
diff changeset
7094 MatrixType mattype (*this);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7095 return solve (mattype, b, err, rcond, sing_handler);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7096 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7097
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7098 ComplexColumnVector
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7099 SparseComplexMatrix::solve (const ColumnVector& b) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7100 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7101 octave_idx_type info; double rcond;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7102 return solve (b, info, rcond);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7103 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7104
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7105 ComplexColumnVector
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7106 SparseComplexMatrix::solve (const ColumnVector& b, octave_idx_type& info) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7107 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7108 double rcond;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7109 return solve (b, info, rcond);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7110 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7111
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7112 ComplexColumnVector
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
7113 SparseComplexMatrix::solve (const ColumnVector& b, octave_idx_type& info,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7114 double& rcond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7115 {
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
7116 return solve (b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7117 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7118
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7119 ComplexColumnVector
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7120 SparseComplexMatrix::solve (const ColumnVector& b, octave_idx_type& info,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7121 double& rcond,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7122 solve_singularity_handler sing_handler) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7123 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7124 Matrix tmp (b);
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7125 return solve (tmp, info, rcond,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7126 sing_handler).column (static_cast<octave_idx_type> (0));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7127 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7128
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7129 ComplexColumnVector
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7130 SparseComplexMatrix::solve (const ComplexColumnVector& b) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7131 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7132 octave_idx_type info;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7133 double rcond;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
7134 return solve (b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7135 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7136
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7137 ComplexColumnVector
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7138 SparseComplexMatrix::solve (const ComplexColumnVector& b,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7139 octave_idx_type& info) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7140 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7141 double rcond;
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
7142 return solve (b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7143 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7144
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7145 ComplexColumnVector
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
7146 SparseComplexMatrix::solve (const ComplexColumnVector& b, octave_idx_type& info,
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7147 double& rcond) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7148 {
23796
4f12819a634f Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23795
diff changeset
7149 return solve (b, info, rcond, nullptr);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7150 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7151
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7152 ComplexColumnVector
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
7153 SparseComplexMatrix::solve (const ComplexColumnVector& b, octave_idx_type& info,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7154 double& rcond,
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7155 solve_singularity_handler sing_handler) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7156 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7157 ComplexMatrix tmp (b);
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7158 return solve (tmp, info, rcond,
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7159 sing_handler).column (static_cast<octave_idx_type> (0));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7160 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7161
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7162 // unary operations
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7163 SparseBoolMatrix
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
7164 SparseComplexMatrix::operator ! () const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7165 {
11130
7c573eb981eb consistently give error for operator not applied to NaN values
John W. Eaton <jwe@octave.org>
parents: 10785
diff changeset
7166 if (any_element_is_nan ())
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
7167 octave::err_nan_to_logical_conversion ();
11130
7c573eb981eb consistently give error for operator not applied to NaN values
John W. Eaton <jwe@octave.org>
parents: 10785
diff changeset
7168
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7169 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7170 octave_idx_type nc = cols ();
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
7171 octave_idx_type nz1 = nnz ();
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7172 octave_idx_type nz2 = nr*nc - nz1;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
7173
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7174 SparseBoolMatrix r (nr, nc, nz2);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
7175
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7176 octave_idx_type ii = 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7177 octave_idx_type jj = 0;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7178 r.cidx (0) = 0;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7179 for (octave_idx_type i = 0; i < nc; i++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7180 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7181 for (octave_idx_type j = 0; j < nr; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7182 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
7183 if (jj < cidx (i+1) && ridx (jj) == j)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7184 jj++;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7185 else
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7186 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
7187 r.data (ii) = true;
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
7188 r.ridx (ii++) = j;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7189 }
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7190 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7191 r.cidx (i+1) = ii;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7192 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7193
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7194 return r;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7195 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7196
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
7197 SparseComplexMatrix
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
7198 SparseComplexMatrix::squeeze () const
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
7199 {
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
7200 return MSparse<Complex>::squeeze ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7201 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7202
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7203 SparseComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7204 SparseComplexMatrix::reshape (const dim_vector& new_dims) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7205 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7206 return MSparse<Complex>::reshape (new_dims);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7207 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7208
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7209 SparseComplexMatrix
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7210 SparseComplexMatrix::permute (const Array<octave_idx_type>& vec, bool inv) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7211 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7212 return MSparse<Complex>::permute (vec, inv);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7213 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7214
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7215 SparseComplexMatrix
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7216 SparseComplexMatrix::ipermute (const Array<octave_idx_type>& vec) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7217 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7218 return MSparse<Complex>::ipermute (vec);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7219 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7220
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7221 // other operations
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7222
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7223 bool
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
7224 SparseComplexMatrix::any_element_is_nan () const
7922
935be827eaf8 error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents: 7802
diff changeset
7225 {
935be827eaf8 error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents: 7802
diff changeset
7226 octave_idx_type nel = nnz ();
935be827eaf8 error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents: 7802
diff changeset
7227
935be827eaf8 error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents: 7802
diff changeset
7228 for (octave_idx_type i = 0; i < nel; i++)
935be827eaf8 error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents: 7802
diff changeset
7229 {
935be827eaf8 error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents: 7802
diff changeset
7230 Complex val = data (i);
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
7231 if (octave::math::isnan (val))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7232 return true;
7922
935be827eaf8 error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents: 7802
diff changeset
7233 }
935be827eaf8 error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents: 7802
diff changeset
7234
935be827eaf8 error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents: 7802
diff changeset
7235 return false;
935be827eaf8 error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents: 7802
diff changeset
7236 }
935be827eaf8 error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents: 7802
diff changeset
7237
935be827eaf8 error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents: 7802
diff changeset
7238 bool
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
7239 SparseComplexMatrix::any_element_is_inf_or_nan () const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7240 {
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
7241 octave_idx_type nel = nnz ();
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7242
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7243 for (octave_idx_type i = 0; i < nel; i++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7244 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7245 Complex val = data (i);
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
7246 if (octave::math::isinf (val) || octave::math::isnan (val))
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7247 return true;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7248 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7249
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7250 return false;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7251 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7252
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7253 // Return true if no elements have imaginary components.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7254
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7255 bool
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
7256 SparseComplexMatrix::all_elements_are_real () const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7257 {
9825
7483fe200fab narrow complex values with negative zero imaginary parts
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
7258 return mx_inline_all_real (nnz (), data ());
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7259 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7260
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7261 // Return nonzero if any element of CM has a non-integer real or
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7262 // imaginary part. Also extract the largest and smallest (real or
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
7263 // imaginary) values and return them in MAX_VAL and MIN_VAL.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7264
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7265 bool
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7266 SparseComplexMatrix::all_integers (double& max_val, double& min_val) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7267 {
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
7268 octave_idx_type nel = nnz ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7269
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7270 if (nel == 0)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7271 return false;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7272
23708
750e42a35adc Use imag, real, arg from std library for Complex types.
Rik <rik@octave.org>
parents: 23594
diff changeset
7273 max_val = std::real (data (0));
750e42a35adc Use imag, real, arg from std library for Complex types.
Rik <rik@octave.org>
parents: 23594
diff changeset
7274 min_val = std::real (data (0));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7275
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7276 for (octave_idx_type i = 0; i < nel; i++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7277 {
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7278 Complex val = data (i);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7279
22274
edcad35c364f don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
7280 double r_val = val.real ();
edcad35c364f don't rely on std:: overloads of arg, conj, imag, and real for real args
John W. Eaton <jwe@octave.org>
parents: 22197
diff changeset
7281 double i_val = val.imag ();
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7282
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7283 if (r_val > max_val)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7284 max_val = r_val;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7285
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7286 if (i_val > max_val)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7287 max_val = i_val;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7288
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7289 if (r_val < min_val)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7290 min_val = r_val;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7291
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7292 if (i_val < min_val)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7293 min_val = i_val;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7294
22402
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22327
diff changeset
7295 if (octave::math::x_nint (r_val) != r_val
4caa7b28d183 maint: Style check C++ code in liboctave/
Rik <rik@octave.org>
parents: 22327
diff changeset
7296 || octave::math::x_nint (i_val) != i_val)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7297 return false;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7298 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7299
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7300 return true;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7301 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7302
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7303 bool
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
7304 SparseComplexMatrix::too_large_for_float () const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7305 {
29937
da7210e30f3e move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29931
diff changeset
7306 return test_any (octave::too_large_for_float);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7307 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7308
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7309 // FIXME: Do these really belong here? Maybe they should be in a base class?
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7310
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7311 SparseBoolMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7312 SparseComplexMatrix::all (int dim) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7313 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7314 SPARSE_ALL_OP (dim);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7315 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7316
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7317 SparseBoolMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7318 SparseComplexMatrix::any (int dim) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7319 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7320 SPARSE_ANY_OP (dim);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7321 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7322
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7323 SparseComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7324 SparseComplexMatrix::cumprod (int dim) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7325 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7326 SPARSE_CUMPROD (SparseComplexMatrix, Complex, cumprod);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7327 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7328
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7329 SparseComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7330 SparseComplexMatrix::cumsum (int dim) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7331 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7332 SPARSE_CUMSUM (SparseComplexMatrix, Complex, cumsum);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7333 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7334
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7335 SparseComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7336 SparseComplexMatrix::prod (int dim) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7337 {
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
7338 if ((rows () == 1 && dim == -1) || dim == 1)
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21724
diff changeset
7339 return transpose ().prod (0).transpose ();
7269
3fade00a6ac7 [project @ 2007-12-07 19:26:20 by jwe]
jwe
parents: 7036
diff changeset
7340 else
3fade00a6ac7 [project @ 2007-12-07 19:26:20 by jwe]
jwe
parents: 7036
diff changeset
7341 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
7342 SPARSE_REDUCTION_OP (SparseComplexMatrix, Complex, *=,
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
7343 (cidx (j+1) - cidx (j) < nr ? 0.0 : 1.0), 1.0);
7269
3fade00a6ac7 [project @ 2007-12-07 19:26:20 by jwe]
jwe
parents: 7036
diff changeset
7344 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7345 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7346
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7347 SparseComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7348 SparseComplexMatrix::sum (int dim) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7349 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7350 SPARSE_REDUCTION_OP (SparseComplexMatrix, Complex, +=, 0.0, 0.0);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7351 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7352
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7353 SparseComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7354 SparseComplexMatrix::sumsq (int dim) const
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7355 {
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22135
diff changeset
7356 #define ROW_EXPR \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22135
diff changeset
7357 Complex d = data (i); \
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
7358 tmp[ridx (i)] += d * conj (d)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7359
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22135
diff changeset
7360 #define COL_EXPR \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22135
diff changeset
7361 Complex d = data (i); \
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
7362 tmp[j] += d * conj (d)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7363
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
7364 SPARSE_BASE_REDUCTION_OP (SparseComplexMatrix, Complex, ROW_EXPR,
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7365 COL_EXPR, 0.0, 0.0);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7366
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7367 #undef ROW_EXPR
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7368 #undef COL_EXPR
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7369 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7370
32590
3c2c585965cc maint: C++ style check for liboctave/ before 9.1 release.
Rik <rik@octave.org>
parents: 32513
diff changeset
7371 SparseMatrix
3c2c585965cc maint: C++ style check for liboctave/ before 9.1 release.
Rik <rik@octave.org>
parents: 32513
diff changeset
7372 SparseComplexMatrix::abs () const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7373 {
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
7374 octave_idx_type nz = nnz ();
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7375 octave_idx_type nc = cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7376
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14844
diff changeset
7377 SparseMatrix retval (rows (), nc, nz);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7378
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7379 for (octave_idx_type i = 0; i < nc + 1; i++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7380 retval.cidx (i) = cidx (i);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7381
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7382 for (octave_idx_type i = 0; i < nz; i++)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7383 {
5261
90a9058de7e8 [project @ 2005-03-31 02:48:38 by jwe]
jwe
parents: 5203
diff changeset
7384 retval.data (i) = std::abs (data (i));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7385 retval.ridx (i) = ridx (i);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7386 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7387
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7388 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7389 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7390
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7391 SparseComplexMatrix
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7392 SparseComplexMatrix::diag (octave_idx_type k) const
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7393 {
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7602
diff changeset
7394 return MSparse<Complex>::diag (k);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7395 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7396
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7397 std::ostream&
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7398 operator << (std::ostream& os, const SparseComplexMatrix& a)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7399 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7400 octave_idx_type nc = a.cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7401
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7402 // add one to the printed indices to go from
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7403 // zero-based to one-based arrays
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7404 for (octave_idx_type j = 0; j < nc; j++)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7405 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7406 octave_quit ();
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7407 for (octave_idx_type i = a.cidx (j); i < a.cidx (j+1); i++)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7408 {
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23796
diff changeset
7409 os << a.ridx (i) + 1 << ' ' << j + 1 << ' ';
28628
83172e1c77f2 refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents: 27957
diff changeset
7410 octave::write_value<Complex> (os, a.data (i));
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7411 os << "\n";
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7412 }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7413 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7414
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7415 return os;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7416 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7417
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7418 std::istream&
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7419 operator >> (std::istream& is, SparseComplexMatrix& a)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7420 {
9469
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 9417
diff changeset
7421 typedef SparseComplexMatrix::element_type elt_type;
c6edba80dfae sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents: 9417
diff changeset
7422
28628
83172e1c77f2 refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents: 27957
diff changeset
7423 return read_sparse_matrix<elt_type> (is, a, octave::read_value<Complex>);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7424 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7425
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7426 SparseComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7427 operator * (const SparseComplexMatrix& m, const SparseMatrix& a)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7428 {
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
7429 SPARSE_SPARSE_MUL (SparseComplexMatrix, Complex, double);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7430 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7431
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7432 SparseComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7433 operator * (const SparseMatrix& m, const SparseComplexMatrix& a)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7434 {
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
7435 SPARSE_SPARSE_MUL (SparseComplexMatrix, Complex, Complex);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7436 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7437
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7438 SparseComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7439 operator * (const SparseComplexMatrix& m, const SparseComplexMatrix& a)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7440 {
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5648
diff changeset
7441 SPARSE_SPARSE_MUL (SparseComplexMatrix, Complex, Complex);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7442 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7443
5429
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7444 ComplexMatrix
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7445 operator * (const ComplexMatrix& m, const SparseMatrix& a)
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7446 {
25665
dc073ccde64e eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents: 25664
diff changeset
7447 FULL_SPARSE_MUL (ComplexMatrix, double);
5429
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7448 }
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7449
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7450 ComplexMatrix
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7451 operator * (const Matrix& m, const SparseComplexMatrix& a)
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7452 {
25665
dc073ccde64e eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents: 25664
diff changeset
7453 FULL_SPARSE_MUL (ComplexMatrix, Complex);
5429
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7454 }
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7455
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7456 ComplexMatrix
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7457 operator * (const ComplexMatrix& m, const SparseComplexMatrix& a)
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7458 {
25665
dc073ccde64e eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents: 25664
diff changeset
7459 FULL_SPARSE_MUL (ComplexMatrix, Complex);
5429
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7460 }
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7461
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7462 ComplexMatrix
7802
1a446f28ce68 implement optimized sparse-dense transposed multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
7463 mul_trans (const ComplexMatrix& m, const SparseComplexMatrix& a)
1a446f28ce68 implement optimized sparse-dense transposed multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
7464 {
25665
dc073ccde64e eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents: 25664
diff changeset
7465 FULL_SPARSE_MUL_TRANS (ComplexMatrix, Complex, );
7802
1a446f28ce68 implement optimized sparse-dense transposed multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
7466 }
1a446f28ce68 implement optimized sparse-dense transposed multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
7467
1a446f28ce68 implement optimized sparse-dense transposed multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
7468 ComplexMatrix
1a446f28ce68 implement optimized sparse-dense transposed multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
7469 mul_herm (const ComplexMatrix& m, const SparseComplexMatrix& a)
1a446f28ce68 implement optimized sparse-dense transposed multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
7470 {
25665
dc073ccde64e eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents: 25664
diff changeset
7471 FULL_SPARSE_MUL_TRANS (ComplexMatrix, Complex, conj);
7802
1a446f28ce68 implement optimized sparse-dense transposed multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
7472 }
1a446f28ce68 implement optimized sparse-dense transposed multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
7473
1a446f28ce68 implement optimized sparse-dense transposed multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
7474 ComplexMatrix
5429
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7475 operator * (const SparseComplexMatrix& m, const Matrix& a)
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7476 {
25665
dc073ccde64e eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents: 25664
diff changeset
7477 SPARSE_FULL_MUL (ComplexMatrix, double);
5429
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7478 }
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7479
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7480 ComplexMatrix
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7481 operator * (const SparseMatrix& m, const ComplexMatrix& a)
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7482 {
25665
dc073ccde64e eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents: 25664
diff changeset
7483 SPARSE_FULL_MUL (ComplexMatrix, Complex);
5429
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7484 }
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7485
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7486 ComplexMatrix
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7487 operator * (const SparseComplexMatrix& m, const ComplexMatrix& a)
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7488 {
25665
dc073ccde64e eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents: 25664
diff changeset
7489 SPARSE_FULL_MUL (ComplexMatrix, Complex);
5429
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7490 }
2042301733ce [project @ 2005-08-25 12:21:24 by dbateman]
dbateman
parents: 5404
diff changeset
7491
7802
1a446f28ce68 implement optimized sparse-dense transposed multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
7492 ComplexMatrix
1a446f28ce68 implement optimized sparse-dense transposed multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
7493 trans_mul (const SparseComplexMatrix& m, const ComplexMatrix& a)
1a446f28ce68 implement optimized sparse-dense transposed multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
7494 {
25665
dc073ccde64e eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents: 25664
diff changeset
7495 SPARSE_FULL_TRANS_MUL (ComplexMatrix, Complex, );
7802
1a446f28ce68 implement optimized sparse-dense transposed multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
7496 }
1a446f28ce68 implement optimized sparse-dense transposed multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
7497
1a446f28ce68 implement optimized sparse-dense transposed multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
7498 ComplexMatrix
1a446f28ce68 implement optimized sparse-dense transposed multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
7499 herm_mul (const SparseComplexMatrix& m, const ComplexMatrix& a)
1a446f28ce68 implement optimized sparse-dense transposed multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
7500 {
25665
dc073ccde64e eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents: 25664
diff changeset
7501 SPARSE_FULL_TRANS_MUL (ComplexMatrix, Complex, conj);
7802
1a446f28ce68 implement optimized sparse-dense transposed multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
7502 }
1a446f28ce68 implement optimized sparse-dense transposed multiplication
Jaroslav Hajek <highegg@gmail.com>
parents: 7620
diff changeset
7503
8964
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7504 // diag * sparse and sparse * diag
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7505 SparseComplexMatrix
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7506 operator * (const DiagMatrix& d, const SparseComplexMatrix& a)
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7507 {
8967
5bbbf482909a fix omissions adjusting JR's patches
Jaroslav Hajek <highegg@gmail.com>
parents: 8966
diff changeset
7508 return do_mul_dm_sm<SparseComplexMatrix> (d, a);
8964
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7509 }
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7510 SparseComplexMatrix
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7511 operator * (const SparseComplexMatrix& a, const DiagMatrix& d)
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7512 {
8967
5bbbf482909a fix omissions adjusting JR's patches
Jaroslav Hajek <highegg@gmail.com>
parents: 8966
diff changeset
7513 return do_mul_sm_dm<SparseComplexMatrix> (a, d);
8964
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7514 }
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7515
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7516 SparseComplexMatrix
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7517 operator * (const ComplexDiagMatrix& d, const SparseMatrix& a)
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7518 {
8967
5bbbf482909a fix omissions adjusting JR's patches
Jaroslav Hajek <highegg@gmail.com>
parents: 8966
diff changeset
7519 return do_mul_dm_sm<SparseComplexMatrix> (d, a);
8964
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7520 }
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7521 SparseComplexMatrix
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7522 operator * (const SparseMatrix& a, const ComplexDiagMatrix& d)
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7523 {
8967
5bbbf482909a fix omissions adjusting JR's patches
Jaroslav Hajek <highegg@gmail.com>
parents: 8966
diff changeset
7524 return do_mul_sm_dm<SparseComplexMatrix> (a, d);
8964
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7525 }
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7526
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7527 SparseComplexMatrix
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7528 operator * (const ComplexDiagMatrix& d, const SparseComplexMatrix& a)
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7529 {
8967
5bbbf482909a fix omissions adjusting JR's patches
Jaroslav Hajek <highegg@gmail.com>
parents: 8966
diff changeset
7530 return do_mul_dm_sm<SparseComplexMatrix> (d, a);
8964
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7531 }
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7532 SparseComplexMatrix
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7533 operator * (const SparseComplexMatrix& a, const ComplexDiagMatrix& d)
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7534 {
8967
5bbbf482909a fix omissions adjusting JR's patches
Jaroslav Hajek <highegg@gmail.com>
parents: 8966
diff changeset
7535 return do_mul_sm_dm<SparseComplexMatrix> (a, d);
8964
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7536 }
f4f4d65faaa0 Implement sparse * diagonal and diagonal * sparse operations, double-prec only.
Jason Riedy <jason@acm.org>
parents: 8920
diff changeset
7537
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7538 SparseComplexMatrix
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7539 operator + (const ComplexDiagMatrix& d, const SparseMatrix& a)
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7540 {
8967
5bbbf482909a fix omissions adjusting JR's patches
Jaroslav Hajek <highegg@gmail.com>
parents: 8966
diff changeset
7541 return do_add_dm_sm<SparseComplexMatrix> (d, a);
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7542 }
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7543 SparseComplexMatrix
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7544 operator + (const DiagMatrix& d, const SparseComplexMatrix& a)
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7545 {
8967
5bbbf482909a fix omissions adjusting JR's patches
Jaroslav Hajek <highegg@gmail.com>
parents: 8966
diff changeset
7546 return do_add_dm_sm<SparseComplexMatrix> (d, a);
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7547 }
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7548 SparseComplexMatrix
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7549 operator + (const ComplexDiagMatrix& d, const SparseComplexMatrix& a)
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7550 {
8967
5bbbf482909a fix omissions adjusting JR's patches
Jaroslav Hajek <highegg@gmail.com>
parents: 8966
diff changeset
7551 return do_add_dm_sm<SparseComplexMatrix> (d, a);
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7552 }
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7553 SparseComplexMatrix
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7554 operator + (const SparseMatrix& a, const ComplexDiagMatrix& d)
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7555 {
8967
5bbbf482909a fix omissions adjusting JR's patches
Jaroslav Hajek <highegg@gmail.com>
parents: 8966
diff changeset
7556 return do_add_sm_dm<SparseComplexMatrix> (a, d);
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7557 }
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7558 SparseComplexMatrix
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7559 operator + (const SparseComplexMatrix& a, const DiagMatrix& d)
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7560 {
8967
5bbbf482909a fix omissions adjusting JR's patches
Jaroslav Hajek <highegg@gmail.com>
parents: 8966
diff changeset
7561 return do_add_sm_dm<SparseComplexMatrix> (a, d);
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7562 }
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7563 SparseComplexMatrix
21661
1b9a36a66b01 maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents: 21660
diff changeset
7564 operator + (const SparseComplexMatrix& a, const ComplexDiagMatrix& d)
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7565 {
8967
5bbbf482909a fix omissions adjusting JR's patches
Jaroslav Hajek <highegg@gmail.com>
parents: 8966
diff changeset
7566 return do_add_sm_dm<SparseComplexMatrix> (a, d);
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7567 }
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7568
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7569 SparseComplexMatrix
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7570 operator - (const ComplexDiagMatrix& d, const SparseMatrix& a)
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7571 {
8967
5bbbf482909a fix omissions adjusting JR's patches
Jaroslav Hajek <highegg@gmail.com>
parents: 8966
diff changeset
7572 return do_sub_dm_sm<SparseComplexMatrix> (d, a);
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7573 }
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7574 SparseComplexMatrix
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7575 operator - (const DiagMatrix& d, const SparseComplexMatrix& a)
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7576 {
8967
5bbbf482909a fix omissions adjusting JR's patches
Jaroslav Hajek <highegg@gmail.com>
parents: 8966
diff changeset
7577 return do_sub_dm_sm<SparseComplexMatrix> (d, a);
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7578 }
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7579 SparseComplexMatrix
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7580 operator - (const ComplexDiagMatrix& d, const SparseComplexMatrix& a)
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7581 {
8967
5bbbf482909a fix omissions adjusting JR's patches
Jaroslav Hajek <highegg@gmail.com>
parents: 8966
diff changeset
7582 return do_sub_dm_sm<SparseComplexMatrix> (d, a);
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7583 }
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7584 SparseComplexMatrix
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7585 operator - (const SparseMatrix& a, const ComplexDiagMatrix& d)
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7586 {
8967
5bbbf482909a fix omissions adjusting JR's patches
Jaroslav Hajek <highegg@gmail.com>
parents: 8966
diff changeset
7587 return do_sub_sm_dm<SparseComplexMatrix> (a, d);
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7588 }
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7589 SparseComplexMatrix
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7590 operator - (const SparseComplexMatrix& a, const DiagMatrix& d)
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7591 {
8967
5bbbf482909a fix omissions adjusting JR's patches
Jaroslav Hajek <highegg@gmail.com>
parents: 8966
diff changeset
7592 return do_sub_sm_dm<SparseComplexMatrix> (a, d);
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7593 }
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7594 SparseComplexMatrix
21661
1b9a36a66b01 maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents: 21660
diff changeset
7595 operator - (const SparseComplexMatrix& a, const ComplexDiagMatrix& d)
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7596 {
8967
5bbbf482909a fix omissions adjusting JR's patches
Jaroslav Hajek <highegg@gmail.com>
parents: 8966
diff changeset
7597 return do_sub_sm_dm<SparseComplexMatrix> (a, d);
8966
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7598 }
1bba53c0a38d Implement diag + sparse, diag - sparse, sparse + diag, sparse - diag.
Jason Riedy <jason@acm.org>
parents: 8964
diff changeset
7599
8968
91d53dc37f79 Add perm * sparse, perm \ sparse, sparse * perm, and sparse / perm operations.
Jason Riedy <jason@acm.org>
parents: 8967
diff changeset
7600 // perm * sparse and sparse * perm
91d53dc37f79 Add perm * sparse, perm \ sparse, sparse * perm, and sparse / perm operations.
Jason Riedy <jason@acm.org>
parents: 8967
diff changeset
7601
91d53dc37f79 Add perm * sparse, perm \ sparse, sparse * perm, and sparse / perm operations.
Jason Riedy <jason@acm.org>
parents: 8967
diff changeset
7602 SparseComplexMatrix
91d53dc37f79 Add perm * sparse, perm \ sparse, sparse * perm, and sparse / perm operations.
Jason Riedy <jason@acm.org>
parents: 8967
diff changeset
7603 operator * (const PermMatrix& p, const SparseComplexMatrix& a)
91d53dc37f79 Add perm * sparse, perm \ sparse, sparse * perm, and sparse / perm operations.
Jason Riedy <jason@acm.org>
parents: 8967
diff changeset
7604 {
91d53dc37f79 Add perm * sparse, perm \ sparse, sparse * perm, and sparse / perm operations.
Jason Riedy <jason@acm.org>
parents: 8967
diff changeset
7605 return octinternal_do_mul_pm_sm (p, a);
91d53dc37f79 Add perm * sparse, perm \ sparse, sparse * perm, and sparse / perm operations.
Jason Riedy <jason@acm.org>
parents: 8967
diff changeset
7606 }
91d53dc37f79 Add perm * sparse, perm \ sparse, sparse * perm, and sparse / perm operations.
Jason Riedy <jason@acm.org>
parents: 8967
diff changeset
7607
91d53dc37f79 Add perm * sparse, perm \ sparse, sparse * perm, and sparse / perm operations.
Jason Riedy <jason@acm.org>
parents: 8967
diff changeset
7608 SparseComplexMatrix
91d53dc37f79 Add perm * sparse, perm \ sparse, sparse * perm, and sparse / perm operations.
Jason Riedy <jason@acm.org>
parents: 8967
diff changeset
7609 operator * (const SparseComplexMatrix& a, const PermMatrix& p)
91d53dc37f79 Add perm * sparse, perm \ sparse, sparse * perm, and sparse / perm operations.
Jason Riedy <jason@acm.org>
parents: 8967
diff changeset
7610 {
91d53dc37f79 Add perm * sparse, perm \ sparse, sparse * perm, and sparse / perm operations.
Jason Riedy <jason@acm.org>
parents: 8967
diff changeset
7611 return octinternal_do_mul_sm_pm (a, p);
91d53dc37f79 Add perm * sparse, perm \ sparse, sparse * perm, and sparse / perm operations.
Jason Riedy <jason@acm.org>
parents: 8967
diff changeset
7612 }
91d53dc37f79 Add perm * sparse, perm \ sparse, sparse * perm, and sparse / perm operations.
Jason Riedy <jason@acm.org>
parents: 8967
diff changeset
7613
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
7614 // FIXME: it would be nice to share code among the min/max functions below.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7615
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22135
diff changeset
7616 #define EMPTY_RETURN_CHECK(T) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22135
diff changeset
7617 if (nr == 0 || nc == 0) \
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7618 return T (nr, nc);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7619
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7620 SparseComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7621 min (const Complex& c, const SparseComplexMatrix& m)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7622 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7623 SparseComplexMatrix result;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7624
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7625 octave_idx_type nr = m.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7626 octave_idx_type nc = m.columns ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7627
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7628 EMPTY_RETURN_CHECK (SparseComplexMatrix);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7629
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
7630 if (abs (c) == 0.)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7631 return SparseComplexMatrix (nr, nc);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7632 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7633 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7634 result = SparseComplexMatrix (m);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7635
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7636 for (octave_idx_type j = 0; j < nc; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
7637 for (octave_idx_type i = m.cidx (j); i < m.cidx (j+1); i++)
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
7638 result.data (i) = octave::math::min (c, m.data (i));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7639 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11574
diff changeset
7640
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7641 return result;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7642 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7643
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7644 SparseComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7645 min (const SparseComplexMatrix& m, const Complex& c)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7646 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7647 return min (c, m);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7648 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7649
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7650 SparseComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7651 min (const SparseComplexMatrix& a, const SparseComplexMatrix& b)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7652 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7653 SparseComplexMatrix r;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7654
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7655 octave_idx_type a_nr = a.rows ();
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7656 octave_idx_type a_nc = a.cols ();
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7657 octave_idx_type b_nr = b.rows ();
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7658 octave_idx_type b_nc = b.cols ();
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7659
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7660 if (a_nr == b_nr && a_nc == b_nc)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7661 {
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7662 r = SparseComplexMatrix (a_nr, a_nc, (a.nnz () + b.nnz ()));
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7663
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7664 octave_idx_type jx = 0;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7665 r.cidx (0) = 0;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7666 for (octave_idx_type i = 0 ; i < a_nc ; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7667 {
21562
6c2fd62db1f7 maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents: 21301
diff changeset
7668 octave_idx_type ja = a.cidx (i);
6c2fd62db1f7 maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents: 21301
diff changeset
7669 octave_idx_type ja_max = a.cidx (i+1);
6c2fd62db1f7 maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents: 21301
diff changeset
7670 bool ja_lt_max = ja < ja_max;
6c2fd62db1f7 maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents: 21301
diff changeset
7671
6c2fd62db1f7 maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents: 21301
diff changeset
7672 octave_idx_type jb = b.cidx (i);
6c2fd62db1f7 maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents: 21301
diff changeset
7673 octave_idx_type jb_max = b.cidx (i+1);
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7674 bool jb_lt_max = jb < jb_max;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7675
18678
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18676
diff changeset
7676 while (ja_lt_max || jb_lt_max)
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7677 {
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7678 octave_quit ();
19864
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
7679 if ((! jb_lt_max) || (ja_lt_max && (a.ridx (ja) < b.ridx (jb))))
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7680 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
7681 Complex tmp = octave::math::min (a.data (ja), 0.);
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7682 if (tmp != 0.)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7683 {
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7684 r.ridx (jx) = a.ridx (ja);
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7685 r.data (jx) = tmp;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7686 jx++;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7687 }
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7688 ja++;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7689 ja_lt_max= ja < ja_max;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7690 }
19864
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
7691 else if ((! ja_lt_max)
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
7692 || (jb_lt_max && (b.ridx (jb) < a.ridx (ja))))
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7693 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
7694 Complex tmp = octave::math::min (0., b.data (jb));
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7695 if (tmp != 0.)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7696 {
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7697 r.ridx (jx) = b.ridx (jb);
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7698 r.data (jx) = tmp;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7699 jx++;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7700 }
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7701 jb++;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7702 jb_lt_max= jb < jb_max;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7703 }
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7704 else
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7705 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
7706 Complex tmp = octave::math::min (a.data (ja), b.data (jb));
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7707 if (tmp != 0.)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7708 {
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7709 r.data (jx) = tmp;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7710 r.ridx (jx) = a.ridx (ja);
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7711 jx++;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7712 }
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7713 ja++;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7714 ja_lt_max= ja < ja_max;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7715 jb++;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7716 jb_lt_max= jb < jb_max;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7717 }
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7718 }
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7719 r.cidx (i+1) = jx;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7720 }
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7721
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7722 r.maybe_compress ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7723 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7724 else
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7725 {
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7726 if (a_nr == 0 || a_nc == 0)
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7727 r.resize (a_nr, a_nc);
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7728 else if (b_nr == 0 || b_nc == 0)
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7729 r.resize (b_nr, b_nc);
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7730 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
7731 octave::err_nonconformant ("min", a_nr, a_nc, b_nr, b_nc);
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7732 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7733
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7734 return r;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7735 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7736
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7737 SparseComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7738 max (const Complex& c, const SparseComplexMatrix& m)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7739 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7740 SparseComplexMatrix result;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7741
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7742 octave_idx_type nr = m.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7743 octave_idx_type nc = m.columns ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7744
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7745 EMPTY_RETURN_CHECK (SparseComplexMatrix);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7746
18812
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18678
diff changeset
7747 // Count the number of nonzero elements
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
7748 if (octave::math::max (c, 0.) != 0.)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7749 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7750 result = SparseComplexMatrix (nr, nc, c);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5261
diff changeset
7751 for (octave_idx_type j = 0; j < nc; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
7752 for (octave_idx_type i = m.cidx (j); i < m.cidx (j+1); i++)
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
7753 result.xdata (m.ridx (i) + j * nr) = octave::math::max (c, m.data (i));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7754 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7755 else
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7756 result = SparseComplexMatrix (m);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7757
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7758 return result;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7759 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7760
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7761 SparseComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7762 max (const SparseComplexMatrix& m, const Complex& c)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7763 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7764 return max (c, m);
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7765 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7766
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7767 SparseComplexMatrix
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7768 max (const SparseComplexMatrix& a, const SparseComplexMatrix& b)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7769 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7770 SparseComplexMatrix r;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7771
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7772 octave_idx_type a_nr = a.rows ();
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7773 octave_idx_type a_nc = a.cols ();
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7774 octave_idx_type b_nr = b.rows ();
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7775 octave_idx_type b_nc = b.cols ();
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7776
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7777 if (a_nr == b_nr && a_nc == b_nc)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7778 {
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7779 r = SparseComplexMatrix (a_nr, a_nc, (a.nnz () + b.nnz ()));
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7780
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7781 octave_idx_type jx = 0;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7782 r.cidx (0) = 0;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7783 for (octave_idx_type i = 0 ; i < a_nc ; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7784 {
21562
6c2fd62db1f7 maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents: 21301
diff changeset
7785 octave_idx_type ja = a.cidx (i);
6c2fd62db1f7 maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents: 21301
diff changeset
7786 octave_idx_type ja_max = a.cidx (i+1);
6c2fd62db1f7 maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents: 21301
diff changeset
7787 bool ja_lt_max = ja < ja_max;
6c2fd62db1f7 maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents: 21301
diff changeset
7788
6c2fd62db1f7 maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents: 21301
diff changeset
7789 octave_idx_type jb = b.cidx (i);
6c2fd62db1f7 maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents: 21301
diff changeset
7790 octave_idx_type jb_max = b.cidx (i+1);
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7791 bool jb_lt_max = jb < jb_max;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7792
18678
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18676
diff changeset
7793 while (ja_lt_max || jb_lt_max)
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7794 {
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7795 octave_quit ();
19864
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
7796 if ((! jb_lt_max) || (ja_lt_max && (a.ridx (ja) < b.ridx (jb))))
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7797 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
7798 Complex tmp = octave::math::max (a.data (ja), 0.);
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7799 if (tmp != 0.)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7800 {
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7801 r.ridx (jx) = a.ridx (ja);
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7802 r.data (jx) = tmp;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7803 jx++;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7804 }
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7805 ja++;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7806 ja_lt_max= ja < ja_max;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7807 }
19864
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
7808 else if ((! ja_lt_max)
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
7809 || (jb_lt_max && (b.ridx (jb) < a.ridx (ja))))
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7810 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
7811 Complex tmp = octave::math::max (0., b.data (jb));
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7812 if (tmp != 0.)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7813 {
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7814 r.ridx (jx) = b.ridx (jb);
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7815 r.data (jx) = tmp;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7816 jx++;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7817 }
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7818 jb++;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7819 jb_lt_max= jb < jb_max;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7820 }
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7821 else
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7822 {
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
7823 Complex tmp = octave::math::max (a.data (ja), b.data (jb));
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7824 if (tmp != 0.)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7825 {
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7826 r.data (jx) = tmp;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7827 r.ridx (jx) = a.ridx (ja);
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7828 jx++;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7829 }
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7830 ja++;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7831 ja_lt_max= ja < ja_max;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7832 jb++;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7833 jb_lt_max= jb < jb_max;
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7834 }
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7835 }
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7836 r.cidx (i+1) = jx;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
7837 }
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7838
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7839 r.maybe_compress ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7840 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7841 else
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7842 {
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7843 if (a_nr == 0 || a_nc == 0)
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7844 r.resize (a_nr, a_nc);
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7845 else if (b_nr == 0 || b_nc == 0)
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7846 r.resize (b_nr, b_nc);
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7847 else
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
7848 octave::err_nonconformant ("max", a_nr, a_nc, b_nr, b_nc);
18110
2217bc116aa9 maint: Dummy merge with gui-release, ignoring all recent backout merges
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 18107
diff changeset
7849 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7850
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7851 return r;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7852 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7853
25665
dc073ccde64e eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents: 25664
diff changeset
7854 SPARSE_SMS_CMP_OPS (SparseComplexMatrix, Complex)
25663
2de707ae8de4 eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
7855 SPARSE_SMS_BOOL_OPS (SparseComplexMatrix, Complex)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7856
25665
dc073ccde64e eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents: 25664
diff changeset
7857 SPARSE_SSM_CMP_OPS (Complex, SparseComplexMatrix)
25663
2de707ae8de4 eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
7858 SPARSE_SSM_BOOL_OPS (Complex, SparseComplexMatrix)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7859
25665
dc073ccde64e eliminate more zero args in macros and type definitions for operators
John W. Eaton <jwe@octave.org>
parents: 25664
diff changeset
7860 SPARSE_SMSM_CMP_OPS (SparseComplexMatrix, SparseComplexMatrix)
25663
2de707ae8de4 eliminate LHS_ZERO and RHS_ZERO args from sparse macros
John W. Eaton <jwe@octave.org>
parents: 25438
diff changeset
7861 SPARSE_SMSM_BOOL_OPS (SparseComplexMatrix, SparseComplexMatrix)