Mercurial > hg > octave-nkf
annotate liboctave/array/MatrixType.cc @ 17795:0a8c35ae5ce1
maint: Fix various problems with GPL copyright statements.
* libgui/qterminal/libqterminal/QTerminal.cc,
libgui/qterminal/libqterminal/QTerminal.h,
libgui/qterminal/libqterminal/win32/QTerminalColors.cpp,
libgui/qterminal/libqterminal/win32/QTerminalColors.h,
libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp,
libgui/qterminal/libqterminal/win32/QWinTerminalImpl.h:
Replace "Foobar" with "This program" in GPL statement.
* scripts/linear-algebra/linsolve.m: Replace "This program" with "Octave" in
* GPL statement.
* scripts/miscellaneous/getappdata.m, scripts/miscellaneous/isappdata.m,
scripts/miscellaneous/rmappdata.m, scripts/miscellaneous/setappdata.m:
Add "This file is part of Octave" line. Replace "This program" with "Octave"
in GPL statement. Update GPL version to 3.
* scripts/plot/util/copyobj.m, scripts/plot/util/hdl2struct.m,
scripts/plot/util/struct2hdl.m, scripts/polynomial/ppder.m,
scripts/polynomial/ppint.m, scripts/polynomial/ppjumps.m,
scripts/sparse/bicg.m, scripts/strings/untabify.m:
Replace "This program" with "Octave" in GPL statement.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 29 Oct 2013 12:31:57 -0700 |
parents | 49a5a4be04a1 |
children | 8e056300994b |
rev | line source |
---|---|
5785 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
3 Copyright (C) 2006-2013 David Bateman |
5785 | 4 Copyright (C) 2006 Andy Adler |
10521
4d1fc073fbb7
add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents:
10506
diff
changeset
|
5 Copyright (C) 2009 VZLU Prague |
5785 | 6 |
7016 | 7 This file is part of Octave. |
8 | |
5785 | 9 Octave is free software; you can redistribute it and/or modify it |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
5785 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
5785 | 22 |
23 */ | |
24 | |
25 #ifdef HAVE_CONFIG_H | |
26 #include <config.h> | |
27 #endif | |
28 | |
29 #include <vector> | |
30 | |
31 #include "MatrixType.h" | |
32 #include "dMatrix.h" | |
33 #include "CMatrix.h" | |
34 #include "dSparse.h" | |
35 #include "CSparse.h" | |
36 #include "oct-spparms.h" | |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
7798
diff
changeset
|
37 #include "oct-locbuf.h" |
5785 | 38 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
39 // FIXME: There is a large code duplication here |
5785 | 40 |
5892 | 41 MatrixType::MatrixType (void) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
42 : typ (MatrixType::Unknown), |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
43 sp_bandden (octave_sparse_params::get_bandden ()), |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
44 bandden (0), upper_band (0), |
6452 | 45 lower_band (0), dense (false), full (false), nperm (0), perm (0) { } |
5785 | 46 |
5892 | 47 MatrixType::MatrixType (const MatrixType &a) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
48 : typ (a.typ), sp_bandden (a.sp_bandden), bandden (a.bandden), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
49 upper_band (a.upper_band), lower_band (a.lower_band), |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10713
diff
changeset
|
50 dense (a.dense), full (a.full), nperm (a.nperm), perm (0) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
51 { |
5785 | 52 if (nperm != 0) |
53 { | |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
54 perm = new octave_idx_type [nperm]; |
5785 | 55 for (octave_idx_type i = 0; i < nperm; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
56 perm[i] = a.perm[i]; |
5785 | 57 } |
58 } | |
59 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
60 template<class T> |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
61 MatrixType::matrix_type |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
62 matrix_real_probe (const MArray<T>& a) |
5785 | 63 { |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
64 MatrixType::matrix_type typ; |
5785 | 65 octave_idx_type nrows = a.rows (); |
66 octave_idx_type ncols = a.cols (); | |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
67 |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
68 const T zero = 0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
69 |
5785 | 70 if (ncols == nrows) |
71 { | |
72 bool upper = true; | |
73 bool lower = true; | |
74 bool hermitian = true; | |
75 | |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
76 // do the checks for lower/upper/hermitian all in one pass. |
15022
e47b4e8c2714
maint: Use space after OCTAVE_LOCAL_BUFFER invocation in liboctave source code.
Rik <rik@octave.org>
parents:
15020
diff
changeset
|
77 OCTAVE_LOCAL_BUFFER (T, diag, ncols); |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
78 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
79 for (octave_idx_type j = 0; |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
80 j < ncols && upper; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
81 { |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
82 T d = a.elem (j,j); |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
83 upper = upper && (d != zero); |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
84 lower = lower && (d != zero); |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
85 hermitian = hermitian && (d > zero); |
10713
0e05ed9f2a62
improve some MatrixType code
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
86 diag[j] = d; |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
87 } |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
88 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
89 for (octave_idx_type j = 0; |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
90 j < ncols && (upper || lower || hermitian); j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
91 { |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
92 for (octave_idx_type i = 0; i < j; i++) |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
93 { |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
94 double aij = a.elem (i,j), aji = a.elem (j,i); |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
95 lower = lower && (aij == zero); |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
96 upper = upper && (aji == zero); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
97 hermitian = hermitian && (aij == aji |
10713
0e05ed9f2a62
improve some MatrixType code
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
98 && aij*aij < diag[i]*diag[j]); |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
99 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
100 } |
5785 | 101 |
102 if (upper) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
103 typ = MatrixType::Upper; |
5785 | 104 else if (lower) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
105 typ = MatrixType::Lower; |
5785 | 106 else if (hermitian) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
107 typ = MatrixType::Hermitian; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
108 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
109 typ = MatrixType::Full; |
5785 | 110 } |
111 else | |
112 typ = MatrixType::Rectangular; | |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
113 |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
114 return typ; |
5785 | 115 } |
116 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
117 template<class T> |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
118 MatrixType::matrix_type |
10713
0e05ed9f2a62
improve some MatrixType code
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
119 matrix_complex_probe (const MArray<std::complex<T> >& a) |
5785 | 120 { |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
121 MatrixType::matrix_type typ; |
5785 | 122 octave_idx_type nrows = a.rows (); |
123 octave_idx_type ncols = a.cols (); | |
124 | |
10713
0e05ed9f2a62
improve some MatrixType code
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
125 const T zero = 0; |
0e05ed9f2a62
improve some MatrixType code
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
126 // get the real type |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
127 |
5785 | 128 if (ncols == nrows) |
129 { | |
130 bool upper = true; | |
131 bool lower = true; | |
132 bool hermitian = true; | |
133 | |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
134 // do the checks for lower/upper/hermitian all in one pass. |
15022
e47b4e8c2714
maint: Use space after OCTAVE_LOCAL_BUFFER invocation in liboctave source code.
Rik <rik@octave.org>
parents:
15020
diff
changeset
|
135 OCTAVE_LOCAL_BUFFER (T, diag, ncols); |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
136 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
137 for (octave_idx_type j = 0; |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
138 j < ncols && upper; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
139 { |
10713
0e05ed9f2a62
improve some MatrixType code
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
140 std::complex<T> d = a.elem (j,j); |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
141 upper = upper && (d != zero); |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
142 lower = lower && (d != zero); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
143 hermitian = hermitian && (d.real () > zero && d.imag () == zero); |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
144 diag[j] = d.real (); |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
145 } |
5785 | 146 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
147 for (octave_idx_type j = 0; |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
148 j < ncols && (upper || lower || hermitian); j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
149 { |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
150 for (octave_idx_type i = 0; i < j; i++) |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
151 { |
10713
0e05ed9f2a62
improve some MatrixType code
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
152 std::complex<T> aij = a.elem (i,j), aji = a.elem (j,i); |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
153 lower = lower && (aij == zero); |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
154 upper = upper && (aji == zero); |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
155 hermitian = hermitian && (aij == std::conj (aji) |
10713
0e05ed9f2a62
improve some MatrixType code
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
156 && std::norm (aij) < diag[i]*diag[j]); |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
157 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
158 } |
5785 | 159 |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
160 |
5785 | 161 if (upper) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
162 typ = MatrixType::Upper; |
5785 | 163 else if (lower) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
164 typ = MatrixType::Lower; |
5785 | 165 else if (hermitian) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
166 typ = MatrixType::Hermitian; |
5785 | 167 else if (ncols == nrows) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
168 typ = MatrixType::Full; |
5785 | 169 } |
170 else | |
171 typ = MatrixType::Rectangular; | |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
172 |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
173 return typ; |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
174 } |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
175 |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
176 MatrixType::MatrixType (const Matrix &a) |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
177 : typ (MatrixType::Unknown), |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
178 sp_bandden (0), bandden (0), upper_band (0), lower_band (0), |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
179 dense (false), full (true), nperm (0), perm (0) |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
180 { |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
181 typ = matrix_real_probe (a); |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
182 } |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
183 |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
184 MatrixType::MatrixType (const ComplexMatrix &a) |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
185 : typ (MatrixType::Unknown), |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
186 sp_bandden (0), bandden (0), upper_band (0), lower_band (0), |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
187 dense (false), full (true), nperm (0), perm (0) |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
188 { |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
189 typ = matrix_complex_probe (a); |
5785 | 190 } |
191 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
192 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
193 MatrixType::MatrixType (const FloatMatrix &a) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
194 : typ (MatrixType::Unknown), |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
195 sp_bandden (0), bandden (0), upper_band (0), lower_band (0), |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
196 dense (false), full (true), nperm (0), perm (0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
197 { |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
198 typ = matrix_real_probe (a); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
199 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
200 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
201 MatrixType::MatrixType (const FloatComplexMatrix &a) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
202 : typ (MatrixType::Unknown), |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
203 sp_bandden (0), bandden (0), upper_band (0), lower_band (0), |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
204 dense (false), full (true), nperm (0), perm (0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
205 { |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
206 typ = matrix_complex_probe (a); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
207 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
208 |
5785 | 209 MatrixType::MatrixType (const SparseMatrix &a) |
5892 | 210 : typ (MatrixType::Unknown), |
211 sp_bandden (0), bandden (0), upper_band (0), lower_band (0), | |
212 dense (false), full (false), nperm (0), perm (0) | |
5785 | 213 { |
214 octave_idx_type nrows = a.rows (); | |
215 octave_idx_type ncols = a.cols (); | |
216 octave_idx_type nm = (ncols < nrows ? ncols : nrows); | |
10506
bdf5d85cfc5e
replace nzmax by nnz where appropriate in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
217 octave_idx_type nnz = a.nnz (); |
5785 | 218 |
5893 | 219 if (octave_sparse_params::get_key ("spumoni") != 0.) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
220 (*current_liboctave_warning_handler) |
5785 | 221 ("Calculating Sparse Matrix Type"); |
222 | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
223 sp_bandden = octave_sparse_params::get_bandden (); |
5785 | 224 bool maybe_hermitian = false; |
225 typ = MatrixType::Full; | |
226 | |
227 if (nnz == nm) | |
228 { | |
229 matrix_type tmp_typ = MatrixType::Diagonal; | |
230 octave_idx_type i; | |
231 // Maybe the matrix is diagonal | |
232 for (i = 0; i < nm; i++) | |
10314
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 if (a.cidx (i+1) != a.cidx (i) + 1) |
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 tmp_typ = MatrixType::Full; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
237 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
238 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
239 if (a.ridx (i) != i) |
10314
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 tmp_typ = MatrixType::Permuted_Diagonal; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
242 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
243 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
244 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
245 |
5785 | 246 if (tmp_typ == MatrixType::Permuted_Diagonal) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
247 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
248 std::vector<bool> found (nrows); |
5785 | 249 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
250 for (octave_idx_type j = 0; j < i; j++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
251 found[j] = true; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
252 for (octave_idx_type j = i; j < nrows; j++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
253 found[j] = false; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
254 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
255 for (octave_idx_type j = i; j < nm; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
256 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
257 if ((a.cidx (j+1) > a.cidx (j) + 1) || |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
258 ((a.cidx (j+1) == a.cidx (j) + 1) && found[a.ridx (j)])) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
259 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
260 tmp_typ = MatrixType::Full; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
261 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
262 } |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
263 found[a.ridx (j)] = true; |
10314
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 } |
5785 | 266 typ = tmp_typ; |
267 } | |
268 | |
269 if (typ == MatrixType::Full) | |
270 { | |
271 // Search for banded, upper and lower triangular matrices | |
272 bool singular = false; | |
273 upper_band = 0; | |
274 lower_band = 0; | |
275 for (octave_idx_type j = 0; j < ncols; j++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
276 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
277 bool zero_on_diagonal = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
278 if (j < nrows) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
279 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
280 zero_on_diagonal = true; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
281 for (octave_idx_type i = a.cidx (j); i < a.cidx (j+1); i++) |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
282 if (a.ridx (i) == j) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
283 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
284 zero_on_diagonal = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
285 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
286 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
287 } |
5785 | 288 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
289 if (zero_on_diagonal) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
290 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
291 singular = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
292 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
293 } |
5785 | 294 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
295 if (a.cidx (j+1) != a.cidx (j)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
296 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
297 octave_idx_type ru = a.ridx (a.cidx (j)); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
298 octave_idx_type rl = a.ridx (a.cidx (j+1)-1); |
5785 | 299 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
300 if (j - ru > upper_band) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
301 upper_band = j - ru; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
302 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
303 if (rl - j > lower_band) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
304 lower_band = rl - j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
305 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
306 } |
5785 | 307 |
308 if (!singular) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
309 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
310 bandden = double (nnz) / |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
311 (double (ncols) * (double (lower_band) + |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
312 double (upper_band)) - |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
313 0.5 * double (upper_band + 1) * double (upper_band) - |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
314 0.5 * double (lower_band + 1) * double (lower_band)); |
5785 | 315 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
316 if (nrows == ncols && sp_bandden != 1. && bandden > sp_bandden) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
317 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
318 if (upper_band == 1 && lower_band == 1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
319 typ = MatrixType::Tridiagonal; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
320 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
321 typ = MatrixType::Banded; |
5785 | 322 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
323 octave_idx_type nnz_in_band = |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
324 (upper_band + lower_band + 1) * nrows - |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
325 (1 + upper_band) * upper_band / 2 - |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
326 (1 + lower_band) * lower_band / 2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
327 if (nnz_in_band == nnz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
328 dense = true; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
329 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
330 dense = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
331 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
332 else if (upper_band == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
333 typ = MatrixType::Lower; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
334 else if (lower_band == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
335 typ = MatrixType::Upper; |
5785 | 336 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
337 if (upper_band == lower_band && nrows == ncols) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
338 maybe_hermitian = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
339 } |
5785 | 340 |
341 if (typ == MatrixType::Full) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
342 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
343 // Search for a permuted triangular matrix, and test if |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
344 // permutation is singular |
5785 | 345 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
346 // FIXME: Perhaps this should be based on a dmperm algorithm? |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
347 bool found = false; |
5785 | 348 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
349 nperm = ncols; |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
350 perm = new octave_idx_type [ncols]; |
5785 | 351 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
352 for (octave_idx_type i = 0; i < ncols; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
353 perm[i] = -1; |
5785 | 354 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
355 for (octave_idx_type i = 0; i < nm; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
356 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
357 found = false; |
5785 | 358 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
359 for (octave_idx_type j = 0; j < ncols; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
360 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
361 if ((a.cidx (j+1) - a.cidx (j)) > 0 && |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
362 (a.ridx (a.cidx (j+1)-1) == i)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
363 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
364 perm[i] = j; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
365 found = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
366 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
367 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
368 } |
5785 | 369 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
370 if (!found) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
371 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
372 } |
5785 | 373 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
374 if (found) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
375 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
376 typ = MatrixType::Permuted_Upper; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
377 if (ncols > nrows) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
378 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
379 octave_idx_type k = nrows; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
380 for (octave_idx_type i = 0; i < ncols; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
381 if (perm[i] == -1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
382 perm[i] = k++; |
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 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
385 else if (a.cidx (nm) == a.cidx (ncols)) |
10314
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 nperm = nrows; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
388 delete [] perm; |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
389 perm = new octave_idx_type [nrows]; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
390 OCTAVE_LOCAL_BUFFER (octave_idx_type, tmp, nrows); |
5785 | 391 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
392 for (octave_idx_type i = 0; i < nrows; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
393 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
394 perm[i] = -1; |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
395 tmp[i] = -1; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
396 } |
5785 | 397 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
398 for (octave_idx_type j = 0; j < ncols; j++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
399 for (octave_idx_type i = a.cidx (j); i < a.cidx (j+1); i++) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
400 perm[a.ridx (i)] = j; |
5785 | 401 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
402 found = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
403 for (octave_idx_type i = 0; i < nm; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
404 if (perm[i] == -1) |
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 found = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
407 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
408 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
409 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
410 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
411 tmp[perm[i]] = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
412 } |
5785 | 413 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
414 if (found) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
415 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
416 octave_idx_type k = ncols; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
417 for (octave_idx_type i = 0; i < nrows; i++) |
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 if (tmp[i] == -1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
420 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
421 if (k < nrows) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
422 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
423 perm[k++] = i; |
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 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
426 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
427 found = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
428 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
429 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
430 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
431 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
432 } |
5785 | 433 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
434 if (found) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
435 typ = MatrixType::Permuted_Lower; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
436 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
437 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
438 delete [] perm; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
439 nperm = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
440 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
441 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
442 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
443 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
444 delete [] perm; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
445 nperm = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
446 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
447 } |
5785 | 448 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
449 // FIXME: Disable lower under-determined and upper over-determined |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
450 // problems as being detected, and force to treat as singular |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
451 // as this seems to cause issues. |
5785 | 452 if (((typ == MatrixType::Lower || typ == MatrixType::Permuted_Lower) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
453 && nrows > ncols) || |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
454 ((typ == MatrixType::Upper || typ == MatrixType::Permuted_Upper) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
455 && nrows < ncols)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
456 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
457 if (typ == MatrixType::Permuted_Upper || |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
458 typ == MatrixType::Permuted_Lower) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
459 delete [] perm; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
460 nperm = 0; |
14097
4804ad4ce0de
Plug memory leak in Matrixtype for sparse permuted matrices.
Rik <octave@nomad.inbox5.com>
parents:
12564
diff
changeset
|
461 typ = MatrixType::Rectangular; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
462 } |
5785 | 463 |
464 if (typ == MatrixType::Full && ncols != nrows) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
465 typ = MatrixType::Rectangular; |
5785 | 466 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
467 if (maybe_hermitian && (typ == MatrixType::Full || |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
468 typ == MatrixType::Tridiagonal || |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
469 typ == MatrixType::Banded)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
470 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
471 bool is_herm = true; |
5785 | 472 |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
473 // first, check whether the diagonal is positive & extract it |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
474 ColumnVector diag (ncols); |
5785 | 475 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
476 for (octave_idx_type j = 0; is_herm && j < ncols; j++) |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
477 { |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
478 is_herm = false; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
479 for (octave_idx_type i = a.cidx (j); i < a.cidx (j+1); i++) |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
480 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
481 if (a.ridx (i) == j) |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
482 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
483 double d = a.data (i); |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
484 is_herm = d > 0.; |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
485 diag(j) = d; |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
486 break; |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
487 } |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
488 } |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
489 } |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
490 |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
491 |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
492 // next, check symmetry and 2x2 positiveness |
5785 | 493 |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
494 for (octave_idx_type j = 0; is_herm && j < ncols; j++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
495 for (octave_idx_type i = a.cidx (j); is_herm && i < a.cidx (j+1); i++) |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
496 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
497 octave_idx_type k = a.ridx (i); |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
498 is_herm = k == j; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
499 if (is_herm) |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
500 continue; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
501 double d = a.data (i); |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
502 if (d*d < diag(j)*diag(k)) |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
503 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
504 for (octave_idx_type l = a.cidx (k); l < a.cidx (k+1); l++) |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
505 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
506 if (a.ridx (l) == j) |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
507 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
508 is_herm = a.data (l) == d; |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
509 break; |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
510 } |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
511 } |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
512 } |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
513 } |
5785 | 514 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
515 if (is_herm) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
516 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
517 if (typ == MatrixType::Full) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
518 typ = MatrixType::Hermitian; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
519 else if (typ == MatrixType::Banded) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
520 typ = MatrixType::Banded_Hermitian; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
521 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
522 typ = MatrixType::Tridiagonal_Hermitian; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
523 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
524 } |
5785 | 525 } |
526 } | |
527 | |
528 MatrixType::MatrixType (const SparseComplexMatrix &a) | |
5892 | 529 : typ (MatrixType::Unknown), |
530 sp_bandden (0), bandden (0), upper_band (0), lower_band (0), | |
531 dense (false), full (false), nperm (0), perm (0) | |
5785 | 532 { |
533 octave_idx_type nrows = a.rows (); | |
534 octave_idx_type ncols = a.cols (); | |
535 octave_idx_type nm = (ncols < nrows ? ncols : nrows); | |
10506
bdf5d85cfc5e
replace nzmax by nnz where appropriate in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
10350
diff
changeset
|
536 octave_idx_type nnz = a.nnz (); |
5785 | 537 |
5996 | 538 if (octave_sparse_params::get_key ("spumoni") != 0.) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
539 (*current_liboctave_warning_handler) |
5785 | 540 ("Calculating Sparse Matrix Type"); |
541 | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
542 sp_bandden = octave_sparse_params::get_bandden (); |
5785 | 543 bool maybe_hermitian = false; |
544 typ = MatrixType::Full; | |
545 | |
546 if (nnz == nm) | |
547 { | |
548 matrix_type tmp_typ = MatrixType::Diagonal; | |
549 octave_idx_type i; | |
550 // Maybe the matrix is diagonal | |
551 for (i = 0; i < nm; i++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
552 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
553 if (a.cidx (i+1) != a.cidx (i) + 1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
554 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
555 tmp_typ = MatrixType::Full; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
556 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
557 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
558 if (a.ridx (i) != i) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
559 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
560 tmp_typ = MatrixType::Permuted_Diagonal; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
561 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
562 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
563 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
564 |
5785 | 565 if (tmp_typ == MatrixType::Permuted_Diagonal) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
566 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
567 std::vector<bool> found (nrows); |
5785 | 568 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
569 for (octave_idx_type j = 0; j < i; j++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
570 found[j] = true; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
571 for (octave_idx_type j = i; j < nrows; j++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
572 found[j] = false; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
573 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
574 for (octave_idx_type j = i; j < nm; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
575 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
576 if ((a.cidx (j+1) > a.cidx (j) + 1) || |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
577 ((a.cidx (j+1) == a.cidx (j) + 1) && found[a.ridx (j)])) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
578 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
579 tmp_typ = MatrixType::Full; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
580 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
581 } |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
582 found[a.ridx (j)] = true; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
583 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
584 } |
5785 | 585 typ = tmp_typ; |
586 } | |
587 | |
588 if (typ == MatrixType::Full) | |
589 { | |
590 // Search for banded, upper and lower triangular matrices | |
591 bool singular = false; | |
592 upper_band = 0; | |
593 lower_band = 0; | |
594 for (octave_idx_type j = 0; j < ncols; j++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
595 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
596 bool zero_on_diagonal = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
597 if (j < nrows) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
598 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
599 zero_on_diagonal = true; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
600 for (octave_idx_type i = a.cidx (j); i < a.cidx (j+1); i++) |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
601 if (a.ridx (i) == j) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
602 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
603 zero_on_diagonal = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
604 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
605 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
606 } |
5785 | 607 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
608 if (zero_on_diagonal) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
609 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
610 singular = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
611 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
612 } |
5785 | 613 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
614 if (a.cidx (j+1) != a.cidx (j)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
615 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
616 octave_idx_type ru = a.ridx (a.cidx (j)); |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
617 octave_idx_type rl = a.ridx (a.cidx (j+1)-1); |
5785 | 618 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
619 if (j - ru > upper_band) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
620 upper_band = j - ru; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
621 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
622 if (rl - j > lower_band) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
623 lower_band = rl - j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
624 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
625 } |
5785 | 626 |
627 if (!singular) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
628 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
629 bandden = double (nnz) / |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
630 (double (ncols) * (double (lower_band) + |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
631 double (upper_band)) - |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
632 0.5 * double (upper_band + 1) * double (upper_band) - |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
633 0.5 * double (lower_band + 1) * double (lower_band)); |
5785 | 634 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
635 if (nrows == ncols && sp_bandden != 1. && bandden > sp_bandden) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
636 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
637 if (upper_band == 1 && lower_band == 1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
638 typ = MatrixType::Tridiagonal; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
639 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
640 typ = MatrixType::Banded; |
5785 | 641 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
642 octave_idx_type nnz_in_band = |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
643 (upper_band + lower_band + 1) * nrows - |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
644 (1 + upper_band) * upper_band / 2 - |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
645 (1 + lower_band) * lower_band / 2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
646 if (nnz_in_band == nnz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
647 dense = true; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
648 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
649 dense = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
650 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
651 else if (upper_band == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
652 typ = MatrixType::Lower; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
653 else if (lower_band == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
654 typ = MatrixType::Upper; |
5785 | 655 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
656 if (upper_band == lower_band && nrows == ncols) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
657 maybe_hermitian = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
658 } |
5785 | 659 |
660 if (typ == MatrixType::Full) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
661 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
662 // Search for a permuted triangular matrix, and test if |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
663 // permutation is singular |
5785 | 664 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
665 // FIXME: Perhaps this should be based on a dmperm algorithm? |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
666 bool found = false; |
5785 | 667 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
668 nperm = ncols; |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
669 perm = new octave_idx_type [ncols]; |
5785 | 670 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
671 for (octave_idx_type i = 0; i < ncols; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
672 perm[i] = -1; |
5785 | 673 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
674 for (octave_idx_type i = 0; i < nm; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
675 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
676 found = false; |
5785 | 677 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
678 for (octave_idx_type j = 0; j < ncols; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
679 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
680 if ((a.cidx (j+1) - a.cidx (j)) > 0 && |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
681 (a.ridx (a.cidx (j+1)-1) == i)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
682 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
683 perm[i] = j; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
684 found = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
685 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
686 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
687 } |
5785 | 688 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
689 if (!found) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
690 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
691 } |
5785 | 692 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
693 if (found) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
694 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
695 typ = MatrixType::Permuted_Upper; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
696 if (ncols > nrows) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
697 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
698 octave_idx_type k = nrows; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
699 for (octave_idx_type i = 0; i < ncols; i++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
700 if (perm[i] == -1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
701 perm[i] = k++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
702 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
703 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
704 else if (a.cidx (nm) == a.cidx (ncols)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
705 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
706 nperm = nrows; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
707 delete [] perm; |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
708 perm = new octave_idx_type [nrows]; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
709 OCTAVE_LOCAL_BUFFER (octave_idx_type, tmp, nrows); |
5785 | 710 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
711 for (octave_idx_type i = 0; i < nrows; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
712 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
713 perm[i] = -1; |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
714 tmp[i] = -1; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
715 } |
5785 | 716 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
717 for (octave_idx_type j = 0; j < ncols; j++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
718 for (octave_idx_type i = a.cidx (j); i < a.cidx (j+1); i++) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
719 perm[a.ridx (i)] = j; |
5785 | 720 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
721 found = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
722 for (octave_idx_type i = 0; i < nm; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
723 if (perm[i] == -1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
724 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
725 found = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
726 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
727 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
728 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
729 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
730 tmp[perm[i]] = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
731 } |
5785 | 732 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
733 if (found) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
734 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
735 octave_idx_type k = ncols; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
736 for (octave_idx_type i = 0; i < nrows; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
737 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
738 if (tmp[i] == -1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
739 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
740 if (k < nrows) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
741 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
742 perm[k++] = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
743 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
744 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
745 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
746 found = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
747 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
748 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
749 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
750 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
751 } |
5785 | 752 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
753 if (found) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
754 typ = MatrixType::Permuted_Lower; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
755 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
756 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
757 delete [] perm; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
758 nperm = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
759 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
760 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
761 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
762 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
763 delete [] perm; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
764 nperm = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
765 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
766 } |
5785 | 767 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
768 // FIXME: Disable lower under-determined and upper over-determined |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
769 // problems as being detected, and force to treat as singular |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
770 // as this seems to cause issues. |
5785 | 771 if (((typ == MatrixType::Lower || typ == MatrixType::Permuted_Lower) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
772 && nrows > ncols) || |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
773 ((typ == MatrixType::Upper || typ == MatrixType::Permuted_Upper) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
774 && nrows < ncols)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
775 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
776 if (typ == MatrixType::Permuted_Upper || |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
777 typ == MatrixType::Permuted_Lower) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
778 delete [] perm; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
779 nperm = 0; |
14097
4804ad4ce0de
Plug memory leak in Matrixtype for sparse permuted matrices.
Rik <octave@nomad.inbox5.com>
parents:
12564
diff
changeset
|
780 typ = MatrixType::Rectangular; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
781 } |
5785 | 782 |
783 if (typ == MatrixType::Full && ncols != nrows) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
784 typ = MatrixType::Rectangular; |
5785 | 785 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
786 if (maybe_hermitian && (typ == MatrixType::Full || |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
787 typ == MatrixType::Tridiagonal || |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
788 typ == MatrixType::Banded)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
789 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
790 bool is_herm = true; |
5785 | 791 |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
792 // first, check whether the diagonal is positive & extract it |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
793 ColumnVector diag (ncols); |
5785 | 794 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
795 for (octave_idx_type j = 0; is_herm && j < ncols; j++) |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
796 { |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
797 is_herm = false; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
798 for (octave_idx_type i = a.cidx (j); i < a.cidx (j+1); i++) |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
799 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
800 if (a.ridx (i) == j) |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
801 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
802 Complex d = a.data (i); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
803 is_herm = d.real () > 0. && d.imag () == 0.; |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
804 diag(j) = d.real (); |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
805 break; |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
806 } |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
807 } |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
808 } |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
809 |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
810 // next, check symmetry and 2x2 positiveness |
5785 | 811 |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
812 for (octave_idx_type j = 0; is_herm && j < ncols; j++) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
813 for (octave_idx_type i = a.cidx (j); is_herm && i < a.cidx (j+1); i++) |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
814 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
815 octave_idx_type k = a.ridx (i); |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
816 is_herm = k == j; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
817 if (is_herm) |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
818 continue; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
819 Complex d = a.data (i); |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
820 if (std::norm (d) < diag(j)*diag(k)) |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
821 { |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
822 d = std::conj (d); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
823 for (octave_idx_type l = a.cidx (k); l < a.cidx (k+1); l++) |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
824 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
825 if (a.ridx (l) == j) |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
826 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
827 is_herm = a.data (l) == d; |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
828 break; |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
829 } |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
830 } |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
831 } |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
832 } |
5785 | 833 |
834 | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
835 if (is_herm) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
836 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
837 if (typ == MatrixType::Full) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
838 typ = MatrixType::Hermitian; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
839 else if (typ == MatrixType::Banded) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
840 typ = MatrixType::Banded_Hermitian; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
841 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
842 typ = MatrixType::Tridiagonal_Hermitian; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
843 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
844 } |
5785 | 845 } |
846 } | |
5892 | 847 MatrixType::MatrixType (const matrix_type t, bool _full) |
848 : typ (MatrixType::Unknown), | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
849 sp_bandden (octave_sparse_params::get_bandden ()), |
5892 | 850 bandden (0), upper_band (0), lower_band (0), |
851 dense (false), full (_full), nperm (0), perm (0) | |
5785 | 852 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
853 if (t == MatrixType::Unknown || t == MatrixType::Full |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
854 || t == MatrixType::Diagonal || t == MatrixType::Permuted_Diagonal |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
855 || t == MatrixType::Upper || t == MatrixType::Lower |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
856 || t == MatrixType::Tridiagonal || t == MatrixType::Tridiagonal_Hermitian |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
857 || t == MatrixType::Rectangular) |
5785 | 858 typ = t; |
859 else | |
860 (*current_liboctave_warning_handler) ("Invalid matrix type"); | |
861 } | |
862 | |
863 MatrixType::MatrixType (const matrix_type t, const octave_idx_type np, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
864 const octave_idx_type *p, bool _full) |
5892 | 865 : typ (MatrixType::Unknown), |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
866 sp_bandden (octave_sparse_params::get_bandden ()), |
5892 | 867 bandden (0), upper_band (0), lower_band (0), |
868 dense (false), full (_full), nperm (0), perm (0) | |
5785 | 869 { |
6027 | 870 if ((t == MatrixType::Permuted_Upper || t == MatrixType::Permuted_Lower) && |
871 np > 0 && p != 0) | |
5785 | 872 { |
873 typ = t; | |
874 nperm = np; | |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
875 perm = new octave_idx_type [nperm]; |
5785 | 876 for (octave_idx_type i = 0; i < nperm; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
877 perm[i] = p[i]; |
5785 | 878 } |
879 else | |
880 (*current_liboctave_warning_handler) ("Invalid matrix type"); | |
881 } | |
882 | |
883 MatrixType::MatrixType (const matrix_type t, const octave_idx_type ku, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
884 const octave_idx_type kl, bool _full) |
5892 | 885 : typ (MatrixType::Unknown), |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
886 sp_bandden (octave_sparse_params::get_bandden ()), |
5892 | 887 bandden (0), upper_band (0), lower_band (0), |
888 dense (false), full (_full), nperm (0), perm (0) | |
5785 | 889 { |
890 if (t == MatrixType::Banded || t == MatrixType::Banded_Hermitian) | |
891 { | |
892 typ = t; | |
893 upper_band = ku; | |
894 lower_band = kl; | |
895 } | |
896 else | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
897 (*current_liboctave_warning_handler) ("Invalid sparse matrix type"); |
5785 | 898 } |
899 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
900 MatrixType::~MatrixType (void) |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
901 { |
5785 | 902 if (nperm != 0) |
903 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
904 delete [] perm; |
5785 | 905 } |
906 } | |
907 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
908 MatrixType& |
5785 | 909 MatrixType::operator = (const MatrixType& a) |
910 { | |
911 if (this != &a) | |
912 { | |
913 typ = a.typ; | |
914 sp_bandden = a.sp_bandden; | |
915 bandden = a.bandden; | |
916 upper_band = a.upper_band; | |
917 lower_band = a.lower_band; | |
918 dense = a.dense; | |
919 full = a.full; | |
920 | |
12564
61cd086e9aeb
Correct slight logical mistake in memleak patch (bug #32804)
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12563
diff
changeset
|
921 if (nperm) |
61cd086e9aeb
Correct slight logical mistake in memleak patch (bug #32804)
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12563
diff
changeset
|
922 { |
61cd086e9aeb
Correct slight logical mistake in memleak patch (bug #32804)
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12563
diff
changeset
|
923 delete[] perm; |
61cd086e9aeb
Correct slight logical mistake in memleak patch (bug #32804)
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12563
diff
changeset
|
924 } |
61cd086e9aeb
Correct slight logical mistake in memleak patch (bug #32804)
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12563
diff
changeset
|
925 |
12563
681bb733f4f4
MatrixType:: plug memory leak (bug #32804).
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
926 if (a.nperm != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
927 { |
12563
681bb733f4f4
MatrixType:: plug memory leak (bug #32804).
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
928 perm = new octave_idx_type [a.nperm]; |
681bb733f4f4
MatrixType:: plug memory leak (bug #32804).
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
929 for (octave_idx_type i = 0; i < a.nperm; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
930 perm[i] = a.perm[i]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
931 } |
12563
681bb733f4f4
MatrixType:: plug memory leak (bug #32804).
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
932 |
681bb733f4f4
MatrixType:: plug memory leak (bug #32804).
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
933 nperm = a.nperm; |
5785 | 934 } |
935 | |
936 return *this; | |
937 } | |
938 | |
939 int | |
940 MatrixType::type (bool quiet) | |
941 { | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
942 if (typ != MatrixType::Unknown |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
943 && (full || sp_bandden == octave_sparse_params::get_bandden ())) |
5785 | 944 { |
945 if (!quiet && | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
946 octave_sparse_params::get_key ("spumoni") != 0.) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
947 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
948 ("Using Cached Matrix Type"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
949 |
5785 | 950 return typ; |
951 } | |
952 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
953 if (typ != MatrixType::Unknown && |
5893 | 954 octave_sparse_params::get_key ("spumoni") != 0.) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
955 (*current_liboctave_warning_handler) |
5785 | 956 ("Invalidating Matrix Type"); |
957 | |
958 typ = MatrixType::Unknown; | |
959 | |
960 return typ; | |
961 } | |
962 | |
963 int | |
964 MatrixType::type (const SparseMatrix &a) | |
965 { | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
966 if (typ != MatrixType::Unknown |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
967 && (full || sp_bandden == octave_sparse_params::get_bandden ())) |
5785 | 968 { |
5893 | 969 if (octave_sparse_params::get_key ("spumoni") != 0.) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
970 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
971 ("Using Cached Matrix Type"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
972 |
5785 | 973 return typ; |
974 } | |
975 | |
976 MatrixType tmp_typ (a); | |
977 typ = tmp_typ.typ; | |
978 sp_bandden = tmp_typ.sp_bandden; | |
979 bandden = tmp_typ.bandden; | |
980 upper_band = tmp_typ.upper_band; | |
981 lower_band = tmp_typ.lower_band; | |
982 dense = tmp_typ.dense; | |
983 full = tmp_typ.full; | |
984 nperm = tmp_typ.nperm; | |
985 | |
986 if (nperm != 0) | |
987 { | |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
988 perm = new octave_idx_type [nperm]; |
5785 | 989 for (octave_idx_type i = 0; i < nperm; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
990 perm[i] = tmp_typ.perm[i]; |
5785 | 991 } |
992 | |
993 return typ; | |
994 } | |
995 | |
996 int | |
997 MatrixType::type (const SparseComplexMatrix &a) | |
998 { | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
999 if (typ != MatrixType::Unknown |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1000 && (full || sp_bandden == octave_sparse_params::get_bandden ())) |
5785 | 1001 { |
5893 | 1002 if (octave_sparse_params::get_key ("spumoni") != 0.) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1003 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1004 ("Using Cached Matrix Type"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1005 |
5785 | 1006 return typ; |
1007 } | |
1008 | |
1009 MatrixType tmp_typ (a); | |
1010 typ = tmp_typ.typ; | |
1011 sp_bandden = tmp_typ.sp_bandden; | |
1012 bandden = tmp_typ.bandden; | |
1013 upper_band = tmp_typ.upper_band; | |
1014 lower_band = tmp_typ.lower_band; | |
1015 dense = tmp_typ.dense; | |
1016 full = tmp_typ.full; | |
1017 nperm = tmp_typ.nperm; | |
1018 | |
1019 if (nperm != 0) | |
1020 { | |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
1021 perm = new octave_idx_type [nperm]; |
5785 | 1022 for (octave_idx_type i = 0; i < nperm; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1023 perm[i] = tmp_typ.perm[i]; |
5785 | 1024 } |
1025 | |
1026 return typ; | |
1027 } | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1028 |
5785 | 1029 int |
1030 MatrixType::type (const Matrix &a) | |
1031 { | |
1032 if (typ != MatrixType::Unknown) | |
1033 { | |
5893 | 1034 if (octave_sparse_params::get_key ("spumoni") != 0.) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1035 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1036 ("Using Cached Matrix Type"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1037 |
5785 | 1038 return typ; |
1039 } | |
1040 | |
1041 MatrixType tmp_typ (a); | |
1042 typ = tmp_typ.typ; | |
1043 full = tmp_typ.full; | |
1044 nperm = tmp_typ.nperm; | |
1045 | |
1046 if (nperm != 0) | |
1047 { | |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
1048 perm = new octave_idx_type [nperm]; |
5785 | 1049 for (octave_idx_type i = 0; i < nperm; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1050 perm[i] = tmp_typ.perm[i]; |
5785 | 1051 } |
1052 | |
1053 return typ; | |
1054 } | |
1055 | |
1056 int | |
1057 MatrixType::type (const ComplexMatrix &a) | |
1058 { | |
1059 if (typ != MatrixType::Unknown) | |
1060 { | |
5893 | 1061 if (octave_sparse_params::get_key ("spumoni") != 0.) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1062 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1063 ("Using Cached Matrix Type"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1064 |
5785 | 1065 return typ; |
1066 } | |
1067 | |
1068 MatrixType tmp_typ (a); | |
1069 typ = tmp_typ.typ; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1070 full = tmp_typ.full; |
5785 | 1071 nperm = tmp_typ.nperm; |
1072 | |
1073 if (nperm != 0) | |
1074 { | |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
1075 perm = new octave_idx_type [nperm]; |
5785 | 1076 for (octave_idx_type i = 0; i < nperm; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1077 perm[i] = tmp_typ.perm[i]; |
5785 | 1078 } |
1079 | |
1080 return typ; | |
1081 } | |
1082 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1083 int |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1084 MatrixType::type (const FloatMatrix &a) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1085 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1086 if (typ != MatrixType::Unknown) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1087 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1088 if (octave_sparse_params::get_key ("spumoni") != 0.) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1089 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1090 ("Using Cached Matrix Type"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1091 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1092 return typ; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1093 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1094 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1095 MatrixType tmp_typ (a); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1096 typ = tmp_typ.typ; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1097 full = tmp_typ.full; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1098 nperm = tmp_typ.nperm; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1099 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1100 if (nperm != 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1101 { |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
1102 perm = new octave_idx_type [nperm]; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1103 for (octave_idx_type i = 0; i < nperm; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1104 perm[i] = tmp_typ.perm[i]; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1105 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1106 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1107 return typ; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1108 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1109 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1110 int |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1111 MatrixType::type (const FloatComplexMatrix &a) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1112 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1113 if (typ != MatrixType::Unknown) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1114 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1115 if (octave_sparse_params::get_key ("spumoni") != 0.) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1116 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1117 ("Using Cached Matrix Type"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1118 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1119 return typ; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1120 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1121 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1122 MatrixType tmp_typ (a); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1123 typ = tmp_typ.typ; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1124 full = tmp_typ.full; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1125 nperm = tmp_typ.nperm; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1126 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1127 if (nperm != 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1128 { |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
1129 perm = new octave_idx_type [nperm]; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1130 for (octave_idx_type i = 0; i < nperm; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1131 perm[i] = tmp_typ.perm[i]; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1132 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1133 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1134 return typ; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1135 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
1136 |
5785 | 1137 void |
1138 MatrixType::info () const | |
1139 { | |
5893 | 1140 if (octave_sparse_params::get_key ("spumoni") != 0.) |
5785 | 1141 { |
1142 if (typ == MatrixType::Unknown) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1143 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1144 ("Unknown Matrix Type"); |
5785 | 1145 else if (typ == MatrixType::Diagonal) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1146 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1147 ("Diagonal Sparse Matrix"); |
5785 | 1148 else if (typ == MatrixType::Permuted_Diagonal) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1149 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1150 ("Permuted Diagonal Sparse Matrix"); |
5785 | 1151 else if (typ == MatrixType::Upper) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1152 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1153 ("Upper Triangular Matrix"); |
5785 | 1154 else if (typ == MatrixType::Lower) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1155 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1156 ("Lower Triangular Matrix"); |
5785 | 1157 else if (typ == MatrixType::Permuted_Upper) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1158 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1159 ("Permuted Upper Triangular Matrix"); |
5785 | 1160 else if (typ == MatrixType::Permuted_Lower) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1161 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1162 ("Permuted Lower Triangular Matrix"); |
5785 | 1163 else if (typ == MatrixType::Banded) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1164 (*current_liboctave_warning_handler) |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1165 ("Banded Sparse Matrix %d-1-%d (Density %f)", lower_band, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1166 upper_band, bandden); |
5785 | 1167 else if (typ == MatrixType::Banded_Hermitian) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1168 (*current_liboctave_warning_handler) |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1169 ("Banded Hermitian/Symmetric Sparse Matrix %d-1-%d (Density %f)", |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1170 lower_band, upper_band, bandden); |
5785 | 1171 else if (typ == MatrixType::Hermitian) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1172 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1173 ("Hermitian/Symmetric Matrix"); |
5785 | 1174 else if (typ == MatrixType::Tridiagonal) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1175 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1176 ("Tridiagonal Sparse Matrix"); |
5785 | 1177 else if (typ == MatrixType::Tridiagonal_Hermitian) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1178 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1179 ("Hermitian/Symmetric Tridiagonal Sparse Matrix"); |
5785 | 1180 else if (typ == MatrixType::Rectangular) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1181 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1182 ("Rectangular/Singular Matrix"); |
5785 | 1183 else if (typ == MatrixType::Full) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1184 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1185 ("Full Matrix"); |
5785 | 1186 } |
1187 } | |
1188 | |
1189 void | |
1190 MatrixType::mark_as_symmetric (void) | |
1191 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1192 if (typ == MatrixType::Tridiagonal || |
5785 | 1193 typ == MatrixType::Tridiagonal_Hermitian) |
1194 typ = MatrixType::Tridiagonal_Hermitian; | |
1195 else if (typ == MatrixType::Banded || | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1196 typ == MatrixType::Banded_Hermitian) |
5785 | 1197 typ = MatrixType::Banded_Hermitian; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1198 else if (typ == MatrixType::Full || typ == MatrixType::Hermitian || |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1199 typ == MatrixType::Unknown) |
5785 | 1200 typ = MatrixType::Hermitian; |
1201 else | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1202 (*current_liboctave_error_handler) |
5785 | 1203 ("Can not mark current matrix type as symmetric"); |
1204 } | |
1205 | |
1206 void | |
1207 MatrixType::mark_as_unsymmetric (void) | |
1208 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1209 if (typ == MatrixType::Tridiagonal || |
5785 | 1210 typ == MatrixType::Tridiagonal_Hermitian) |
1211 typ = MatrixType::Tridiagonal; | |
1212 else if (typ == MatrixType::Banded || | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1213 typ == MatrixType::Banded_Hermitian) |
5785 | 1214 typ = MatrixType::Banded; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1215 else if (typ == MatrixType::Full || typ == MatrixType::Hermitian || |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1216 typ == MatrixType::Unknown) |
5785 | 1217 typ = MatrixType::Full; |
1218 } | |
1219 | |
1220 void | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1221 MatrixType::mark_as_permuted (const octave_idx_type np, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1222 const octave_idx_type *p) |
5785 | 1223 { |
1224 nperm = np; | |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
1225 perm = new octave_idx_type [nperm]; |
5785 | 1226 for (octave_idx_type i = 0; i < nperm; i++) |
1227 perm[i] = p[i]; | |
1228 | |
1229 if (typ == MatrixType::Diagonal || typ == MatrixType::Permuted_Diagonal) | |
1230 typ = MatrixType::Permuted_Diagonal; | |
1231 else if (typ == MatrixType::Upper || typ == MatrixType::Permuted_Upper) | |
1232 typ = MatrixType::Permuted_Upper; | |
1233 else if (typ == MatrixType::Lower || typ == MatrixType::Permuted_Lower) | |
1234 typ = MatrixType::Permuted_Lower; | |
1235 else | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1236 (*current_liboctave_error_handler) |
5785 | 1237 ("Can not mark current matrix type as symmetric"); |
1238 } | |
1239 | |
1240 void | |
1241 MatrixType::mark_as_unpermuted (void) | |
1242 { | |
1243 if (nperm) | |
1244 { | |
1245 nperm = 0; | |
1246 delete [] perm; | |
1247 } | |
1248 | |
1249 if (typ == MatrixType::Diagonal || typ == MatrixType::Permuted_Diagonal) | |
1250 typ = MatrixType::Diagonal; | |
1251 else if (typ == MatrixType::Upper || typ == MatrixType::Permuted_Upper) | |
1252 typ = MatrixType::Upper; | |
1253 else if (typ == MatrixType::Lower || typ == MatrixType::Permuted_Lower) | |
1254 typ = MatrixType::Lower; | |
1255 } | |
1256 | |
1257 MatrixType | |
1258 MatrixType::transpose (void) const | |
1259 { | |
1260 MatrixType retval (*this); | |
1261 if (typ == MatrixType::Upper) | |
1262 retval.typ = MatrixType::Lower; | |
1263 else if (typ == MatrixType::Permuted_Upper) | |
1264 retval.typ = MatrixType::Permuted_Lower; | |
1265 else if (typ == MatrixType::Lower) | |
1266 retval.typ = MatrixType::Upper; | |
1267 else if (typ == MatrixType::Permuted_Lower) | |
1268 retval.typ = MatrixType::Permuted_Upper; | |
1269 else if (typ == MatrixType::Banded) | |
1270 { | |
1271 retval.upper_band = lower_band; | |
1272 retval.lower_band = upper_band; | |
1273 } | |
1274 | |
1275 return retval; | |
1276 } |