Mercurial > octave
annotate liboctave/array/MatrixType.cc @ 22246:fa917f1f0faf
MatrixType: remove duplicate code for SparseMatrix and ComplexSparseMatrix.
* liboctave/array/MatrixType.cc: constructor for SparseMatrix and
ComplexSparseMatrix is exactly the same. With C++11, we have conj,
norm, real, and imag functions overloaded for double and float that
behave as we would want them to.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Wed, 10 Aug 2016 00:56:51 +0100 |
parents | 71d86e88589f |
children | edcad35c364f |
rev | line source |
---|---|
5785 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19410
diff
changeset
|
3 Copyright (C) 2006-2015 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 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
25 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
26 # include "config.h" |
5785 | 27 #endif |
28 | |
29 #include <vector> | |
30 | |
31 #include "MatrixType.h" | |
32 #include "dMatrix.h" | |
19269
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
18676
diff
changeset
|
33 #include "fMatrix.h" |
5785 | 34 #include "CMatrix.h" |
19269
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
18676
diff
changeset
|
35 #include "fCMatrix.h" |
5785 | 36 #include "dSparse.h" |
37 #include "CSparse.h" | |
38 #include "oct-spparms.h" | |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
7798
diff
changeset
|
39 #include "oct-locbuf.h" |
5785 | 40 |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
41 static void |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
42 warn_cached (void) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
43 { |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
44 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
45 ("Octave:matrix-type-info", "using cached matrix type"); |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
46 } |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
47 |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
48 static void |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
49 warn_invalid (void) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
50 { |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
51 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
52 ("Octave:matrix-type-info", "invalid matrix type"); |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
53 } |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
54 |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
55 static void |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
56 warn_calculating_sparse_type (void) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
57 { |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
58 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
59 ("Octave:matrix-type-info", "calculating sparse matrix type"); |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
60 } |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
61 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
62 // FIXME: There is a large code duplication here |
5785 | 63 |
5892 | 64 MatrixType::MatrixType (void) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
65 : 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
|
66 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
|
67 bandden (0), upper_band (0), |
6452 | 68 lower_band (0), dense (false), full (false), nperm (0), perm (0) { } |
5785 | 69 |
5892 | 70 MatrixType::MatrixType (const MatrixType &a) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
71 : 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
|
72 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
|
73 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
|
74 { |
5785 | 75 if (nperm != 0) |
76 { | |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
77 perm = new octave_idx_type [nperm]; |
5785 | 78 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
|
79 perm[i] = a.perm[i]; |
5785 | 80 } |
81 } | |
82 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
83 template <typename T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
84 MatrixType::matrix_type |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
85 matrix_real_probe (const MArray<T>& a) |
5785 | 86 { |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
87 MatrixType::matrix_type typ; |
5785 | 88 octave_idx_type nrows = a.rows (); |
89 octave_idx_type ncols = a.cols (); | |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
90 |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
91 const T zero = 0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
92 |
5785 | 93 if (ncols == nrows) |
94 { | |
95 bool upper = true; | |
96 bool lower = true; | |
97 bool hermitian = true; | |
98 | |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
99 // 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
|
100 OCTAVE_LOCAL_BUFFER (T, diag, ncols); |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
101 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
102 for (octave_idx_type j = 0; |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
103 j < ncols && upper; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
104 { |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
105 T d = a.elem (j,j); |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
106 upper = upper && (d != zero); |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
107 lower = lower && (d != zero); |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
108 hermitian = hermitian && (d > zero); |
10713
0e05ed9f2a62
improve some MatrixType code
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
109 diag[j] = d; |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
110 } |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
111 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
112 for (octave_idx_type j = 0; |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
113 j < ncols && (upper || lower || hermitian); j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
114 { |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
115 for (octave_idx_type i = 0; i < j; i++) |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
116 { |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
117 double aij = a.elem (i,j); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
118 double aji = a.elem (j,i); |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
119 lower = lower && (aij == zero); |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
120 upper = upper && (aji == zero); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
121 hermitian = hermitian && (aij == aji |
10713
0e05ed9f2a62
improve some MatrixType code
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
122 && aij*aij < diag[i]*diag[j]); |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
123 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
124 } |
5785 | 125 |
126 if (upper) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
127 typ = MatrixType::Upper; |
5785 | 128 else if (lower) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
129 typ = MatrixType::Lower; |
5785 | 130 else if (hermitian) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
131 typ = MatrixType::Hermitian; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
132 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
133 typ = MatrixType::Full; |
5785 | 134 } |
135 else | |
136 typ = MatrixType::Rectangular; | |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
137 |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
138 return typ; |
5785 | 139 } |
140 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
20955
diff
changeset
|
141 template <typename T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
142 MatrixType::matrix_type |
10713
0e05ed9f2a62
improve some MatrixType code
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
143 matrix_complex_probe (const MArray<std::complex<T> >& a) |
5785 | 144 { |
18676
5bd1ca29c5f0
Clean up questionable code bits identified by clang sanitize.
Rik <rik@octave.org>
parents:
18084
diff
changeset
|
145 MatrixType::matrix_type typ = MatrixType::Unknown; |
5785 | 146 octave_idx_type nrows = a.rows (); |
147 octave_idx_type ncols = a.cols (); | |
148 | |
10713
0e05ed9f2a62
improve some MatrixType code
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
149 const T zero = 0; |
0e05ed9f2a62
improve some MatrixType code
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
150 // get the real type |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
151 |
5785 | 152 if (ncols == nrows) |
153 { | |
154 bool upper = true; | |
155 bool lower = true; | |
156 bool hermitian = true; | |
157 | |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
158 // 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
|
159 OCTAVE_LOCAL_BUFFER (T, diag, ncols); |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
160 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
161 for (octave_idx_type j = 0; |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
162 j < ncols && upper; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
163 { |
10713
0e05ed9f2a62
improve some MatrixType code
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
164 std::complex<T> d = a.elem (j,j); |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
165 upper = upper && (d != zero); |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
166 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
|
167 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
|
168 diag[j] = d.real (); |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
169 } |
5785 | 170 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
171 for (octave_idx_type j = 0; |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
172 j < ncols && (upper || lower || hermitian); j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
173 { |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
174 for (octave_idx_type i = 0; i < j; i++) |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
175 { |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
176 std::complex<T> aij = a.elem (i,j); |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
177 std::complex<T> aji = a.elem (j,i); |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
178 lower = lower && (aij == zero); |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
179 upper = upper && (aji == zero); |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
180 hermitian = hermitian && (aij == std::conj (aji) |
10713
0e05ed9f2a62
improve some MatrixType code
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
181 && std::norm (aij) < diag[i]*diag[j]); |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
182 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
183 } |
5785 | 184 |
185 if (upper) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
186 typ = MatrixType::Upper; |
5785 | 187 else if (lower) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
188 typ = MatrixType::Lower; |
5785 | 189 else if (hermitian) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
190 typ = MatrixType::Hermitian; |
5785 | 191 else if (ncols == nrows) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
192 typ = MatrixType::Full; |
5785 | 193 } |
194 else | |
195 typ = MatrixType::Rectangular; | |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
196 |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
197 return typ; |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
198 } |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
199 |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
200 MatrixType::MatrixType (const Matrix &a) |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
201 : typ (MatrixType::Unknown), |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
202 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
|
203 dense (false), full (true), nperm (0), perm (0) |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
204 { |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
205 typ = matrix_real_probe (a); |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
206 } |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
207 |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
208 MatrixType::MatrixType (const ComplexMatrix &a) |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
209 : typ (MatrixType::Unknown), |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
210 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
|
211 dense (false), full (true), nperm (0), perm (0) |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
212 { |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
213 typ = matrix_complex_probe (a); |
5785 | 214 } |
215 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
216 MatrixType::MatrixType (const FloatMatrix &a) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
217 : typ (MatrixType::Unknown), |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
218 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
|
219 dense (false), full (true), nperm (0), perm (0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
220 { |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
221 typ = matrix_real_probe (a); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
222 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
223 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
224 MatrixType::MatrixType (const FloatComplexMatrix &a) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
225 : typ (MatrixType::Unknown), |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
226 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
|
227 dense (false), full (true), nperm (0), perm (0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
228 { |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
229 typ = matrix_complex_probe (a); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
230 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
231 |
22246
fa917f1f0faf
MatrixType: remove duplicate code for SparseMatrix and ComplexSparseMatrix.
Carnë Draug <carandraug@octave.org>
parents:
22241
diff
changeset
|
232 |
fa917f1f0faf
MatrixType: remove duplicate code for SparseMatrix and ComplexSparseMatrix.
Carnë Draug <carandraug@octave.org>
parents:
22241
diff
changeset
|
233 template <typename T> |
fa917f1f0faf
MatrixType: remove duplicate code for SparseMatrix and ComplexSparseMatrix.
Carnë Draug <carandraug@octave.org>
parents:
22241
diff
changeset
|
234 MatrixType::MatrixType (const MSparse<T>& a) |
5892 | 235 : typ (MatrixType::Unknown), |
236 sp_bandden (0), bandden (0), upper_band (0), lower_band (0), | |
237 dense (false), full (false), nperm (0), perm (0) | |
5785 | 238 { |
239 octave_idx_type nrows = a.rows (); | |
240 octave_idx_type ncols = a.cols (); | |
241 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
|
242 octave_idx_type nnz = a.nnz (); |
5785 | 243 |
5893 | 244 if (octave_sparse_params::get_key ("spumoni") != 0.) |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
245 warn_calculating_sparse_type (); |
5785 | 246 |
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
|
247 sp_bandden = octave_sparse_params::get_bandden (); |
5785 | 248 bool maybe_hermitian = false; |
249 typ = MatrixType::Full; | |
250 | |
251 if (nnz == nm) | |
252 { | |
253 matrix_type tmp_typ = MatrixType::Diagonal; | |
254 octave_idx_type i; | |
255 // Maybe the matrix is diagonal | |
256 for (i = 0; i < nm; i++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
257 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
258 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
|
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 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
263 if (a.ridx (i) != i) |
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 tmp_typ = MatrixType::Permuted_Diagonal; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
266 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
267 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
268 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
269 |
5785 | 270 if (tmp_typ == MatrixType::Permuted_Diagonal) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
271 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
272 std::vector<bool> found (nrows); |
5785 | 273 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
274 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
|
275 found[j] = true; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
276 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
|
277 found[j] = false; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
278 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
279 for (octave_idx_type j = i; j < nm; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
280 { |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
281 if ((a.cidx (j+1) > a.cidx (j) + 1) |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
282 || ((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
|
283 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
284 tmp_typ = MatrixType::Full; |
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 } |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
287 found[a.ridx (j)] = true; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
288 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
289 } |
5785 | 290 typ = tmp_typ; |
291 } | |
292 | |
293 if (typ == MatrixType::Full) | |
294 { | |
295 // Search for banded, upper and lower triangular matrices | |
296 bool singular = false; | |
297 upper_band = 0; | |
298 lower_band = 0; | |
299 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
|
300 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
301 bool zero_on_diagonal = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
302 if (j < nrows) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
303 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
304 zero_on_diagonal = true; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
305 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
|
306 if (a.ridx (i) == j) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
307 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
308 zero_on_diagonal = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
309 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
310 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
311 } |
5785 | 312 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
313 if (zero_on_diagonal) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
314 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
315 singular = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
316 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
317 } |
5785 | 318 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
319 if (a.cidx (j+1) != a.cidx (j)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
320 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
321 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
|
322 octave_idx_type rl = a.ridx (a.cidx (j+1)-1); |
5785 | 323 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
324 if (j - ru > upper_band) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
325 upper_band = j - ru; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
326 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
327 if (rl - j > lower_band) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
328 lower_band = rl - j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
329 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
330 } |
5785 | 331 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
332 if (! singular) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
333 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
334 bandden = double (nnz) / |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
335 (double (ncols) * (double (lower_band) + |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
336 double (upper_band)) - |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
337 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
|
338 0.5 * double (lower_band + 1) * double (lower_band)); |
5785 | 339 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
340 if (nrows == ncols && sp_bandden != 1. && bandden > sp_bandden) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
341 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
342 if (upper_band == 1 && lower_band == 1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
343 typ = MatrixType::Tridiagonal; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
344 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
345 typ = MatrixType::Banded; |
5785 | 346 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
347 octave_idx_type nnz_in_band = |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
348 (upper_band + lower_band + 1) * nrows - |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
349 (1 + upper_band) * upper_band / 2 - |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
350 (1 + lower_band) * lower_band / 2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
351 if (nnz_in_band == nnz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
352 dense = true; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
353 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
354 dense = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
355 } |
22241
71d86e88589f
chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22022
diff
changeset
|
356 |
71d86e88589f
chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22022
diff
changeset
|
357 // If a matrix is Banded but also Upper/Lower, set to the latter. |
71d86e88589f
chol2inv: fix support for sparse matrices by fixing MatrixType (bug #36437)
Barbara Locsi <locsi.barbara@gmail.com>
parents:
22022
diff
changeset
|
358 if (upper_band == 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
359 typ = MatrixType::Lower; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
360 else if (lower_band == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
361 typ = MatrixType::Upper; |
5785 | 362 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
363 if (upper_band == lower_band && nrows == ncols) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
364 maybe_hermitian = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
365 } |
5785 | 366 |
367 if (typ == MatrixType::Full) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
368 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
369 // Search for a permuted triangular matrix, and test if |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
370 // permutation is singular |
5785 | 371 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
372 // 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
|
373 bool found = false; |
5785 | 374 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
375 nperm = ncols; |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
376 perm = new octave_idx_type [ncols]; |
5785 | 377 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
378 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
|
379 perm[i] = -1; |
5785 | 380 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
381 for (octave_idx_type i = 0; i < nm; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
382 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
383 found = false; |
5785 | 384 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
385 for (octave_idx_type j = 0; j < ncols; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
386 { |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
387 if ((a.cidx (j+1) - a.cidx (j)) > 0 |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
388 && (a.ridx (a.cidx (j+1)-1) == i)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
389 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
390 perm[i] = j; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
391 found = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
392 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
393 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
394 } |
5785 | 395 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
396 if (! found) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
397 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
398 } |
5785 | 399 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
400 if (found) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
401 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
402 typ = MatrixType::Permuted_Upper; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
403 if (ncols > nrows) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
404 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
405 octave_idx_type k = nrows; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
406 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
|
407 if (perm[i] == -1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
408 perm[i] = k++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
409 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
410 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
411 else if (a.cidx (nm) == a.cidx (ncols)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
412 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
413 nperm = nrows; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
414 delete [] perm; |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
415 perm = new octave_idx_type [nrows]; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
416 OCTAVE_LOCAL_BUFFER (octave_idx_type, tmp, nrows); |
5785 | 417 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
418 for (octave_idx_type i = 0; i < nrows; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
419 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
420 perm[i] = -1; |
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
421 tmp[i] = -1; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
422 } |
5785 | 423 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
424 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
|
425 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
|
426 perm[a.ridx (i)] = j; |
5785 | 427 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
428 found = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
429 for (octave_idx_type i = 0; i < nm; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
430 if (perm[i] == -1) |
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 found = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
433 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
434 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
435 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
436 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
437 tmp[perm[i]] = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
438 } |
5785 | 439 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
440 if (found) |
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 octave_idx_type k = ncols; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
443 for (octave_idx_type i = 0; i < nrows; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
444 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
445 if (tmp[i] == -1) |
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 if (k < nrows) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
448 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
449 perm[k++] = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
450 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
451 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
452 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
453 found = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
454 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
455 } |
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 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
458 } |
5785 | 459 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
460 if (found) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
461 typ = MatrixType::Permuted_Lower; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
462 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
463 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
464 delete [] perm; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
465 nperm = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
466 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
467 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
468 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
469 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
470 delete [] perm; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
471 nperm = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
472 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
473 } |
5785 | 474 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
475 // 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
|
476 // 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
|
477 // as this seems to cause issues. |
5785 | 478 if (((typ == MatrixType::Lower || typ == MatrixType::Permuted_Lower) |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
479 && nrows > ncols) |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
480 || ((typ == MatrixType::Upper || typ == MatrixType::Permuted_Upper) |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
481 && nrows < ncols)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
482 { |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
483 if (typ == MatrixType::Permuted_Upper |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
484 || typ == MatrixType::Permuted_Lower) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
485 delete [] perm; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
486 nperm = 0; |
14097
4804ad4ce0de
Plug memory leak in Matrixtype for sparse permuted matrices.
Rik <octave@nomad.inbox5.com>
parents:
12564
diff
changeset
|
487 typ = MatrixType::Rectangular; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
488 } |
5785 | 489 |
490 if (typ == MatrixType::Full && ncols != nrows) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
491 typ = MatrixType::Rectangular; |
5785 | 492 |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
493 if (maybe_hermitian && (typ == MatrixType::Full |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
494 || typ == MatrixType::Tridiagonal |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
495 || typ == MatrixType::Banded)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
496 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
497 bool is_herm = true; |
5785 | 498 |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
499 // first, check whether the diagonal is positive & extract it |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
500 ColumnVector diag (ncols); |
5785 | 501 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
502 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
|
503 { |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
504 is_herm = false; |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
505 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
|
506 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
507 if (a.ridx (i) == j) |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
508 { |
22246
fa917f1f0faf
MatrixType: remove duplicate code for SparseMatrix and ComplexSparseMatrix.
Carnë Draug <carandraug@octave.org>
parents:
22241
diff
changeset
|
509 T d = a.data (i); |
fa917f1f0faf
MatrixType: remove duplicate code for SparseMatrix and ComplexSparseMatrix.
Carnë Draug <carandraug@octave.org>
parents:
22241
diff
changeset
|
510 is_herm = std::real (d) > 0.0 && std::imag (d) == 0.0; |
fa917f1f0faf
MatrixType: remove duplicate code for SparseMatrix and ComplexSparseMatrix.
Carnë Draug <carandraug@octave.org>
parents:
22241
diff
changeset
|
511 diag(j) = std::real (d); |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
512 break; |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
513 } |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
514 } |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
515 } |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
516 |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
517 // next, check symmetry and 2x2 positiveness |
5785 | 518 |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
519 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
|
520 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
|
521 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
522 octave_idx_type k = a.ridx (i); |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
523 is_herm = k == j; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
524 if (is_herm) |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
525 continue; |
5785 | 526 |
22246
fa917f1f0faf
MatrixType: remove duplicate code for SparseMatrix and ComplexSparseMatrix.
Carnë Draug <carandraug@octave.org>
parents:
22241
diff
changeset
|
527 T d = a.data (i); |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
528 if (std::norm (d) < diag(j)*diag(k)) |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
529 { |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
530 d = std::conj (d); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
531 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
|
532 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
533 if (a.ridx (l) == j) |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
534 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
535 is_herm = a.data (l) == d; |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
536 break; |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
537 } |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
538 } |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
539 } |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
540 } |
5785 | 541 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
542 if (is_herm) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
543 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
544 if (typ == MatrixType::Full) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
545 typ = MatrixType::Hermitian; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
546 else if (typ == MatrixType::Banded) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
547 typ = MatrixType::Banded_Hermitian; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
548 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
549 typ = MatrixType::Tridiagonal_Hermitian; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
550 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
551 } |
5785 | 552 } |
553 } | |
22246
fa917f1f0faf
MatrixType: remove duplicate code for SparseMatrix and ComplexSparseMatrix.
Carnë Draug <carandraug@octave.org>
parents:
22241
diff
changeset
|
554 |
fa917f1f0faf
MatrixType: remove duplicate code for SparseMatrix and ComplexSparseMatrix.
Carnë Draug <carandraug@octave.org>
parents:
22241
diff
changeset
|
555 |
5892 | 556 MatrixType::MatrixType (const matrix_type t, bool _full) |
557 : 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
|
558 sp_bandden (octave_sparse_params::get_bandden ()), |
5892 | 559 bandden (0), upper_band (0), lower_band (0), |
560 dense (false), full (_full), nperm (0), perm (0) | |
5785 | 561 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
562 if (t == MatrixType::Unknown || t == MatrixType::Full |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
563 || t == MatrixType::Diagonal || t == MatrixType::Permuted_Diagonal |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
564 || t == MatrixType::Upper || t == MatrixType::Lower |
7798
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
565 || t == MatrixType::Tridiagonal || t == MatrixType::Tridiagonal_Hermitian |
42c42c640108
improved matrix_type check
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
566 || t == MatrixType::Rectangular) |
5785 | 567 typ = t; |
568 else | |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
569 warn_invalid (); |
5785 | 570 } |
571 | |
572 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
|
573 const octave_idx_type *p, bool _full) |
5892 | 574 : 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
|
575 sp_bandden (octave_sparse_params::get_bandden ()), |
5892 | 576 bandden (0), upper_band (0), lower_band (0), |
577 dense (false), full (_full), nperm (0), perm (0) | |
5785 | 578 { |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
579 if ((t == MatrixType::Permuted_Upper || t == MatrixType::Permuted_Lower) |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
580 && np > 0 && p != 0) |
5785 | 581 { |
582 typ = t; | |
583 nperm = np; | |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
584 perm = new octave_idx_type [nperm]; |
5785 | 585 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
|
586 perm[i] = p[i]; |
5785 | 587 } |
588 else | |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
589 warn_invalid (); |
5785 | 590 } |
591 | |
592 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
|
593 const octave_idx_type kl, bool _full) |
5892 | 594 : 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
|
595 sp_bandden (octave_sparse_params::get_bandden ()), |
5892 | 596 bandden (0), upper_band (0), lower_band (0), |
597 dense (false), full (_full), nperm (0), perm (0) | |
5785 | 598 { |
599 if (t == MatrixType::Banded || t == MatrixType::Banded_Hermitian) | |
600 { | |
601 typ = t; | |
602 upper_band = ku; | |
603 lower_band = kl; | |
604 } | |
605 else | |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
606 warn_invalid (); |
5785 | 607 } |
608 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
609 MatrixType::~MatrixType (void) |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
610 { |
5785 | 611 if (nperm != 0) |
612 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
613 delete [] perm; |
5785 | 614 } |
615 } | |
616 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
617 MatrixType& |
5785 | 618 MatrixType::operator = (const MatrixType& a) |
619 { | |
620 if (this != &a) | |
621 { | |
622 typ = a.typ; | |
623 sp_bandden = a.sp_bandden; | |
624 bandden = a.bandden; | |
625 upper_band = a.upper_band; | |
626 lower_band = a.lower_band; | |
627 dense = a.dense; | |
628 full = a.full; | |
629 | |
12564
61cd086e9aeb
Correct slight logical mistake in memleak patch (bug #32804)
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12563
diff
changeset
|
630 if (nperm) |
61cd086e9aeb
Correct slight logical mistake in memleak patch (bug #32804)
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12563
diff
changeset
|
631 { |
61cd086e9aeb
Correct slight logical mistake in memleak patch (bug #32804)
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12563
diff
changeset
|
632 delete[] perm; |
61cd086e9aeb
Correct slight logical mistake in memleak patch (bug #32804)
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12563
diff
changeset
|
633 } |
61cd086e9aeb
Correct slight logical mistake in memleak patch (bug #32804)
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12563
diff
changeset
|
634 |
12563
681bb733f4f4
MatrixType:: plug memory leak (bug #32804).
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
635 if (a.nperm != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
636 { |
12563
681bb733f4f4
MatrixType:: plug memory leak (bug #32804).
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
637 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
|
638 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
|
639 perm[i] = a.perm[i]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
640 } |
12563
681bb733f4f4
MatrixType:: plug memory leak (bug #32804).
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
641 |
681bb733f4f4
MatrixType:: plug memory leak (bug #32804).
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11586
diff
changeset
|
642 nperm = a.nperm; |
5785 | 643 } |
644 | |
645 return *this; | |
646 } | |
647 | |
648 int | |
649 MatrixType::type (bool quiet) | |
650 { | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
651 if (typ != MatrixType::Unknown |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
652 && (full || sp_bandden == octave_sparse_params::get_bandden ())) |
5785 | 653 { |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
654 if (! quiet && octave_sparse_params::get_key ("spumoni") != 0.) |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
655 warn_cached (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
656 |
5785 | 657 return typ; |
658 } | |
659 | |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
660 if (typ != MatrixType::Unknown |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
661 && octave_sparse_params::get_key ("spumoni") != 0.) |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
662 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
663 ("Octave:matrix-type-info", "invalidating matrix type"); |
5785 | 664 |
665 typ = MatrixType::Unknown; | |
666 | |
667 return typ; | |
668 } | |
669 | |
670 int | |
671 MatrixType::type (const SparseMatrix &a) | |
672 { | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
673 if (typ != MatrixType::Unknown |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
674 && (full || sp_bandden == octave_sparse_params::get_bandden ())) |
5785 | 675 { |
5893 | 676 if (octave_sparse_params::get_key ("spumoni") != 0.) |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
677 warn_cached (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
678 |
5785 | 679 return typ; |
680 } | |
681 | |
682 MatrixType tmp_typ (a); | |
683 typ = tmp_typ.typ; | |
684 sp_bandden = tmp_typ.sp_bandden; | |
685 bandden = tmp_typ.bandden; | |
686 upper_band = tmp_typ.upper_band; | |
687 lower_band = tmp_typ.lower_band; | |
688 dense = tmp_typ.dense; | |
689 full = tmp_typ.full; | |
690 nperm = tmp_typ.nperm; | |
691 | |
692 if (nperm != 0) | |
693 { | |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
694 perm = new octave_idx_type [nperm]; |
5785 | 695 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
|
696 perm[i] = tmp_typ.perm[i]; |
5785 | 697 } |
698 | |
699 return typ; | |
700 } | |
701 | |
702 int | |
703 MatrixType::type (const SparseComplexMatrix &a) | |
704 { | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
705 if (typ != MatrixType::Unknown |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
706 && (full || sp_bandden == octave_sparse_params::get_bandden ())) |
5785 | 707 { |
5893 | 708 if (octave_sparse_params::get_key ("spumoni") != 0.) |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
709 warn_cached (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
710 |
5785 | 711 return typ; |
712 } | |
713 | |
714 MatrixType tmp_typ (a); | |
715 typ = tmp_typ.typ; | |
716 sp_bandden = tmp_typ.sp_bandden; | |
717 bandden = tmp_typ.bandden; | |
718 upper_band = tmp_typ.upper_band; | |
719 lower_band = tmp_typ.lower_band; | |
720 dense = tmp_typ.dense; | |
721 full = tmp_typ.full; | |
722 nperm = tmp_typ.nperm; | |
723 | |
724 if (nperm != 0) | |
725 { | |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
726 perm = new octave_idx_type [nperm]; |
5785 | 727 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
|
728 perm[i] = tmp_typ.perm[i]; |
5785 | 729 } |
730 | |
731 return typ; | |
732 } | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
733 |
5785 | 734 int |
735 MatrixType::type (const Matrix &a) | |
736 { | |
737 if (typ != MatrixType::Unknown) | |
738 { | |
5893 | 739 if (octave_sparse_params::get_key ("spumoni") != 0.) |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
740 warn_cached (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
741 |
5785 | 742 return typ; |
743 } | |
744 | |
745 MatrixType tmp_typ (a); | |
746 typ = tmp_typ.typ; | |
747 full = tmp_typ.full; | |
748 nperm = tmp_typ.nperm; | |
749 | |
750 if (nperm != 0) | |
751 { | |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
752 perm = new octave_idx_type [nperm]; |
5785 | 753 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
|
754 perm[i] = tmp_typ.perm[i]; |
5785 | 755 } |
756 | |
757 return typ; | |
758 } | |
759 | |
760 int | |
761 MatrixType::type (const ComplexMatrix &a) | |
762 { | |
763 if (typ != MatrixType::Unknown) | |
764 { | |
5893 | 765 if (octave_sparse_params::get_key ("spumoni") != 0.) |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
766 warn_cached (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
767 |
5785 | 768 return typ; |
769 } | |
770 | |
771 MatrixType tmp_typ (a); | |
772 typ = tmp_typ.typ; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
773 full = tmp_typ.full; |
5785 | 774 nperm = tmp_typ.nperm; |
775 | |
776 if (nperm != 0) | |
777 { | |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
778 perm = new octave_idx_type [nperm]; |
5785 | 779 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
|
780 perm[i] = tmp_typ.perm[i]; |
5785 | 781 } |
782 | |
783 return typ; | |
784 } | |
785 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
786 int |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
787 MatrixType::type (const FloatMatrix &a) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
788 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
789 if (typ != MatrixType::Unknown) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
790 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
791 if (octave_sparse_params::get_key ("spumoni") != 0.) |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
792 warn_cached (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
793 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
794 return typ; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
795 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
796 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
797 MatrixType tmp_typ (a); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
798 typ = tmp_typ.typ; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
799 full = tmp_typ.full; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
800 nperm = tmp_typ.nperm; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
801 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
802 if (nperm != 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
803 { |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
804 perm = new octave_idx_type [nperm]; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
805 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
|
806 perm[i] = tmp_typ.perm[i]; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
807 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
808 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
809 return typ; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
810 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
811 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
812 int |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
813 MatrixType::type (const FloatComplexMatrix &a) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
814 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
815 if (typ != MatrixType::Unknown) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
816 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
817 if (octave_sparse_params::get_key ("spumoni") != 0.) |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
818 warn_cached (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
819 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
820 return typ; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
821 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
822 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
823 MatrixType tmp_typ (a); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
824 typ = tmp_typ.typ; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
825 full = tmp_typ.full; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
826 nperm = tmp_typ.nperm; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
827 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
828 if (nperm != 0) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
829 { |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
830 perm = new octave_idx_type [nperm]; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
831 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
|
832 perm[i] = tmp_typ.perm[i]; |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
833 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
834 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
835 return typ; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
836 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
837 |
5785 | 838 void |
839 MatrixType::info () const | |
840 { | |
5893 | 841 if (octave_sparse_params::get_key ("spumoni") != 0.) |
5785 | 842 { |
843 if (typ == MatrixType::Unknown) | |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
844 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
845 ("Octave:matrix-type-info", "unknown matrix type"); |
5785 | 846 else if (typ == MatrixType::Diagonal) |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
847 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
848 ("Octave:matrix-type-info", "diagonal sparse matrix"); |
5785 | 849 else if (typ == MatrixType::Permuted_Diagonal) |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
850 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
851 ("Octave:matrix-type-info", "permuted diagonal sparse matrix"); |
5785 | 852 else if (typ == MatrixType::Upper) |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
853 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
854 ("Octave:matrix-type-info", "upper triangular matrix"); |
5785 | 855 else if (typ == MatrixType::Lower) |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
856 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
857 ("Octave:matrix-type-info", "lower triangular matrix"); |
5785 | 858 else if (typ == MatrixType::Permuted_Upper) |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
859 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
860 ("Octave:matrix-type-info", "permuted upper triangular matrix"); |
5785 | 861 else if (typ == MatrixType::Permuted_Lower) |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
862 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
863 ("Octave:matrix-type-info", "permuted lower triangular Matrix"); |
5785 | 864 else if (typ == MatrixType::Banded) |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
865 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
866 ("Octave:matrix-type-info", |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
867 "banded sparse matrix %d-1-%d (density %f)", |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
868 lower_band, upper_band, bandden); |
5785 | 869 else if (typ == MatrixType::Banded_Hermitian) |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
870 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
871 ("Octave:matrix-type-info", |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
872 "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
|
873 lower_band, upper_band, bandden); |
5785 | 874 else if (typ == MatrixType::Hermitian) |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
875 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
876 ("Octave:matrix-type-info", "hermitian/symmetric matrix"); |
5785 | 877 else if (typ == MatrixType::Tridiagonal) |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
878 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
879 ("Octave:matrix-type-info", "tridiagonal sparse matrix"); |
5785 | 880 else if (typ == MatrixType::Tridiagonal_Hermitian) |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
881 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
882 ("Octave:matrix-type-info", |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
883 "hermitian/symmetric tridiagonal sparse matrix"); |
5785 | 884 else if (typ == MatrixType::Rectangular) |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
885 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
886 ("Octave:matrix-type-info", "rectangular/singular matrix"); |
5785 | 887 else if (typ == MatrixType::Full) |
19410
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
888 (*current_liboctave_warning_with_id_handler) |
95c533ed464b
use warning IDs for all warnings in liboctave
John W. Eaton <jwe@octave.org>
parents:
19269
diff
changeset
|
889 ("Octave:matrix-type-info", "full matrix"); |
5785 | 890 } |
891 } | |
892 | |
893 void | |
894 MatrixType::mark_as_symmetric (void) | |
895 { | |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
896 if (typ == MatrixType::Tridiagonal |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
897 || typ == MatrixType::Tridiagonal_Hermitian) |
5785 | 898 typ = MatrixType::Tridiagonal_Hermitian; |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
899 else if (typ == MatrixType::Banded || typ == MatrixType::Banded_Hermitian) |
5785 | 900 typ = MatrixType::Banded_Hermitian; |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
901 else if (typ == MatrixType::Full || typ == MatrixType::Hermitian |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
902 || typ == MatrixType::Unknown) |
5785 | 903 typ = MatrixType::Hermitian; |
904 else | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
905 (*current_liboctave_error_handler) |
5785 | 906 ("Can not mark current matrix type as symmetric"); |
907 } | |
908 | |
909 void | |
910 MatrixType::mark_as_unsymmetric (void) | |
911 { | |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
912 if (typ == MatrixType::Tridiagonal |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
913 || typ == MatrixType::Tridiagonal_Hermitian) |
5785 | 914 typ = MatrixType::Tridiagonal; |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
915 else if (typ == MatrixType::Banded || typ == MatrixType::Banded_Hermitian) |
5785 | 916 typ = MatrixType::Banded; |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
917 else if (typ == MatrixType::Full || typ == MatrixType::Hermitian |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
918 || typ == MatrixType::Unknown) |
5785 | 919 typ = MatrixType::Full; |
920 } | |
921 | |
922 void | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
923 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
|
924 const octave_idx_type *p) |
5785 | 925 { |
926 nperm = np; | |
15020
560317fd5977
maint: Cuddle open bracket used for indexing C++ arrays in source code.
Rik <rik@octave.org>
parents:
15018
diff
changeset
|
927 perm = new octave_idx_type [nperm]; |
5785 | 928 for (octave_idx_type i = 0; i < nperm; i++) |
929 perm[i] = p[i]; | |
930 | |
931 if (typ == MatrixType::Diagonal || typ == MatrixType::Permuted_Diagonal) | |
932 typ = MatrixType::Permuted_Diagonal; | |
933 else if (typ == MatrixType::Upper || typ == MatrixType::Permuted_Upper) | |
934 typ = MatrixType::Permuted_Upper; | |
935 else if (typ == MatrixType::Lower || typ == MatrixType::Permuted_Lower) | |
936 typ = MatrixType::Permuted_Lower; | |
937 else | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
938 (*current_liboctave_error_handler) |
5785 | 939 ("Can not mark current matrix type as symmetric"); |
940 } | |
941 | |
942 void | |
943 MatrixType::mark_as_unpermuted (void) | |
944 { | |
945 if (nperm) | |
946 { | |
947 nperm = 0; | |
948 delete [] perm; | |
949 } | |
950 | |
951 if (typ == MatrixType::Diagonal || typ == MatrixType::Permuted_Diagonal) | |
952 typ = MatrixType::Diagonal; | |
953 else if (typ == MatrixType::Upper || typ == MatrixType::Permuted_Upper) | |
954 typ = MatrixType::Upper; | |
955 else if (typ == MatrixType::Lower || typ == MatrixType::Permuted_Lower) | |
956 typ = MatrixType::Lower; | |
957 } | |
958 | |
959 MatrixType | |
960 MatrixType::transpose (void) const | |
961 { | |
962 MatrixType retval (*this); | |
963 if (typ == MatrixType::Upper) | |
964 retval.typ = MatrixType::Lower; | |
965 else if (typ == MatrixType::Permuted_Upper) | |
966 retval.typ = MatrixType::Permuted_Lower; | |
967 else if (typ == MatrixType::Lower) | |
968 retval.typ = MatrixType::Upper; | |
969 else if (typ == MatrixType::Permuted_Lower) | |
970 retval.typ = MatrixType::Permuted_Upper; | |
971 else if (typ == MatrixType::Banded) | |
972 { | |
973 retval.upper_band = lower_band; | |
974 retval.lower_band = upper_band; | |
975 } | |
976 | |
977 return retval; | |
978 } |