Mercurial > octave
annotate liboctave/array/CMatrix.cc @ 21266:e69eaee28737
make better use of templates for Schur decomposition
* liboctave/numeric/schur.h, liboctave/numeric/schur.cc:
New files generated from SCHUR.h, SCHUR.cc, CmplxSCHUR.h,
CmplxSCHUR.cc, dbleSCHUR.h, dbleSCHUR.cc, fCmplxSCHUR.h,
fCmplxSCHUR.cc, floatSCHUR.h, and floatSCHUR.cc and making them
templates.
* liboctave/numeric/module.mk: Update.
* libinterp/corefcn/schur.cc, sqrtm.cc, CMatrix.cc, dMatrix.cc,
fCMatrix.cc, fMatrix.cc, mx-defs.h, mx-ext.h: Use new template classes
and header file.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 15 Feb 2016 20:06:12 -0500 |
parents | f7121e111991 |
children | 3c8a3d35661a |
rev | line source |
---|---|
1993 | 1 // Matrix manipulations. |
458 | 2 /* |
3 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19457
diff
changeset
|
4 Copyright (C) 1994-2015 John W. Eaton |
11523 | 5 Copyright (C) 2008-2009 Jaroslav Hajek |
9601
a9b37bae1802
add a couple of missing copyright statements
Jaroslav Hajek <highegg@gmail.com>
parents:
9578
diff
changeset
|
6 Copyright (C) 2009 VZLU Prague, a.s. |
458 | 7 |
8 This file is part of Octave. | |
9 | |
10 Octave is free software; you can redistribute it and/or modify it | |
11 under the terms of the GNU General Public License as published by the | |
7016 | 12 Free Software Foundation; either version 3 of the License, or (at your |
13 option) any later version. | |
458 | 14 |
15 Octave is distributed in the hope that it will be useful, but WITHOUT | |
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
18 for more details. | |
19 | |
20 You should have received a copy of the GNU General Public License | |
7016 | 21 along with Octave; see the file COPYING. If not, see |
22 <http://www.gnu.org/licenses/>. | |
458 | 23 |
24 */ | |
25 | |
26 #ifdef HAVE_CONFIG_H | |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21168
diff
changeset
|
27 # include <config.h> |
458 | 28 #endif |
29 | |
1367 | 30 #include <cfloat> |
31 | |
3503 | 32 #include <iostream> |
6209 | 33 #include <vector> |
1367 | 34 |
5775 | 35 // FIXME |
2443 | 36 #include <sys/types.h> |
458 | 37 |
4669 | 38 #include "Array-util.h" |
19269
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
19065
diff
changeset
|
39 #include "boolMatrix.h" |
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
19065
diff
changeset
|
40 #include "chMatrix.h" |
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
19065
diff
changeset
|
41 #include "dMatrix.h" |
2828 | 42 #include "CMatrix.h" |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19269
diff
changeset
|
43 #include "CNDArray.h" |
19269
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
19065
diff
changeset
|
44 #include "CRowVector.h" |
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
19065
diff
changeset
|
45 #include "dRowVector.h" |
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
19065
diff
changeset
|
46 #include "CDiagMatrix.h" |
65554f5847ac
don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents:
19065
diff
changeset
|
47 #include "dDiagMatrix.h" |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
48 #include "CmplxCHOL.h" |
21266
e69eaee28737
make better use of templates for Schur decomposition
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
49 #include "schur.h" |
740 | 50 #include "CmplxSVD.h" |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
51 #include "DET.h" |
1847 | 52 #include "f77-fcn.h" |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7488
diff
changeset
|
53 #include "functor.h" |
458 | 54 #include "lo-error.h" |
2354 | 55 #include "lo-ieee.h" |
56 #include "lo-mappers.h" | |
1968 | 57 #include "lo-utils.h" |
2828 | 58 #include "mx-cm-dm.h" |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
59 #include "mx-cm-s.h" |
3176 | 60 #include "mx-dm-cm.h" |
1367 | 61 #include "mx-inlines.cc" |
8774
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
8743
diff
changeset
|
62 #include "mx-op-defs.h" |
1650 | 63 #include "oct-cmplx.h" |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
64 #include "oct-fftw.h" |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
65 #include "oct-locbuf.h" |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
66 #include "oct-norm.h" |
458 | 67 |
68 // Fortran functions we call. | |
69 | |
70 extern "C" | |
71 { | |
7477 | 72 F77_RET_T |
11518 | 73 F77_FUNC (xilaenv, XILAENV) (const octave_idx_type&, |
74 F77_CONST_CHAR_ARG_DECL, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
75 F77_CONST_CHAR_ARG_DECL, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
76 const octave_idx_type&, const octave_idx_type&, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
77 const octave_idx_type&, const octave_idx_type&, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
78 octave_idx_type& |
11518 | 79 F77_CHAR_ARG_LEN_DECL |
80 F77_CHAR_ARG_LEN_DECL); | |
7476 | 81 |
4552 | 82 F77_RET_T |
83 F77_FUNC (zgebal, ZGEBAL) (F77_CONST_CHAR_ARG_DECL, | |
11518 | 84 const octave_idx_type&, Complex*, |
85 const octave_idx_type&, octave_idx_type&, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
86 octave_idx_type&, double*, octave_idx_type& |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
87 F77_CHAR_ARG_LEN_DECL); |
4552 | 88 |
89 F77_RET_T | |
90 F77_FUNC (dgebak, DGEBAK) (F77_CONST_CHAR_ARG_DECL, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
91 F77_CONST_CHAR_ARG_DECL, |
11518 | 92 const octave_idx_type&, const octave_idx_type&, |
93 const octave_idx_type&, double*, | |
94 const octave_idx_type&, double*, | |
95 const octave_idx_type&, octave_idx_type& | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
96 F77_CHAR_ARG_LEN_DECL |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
97 F77_CHAR_ARG_LEN_DECL); |
4552 | 98 |
99 F77_RET_T | |
100 F77_FUNC (zgemm, ZGEMM) (F77_CONST_CHAR_ARG_DECL, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
101 F77_CONST_CHAR_ARG_DECL, |
11518 | 102 const octave_idx_type&, const octave_idx_type&, |
103 const octave_idx_type&, const Complex&, | |
104 const Complex*, const octave_idx_type&, | |
105 const Complex*, const octave_idx_type&, | |
106 const Complex&, Complex*, const octave_idx_type& | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
107 F77_CHAR_ARG_LEN_DECL |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
108 F77_CHAR_ARG_LEN_DECL); |
4552 | 109 |
110 F77_RET_T | |
5983 | 111 F77_FUNC (zgemv, ZGEMV) (F77_CONST_CHAR_ARG_DECL, |
11518 | 112 const octave_idx_type&, const octave_idx_type&, |
113 const Complex&, const Complex*, | |
114 const octave_idx_type&, const Complex*, | |
115 const octave_idx_type&, const Complex&, | |
116 Complex*, const octave_idx_type& | |
5983 | 117 F77_CHAR_ARG_LEN_DECL); |
118 | |
119 F77_RET_T | |
11518 | 120 F77_FUNC (xzdotu, XZDOTU) (const octave_idx_type&, const Complex*, |
121 const octave_idx_type&, const Complex*, | |
122 const octave_idx_type&, Complex&); | |
5983 | 123 |
124 F77_RET_T | |
11518 | 125 F77_FUNC (xzdotc, XZDOTC) (const octave_idx_type&, const Complex*, |
126 const octave_idx_type&, const Complex*, | |
127 const octave_idx_type&, Complex&); | |
7800
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
128 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
129 F77_RET_T |
7801
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
130 F77_FUNC (zsyrk, ZSYRK) (F77_CONST_CHAR_ARG_DECL, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
131 F77_CONST_CHAR_ARG_DECL, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
132 const octave_idx_type&, const octave_idx_type&, |
11518 | 133 const Complex&, const Complex*, |
134 const octave_idx_type&, const Complex&, | |
135 Complex*, const octave_idx_type& | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
136 F77_CHAR_ARG_LEN_DECL |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
137 F77_CHAR_ARG_LEN_DECL); |
7801
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
138 |
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
139 F77_RET_T |
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
140 F77_FUNC (zherk, ZHERK) (F77_CONST_CHAR_ARG_DECL, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
141 F77_CONST_CHAR_ARG_DECL, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
142 const octave_idx_type&, const octave_idx_type&, |
11518 | 143 const double&, const Complex*, |
144 const octave_idx_type&, const double&, Complex*, | |
145 const octave_idx_type& | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
146 F77_CHAR_ARG_LEN_DECL |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
147 F77_CHAR_ARG_LEN_DECL); |
7801
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
148 |
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
149 F77_RET_T |
11518 | 150 F77_FUNC (zgetrf, ZGETRF) (const octave_idx_type&, const octave_idx_type&, |
151 Complex*, const octave_idx_type&, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
152 octave_idx_type*, octave_idx_type&); |
4552 | 153 |
154 F77_RET_T | |
155 F77_FUNC (zgetrs, ZGETRS) (F77_CONST_CHAR_ARG_DECL, | |
11518 | 156 const octave_idx_type&, const octave_idx_type&, |
157 Complex*, const octave_idx_type&, | |
158 const octave_idx_type*, Complex*, | |
159 const octave_idx_type&, octave_idx_type& | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
160 F77_CHAR_ARG_LEN_DECL); |
4552 | 161 |
162 F77_RET_T | |
11518 | 163 F77_FUNC (zgetri, ZGETRI) (const octave_idx_type&, Complex*, |
164 const octave_idx_type&, const octave_idx_type*, | |
165 Complex*, const octave_idx_type&, | |
166 octave_idx_type&); | |
4552 | 167 |
168 F77_RET_T | |
169 F77_FUNC (zgecon, ZGECON) (F77_CONST_CHAR_ARG_DECL, | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
170 const octave_idx_type&, Complex*, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
171 const octave_idx_type&, const double&, double&, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
172 Complex*, double*, octave_idx_type& |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
173 F77_CHAR_ARG_LEN_DECL); |
4552 | 174 |
175 F77_RET_T | |
11518 | 176 F77_FUNC (zgelsy, ZGELSY) (const octave_idx_type&, const octave_idx_type&, |
177 const octave_idx_type&, Complex*, | |
178 const octave_idx_type&, Complex*, | |
179 const octave_idx_type&, octave_idx_type*, | |
180 double&, octave_idx_type&, Complex*, | |
181 const octave_idx_type&, double*, | |
182 octave_idx_type&); | |
7072 | 183 |
184 F77_RET_T | |
11518 | 185 F77_FUNC (zgelsd, ZGELSD) (const octave_idx_type&, const octave_idx_type&, |
186 const octave_idx_type&, Complex*, | |
187 const octave_idx_type&, Complex*, | |
188 const octave_idx_type&, double*, double&, | |
189 octave_idx_type&, Complex*, | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
190 const octave_idx_type&, double*, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
191 octave_idx_type*, octave_idx_type&); |
458 | 192 |
5785 | 193 F77_RET_T |
11518 | 194 F77_FUNC (zpotrf, ZPOTRF) (F77_CONST_CHAR_ARG_DECL, |
195 const octave_idx_type&, Complex*, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
196 const octave_idx_type&, octave_idx_type& |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
197 F77_CHAR_ARG_LEN_DECL); |
5785 | 198 |
199 F77_RET_T | |
11518 | 200 F77_FUNC (zpocon, ZPOCON) (F77_CONST_CHAR_ARG_DECL, |
201 const octave_idx_type&, Complex*, | |
202 const octave_idx_type&, const double&, | |
203 double&, Complex*, double*, octave_idx_type& | |
204 F77_CHAR_ARG_LEN_DECL); | |
205 | |
206 F77_RET_T | |
207 F77_FUNC (zpotrs, ZPOTRS) (F77_CONST_CHAR_ARG_DECL, | |
208 const octave_idx_type&, const octave_idx_type&, | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
209 const Complex*, const octave_idx_type&, Complex*, |
11518 | 210 const octave_idx_type&, octave_idx_type& |
211 F77_CHAR_ARG_LEN_DECL); | |
212 | |
213 F77_RET_T | |
214 F77_FUNC (ztrtri, ZTRTRI) (F77_CONST_CHAR_ARG_DECL, | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
215 F77_CONST_CHAR_ARG_DECL, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
216 const octave_idx_type&, const Complex*, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
217 const octave_idx_type&, octave_idx_type& |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
218 F77_CHAR_ARG_LEN_DECL |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
219 F77_CHAR_ARG_LEN_DECL); |
6207 | 220 |
221 F77_RET_T | |
11518 | 222 F77_FUNC (ztrcon, ZTRCON) (F77_CONST_CHAR_ARG_DECL, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
223 F77_CONST_CHAR_ARG_DECL, |
11518 | 224 F77_CONST_CHAR_ARG_DECL, |
225 const octave_idx_type&, const Complex*, | |
226 const octave_idx_type&, double&, | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
227 Complex*, double*, octave_idx_type& |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
228 F77_CHAR_ARG_LEN_DECL |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
229 F77_CHAR_ARG_LEN_DECL |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
230 F77_CHAR_ARG_LEN_DECL); |
5785 | 231 |
232 F77_RET_T | |
11518 | 233 F77_FUNC (ztrtrs, ZTRTRS) (F77_CONST_CHAR_ARG_DECL, |
234 F77_CONST_CHAR_ARG_DECL, | |
235 F77_CONST_CHAR_ARG_DECL, | |
236 const octave_idx_type&, const octave_idx_type&, | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
237 const Complex*, const octave_idx_type&, Complex*, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
238 const octave_idx_type&, octave_idx_type& |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
239 F77_CHAR_ARG_LEN_DECL |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
240 F77_CHAR_ARG_LEN_DECL |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
241 F77_CHAR_ARG_LEN_DECL); |
5785 | 242 |
4552 | 243 F77_RET_T |
11518 | 244 F77_FUNC (zlartg, ZLARTG) (const Complex&, const Complex&, double&, |
245 Complex&, Complex&); | |
4552 | 246 |
247 F77_RET_T | |
248 F77_FUNC (ztrsyl, ZTRSYL) (F77_CONST_CHAR_ARG_DECL, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
249 F77_CONST_CHAR_ARG_DECL, |
11518 | 250 const octave_idx_type&, const octave_idx_type&, |
251 const octave_idx_type&, const Complex*, | |
252 const octave_idx_type&, const Complex*, | |
253 const octave_idx_type&, const Complex*, | |
254 const octave_idx_type&, double&, octave_idx_type& | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
255 F77_CHAR_ARG_LEN_DECL |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
256 F77_CHAR_ARG_LEN_DECL); |
4552 | 257 |
258 F77_RET_T | |
259 F77_FUNC (xzlange, XZLANGE) (F77_CONST_CHAR_ARG_DECL, | |
11518 | 260 const octave_idx_type&, const octave_idx_type&, |
261 const Complex*, const octave_idx_type&, | |
262 double*, double& | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
263 F77_CHAR_ARG_LEN_DECL); |
458 | 264 } |
265 | |
2354 | 266 static const Complex Complex_NaN_result (octave_NaN, octave_NaN); |
267 | |
1360 | 268 // Complex Matrix class |
458 | 269 |
270 ComplexMatrix::ComplexMatrix (const Matrix& a) | |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19269
diff
changeset
|
271 : ComplexNDArray (a) |
458 | 272 { |
273 } | |
274 | |
2349 | 275 ComplexMatrix::ComplexMatrix (const RowVector& rv) |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19269
diff
changeset
|
276 : ComplexNDArray (rv) |
2349 | 277 { |
278 } | |
279 | |
280 ComplexMatrix::ComplexMatrix (const ColumnVector& cv) | |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19269
diff
changeset
|
281 : ComplexNDArray (cv) |
2349 | 282 { |
283 } | |
284 | |
458 | 285 ComplexMatrix::ComplexMatrix (const DiagMatrix& a) |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19269
diff
changeset
|
286 : ComplexNDArray (a.dims (), 0.0) |
458 | 287 { |
5275 | 288 for (octave_idx_type i = 0; i < a.length (); i++) |
458 | 289 elem (i, i) = a.elem (i, i); |
290 } | |
291 | |
19391
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
292 ComplexMatrix::ComplexMatrix (const MDiagArray2<double>& a) |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
293 : ComplexNDArray (a.dims (), 0.0) |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
294 { |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
295 for (octave_idx_type i = 0; i < a.length (); i++) |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
296 elem (i, i) = a.elem (i, i); |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
297 } |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
298 |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
299 ComplexMatrix::ComplexMatrix (const DiagArray2<double>& a) |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
300 : ComplexNDArray (a.dims (), 0.0) |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
301 { |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
302 for (octave_idx_type i = 0; i < a.length (); i++) |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
303 elem (i, i) = a.elem (i, i); |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
304 } |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
305 |
2349 | 306 ComplexMatrix::ComplexMatrix (const ComplexRowVector& rv) |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19269
diff
changeset
|
307 : ComplexNDArray (rv) |
2349 | 308 { |
309 } | |
310 | |
311 ComplexMatrix::ComplexMatrix (const ComplexColumnVector& cv) | |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19269
diff
changeset
|
312 : ComplexNDArray (cv) |
2349 | 313 { |
314 } | |
315 | |
458 | 316 ComplexMatrix::ComplexMatrix (const ComplexDiagMatrix& a) |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19269
diff
changeset
|
317 : ComplexNDArray (a.dims (), 0.0) |
458 | 318 { |
5275 | 319 for (octave_idx_type i = 0; i < a.length (); i++) |
458 | 320 elem (i, i) = a.elem (i, i); |
321 } | |
322 | |
19391
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
323 ComplexMatrix::ComplexMatrix (const MDiagArray2<Complex>& a) |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
324 : ComplexNDArray (a.dims (), 0.0) |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
325 { |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
326 for (octave_idx_type i = 0; i < a.length (); i++) |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
327 elem (i, i) = a.elem (i, i); |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
328 } |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
329 |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
330 ComplexMatrix::ComplexMatrix (const DiagArray2<Complex>& a) |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
331 : ComplexNDArray (a.dims (), 0.0) |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
332 { |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
333 for (octave_idx_type i = 0; i < a.length (); i++) |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
334 elem (i, i) = a.elem (i, i); |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
335 } |
385499581a5e
allow disabling of permutation and diagonal matrices
John W. Eaton <jwe@octave.org>
parents:
19340
diff
changeset
|
336 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
337 // FIXME: could we use a templated mixed-type copy function here? |
1574 | 338 |
2828 | 339 ComplexMatrix::ComplexMatrix (const boolMatrix& a) |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19269
diff
changeset
|
340 : ComplexNDArray (a) |
2828 | 341 { |
342 } | |
343 | |
1574 | 344 ComplexMatrix::ComplexMatrix (const charMatrix& a) |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19269
diff
changeset
|
345 : ComplexNDArray (a.dims (), 0.0) |
1574 | 346 { |
5275 | 347 for (octave_idx_type i = 0; i < a.rows (); i++) |
348 for (octave_idx_type j = 0; j < a.cols (); j++) | |
8956
d91fa4b20bbb
ensure nonnegative char -> real conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
349 elem (i, j) = static_cast<unsigned char> (a.elem (i, j)); |
1574 | 350 } |
351 | |
9663
7e5b4de5fbfe
improve mixed real x complex ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
352 ComplexMatrix::ComplexMatrix (const Matrix& re, const Matrix& im) |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19269
diff
changeset
|
353 : ComplexNDArray (re.dims ()) |
9663
7e5b4de5fbfe
improve mixed real x complex ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
354 { |
7e5b4de5fbfe
improve mixed real x complex ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
355 if (im.rows () != rows () || im.cols () != cols ()) |
7e5b4de5fbfe
improve mixed real x complex ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
356 (*current_liboctave_error_handler) ("complex: internal error"); |
7e5b4de5fbfe
improve mixed real x complex ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
357 |
7e5b4de5fbfe
improve mixed real x complex ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
358 octave_idx_type nel = numel (); |
7e5b4de5fbfe
improve mixed real x complex ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
359 for (octave_idx_type i = 0; i < nel; i++) |
7e5b4de5fbfe
improve mixed real x complex ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
360 xelem (i) = Complex (re(i), im(i)); |
7e5b4de5fbfe
improve mixed real x complex ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
361 } |
7e5b4de5fbfe
improve mixed real x complex ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
362 |
2384 | 363 bool |
458 | 364 ComplexMatrix::operator == (const ComplexMatrix& a) const |
365 { | |
366 if (rows () != a.rows () || cols () != a.cols ()) | |
2384 | 367 return false; |
458 | 368 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
369 return mx_inline_equal (numel (), data (), a.data ()); |
458 | 370 } |
371 | |
2384 | 372 bool |
458 | 373 ComplexMatrix::operator != (const ComplexMatrix& a) const |
374 { | |
375 return !(*this == a); | |
376 } | |
377 | |
2815 | 378 bool |
379 ComplexMatrix::is_hermitian (void) const | |
380 { | |
5275 | 381 octave_idx_type nr = rows (); |
382 octave_idx_type nc = cols (); | |
2815 | 383 |
384 if (is_square () && nr > 0) | |
385 { | |
5275 | 386 for (octave_idx_type i = 0; i < nr; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
387 for (octave_idx_type j = i; j < nc; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
388 if (elem (i, j) != conj (elem (j, i))) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
389 return false; |
2815 | 390 |
391 return true; | |
392 } | |
393 | |
394 return false; | |
395 } | |
396 | |
458 | 397 // destructive insert/delete/reorder operations |
398 | |
399 ComplexMatrix& | |
5275 | 400 ComplexMatrix::insert (const Matrix& a, octave_idx_type r, octave_idx_type c) |
458 | 401 { |
5275 | 402 octave_idx_type a_nr = a.rows (); |
403 octave_idx_type a_nc = a.cols (); | |
1699 | 404 |
405 if (r < 0 || r + a_nr > rows () || c < 0 || c + a_nc > cols ()) | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
406 (*current_liboctave_error_handler) ("range error for insert"); |
458 | 407 |
4316 | 408 if (a_nr >0 && a_nc > 0) |
409 { | |
410 make_unique (); | |
411 | |
5275 | 412 for (octave_idx_type j = 0; j < a_nc; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
413 for (octave_idx_type i = 0; i < a_nr; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
414 xelem (r+i, c+j) = a.elem (i, j); |
4316 | 415 } |
458 | 416 |
417 return *this; | |
418 } | |
419 | |
420 ComplexMatrix& | |
5275 | 421 ComplexMatrix::insert (const RowVector& a, octave_idx_type r, octave_idx_type c) |
458 | 422 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
423 octave_idx_type a_len = a.numel (); |
4316 | 424 |
1699 | 425 if (r < 0 || r >= rows () || c < 0 || c + a_len > cols ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
426 (*current_liboctave_error_handler) ("range error for insert"); |
458 | 427 |
4316 | 428 if (a_len > 0) |
429 { | |
430 make_unique (); | |
431 | |
5275 | 432 for (octave_idx_type i = 0; i < a_len; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
433 xelem (r, c+i) = a.elem (i); |
4316 | 434 } |
458 | 435 |
436 return *this; | |
437 } | |
438 | |
439 ComplexMatrix& | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
440 ComplexMatrix::insert (const ColumnVector& a, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
441 octave_idx_type r, octave_idx_type c) |
458 | 442 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
443 octave_idx_type a_len = a.numel (); |
4316 | 444 |
1699 | 445 if (r < 0 || r + a_len > rows () || c < 0 || c >= cols ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
446 (*current_liboctave_error_handler) ("range error for insert"); |
458 | 447 |
4316 | 448 if (a_len > 0) |
449 { | |
450 make_unique (); | |
451 | |
5275 | 452 for (octave_idx_type i = 0; i < a_len; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
453 xelem (r+i, c) = a.elem (i); |
4316 | 454 } |
458 | 455 |
456 return *this; | |
457 } | |
458 | |
459 ComplexMatrix& | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
460 ComplexMatrix::insert (const DiagMatrix& a, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
461 octave_idx_type r, octave_idx_type c) |
458 | 462 { |
5275 | 463 octave_idx_type a_nr = a.rows (); |
464 octave_idx_type a_nc = a.cols (); | |
1699 | 465 |
466 if (r < 0 || r + a_nr > rows () || c < 0 || c + a_nc > cols ()) | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
467 (*current_liboctave_error_handler) ("range error for insert"); |
458 | 468 |
1699 | 469 fill (0.0, r, c, r + a_nr - 1, c + a_nc - 1); |
470 | |
5275 | 471 octave_idx_type a_len = a.length (); |
4316 | 472 |
473 if (a_len > 0) | |
474 { | |
475 make_unique (); | |
476 | |
5275 | 477 for (octave_idx_type i = 0; i < a_len; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
478 xelem (r+i, c+i) = a.elem (i, i); |
4316 | 479 } |
458 | 480 |
481 return *this; | |
482 } | |
483 | |
484 ComplexMatrix& | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
485 ComplexMatrix::insert (const ComplexMatrix& a, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
486 octave_idx_type r, octave_idx_type c) |
458 | 487 { |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19269
diff
changeset
|
488 ComplexNDArray::insert (a, r, c); |
458 | 489 return *this; |
490 } | |
491 | |
492 ComplexMatrix& | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
493 ComplexMatrix::insert (const ComplexRowVector& a, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
494 octave_idx_type r, octave_idx_type c) |
458 | 495 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
496 octave_idx_type a_len = a.numel (); |
1699 | 497 if (r < 0 || r >= rows () || c < 0 || c + a_len > cols ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
498 (*current_liboctave_error_handler) ("range error for insert"); |
458 | 499 |
5275 | 500 for (octave_idx_type i = 0; i < a_len; i++) |
458 | 501 elem (r, c+i) = a.elem (i); |
502 | |
503 return *this; | |
504 } | |
505 | |
506 ComplexMatrix& | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
507 ComplexMatrix::insert (const ComplexColumnVector& a, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
508 octave_idx_type r, octave_idx_type c) |
458 | 509 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
510 octave_idx_type a_len = a.numel (); |
4316 | 511 |
1699 | 512 if (r < 0 || r + a_len > rows () || c < 0 || c >= cols ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
513 (*current_liboctave_error_handler) ("range error for insert"); |
458 | 514 |
4316 | 515 if (a_len > 0) |
516 { | |
517 make_unique (); | |
518 | |
5275 | 519 for (octave_idx_type i = 0; i < a_len; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
520 xelem (r+i, c) = a.elem (i); |
4316 | 521 } |
458 | 522 |
523 return *this; | |
524 } | |
525 | |
526 ComplexMatrix& | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
527 ComplexMatrix::insert (const ComplexDiagMatrix& a, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
528 octave_idx_type r, octave_idx_type c) |
458 | 529 { |
5275 | 530 octave_idx_type a_nr = a.rows (); |
531 octave_idx_type a_nc = a.cols (); | |
1699 | 532 |
533 if (r < 0 || r + a_nr > rows () || c < 0 || c + a_nc > cols ()) | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
534 (*current_liboctave_error_handler) ("range error for insert"); |
458 | 535 |
1699 | 536 fill (0.0, r, c, r + a_nr - 1, c + a_nc - 1); |
537 | |
5275 | 538 octave_idx_type a_len = a.length (); |
4316 | 539 |
540 if (a_len > 0) | |
541 { | |
542 make_unique (); | |
543 | |
5275 | 544 for (octave_idx_type i = 0; i < a_len; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
545 xelem (r+i, c+i) = a.elem (i, i); |
4316 | 546 } |
458 | 547 |
548 return *this; | |
549 } | |
550 | |
551 ComplexMatrix& | |
552 ComplexMatrix::fill (double val) | |
553 { | |
5275 | 554 octave_idx_type nr = rows (); |
555 octave_idx_type nc = cols (); | |
4316 | 556 |
458 | 557 if (nr > 0 && nc > 0) |
4316 | 558 { |
559 make_unique (); | |
560 | |
5275 | 561 for (octave_idx_type j = 0; j < nc; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
562 for (octave_idx_type i = 0; i < nr; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
563 xelem (i, j) = val; |
4316 | 564 } |
458 | 565 |
566 return *this; | |
567 } | |
568 | |
569 ComplexMatrix& | |
570 ComplexMatrix::fill (const Complex& val) | |
571 { | |
5275 | 572 octave_idx_type nr = rows (); |
573 octave_idx_type nc = cols (); | |
4316 | 574 |
458 | 575 if (nr > 0 && nc > 0) |
4316 | 576 { |
577 make_unique (); | |
578 | |
5275 | 579 for (octave_idx_type j = 0; j < nc; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
580 for (octave_idx_type i = 0; i < nr; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
581 xelem (i, j) = val; |
4316 | 582 } |
458 | 583 |
584 return *this; | |
585 } | |
586 | |
587 ComplexMatrix& | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
588 ComplexMatrix::fill (double val, octave_idx_type r1, octave_idx_type c1, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
589 octave_idx_type r2, octave_idx_type c2) |
458 | 590 { |
5275 | 591 octave_idx_type nr = rows (); |
592 octave_idx_type nc = cols (); | |
4316 | 593 |
458 | 594 if (r1 < 0 || r2 < 0 || c1 < 0 || c2 < 0 |
595 || r1 >= nr || r2 >= nr || c1 >= nc || c2 >= nc) | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
596 (*current_liboctave_error_handler) ("range error for fill"); |
458 | 597 |
17663
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
16300
diff
changeset
|
598 if (r1 > r2) { std::swap (r1, r2); } |
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
16300
diff
changeset
|
599 if (c1 > c2) { std::swap (c1, c2); } |
458 | 600 |
4316 | 601 if (r2 >= r1 && c2 >= c1) |
602 { | |
603 make_unique (); | |
604 | |
5275 | 605 for (octave_idx_type j = c1; j <= c2; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
606 for (octave_idx_type i = r1; i <= r2; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
607 xelem (i, j) = val; |
4316 | 608 } |
458 | 609 |
610 return *this; | |
611 } | |
612 | |
613 ComplexMatrix& | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
614 ComplexMatrix::fill (const Complex& val, octave_idx_type r1, octave_idx_type c1, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
615 octave_idx_type r2, octave_idx_type c2) |
458 | 616 { |
5275 | 617 octave_idx_type nr = rows (); |
618 octave_idx_type nc = cols (); | |
4316 | 619 |
458 | 620 if (r1 < 0 || r2 < 0 || c1 < 0 || c2 < 0 |
621 || r1 >= nr || r2 >= nr || c1 >= nc || c2 >= nc) | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
622 (*current_liboctave_error_handler) ("range error for fill"); |
458 | 623 |
17663
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
16300
diff
changeset
|
624 if (r1 > r2) { std::swap (r1, r2); } |
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
16300
diff
changeset
|
625 if (c1 > c2) { std::swap (c1, c2); } |
458 | 626 |
4316 | 627 if (r2 >= r1 && c2 >=c1) |
628 { | |
629 make_unique (); | |
630 | |
5275 | 631 for (octave_idx_type j = c1; j <= c2; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
632 for (octave_idx_type i = r1; i <= r2; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
633 xelem (i, j) = val; |
4316 | 634 } |
458 | 635 |
636 return *this; | |
637 } | |
638 | |
639 ComplexMatrix | |
640 ComplexMatrix::append (const Matrix& a) const | |
641 { | |
5275 | 642 octave_idx_type nr = rows (); |
643 octave_idx_type nc = cols (); | |
458 | 644 if (nr != a.rows ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
645 (*current_liboctave_error_handler) ("row dimension mismatch for append"); |
458 | 646 |
5275 | 647 octave_idx_type nc_insert = nc; |
458 | 648 ComplexMatrix retval (nr, nc + a.cols ()); |
649 retval.insert (*this, 0, 0); | |
650 retval.insert (a, 0, nc_insert); | |
651 return retval; | |
652 } | |
653 | |
654 ComplexMatrix | |
655 ComplexMatrix::append (const RowVector& a) const | |
656 { | |
5275 | 657 octave_idx_type nr = rows (); |
658 octave_idx_type nc = cols (); | |
458 | 659 if (nr != 1) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
660 (*current_liboctave_error_handler) ("row dimension mismatch for append"); |
458 | 661 |
5275 | 662 octave_idx_type nc_insert = nc; |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
663 ComplexMatrix retval (nr, nc + a.numel ()); |
458 | 664 retval.insert (*this, 0, 0); |
665 retval.insert (a, 0, nc_insert); | |
666 return retval; | |
667 } | |
668 | |
669 ComplexMatrix | |
670 ComplexMatrix::append (const ColumnVector& a) const | |
671 { | |
5275 | 672 octave_idx_type nr = rows (); |
673 octave_idx_type nc = cols (); | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
674 if (nr != a.numel ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
675 (*current_liboctave_error_handler) ("row dimension mismatch for append"); |
458 | 676 |
5275 | 677 octave_idx_type nc_insert = nc; |
458 | 678 ComplexMatrix retval (nr, nc + 1); |
679 retval.insert (*this, 0, 0); | |
680 retval.insert (a, 0, nc_insert); | |
681 return retval; | |
682 } | |
683 | |
684 ComplexMatrix | |
685 ComplexMatrix::append (const DiagMatrix& a) const | |
686 { | |
5275 | 687 octave_idx_type nr = rows (); |
688 octave_idx_type nc = cols (); | |
458 | 689 if (nr != a.rows ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
690 (*current_liboctave_error_handler) ("row dimension mismatch for append"); |
458 | 691 |
5275 | 692 octave_idx_type nc_insert = nc; |
458 | 693 ComplexMatrix retval (nr, nc + a.cols ()); |
694 retval.insert (*this, 0, 0); | |
695 retval.insert (a, 0, nc_insert); | |
696 return retval; | |
697 } | |
698 | |
699 ComplexMatrix | |
700 ComplexMatrix::append (const ComplexMatrix& a) const | |
701 { | |
5275 | 702 octave_idx_type nr = rows (); |
703 octave_idx_type nc = cols (); | |
458 | 704 if (nr != a.rows ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
705 (*current_liboctave_error_handler) ("row dimension mismatch for append"); |
458 | 706 |
5275 | 707 octave_idx_type nc_insert = nc; |
458 | 708 ComplexMatrix retval (nr, nc + a.cols ()); |
709 retval.insert (*this, 0, 0); | |
710 retval.insert (a, 0, nc_insert); | |
711 return retval; | |
712 } | |
713 | |
714 ComplexMatrix | |
715 ComplexMatrix::append (const ComplexRowVector& a) const | |
716 { | |
5275 | 717 octave_idx_type nr = rows (); |
718 octave_idx_type nc = cols (); | |
458 | 719 if (nr != 1) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
720 (*current_liboctave_error_handler) ("row dimension mismatch for append"); |
458 | 721 |
5275 | 722 octave_idx_type nc_insert = nc; |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
723 ComplexMatrix retval (nr, nc + a.numel ()); |
458 | 724 retval.insert (*this, 0, 0); |
725 retval.insert (a, 0, nc_insert); | |
726 return retval; | |
727 } | |
728 | |
729 ComplexMatrix | |
730 ComplexMatrix::append (const ComplexColumnVector& a) const | |
731 { | |
5275 | 732 octave_idx_type nr = rows (); |
733 octave_idx_type nc = cols (); | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
734 if (nr != a.numel ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
735 (*current_liboctave_error_handler) ("row dimension mismatch for append"); |
458 | 736 |
5275 | 737 octave_idx_type nc_insert = nc; |
458 | 738 ComplexMatrix retval (nr, nc + 1); |
739 retval.insert (*this, 0, 0); | |
740 retval.insert (a, 0, nc_insert); | |
741 return retval; | |
742 } | |
743 | |
744 ComplexMatrix | |
745 ComplexMatrix::append (const ComplexDiagMatrix& a) const | |
746 { | |
5275 | 747 octave_idx_type nr = rows (); |
748 octave_idx_type nc = cols (); | |
458 | 749 if (nr != a.rows ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
750 (*current_liboctave_error_handler) ("row dimension mismatch for append"); |
458 | 751 |
5275 | 752 octave_idx_type nc_insert = nc; |
458 | 753 ComplexMatrix retval (nr, nc + a.cols ()); |
754 retval.insert (*this, 0, 0); | |
755 retval.insert (a, 0, nc_insert); | |
756 return retval; | |
757 } | |
758 | |
759 ComplexMatrix | |
760 ComplexMatrix::stack (const Matrix& a) const | |
761 { | |
5275 | 762 octave_idx_type nr = rows (); |
763 octave_idx_type nc = cols (); | |
458 | 764 if (nc != a.cols ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
765 (*current_liboctave_error_handler) ("column dimension mismatch for stack"); |
458 | 766 |
5275 | 767 octave_idx_type nr_insert = nr; |
458 | 768 ComplexMatrix retval (nr + a.rows (), nc); |
769 retval.insert (*this, 0, 0); | |
770 retval.insert (a, nr_insert, 0); | |
771 return retval; | |
772 } | |
773 | |
774 ComplexMatrix | |
775 ComplexMatrix::stack (const RowVector& a) const | |
776 { | |
5275 | 777 octave_idx_type nr = rows (); |
778 octave_idx_type nc = cols (); | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
779 if (nc != a.numel ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
780 (*current_liboctave_error_handler) ("column dimension mismatch for stack"); |
458 | 781 |
5275 | 782 octave_idx_type nr_insert = nr; |
458 | 783 ComplexMatrix retval (nr + 1, nc); |
784 retval.insert (*this, 0, 0); | |
785 retval.insert (a, nr_insert, 0); | |
786 return retval; | |
787 } | |
788 | |
789 ComplexMatrix | |
790 ComplexMatrix::stack (const ColumnVector& a) const | |
791 { | |
5275 | 792 octave_idx_type nr = rows (); |
793 octave_idx_type nc = cols (); | |
458 | 794 if (nc != 1) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
795 (*current_liboctave_error_handler) ("column dimension mismatch for stack"); |
458 | 796 |
5275 | 797 octave_idx_type nr_insert = nr; |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
798 ComplexMatrix retval (nr + a.numel (), nc); |
458 | 799 retval.insert (*this, 0, 0); |
800 retval.insert (a, nr_insert, 0); | |
801 return retval; | |
802 } | |
803 | |
804 ComplexMatrix | |
805 ComplexMatrix::stack (const DiagMatrix& a) const | |
806 { | |
5275 | 807 octave_idx_type nr = rows (); |
808 octave_idx_type nc = cols (); | |
458 | 809 if (nc != a.cols ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
810 (*current_liboctave_error_handler) ("column dimension mismatch for stack"); |
458 | 811 |
5275 | 812 octave_idx_type nr_insert = nr; |
458 | 813 ComplexMatrix retval (nr + a.rows (), nc); |
814 retval.insert (*this, 0, 0); | |
815 retval.insert (a, nr_insert, 0); | |
816 return retval; | |
817 } | |
818 | |
819 ComplexMatrix | |
820 ComplexMatrix::stack (const ComplexMatrix& a) const | |
821 { | |
5275 | 822 octave_idx_type nr = rows (); |
823 octave_idx_type nc = cols (); | |
458 | 824 if (nc != a.cols ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
825 (*current_liboctave_error_handler) ("column dimension mismatch for stack"); |
458 | 826 |
5275 | 827 octave_idx_type nr_insert = nr; |
458 | 828 ComplexMatrix retval (nr + a.rows (), nc); |
829 retval.insert (*this, 0, 0); | |
830 retval.insert (a, nr_insert, 0); | |
831 return retval; | |
832 } | |
833 | |
834 ComplexMatrix | |
835 ComplexMatrix::stack (const ComplexRowVector& a) const | |
836 { | |
5275 | 837 octave_idx_type nr = rows (); |
838 octave_idx_type nc = cols (); | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
839 if (nc != a.numel ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
840 (*current_liboctave_error_handler) ("column dimension mismatch for stack"); |
458 | 841 |
5275 | 842 octave_idx_type nr_insert = nr; |
458 | 843 ComplexMatrix retval (nr + 1, nc); |
844 retval.insert (*this, 0, 0); | |
845 retval.insert (a, nr_insert, 0); | |
846 return retval; | |
847 } | |
848 | |
849 ComplexMatrix | |
850 ComplexMatrix::stack (const ComplexColumnVector& a) const | |
851 { | |
5275 | 852 octave_idx_type nr = rows (); |
853 octave_idx_type nc = cols (); | |
458 | 854 if (nc != 1) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
855 (*current_liboctave_error_handler) ("column dimension mismatch for stack"); |
458 | 856 |
5275 | 857 octave_idx_type nr_insert = nr; |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
858 ComplexMatrix retval (nr + a.numel (), nc); |
458 | 859 retval.insert (*this, 0, 0); |
860 retval.insert (a, nr_insert, 0); | |
861 return retval; | |
862 } | |
863 | |
864 ComplexMatrix | |
865 ComplexMatrix::stack (const ComplexDiagMatrix& a) const | |
866 { | |
5275 | 867 octave_idx_type nr = rows (); |
868 octave_idx_type nc = cols (); | |
458 | 869 if (nc != a.cols ()) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
870 (*current_liboctave_error_handler) ("column dimension mismatch for stack"); |
458 | 871 |
5275 | 872 octave_idx_type nr_insert = nr; |
458 | 873 ComplexMatrix retval (nr + a.rows (), nc); |
874 retval.insert (*this, 0, 0); | |
875 retval.insert (a, nr_insert, 0); | |
876 return retval; | |
877 } | |
878 | |
879 ComplexMatrix | |
880 conj (const ComplexMatrix& a) | |
881 { | |
13107
353c71c76f22
maint: fix compilation problem with g++ -std=c++0x option
Júlio Hoffimann <julio.hoffimann@gmail.com>
parents:
11596
diff
changeset
|
882 return do_mx_unary_map<Complex, Complex, std::conj<double> > (a); |
458 | 883 } |
884 | |
885 // resize is the destructive equivalent for this one | |
886 | |
887 ComplexMatrix | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
888 ComplexMatrix::extract (octave_idx_type r1, octave_idx_type c1, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
889 octave_idx_type r2, octave_idx_type c2) const |
458 | 890 { |
17663
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
16300
diff
changeset
|
891 if (r1 > r2) { std::swap (r1, r2); } |
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
16300
diff
changeset
|
892 if (c1 > c2) { std::swap (c1, c2); } |
5275 | 893 |
10805
8c858a1a2079
simplify Matrix::extract
Jaroslav Hajek <highegg@gmail.com>
parents:
10779
diff
changeset
|
894 return index (idx_vector (r1, r2+1), idx_vector (c1, c2+1)); |
4316 | 895 } |
896 | |
897 ComplexMatrix | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
898 ComplexMatrix::extract_n (octave_idx_type r1, octave_idx_type c1, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
899 octave_idx_type nr, octave_idx_type nc) const |
4316 | 900 { |
10806
7c542263a92a
omissions from last two patches
Jaroslav Hajek <highegg@gmail.com>
parents:
10805
diff
changeset
|
901 return index (idx_vector (r1, r1 + nr), idx_vector (c1, c1 + nc)); |
458 | 902 } |
903 | |
904 // extract row or column i. | |
905 | |
906 ComplexRowVector | |
5275 | 907 ComplexMatrix::row (octave_idx_type i) const |
458 | 908 { |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
909 return index (idx_vector (i), idx_vector::colon); |
458 | 910 } |
911 | |
912 ComplexColumnVector | |
5275 | 913 ComplexMatrix::column (octave_idx_type i) const |
458 | 914 { |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
915 return index (idx_vector::colon, idx_vector (i)); |
458 | 916 } |
917 | |
918 ComplexMatrix | |
919 ComplexMatrix::inverse (void) const | |
920 { | |
5275 | 921 octave_idx_type info; |
7788 | 922 double rcon; |
6207 | 923 MatrixType mattype (*this); |
7788 | 924 return inverse (mattype, info, rcon, 0, 0); |
6207 | 925 } |
926 | |
927 ComplexMatrix | |
6479 | 928 ComplexMatrix::inverse (octave_idx_type& info) const |
929 { | |
7788 | 930 double rcon; |
6479 | 931 MatrixType mattype (*this); |
7788 | 932 return inverse (mattype, info, rcon, 0, 0); |
6479 | 933 } |
934 | |
935 ComplexMatrix | |
7788 | 936 ComplexMatrix::inverse (octave_idx_type& info, double& rcon, int force, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
937 int calc_cond) const |
6479 | 938 { |
939 MatrixType mattype (*this); | |
7788 | 940 return inverse (mattype, info, rcon, force, calc_cond); |
6479 | 941 } |
942 | |
943 ComplexMatrix | |
6207 | 944 ComplexMatrix::inverse (MatrixType &mattype) const |
945 { | |
946 octave_idx_type info; | |
7788 | 947 double rcon; |
948 return inverse (mattype, info, rcon, 0, 0); | |
6207 | 949 } |
950 | |
951 ComplexMatrix | |
952 ComplexMatrix::inverse (MatrixType &mattype, octave_idx_type& info) const | |
953 { | |
7788 | 954 double rcon; |
955 return inverse (mattype, info, rcon, 0, 0); | |
458 | 956 } |
957 | |
958 ComplexMatrix | |
6207 | 959 ComplexMatrix::tinverse (MatrixType &mattype, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
960 double& rcon, int force, int calc_cond) const |
458 | 961 { |
6207 | 962 ComplexMatrix retval; |
963 | |
964 octave_idx_type nr = rows (); | |
965 octave_idx_type nc = cols (); | |
966 | |
967 if (nr != nc || nr == 0 || nc == 0) | |
968 (*current_liboctave_error_handler) ("inverse requires square matrix"); | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
969 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
970 int typ = mattype.type (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
971 char uplo = (typ == MatrixType::Lower ? 'L' : 'U'); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
972 char udiag = 'N'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
973 retval = *this; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
974 Complex *tmp_data = retval.fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
975 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
976 F77_XFCN (ztrtri, ZTRTRI, (F77_CONST_CHAR_ARG2 (&uplo, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
977 F77_CONST_CHAR_ARG2 (&udiag, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
978 nr, tmp_data, nr, info |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
979 F77_CHAR_ARG_LEN (1) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
980 F77_CHAR_ARG_LEN (1))); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
981 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
982 // Throw-away extra info LAPACK gives so as to not change output. |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
983 rcon = 0.0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
984 if (info != 0) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
985 info = -1; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
986 else if (calc_cond) |
6207 | 987 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
988 octave_idx_type ztrcon_info = 0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
989 char job = '1'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
990 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
991 OCTAVE_LOCAL_BUFFER (Complex, cwork, 2*nr); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
992 OCTAVE_LOCAL_BUFFER (double, rwork, nr); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
993 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
994 F77_XFCN (ztrcon, ZTRCON, (F77_CONST_CHAR_ARG2 (&job, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
995 F77_CONST_CHAR_ARG2 (&uplo, 1), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
996 F77_CONST_CHAR_ARG2 (&udiag, 1), |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
997 nr, tmp_data, nr, rcon, |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
998 cwork, rwork, ztrcon_info |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
999 F77_CHAR_ARG_LEN (1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1000 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1001 F77_CHAR_ARG_LEN (1))); |
6207 | 1002 |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1003 if (ztrcon_info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1004 info = -1; |
6207 | 1005 } |
1006 | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1007 if (info == -1 && ! force) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1008 retval = *this; // Restore matrix contents. |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1009 |
6207 | 1010 return retval; |
458 | 1011 } |
1012 | |
1013 ComplexMatrix | |
6207 | 1014 ComplexMatrix::finverse (MatrixType &mattype, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1015 double& rcon, int force, int calc_cond) const |
458 | 1016 { |
1948 | 1017 ComplexMatrix retval; |
1018 | |
5275 | 1019 octave_idx_type nr = rows (); |
1020 octave_idx_type nc = cols (); | |
1948 | 1021 |
458 | 1022 if (nr != nc) |
1948 | 1023 (*current_liboctave_error_handler) ("inverse requires square matrix"); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1024 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1025 Array<octave_idx_type> ipvt (dim_vector (nr, 1)); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1026 octave_idx_type *pipvt = ipvt.fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1027 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1028 retval = *this; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1029 Complex *tmp_data = retval.fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1030 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1031 Array<Complex> z (dim_vector (1, 1)); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1032 octave_idx_type lwork = -1; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1033 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1034 // Query the optimum work array size. |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1035 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1036 F77_XFCN (zgetri, ZGETRI, (nc, tmp_data, nr, pipvt, |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1037 z.fortran_vec (), lwork, info)); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1038 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1039 lwork = static_cast<octave_idx_type> (std::real (z(0))); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1040 lwork = (lwork < 2 *nc ? 2*nc : lwork); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1041 z.resize (dim_vector (lwork, 1)); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1042 Complex *pz = z.fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1043 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1044 info = 0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1045 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1046 // Calculate the norm of the matrix, for later use. |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1047 double anorm; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1048 //if (calc_cond) // Must always calculate anorm for bug #45577 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1049 anorm = retval.abs ().sum ().row (static_cast<octave_idx_type>(0)).max (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1050 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1051 // Work around bug #45577, LAPACK crashes Octave if norm is NaN |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1052 if (xisnan (anorm)) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1053 info = -1; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1054 else |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1055 F77_XFCN (zgetrf, ZGETRF, (nc, nc, tmp_data, nr, pipvt, info)); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1056 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1057 // Throw-away extra info LAPACK gives so as to not change output. |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1058 rcon = 0.0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1059 if (info != 0) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1060 info = -1; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1061 else if (calc_cond) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1062 { |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1063 // Now calculate the condition number for non-singular matrix. |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1064 octave_idx_type zgecon_info = 0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1065 char job = '1'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1066 Array<double> rz (dim_vector (2 * nc, 1)); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1067 double *prz = rz.fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1068 F77_XFCN (zgecon, ZGECON, (F77_CONST_CHAR_ARG2 (&job, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1069 nc, tmp_data, nr, anorm, |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1070 rcon, pz, prz, zgecon_info |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1071 F77_CHAR_ARG_LEN (1))); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1072 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1073 if (zgecon_info != 0) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1074 info = -1; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1075 } |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1076 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1077 if (info == -1 && ! force) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1078 retval = *this; // Restore contents. |
458 | 1079 else |
1080 { | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1081 octave_idx_type zgetri_info = 0; |
4329 | 1082 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1083 F77_XFCN (zgetri, ZGETRI, (nc, tmp_data, nr, pipvt, |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1084 pz, lwork, zgetri_info)); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1085 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1086 if (zgetri_info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1087 info = -1; |
458 | 1088 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1089 |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1090 if (info != 0) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1091 mattype.mark_as_rectangular (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1092 |
1948 | 1093 return retval; |
458 | 1094 } |
1095 | |
1096 ComplexMatrix | |
6207 | 1097 ComplexMatrix::inverse (MatrixType &mattype, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1098 double& rcon, int force, int calc_cond) const |
6207 | 1099 { |
1100 int typ = mattype.type (false); | |
1101 ComplexMatrix ret; | |
1102 | |
1103 if (typ == MatrixType::Unknown) | |
1104 typ = mattype.type (*this); | |
1105 | |
1106 if (typ == MatrixType::Upper || typ == MatrixType::Lower) | |
7788 | 1107 ret = tinverse (mattype, info, rcon, force, calc_cond); |
6840 | 1108 else |
6207 | 1109 { |
1110 if (mattype.is_hermitian ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1111 { |
20462
5ce959c55cc0
Propagate 'lower' in chol(a, 'lower') to underlying library function.
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
20232
diff
changeset
|
1112 ComplexCHOL chol (*this, info, true, calc_cond); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1113 if (info == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1114 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1115 if (calc_cond) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14557
diff
changeset
|
1116 rcon = chol.rcond (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1117 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1118 rcon = 1.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1119 ret = chol.inverse (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1120 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1121 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1122 mattype.mark_as_unsymmetric (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1123 } |
6207 | 1124 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20715
diff
changeset
|
1125 if (! mattype.is_hermitian ()) |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1126 ret = finverse (mattype, info, rcon, force, calc_cond); |
7788 | 1127 |
1128 if ((mattype.is_hermitian () || calc_cond) && rcon == 0.) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1129 ret = ComplexMatrix (rows (), columns (), Complex (octave_Inf, 0.)); |
6207 | 1130 } |
1131 | |
1132 return ret; | |
1133 } | |
1134 | |
1135 ComplexMatrix | |
4384 | 1136 ComplexMatrix::pseudo_inverse (double tol) const |
740 | 1137 { |
1549 | 1138 ComplexMatrix retval; |
1139 | |
3480 | 1140 ComplexSVD result (*this, SVD::economy); |
740 | 1141 |
1142 DiagMatrix S = result.singular_values (); | |
1143 ComplexMatrix U = result.left_singular_matrix (); | |
1144 ComplexMatrix V = result.right_singular_matrix (); | |
1145 | |
15448
0a0912a9ab6e
Replace deprecated DiagArray2<T>::diag calls with DiagArray2<T>::extract_diag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15383
diff
changeset
|
1146 ColumnVector sigma = S.extract_diag (); |
740 | 1147 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
1148 octave_idx_type r = sigma.numel () - 1; |
5275 | 1149 octave_idx_type nr = rows (); |
1150 octave_idx_type nc = cols (); | |
740 | 1151 |
1152 if (tol <= 0.0) | |
1153 { | |
1154 if (nr > nc) | |
15220
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15212
diff
changeset
|
1155 tol = nr * sigma.elem (0) * std::numeric_limits<double>::epsilon (); |
740 | 1156 else |
15220
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15212
diff
changeset
|
1157 tol = nc * sigma.elem (0) * std::numeric_limits<double>::epsilon (); |
740 | 1158 } |
1159 | |
1160 while (r >= 0 && sigma.elem (r) < tol) | |
1161 r--; | |
1162 | |
1163 if (r < 0) | |
1549 | 1164 retval = ComplexMatrix (nc, nr, 0.0); |
740 | 1165 else |
1166 { | |
1167 ComplexMatrix Ur = U.extract (0, 0, nr-1, r); | |
1168 DiagMatrix D = DiagMatrix (sigma.extract (0, r)) . inverse (); | |
1169 ComplexMatrix Vr = V.extract (0, 0, nc-1, r); | |
1549 | 1170 retval = Vr * D * Ur.hermitian (); |
740 | 1171 } |
1549 | 1172 |
1173 return retval; | |
740 | 1174 } |
1175 | |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
1176 #if defined (HAVE_FFTW) |
3827 | 1177 |
1178 ComplexMatrix | |
1179 ComplexMatrix::fourier (void) const | |
1180 { | |
1181 size_t nr = rows (); | |
1182 size_t nc = cols (); | |
1183 | |
1184 ComplexMatrix retval (nr, nc); | |
1185 | |
1186 size_t npts, nsamples; | |
1187 | |
1188 if (nr == 1 || nc == 1) | |
1189 { | |
1190 npts = nr > nc ? nr : nc; | |
1191 nsamples = 1; | |
1192 } | |
1193 else | |
1194 { | |
1195 npts = nr; | |
1196 nsamples = nc; | |
1197 } | |
1198 | |
1199 const Complex *in (data ()); | |
1200 Complex *out (retval.fortran_vec ()); | |
1201 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1202 octave_fftw::fft (in, out, npts, nsamples); |
3827 | 1203 |
1204 return retval; | |
1205 } | |
1206 | |
1207 ComplexMatrix | |
1208 ComplexMatrix::ifourier (void) const | |
1209 { | |
1210 size_t nr = rows (); | |
1211 size_t nc = cols (); | |
1212 | |
1213 ComplexMatrix retval (nr, nc); | |
1214 | |
1215 size_t npts, nsamples; | |
1216 | |
1217 if (nr == 1 || nc == 1) | |
1218 { | |
1219 npts = nr > nc ? nr : nc; | |
1220 nsamples = 1; | |
1221 } | |
1222 else | |
1223 { | |
1224 npts = nr; | |
1225 nsamples = nc; | |
1226 } | |
1227 | |
1228 const Complex *in (data ()); | |
1229 Complex *out (retval.fortran_vec ()); | |
1230 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1231 octave_fftw::ifft (in, out, npts, nsamples); |
3827 | 1232 |
1233 return retval; | |
1234 } | |
1235 | |
1236 ComplexMatrix | |
1237 ComplexMatrix::fourier2d (void) const | |
1238 { | |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
1239 dim_vector dv (rows (), cols ()); |
4773 | 1240 |
1241 ComplexMatrix retval (rows (), cols ()); | |
1242 const Complex *in (data ()); | |
1243 Complex *out (retval.fortran_vec ()); | |
1244 | |
1245 octave_fftw::fftNd (in, out, 2, dv); | |
3827 | 1246 |
1247 return retval; | |
1248 } | |
1249 | |
1250 ComplexMatrix | |
1251 ComplexMatrix::ifourier2d (void) const | |
1252 { | |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
1253 dim_vector dv (rows (), cols ()); |
4773 | 1254 |
1255 ComplexMatrix retval (rows (), cols ()); | |
1256 const Complex *in (data ()); | |
1257 Complex *out (retval.fortran_vec ()); | |
1258 | |
1259 octave_fftw::ifftNd (in, out, 2, dv); | |
3827 | 1260 |
1261 return retval; | |
1262 } | |
1263 | |
1264 #else | |
1265 | |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
1266 extern "C" |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
1267 { |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
1268 // Note that the original complex fft routines were not written for |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
1269 // double complex arguments. They have been modified by adding an |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
1270 // implicit double precision (a-h,o-z) statement at the beginning of |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
1271 // each subroutine. |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
1272 |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
1273 F77_RET_T |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
1274 F77_FUNC (zffti, ZFFTI) (const octave_idx_type&, Complex*); |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
1275 |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
1276 F77_RET_T |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
1277 F77_FUNC (zfftf, ZFFTF) (const octave_idx_type&, Complex*, Complex*); |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
1278 |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
1279 F77_RET_T |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
1280 F77_FUNC (zfftb, ZFFTB) (const octave_idx_type&, Complex*, Complex*); |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
1281 } |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
1282 |
740 | 1283 ComplexMatrix |
458 | 1284 ComplexMatrix::fourier (void) const |
1285 { | |
1948 | 1286 ComplexMatrix retval; |
1287 | |
5275 | 1288 octave_idx_type nr = rows (); |
1289 octave_idx_type nc = cols (); | |
1290 | |
1291 octave_idx_type npts, nsamples; | |
1948 | 1292 |
458 | 1293 if (nr == 1 || nc == 1) |
1294 { | |
1295 npts = nr > nc ? nr : nc; | |
1296 nsamples = 1; | |
1297 } | |
1298 else | |
1299 { | |
1300 npts = nr; | |
1301 nsamples = nc; | |
1302 } | |
1303 | |
5275 | 1304 octave_idx_type nn = 4*npts+15; |
1948 | 1305 |
19340
fcd9e1198847
CMatrix.cc: Use undeprecated Array constructor (bug #43646).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19321
diff
changeset
|
1306 Array<Complex> wsave (dim_vector (nn, 1)); |
1948 | 1307 Complex *pwsave = wsave.fortran_vec (); |
1308 | |
1309 retval = *this; | |
1310 Complex *tmp_data = retval.fortran_vec (); | |
1311 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
1312 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
458 | 1313 |
5275 | 1314 for (octave_idx_type j = 0; j < nsamples; j++) |
4153 | 1315 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10124
diff
changeset
|
1316 octave_quit (); |
4153 | 1317 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
1318 F77_FUNC (zfftf, ZFFTF) (npts, &tmp_data[npts*j], pwsave); |
4153 | 1319 } |
1948 | 1320 |
1321 return retval; | |
458 | 1322 } |
1323 | |
1324 ComplexMatrix | |
1325 ComplexMatrix::ifourier (void) const | |
1326 { | |
1948 | 1327 ComplexMatrix retval; |
1328 | |
5275 | 1329 octave_idx_type nr = rows (); |
1330 octave_idx_type nc = cols (); | |
1331 | |
1332 octave_idx_type npts, nsamples; | |
1948 | 1333 |
458 | 1334 if (nr == 1 || nc == 1) |
1335 { | |
1336 npts = nr > nc ? nr : nc; | |
1337 nsamples = 1; | |
1338 } | |
1339 else | |
1340 { | |
1341 npts = nr; | |
1342 nsamples = nc; | |
1343 } | |
1344 | |
5275 | 1345 octave_idx_type nn = 4*npts+15; |
1948 | 1346 |
19340
fcd9e1198847
CMatrix.cc: Use undeprecated Array constructor (bug #43646).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19321
diff
changeset
|
1347 Array<Complex> wsave (dim_vector (nn, 1)); |
1948 | 1348 Complex *pwsave = wsave.fortran_vec (); |
1349 | |
1350 retval = *this; | |
1351 Complex *tmp_data = retval.fortran_vec (); | |
1352 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
1353 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
458 | 1354 |
5275 | 1355 for (octave_idx_type j = 0; j < nsamples; j++) |
4153 | 1356 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10124
diff
changeset
|
1357 octave_quit (); |
4153 | 1358 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
1359 F77_FUNC (zfftb, ZFFTB) (npts, &tmp_data[npts*j], pwsave); |
4153 | 1360 } |
458 | 1361 |
5275 | 1362 for (octave_idx_type j = 0; j < npts*nsamples; j++) |
3572 | 1363 tmp_data[j] = tmp_data[j] / static_cast<double> (npts); |
458 | 1364 |
1948 | 1365 return retval; |
458 | 1366 } |
1367 | |
677 | 1368 ComplexMatrix |
1369 ComplexMatrix::fourier2d (void) const | |
1370 { | |
1948 | 1371 ComplexMatrix retval; |
1372 | |
5275 | 1373 octave_idx_type nr = rows (); |
1374 octave_idx_type nc = cols (); | |
1375 | |
1376 octave_idx_type npts, nsamples; | |
1948 | 1377 |
677 | 1378 if (nr == 1 || nc == 1) |
1379 { | |
1380 npts = nr > nc ? nr : nc; | |
1381 nsamples = 1; | |
1382 } | |
1383 else | |
1384 { | |
1385 npts = nr; | |
1386 nsamples = nc; | |
1387 } | |
1388 | |
5275 | 1389 octave_idx_type nn = 4*npts+15; |
1948 | 1390 |
19340
fcd9e1198847
CMatrix.cc: Use undeprecated Array constructor (bug #43646).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19321
diff
changeset
|
1391 Array<Complex> wsave (dim_vector (nn, 1)); |
1948 | 1392 Complex *pwsave = wsave.fortran_vec (); |
1393 | |
1394 retval = *this; | |
1395 Complex *tmp_data = retval.fortran_vec (); | |
1396 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
1397 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
677 | 1398 |
5275 | 1399 for (octave_idx_type j = 0; j < nsamples; j++) |
4153 | 1400 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10124
diff
changeset
|
1401 octave_quit (); |
4153 | 1402 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
1403 F77_FUNC (zfftf, ZFFTF) (npts, &tmp_data[npts*j], pwsave); |
4153 | 1404 } |
677 | 1405 |
1406 npts = nc; | |
1407 nsamples = nr; | |
1408 nn = 4*npts+15; | |
1948 | 1409 |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1410 wsave.resize (dim_vector (nn, 1)); |
1948 | 1411 pwsave = wsave.fortran_vec (); |
1412 | |
19340
fcd9e1198847
CMatrix.cc: Use undeprecated Array constructor (bug #43646).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19321
diff
changeset
|
1413 Array<Complex> tmp (dim_vector (npts, 1)); |
4773 | 1414 Complex *prow = tmp.fortran_vec (); |
1948 | 1415 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
1416 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
677 | 1417 |
5275 | 1418 for (octave_idx_type j = 0; j < nsamples; j++) |
677 | 1419 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10124
diff
changeset
|
1420 octave_quit (); |
4153 | 1421 |
5275 | 1422 for (octave_idx_type i = 0; i < npts; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1423 prow[i] = tmp_data[i*nr + j]; |
1948 | 1424 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
1425 F77_FUNC (zfftf, ZFFTF) (npts, prow, pwsave); |
677 | 1426 |
5275 | 1427 for (octave_idx_type i = 0; i < npts; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1428 tmp_data[i*nr + j] = prow[i]; |
677 | 1429 } |
1430 | |
1948 | 1431 return retval; |
677 | 1432 } |
1433 | |
1434 ComplexMatrix | |
1435 ComplexMatrix::ifourier2d (void) const | |
1436 { | |
1948 | 1437 ComplexMatrix retval; |
1438 | |
5275 | 1439 octave_idx_type nr = rows (); |
1440 octave_idx_type nc = cols (); | |
1441 | |
1442 octave_idx_type npts, nsamples; | |
1948 | 1443 |
677 | 1444 if (nr == 1 || nc == 1) |
1445 { | |
1446 npts = nr > nc ? nr : nc; | |
1447 nsamples = 1; | |
1448 } | |
1449 else | |
1450 { | |
1451 npts = nr; | |
1452 nsamples = nc; | |
1453 } | |
1454 | |
5275 | 1455 octave_idx_type nn = 4*npts+15; |
1948 | 1456 |
19340
fcd9e1198847
CMatrix.cc: Use undeprecated Array constructor (bug #43646).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19321
diff
changeset
|
1457 Array<Complex> wsave (dim_vector (nn, 1)); |
1948 | 1458 Complex *pwsave = wsave.fortran_vec (); |
1459 | |
1460 retval = *this; | |
1461 Complex *tmp_data = retval.fortran_vec (); | |
1462 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
1463 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
677 | 1464 |
5275 | 1465 for (octave_idx_type j = 0; j < nsamples; j++) |
4153 | 1466 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10124
diff
changeset
|
1467 octave_quit (); |
4153 | 1468 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
1469 F77_FUNC (zfftb, ZFFTB) (npts, &tmp_data[npts*j], pwsave); |
4153 | 1470 } |
677 | 1471 |
5275 | 1472 for (octave_idx_type j = 0; j < npts*nsamples; j++) |
3572 | 1473 tmp_data[j] = tmp_data[j] / static_cast<double> (npts); |
677 | 1474 |
1475 npts = nc; | |
1476 nsamples = nr; | |
1477 nn = 4*npts+15; | |
1948 | 1478 |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1479 wsave.resize (dim_vector (nn, 1)); |
1948 | 1480 pwsave = wsave.fortran_vec (); |
1481 | |
19340
fcd9e1198847
CMatrix.cc: Use undeprecated Array constructor (bug #43646).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19321
diff
changeset
|
1482 Array<Complex> tmp (dim_vector (npts, 1)); |
4773 | 1483 Complex *prow = tmp.fortran_vec (); |
1948 | 1484 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
1485 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
677 | 1486 |
5275 | 1487 for (octave_idx_type j = 0; j < nsamples; j++) |
677 | 1488 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10124
diff
changeset
|
1489 octave_quit (); |
4153 | 1490 |
5275 | 1491 for (octave_idx_type i = 0; i < npts; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1492 prow[i] = tmp_data[i*nr + j]; |
1948 | 1493 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
1494 F77_FUNC (zfftb, ZFFTB) (npts, prow, pwsave); |
677 | 1495 |
5275 | 1496 for (octave_idx_type i = 0; i < npts; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1497 tmp_data[i*nr + j] = prow[i] / static_cast<double> (npts); |
677 | 1498 } |
1499 | |
1948 | 1500 return retval; |
677 | 1501 } |
1502 | |
3827 | 1503 #endif |
1504 | |
458 | 1505 ComplexDET |
1506 ComplexMatrix::determinant (void) const | |
1507 { | |
5275 | 1508 octave_idx_type info; |
7788 | 1509 double rcon; |
1510 return determinant (info, rcon, 0); | |
458 | 1511 } |
1512 | |
1513 ComplexDET | |
5275 | 1514 ComplexMatrix::determinant (octave_idx_type& info) const |
458 | 1515 { |
7788 | 1516 double rcon; |
1517 return determinant (info, rcon, 0); | |
458 | 1518 } |
1519 | |
1520 ComplexDET | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1521 ComplexMatrix::determinant (octave_idx_type& info, double& rcon, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1522 int calc_cond) const |
458 | 1523 { |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1524 MatrixType mattype (*this); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1525 return determinant (mattype, info, rcon, calc_cond); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1526 } |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1527 |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1528 ComplexDET |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1529 ComplexMatrix::determinant (MatrixType& mattype, |
8806 | 1530 octave_idx_type& info, double& rcon, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1531 int calc_cond) const |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1532 { |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1533 ComplexDET retval (1.0); |
458 | 1534 |
13828
f1b023fd098d
always initialize info and rcon in Matrix determinant methods
John W. Eaton <jwe@octave.org>
parents:
13107
diff
changeset
|
1535 info = 0; |
f1b023fd098d
always initialize info and rcon in Matrix determinant methods
John W. Eaton <jwe@octave.org>
parents:
13107
diff
changeset
|
1536 rcon = 0.0; |
f1b023fd098d
always initialize info and rcon in Matrix determinant methods
John W. Eaton <jwe@octave.org>
parents:
13107
diff
changeset
|
1537 |
5275 | 1538 octave_idx_type nr = rows (); |
1539 octave_idx_type nc = cols (); | |
458 | 1540 |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1541 if (nr != nc) |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1542 (*current_liboctave_error_handler) ("matrix must be square"); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1543 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1544 volatile int typ = mattype.type (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1545 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1546 // Even though the matrix is marked as singular (Rectangular), we may |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1547 // still get a useful number from the LU factorization, because it always |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1548 // completes. |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1549 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1550 if (typ == MatrixType::Unknown) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1551 typ = mattype.type (*this); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1552 else if (typ == MatrixType::Rectangular) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1553 typ = MatrixType::Full; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1554 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1555 if (typ == MatrixType::Lower || typ == MatrixType::Upper) |
458 | 1556 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1557 for (octave_idx_type i = 0; i < nc; i++) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1558 retval *= elem (i,i); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1559 } |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1560 else if (typ == MatrixType::Hermitian) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1561 { |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1562 ComplexMatrix atmp = *this; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1563 Complex *tmp_data = atmp.fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1564 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1565 double anorm = 0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1566 if (calc_cond) anorm = xnorm (*this, 1); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1567 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1568 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1569 char job = 'L'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1570 F77_XFCN (zpotrf, ZPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr, |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1571 tmp_data, nr, info |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1572 F77_CHAR_ARG_LEN (1))); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1573 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1574 if (info != 0) |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1575 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1576 rcon = 0.0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1577 mattype.mark_as_unsymmetric (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1578 typ = MatrixType::Full; |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1579 } |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1580 else |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1581 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1582 Array<Complex> z (dim_vector (2 * nc, 1)); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1583 Complex *pz = z.fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1584 Array<double> rz (dim_vector (nc, 1)); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1585 double *prz = rz.fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1586 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1587 F77_XFCN (zpocon, ZPOCON, (F77_CONST_CHAR_ARG2 (&job, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1588 nr, tmp_data, nr, anorm, |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1589 rcon, pz, prz, info |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1590 F77_CHAR_ARG_LEN (1))); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1591 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1592 if (info != 0) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1593 rcon = 0.0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1594 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1595 for (octave_idx_type i = 0; i < nc; i++) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1596 retval *= atmp (i,i); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1597 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1598 retval = retval.square (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1599 } |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1600 } |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1601 else if (typ != MatrixType::Full) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1602 (*current_liboctave_error_handler) ("det: invalid dense matrix type"); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1603 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1604 if (typ == MatrixType::Full) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1605 { |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1606 Array<octave_idx_type> ipvt (dim_vector (nr, 1)); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1607 octave_idx_type *pipvt = ipvt.fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1608 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1609 ComplexMatrix atmp = *this; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1610 Complex *tmp_data = atmp.fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1611 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1612 info = 0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1613 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1614 // Calculate the norm of the matrix, for later use. |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1615 double anorm = 0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1616 //if (calc_cond) // Must always calculate anorm for bug #45577 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1617 anorm = xnorm (*this, 1); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1618 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1619 // Work around bug #45577, LAPACK crashes Octave if norm is NaN |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1620 if (xisnan (anorm)) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1621 info = -1; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1622 else |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1623 F77_XFCN (zgetrf, ZGETRF, (nr, nr, tmp_data, nr, pipvt, info)); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1624 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1625 // Throw-away extra info LAPACK gives so as to not change output. |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1626 rcon = 0.0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1627 if (info != 0) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1628 { |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1629 info = -1; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1630 retval = ComplexDET (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1631 } |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1632 else |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1633 { |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1634 if (calc_cond) |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1635 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1636 // Now calc the condition number for non-singular matrix. |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1637 char job = '1'; |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1638 Array<Complex> z (dim_vector (2 * nc, 1)); |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1639 Complex *pz = z.fortran_vec (); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1640 Array<double> rz (dim_vector (2 * nc, 1)); |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1641 double *prz = rz.fortran_vec (); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1642 |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1643 F77_XFCN (zgecon, ZGECON, (F77_CONST_CHAR_ARG2 (&job, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1644 nc, tmp_data, nr, anorm, |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1645 rcon, pz, prz, info |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1646 F77_CHAR_ARG_LEN (1))); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1647 } |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1648 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1649 if (info != 0) |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1650 { |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1651 info = -1; |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1652 retval = ComplexDET (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1653 } |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1654 else |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1655 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1656 for (octave_idx_type i = 0; i < nc; i++) |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1657 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1658 Complex c = atmp(i,i); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1659 retval *= (ipvt(i) != (i+1)) ? -c : c; |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1660 } |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1661 } |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1662 } |
458 | 1663 } |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1664 |
458 | 1665 return retval; |
1666 } | |
1667 | |
7788 | 1668 double |
1669 ComplexMatrix::rcond (void) const | |
1670 { | |
1671 MatrixType mattype (*this); | |
1672 return rcond (mattype); | |
1673 } | |
1674 | |
1675 double | |
1676 ComplexMatrix::rcond (MatrixType &mattype) const | |
1677 { | |
18632
cb37b17b6091
Initialize rcond value to octave_NaN.
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents:
18084
diff
changeset
|
1678 double rcon = octave_NaN; |
7788 | 1679 octave_idx_type nr = rows (); |
1680 octave_idx_type nc = cols (); | |
1681 | |
1682 if (nr != nc) | |
1683 (*current_liboctave_error_handler) ("matrix must be square"); | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1684 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1685 if (nr == 0 || nc == 0) |
7788 | 1686 rcon = octave_Inf; |
1687 else | |
1688 { | |
16300
23c5f90f92cd
eliminate some variable might be clobbered by 'longjmp' or 'vfork' warnings
John W. Eaton <jwe@octave.org>
parents:
15448
diff
changeset
|
1689 volatile int typ = mattype.type (); |
7788 | 1690 |
1691 if (typ == MatrixType::Unknown) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1692 typ = mattype.type (*this); |
7788 | 1693 |
1694 // Only calculate the condition number for LU/Cholesky | |
1695 if (typ == MatrixType::Upper) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1696 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1697 const Complex *tmp_data = fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1698 octave_idx_type info = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1699 char norm = '1'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1700 char uplo = 'U'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1701 char dia = 'N'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1702 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1703 Array<Complex> z (dim_vector (2 * nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1704 Complex *pz = z.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1705 Array<double> rz (dim_vector (nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1706 double *prz = rz.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1707 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1708 F77_XFCN (ztrcon, ZTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1709 F77_CONST_CHAR_ARG2 (&uplo, 1), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1710 F77_CONST_CHAR_ARG2 (&dia, 1), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1711 nr, tmp_data, nr, rcon, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1712 pz, prz, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1713 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1714 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1715 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1716 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1717 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1718 rcon = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1719 } |
7788 | 1720 else if (typ == MatrixType::Permuted_Upper) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1721 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1722 ("permuted triangular matrix not implemented"); |
7788 | 1723 else if (typ == MatrixType::Lower) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1724 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1725 const Complex *tmp_data = fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1726 octave_idx_type info = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1727 char norm = '1'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1728 char uplo = 'L'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1729 char dia = 'N'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1730 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1731 Array<Complex> z (dim_vector (2 * nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1732 Complex *pz = z.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1733 Array<double> rz (dim_vector (nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1734 double *prz = rz.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1735 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1736 F77_XFCN (ztrcon, ZTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1737 F77_CONST_CHAR_ARG2 (&uplo, 1), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1738 F77_CONST_CHAR_ARG2 (&dia, 1), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1739 nr, tmp_data, nr, rcon, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1740 pz, prz, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1741 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1742 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1743 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1744 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1745 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1746 rcon = 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1747 } |
7788 | 1748 else if (typ == MatrixType::Permuted_Lower) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1749 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1750 ("permuted triangular matrix not implemented"); |
7788 | 1751 else if (typ == MatrixType::Full || typ == MatrixType::Hermitian) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1752 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1753 double anorm = -1.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1754 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1755 if (typ == MatrixType::Hermitian) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1756 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1757 octave_idx_type info = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1758 char job = 'L'; |
15382
197774b411ec
rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1759 |
197774b411ec
rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1760 ComplexMatrix atmp = *this; |
197774b411ec
rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1761 Complex *tmp_data = atmp.fortran_vec (); |
197774b411ec
rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1762 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1763 anorm = atmp.abs().sum(). |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1764 row(static_cast<octave_idx_type>(0)).max(); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1765 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1766 F77_XFCN (zpotrf, ZPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1767 tmp_data, nr, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1768 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1769 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1770 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1771 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1772 rcon = 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1773 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1774 mattype.mark_as_unsymmetric (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1775 typ = MatrixType::Full; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1776 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1777 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1778 { |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1779 Array<Complex> z (dim_vector (2 * nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1780 Complex *pz = z.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1781 Array<double> rz (dim_vector (nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1782 double *prz = rz.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1783 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1784 F77_XFCN (zpocon, ZPOCON, (F77_CONST_CHAR_ARG2 (&job, 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1785 nr, tmp_data, nr, anorm, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1786 rcon, pz, prz, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1787 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1788 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1789 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1790 rcon = 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1791 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1792 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1793 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1794 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1795 if (typ == MatrixType::Full) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1796 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1797 octave_idx_type info = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1798 |
15382
197774b411ec
rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1799 ComplexMatrix atmp = *this; |
197774b411ec
rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1800 Complex *tmp_data = atmp.fortran_vec (); |
197774b411ec
rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1801 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1802 Array<octave_idx_type> ipvt (dim_vector (nr, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1803 octave_idx_type *pipvt = ipvt.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1804 |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
1805 if (anorm < 0.) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14557
diff
changeset
|
1806 anorm = atmp.abs ().sum (). |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1807 row(static_cast<octave_idx_type>(0)).max (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1808 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1809 Array<Complex> z (dim_vector (2 * nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1810 Complex *pz = z.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1811 Array<double> rz (dim_vector (2 * nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1812 double *prz = rz.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1813 |
20598
ffc6cdcd02c5
Fix segfault when complex double matrix calls ZGETRF (bug #45577).
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
1814 // Work around bug #45577, LAPACK crashes Octave if norm is NaN |
ffc6cdcd02c5
Fix segfault when complex double matrix calls ZGETRF (bug #45577).
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
1815 if (xisnan (anorm)) |
ffc6cdcd02c5
Fix segfault when complex double matrix calls ZGETRF (bug #45577).
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
1816 info = -1; |
ffc6cdcd02c5
Fix segfault when complex double matrix calls ZGETRF (bug #45577).
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
1817 else |
ffc6cdcd02c5
Fix segfault when complex double matrix calls ZGETRF (bug #45577).
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
1818 F77_XFCN (zgetrf, ZGETRF, (nr, nr, tmp_data, nr, pipvt, info)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1819 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1820 if (info != 0) |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1821 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1822 rcon = 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1823 mattype.mark_as_rectangular (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1824 } |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1825 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1826 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1827 char job = '1'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1828 F77_XFCN (zgecon, ZGECON, (F77_CONST_CHAR_ARG2 (&job, 1), |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1829 nc, tmp_data, nr, anorm, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1830 rcon, pz, prz, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1831 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1832 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1833 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1834 rcon = 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1835 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1836 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1837 } |
7788 | 1838 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1839 rcon = 0.0; |
7788 | 1840 } |
1841 | |
1842 return rcon; | |
1843 } | |
1844 | |
458 | 1845 ComplexMatrix |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1846 ComplexMatrix::utsolve (MatrixType &mattype, const ComplexMatrix& b, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1847 octave_idx_type& info, double& rcon, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1848 solve_singularity_handler sing_handler, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1849 bool calc_cond, blas_trans_type transt) const |
5785 | 1850 { |
1851 ComplexMatrix retval; | |
1852 | |
1853 octave_idx_type nr = rows (); | |
1854 octave_idx_type nc = cols (); | |
1855 | |
6924 | 1856 if (nr != b.rows ()) |
5785 | 1857 (*current_liboctave_error_handler) |
1858 ("matrix dimension mismatch solution of linear equations"); | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1859 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1860 if (nr == 0 || nc == 0 || b.cols () == 0) |
6924 | 1861 retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0)); |
5785 | 1862 else |
1863 { | |
1864 volatile int typ = mattype.type (); | |
1865 | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1866 if (typ != MatrixType::Permuted_Upper && typ != MatrixType::Upper) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1867 (*current_liboctave_error_handler) ("incorrect matrix type"); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1868 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1869 octave_idx_type b_nc = b.cols (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1870 rcon = 1.; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1871 info = 0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1872 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1873 if (typ == MatrixType::Permuted_Upper) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1874 (*current_liboctave_error_handler) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1875 ("permuted triangular matrix not implemented"); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1876 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1877 const Complex *tmp_data = fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1878 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1879 retval = b; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1880 Complex *result = retval.fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1881 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1882 char uplo = 'U'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1883 char trans = get_blas_char (transt); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1884 char dia = 'N'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1885 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1886 F77_XFCN (ztrtrs, ZTRTRS, (F77_CONST_CHAR_ARG2 (&uplo, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1887 F77_CONST_CHAR_ARG2 (&trans, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1888 F77_CONST_CHAR_ARG2 (&dia, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1889 nr, b_nc, tmp_data, nr, |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1890 result, nr, info |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1891 F77_CHAR_ARG_LEN (1) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1892 F77_CHAR_ARG_LEN (1) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1893 F77_CHAR_ARG_LEN (1))); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1894 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1895 if (calc_cond) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1896 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1897 char norm = '1'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1898 uplo = 'U'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1899 dia = 'N'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1900 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1901 Array<Complex> z (dim_vector (2 * nc, 1)); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1902 Complex *pz = z.fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1903 Array<double> rz (dim_vector (nc, 1)); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1904 double *prz = rz.fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1905 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1906 F77_XFCN (ztrcon, ZTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1907 F77_CONST_CHAR_ARG2 (&uplo, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1908 F77_CONST_CHAR_ARG2 (&dia, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1909 nr, tmp_data, nr, rcon, |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1910 pz, prz, info |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1911 F77_CHAR_ARG_LEN (1) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1912 F77_CHAR_ARG_LEN (1) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1913 F77_CHAR_ARG_LEN (1))); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1914 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1915 if (info != 0) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1916 info = -2; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1917 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1918 volatile double rcond_plus_one = rcon + 1.0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1919 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1920 if (rcond_plus_one == 1.0 || xisnan (rcon)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1921 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1922 info = -2; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1923 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1924 if (sing_handler) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1925 sing_handler (rcon); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1926 else |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1927 warn_singular_matrix (rcon); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1928 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1929 } |
5785 | 1930 } |
1931 | |
1932 return retval; | |
1933 } | |
1934 | |
1935 ComplexMatrix | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1936 ComplexMatrix::ltsolve (MatrixType &mattype, const ComplexMatrix& b, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1937 octave_idx_type& info, double& rcon, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1938 solve_singularity_handler sing_handler, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1939 bool calc_cond, blas_trans_type transt) const |
5785 | 1940 { |
1941 ComplexMatrix retval; | |
1942 | |
1943 octave_idx_type nr = rows (); | |
1944 octave_idx_type nc = cols (); | |
1945 | |
6924 | 1946 if (nr != b.rows ()) |
5785 | 1947 (*current_liboctave_error_handler) |
1948 ("matrix dimension mismatch solution of linear equations"); | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1949 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1950 if (nr == 0 || nc == 0 || b.cols () == 0) |
6924 | 1951 retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0)); |
5785 | 1952 else |
1953 { | |
1954 volatile int typ = mattype.type (); | |
1955 | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1956 if (typ != MatrixType::Permuted_Lower && typ != MatrixType::Lower) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1957 (*current_liboctave_error_handler) ("incorrect matrix type"); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1958 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1959 octave_idx_type b_nc = b.cols (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1960 rcon = 1.; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1961 info = 0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1962 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1963 if (typ == MatrixType::Permuted_Lower) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1964 (*current_liboctave_error_handler) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1965 ("permuted triangular matrix not implemented"); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1966 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1967 const Complex *tmp_data = fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1968 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1969 retval = b; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1970 Complex *result = retval.fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1971 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1972 char uplo = 'L'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1973 char trans = get_blas_char (transt); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1974 char dia = 'N'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1975 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1976 F77_XFCN (ztrtrs, ZTRTRS, (F77_CONST_CHAR_ARG2 (&uplo, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1977 F77_CONST_CHAR_ARG2 (&trans, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1978 F77_CONST_CHAR_ARG2 (&dia, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1979 nr, b_nc, tmp_data, nr, |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1980 result, nr, info |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1981 F77_CHAR_ARG_LEN (1) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1982 F77_CHAR_ARG_LEN (1) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1983 F77_CHAR_ARG_LEN (1))); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1984 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1985 if (calc_cond) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1986 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1987 char norm = '1'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1988 uplo = 'L'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1989 dia = 'N'; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1990 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1991 Array<Complex> z (dim_vector (2 * nc, 1)); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1992 Complex *pz = z.fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1993 Array<double> rz (dim_vector (nc, 1)); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1994 double *prz = rz.fortran_vec (); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1995 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1996 F77_XFCN (ztrcon, ZTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1997 F77_CONST_CHAR_ARG2 (&uplo, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1998 F77_CONST_CHAR_ARG2 (&dia, 1), |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
1999 nr, tmp_data, nr, rcon, |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2000 pz, prz, info |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2001 F77_CHAR_ARG_LEN (1) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2002 F77_CHAR_ARG_LEN (1) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2003 F77_CHAR_ARG_LEN (1))); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2004 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2005 if (info != 0) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2006 info = -2; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2007 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2008 volatile double rcond_plus_one = rcon + 1.0; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2009 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2010 if (rcond_plus_one == 1.0 || xisnan (rcon)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2011 { |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2012 info = -2; |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2013 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2014 if (sing_handler) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2015 sing_handler (rcon); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2016 else |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2017 warn_singular_matrix (rcon); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2018 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2019 } |
5785 | 2020 } |
2021 | |
2022 return retval; | |
2023 } | |
2024 | |
2025 ComplexMatrix | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2026 ComplexMatrix::fsolve (MatrixType &mattype, const ComplexMatrix& b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2027 octave_idx_type& info, double& rcon, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2028 solve_singularity_handler sing_handler, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2029 bool calc_cond) const |
5785 | 2030 { |
2031 ComplexMatrix retval; | |
2032 | |
2033 octave_idx_type nr = rows (); | |
2034 octave_idx_type nc = cols (); | |
2035 | |
6924 | 2036 |
2037 if (nr != nc || nr != b.rows ()) | |
5785 | 2038 (*current_liboctave_error_handler) |
6924 | 2039 ("matrix dimension mismatch solution of linear equations"); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2040 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2041 if (nr == 0 || b.cols () == 0) |
6924 | 2042 retval = ComplexMatrix (nc, b.cols (), Complex (0.0, 0.0)); |
5785 | 2043 else |
2044 { | |
2045 volatile int typ = mattype.type (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2046 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2047 // Calculate the norm of the matrix, for later use. |
5785 | 2048 double anorm = -1.; |
2049 | |
2050 if (typ == MatrixType::Hermitian) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2051 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2052 info = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2053 char job = 'L'; |
15382
197774b411ec
rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
2054 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2055 ComplexMatrix atmp = *this; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2056 Complex *tmp_data = atmp.fortran_vec (); |
15382
197774b411ec
rcond: use new copy of data for full factorization if positive definite cholesky factorization fails (bug #37336)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
2057 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2058 anorm = atmp.abs().sum().row(static_cast<octave_idx_type>(0)).max(); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2059 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2060 F77_XFCN (zpotrf, ZPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2061 tmp_data, nr, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2062 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2063 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2064 // Throw-away extra info LAPACK gives so as to not change output. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2065 rcon = 0.0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2066 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2067 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2068 info = -2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2069 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2070 mattype.mark_as_unsymmetric (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2071 typ = MatrixType::Full; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2072 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2073 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2074 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2075 if (calc_cond) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2076 { |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2077 Array<Complex> z (dim_vector (2 * nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2078 Complex *pz = z.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2079 Array<double> rz (dim_vector (nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2080 double *prz = rz.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2081 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2082 F77_XFCN (zpocon, ZPOCON, (F77_CONST_CHAR_ARG2 (&job, 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2083 nr, tmp_data, nr, anorm, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2084 rcon, pz, prz, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2085 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2086 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2087 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2088 info = -2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2089 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2090 volatile double rcond_plus_one = rcon + 1.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2091 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2092 if (rcond_plus_one == 1.0 || xisnan (rcon)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2093 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2094 info = -2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2095 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2096 if (sing_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2097 sing_handler (rcon); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2098 else |
21112
358aa7fcbd33
Rename errwarn_singular_matrix to warn_singular_matrix.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
2099 warn_singular_matrix (rcon); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2100 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2101 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2102 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2103 if (info == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2104 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2105 retval = b; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2106 Complex *result = retval.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2107 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2108 octave_idx_type b_nc = b.cols (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2109 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2110 F77_XFCN (zpotrs, ZPOTRS, (F77_CONST_CHAR_ARG2 (&job, 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2111 nr, b_nc, tmp_data, nr, |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14557
diff
changeset
|
2112 result, b.rows (), info |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2113 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2114 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2115 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2116 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2117 mattype.mark_as_unsymmetric (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2118 typ = MatrixType::Full; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2119 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2120 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2121 } |
5785 | 2122 |
2123 if (typ == MatrixType::Full) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2124 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2125 info = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2126 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2127 Array<octave_idx_type> ipvt (dim_vector (nr, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2128 octave_idx_type *pipvt = ipvt.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2129 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2130 ComplexMatrix atmp = *this; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2131 Complex *tmp_data = atmp.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2132 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2133 Array<Complex> z (dim_vector (2 * nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2134 Complex *pz = z.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2135 Array<double> rz (dim_vector (2 * nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2136 double *prz = rz.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2137 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2138 // Calculate the norm of the matrix, for later use. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2139 if (anorm < 0.) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2140 anorm = atmp.abs ().sum ().row (static_cast<octave_idx_type>(0)) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2141 .max (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2142 |
20598
ffc6cdcd02c5
Fix segfault when complex double matrix calls ZGETRF (bug #45577).
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
2143 // Work around bug #45577, LAPACK crashes Octave if norm is NaN |
ffc6cdcd02c5
Fix segfault when complex double matrix calls ZGETRF (bug #45577).
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
2144 if (xisnan (anorm)) |
ffc6cdcd02c5
Fix segfault when complex double matrix calls ZGETRF (bug #45577).
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
2145 info = -2; |
ffc6cdcd02c5
Fix segfault when complex double matrix calls ZGETRF (bug #45577).
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
2146 else |
ffc6cdcd02c5
Fix segfault when complex double matrix calls ZGETRF (bug #45577).
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
2147 F77_XFCN (zgetrf, ZGETRF, (nr, nr, tmp_data, nr, pipvt, info)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2148 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2149 // Throw-away extra info LAPACK gives so as to not change output. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2150 rcon = 0.0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2151 if (info != 0) |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2152 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2153 info = -2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2154 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2155 if (sing_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2156 sing_handler (rcon); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2157 else |
21112
358aa7fcbd33
Rename errwarn_singular_matrix to warn_singular_matrix.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
2158 warn_singular_matrix (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2159 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2160 mattype.mark_as_rectangular (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2161 } |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2162 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2163 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2164 if (calc_cond) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2165 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2166 // Now calculate the condition number for |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2167 // non-singular matrix. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2168 char job = '1'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2169 F77_XFCN (zgecon, ZGECON, (F77_CONST_CHAR_ARG2 (&job, 1), |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2170 nc, tmp_data, nr, anorm, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2171 rcon, pz, prz, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2172 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2173 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2174 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2175 info = -2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2176 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2177 volatile double rcond_plus_one = rcon + 1.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2178 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2179 if (rcond_plus_one == 1.0 || xisnan (rcon)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2180 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2181 info = -2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2182 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2183 if (sing_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2184 sing_handler (rcon); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2185 else |
21112
358aa7fcbd33
Rename errwarn_singular_matrix to warn_singular_matrix.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
2186 warn_singular_matrix (rcon); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2187 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2188 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2189 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2190 if (info == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2191 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2192 retval = b; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2193 Complex *result = retval.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2194 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2195 octave_idx_type b_nc = b.cols (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2196 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2197 char job = 'N'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2198 F77_XFCN (zgetrs, ZGETRS, (F77_CONST_CHAR_ARG2 (&job, 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2199 nr, b_nc, tmp_data, nr, |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14557
diff
changeset
|
2200 pipvt, result, b.rows (), info |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2201 F77_CHAR_ARG_LEN (1))); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2202 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2203 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2204 mattype.mark_as_rectangular (); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2205 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2206 } |
5785 | 2207 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2208 |
5785 | 2209 return retval; |
2210 } | |
2211 | |
2212 ComplexMatrix | |
2213 ComplexMatrix::solve (MatrixType &typ, const Matrix& b) const | |
2214 { | |
2215 octave_idx_type info; | |
7788 | 2216 double rcon; |
2217 return solve (typ, b, info, rcon, 0); | |
5785 | 2218 } |
2219 | |
2220 ComplexMatrix | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2221 ComplexMatrix::solve (MatrixType &typ, const Matrix& b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2222 octave_idx_type& info) const |
5785 | 2223 { |
7788 | 2224 double rcon; |
2225 return solve (typ, b, info, rcon, 0); | |
5785 | 2226 } |
2227 | |
2228 ComplexMatrix | |
2229 ComplexMatrix::solve (MatrixType &typ, const Matrix& b, octave_idx_type& info, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2230 double& rcon) const |
5785 | 2231 { |
7788 | 2232 return solve (typ, b, info, rcon, 0); |
5785 | 2233 } |
2234 | |
2235 ComplexMatrix | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2236 ComplexMatrix::solve (MatrixType &typ, const Matrix& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2237 double& rcon, solve_singularity_handler sing_handler, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2238 bool singular_fallback, blas_trans_type transt) const |
5785 | 2239 { |
2240 ComplexMatrix tmp (b); | |
9661
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9658
diff
changeset
|
2241 return solve (typ, tmp, info, rcon, sing_handler, singular_fallback, transt); |
5785 | 2242 } |
2243 | |
2244 ComplexMatrix | |
2245 ComplexMatrix::solve (MatrixType &typ, const ComplexMatrix& b) const | |
2246 { | |
2247 octave_idx_type info; | |
7788 | 2248 double rcon; |
2249 return solve (typ, b, info, rcon, 0); | |
5785 | 2250 } |
2251 | |
2252 ComplexMatrix | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2253 ComplexMatrix::solve (MatrixType &typ, const ComplexMatrix& b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2254 octave_idx_type& info) const |
5785 | 2255 { |
7788 | 2256 double rcon; |
2257 return solve (typ, b, info, rcon, 0); | |
5785 | 2258 } |
2259 | |
2260 ComplexMatrix | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2261 ComplexMatrix::solve (MatrixType &typ, const ComplexMatrix& b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2262 octave_idx_type& info, double& rcon) const |
5785 | 2263 { |
7788 | 2264 return solve (typ, b, info, rcon, 0); |
5785 | 2265 } |
2266 | |
2267 ComplexMatrix | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2268 ComplexMatrix::solve (MatrixType &mattype, const ComplexMatrix& b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2269 octave_idx_type& info, double& rcon, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2270 solve_singularity_handler sing_handler, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2271 bool singular_fallback, blas_trans_type transt) const |
5785 | 2272 { |
2273 ComplexMatrix retval; | |
2274 int typ = mattype.type (); | |
2275 | |
2276 if (typ == MatrixType::Unknown) | |
2277 typ = mattype.type (*this); | |
2278 | |
2279 // Only calculate the condition number for LU/Cholesky | |
2280 if (typ == MatrixType::Upper || typ == MatrixType::Permuted_Upper) | |
19434
aee5fea8a03e
compute condition number when solving triangular systems (bug #43875)
John W. Eaton <jwe@octave.org>
parents:
19408
diff
changeset
|
2281 retval = utsolve (mattype, b, info, rcon, sing_handler, true, transt); |
5785 | 2282 else if (typ == MatrixType::Lower || typ == MatrixType::Permuted_Lower) |
19434
aee5fea8a03e
compute condition number when solving triangular systems (bug #43875)
John W. Eaton <jwe@octave.org>
parents:
19408
diff
changeset
|
2283 retval = ltsolve (mattype, b, info, rcon, sing_handler, true, transt); |
9661
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9658
diff
changeset
|
2284 else if (transt == blas_trans) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2285 return transpose ().solve (mattype, b, info, rcon, sing_handler, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2286 singular_fallback); |
9661
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9658
diff
changeset
|
2287 else if (transt == blas_conj_trans) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2288 retval = hermitian ().solve (mattype, b, info, rcon, sing_handler, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2289 singular_fallback); |
5785 | 2290 else if (typ == MatrixType::Full || typ == MatrixType::Hermitian) |
7788 | 2291 retval = fsolve (mattype, b, info, rcon, sing_handler, true); |
5785 | 2292 else if (typ != MatrixType::Rectangular) |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2293 (*current_liboctave_error_handler) ("unknown matrix type"); |
5785 | 2294 |
2295 // Rectangular or one of the above solvers flags a singular matrix | |
2296 if (singular_fallback && mattype.type () == MatrixType::Rectangular) | |
2297 { | |
2298 octave_idx_type rank; | |
7788 | 2299 retval = lssolve (b, info, rank, rcon); |
5785 | 2300 } |
2301 | |
2302 return retval; | |
2303 } | |
2304 | |
2305 ComplexColumnVector | |
2306 ComplexMatrix::solve (MatrixType &typ, const ColumnVector& b) const | |
2307 { | |
2308 octave_idx_type info; | |
7788 | 2309 double rcon; |
2310 return solve (typ, ComplexColumnVector (b), info, rcon, 0); | |
5785 | 2311 } |
2312 | |
2313 ComplexColumnVector | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2314 ComplexMatrix::solve (MatrixType &typ, const ColumnVector& b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2315 octave_idx_type& info) const |
5785 | 2316 { |
7788 | 2317 double rcon; |
2318 return solve (typ, ComplexColumnVector (b), info, rcon, 0); | |
5785 | 2319 } |
2320 | |
2321 ComplexColumnVector | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2322 ComplexMatrix::solve (MatrixType &typ, const ColumnVector& b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2323 octave_idx_type& info, double& rcon) const |
5785 | 2324 { |
7788 | 2325 return solve (typ, ComplexColumnVector (b), info, rcon, 0); |
5785 | 2326 } |
2327 | |
2328 ComplexColumnVector | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2329 ComplexMatrix::solve (MatrixType &typ, const ColumnVector& b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2330 octave_idx_type& info, double& rcon, |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2331 solve_singularity_handler sing_handler, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2332 blas_trans_type transt) const |
5785 | 2333 { |
9661
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9658
diff
changeset
|
2334 return solve (typ, ComplexColumnVector (b), info, rcon, sing_handler, transt); |
5785 | 2335 } |
2336 | |
2337 ComplexColumnVector | |
2338 ComplexMatrix::solve (MatrixType &typ, const ComplexColumnVector& b) const | |
2339 { | |
2340 octave_idx_type info; | |
7788 | 2341 double rcon; |
2342 return solve (typ, b, info, rcon, 0); | |
5785 | 2343 } |
2344 | |
2345 ComplexColumnVector | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2346 ComplexMatrix::solve (MatrixType &typ, const ComplexColumnVector& b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2347 octave_idx_type& info) const |
5785 | 2348 { |
7788 | 2349 double rcon; |
2350 return solve (typ, b, info, rcon, 0); | |
5785 | 2351 } |
2352 | |
2353 ComplexColumnVector | |
2354 ComplexMatrix::solve (MatrixType &typ, const ComplexColumnVector& b, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2355 octave_idx_type& info, double& rcon) const |
5785 | 2356 { |
7788 | 2357 return solve (typ, b, info, rcon, 0); |
5785 | 2358 } |
2359 | |
2360 ComplexColumnVector | |
2361 ComplexMatrix::solve (MatrixType &typ, const ComplexColumnVector& b, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2362 octave_idx_type& info, double& rcon, |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2363 solve_singularity_handler sing_handler, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2364 blas_trans_type transt) const |
5785 | 2365 { |
2366 | |
2367 ComplexMatrix tmp (b); | |
10352 | 2368 tmp = solve (typ, tmp, info, rcon, sing_handler, true, transt); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
2369 return tmp.column (static_cast<octave_idx_type> (0)); |
5785 | 2370 } |
2371 | |
2372 ComplexMatrix | |
458 | 2373 ComplexMatrix::solve (const Matrix& b) const |
2374 { | |
5275 | 2375 octave_idx_type info; |
7788 | 2376 double rcon; |
2377 return solve (b, info, rcon, 0); | |
458 | 2378 } |
2379 | |
2380 ComplexMatrix | |
5275 | 2381 ComplexMatrix::solve (const Matrix& b, octave_idx_type& info) const |
458 | 2382 { |
7788 | 2383 double rcon; |
2384 return solve (b, info, rcon, 0); | |
458 | 2385 } |
2386 | |
2387 ComplexMatrix | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2388 ComplexMatrix::solve (const Matrix& b, octave_idx_type& info, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2389 double& rcon) const |
458 | 2390 { |
7788 | 2391 return solve (b, info, rcon, 0); |
3480 | 2392 } |
2393 | |
2394 ComplexMatrix | |
7788 | 2395 ComplexMatrix::solve (const Matrix& b, octave_idx_type& info, double& rcon, |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2396 solve_singularity_handler sing_handler, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2397 blas_trans_type transt) const |
3480 | 2398 { |
458 | 2399 ComplexMatrix tmp (b); |
9661
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9658
diff
changeset
|
2400 return solve (tmp, info, rcon, sing_handler, transt); |
458 | 2401 } |
2402 | |
2403 ComplexMatrix | |
2404 ComplexMatrix::solve (const ComplexMatrix& b) const | |
2405 { | |
5275 | 2406 octave_idx_type info; |
7788 | 2407 double rcon; |
2408 return solve (b, info, rcon, 0); | |
458 | 2409 } |
2410 | |
2411 ComplexMatrix | |
5275 | 2412 ComplexMatrix::solve (const ComplexMatrix& b, octave_idx_type& info) const |
458 | 2413 { |
7788 | 2414 double rcon; |
2415 return solve (b, info, rcon, 0); | |
458 | 2416 } |
3480 | 2417 |
458 | 2418 ComplexMatrix |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2419 ComplexMatrix::solve (const ComplexMatrix& b, octave_idx_type& info, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2420 double& rcon) const |
458 | 2421 { |
7788 | 2422 return solve (b, info, rcon, 0); |
3480 | 2423 } |
2424 | |
2425 ComplexMatrix | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2426 ComplexMatrix::solve (const ComplexMatrix& b, octave_idx_type& info, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2427 double& rcon, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2428 solve_singularity_handler sing_handler, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2429 blas_trans_type transt) const |
3480 | 2430 { |
5785 | 2431 MatrixType mattype (*this); |
9661
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9658
diff
changeset
|
2432 return solve (mattype, b, info, rcon, sing_handler, true, transt); |
458 | 2433 } |
2434 | |
2435 ComplexColumnVector | |
3585 | 2436 ComplexMatrix::solve (const ColumnVector& b) const |
2437 { | |
5275 | 2438 octave_idx_type info; |
7788 | 2439 double rcon; |
2440 return solve (ComplexColumnVector (b), info, rcon, 0); | |
3585 | 2441 } |
2442 | |
2443 ComplexColumnVector | |
5275 | 2444 ComplexMatrix::solve (const ColumnVector& b, octave_idx_type& info) const |
3585 | 2445 { |
7788 | 2446 double rcon; |
2447 return solve (ComplexColumnVector (b), info, rcon, 0); | |
3585 | 2448 } |
2449 | |
2450 ComplexColumnVector | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2451 ComplexMatrix::solve (const ColumnVector& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2452 double& rcon) const |
3585 | 2453 { |
7788 | 2454 return solve (ComplexColumnVector (b), info, rcon, 0); |
3585 | 2455 } |
2456 | |
2457 ComplexColumnVector | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2458 ComplexMatrix::solve (const ColumnVector& b, octave_idx_type& info, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2459 double& rcon, |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2460 solve_singularity_handler sing_handler, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2461 blas_trans_type transt) const |
3585 | 2462 { |
9661
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9658
diff
changeset
|
2463 return solve (ComplexColumnVector (b), info, rcon, sing_handler, transt); |
3585 | 2464 } |
2465 | |
2466 ComplexColumnVector | |
458 | 2467 ComplexMatrix::solve (const ComplexColumnVector& b) const |
2468 { | |
5275 | 2469 octave_idx_type info; |
7788 | 2470 double rcon; |
2471 return solve (b, info, rcon, 0); | |
458 | 2472 } |
2473 | |
2474 ComplexColumnVector | |
5275 | 2475 ComplexMatrix::solve (const ComplexColumnVector& b, octave_idx_type& info) const |
458 | 2476 { |
7788 | 2477 double rcon; |
2478 return solve (b, info, rcon, 0); | |
458 | 2479 } |
2480 | |
2481 ComplexColumnVector | |
5275 | 2482 ComplexMatrix::solve (const ComplexColumnVector& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2483 double& rcon) const |
458 | 2484 { |
7788 | 2485 return solve (b, info, rcon, 0); |
3480 | 2486 } |
2487 | |
2488 ComplexColumnVector | |
5275 | 2489 ComplexMatrix::solve (const ComplexColumnVector& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2490 double& rcon, |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2491 solve_singularity_handler sing_handler, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2492 blas_trans_type transt) const |
3480 | 2493 { |
5785 | 2494 MatrixType mattype (*this); |
9661
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9658
diff
changeset
|
2495 return solve (mattype, b, info, rcon, sing_handler, transt); |
458 | 2496 } |
2497 | |
2498 ComplexMatrix | |
3585 | 2499 ComplexMatrix::lssolve (const Matrix& b) const |
2500 { | |
5275 | 2501 octave_idx_type info; |
2502 octave_idx_type rank; | |
7788 | 2503 double rcon; |
2504 return lssolve (ComplexMatrix (b), info, rank, rcon); | |
3585 | 2505 } |
2506 | |
2507 ComplexMatrix | |
5275 | 2508 ComplexMatrix::lssolve (const Matrix& b, octave_idx_type& info) const |
3585 | 2509 { |
5275 | 2510 octave_idx_type rank; |
7788 | 2511 double rcon; |
2512 return lssolve (ComplexMatrix (b), info, rank, rcon); | |
3585 | 2513 } |
2514 | |
2515 ComplexMatrix | |
7076 | 2516 ComplexMatrix::lssolve (const Matrix& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2517 octave_idx_type& rank) const |
3585 | 2518 { |
7788 | 2519 double rcon; |
2520 return lssolve (ComplexMatrix (b), info, rank, rcon); | |
7076 | 2521 } |
2522 | |
2523 ComplexMatrix | |
2524 ComplexMatrix::lssolve (const Matrix& b, octave_idx_type& info, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2525 octave_idx_type& rank, double& rcon) const |
7076 | 2526 { |
7788 | 2527 return lssolve (ComplexMatrix (b), info, rank, rcon); |
3585 | 2528 } |
2529 | |
2530 ComplexMatrix | |
458 | 2531 ComplexMatrix::lssolve (const ComplexMatrix& b) const |
2532 { | |
5275 | 2533 octave_idx_type info; |
2534 octave_idx_type rank; | |
7788 | 2535 double rcon; |
2536 return lssolve (b, info, rank, rcon); | |
458 | 2537 } |
2538 | |
2539 ComplexMatrix | |
5275 | 2540 ComplexMatrix::lssolve (const ComplexMatrix& b, octave_idx_type& info) const |
458 | 2541 { |
5275 | 2542 octave_idx_type rank; |
7788 | 2543 double rcon; |
2544 return lssolve (b, info, rank, rcon); | |
458 | 2545 } |
2546 | |
2547 ComplexMatrix | |
7076 | 2548 ComplexMatrix::lssolve (const ComplexMatrix& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2549 octave_idx_type& rank) const |
7076 | 2550 { |
7788 | 2551 double rcon; |
2552 return lssolve (b, info, rank, rcon); | |
7076 | 2553 } |
2554 | |
2555 ComplexMatrix | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2556 ComplexMatrix::lssolve (const ComplexMatrix& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2557 octave_idx_type& rank, double& rcon) const |
458 | 2558 { |
1948 | 2559 ComplexMatrix retval; |
2560 | |
5275 | 2561 octave_idx_type nrhs = b.cols (); |
2562 | |
2563 octave_idx_type m = rows (); | |
2564 octave_idx_type n = cols (); | |
458 | 2565 |
6924 | 2566 if (m != b.rows ()) |
1948 | 2567 (*current_liboctave_error_handler) |
2568 ("matrix dimension mismatch solution of linear equations"); | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2569 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2570 if (m== 0 || n == 0 || b.cols () == 0) |
6924 | 2571 retval = ComplexMatrix (n, b.cols (), Complex (0.0, 0.0)); |
1948 | 2572 else |
458 | 2573 { |
7072 | 2574 volatile octave_idx_type minmn = (m < n ? m : n); |
2575 octave_idx_type maxmn = m > n ? m : n; | |
7788 | 2576 rcon = -1.0; |
7072 | 2577 |
2578 if (m != n) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2579 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2580 retval = ComplexMatrix (maxmn, nrhs); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2581 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2582 for (octave_idx_type j = 0; j < nrhs; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2583 for (octave_idx_type i = 0; i < m; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2584 retval.elem (i, j) = b.elem (i, j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2585 } |
7072 | 2586 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2587 retval = b; |
7072 | 2588 |
1948 | 2589 ComplexMatrix atmp = *this; |
2590 Complex *tmp_data = atmp.fortran_vec (); | |
2591 | |
7072 | 2592 Complex *pretval = retval.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2593 Array<double> s (dim_vector (minmn, 1)); |
7071 | 2594 double *ps = s.fortran_vec (); |
2563 | 2595 |
7072 | 2596 // Ask ZGELSD what the dimension of WORK should be. |
5275 | 2597 octave_idx_type lwork = -1; |
3752 | 2598 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2599 Array<Complex> work (dim_vector (1, 1)); |
7079 | 2600 |
7477 | 2601 octave_idx_type smlsiz; |
2602 F77_FUNC (xilaenv, XILAENV) (9, F77_CONST_CHAR_ARG2 ("ZGELSD", 6), | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2603 F77_CONST_CHAR_ARG2 (" ", 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2604 0, 0, 0, 0, smlsiz |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2605 F77_CHAR_ARG_LEN (6) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2606 F77_CHAR_ARG_LEN (1)); |
7079 | 2607 |
7486
6a6d2abe51ff
more xGELSD workspace fixes
John W. Eaton <jwe@octave.org>
parents:
7482
diff
changeset
|
2608 octave_idx_type mnthr; |
6a6d2abe51ff
more xGELSD workspace fixes
John W. Eaton <jwe@octave.org>
parents:
7482
diff
changeset
|
2609 F77_FUNC (xilaenv, XILAENV) (6, F77_CONST_CHAR_ARG2 ("ZGELSD", 6), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2610 F77_CONST_CHAR_ARG2 (" ", 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2611 m, n, nrhs, -1, mnthr |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2612 F77_CHAR_ARG_LEN (6) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2613 F77_CHAR_ARG_LEN (1)); |
7486
6a6d2abe51ff
more xGELSD workspace fixes
John W. Eaton <jwe@octave.org>
parents:
7482
diff
changeset
|
2614 |
7079 | 2615 // We compute the size of rwork and iwork because ZGELSD in |
2616 // older versions of LAPACK does not return them on a query | |
2617 // call. | |
7124 | 2618 double dminmn = static_cast<double> (minmn); |
2619 double dsmlsizp1 = static_cast<double> (smlsiz+1); | |
18847
ff4da3c8ed16
use gnulib log2 modules (bug #42583)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
2620 double tmp = xlog2 (dminmn / dsmlsizp1); |
ff4da3c8ed16
use gnulib log2 modules (bug #42583)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
2621 |
7544
f9983d2761df
more xGELSD workspace fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
7532
diff
changeset
|
2622 octave_idx_type nlvl = static_cast<octave_idx_type> (tmp) + 1; |
7079 | 2623 if (nlvl < 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2624 nlvl = 0; |
7079 | 2625 |
2626 octave_idx_type lrwork = minmn*(10 + 2*smlsiz + 8*nlvl) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2627 + 3*smlsiz*nrhs |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2628 + std::max ((smlsiz+1)*(smlsiz+1), |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2629 n*(1+nrhs) + 2*nrhs); |
7079 | 2630 if (lrwork < 1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2631 lrwork = 1; |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2632 Array<double> rwork (dim_vector (lrwork, 1)); |
7079 | 2633 double *prwork = rwork.fortran_vec (); |
2634 | |
2635 octave_idx_type liwork = 3 * minmn * nlvl + 11 * minmn; | |
2636 if (liwork < 1) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2637 liwork = 1; |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2638 Array<octave_idx_type> iwork (dim_vector (liwork, 1)); |
7079 | 2639 octave_idx_type* piwork = iwork.fortran_vec (); |
7072 | 2640 |
2641 F77_XFCN (zgelsd, ZGELSD, (m, n, nrhs, tmp_data, m, pretval, maxmn, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2642 ps, rcon, rank, work.fortran_vec (), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2643 lwork, prwork, piwork, info)); |
1948 | 2644 |
7476 | 2645 // The workspace query is broken in at least LAPACK 3.0.0 |
7488
6470f946a425
another small xGELSD workspace fix
John W. Eaton <jwe@octave.org>
parents:
7486
diff
changeset
|
2646 // through 3.1.1 when n >= mnthr. The obtuse formula below |
7486
6a6d2abe51ff
more xGELSD workspace fixes
John W. Eaton <jwe@octave.org>
parents:
7482
diff
changeset
|
2647 // should provide sufficient workspace for ZGELSD to operate |
7476 | 2648 // efficiently. |
10813
2c2d4a2f1047
fix workspace bug workaround for xGELSD (since 7486:6a6d2abe51ff)
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
2649 if (n > m && n >= mnthr) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2650 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2651 octave_idx_type addend = m; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2652 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2653 if (2*m-4 > addend) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2654 addend = 2*m-4; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2655 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2656 if (nrhs > addend) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2657 addend = nrhs; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2658 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2659 if (n-3*m > addend) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2660 addend = n-3*m; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2661 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2662 const octave_idx_type lworkaround = 4*m + m*m + addend; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2663 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2664 if (std::real (work(0)) < lworkaround) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2665 work(0) = lworkaround; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2666 } |
7532
493bb0de3199
avoid another xGELSD workspace query bug
John W. Eaton <jwe@octave.org>
parents:
7503
diff
changeset
|
2667 else if (m >= n) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2668 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2669 octave_idx_type lworkaround = 2*m + m*nrhs; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2670 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2671 if (std::real (work(0)) < lworkaround) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2672 work(0) = lworkaround; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2673 } |
7476 | 2674 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2675 lwork = static_cast<octave_idx_type> (std::real (work(0))); |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2676 work.resize (dim_vector (lwork, 1)); |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2677 |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2678 F77_XFCN (zgelsd, ZGELSD, (m, n, nrhs, tmp_data, m, pretval, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2679 maxmn, ps, rcon, rank, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2680 work.fortran_vec (), lwork, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2681 prwork, piwork, info)); |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2682 |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2683 if (s.elem (0) == 0.0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2684 rcon = 0.0; |
1948 | 2685 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2686 rcon = s.elem (minmn - 1) / s.elem (0); |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2687 |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2688 retval.resize (n, nrhs); |
458 | 2689 } |
2690 | |
2691 return retval; | |
2692 } | |
2693 | |
2694 ComplexColumnVector | |
3585 | 2695 ComplexMatrix::lssolve (const ColumnVector& b) const |
2696 { | |
5275 | 2697 octave_idx_type info; |
2698 octave_idx_type rank; | |
7788 | 2699 double rcon; |
2700 return lssolve (ComplexColumnVector (b), info, rank, rcon); | |
3585 | 2701 } |
2702 | |
2703 ComplexColumnVector | |
5275 | 2704 ComplexMatrix::lssolve (const ColumnVector& b, octave_idx_type& info) const |
3585 | 2705 { |
5275 | 2706 octave_idx_type rank; |
7788 | 2707 double rcon; |
2708 return lssolve (ComplexColumnVector (b), info, rank, rcon); | |
3585 | 2709 } |
2710 | |
2711 ComplexColumnVector | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2712 ComplexMatrix::lssolve (const ColumnVector& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2713 octave_idx_type& rank) const |
3585 | 2714 { |
7788 | 2715 double rcon; |
2716 return lssolve (ComplexColumnVector (b), info, rank, rcon); | |
7076 | 2717 } |
2718 | |
2719 ComplexColumnVector | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2720 ComplexMatrix::lssolve (const ColumnVector& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2721 octave_idx_type& rank, double& rcon) const |
7076 | 2722 { |
7788 | 2723 return lssolve (ComplexColumnVector (b), info, rank, rcon); |
3585 | 2724 } |
2725 | |
2726 ComplexColumnVector | |
458 | 2727 ComplexMatrix::lssolve (const ComplexColumnVector& b) const |
2728 { | |
5275 | 2729 octave_idx_type info; |
2730 octave_idx_type rank; | |
7788 | 2731 double rcon; |
2732 return lssolve (b, info, rank, rcon); | |
458 | 2733 } |
2734 | |
2735 ComplexColumnVector | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2736 ComplexMatrix::lssolve (const ComplexColumnVector& b, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2737 octave_idx_type& info) const |
458 | 2738 { |
5275 | 2739 octave_idx_type rank; |
7788 | 2740 double rcon; |
2741 return lssolve (b, info, rank, rcon); | |
458 | 2742 } |
2743 | |
2744 ComplexColumnVector | |
5275 | 2745 ComplexMatrix::lssolve (const ComplexColumnVector& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2746 octave_idx_type& rank) const |
458 | 2747 { |
7788 | 2748 double rcon; |
2749 return lssolve (b, info, rank, rcon); | |
7076 | 2750 |
2751 } | |
2752 | |
2753 ComplexColumnVector | |
2754 ComplexMatrix::lssolve (const ComplexColumnVector& b, octave_idx_type& info, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2755 octave_idx_type& rank, double& rcon) const |
7076 | 2756 { |
1948 | 2757 ComplexColumnVector retval; |
2758 | |
5275 | 2759 octave_idx_type nrhs = 1; |
2760 | |
2761 octave_idx_type m = rows (); | |
2762 octave_idx_type n = cols (); | |
458 | 2763 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
2764 if (m != b.numel ()) |
1948 | 2765 (*current_liboctave_error_handler) |
6924 | 2766 ("matrix dimension mismatch solution of linear equations"); |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2767 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
2768 if (m == 0 || n == 0 || b.cols () == 0) |
6924 | 2769 retval = ComplexColumnVector (n, Complex (0.0, 0.0)); |
1948 | 2770 else |
458 | 2771 { |
7072 | 2772 volatile octave_idx_type minmn = (m < n ? m : n); |
2773 octave_idx_type maxmn = m > n ? m : n; | |
7788 | 2774 rcon = -1.0; |
7072 | 2775 |
2776 if (m != n) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2777 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2778 retval = ComplexColumnVector (maxmn); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2779 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2780 for (octave_idx_type i = 0; i < m; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2781 retval.elem (i) = b.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2782 } |
7072 | 2783 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2784 retval = b; |
7072 | 2785 |
1948 | 2786 ComplexMatrix atmp = *this; |
2787 Complex *tmp_data = atmp.fortran_vec (); | |
2788 | |
7072 | 2789 Complex *pretval = retval.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2790 Array<double> s (dim_vector (minmn, 1)); |
7071 | 2791 double *ps = s.fortran_vec (); |
1948 | 2792 |
7072 | 2793 // Ask ZGELSD what the dimension of WORK should be. |
5275 | 2794 octave_idx_type lwork = -1; |
3752 | 2795 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2796 Array<Complex> work (dim_vector (1, 1)); |
7079 | 2797 |
7544
f9983d2761df
more xGELSD workspace fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
7532
diff
changeset
|
2798 octave_idx_type smlsiz; |
f9983d2761df
more xGELSD workspace fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
7532
diff
changeset
|
2799 F77_FUNC (xilaenv, XILAENV) (9, F77_CONST_CHAR_ARG2 ("ZGELSD", 6), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2800 F77_CONST_CHAR_ARG2 (" ", 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2801 0, 0, 0, 0, smlsiz |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2802 F77_CHAR_ARG_LEN (6) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2803 F77_CHAR_ARG_LEN (1)); |
7079 | 2804 |
2805 // We compute the size of rwork and iwork because ZGELSD in | |
2806 // older versions of LAPACK does not return them on a query | |
2807 // call. | |
7124 | 2808 double dminmn = static_cast<double> (minmn); |
2809 double dsmlsizp1 = static_cast<double> (smlsiz+1); | |
18847
ff4da3c8ed16
use gnulib log2 modules (bug #42583)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
2810 double tmp = xlog2 (dminmn / dsmlsizp1); |
ff4da3c8ed16
use gnulib log2 modules (bug #42583)
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
2811 |
7544
f9983d2761df
more xGELSD workspace fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
7532
diff
changeset
|
2812 octave_idx_type nlvl = static_cast<octave_idx_type> (tmp) + 1; |
7079 | 2813 if (nlvl < 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2814 nlvl = 0; |
7079 | 2815 |
2816 octave_idx_type lrwork = minmn*(10 + 2*smlsiz + 8*nlvl) | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2817 + 3*smlsiz*nrhs + (smlsiz+1)*(smlsiz+1); |
7079 | 2818 if (lrwork < 1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2819 lrwork = 1; |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2820 Array<double> rwork (dim_vector (lrwork, 1)); |
7079 | 2821 double *prwork = rwork.fortran_vec (); |
2822 | |
2823 octave_idx_type liwork = 3 * minmn * nlvl + 11 * minmn; | |
2824 if (liwork < 1) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2825 liwork = 1; |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2826 Array<octave_idx_type> iwork (dim_vector (liwork, 1)); |
7079 | 2827 octave_idx_type* piwork = iwork.fortran_vec (); |
7072 | 2828 |
2829 F77_XFCN (zgelsd, ZGELSD, (m, n, nrhs, tmp_data, m, pretval, maxmn, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2830 ps, rcon, rank, work.fortran_vec (), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2831 lwork, prwork, piwork, info)); |
1948 | 2832 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2833 lwork = static_cast<octave_idx_type> (std::real (work(0))); |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2834 work.resize (dim_vector (lwork, 1)); |
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2835 rwork.resize (dim_vector (static_cast<octave_idx_type> (rwork(0)), 1)); |
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2836 iwork.resize (dim_vector (iwork(0), 1)); |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2837 |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2838 F77_XFCN (zgelsd, ZGELSD, (m, n, nrhs, tmp_data, m, pretval, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2839 maxmn, ps, rcon, rank, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2840 work.fortran_vec (), lwork, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2841 prwork, piwork, info)); |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2842 |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2843 if (rank < minmn) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2844 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2845 if (s.elem (0) == 0.0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2846 rcon = 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2847 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2848 rcon = s.elem (minmn - 1) / s.elem (0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2849 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2850 retval.resize (n, nrhs); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2851 } |
458 | 2852 } |
2853 | |
2854 return retval; | |
2855 } | |
2856 | |
1205 | 2857 // column vector by row vector -> matrix operations |
2858 | |
2859 ComplexMatrix | |
2860 operator * (const ColumnVector& v, const ComplexRowVector& a) | |
2861 { | |
2862 ComplexColumnVector tmp (v); | |
2863 return tmp * a; | |
2864 } | |
2865 | |
2866 ComplexMatrix | |
2867 operator * (const ComplexColumnVector& a, const RowVector& b) | |
2868 { | |
2869 ComplexRowVector tmp (b); | |
2870 return a * tmp; | |
2871 } | |
2872 | |
2873 ComplexMatrix | |
2874 operator * (const ComplexColumnVector& v, const ComplexRowVector& a) | |
2875 { | |
1948 | 2876 ComplexMatrix retval; |
2877 | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
2878 octave_idx_type len = v.numel (); |
3233 | 2879 |
2880 if (len != 0) | |
1205 | 2881 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
2882 octave_idx_type a_len = a.numel (); |
3233 | 2883 |
9359
be6867ba8104
avoid useless zero initialization when doing matrix multiply
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
2884 retval = ComplexMatrix (len, a_len); |
3233 | 2885 Complex *c = retval.fortran_vec (); |
2886 | |
4552 | 2887 F77_XFCN (zgemm, ZGEMM, (F77_CONST_CHAR_ARG2 ("N", 1), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2888 F77_CONST_CHAR_ARG2 ("N", 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2889 len, a_len, 1, 1.0, v.data (), len, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2890 a.data (), 1, 0.0, c, len |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2891 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2892 F77_CHAR_ARG_LEN (1))); |
1205 | 2893 } |
2894 | |
1948 | 2895 return retval; |
1205 | 2896 } |
2897 | |
458 | 2898 // matrix by diagonal matrix -> matrix operations |
2899 | |
2900 ComplexMatrix& | |
2901 ComplexMatrix::operator += (const DiagMatrix& a) | |
2902 { | |
5275 | 2903 octave_idx_type nr = rows (); |
2904 octave_idx_type nc = cols (); | |
2905 | |
2906 octave_idx_type a_nr = rows (); | |
2907 octave_idx_type a_nc = cols (); | |
2384 | 2908 |
2909 if (nr != a_nr || nc != a_nc) | |
21129
228b65504557
maint: Eliminate useless statements after err_XXX.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
2910 err_nonconformant ("operator +=", nr, nc, a_nr, a_nc); |
458 | 2911 |
5275 | 2912 for (octave_idx_type i = 0; i < a.length (); i++) |
458 | 2913 elem (i, i) += a.elem (i, i); |
2914 | |
2915 return *this; | |
2916 } | |
2917 | |
2918 ComplexMatrix& | |
2919 ComplexMatrix::operator -= (const DiagMatrix& a) | |
2920 { | |
5275 | 2921 octave_idx_type nr = rows (); |
2922 octave_idx_type nc = cols (); | |
2923 | |
2924 octave_idx_type a_nr = rows (); | |
2925 octave_idx_type a_nc = cols (); | |
2384 | 2926 |
2927 if (nr != a_nr || nc != a_nc) | |
21129
228b65504557
maint: Eliminate useless statements after err_XXX.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
2928 err_nonconformant ("operator -=", nr, nc, a_nr, a_nc); |
458 | 2929 |
5275 | 2930 for (octave_idx_type i = 0; i < a.length (); i++) |
458 | 2931 elem (i, i) -= a.elem (i, i); |
2932 | |
2933 return *this; | |
2934 } | |
2935 | |
2936 ComplexMatrix& | |
2937 ComplexMatrix::operator += (const ComplexDiagMatrix& a) | |
2938 { | |
5275 | 2939 octave_idx_type nr = rows (); |
2940 octave_idx_type nc = cols (); | |
2941 | |
2942 octave_idx_type a_nr = rows (); | |
2943 octave_idx_type a_nc = cols (); | |
2384 | 2944 |
2945 if (nr != a_nr || nc != a_nc) | |
21129
228b65504557
maint: Eliminate useless statements after err_XXX.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
2946 err_nonconformant ("operator +=", nr, nc, a_nr, a_nc); |
458 | 2947 |
5275 | 2948 for (octave_idx_type i = 0; i < a.length (); i++) |
458 | 2949 elem (i, i) += a.elem (i, i); |
2950 | |
2951 return *this; | |
2952 } | |
2953 | |
2954 ComplexMatrix& | |
2955 ComplexMatrix::operator -= (const ComplexDiagMatrix& a) | |
2956 { | |
5275 | 2957 octave_idx_type nr = rows (); |
2958 octave_idx_type nc = cols (); | |
2959 | |
2960 octave_idx_type a_nr = rows (); | |
2961 octave_idx_type a_nc = cols (); | |
2384 | 2962 |
2963 if (nr != a_nr || nc != a_nc) | |
21129
228b65504557
maint: Eliminate useless statements after err_XXX.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
2964 err_nonconformant ("operator -=", nr, nc, a_nr, a_nc); |
458 | 2965 |
5275 | 2966 for (octave_idx_type i = 0; i < a.length (); i++) |
458 | 2967 elem (i, i) -= a.elem (i, i); |
2968 | |
2969 return *this; | |
2970 } | |
2971 | |
2972 // matrix by matrix -> matrix operations | |
2973 | |
2974 ComplexMatrix& | |
2975 ComplexMatrix::operator += (const Matrix& a) | |
2976 { | |
5275 | 2977 octave_idx_type nr = rows (); |
2978 octave_idx_type nc = cols (); | |
2979 | |
2980 octave_idx_type a_nr = a.rows (); | |
2981 octave_idx_type a_nc = a.cols (); | |
2384 | 2982 |
2983 if (nr != a_nr || nc != a_nc) | |
21129
228b65504557
maint: Eliminate useless statements after err_XXX.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
2984 err_nonconformant ("operator +=", nr, nc, a_nr, a_nc); |
458 | 2985 |
2986 if (nr == 0 || nc == 0) | |
2987 return *this; | |
2988 | |
2989 Complex *d = fortran_vec (); // Ensures only one reference to my privates! | |
2990 | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
2991 mx_inline_add2 (numel (), d, a.data ()); |
458 | 2992 return *this; |
2993 } | |
2994 | |
2995 ComplexMatrix& | |
2996 ComplexMatrix::operator -= (const Matrix& a) | |
2997 { | |
5275 | 2998 octave_idx_type nr = rows (); |
2999 octave_idx_type nc = cols (); | |
3000 | |
3001 octave_idx_type a_nr = a.rows (); | |
3002 octave_idx_type a_nc = a.cols (); | |
2384 | 3003 |
3004 if (nr != a_nr || nc != a_nc) | |
21129
228b65504557
maint: Eliminate useless statements after err_XXX.
Rik <rik@octave.org>
parents:
21120
diff
changeset
|
3005 err_nonconformant ("operator -=", nr, nc, a_nr, a_nc); |
458 | 3006 |
3007 if (nr == 0 || nc == 0) | |
3008 return *this; | |
3009 | |
3010 Complex *d = fortran_vec (); // Ensures only one reference to my privates! | |
3011 | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
3012 mx_inline_sub2 (numel (), d, a.data ()); |
458 | 3013 return *this; |
3014 } | |
3015 | |
3016 // other operations | |
3017 | |
2832 | 3018 boolMatrix |
4015 | 3019 ComplexMatrix::all (int dim) const |
458 | 3020 { |
19321
3746b92739f7
Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents:
19320
diff
changeset
|
3021 return ComplexNDArray::all (dim); |
458 | 3022 } |
3023 | |
2832 | 3024 boolMatrix |
4015 | 3025 ComplexMatrix::any (int dim) const |
458 | 3026 { |
19321
3746b92739f7
Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents:
19320
diff
changeset
|
3027 return ComplexNDArray::any (dim); |
458 | 3028 } |
3029 | |
3030 ComplexMatrix | |
3723 | 3031 ComplexMatrix::cumprod (int dim) const |
458 | 3032 { |
19321
3746b92739f7
Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents:
19320
diff
changeset
|
3033 return ComplexNDArray::cumprod (dim); |
458 | 3034 } |
3035 | |
3036 ComplexMatrix | |
3723 | 3037 ComplexMatrix::cumsum (int dim) const |
458 | 3038 { |
19321
3746b92739f7
Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents:
19320
diff
changeset
|
3039 return ComplexNDArray::cumsum (dim); |
458 | 3040 } |
3041 | |
3042 ComplexMatrix | |
3723 | 3043 ComplexMatrix::prod (int dim) const |
458 | 3044 { |
19321
3746b92739f7
Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents:
19320
diff
changeset
|
3045 return ComplexNDArray::prod (dim); |
458 | 3046 } |
3047 | |
3048 ComplexMatrix | |
3723 | 3049 ComplexMatrix::sum (int dim) const |
458 | 3050 { |
19321
3746b92739f7
Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents:
19320
diff
changeset
|
3051 return ComplexNDArray::sum (dim); |
458 | 3052 } |
3053 | |
3054 ComplexMatrix | |
3723 | 3055 ComplexMatrix::sumsq (int dim) const |
458 | 3056 { |
19321
3746b92739f7
Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents:
19320
diff
changeset
|
3057 return ComplexNDArray::sumsq (dim); |
458 | 3058 } |
3059 | |
19321
3746b92739f7
Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents:
19320
diff
changeset
|
3060 Matrix |
3746b92739f7
Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents:
19320
diff
changeset
|
3061 ComplexMatrix::abs (void) const |
4329 | 3062 { |
19321
3746b92739f7
Replace some duplicated code and count on methods implemented on base classes.
Carnë Draug <carandraug@octave.org>
parents:
19320
diff
changeset
|
3063 return ComplexNDArray::abs (); |
4329 | 3064 } |
3065 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7544
diff
changeset
|
3066 ComplexMatrix |
5275 | 3067 ComplexMatrix::diag (octave_idx_type k) const |
458 | 3068 { |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19269
diff
changeset
|
3069 return ComplexNDArray::diag (k); |
458 | 3070 } |
3071 | |
14557
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14427
diff
changeset
|
3072 ComplexDiagMatrix |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14427
diff
changeset
|
3073 ComplexMatrix::diag (octave_idx_type m, octave_idx_type n) const |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14427
diff
changeset
|
3074 { |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14427
diff
changeset
|
3075 octave_idx_type nr = rows (); |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14427
diff
changeset
|
3076 octave_idx_type nc = cols (); |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14427
diff
changeset
|
3077 |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
3078 if (nr != 1 && nc != 1) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
3079 (*current_liboctave_error_handler) ("diag: expecting vector argument"); |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
3080 |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
3081 return ComplexDiagMatrix (*this, m, n); |
14557
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14427
diff
changeset
|
3082 } |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14427
diff
changeset
|
3083 |
2354 | 3084 bool |
5275 | 3085 ComplexMatrix::row_is_real_only (octave_idx_type i) const |
2354 | 3086 { |
3087 bool retval = true; | |
3088 | |
5275 | 3089 octave_idx_type nc = columns (); |
3090 | |
3091 for (octave_idx_type j = 0; j < nc; j++) | |
2354 | 3092 { |
5315 | 3093 if (std::imag (elem (i, j)) != 0.0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3094 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3095 retval = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3096 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3097 } |
2354 | 3098 } |
3099 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
3100 return retval; |
2354 | 3101 } |
3102 | |
3103 bool | |
5275 | 3104 ComplexMatrix::column_is_real_only (octave_idx_type j) const |
2354 | 3105 { |
3106 bool retval = true; | |
3107 | |
5275 | 3108 octave_idx_type nr = rows (); |
3109 | |
3110 for (octave_idx_type i = 0; i < nr; i++) | |
2354 | 3111 { |
5315 | 3112 if (std::imag (elem (i, j)) != 0.0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3113 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3114 retval = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3115 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3116 } |
2354 | 3117 } |
3118 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
3119 return retval; |
2354 | 3120 } |
891 | 3121 |
458 | 3122 ComplexColumnVector |
3123 ComplexMatrix::row_min (void) const | |
3124 { | |
5275 | 3125 Array<octave_idx_type> dummy_idx; |
4587 | 3126 return row_min (dummy_idx); |
458 | 3127 } |
3128 | |
3129 ComplexColumnVector | |
5275 | 3130 ComplexMatrix::row_min (Array<octave_idx_type>& idx_arg) const |
458 | 3131 { |
3132 ComplexColumnVector result; | |
3133 | |
5275 | 3134 octave_idx_type nr = rows (); |
3135 octave_idx_type nc = cols (); | |
458 | 3136 |
3137 if (nr > 0 && nc > 0) | |
3138 { | |
3139 result.resize (nr); | |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3140 idx_arg.resize (dim_vector (nr, 1)); |
458 | 3141 |
5275 | 3142 for (octave_idx_type i = 0; i < nr; i++) |
458 | 3143 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3144 bool real_only = row_is_real_only (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3145 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3146 octave_idx_type idx_j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3147 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3148 Complex tmp_min; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3149 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3150 double abs_min = octave_NaN; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3151 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3152 for (idx_j = 0; idx_j < nc; idx_j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3153 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3154 tmp_min = elem (i, idx_j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3155 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3156 if (! xisnan (tmp_min)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3157 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3158 abs_min = real_only ? std::real (tmp_min) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3159 : std::abs (tmp_min); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3160 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3161 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3162 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3163 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3164 for (octave_idx_type j = idx_j+1; j < nc; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3165 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3166 Complex tmp = elem (i, j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3167 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3168 if (xisnan (tmp)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3169 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3170 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3171 double abs_tmp = real_only ? std::real (tmp) : std::abs (tmp); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3172 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3173 if (abs_tmp < abs_min) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3174 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3175 idx_j = j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3176 tmp_min = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3177 abs_min = abs_tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3178 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3179 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3180 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3181 if (xisnan (tmp_min)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3182 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3183 result.elem (i) = Complex_NaN_result; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3184 idx_arg.elem (i) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3185 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3186 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3187 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3188 result.elem (i) = tmp_min; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3189 idx_arg.elem (i) = idx_j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3190 } |
458 | 3191 } |
3192 } | |
3193 | |
3194 return result; | |
3195 } | |
3196 | |
3197 ComplexColumnVector | |
3198 ComplexMatrix::row_max (void) const | |
3199 { | |
5275 | 3200 Array<octave_idx_type> dummy_idx; |
4587 | 3201 return row_max (dummy_idx); |
458 | 3202 } |
3203 | |
3204 ComplexColumnVector | |
5275 | 3205 ComplexMatrix::row_max (Array<octave_idx_type>& idx_arg) const |
458 | 3206 { |
3207 ComplexColumnVector result; | |
3208 | |
5275 | 3209 octave_idx_type nr = rows (); |
3210 octave_idx_type nc = cols (); | |
458 | 3211 |
3212 if (nr > 0 && nc > 0) | |
3213 { | |
3214 result.resize (nr); | |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3215 idx_arg.resize (dim_vector (nr, 1)); |
458 | 3216 |
5275 | 3217 for (octave_idx_type i = 0; i < nr; i++) |
458 | 3218 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3219 bool real_only = row_is_real_only (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3220 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3221 octave_idx_type idx_j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3222 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3223 Complex tmp_max; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3224 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3225 double abs_max = octave_NaN; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3226 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3227 for (idx_j = 0; idx_j < nc; idx_j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3228 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3229 tmp_max = elem (i, idx_j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3230 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3231 if (! xisnan (tmp_max)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3232 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3233 abs_max = real_only ? std::real (tmp_max) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3234 : std::abs (tmp_max); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3235 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3236 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3237 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3238 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3239 for (octave_idx_type j = idx_j+1; j < nc; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3240 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3241 Complex tmp = elem (i, j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3242 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3243 if (xisnan (tmp)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3244 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3245 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3246 double abs_tmp = real_only ? std::real (tmp) : std::abs (tmp); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3247 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3248 if (abs_tmp > abs_max) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3249 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3250 idx_j = j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3251 tmp_max = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3252 abs_max = abs_tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3253 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3254 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3255 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3256 if (xisnan (tmp_max)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3257 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3258 result.elem (i) = Complex_NaN_result; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3259 idx_arg.elem (i) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3260 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3261 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3262 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3263 result.elem (i) = tmp_max; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3264 idx_arg.elem (i) = idx_j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3265 } |
458 | 3266 } |
3267 } | |
3268 | |
3269 return result; | |
3270 } | |
3271 | |
3272 ComplexRowVector | |
3273 ComplexMatrix::column_min (void) const | |
3274 { | |
5275 | 3275 Array<octave_idx_type> dummy_idx; |
4587 | 3276 return column_min (dummy_idx); |
458 | 3277 } |
3278 | |
3279 ComplexRowVector | |
5275 | 3280 ComplexMatrix::column_min (Array<octave_idx_type>& idx_arg) const |
458 | 3281 { |
3282 ComplexRowVector result; | |
3283 | |
5275 | 3284 octave_idx_type nr = rows (); |
3285 octave_idx_type nc = cols (); | |
458 | 3286 |
3287 if (nr > 0 && nc > 0) | |
3288 { | |
3289 result.resize (nc); | |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3290 idx_arg.resize (dim_vector (1, nc)); |
458 | 3291 |
5275 | 3292 for (octave_idx_type j = 0; j < nc; j++) |
458 | 3293 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3294 bool real_only = column_is_real_only (j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3295 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3296 octave_idx_type idx_i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3297 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3298 Complex tmp_min; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3299 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3300 double abs_min = octave_NaN; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3301 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3302 for (idx_i = 0; idx_i < nr; idx_i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3303 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3304 tmp_min = elem (idx_i, j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3305 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3306 if (! xisnan (tmp_min)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3307 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3308 abs_min = real_only ? std::real (tmp_min) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3309 : std::abs (tmp_min); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3310 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3311 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3312 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3313 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3314 for (octave_idx_type i = idx_i+1; i < nr; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3315 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3316 Complex tmp = elem (i, j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3317 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3318 if (xisnan (tmp)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3319 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3320 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3321 double abs_tmp = real_only ? std::real (tmp) : std::abs (tmp); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3322 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3323 if (abs_tmp < abs_min) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3324 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3325 idx_i = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3326 tmp_min = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3327 abs_min = abs_tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3328 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3329 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3330 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3331 if (xisnan (tmp_min)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3332 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3333 result.elem (j) = Complex_NaN_result; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3334 idx_arg.elem (j) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3335 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3336 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3337 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3338 result.elem (j) = tmp_min; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3339 idx_arg.elem (j) = idx_i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3340 } |
458 | 3341 } |
3342 } | |
3343 | |
3344 return result; | |
3345 } | |
3346 | |
3347 ComplexRowVector | |
3348 ComplexMatrix::column_max (void) const | |
3349 { | |
5275 | 3350 Array<octave_idx_type> dummy_idx; |
4587 | 3351 return column_max (dummy_idx); |
458 | 3352 } |
3353 | |
3354 ComplexRowVector | |
5275 | 3355 ComplexMatrix::column_max (Array<octave_idx_type>& idx_arg) const |
458 | 3356 { |
3357 ComplexRowVector result; | |
3358 | |
5275 | 3359 octave_idx_type nr = rows (); |
3360 octave_idx_type nc = cols (); | |
458 | 3361 |
3362 if (nr > 0 && nc > 0) | |
3363 { | |
3364 result.resize (nc); | |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
3365 idx_arg.resize (dim_vector (1, nc)); |
458 | 3366 |
5275 | 3367 for (octave_idx_type j = 0; j < nc; j++) |
458 | 3368 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3369 bool real_only = column_is_real_only (j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3370 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3371 octave_idx_type idx_i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3372 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3373 Complex tmp_max; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3374 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3375 double abs_max = octave_NaN; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3376 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3377 for (idx_i = 0; idx_i < nr; idx_i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3378 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3379 tmp_max = elem (idx_i, j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3380 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3381 if (! xisnan (tmp_max)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3382 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3383 abs_max = real_only ? std::real (tmp_max) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3384 : std::abs (tmp_max); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3385 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3386 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3387 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3388 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3389 for (octave_idx_type i = idx_i+1; i < nr; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3390 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3391 Complex tmp = elem (i, j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3392 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3393 if (xisnan (tmp)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3394 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3395 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3396 double abs_tmp = real_only ? std::real (tmp) : std::abs (tmp); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3397 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3398 if (abs_tmp > abs_max) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3399 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3400 idx_i = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3401 tmp_max = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3402 abs_max = abs_tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3403 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3404 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3405 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3406 if (xisnan (tmp_max)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3407 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3408 result.elem (j) = Complex_NaN_result; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3409 idx_arg.elem (j) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3410 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3411 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3412 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3413 result.elem (j) = tmp_max; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3414 idx_arg.elem (j) = idx_i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3415 } |
458 | 3416 } |
3417 } | |
3418 | |
3419 return result; | |
3420 } | |
3421 | |
3422 // i/o | |
3423 | |
3504 | 3424 std::ostream& |
3425 operator << (std::ostream& os, const ComplexMatrix& a) | |
458 | 3426 { |
5275 | 3427 for (octave_idx_type i = 0; i < a.rows (); i++) |
458 | 3428 { |
5275 | 3429 for (octave_idx_type j = 0; j < a.cols (); j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3430 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3431 os << " "; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3432 octave_write_complex (os, a.elem (i, j)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3433 } |
458 | 3434 os << "\n"; |
3435 } | |
3436 return os; | |
3437 } | |
3438 | |
3504 | 3439 std::istream& |
3440 operator >> (std::istream& is, ComplexMatrix& a) | |
458 | 3441 { |
5275 | 3442 octave_idx_type nr = a.rows (); |
3443 octave_idx_type nc = a.cols (); | |
458 | 3444 |
8999
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8956
diff
changeset
|
3445 if (nr > 0 && nc > 0) |
458 | 3446 { |
3447 Complex tmp; | |
5275 | 3448 for (octave_idx_type i = 0; i < nr; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3449 for (octave_idx_type j = 0; j < nc; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3450 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3451 tmp = octave_read_value<Complex> (is); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3452 if (is) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3453 a.elem (i, j) = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3454 else |
21168
26f85aa072de
maint: Replace instances of goto in liboctave where convenient.
Rik <rik@octave.org>
parents:
21136
diff
changeset
|
3455 return is; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3456 } |
458 | 3457 } |
3458 | |
3459 return is; | |
3460 } | |
3461 | |
1819 | 3462 ComplexMatrix |
3463 Givens (const Complex& x, const Complex& y) | |
3464 { | |
3465 double cc; | |
3466 Complex cs, temp_r; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
3467 |
3887 | 3468 F77_FUNC (zlartg, ZLARTG) (x, y, cc, cs, temp_r); |
1819 | 3469 |
3470 ComplexMatrix g (2, 2); | |
3471 | |
3472 g.elem (0, 0) = cc; | |
3473 g.elem (1, 1) = cc; | |
3474 g.elem (0, 1) = cs; | |
3475 g.elem (1, 0) = -conj (cs); | |
3476 | |
3477 return g; | |
3478 } | |
3479 | |
3480 ComplexMatrix | |
3481 Sylvester (const ComplexMatrix& a, const ComplexMatrix& b, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3482 const ComplexMatrix& c) |
1819 | 3483 { |
3484 ComplexMatrix retval; | |
3485 | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3486 // FIXME: need to check that a, b, and c are all the same size. |
1819 | 3487 |
3488 // Compute Schur decompositions | |
3489 | |
21266
e69eaee28737
make better use of templates for Schur decomposition
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
3490 schur<ComplexMatrix> as (a, "U"); |
e69eaee28737
make better use of templates for Schur decomposition
John W. Eaton <jwe@octave.org>
parents:
21202
diff
changeset
|
3491 schur<ComplexMatrix> bs (b, "U"); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
3492 |
1819 | 3493 // Transform c to new coordinates. |
3494 | |
3495 ComplexMatrix ua = as.unitary_matrix (); | |
3496 ComplexMatrix sch_a = as.schur_matrix (); | |
3497 | |
3498 ComplexMatrix ub = bs.unitary_matrix (); | |
3499 ComplexMatrix sch_b = bs.schur_matrix (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
3500 |
1819 | 3501 ComplexMatrix cx = ua.hermitian () * c * ub; |
3502 | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3503 // Solve the sylvester equation, back-transform, and return the solution. |
1819 | 3504 |
5275 | 3505 octave_idx_type a_nr = a.rows (); |
3506 octave_idx_type b_nr = b.rows (); | |
1819 | 3507 |
3508 double scale; | |
5275 | 3509 octave_idx_type info; |
1950 | 3510 |
3511 Complex *pa = sch_a.fortran_vec (); | |
3512 Complex *pb = sch_b.fortran_vec (); | |
3513 Complex *px = cx.fortran_vec (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
3514 |
4552 | 3515 F77_XFCN (ztrsyl, ZTRSYL, (F77_CONST_CHAR_ARG2 ("N", 1), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3516 F77_CONST_CHAR_ARG2 ("N", 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3517 1, a_nr, b_nr, pa, a_nr, pb, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3518 b_nr, px, a_nr, scale, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3519 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3520 F77_CHAR_ARG_LEN (1))); |
1950 | 3521 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3522 // FIXME: check info? |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
3523 |
19065
d20c81d3cd21
Deprecate syl, add new function sylvester.
Rik <rik@octave.org>
parents:
18850
diff
changeset
|
3524 retval = ua * cx * ub.hermitian (); |
1819 | 3525 |
3526 return retval; | |
3527 } | |
3528 | |
2828 | 3529 ComplexMatrix |
3530 operator * (const ComplexMatrix& m, const Matrix& a) | |
3531 { | |
9663
7e5b4de5fbfe
improve mixed real x complex ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
3532 if (m.columns () > std::min (m.rows (), a.columns ()) / 10) |
7e5b4de5fbfe
improve mixed real x complex ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
3533 return ComplexMatrix (real (m) * a, imag (m) * a); |
7e5b4de5fbfe
improve mixed real x complex ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
3534 else |
7e5b4de5fbfe
improve mixed real x complex ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
3535 return m * ComplexMatrix (a); |
2828 | 3536 } |
3537 | |
3538 ComplexMatrix | |
3539 operator * (const Matrix& m, const ComplexMatrix& a) | |
3540 { | |
9663
7e5b4de5fbfe
improve mixed real x complex ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
3541 if (a.rows () > std::min (m.rows (), a.columns ()) / 10) |
7e5b4de5fbfe
improve mixed real x complex ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
3542 return ComplexMatrix (m * real (a), m * imag (a)); |
7e5b4de5fbfe
improve mixed real x complex ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
3543 else |
11352
5ea2644b0111
fix cut and paste error in Matrix by ComplexMatrix multiplication operator
John W. Eaton <jwe@octave.org>
parents:
11130
diff
changeset
|
3544 return ComplexMatrix (m) * a; |
2828 | 3545 } |
3546 | |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3547 /* |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3548 |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3549 ## Simple Dot Product, Matrix-Vector, and Matrix-Matrix Unit tests |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3550 %!assert ([1+i 2+i 3+i] * [ 4+i ; 5+i ; 6+i], 29+21i, 1e-14) |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3551 %!assert ([1+i 2+i ; 3+i 4+i ] * [5+i ; 6+i], [15 + 14i ; 37 + 18i], 1e-14) |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3552 %!assert ([1+i 2+i ; 3+i 4+i ] * [5+i 6+i ; 7+i 8+i], [17 + 15i 20 + 17i; 41 + 19i 48 + 21i], 1e-14) |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3553 %!assert ([1 i]*[i 0]', -i); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3554 |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3555 ## Test some simple identities |
6162 | 3556 %!shared M, cv, rv |
14427
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3557 %! M = randn (10,10) + i*rand (10,10); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3558 %! cv = randn (10,1) + i*rand (10,1); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3559 %! rv = randn (1,10) + i*rand (1,10); |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3560 %!assert ([M*cv,M*cv], M*[cv,cv], 1e-14) |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3561 %!assert ([M.'*cv,M.'*cv], M.'*[cv,cv], 1e-14) |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3562 %!assert ([M'*cv,M'*cv], M'*[cv,cv], 1e-14) |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3563 %!assert ([rv*M;rv*M], [rv;rv]*M, 1e-14) |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3564 %!assert ([rv*M.';rv*M.'], [rv;rv]*M.', 1e-14) |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3565 %!assert ([rv*M';rv*M'], [rv;rv]*M', 1e-14) |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3566 %!assert (2*rv*cv, [rv,rv]*[cv;cv], 1e-14) |
d07e989686b0
Use Octave coding conventions in liboctave %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3567 |
6162 | 3568 */ |
3569 | |
11516 | 3570 static inline char |
7800
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3571 get_blas_trans_arg (bool trans, bool conj) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3572 { |
11516 | 3573 return trans ? (conj ? 'C' : 'T') : 'N'; |
7800
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3574 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3575 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3576 // the general GEMM operation |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3577 |
2828 | 3578 ComplexMatrix |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
3579 xgemm (const ComplexMatrix& a, const ComplexMatrix& b, |
9665
1dba57e9d08d
use blas_trans_type for xgemm
Jaroslav Hajek <highegg@gmail.com>
parents:
9663
diff
changeset
|
3580 blas_trans_type transa, blas_trans_type transb) |
2828 | 3581 { |
3582 ComplexMatrix retval; | |
3583 | |
18084
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
3584 bool tra = transa != blas_no_trans; |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
3585 bool trb = transb != blas_no_trans; |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
3586 bool cja = transa == blas_conj_trans; |
8e056300994b
Follow coding convention of defining and initializing only 1 variable per line in liboctave.
Rik <rik@octave.org>
parents:
18083
diff
changeset
|
3587 bool cjb = transb == blas_conj_trans; |
9665
1dba57e9d08d
use blas_trans_type for xgemm
Jaroslav Hajek <highegg@gmail.com>
parents:
9663
diff
changeset
|
3588 |
1dba57e9d08d
use blas_trans_type for xgemm
Jaroslav Hajek <highegg@gmail.com>
parents:
9663
diff
changeset
|
3589 octave_idx_type a_nr = tra ? a.cols () : a.rows (); |
1dba57e9d08d
use blas_trans_type for xgemm
Jaroslav Hajek <highegg@gmail.com>
parents:
9663
diff
changeset
|
3590 octave_idx_type a_nc = tra ? a.rows () : a.cols (); |
1dba57e9d08d
use blas_trans_type for xgemm
Jaroslav Hajek <highegg@gmail.com>
parents:
9663
diff
changeset
|
3591 |
1dba57e9d08d
use blas_trans_type for xgemm
Jaroslav Hajek <highegg@gmail.com>
parents:
9663
diff
changeset
|
3592 octave_idx_type b_nr = trb ? b.cols () : b.rows (); |
1dba57e9d08d
use blas_trans_type for xgemm
Jaroslav Hajek <highegg@gmail.com>
parents:
9663
diff
changeset
|
3593 octave_idx_type b_nc = trb ? b.rows () : b.cols (); |
7800
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3594 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3595 if (a_nc != b_nr) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
3596 err_nonconformant ("operator *", a_nr, a_nc, b_nr, b_nc); |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3597 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3598 if (a_nr == 0 || a_nc == 0 || b_nc == 0) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3599 retval = ComplexMatrix (a_nr, b_nc, 0.0); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3600 else if (a.data () == b.data () && a_nr == b_nc && tra != trb) |
2828 | 3601 { |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3602 octave_idx_type lda = a.rows (); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3603 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3604 // FIXME: looking at the reference BLAS, it appears that it |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3605 // should not be necessary to initialize the output matrix if |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3606 // BETA is 0 in the call to ZHERK, but ATLAS appears to |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3607 // use the result matrix before zeroing the elements. |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3608 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3609 retval = ComplexMatrix (a_nr, b_nc, 0.0); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3610 Complex *c = retval.fortran_vec (); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3611 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3612 const char ctra = get_blas_trans_arg (tra, cja); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3613 if (cja || cjb) |
7801
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
3614 { |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3615 F77_XFCN (zherk, ZHERK, (F77_CONST_CHAR_ARG2 ("U", 1), |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3616 F77_CONST_CHAR_ARG2 (&ctra, 1), |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3617 a_nr, a_nc, 1.0, |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3618 a.data (), lda, 0.0, c, a_nr |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3619 F77_CHAR_ARG_LEN (1) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3620 F77_CHAR_ARG_LEN (1))); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3621 for (octave_idx_type j = 0; j < a_nr; j++) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3622 for (octave_idx_type i = 0; i < j; i++) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3623 retval.xelem (j,i) = std::conj (retval.xelem (i,j)); |
7801
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
3624 } |
2828 | 3625 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3626 { |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3627 F77_XFCN (zsyrk, ZSYRK, (F77_CONST_CHAR_ARG2 ("U", 1), |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3628 F77_CONST_CHAR_ARG2 (&ctra, 1), |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3629 a_nr, a_nc, 1.0, |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3630 a.data (), lda, 0.0, c, a_nr |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3631 F77_CHAR_ARG_LEN (1) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3632 F77_CHAR_ARG_LEN (1))); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3633 for (octave_idx_type j = 0; j < a_nr; j++) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3634 for (octave_idx_type i = 0; i < j; i++) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3635 retval.xelem (j,i) = retval.xelem (i,j); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3636 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3637 } |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3638 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3639 } |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3640 else |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3641 { |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3642 octave_idx_type lda = a.rows (); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3643 octave_idx_type tda = a.cols (); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3644 octave_idx_type ldb = b.rows (); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3645 octave_idx_type tdb = b.cols (); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3646 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3647 retval = ComplexMatrix (a_nr, b_nc, 0.0); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3648 Complex *c = retval.fortran_vec (); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3649 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3650 if (b_nc == 1 && a_nr == 1) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3651 { |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3652 if (cja == cjb) |
7800
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3653 { |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3654 F77_FUNC (xzdotu, XZDOTU) (a_nc, a.data (), 1, b.data (), 1, |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3655 *c); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3656 if (cja) *c = std::conj (*c); |
7800
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3657 } |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3658 else if (cja) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3659 F77_FUNC (xzdotc, XZDOTC) (a_nc, a.data (), 1, b.data (), 1, |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3660 *c); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3661 else |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3662 F77_FUNC (xzdotc, XZDOTC) (a_nc, b.data (), 1, a.data (), 1, |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3663 *c); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3664 } |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3665 else if (b_nc == 1 && ! cjb) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3666 { |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3667 const char ctra = get_blas_trans_arg (tra, cja); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3668 F77_XFCN (zgemv, ZGEMV, (F77_CONST_CHAR_ARG2 (&ctra, 1), |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3669 lda, tda, 1.0, a.data (), lda, |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3670 b.data (), 1, 0.0, c, 1 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3671 F77_CHAR_ARG_LEN (1))); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3672 } |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3673 else if (a_nr == 1 && ! cja && ! cjb) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3674 { |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3675 const char crevtrb = get_blas_trans_arg (! trb, cjb); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3676 F77_XFCN (zgemv, ZGEMV, (F77_CONST_CHAR_ARG2 (&crevtrb, 1), |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3677 ldb, tdb, 1.0, b.data (), ldb, |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3678 a.data (), 1, 0.0, c, 1 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3679 F77_CHAR_ARG_LEN (1))); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3680 } |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3681 else |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3682 { |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3683 const char ctra = get_blas_trans_arg (tra, cja); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3684 const char ctrb = get_blas_trans_arg (trb, cjb); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3685 F77_XFCN (zgemm, ZGEMM, (F77_CONST_CHAR_ARG2 (&ctra, 1), |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3686 F77_CONST_CHAR_ARG2 (&ctrb, 1), |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3687 a_nr, b_nc, a_nc, 1.0, a.data (), |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3688 lda, b.data (), ldb, 0.0, c, a_nr |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3689 F77_CHAR_ARG_LEN (1) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21112
diff
changeset
|
3690 F77_CHAR_ARG_LEN (1))); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3691 } |
2828 | 3692 } |
3693 | |
3694 return retval; | |
3695 } | |
3696 | |
7800
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3697 ComplexMatrix |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3698 operator * (const ComplexMatrix& a, const ComplexMatrix& b) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3699 { |
9665
1dba57e9d08d
use blas_trans_type for xgemm
Jaroslav Hajek <highegg@gmail.com>
parents:
9663
diff
changeset
|
3700 return xgemm (a, b); |
7800
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3701 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3702 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3703 // FIXME: it would be nice to share code among the min/max functions below. |
4309 | 3704 |
3705 #define EMPTY_RETURN_CHECK(T) \ | |
3706 if (nr == 0 || nc == 0) \ | |
3707 return T (nr, nc); | |
3708 | |
3709 ComplexMatrix | |
3710 min (const Complex& c, const ComplexMatrix& m) | |
3711 { | |
5275 | 3712 octave_idx_type nr = m.rows (); |
3713 octave_idx_type nc = m.columns (); | |
4309 | 3714 |
3715 EMPTY_RETURN_CHECK (ComplexMatrix); | |
3716 | |
3717 ComplexMatrix result (nr, nc); | |
3718 | |
5275 | 3719 for (octave_idx_type j = 0; j < nc; j++) |
3720 for (octave_idx_type i = 0; i < nr; i++) | |
4309 | 3721 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3722 octave_quit (); |
18083
938f01339043
maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
3723 result(i, j) = xmin (c, m(i, j)); |
4309 | 3724 } |
3725 | |
3726 return result; | |
3727 } | |
3728 | |
3729 ComplexMatrix | |
3730 min (const ComplexMatrix& m, const Complex& c) | |
3731 { | |
5275 | 3732 octave_idx_type nr = m.rows (); |
3733 octave_idx_type nc = m.columns (); | |
4309 | 3734 |
3735 EMPTY_RETURN_CHECK (ComplexMatrix); | |
3736 | |
3737 ComplexMatrix result (nr, nc); | |
3738 | |
5275 | 3739 for (octave_idx_type j = 0; j < nc; j++) |
3740 for (octave_idx_type i = 0; i < nr; i++) | |
4309 | 3741 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3742 octave_quit (); |
18083
938f01339043
maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
3743 result(i, j) = xmin (m(i, j), c); |
4309 | 3744 } |
3745 | |
3746 return result; | |
3747 } | |
3748 | |
3749 ComplexMatrix | |
3750 min (const ComplexMatrix& a, const ComplexMatrix& b) | |
3751 { | |
5275 | 3752 octave_idx_type nr = a.rows (); |
3753 octave_idx_type nc = a.columns (); | |
4309 | 3754 |
3755 if (nr != b.rows () || nc != b.columns ()) | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
3756 (*current_liboctave_error_handler) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
3757 ("two-arg min requires same size arguments"); |
4309 | 3758 |
3759 EMPTY_RETURN_CHECK (ComplexMatrix); | |
3760 | |
3761 ComplexMatrix result (nr, nc); | |
3762 | |
5275 | 3763 for (octave_idx_type j = 0; j < nc; j++) |
4309 | 3764 { |
3765 int columns_are_real_only = 1; | |
5275 | 3766 for (octave_idx_type i = 0; i < nr; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3767 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3768 octave_quit (); |
18083
938f01339043
maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
3769 if (std::imag (a(i, j)) != 0.0 || std::imag (b(i, j)) != 0.0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3770 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3771 columns_are_real_only = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3772 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3773 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3774 } |
4309 | 3775 |
3776 if (columns_are_real_only) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3777 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3778 for (octave_idx_type i = 0; i < nr; i++) |
18083
938f01339043
maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
3779 result(i, j) = xmin (std::real (a(i, j)), std::real (b(i, j))); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3780 } |
4309 | 3781 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3782 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3783 for (octave_idx_type i = 0; i < nr; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3784 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3785 octave_quit (); |
18083
938f01339043
maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
3786 result(i, j) = xmin (a(i, j), b(i, j)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3787 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3788 } |
4309 | 3789 } |
3790 | |
3791 return result; | |
3792 } | |
3793 | |
3794 ComplexMatrix | |
3795 max (const Complex& c, const ComplexMatrix& m) | |
3796 { | |
5275 | 3797 octave_idx_type nr = m.rows (); |
3798 octave_idx_type nc = m.columns (); | |
4309 | 3799 |
3800 EMPTY_RETURN_CHECK (ComplexMatrix); | |
3801 | |
3802 ComplexMatrix result (nr, nc); | |
3803 | |
5275 | 3804 for (octave_idx_type j = 0; j < nc; j++) |
3805 for (octave_idx_type i = 0; i < nr; i++) | |
4309 | 3806 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3807 octave_quit (); |
18083
938f01339043
maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
3808 result(i, j) = xmax (c, m(i, j)); |
4309 | 3809 } |
3810 | |
3811 return result; | |
3812 } | |
3813 | |
3814 ComplexMatrix | |
3815 max (const ComplexMatrix& m, const Complex& c) | |
3816 { | |
5275 | 3817 octave_idx_type nr = m.rows (); |
3818 octave_idx_type nc = m.columns (); | |
4309 | 3819 |
3820 EMPTY_RETURN_CHECK (ComplexMatrix); | |
3821 | |
3822 ComplexMatrix result (nr, nc); | |
3823 | |
5275 | 3824 for (octave_idx_type j = 0; j < nc; j++) |
3825 for (octave_idx_type i = 0; i < nr; i++) | |
4309 | 3826 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3827 octave_quit (); |
18083
938f01339043
maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
3828 result(i, j) = xmax (m(i, j), c); |
4309 | 3829 } |
3830 | |
3831 return result; | |
3832 } | |
3833 | |
3834 ComplexMatrix | |
3835 max (const ComplexMatrix& a, const ComplexMatrix& b) | |
3836 { | |
5275 | 3837 octave_idx_type nr = a.rows (); |
3838 octave_idx_type nc = a.columns (); | |
4309 | 3839 |
3840 if (nr != b.rows () || nc != b.columns ()) | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
3841 (*current_liboctave_error_handler) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
21129
diff
changeset
|
3842 ("two-arg max requires same size arguments"); |
4309 | 3843 |
3844 EMPTY_RETURN_CHECK (ComplexMatrix); | |
3845 | |
3846 ComplexMatrix result (nr, nc); | |
3847 | |
5275 | 3848 for (octave_idx_type j = 0; j < nc; j++) |
4309 | 3849 { |
3850 int columns_are_real_only = 1; | |
5275 | 3851 for (octave_idx_type i = 0; i < nr; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3852 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3853 octave_quit (); |
18083
938f01339043
maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
3854 if (std::imag (a(i, j)) != 0.0 || std::imag (b(i, j)) != 0.0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3855 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3856 columns_are_real_only = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3857 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3858 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3859 } |
4309 | 3860 |
3861 if (columns_are_real_only) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3862 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3863 for (octave_idx_type i = 0; i < nr; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3864 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3865 octave_quit (); |
18083
938f01339043
maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
3866 result(i, j) = xmax (std::real (a(i, j)), std::real (b(i, j))); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3867 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3868 } |
4309 | 3869 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3870 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3871 for (octave_idx_type i = 0; i < nr; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3872 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3873 octave_quit (); |
18083
938f01339043
maint: Use Octave coding convention for indexing vs. function calls in liboctave/array.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
3874 result(i, j) = xmax (a(i, j), b(i, j)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3875 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3876 } |
4309 | 3877 } |
3878 | |
3879 return result; | |
3880 } | |
3881 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
3882 ComplexMatrix linspace (const ComplexColumnVector& x1, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
3883 const ComplexColumnVector& x2, |
9653
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3884 octave_idx_type n) |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3885 |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3886 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
3887 octave_idx_type m = x1.numel (); |
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
3888 |
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
3889 if (x2.numel () != m) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3890 (*current_liboctave_error_handler) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3891 ("linspace: vectors must be of equal length"); |
9653
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3892 |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3893 NoAlias<ComplexMatrix> retval; |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3894 |
20466
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20462
diff
changeset
|
3895 if (n < 1) |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20462
diff
changeset
|
3896 { |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20462
diff
changeset
|
3897 retval.clear (m, 0); |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20462
diff
changeset
|
3898 return retval; |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20462
diff
changeset
|
3899 } |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20462
diff
changeset
|
3900 |
9653
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3901 retval.clear (m, n); |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3902 for (octave_idx_type i = 0; i < m; i++) |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3903 retval(i, 0) = x1(i); |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3904 |
20466
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20462
diff
changeset
|
3905 // The last column is unused so temporarily store delta there |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
3906 Complex *delta = &retval(0, n-1); |
9653
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3907 for (octave_idx_type i = 0; i < m; i++) |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3908 delta[i] = (x2(i) - x1(i)) / (n - 1.0); |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3909 |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3910 for (octave_idx_type j = 1; j < n-1; j++) |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3911 for (octave_idx_type i = 0; i < m; i++) |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9653
diff
changeset
|
3912 retval(i, j) = x1(i) + static_cast<double> (j)*delta[i]; |
9653
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3913 |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3914 for (octave_idx_type i = 0; i < m; i++) |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3915 retval(i, n-1) = x2(i); |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3916 |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3917 return retval; |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3918 } |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3919 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
3920 MS_CMP_OPS (ComplexMatrix, Complex) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9528
diff
changeset
|
3921 MS_BOOL_OPS (ComplexMatrix, Complex) |
2870 | 3922 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
3923 SM_CMP_OPS (Complex, ComplexMatrix) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9528
diff
changeset
|
3924 SM_BOOL_OPS (Complex, ComplexMatrix) |
2870 | 3925 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
3926 MM_CMP_OPS (ComplexMatrix, ComplexMatrix) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9528
diff
changeset
|
3927 MM_BOOL_OPS (ComplexMatrix, ComplexMatrix) |