Mercurial > hg > octave-nkf
annotate liboctave/dMatrix.cc @ 12283:0664a7ddd944 release-3-4-x
README.MacOS: Spelling corrections.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Fri, 28 Jan 2011 22:27:17 -0500 |
parents | 12df7854fa7c |
children | f217edac2c71 |
rev | line source |
---|---|
1993 | 1 // Matrix manipulations. |
458 | 2 /* |
3 | |
11523 | 4 Copyright (C) 1994-2011 John W. Eaton |
7803 | 5 Copyright (C) 2008 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 | |
1192 | 27 #include <config.h> |
458 | 28 #endif |
29 | |
1367 | 30 #include <cfloat> |
31 | |
3503 | 32 #include <iostream> |
6209 | 33 #include <vector> |
1367 | 34 |
4669 | 35 #include "Array-util.h" |
2317 | 36 #include "byte-swap.h" |
2828 | 37 #include "dMatrix.h" |
1819 | 38 #include "dbleAEPBAL.h" |
8335 | 39 #include "DET.h" |
1819 | 40 #include "dbleSCHUR.h" |
740 | 41 #include "dbleSVD.h" |
6207 | 42 #include "dbleCHOL.h" |
1847 | 43 #include "f77-fcn.h" |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7488
diff
changeset
|
44 #include "functor.h" |
458 | 45 #include "lo-error.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8375
diff
changeset
|
46 #include "oct-locbuf.h" |
2354 | 47 #include "lo-ieee.h" |
48 #include "lo-mappers.h" | |
1968 | 49 #include "lo-utils.h" |
1367 | 50 #include "mx-base.h" |
2828 | 51 #include "mx-m-dm.h" |
3176 | 52 #include "mx-dm-m.h" |
1367 | 53 #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
|
54 #include "mx-op-defs.h" |
1650 | 55 #include "oct-cmplx.h" |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
56 #include "oct-fftw.h" |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
57 #include "oct-norm.h" |
4153 | 58 #include "quit.h" |
458 | 59 |
60 // Fortran functions we call. | |
61 | |
62 extern "C" | |
63 { | |
7478 | 64 F77_RET_T |
11518 | 65 F77_FUNC (xilaenv, XILAENV) (const octave_idx_type&, |
66 F77_CONST_CHAR_ARG_DECL, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
67 F77_CONST_CHAR_ARG_DECL, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
68 const octave_idx_type&, const octave_idx_type&, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
69 const octave_idx_type&, const octave_idx_type&, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
70 octave_idx_type& |
11518 | 71 F77_CHAR_ARG_LEN_DECL |
72 F77_CHAR_ARG_LEN_DECL); | |
7476 | 73 |
4552 | 74 F77_RET_T |
75 F77_FUNC (dgebal, DGEBAL) (F77_CONST_CHAR_ARG_DECL, | |
11518 | 76 const octave_idx_type&, double*, |
77 const octave_idx_type&, octave_idx_type&, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
78 octave_idx_type&, double*, octave_idx_type& |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
79 F77_CHAR_ARG_LEN_DECL); |
4552 | 80 |
81 F77_RET_T | |
82 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
|
83 F77_CONST_CHAR_ARG_DECL, |
11518 | 84 const octave_idx_type&, const octave_idx_type&, |
85 const octave_idx_type&, double*, | |
86 const octave_idx_type&, double*, | |
87 const octave_idx_type&, octave_idx_type& | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
88 F77_CHAR_ARG_LEN_DECL |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
89 F77_CHAR_ARG_LEN_DECL); |
4552 | 90 |
91 | |
92 F77_RET_T | |
93 F77_FUNC (dgemm, DGEMM) (F77_CONST_CHAR_ARG_DECL, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
94 F77_CONST_CHAR_ARG_DECL, |
11518 | 95 const octave_idx_type&, const octave_idx_type&, |
96 const octave_idx_type&, const double&, | |
97 const double*, const octave_idx_type&, | |
98 const double*, const octave_idx_type&, | |
99 const double&, double*, const octave_idx_type& | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
100 F77_CHAR_ARG_LEN_DECL |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
101 F77_CHAR_ARG_LEN_DECL); |
4552 | 102 |
103 F77_RET_T | |
5983 | 104 F77_FUNC (dgemv, DGEMV) (F77_CONST_CHAR_ARG_DECL, |
11518 | 105 const octave_idx_type&, const octave_idx_type&, |
106 const double&, const double*, | |
107 const octave_idx_type&, const double*, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
108 const octave_idx_type&, const double&, double*, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
109 const octave_idx_type& |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
110 F77_CHAR_ARG_LEN_DECL); |
5983 | 111 |
112 F77_RET_T | |
11518 | 113 F77_FUNC (xddot, XDDOT) (const octave_idx_type&, const double*, |
114 const octave_idx_type&, const double*, | |
115 const octave_idx_type&, double&); | |
5983 | 116 |
117 F77_RET_T | |
7801
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
118 F77_FUNC (dsyrk, DSYRK) (F77_CONST_CHAR_ARG_DECL, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
119 F77_CONST_CHAR_ARG_DECL, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
120 const octave_idx_type&, const octave_idx_type&, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
121 const double&, const double*, const octave_idx_type&, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
122 const double&, double*, const octave_idx_type& |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
123 F77_CHAR_ARG_LEN_DECL |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
124 F77_CHAR_ARG_LEN_DECL); |
7801
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
125 |
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
126 F77_RET_T |
11518 | 127 F77_FUNC (dgetrf, DGETRF) (const octave_idx_type&, const octave_idx_type&, |
128 double*, const octave_idx_type&, | |
129 octave_idx_type*, octave_idx_type&); | |
4329 | 130 |
4552 | 131 F77_RET_T |
11518 | 132 F77_FUNC (dgetrs, DGETRS) (F77_CONST_CHAR_ARG_DECL, |
133 const octave_idx_type&, const octave_idx_type&, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
134 const double*, const octave_idx_type&, |
11518 | 135 const octave_idx_type*, double*, |
136 const octave_idx_type&, octave_idx_type& | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
137 F77_CHAR_ARG_LEN_DECL); |
4552 | 138 |
139 F77_RET_T | |
11518 | 140 F77_FUNC (dgetri, DGETRI) (const octave_idx_type&, double*, |
141 const octave_idx_type&, const octave_idx_type*, | |
142 double*, const octave_idx_type&, | |
143 octave_idx_type&); | |
4552 | 144 |
145 F77_RET_T | |
11518 | 146 F77_FUNC (dgecon, DGECON) (F77_CONST_CHAR_ARG_DECL, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
147 const octave_idx_type&, double*, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
148 const octave_idx_type&, const double&, double&, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
149 double*, octave_idx_type*, octave_idx_type& |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
150 F77_CHAR_ARG_LEN_DECL); |
4552 | 151 |
152 F77_RET_T | |
11518 | 153 F77_FUNC (dgelsy, DGELSY) (const octave_idx_type&, const octave_idx_type&, |
154 const octave_idx_type&, double*, | |
155 const octave_idx_type&, double*, | |
156 const octave_idx_type&, octave_idx_type*, | |
157 double&, octave_idx_type&, double*, | |
158 const octave_idx_type&, octave_idx_type&); | |
7072 | 159 |
160 F77_RET_T | |
11518 | 161 F77_FUNC (dgelsd, DGELSD) (const octave_idx_type&, const octave_idx_type&, |
162 const octave_idx_type&, double*, | |
163 const octave_idx_type&, double*, | |
164 const octave_idx_type&, double*, double&, | |
165 octave_idx_type&, double*, | |
166 const octave_idx_type&, octave_idx_type*, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
167 octave_idx_type&); |
458 | 168 |
5785 | 169 F77_RET_T |
11518 | 170 F77_FUNC (dpotrf, DPOTRF) (F77_CONST_CHAR_ARG_DECL, |
171 const octave_idx_type&, double *, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
172 const octave_idx_type&, octave_idx_type& |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
173 F77_CHAR_ARG_LEN_DECL); |
5785 | 174 |
175 F77_RET_T | |
11518 | 176 F77_FUNC (dpocon, DPOCON) (F77_CONST_CHAR_ARG_DECL, |
177 const octave_idx_type&, double*, | |
178 const octave_idx_type&, const double&, | |
179 double&, double*, octave_idx_type*, | |
180 octave_idx_type& | |
181 F77_CHAR_ARG_LEN_DECL); | |
182 F77_RET_T | |
183 F77_FUNC (dpotrs, DPOTRS) (F77_CONST_CHAR_ARG_DECL, | |
184 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
|
185 const double*, const octave_idx_type&, double*, |
11518 | 186 const octave_idx_type&, octave_idx_type& |
187 F77_CHAR_ARG_LEN_DECL); | |
188 | |
189 F77_RET_T | |
190 F77_FUNC (dtrtri, DTRTRI) (F77_CONST_CHAR_ARG_DECL, | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
191 F77_CONST_CHAR_ARG_DECL, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
192 const octave_idx_type&, const double*, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
193 const octave_idx_type&, octave_idx_type& |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
194 F77_CHAR_ARG_LEN_DECL |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
195 F77_CHAR_ARG_LEN_DECL); |
6207 | 196 F77_RET_T |
11518 | 197 F77_FUNC (dtrcon, DTRCON) (F77_CONST_CHAR_ARG_DECL, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
198 F77_CONST_CHAR_ARG_DECL, |
11518 | 199 F77_CONST_CHAR_ARG_DECL, |
200 const octave_idx_type&, const double*, | |
201 const octave_idx_type&, double&, | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
202 double*, octave_idx_type*, octave_idx_type& |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
203 F77_CHAR_ARG_LEN_DECL |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
204 F77_CHAR_ARG_LEN_DECL |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
205 F77_CHAR_ARG_LEN_DECL); |
5785 | 206 F77_RET_T |
11518 | 207 F77_FUNC (dtrtrs, DTRTRS) (F77_CONST_CHAR_ARG_DECL, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
208 F77_CONST_CHAR_ARG_DECL, |
11518 | 209 F77_CONST_CHAR_ARG_DECL, |
210 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
|
211 const double*, const octave_idx_type&, double*, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
212 const octave_idx_type&, octave_idx_type& |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
213 F77_CHAR_ARG_LEN_DECL |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
214 F77_CHAR_ARG_LEN_DECL |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
215 F77_CHAR_ARG_LEN_DECL); |
5785 | 216 |
4552 | 217 F77_RET_T |
218 F77_FUNC (dlartg, DLARTG) (const double&, const double&, double&, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
219 double&, double&); |
4552 | 220 |
221 F77_RET_T | |
222 F77_FUNC (dtrsyl, DTRSYL) (F77_CONST_CHAR_ARG_DECL, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
223 F77_CONST_CHAR_ARG_DECL, |
11518 | 224 const octave_idx_type&, const octave_idx_type&, |
225 const octave_idx_type&, const double*, | |
226 const octave_idx_type&, const double*, | |
227 const octave_idx_type&, const double*, | |
228 const octave_idx_type&, double&, octave_idx_type& | |
10314
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); |
4552 | 231 |
232 F77_RET_T | |
11518 | 233 F77_FUNC (xdlange, XDLANGE) (F77_CONST_CHAR_ARG_DECL, |
234 const octave_idx_type&, const octave_idx_type&, | |
235 const double*, const octave_idx_type&, | |
236 double*, double& | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
237 F77_CHAR_ARG_LEN_DECL); |
458 | 238 } |
239 | |
1360 | 240 // Matrix class. |
458 | 241 |
2349 | 242 Matrix::Matrix (const RowVector& rv) |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
243 : MArray<double> (rv) |
2349 | 244 { |
245 } | |
246 | |
247 Matrix::Matrix (const ColumnVector& cv) | |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
248 : MArray<double> (cv) |
2349 | 249 { |
250 } | |
251 | |
458 | 252 Matrix::Matrix (const DiagMatrix& a) |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
253 : MArray<double> (a.dims (), 0.0) |
458 | 254 { |
5275 | 255 for (octave_idx_type i = 0; i < a.length (); i++) |
458 | 256 elem (i, i) = a.elem (i, i); |
257 } | |
258 | |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8337
diff
changeset
|
259 Matrix::Matrix (const PermMatrix& a) |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
260 : MArray<double> (a.dims (), 0.0) |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8337
diff
changeset
|
261 { |
8375
e3c9102431a9
fix design problems of diag & perm matrix classes
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
262 const Array<octave_idx_type> ia (a.pvec ()); |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8337
diff
changeset
|
263 octave_idx_type len = a.rows (); |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8337
diff
changeset
|
264 if (a.is_col_perm ()) |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8337
diff
changeset
|
265 for (octave_idx_type i = 0; i < len; i++) |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8337
diff
changeset
|
266 elem (ia(i), i) = 1.0; |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8337
diff
changeset
|
267 else |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8337
diff
changeset
|
268 for (octave_idx_type i = 0; i < len; i++) |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8337
diff
changeset
|
269 elem (i, ia(i)) = 1.0; |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8337
diff
changeset
|
270 } |
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8337
diff
changeset
|
271 |
5775 | 272 // FIXME -- could we use a templated mixed-type copy function |
1574 | 273 // here? |
274 | |
2828 | 275 Matrix::Matrix (const boolMatrix& a) |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
276 : MArray<double> (a) |
2828 | 277 { |
278 } | |
279 | |
1574 | 280 Matrix::Matrix (const charMatrix& a) |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
281 : MArray<double> (a.dims ()) |
1574 | 282 { |
5275 | 283 for (octave_idx_type i = 0; i < a.rows (); i++) |
284 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
|
285 elem (i, j) = static_cast<unsigned char> (a.elem (i, j)); |
1574 | 286 } |
287 | |
2385 | 288 bool |
458 | 289 Matrix::operator == (const Matrix& a) const |
290 { | |
291 if (rows () != a.rows () || cols () != a.cols ()) | |
2385 | 292 return false; |
458 | 293 |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9528
diff
changeset
|
294 return mx_inline_equal (length (), data (), a.data ()); |
458 | 295 } |
296 | |
2385 | 297 bool |
458 | 298 Matrix::operator != (const Matrix& a) const |
299 { | |
300 return !(*this == a); | |
301 } | |
302 | |
3354 | 303 bool |
304 Matrix::is_symmetric (void) const | |
305 { | |
306 if (is_square () && rows () > 0) | |
307 { | |
5275 | 308 for (octave_idx_type i = 0; i < rows (); i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
309 for (octave_idx_type j = i+1; j < cols (); j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
310 if (elem (i, j) != elem (j, i)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
311 return false; |
3354 | 312 |
313 return true; | |
314 } | |
315 | |
316 return false; | |
317 } | |
318 | |
458 | 319 Matrix& |
5275 | 320 Matrix::insert (const Matrix& a, octave_idx_type r, octave_idx_type c) |
458 | 321 { |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
322 Array<double>::insert (a, r, c); |
458 | 323 return *this; |
324 } | |
325 | |
326 Matrix& | |
5275 | 327 Matrix::insert (const RowVector& a, octave_idx_type r, octave_idx_type c) |
458 | 328 { |
5275 | 329 octave_idx_type a_len = a.length (); |
4316 | 330 |
1698 | 331 if (r < 0 || r >= rows () || c < 0 || c + a_len > cols ()) |
458 | 332 { |
333 (*current_liboctave_error_handler) ("range error for insert"); | |
334 return *this; | |
335 } | |
336 | |
4316 | 337 if (a_len > 0) |
338 { | |
339 make_unique (); | |
340 | |
5275 | 341 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
|
342 xelem (r, c+i) = a.elem (i); |
4316 | 343 } |
458 | 344 |
345 return *this; | |
346 } | |
347 | |
348 Matrix& | |
5275 | 349 Matrix::insert (const ColumnVector& a, octave_idx_type r, octave_idx_type c) |
458 | 350 { |
5275 | 351 octave_idx_type a_len = a.length (); |
4316 | 352 |
1698 | 353 if (r < 0 || r + a_len > rows () || c < 0 || c >= cols ()) |
458 | 354 { |
355 (*current_liboctave_error_handler) ("range error for insert"); | |
356 return *this; | |
357 } | |
358 | |
4316 | 359 if (a_len > 0) |
360 { | |
361 make_unique (); | |
362 | |
5275 | 363 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
|
364 xelem (r+i, c) = a.elem (i); |
4316 | 365 } |
458 | 366 |
367 return *this; | |
368 } | |
369 | |
370 Matrix& | |
5275 | 371 Matrix::insert (const DiagMatrix& a, octave_idx_type r, octave_idx_type c) |
458 | 372 { |
5275 | 373 octave_idx_type a_nr = a.rows (); |
374 octave_idx_type a_nc = a.cols (); | |
1697 | 375 |
1698 | 376 if (r < 0 || r + a_nr > rows () || c < 0 || c + a_nc > cols ()) |
458 | 377 { |
378 (*current_liboctave_error_handler) ("range error for insert"); | |
379 return *this; | |
380 } | |
381 | |
1697 | 382 fill (0.0, r, c, r + a_nr - 1, c + a_nc - 1); |
383 | |
5275 | 384 octave_idx_type a_len = a.length (); |
4316 | 385 |
386 if (a_len > 0) | |
387 { | |
388 make_unique (); | |
389 | |
5275 | 390 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
|
391 xelem (r+i, c+i) = a.elem (i, i); |
4316 | 392 } |
458 | 393 |
394 return *this; | |
395 } | |
396 | |
397 Matrix& | |
398 Matrix::fill (double val) | |
399 { | |
5275 | 400 octave_idx_type nr = rows (); |
401 octave_idx_type nc = cols (); | |
4316 | 402 |
458 | 403 if (nr > 0 && nc > 0) |
4316 | 404 { |
405 make_unique (); | |
406 | |
5275 | 407 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
|
408 for (octave_idx_type i = 0; i < nr; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
409 xelem (i, j) = val; |
4316 | 410 } |
458 | 411 |
412 return *this; | |
413 } | |
414 | |
415 Matrix& | |
5275 | 416 Matrix::fill (double val, octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) |
458 | 417 { |
5275 | 418 octave_idx_type nr = rows (); |
419 octave_idx_type nc = cols (); | |
4316 | 420 |
458 | 421 if (r1 < 0 || r2 < 0 || c1 < 0 || c2 < 0 |
422 || r1 >= nr || r2 >= nr || c1 >= nc || c2 >= nc) | |
423 { | |
424 (*current_liboctave_error_handler) ("range error for fill"); | |
425 return *this; | |
426 } | |
427 | |
5275 | 428 if (r1 > r2) { octave_idx_type tmp = r1; r1 = r2; r2 = tmp; } |
429 if (c1 > c2) { octave_idx_type tmp = c1; c1 = c2; c2 = tmp; } | |
458 | 430 |
4316 | 431 if (r2 >= r1 && c2 >= c1) |
432 { | |
433 make_unique (); | |
434 | |
5275 | 435 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
|
436 for (octave_idx_type i = r1; i <= r2; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
437 xelem (i, j) = val; |
4316 | 438 } |
458 | 439 |
440 return *this; | |
441 } | |
442 | |
443 Matrix | |
444 Matrix::append (const Matrix& a) const | |
445 { | |
5275 | 446 octave_idx_type nr = rows (); |
447 octave_idx_type nc = cols (); | |
458 | 448 if (nr != a.rows ()) |
449 { | |
450 (*current_liboctave_error_handler) ("row dimension mismatch for append"); | |
451 return Matrix (); | |
452 } | |
453 | |
5275 | 454 octave_idx_type nc_insert = nc; |
458 | 455 Matrix retval (nr, nc + a.cols ()); |
456 retval.insert (*this, 0, 0); | |
457 retval.insert (a, 0, nc_insert); | |
458 return retval; | |
459 } | |
460 | |
461 Matrix | |
462 Matrix::append (const RowVector& a) const | |
463 { | |
5275 | 464 octave_idx_type nr = rows (); |
465 octave_idx_type nc = cols (); | |
458 | 466 if (nr != 1) |
467 { | |
468 (*current_liboctave_error_handler) ("row dimension mismatch for append"); | |
469 return Matrix (); | |
470 } | |
471 | |
5275 | 472 octave_idx_type nc_insert = nc; |
458 | 473 Matrix retval (nr, nc + a.length ()); |
474 retval.insert (*this, 0, 0); | |
475 retval.insert (a, 0, nc_insert); | |
476 return retval; | |
477 } | |
478 | |
479 Matrix | |
480 Matrix::append (const ColumnVector& a) const | |
481 { | |
5275 | 482 octave_idx_type nr = rows (); |
483 octave_idx_type nc = cols (); | |
458 | 484 if (nr != a.length ()) |
485 { | |
486 (*current_liboctave_error_handler) ("row dimension mismatch for append"); | |
487 return Matrix (); | |
488 } | |
489 | |
5275 | 490 octave_idx_type nc_insert = nc; |
458 | 491 Matrix retval (nr, nc + 1); |
492 retval.insert (*this, 0, 0); | |
493 retval.insert (a, 0, nc_insert); | |
494 return retval; | |
495 } | |
496 | |
497 Matrix | |
498 Matrix::append (const DiagMatrix& a) const | |
499 { | |
5275 | 500 octave_idx_type nr = rows (); |
501 octave_idx_type nc = cols (); | |
458 | 502 if (nr != a.rows ()) |
503 { | |
504 (*current_liboctave_error_handler) ("row dimension mismatch for append"); | |
505 return *this; | |
506 } | |
507 | |
5275 | 508 octave_idx_type nc_insert = nc; |
458 | 509 Matrix retval (nr, nc + a.cols ()); |
510 retval.insert (*this, 0, 0); | |
511 retval.insert (a, 0, nc_insert); | |
512 return retval; | |
513 } | |
514 | |
515 Matrix | |
516 Matrix::stack (const Matrix& a) const | |
517 { | |
5275 | 518 octave_idx_type nr = rows (); |
519 octave_idx_type nc = cols (); | |
458 | 520 if (nc != a.cols ()) |
521 { | |
522 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
523 ("column dimension mismatch for stack"); |
458 | 524 return Matrix (); |
525 } | |
526 | |
5275 | 527 octave_idx_type nr_insert = nr; |
458 | 528 Matrix retval (nr + a.rows (), nc); |
529 retval.insert (*this, 0, 0); | |
530 retval.insert (a, nr_insert, 0); | |
531 return retval; | |
532 } | |
533 | |
534 Matrix | |
535 Matrix::stack (const RowVector& a) const | |
536 { | |
5275 | 537 octave_idx_type nr = rows (); |
538 octave_idx_type nc = cols (); | |
458 | 539 if (nc != a.length ()) |
540 { | |
541 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
542 ("column dimension mismatch for stack"); |
458 | 543 return Matrix (); |
544 } | |
545 | |
5275 | 546 octave_idx_type nr_insert = nr; |
458 | 547 Matrix retval (nr + 1, nc); |
548 retval.insert (*this, 0, 0); | |
549 retval.insert (a, nr_insert, 0); | |
550 return retval; | |
551 } | |
552 | |
553 Matrix | |
554 Matrix::stack (const ColumnVector& a) const | |
555 { | |
5275 | 556 octave_idx_type nr = rows (); |
557 octave_idx_type nc = cols (); | |
458 | 558 if (nc != 1) |
559 { | |
560 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
561 ("column dimension mismatch for stack"); |
458 | 562 return Matrix (); |
563 } | |
564 | |
5275 | 565 octave_idx_type nr_insert = nr; |
458 | 566 Matrix retval (nr + a.length (), nc); |
567 retval.insert (*this, 0, 0); | |
568 retval.insert (a, nr_insert, 0); | |
569 return retval; | |
570 } | |
571 | |
572 Matrix | |
573 Matrix::stack (const DiagMatrix& a) const | |
574 { | |
5275 | 575 octave_idx_type nr = rows (); |
576 octave_idx_type nc = cols (); | |
458 | 577 if (nc != a.cols ()) |
578 { | |
579 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
580 ("column dimension mismatch for stack"); |
458 | 581 return Matrix (); |
582 } | |
583 | |
5275 | 584 octave_idx_type nr_insert = nr; |
458 | 585 Matrix retval (nr + a.rows (), nc); |
586 retval.insert (*this, 0, 0); | |
587 retval.insert (a, nr_insert, 0); | |
588 return retval; | |
589 } | |
590 | |
591 Matrix | |
1205 | 592 real (const ComplexMatrix& a) |
593 { | |
10363
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10362
diff
changeset
|
594 return do_mx_unary_op<double, Complex> (a, mx_inline_real); |
1205 | 595 } |
596 | |
597 Matrix | |
598 imag (const ComplexMatrix& a) | |
599 { | |
10363
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10362
diff
changeset
|
600 return do_mx_unary_op<double, Complex> (a, mx_inline_imag); |
1205 | 601 } |
602 | |
603 Matrix | |
5275 | 604 Matrix::extract (octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const |
458 | 605 { |
5275 | 606 if (r1 > r2) { octave_idx_type tmp = r1; r1 = r2; r2 = tmp; } |
607 if (c1 > c2) { octave_idx_type tmp = c1; c1 = c2; c2 = tmp; } | |
608 | |
10805
8c858a1a2079
simplify Matrix::extract
Jaroslav Hajek <highegg@gmail.com>
parents:
10630
diff
changeset
|
609 return index (idx_vector (r1, r2+1), idx_vector (c1, c2+1)); |
4316 | 610 } |
611 | |
612 Matrix | |
5275 | 613 Matrix::extract_n (octave_idx_type r1, octave_idx_type c1, octave_idx_type nr, octave_idx_type nc) const |
4316 | 614 { |
10806
7c542263a92a
omissions from last two patches
Jaroslav Hajek <highegg@gmail.com>
parents:
10805
diff
changeset
|
615 return index (idx_vector (r1, r1 + nr), idx_vector (c1, c1 + nc)); |
458 | 616 } |
617 | |
618 // extract row or column i. | |
619 | |
620 RowVector | |
5275 | 621 Matrix::row (octave_idx_type i) const |
458 | 622 { |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
623 return index (idx_vector (i), idx_vector::colon); |
458 | 624 } |
625 | |
626 ColumnVector | |
5275 | 627 Matrix::column (octave_idx_type i) const |
458 | 628 { |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
629 return index (idx_vector::colon, idx_vector (i)); |
458 | 630 } |
631 | |
632 Matrix | |
633 Matrix::inverse (void) const | |
634 { | |
5275 | 635 octave_idx_type info; |
7788 | 636 double rcon; |
6207 | 637 MatrixType mattype (*this); |
7788 | 638 return inverse (mattype, info, rcon, 0, 0); |
6207 | 639 } |
640 | |
641 Matrix | |
6479 | 642 Matrix::inverse (octave_idx_type& info) const |
643 { | |
7788 | 644 double rcon; |
6479 | 645 MatrixType mattype (*this); |
7788 | 646 return inverse (mattype, info, rcon, 0, 0); |
6479 | 647 } |
648 | |
649 Matrix | |
7788 | 650 Matrix::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
|
651 int calc_cond) const |
6479 | 652 { |
653 MatrixType mattype (*this); | |
7788 | 654 return inverse (mattype, info, rcon, force, calc_cond); |
6479 | 655 } |
656 | |
657 Matrix | |
6207 | 658 Matrix::inverse (MatrixType& mattype) const |
659 { | |
660 octave_idx_type info; | |
7788 | 661 double rcon; |
662 return inverse (mattype, info, rcon, 0, 0); | |
6207 | 663 } |
664 | |
665 Matrix | |
666 Matrix::inverse (MatrixType &mattype, octave_idx_type& info) const | |
667 { | |
7788 | 668 double rcon; |
669 return inverse (mattype, info, rcon, 0, 0); | |
458 | 670 } |
671 | |
672 Matrix | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
673 Matrix::tinverse (MatrixType &mattype, octave_idx_type& info, double& rcon, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
674 int force, int calc_cond) const |
458 | 675 { |
6207 | 676 Matrix retval; |
677 | |
678 octave_idx_type nr = rows (); | |
679 octave_idx_type nc = cols (); | |
680 | |
681 if (nr != nc || nr == 0 || nc == 0) | |
682 (*current_liboctave_error_handler) ("inverse requires square matrix"); | |
683 else | |
684 { | |
685 int typ = mattype.type (); | |
686 char uplo = (typ == MatrixType::Lower ? 'L' : 'U'); | |
687 char udiag = 'N'; | |
688 retval = *this; | |
689 double *tmp_data = retval.fortran_vec (); | |
690 | |
691 F77_XFCN (dtrtri, DTRTRI, (F77_CONST_CHAR_ARG2 (&uplo, 1), | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
692 F77_CONST_CHAR_ARG2 (&udiag, 1), |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
693 nr, tmp_data, nr, info |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
694 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
695 F77_CHAR_ARG_LEN (1))); |
6207 | 696 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
697 // Throw-away extra info LAPACK gives so as to not change output. |
7788 | 698 rcon = 0.0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
699 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
700 info = -1; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
701 else if (calc_cond) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
702 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
703 octave_idx_type dtrcon_info = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
704 char job = '1'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
705 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
706 OCTAVE_LOCAL_BUFFER (double, work, 3 * nr); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
707 OCTAVE_LOCAL_BUFFER (octave_idx_type, iwork, nr); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
708 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
709 F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&job, 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
710 F77_CONST_CHAR_ARG2 (&uplo, 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
711 F77_CONST_CHAR_ARG2 (&udiag, 1), |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
712 nr, tmp_data, nr, rcon, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
713 work, iwork, dtrcon_info |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
714 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
715 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
716 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
717 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
718 if (dtrcon_info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
719 info = -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
720 } |
6207 | 721 |
722 if (info == -1 && ! force) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
723 retval = *this; // Restore matrix contents. |
6207 | 724 } |
725 | |
726 return retval; | |
458 | 727 } |
728 | |
6207 | 729 |
458 | 730 Matrix |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
731 Matrix::finverse (MatrixType &mattype, octave_idx_type& info, double& rcon, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
732 int force, int calc_cond) const |
458 | 733 { |
1948 | 734 Matrix retval; |
735 | |
5275 | 736 octave_idx_type nr = rows (); |
737 octave_idx_type nc = cols (); | |
1948 | 738 |
458 | 739 if (nr != nc || nr == 0 || nc == 0) |
1948 | 740 (*current_liboctave_error_handler) ("inverse requires square matrix"); |
458 | 741 else |
742 { | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
743 Array<octave_idx_type> ipvt (dim_vector (nr, 1)); |
5275 | 744 octave_idx_type *pipvt = ipvt.fortran_vec (); |
1948 | 745 |
746 retval = *this; | |
747 double *tmp_data = retval.fortran_vec (); | |
748 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
749 Array<double> z (dim_vector (1, 1)); |
5275 | 750 octave_idx_type lwork = -1; |
4329 | 751 |
4330 | 752 // Query the optimum work array size. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
753 F77_XFCN (dgetri, DGETRI, (nc, tmp_data, nr, pipvt, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
754 z.fortran_vec (), lwork, info)); |
4329 | 755 |
5275 | 756 lwork = static_cast<octave_idx_type> (z(0)); |
4329 | 757 lwork = (lwork < 2 *nc ? 2*nc : lwork); |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
758 z.resize (dim_vector (lwork, 1)); |
4329 | 759 double *pz = z.fortran_vec (); |
760 | |
761 info = 0; | |
762 | |
4330 | 763 // Calculate the norm of the matrix, for later use. |
4329 | 764 double anorm = 0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
765 if (calc_cond) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
766 anorm = retval.abs().sum().row(static_cast<octave_idx_type>(0)).max(); |
4329 | 767 |
768 F77_XFCN (dgetrf, DGETRF, (nc, nc, tmp_data, nr, pipvt, info)); | |
1948 | 769 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
770 // Throw-away extra info LAPACK gives so as to not change output. |
7788 | 771 rcon = 0.0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
772 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
773 info = -1; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
774 else if (calc_cond) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
775 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
776 octave_idx_type dgecon_info = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
777 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
778 // Now calculate the condition number for non-singular matrix. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
779 char job = '1'; |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
780 Array<octave_idx_type> iz (dim_vector (nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
781 octave_idx_type *piz = iz.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
782 F77_XFCN (dgecon, DGECON, (F77_CONST_CHAR_ARG2 (&job, 1), |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
783 nc, tmp_data, nr, anorm, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
784 rcon, pz, piz, dgecon_info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
785 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
786 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
787 if (dgecon_info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
788 info = -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
789 } |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
790 |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
791 if (info == -1 && ! force) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
792 retval = *this; // Restore matrix contents. |
1948 | 793 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
794 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
795 octave_idx_type dgetri_info = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
796 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
797 F77_XFCN (dgetri, DGETRI, (nc, tmp_data, nr, pipvt, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
798 pz, lwork, dgetri_info)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
799 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
800 if (dgetri_info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
801 info = -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
802 } |
6207 | 803 |
804 if (info != 0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
805 mattype.mark_as_rectangular(); |
458 | 806 } |
807 | |
1948 | 808 return retval; |
458 | 809 } |
810 | |
740 | 811 Matrix |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
812 Matrix::inverse (MatrixType &mattype, octave_idx_type& info, double& rcon, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
813 int force, int calc_cond) const |
6207 | 814 { |
815 int typ = mattype.type (false); | |
816 Matrix ret; | |
817 | |
818 if (typ == MatrixType::Unknown) | |
819 typ = mattype.type (*this); | |
820 | |
821 if (typ == MatrixType::Upper || typ == MatrixType::Lower) | |
7788 | 822 ret = tinverse (mattype, info, rcon, force, calc_cond); |
6840 | 823 else |
6207 | 824 { |
825 if (mattype.is_hermitian ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
826 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
827 CHOL chol (*this, info, calc_cond); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
828 if (info == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
829 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
830 if (calc_cond) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
831 rcon = chol.rcond (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
832 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
833 rcon = 1.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
834 ret = chol.inverse (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
835 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
836 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
837 mattype.mark_as_unsymmetric (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
838 } |
6207 | 839 |
840 if (!mattype.is_hermitian ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
841 ret = finverse(mattype, info, rcon, force, calc_cond); |
7788 | 842 |
843 if ((mattype.is_hermitian () || calc_cond) && rcon == 0.) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
844 ret = Matrix (rows (), columns (), octave_Inf); |
6207 | 845 } |
846 | |
847 return ret; | |
848 } | |
849 | |
850 Matrix | |
4384 | 851 Matrix::pseudo_inverse (double tol) const |
740 | 852 { |
3480 | 853 SVD result (*this, SVD::economy); |
740 | 854 |
855 DiagMatrix S = result.singular_values (); | |
856 Matrix U = result.left_singular_matrix (); | |
857 Matrix V = result.right_singular_matrix (); | |
858 | |
859 ColumnVector sigma = S.diag (); | |
860 | |
5275 | 861 octave_idx_type r = sigma.length () - 1; |
862 octave_idx_type nr = rows (); | |
863 octave_idx_type nc = cols (); | |
740 | 864 |
865 if (tol <= 0.0) | |
866 { | |
867 if (nr > nc) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
868 tol = nr * sigma.elem (0) * DBL_EPSILON; |
740 | 869 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
870 tol = nc * sigma.elem (0) * DBL_EPSILON; |
740 | 871 } |
872 | |
873 while (r >= 0 && sigma.elem (r) < tol) | |
874 r--; | |
875 | |
876 if (r < 0) | |
877 return Matrix (nc, nr, 0.0); | |
878 else | |
879 { | |
880 Matrix Ur = U.extract (0, 0, nr-1, r); | |
881 DiagMatrix D = DiagMatrix (sigma.extract (0, r)) . inverse (); | |
882 Matrix Vr = V.extract (0, 0, nc-1, r); | |
883 return Vr * D * Ur.transpose (); | |
884 } | |
885 } | |
886 | |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
887 #if defined (HAVE_FFTW) |
3827 | 888 |
889 ComplexMatrix | |
890 Matrix::fourier (void) const | |
891 { | |
892 size_t nr = rows (); | |
893 size_t nc = cols (); | |
894 | |
895 ComplexMatrix retval (nr, nc); | |
896 | |
897 size_t npts, nsamples; | |
898 | |
899 if (nr == 1 || nc == 1) | |
900 { | |
901 npts = nr > nc ? nr : nc; | |
902 nsamples = 1; | |
903 } | |
904 else | |
905 { | |
906 npts = nr; | |
907 nsamples = nc; | |
908 } | |
909 | |
4773 | 910 const double *in (fortran_vec ()); |
3827 | 911 Complex *out (retval.fortran_vec ()); |
912 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
913 octave_fftw::fft (in, out, npts, nsamples); |
3827 | 914 |
915 return retval; | |
916 } | |
917 | |
918 ComplexMatrix | |
919 Matrix::ifourier (void) const | |
920 { | |
921 size_t nr = rows (); | |
922 size_t nc = cols (); | |
923 | |
924 ComplexMatrix retval (nr, nc); | |
925 | |
926 size_t npts, nsamples; | |
927 | |
928 if (nr == 1 || nc == 1) | |
929 { | |
930 npts = nr > nc ? nr : nc; | |
931 nsamples = 1; | |
932 } | |
933 else | |
934 { | |
935 npts = nr; | |
936 nsamples = nc; | |
937 } | |
938 | |
939 ComplexMatrix tmp (*this); | |
940 Complex *in (tmp.fortran_vec ()); | |
941 Complex *out (retval.fortran_vec ()); | |
942 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
943 octave_fftw::ifft (in, out, npts, nsamples); |
3827 | 944 |
945 return retval; | |
946 } | |
947 | |
948 ComplexMatrix | |
949 Matrix::fourier2d (void) const | |
950 { | |
4773 | 951 dim_vector dv(rows (), cols ()); |
952 | |
953 const double *in = fortran_vec (); | |
954 ComplexMatrix retval (rows (), cols ()); | |
955 octave_fftw::fftNd (in, retval.fortran_vec (), 2, dv); | |
3827 | 956 |
957 return retval; | |
958 } | |
959 | |
960 ComplexMatrix | |
961 Matrix::ifourier2d (void) const | |
962 { | |
4773 | 963 dim_vector dv(rows (), cols ()); |
3827 | 964 |
965 ComplexMatrix retval (*this); | |
4773 | 966 Complex *out (retval.fortran_vec ()); |
967 | |
968 octave_fftw::ifftNd (out, out, 2, dv); | |
3827 | 969 |
970 return retval; | |
971 } | |
972 | |
973 #else | |
974 | |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
975 extern "C" |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
976 { |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
977 // 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
|
978 // 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
|
979 // 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
|
980 // each subroutine. |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
981 |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
982 F77_RET_T |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
983 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
|
984 |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
985 F77_RET_T |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
986 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
|
987 |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
988 F77_RET_T |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
989 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
|
990 } |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9469
diff
changeset
|
991 |
458 | 992 ComplexMatrix |
993 Matrix::fourier (void) const | |
994 { | |
1948 | 995 ComplexMatrix retval; |
996 | |
5275 | 997 octave_idx_type nr = rows (); |
998 octave_idx_type nc = cols (); | |
999 | |
1000 octave_idx_type npts, nsamples; | |
1948 | 1001 |
458 | 1002 if (nr == 1 || nc == 1) |
1003 { | |
1004 npts = nr > nc ? nr : nc; | |
1005 nsamples = 1; | |
1006 } | |
1007 else | |
1008 { | |
1009 npts = nr; | |
1010 nsamples = nc; | |
1011 } | |
1012 | |
5275 | 1013 octave_idx_type nn = 4*npts+15; |
1948 | 1014 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1015 Array<Complex> wsave (dim_vector (nn, 1)); |
1948 | 1016 Complex *pwsave = wsave.fortran_vec (); |
1017 | |
3585 | 1018 retval = ComplexMatrix (*this); |
1948 | 1019 Complex *tmp_data = retval.fortran_vec (); |
1020 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
1021 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
458 | 1022 |
5275 | 1023 for (octave_idx_type j = 0; j < nsamples; j++) |
4153 | 1024 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
1025 octave_quit (); |
4153 | 1026 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
1027 F77_FUNC (zfftf, ZFFTF) (npts, &tmp_data[npts*j], pwsave); |
4153 | 1028 } |
1948 | 1029 |
1030 return retval; | |
458 | 1031 } |
1032 | |
1033 ComplexMatrix | |
1034 Matrix::ifourier (void) const | |
1035 { | |
1948 | 1036 ComplexMatrix retval; |
1037 | |
5275 | 1038 octave_idx_type nr = rows (); |
1039 octave_idx_type nc = cols (); | |
1040 | |
1041 octave_idx_type npts, nsamples; | |
1948 | 1042 |
458 | 1043 if (nr == 1 || nc == 1) |
1044 { | |
1045 npts = nr > nc ? nr : nc; | |
1046 nsamples = 1; | |
1047 } | |
1048 else | |
1049 { | |
1050 npts = nr; | |
1051 nsamples = nc; | |
1052 } | |
1053 | |
5275 | 1054 octave_idx_type nn = 4*npts+15; |
1948 | 1055 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1056 Array<Complex> wsave (dim_vector (nn, 1)); |
1948 | 1057 Complex *pwsave = wsave.fortran_vec (); |
1058 | |
3585 | 1059 retval = ComplexMatrix (*this); |
1948 | 1060 Complex *tmp_data = retval.fortran_vec (); |
1061 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
1062 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
458 | 1063 |
5275 | 1064 for (octave_idx_type j = 0; j < nsamples; j++) |
4153 | 1065 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
1066 octave_quit (); |
4153 | 1067 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
1068 F77_FUNC (zfftb, ZFFTB) (npts, &tmp_data[npts*j], pwsave); |
4153 | 1069 } |
458 | 1070 |
5275 | 1071 for (octave_idx_type j = 0; j < npts*nsamples; j++) |
3572 | 1072 tmp_data[j] = tmp_data[j] / static_cast<double> (npts); |
458 | 1073 |
1948 | 1074 return retval; |
458 | 1075 } |
1076 | |
677 | 1077 ComplexMatrix |
1078 Matrix::fourier2d (void) const | |
1079 { | |
1948 | 1080 ComplexMatrix retval; |
1081 | |
5275 | 1082 octave_idx_type nr = rows (); |
1083 octave_idx_type nc = cols (); | |
1084 | |
1085 octave_idx_type npts, nsamples; | |
1948 | 1086 |
677 | 1087 if (nr == 1 || nc == 1) |
1088 { | |
1089 npts = nr > nc ? nr : nc; | |
1090 nsamples = 1; | |
1091 } | |
1092 else | |
1093 { | |
1094 npts = nr; | |
1095 nsamples = nc; | |
1096 } | |
1097 | |
5275 | 1098 octave_idx_type nn = 4*npts+15; |
1948 | 1099 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1100 Array<Complex> wsave (dim_vector (nn, 1)); |
1948 | 1101 Complex *pwsave = wsave.fortran_vec (); |
1102 | |
3585 | 1103 retval = ComplexMatrix (*this); |
1948 | 1104 Complex *tmp_data = retval.fortran_vec (); |
1105 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
1106 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
677 | 1107 |
5275 | 1108 for (octave_idx_type j = 0; j < nsamples; j++) |
4153 | 1109 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
1110 octave_quit (); |
4153 | 1111 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
1112 F77_FUNC (zfftf, ZFFTF) (npts, &tmp_data[npts*j], pwsave); |
4153 | 1113 } |
677 | 1114 |
1115 npts = nc; | |
1116 nsamples = nr; | |
1117 nn = 4*npts+15; | |
1948 | 1118 |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1119 wsave.resize (dim_vector (nn, 1)); |
1948 | 1120 pwsave = wsave.fortran_vec (); |
1121 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1122 Array<Complex> tmp (dim_vector (npts, 1)); |
4773 | 1123 Complex *prow = tmp.fortran_vec (); |
1948 | 1124 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
1125 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
677 | 1126 |
5275 | 1127 for (octave_idx_type j = 0; j < nsamples; j++) |
677 | 1128 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
1129 octave_quit (); |
4153 | 1130 |
5275 | 1131 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
|
1132 prow[i] = tmp_data[i*nr + j]; |
1948 | 1133 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
1134 F77_FUNC (zfftf, ZFFTF) (npts, prow, pwsave); |
677 | 1135 |
5275 | 1136 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
|
1137 tmp_data[i*nr + j] = prow[i]; |
677 | 1138 } |
1139 | |
1948 | 1140 return retval; |
677 | 1141 } |
1142 | |
1143 ComplexMatrix | |
1144 Matrix::ifourier2d (void) const | |
1145 { | |
1948 | 1146 ComplexMatrix retval; |
1147 | |
5275 | 1148 octave_idx_type nr = rows (); |
1149 octave_idx_type nc = cols (); | |
1150 | |
1151 octave_idx_type npts, nsamples; | |
1948 | 1152 |
677 | 1153 if (nr == 1 || nc == 1) |
1154 { | |
1155 npts = nr > nc ? nr : nc; | |
1156 nsamples = 1; | |
1157 } | |
1158 else | |
1159 { | |
1160 npts = nr; | |
1161 nsamples = nc; | |
1162 } | |
1163 | |
5275 | 1164 octave_idx_type nn = 4*npts+15; |
1948 | 1165 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1166 Array<Complex> wsave (dim_vector (nn, 1)); |
1948 | 1167 Complex *pwsave = wsave.fortran_vec (); |
1168 | |
3585 | 1169 retval = ComplexMatrix (*this); |
1948 | 1170 Complex *tmp_data = retval.fortran_vec (); |
1171 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
1172 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
677 | 1173 |
5275 | 1174 for (octave_idx_type j = 0; j < nsamples; j++) |
4153 | 1175 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
1176 octave_quit (); |
4153 | 1177 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
1178 F77_FUNC (zfftb, ZFFTB) (npts, &tmp_data[npts*j], pwsave); |
4153 | 1179 } |
677 | 1180 |
5275 | 1181 for (octave_idx_type j = 0; j < npts*nsamples; j++) |
3572 | 1182 tmp_data[j] = tmp_data[j] / static_cast<double> (npts); |
677 | 1183 |
1184 npts = nc; | |
1185 nsamples = nr; | |
1186 nn = 4*npts+15; | |
1948 | 1187 |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1188 wsave.resize (dim_vector (nn, 1)); |
1948 | 1189 pwsave = wsave.fortran_vec (); |
1190 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1191 Array<Complex> tmp (dim_vector (npts, 1)); |
4773 | 1192 Complex *prow = tmp.fortran_vec (); |
1948 | 1193 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
1194 F77_FUNC (zffti, ZFFTI) (npts, pwsave); |
677 | 1195 |
5275 | 1196 for (octave_idx_type j = 0; j < nsamples; j++) |
677 | 1197 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
1198 octave_quit (); |
4153 | 1199 |
5275 | 1200 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
|
1201 prow[i] = tmp_data[i*nr + j]; |
1948 | 1202 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7788
diff
changeset
|
1203 F77_FUNC (zfftb, ZFFTB) (npts, prow, pwsave); |
677 | 1204 |
5275 | 1205 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
|
1206 tmp_data[i*nr + j] = prow[i] / static_cast<double> (npts); |
677 | 1207 } |
1208 | |
1948 | 1209 return retval; |
677 | 1210 } |
1211 | |
3827 | 1212 #endif |
1213 | |
458 | 1214 DET |
1215 Matrix::determinant (void) const | |
1216 { | |
5275 | 1217 octave_idx_type info; |
7788 | 1218 double rcon; |
1219 return determinant (info, rcon, 0); | |
458 | 1220 } |
1221 | |
1222 DET | |
5275 | 1223 Matrix::determinant (octave_idx_type& info) const |
458 | 1224 { |
7788 | 1225 double rcon; |
1226 return determinant (info, rcon, 0); | |
458 | 1227 } |
1228 | |
1229 DET | |
7788 | 1230 Matrix::determinant (octave_idx_type& info, double& rcon, int calc_cond) const |
458 | 1231 { |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1232 MatrixType mattype (*this); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1233 return determinant (mattype, info, rcon, calc_cond); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1234 } |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1235 |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1236 DET |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1237 Matrix::determinant (MatrixType& mattype, |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1238 octave_idx_type& info, double& rcon, int calc_cond) const |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1239 { |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1240 DET retval (1.0); |
458 | 1241 |
5275 | 1242 octave_idx_type nr = rows (); |
1243 octave_idx_type nc = cols (); | |
458 | 1244 |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1245 if (nr != nc) |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1246 (*current_liboctave_error_handler) ("matrix must be square"); |
458 | 1247 else |
1248 { | |
8806 | 1249 volatile int typ = mattype.type (); |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1250 |
10213
f7ba6cfe7fb7
fix det() after singular matrix is flagged
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
1251 // Even though the matrix is marked as singular (Rectangular), we may |
f7ba6cfe7fb7
fix det() after singular matrix is flagged
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
1252 // still get a useful number from the LU factorization, because it always |
f7ba6cfe7fb7
fix det() after singular matrix is flagged
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
1253 // completes. |
f7ba6cfe7fb7
fix det() after singular matrix is flagged
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
1254 |
8337
e02242c54c49
reuse matrix type detected in det
Jaroslav Hajek <highegg@gmail.com>
parents:
8336
diff
changeset
|
1255 if (typ == MatrixType::Unknown) |
e02242c54c49
reuse matrix type detected in det
Jaroslav Hajek <highegg@gmail.com>
parents:
8336
diff
changeset
|
1256 typ = mattype.type (*this); |
10213
f7ba6cfe7fb7
fix det() after singular matrix is flagged
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
1257 else if (typ == MatrixType::Rectangular) |
f7ba6cfe7fb7
fix det() after singular matrix is flagged
Jaroslav Hajek <highegg@gmail.com>
parents:
10158
diff
changeset
|
1258 typ = MatrixType::Full; |
8337
e02242c54c49
reuse matrix type detected in det
Jaroslav Hajek <highegg@gmail.com>
parents:
8336
diff
changeset
|
1259 |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1260 if (typ == MatrixType::Lower || typ == MatrixType::Upper) |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1261 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1262 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
|
1263 retval *= elem (i,i); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1264 } |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1265 else if (typ == MatrixType::Hermitian) |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1266 { |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1267 Matrix atmp = *this; |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1268 double *tmp_data = atmp.fortran_vec (); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1269 |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1270 info = 0; |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1271 double anorm = 0; |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1272 if (calc_cond) anorm = xnorm (*this, 1); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1273 |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1274 |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1275 char job = 'L'; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1276 F77_XFCN (dpotrf, DPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr, |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1277 tmp_data, nr, info |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1278 F77_CHAR_ARG_LEN (1))); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1279 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1280 if (info != 0) |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1281 { |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1282 rcon = 0.0; |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1283 mattype.mark_as_unsymmetric (); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1284 typ = MatrixType::Full; |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1285 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1286 else |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1287 { |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1288 Array<double> z (dim_vector (3 * nc, 1)); |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1289 double *pz = z.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1290 Array<octave_idx_type> iz (dim_vector (nc, 1)); |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1291 octave_idx_type *piz = iz.fortran_vec (); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1292 |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1293 F77_XFCN (dpocon, DPOCON, (F77_CONST_CHAR_ARG2 (&job, 1), |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1294 nr, tmp_data, nr, anorm, |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1295 rcon, pz, piz, info |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1296 F77_CHAR_ARG_LEN (1))); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1297 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1298 if (info != 0) |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1299 rcon = 0.0; |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1300 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1301 for (octave_idx_type i = 0; i < nc; i++) |
8337
e02242c54c49
reuse matrix type detected in det
Jaroslav Hajek <highegg@gmail.com>
parents:
8336
diff
changeset
|
1302 retval *= atmp (i,i); |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1303 |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1304 retval = retval.square (); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1305 } |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1306 } |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1307 else if (typ != MatrixType::Full) |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1308 (*current_liboctave_error_handler) ("det: invalid dense matrix type"); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1309 |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1310 if (typ == MatrixType::Full) |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1311 { |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1312 Array<octave_idx_type> ipvt (dim_vector (nr, 1)); |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1313 octave_idx_type *pipvt = ipvt.fortran_vec (); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1314 |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1315 Matrix atmp = *this; |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1316 double *tmp_data = atmp.fortran_vec (); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1317 |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1318 info = 0; |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1319 |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1320 // Calculate the norm of the matrix, for later use. |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1321 double anorm = 0; |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1322 if (calc_cond) anorm = xnorm (*this, 1); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1323 |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1324 F77_XFCN (dgetrf, DGETRF, (nr, nr, tmp_data, nr, pipvt, info)); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1325 |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1326 // Throw-away extra info LAPACK gives so as to not change output. |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1327 rcon = 0.0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1328 if (info != 0) |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1329 { |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1330 info = -1; |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1331 retval = DET (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1332 } |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1333 else |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1334 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1335 if (calc_cond) |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1336 { |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1337 // Now calc the condition number for non-singular matrix. |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1338 char job = '1'; |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1339 Array<double> z (dim_vector (4 * nc, 1)); |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1340 double *pz = z.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1341 Array<octave_idx_type> iz (dim_vector (nc, 1)); |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1342 octave_idx_type *piz = iz.fortran_vec (); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1343 |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1344 F77_XFCN (dgecon, DGECON, (F77_CONST_CHAR_ARG2 (&job, 1), |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1345 nc, tmp_data, nr, anorm, |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1346 rcon, pz, piz, info |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1347 F77_CHAR_ARG_LEN (1))); |
8335 | 1348 } |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1349 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1350 if (info != 0) |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1351 { |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1352 info = -1; |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1353 retval = DET (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1354 } |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1355 else |
8336
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1356 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1357 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
|
1358 { |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1359 double c = atmp(i,i); |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1360 retval *= (ipvt(i) != (i+1)) ? -c : c; |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1361 } |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1362 } |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1363 } |
9813c07ca946
make det take advantage of matrix type
Jaroslav Hajek <highegg@gmail.com>
parents:
8335
diff
changeset
|
1364 } |
458 | 1365 } |
1366 | |
1367 return retval; | |
1368 } | |
1369 | |
7788 | 1370 double |
1371 Matrix::rcond (void) const | |
1372 { | |
1373 MatrixType mattype (*this); | |
1374 return rcond (mattype); | |
1375 } | |
1376 | |
1377 double | |
1378 Matrix::rcond (MatrixType &mattype) const | |
1379 { | |
1380 double rcon; | |
1381 octave_idx_type nr = rows (); | |
1382 octave_idx_type nc = cols (); | |
1383 | |
1384 if (nr != nc) | |
1385 (*current_liboctave_error_handler) ("matrix must be square"); | |
1386 else if (nr == 0 || nc == 0) | |
1387 rcon = octave_Inf; | |
1388 else | |
1389 { | |
1390 int typ = mattype.type (); | |
1391 | |
1392 if (typ == MatrixType::Unknown) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1393 typ = mattype.type (*this); |
7788 | 1394 |
1395 // Only calculate the condition number for LU/Cholesky | |
1396 if (typ == MatrixType::Upper) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1397 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1398 const double *tmp_data = fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1399 octave_idx_type info = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1400 char norm = '1'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1401 char uplo = 'U'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1402 char dia = 'N'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1403 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1404 Array<double> z (dim_vector (3 * nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1405 double *pz = z.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1406 Array<octave_idx_type> iz (dim_vector (nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1407 octave_idx_type *piz = iz.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1408 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1409 F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1410 F77_CONST_CHAR_ARG2 (&uplo, 1), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1411 F77_CONST_CHAR_ARG2 (&dia, 1), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1412 nr, tmp_data, nr, rcon, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1413 pz, piz, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1414 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1415 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1416 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1417 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1418 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1419 rcon = 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1420 } |
7788 | 1421 else if (typ == MatrixType::Permuted_Upper) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1422 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1423 ("permuted triangular matrix not implemented"); |
7788 | 1424 else if (typ == MatrixType::Lower) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1425 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1426 const double *tmp_data = fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1427 octave_idx_type info = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1428 char norm = '1'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1429 char uplo = 'L'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1430 char dia = 'N'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1431 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1432 Array<double> z (dim_vector (3 * nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1433 double *pz = z.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1434 Array<octave_idx_type> iz (dim_vector (nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1435 octave_idx_type *piz = iz.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1436 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1437 F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1438 F77_CONST_CHAR_ARG2 (&uplo, 1), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1439 F77_CONST_CHAR_ARG2 (&dia, 1), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1440 nr, tmp_data, nr, rcon, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1441 pz, piz, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1442 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1443 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1444 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1445 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1446 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1447 rcon = 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1448 } |
7788 | 1449 else if (typ == MatrixType::Permuted_Lower) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1450 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1451 ("permuted triangular matrix not implemented"); |
7788 | 1452 else if (typ == MatrixType::Full || typ == MatrixType::Hermitian) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1453 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1454 double anorm = -1.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1455 Matrix atmp = *this; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1456 double *tmp_data = atmp.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1457 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1458 if (typ == MatrixType::Hermitian) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1459 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1460 octave_idx_type info = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1461 char job = 'L'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1462 anorm = atmp.abs().sum(). |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1463 row(static_cast<octave_idx_type>(0)).max(); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1464 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1465 F77_XFCN (dpotrf, DPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1466 tmp_data, nr, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1467 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1468 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1469 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1470 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1471 rcon = 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1472 mattype.mark_as_unsymmetric (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1473 typ = MatrixType::Full; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1474 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1475 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1476 { |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1477 Array<double> z (dim_vector (3 * nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1478 double *pz = z.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1479 Array<octave_idx_type> iz (dim_vector (nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1480 octave_idx_type *piz = iz.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1481 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1482 F77_XFCN (dpocon, DPOCON, (F77_CONST_CHAR_ARG2 (&job, 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1483 nr, tmp_data, nr, anorm, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1484 rcon, pz, piz, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1485 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1486 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1487 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1488 rcon = 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1489 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1490 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1491 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1492 if (typ == MatrixType::Full) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1493 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1494 octave_idx_type info = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1495 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1496 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
|
1497 octave_idx_type *pipvt = ipvt.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1498 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1499 if(anorm < 0.) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1500 anorm = atmp.abs().sum(). |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1501 row(static_cast<octave_idx_type>(0)).max(); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1502 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1503 Array<double> z (dim_vector (4 * nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1504 double *pz = z.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1505 Array<octave_idx_type> iz (dim_vector (nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1506 octave_idx_type *piz = iz.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1507 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1508 F77_XFCN (dgetrf, DGETRF, (nr, nr, tmp_data, nr, pipvt, info)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1509 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1510 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1511 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1512 rcon = 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1513 mattype.mark_as_rectangular (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1514 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1515 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1516 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1517 char job = '1'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1518 F77_XFCN (dgecon, DGECON, (F77_CONST_CHAR_ARG2 (&job, 1), |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1519 nc, tmp_data, nr, anorm, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1520 rcon, pz, piz, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1521 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1522 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1523 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1524 rcon = 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1525 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1526 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1527 } |
7788 | 1528 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1529 rcon = 0.0; |
7788 | 1530 } |
1531 | |
1532 return rcon; | |
1533 } | |
1534 | |
458 | 1535 Matrix |
5785 | 1536 Matrix::utsolve (MatrixType &mattype, const Matrix& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1537 double& rcon, solve_singularity_handler sing_handler, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1538 bool calc_cond, blas_trans_type transt) const |
5785 | 1539 { |
1540 Matrix retval; | |
1541 | |
1542 octave_idx_type nr = rows (); | |
1543 octave_idx_type nc = cols (); | |
1544 | |
6924 | 1545 if (nr != b.rows ()) |
5785 | 1546 (*current_liboctave_error_handler) |
1547 ("matrix dimension mismatch solution of linear equations"); | |
6924 | 1548 else if (nr == 0 || nc == 0 || b.cols () == 0) |
1549 retval = Matrix (nc, b.cols (), 0.0); | |
5785 | 1550 else |
1551 { | |
1552 volatile int typ = mattype.type (); | |
1553 | |
1554 if (typ == MatrixType::Permuted_Upper || | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1555 typ == MatrixType::Upper) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1556 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1557 octave_idx_type b_nc = b.cols (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1558 rcon = 1.; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1559 info = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1560 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1561 if (typ == MatrixType::Permuted_Upper) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1562 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1563 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1564 ("permuted triangular matrix not implemented"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1565 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1566 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1567 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1568 const double *tmp_data = fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1569 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1570 if (calc_cond) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1571 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1572 char norm = '1'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1573 char uplo = 'U'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1574 char dia = 'N'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1575 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1576 Array<double> z (dim_vector (3 * nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1577 double *pz = z.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1578 Array<octave_idx_type> iz (dim_vector (nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1579 octave_idx_type *piz = iz.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1580 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1581 F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1582 F77_CONST_CHAR_ARG2 (&uplo, 1), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1583 F77_CONST_CHAR_ARG2 (&dia, 1), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1584 nr, tmp_data, nr, rcon, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1585 pz, piz, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1586 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1587 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1588 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1589 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1590 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1591 info = -2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1592 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1593 volatile double rcond_plus_one = rcon + 1.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1594 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1595 if (rcond_plus_one == 1.0 || xisnan (rcon)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1596 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1597 info = -2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1598 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1599 if (sing_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1600 sing_handler (rcon); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1601 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1602 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1603 ("matrix singular to machine precision, rcond = %g", |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1604 rcon); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1605 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1606 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1607 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1608 if (info == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1609 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1610 retval = b; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1611 double *result = retval.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1612 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1613 char uplo = 'U'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1614 char trans = get_blas_char (transt); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1615 char dia = 'N'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1616 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1617 F77_XFCN (dtrtrs, DTRTRS, (F77_CONST_CHAR_ARG2 (&uplo, 1), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1618 F77_CONST_CHAR_ARG2 (&trans, 1), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1619 F77_CONST_CHAR_ARG2 (&dia, 1), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1620 nr, b_nc, tmp_data, nr, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1621 result, nr, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1622 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1623 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1624 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1625 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1626 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1627 } |
5785 | 1628 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1629 (*current_liboctave_error_handler) ("incorrect matrix type"); |
5785 | 1630 } |
1631 | |
1632 return retval; | |
1633 } | |
1634 | |
1635 Matrix | |
1636 Matrix::ltsolve (MatrixType &mattype, const Matrix& b, octave_idx_type& info, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1637 double& rcon, solve_singularity_handler sing_handler, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1638 bool calc_cond, blas_trans_type transt) const |
5785 | 1639 { |
1640 Matrix retval; | |
1641 | |
1642 octave_idx_type nr = rows (); | |
1643 octave_idx_type nc = cols (); | |
1644 | |
6924 | 1645 if (nr != b.rows ()) |
5785 | 1646 (*current_liboctave_error_handler) |
1647 ("matrix dimension mismatch solution of linear equations"); | |
6924 | 1648 else if (nr == 0 || nc == 0 || b.cols () == 0) |
1649 retval = Matrix (nc, b.cols (), 0.0); | |
5785 | 1650 else |
1651 { | |
1652 volatile int typ = mattype.type (); | |
1653 | |
1654 if (typ == MatrixType::Permuted_Lower || | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1655 typ == MatrixType::Lower) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1656 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1657 octave_idx_type b_nc = b.cols (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1658 rcon = 1.; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1659 info = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1660 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1661 if (typ == MatrixType::Permuted_Lower) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1662 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1663 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1664 ("permuted triangular matrix not implemented"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1665 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1666 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1667 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1668 const double *tmp_data = fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1669 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1670 if (calc_cond) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1671 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1672 char norm = '1'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1673 char uplo = 'L'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1674 char dia = 'N'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1675 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1676 Array<double> z (dim_vector (3 * nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1677 double *pz = z.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1678 Array<octave_idx_type> iz (dim_vector (nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1679 octave_idx_type *piz = iz.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1680 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1681 F77_XFCN (dtrcon, DTRCON, (F77_CONST_CHAR_ARG2 (&norm, 1), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1682 F77_CONST_CHAR_ARG2 (&uplo, 1), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1683 F77_CONST_CHAR_ARG2 (&dia, 1), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1684 nr, tmp_data, nr, rcon, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1685 pz, piz, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1686 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1687 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1688 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1689 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1690 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1691 info = -2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1692 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1693 volatile double rcond_plus_one = rcon + 1.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1694 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1695 if (rcond_plus_one == 1.0 || xisnan (rcon)) |
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 info = -2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1698 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1699 if (sing_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1700 sing_handler (rcon); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1701 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1702 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1703 ("matrix singular to machine precision, rcond = %g", |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1704 rcon); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1705 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1706 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1707 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1708 if (info == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1709 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1710 retval = b; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1711 double *result = retval.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1712 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1713 char uplo = 'L'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1714 char trans = get_blas_char (transt); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1715 char dia = 'N'; |
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 F77_XFCN (dtrtrs, DTRTRS, (F77_CONST_CHAR_ARG2 (&uplo, 1), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1718 F77_CONST_CHAR_ARG2 (&trans, 1), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1719 F77_CONST_CHAR_ARG2 (&dia, 1), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1720 nr, b_nc, tmp_data, nr, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1721 result, nr, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1722 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1723 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1724 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1725 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1726 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1727 } |
5785 | 1728 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1729 (*current_liboctave_error_handler) ("incorrect matrix type"); |
5785 | 1730 } |
1731 | |
1732 return retval; | |
1733 } | |
1734 | |
1735 Matrix | |
1736 Matrix::fsolve (MatrixType &mattype, const Matrix& b, octave_idx_type& info, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1737 double& rcon, solve_singularity_handler sing_handler, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1738 bool calc_cond) const |
5785 | 1739 { |
1740 Matrix retval; | |
1741 | |
1742 octave_idx_type nr = rows (); | |
1743 octave_idx_type nc = cols (); | |
1744 | |
6924 | 1745 if (nr != nc || nr != b.rows ()) |
5785 | 1746 (*current_liboctave_error_handler) |
1747 ("matrix dimension mismatch solution of linear equations"); | |
6924 | 1748 else if (nr == 0 || b.cols () == 0) |
1749 retval = Matrix (nc, b.cols (), 0.0); | |
5785 | 1750 else |
1751 { | |
1752 volatile int typ = mattype.type (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1753 |
5785 | 1754 // Calculate the norm of the matrix, for later use. |
1755 double anorm = -1.; | |
1756 | |
1757 if (typ == MatrixType::Hermitian) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1758 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1759 info = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1760 char job = 'L'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1761 Matrix atmp = *this; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1762 double *tmp_data = atmp.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1763 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
|
1764 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1765 F77_XFCN (dpotrf, DPOTRF, (F77_CONST_CHAR_ARG2 (&job, 1), nr, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1766 tmp_data, nr, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1767 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1768 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1769 // 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
|
1770 rcon = 0.0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1771 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1772 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1773 info = -2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1774 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1775 mattype.mark_as_unsymmetric (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1776 typ = MatrixType::Full; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1777 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1778 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1779 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1780 if (calc_cond) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1781 { |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1782 Array<double> z (dim_vector (3 * nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1783 double *pz = z.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1784 Array<octave_idx_type> iz (dim_vector (nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1785 octave_idx_type *piz = iz.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1786 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1787 F77_XFCN (dpocon, DPOCON, (F77_CONST_CHAR_ARG2 (&job, 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1788 nr, tmp_data, nr, anorm, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1789 rcon, pz, piz, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1790 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1791 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1792 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1793 info = -2; |
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 volatile double rcond_plus_one = rcon + 1.0; |
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 if (rcond_plus_one == 1.0 || xisnan (rcon)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1798 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1799 info = -2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1800 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1801 if (sing_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1802 sing_handler (rcon); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1803 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1804 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1805 ("matrix singular to machine precision, rcond = %g", |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1806 rcon); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1807 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1808 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1809 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1810 if (info == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1811 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1812 retval = b; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1813 double *result = retval.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1814 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1815 octave_idx_type b_nc = b.cols (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1816 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1817 F77_XFCN (dpotrs, DPOTRS, (F77_CONST_CHAR_ARG2 (&job, 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1818 nr, b_nc, tmp_data, nr, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1819 result, b.rows(), info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1820 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1821 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1822 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1823 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1824 mattype.mark_as_unsymmetric (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1825 typ = MatrixType::Full; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1826 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1827 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1828 } |
5785 | 1829 |
1830 if (typ == MatrixType::Full) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1831 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1832 info = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1833 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1834 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
|
1835 octave_idx_type *pipvt = ipvt.fortran_vec (); |
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 Matrix atmp = *this; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1838 double *tmp_data = atmp.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1839 if(anorm < 0.) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1840 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
|
1841 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1842 Array<double> z (dim_vector (4 * nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1843 double *pz = z.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1844 Array<octave_idx_type> iz (dim_vector (nc, 1)); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1845 octave_idx_type *piz = iz.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1846 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1847 F77_XFCN (dgetrf, DGETRF, (nr, nr, tmp_data, nr, pipvt, info)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1848 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1849 // 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
|
1850 rcon = 0.0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1851 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1852 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1853 info = -2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1854 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1855 if (sing_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1856 sing_handler (rcon); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1857 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1858 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1859 ("matrix singular to machine precision"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1860 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1861 mattype.mark_as_rectangular (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1862 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1863 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1864 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1865 if (calc_cond) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1866 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1867 // Now calculate the condition number for |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1868 // non-singular matrix. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1869 char job = '1'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1870 F77_XFCN (dgecon, DGECON, (F77_CONST_CHAR_ARG2 (&job, 1), |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1871 nc, tmp_data, nr, anorm, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1872 rcon, pz, piz, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1873 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1874 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1875 if (info != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1876 info = -2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1877 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1878 volatile double rcond_plus_one = rcon + 1.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1879 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1880 if (rcond_plus_one == 1.0 || xisnan (rcon)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1881 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1882 info = -2; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1883 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1884 if (sing_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1885 sing_handler (rcon); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1886 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1887 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1888 ("matrix singular to machine precision, rcond = %g", |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1889 rcon); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1890 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1891 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1892 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1893 if (info == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1894 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1895 retval = b; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1896 double *result = retval.fortran_vec (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1897 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1898 octave_idx_type b_nc = b.cols (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1899 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1900 char job = 'N'; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1901 F77_XFCN (dgetrs, DGETRS, (F77_CONST_CHAR_ARG2 (&job, 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1902 nr, b_nc, tmp_data, nr, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1903 pipvt, result, b.rows(), info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1904 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1905 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1906 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1907 mattype.mark_as_rectangular (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1908 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1909 } |
5785 | 1910 else if (typ != MatrixType::Hermitian) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1911 (*current_liboctave_error_handler) ("incorrect matrix type"); |
5785 | 1912 } |
1913 | |
1914 return retval; | |
1915 } | |
1916 | |
1917 Matrix | |
1918 Matrix::solve (MatrixType &typ, const Matrix& b) const | |
1919 { | |
1920 octave_idx_type info; | |
7788 | 1921 double rcon; |
1922 return solve (typ, b, info, rcon, 0); | |
5785 | 1923 } |
1924 | |
1925 Matrix | |
9662
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1926 Matrix::solve (MatrixType &typ, const Matrix& b, octave_idx_type& info) const |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1927 { |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1928 double rcon; |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1929 return solve (typ, b, info, rcon, 0); |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1930 } |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1931 |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1932 Matrix |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1933 Matrix::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
|
1934 double& rcon) const |
5785 | 1935 { |
7788 | 1936 return solve (typ, b, info, rcon, 0); |
5785 | 1937 } |
1938 | |
1939 Matrix | |
1940 Matrix::solve (MatrixType &mattype, const Matrix& b, octave_idx_type& info, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1941 double& rcon, solve_singularity_handler sing_handler, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1942 bool singular_fallback, blas_trans_type transt) const |
5785 | 1943 { |
1944 Matrix retval; | |
1945 int typ = mattype.type (); | |
1946 | |
1947 if (typ == MatrixType::Unknown) | |
1948 typ = mattype.type (*this); | |
1949 | |
1950 // Only calculate the condition number for LU/Cholesky | |
1951 if (typ == MatrixType::Upper || typ == MatrixType::Permuted_Upper) | |
9661
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9658
diff
changeset
|
1952 retval = utsolve (mattype, b, info, rcon, sing_handler, false, transt); |
5785 | 1953 else if (typ == MatrixType::Lower || typ == MatrixType::Permuted_Lower) |
9661
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9658
diff
changeset
|
1954 retval = ltsolve (mattype, b, info, rcon, sing_handler, false, transt); |
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9658
diff
changeset
|
1955 else if (transt == blas_trans || transt == blas_conj_trans) |
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9658
diff
changeset
|
1956 return transpose ().solve (mattype, b, info, rcon, sing_handler, singular_fallback); |
5785 | 1957 else if (typ == MatrixType::Full || typ == MatrixType::Hermitian) |
7788 | 1958 retval = fsolve (mattype, b, info, rcon, sing_handler, true); |
5785 | 1959 else if (typ != MatrixType::Rectangular) |
1960 { | |
1961 (*current_liboctave_error_handler) ("unknown matrix type"); | |
1962 return Matrix (); | |
1963 } | |
1964 | |
1965 // Rectangular or one of the above solvers flags a singular matrix | |
1966 if (singular_fallback && mattype.type () == MatrixType::Rectangular) | |
1967 { | |
1968 octave_idx_type rank; | |
7788 | 1969 retval = lssolve (b, info, rank, rcon); |
5785 | 1970 } |
1971 | |
1972 return retval; | |
1973 } | |
1974 | |
1975 ComplexMatrix | |
1976 Matrix::solve (MatrixType &typ, const ComplexMatrix& b) const | |
1977 { | |
9662
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1978 octave_idx_type info; |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1979 double rcon; |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1980 return solve (typ, b, info, rcon, 0); |
5785 | 1981 } |
1982 | |
1983 ComplexMatrix | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
1984 Matrix::solve (MatrixType &typ, const ComplexMatrix& b, |
5785 | 1985 octave_idx_type& info) const |
1986 { | |
9662
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1987 double rcon; |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1988 return solve (typ, b, info, rcon, 0); |
5785 | 1989 } |
1990 | |
1991 ComplexMatrix | |
1992 Matrix::solve (MatrixType &typ, const ComplexMatrix& b, octave_idx_type& info, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
1993 double& rcon) const |
5785 | 1994 { |
9662
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1995 return solve (typ, b, info, rcon, 0); |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1996 } |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1997 |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1998 static Matrix |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
1999 stack_complex_matrix (const ComplexMatrix& cm) |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2000 { |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2001 octave_idx_type m = cm.rows (), n = cm.cols (), nel = m*n; |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2002 Matrix retval (m, 2*n); |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2003 const Complex *cmd = cm.data (); |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2004 double *rd = retval.fortran_vec (); |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2005 for (octave_idx_type i = 0; i < nel; i++) |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2006 { |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2007 rd[i] = std::real (cmd[i]); |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2008 rd[nel+i] = std::imag (cmd[i]); |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2009 } |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2010 return retval; |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2011 } |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2012 |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2013 static ComplexMatrix |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2014 unstack_complex_matrix (const Matrix& sm) |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2015 { |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2016 octave_idx_type m = sm.rows (), n = sm.cols () / 2, nel = m*n; |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2017 ComplexMatrix retval (m, n); |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2018 const double *smd = sm.data (); |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2019 Complex *rd = retval.fortran_vec (); |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2020 for (octave_idx_type i = 0; i < nel; i++) |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2021 rd[i] = Complex (smd[i], smd[nel+i]); |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2022 return retval; |
5785 | 2023 } |
2024 | |
2025 ComplexMatrix | |
2026 Matrix::solve (MatrixType &typ, const ComplexMatrix& b, octave_idx_type& info, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2027 double& rcon, solve_singularity_handler sing_handler, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2028 bool singular_fallback, blas_trans_type transt) const |
5785 | 2029 { |
9662
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2030 Matrix tmp = stack_complex_matrix (b); |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2031 tmp = solve (typ, tmp, info, rcon, sing_handler, singular_fallback, transt); |
0d3b248f4ab6
further improve mixed real-complex division
Jaroslav Hajek <highegg@gmail.com>
parents:
9661
diff
changeset
|
2032 return unstack_complex_matrix (tmp); |
5785 | 2033 } |
2034 | |
2035 ColumnVector | |
2036 Matrix::solve (MatrixType &typ, const ColumnVector& b) const | |
2037 { | |
7788 | 2038 octave_idx_type info; double rcon; |
2039 return solve (typ, b, info, rcon); | |
5785 | 2040 } |
2041 | |
2042 ColumnVector | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2043 Matrix::solve (MatrixType &typ, const ColumnVector& b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2044 octave_idx_type& info) const |
5785 | 2045 { |
7788 | 2046 double rcon; |
2047 return solve (typ, b, info, rcon); | |
5785 | 2048 } |
2049 | |
2050 ColumnVector | |
2051 Matrix::solve (MatrixType &typ, const ColumnVector& b, octave_idx_type& info, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2052 double& rcon) const |
5785 | 2053 { |
7788 | 2054 return solve (typ, b, info, rcon, 0); |
5785 | 2055 } |
2056 | |
2057 ColumnVector | |
2058 Matrix::solve (MatrixType &typ, const ColumnVector& b, octave_idx_type& info, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2059 double& rcon, solve_singularity_handler sing_handler, blas_trans_type transt) const |
5785 | 2060 { |
2061 Matrix tmp (b); | |
10352 | 2062 tmp = solve (typ, tmp, info, rcon, sing_handler, true, transt); |
2063 return tmp.column(static_cast<octave_idx_type> (0)); | |
5785 | 2064 } |
2065 | |
2066 ComplexColumnVector | |
2067 Matrix::solve (MatrixType &typ, const ComplexColumnVector& b) const | |
2068 { | |
2069 ComplexMatrix tmp (*this); | |
2070 return tmp.solve (typ, b); | |
2071 } | |
2072 | |
2073 ComplexColumnVector | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2074 Matrix::solve (MatrixType &typ, const ComplexColumnVector& b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2075 octave_idx_type& info) const |
5785 | 2076 { |
2077 ComplexMatrix tmp (*this); | |
2078 return tmp.solve (typ, b, info); | |
2079 } | |
2080 | |
2081 ComplexColumnVector | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2082 Matrix::solve (MatrixType &typ, const ComplexColumnVector& b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2083 octave_idx_type& info, double& rcon) const |
5785 | 2084 { |
2085 ComplexMatrix tmp (*this); | |
7788 | 2086 return tmp.solve (typ, b, info, rcon); |
5785 | 2087 } |
2088 | |
2089 ComplexColumnVector | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2090 Matrix::solve (MatrixType &typ, const ComplexColumnVector& b, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2091 octave_idx_type& info, double& rcon, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2092 solve_singularity_handler sing_handler, blas_trans_type transt) const |
5785 | 2093 { |
2094 ComplexMatrix tmp (*this); | |
9661
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9658
diff
changeset
|
2095 return tmp.solve(typ, b, info, rcon, sing_handler, transt); |
5785 | 2096 } |
2097 | |
2098 Matrix | |
458 | 2099 Matrix::solve (const Matrix& b) const |
2100 { | |
5275 | 2101 octave_idx_type info; |
7788 | 2102 double rcon; |
2103 return solve (b, info, rcon, 0); | |
458 | 2104 } |
2105 | |
2106 Matrix | |
5275 | 2107 Matrix::solve (const Matrix& b, octave_idx_type& info) const |
458 | 2108 { |
7788 | 2109 double rcon; |
2110 return solve (b, info, rcon, 0); | |
458 | 2111 } |
2112 | |
2113 Matrix | |
7788 | 2114 Matrix::solve (const Matrix& b, octave_idx_type& info, double& rcon) const |
458 | 2115 { |
7788 | 2116 return solve (b, info, rcon, 0); |
3480 | 2117 } |
2118 | |
2119 Matrix | |
5785 | 2120 Matrix::solve (const Matrix& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2121 double& rcon, solve_singularity_handler sing_handler, blas_trans_type transt) const |
3480 | 2122 { |
5785 | 2123 MatrixType mattype (*this); |
9661
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9658
diff
changeset
|
2124 return solve (mattype, b, info, rcon, sing_handler, true, transt); |
458 | 2125 } |
2126 | |
2127 ComplexMatrix | |
2128 Matrix::solve (const ComplexMatrix& b) const | |
2129 { | |
2130 ComplexMatrix tmp (*this); | |
2131 return tmp.solve (b); | |
2132 } | |
2133 | |
2134 ComplexMatrix | |
5275 | 2135 Matrix::solve (const ComplexMatrix& b, octave_idx_type& info) const |
458 | 2136 { |
2137 ComplexMatrix tmp (*this); | |
2138 return tmp.solve (b, info); | |
2139 } | |
2140 | |
2141 ComplexMatrix | |
7788 | 2142 Matrix::solve (const ComplexMatrix& b, octave_idx_type& info, double& rcon) const |
458 | 2143 { |
2144 ComplexMatrix tmp (*this); | |
7788 | 2145 return tmp.solve (b, info, rcon); |
458 | 2146 } |
2147 | |
3480 | 2148 ComplexMatrix |
7788 | 2149 Matrix::solve (const ComplexMatrix& b, octave_idx_type& info, double& rcon, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2150 solve_singularity_handler sing_handler, blas_trans_type transt) const |
3480 | 2151 { |
2152 ComplexMatrix tmp (*this); | |
9661
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9658
diff
changeset
|
2153 return tmp.solve (b, info, rcon, sing_handler, transt); |
3480 | 2154 } |
2155 | |
458 | 2156 ColumnVector |
2157 Matrix::solve (const ColumnVector& b) const | |
2158 { | |
7788 | 2159 octave_idx_type info; double rcon; |
2160 return solve (b, info, rcon); | |
458 | 2161 } |
2162 | |
2163 ColumnVector | |
5275 | 2164 Matrix::solve (const ColumnVector& b, octave_idx_type& info) const |
458 | 2165 { |
7788 | 2166 double rcon; |
2167 return solve (b, info, rcon); | |
458 | 2168 } |
2169 | |
2170 ColumnVector | |
7788 | 2171 Matrix::solve (const ColumnVector& b, octave_idx_type& info, double& rcon) const |
458 | 2172 { |
7788 | 2173 return solve (b, info, rcon, 0); |
3480 | 2174 } |
2175 | |
2176 ColumnVector | |
7788 | 2177 Matrix::solve (const ColumnVector& b, octave_idx_type& info, double& rcon, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2178 solve_singularity_handler sing_handler, blas_trans_type transt) const |
3480 | 2179 { |
5785 | 2180 MatrixType mattype (*this); |
9661
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9658
diff
changeset
|
2181 return solve (mattype, b, info, rcon, sing_handler, transt); |
458 | 2182 } |
2183 | |
2184 ComplexColumnVector | |
2185 Matrix::solve (const ComplexColumnVector& b) const | |
2186 { | |
2187 ComplexMatrix tmp (*this); | |
2188 return tmp.solve (b); | |
2189 } | |
2190 | |
2191 ComplexColumnVector | |
5275 | 2192 Matrix::solve (const ComplexColumnVector& b, octave_idx_type& info) const |
458 | 2193 { |
2194 ComplexMatrix tmp (*this); | |
2195 return tmp.solve (b, info); | |
2196 } | |
2197 | |
2198 ComplexColumnVector | |
7788 | 2199 Matrix::solve (const ComplexColumnVector& b, octave_idx_type& info, double& rcon) const |
458 | 2200 { |
2201 ComplexMatrix tmp (*this); | |
7788 | 2202 return tmp.solve (b, info, rcon); |
458 | 2203 } |
2204 | |
3480 | 2205 ComplexColumnVector |
7788 | 2206 Matrix::solve (const ComplexColumnVector& b, octave_idx_type& info, double& rcon, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2207 solve_singularity_handler sing_handler, blas_trans_type transt) const |
3480 | 2208 { |
2209 ComplexMatrix tmp (*this); | |
9661
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9658
diff
changeset
|
2210 return tmp.solve (b, info, rcon, sing_handler, transt); |
3480 | 2211 } |
2212 | |
458 | 2213 Matrix |
2214 Matrix::lssolve (const Matrix& b) const | |
2215 { | |
5275 | 2216 octave_idx_type info; |
2217 octave_idx_type rank; | |
7788 | 2218 double rcon; |
2219 return lssolve (b, info, rank, rcon); | |
458 | 2220 } |
2221 | |
2222 Matrix | |
5275 | 2223 Matrix::lssolve (const Matrix& b, octave_idx_type& info) const |
458 | 2224 { |
5275 | 2225 octave_idx_type rank; |
7788 | 2226 double rcon; |
2227 return lssolve (b, info, rank, rcon); | |
458 | 2228 } |
2229 | |
2230 Matrix | |
7072 | 2231 Matrix::lssolve (const Matrix& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2232 octave_idx_type& rank) const |
458 | 2233 { |
7788 | 2234 double rcon; |
2235 return lssolve (b, info, rank, rcon); | |
7076 | 2236 } |
2237 | |
2238 Matrix | |
2239 Matrix::lssolve (const Matrix& b, octave_idx_type& info, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2240 octave_idx_type& rank, double &rcon) const |
7076 | 2241 { |
1948 | 2242 Matrix retval; |
2243 | |
5275 | 2244 octave_idx_type nrhs = b.cols (); |
2245 | |
2246 octave_idx_type m = rows (); | |
2247 octave_idx_type n = cols (); | |
458 | 2248 |
6924 | 2249 if (m != b.rows ()) |
1948 | 2250 (*current_liboctave_error_handler) |
6924 | 2251 ("matrix dimension mismatch solution of linear equations"); |
2252 else if (m == 0 || n == 0 || b.cols () == 0) | |
2253 retval = Matrix (n, b.cols (), 0.0); | |
1948 | 2254 else |
458 | 2255 { |
7072 | 2256 volatile octave_idx_type minmn = (m < n ? m : n); |
2257 octave_idx_type maxmn = m > n ? m : n; | |
7788 | 2258 rcon = -1.0; |
7072 | 2259 if (m != n) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2260 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2261 retval = Matrix (maxmn, nrhs, 0.0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2262 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2263 for (octave_idx_type j = 0; j < nrhs; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2264 for (octave_idx_type i = 0; i < m; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2265 retval.elem (i, j) = b.elem (i, j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2266 } |
7072 | 2267 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2268 retval = b; |
7072 | 2269 |
1948 | 2270 Matrix atmp = *this; |
2271 double *tmp_data = atmp.fortran_vec (); | |
2272 | |
7072 | 2273 double *pretval = retval.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2274 Array<double> s (dim_vector (minmn, 1)); |
7071 | 2275 double *ps = s.fortran_vec (); |
1948 | 2276 |
7072 | 2277 // Ask DGELSD what the dimension of WORK should be. |
5275 | 2278 octave_idx_type lwork = -1; |
3752 | 2279 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2280 Array<double> work (dim_vector (1, 1)); |
1948 | 2281 |
7477 | 2282 octave_idx_type smlsiz; |
2283 F77_FUNC (xilaenv, XILAENV) (9, F77_CONST_CHAR_ARG2 ("DGELSD", 6), | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2284 F77_CONST_CHAR_ARG2 (" ", 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2285 0, 0, 0, 0, smlsiz |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2286 F77_CHAR_ARG_LEN (6) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2287 F77_CHAR_ARG_LEN (1)); |
7079 | 2288 |
7486
6a6d2abe51ff
more xGELSD workspace fixes
John W. Eaton <jwe@octave.org>
parents:
7482
diff
changeset
|
2289 octave_idx_type mnthr; |
6a6d2abe51ff
more xGELSD workspace fixes
John W. Eaton <jwe@octave.org>
parents:
7482
diff
changeset
|
2290 F77_FUNC (xilaenv, XILAENV) (6, F77_CONST_CHAR_ARG2 ("DGELSD", 6), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2291 F77_CONST_CHAR_ARG2 (" ", 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2292 m, n, nrhs, -1, mnthr |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2293 F77_CHAR_ARG_LEN (6) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2294 F77_CHAR_ARG_LEN (1)); |
7486
6a6d2abe51ff
more xGELSD workspace fixes
John W. Eaton <jwe@octave.org>
parents:
7482
diff
changeset
|
2295 |
7079 | 2296 // We compute the size of iwork because DGELSD in older versions |
2297 // of LAPACK does not return it on a query call. | |
7124 | 2298 double dminmn = static_cast<double> (minmn); |
2299 double dsmlsizp1 = static_cast<double> (smlsiz+1); | |
7079 | 2300 #if defined (HAVE_LOG2) |
7367 | 2301 double tmp = log2 (dminmn / dsmlsizp1); |
7079 | 2302 #else |
7367 | 2303 double tmp = log (dminmn / dsmlsizp1) / log (2.0); |
7079 | 2304 #endif |
7544
f9983d2761df
more xGELSD workspace fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
7532
diff
changeset
|
2305 octave_idx_type nlvl = static_cast<octave_idx_type> (tmp) + 1; |
7079 | 2306 if (nlvl < 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2307 nlvl = 0; |
7079 | 2308 |
2309 octave_idx_type liwork = 3 * minmn * nlvl + 11 * minmn; | |
2310 if (liwork < 1) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2311 liwork = 1; |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2312 Array<octave_idx_type> iwork (dim_vector (liwork, 1)); |
7072 | 2313 octave_idx_type* piwork = iwork.fortran_vec (); |
2314 | |
2315 F77_XFCN (dgelsd, DGELSD, (m, n, nrhs, tmp_data, m, pretval, maxmn, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2316 ps, rcon, rank, work.fortran_vec (), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2317 lwork, piwork, info)); |
1948 | 2318 |
7476 | 2319 // 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
|
2320 // through 3.1.1 when n >= mnthr. The obtuse formula below |
7476 | 2321 // should provide sufficient workspace for DGELSD to operate |
2322 // efficiently. | |
10813
2c2d4a2f1047
fix workspace bug workaround for xGELSD (since 7486:6a6d2abe51ff)
Jaroslav Hajek <highegg@gmail.com>
parents:
10806
diff
changeset
|
2323 if (n > m && n >= mnthr) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2324 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2325 const octave_idx_type wlalsd |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2326 = 9*m + 2*m*smlsiz + 8*m*nlvl + m*nrhs + (smlsiz+1)*(smlsiz+1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2327 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2328 octave_idx_type addend = m; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2329 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2330 if (2*m-4 > addend) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2331 addend = 2*m-4; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2332 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2333 if (nrhs > addend) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2334 addend = nrhs; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2335 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2336 if (n-3*m > addend) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2337 addend = n-3*m; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2338 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2339 if (wlalsd > addend) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2340 addend = wlalsd; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2341 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2342 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
|
2343 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2344 if (work(0) < lworkaround) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2345 work(0) = lworkaround; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2346 } |
7532
493bb0de3199
avoid another xGELSD workspace query bug
John W. Eaton <jwe@octave.org>
parents:
7503
diff
changeset
|
2347 else if (m >= n) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2348 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2349 octave_idx_type lworkaround |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2350 = 12*n + 2*n*smlsiz + 8*n*nlvl + n*nrhs + (smlsiz+1)*(smlsiz+1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2351 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2352 if (work(0) < lworkaround) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2353 work(0) = lworkaround; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2354 } |
7476 | 2355 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2356 lwork = static_cast<octave_idx_type> (work(0)); |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2357 work.resize (dim_vector (lwork, 1)); |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2358 |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2359 F77_XFCN (dgelsd, DGELSD, (m, n, nrhs, tmp_data, m, pretval, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2360 maxmn, ps, rcon, rank, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2361 work.fortran_vec (), lwork, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2362 piwork, info)); |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2363 |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2364 if (s.elem (0) == 0.0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2365 rcon = 0.0; |
1948 | 2366 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2367 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
|
2368 |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2369 retval.resize (n, nrhs); |
458 | 2370 } |
2371 | |
2372 return retval; | |
2373 } | |
2374 | |
2375 ComplexMatrix | |
2376 Matrix::lssolve (const ComplexMatrix& b) const | |
2377 { | |
2378 ComplexMatrix tmp (*this); | |
5275 | 2379 octave_idx_type info; |
2380 octave_idx_type rank; | |
7788 | 2381 double rcon; |
2382 return tmp.lssolve (b, info, rank, rcon); | |
458 | 2383 } |
2384 | |
2385 ComplexMatrix | |
5275 | 2386 Matrix::lssolve (const ComplexMatrix& b, octave_idx_type& info) const |
458 | 2387 { |
2388 ComplexMatrix tmp (*this); | |
5275 | 2389 octave_idx_type rank; |
7788 | 2390 double rcon; |
2391 return tmp.lssolve (b, info, rank, rcon); | |
458 | 2392 } |
2393 | |
2394 ComplexMatrix | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2395 Matrix::lssolve (const ComplexMatrix& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2396 octave_idx_type& rank) const |
458 | 2397 { |
2398 ComplexMatrix tmp (*this); | |
7788 | 2399 double rcon; |
2400 return tmp.lssolve (b, info, rank, rcon); | |
7076 | 2401 } |
2402 | |
2403 ComplexMatrix | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2404 Matrix::lssolve (const ComplexMatrix& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2405 octave_idx_type& rank, double& rcon) const |
7076 | 2406 { |
2407 ComplexMatrix tmp (*this); | |
7788 | 2408 return tmp.lssolve (b, info, rank, rcon); |
458 | 2409 } |
2410 | |
2411 ColumnVector | |
2412 Matrix::lssolve (const ColumnVector& b) const | |
2413 { | |
5275 | 2414 octave_idx_type info; |
2415 octave_idx_type rank; | |
7788 | 2416 double rcon; |
2417 return lssolve (b, info, rank, rcon); | |
458 | 2418 } |
2419 | |
2420 ColumnVector | |
5275 | 2421 Matrix::lssolve (const ColumnVector& b, octave_idx_type& info) const |
458 | 2422 { |
5275 | 2423 octave_idx_type rank; |
7788 | 2424 double rcon; |
2425 return lssolve (b, info, rank, rcon); | |
458 | 2426 } |
2427 | |
2428 ColumnVector | |
7072 | 2429 Matrix::lssolve (const ColumnVector& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2430 octave_idx_type& rank) const |
458 | 2431 { |
7788 | 2432 double rcon; |
2433 return lssolve (b, info, rank, rcon); | |
7076 | 2434 } |
2435 | |
2436 ColumnVector | |
2437 Matrix::lssolve (const ColumnVector& b, octave_idx_type& info, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2438 octave_idx_type& rank, double &rcon) const |
7076 | 2439 { |
1948 | 2440 ColumnVector retval; |
2441 | |
5275 | 2442 octave_idx_type nrhs = 1; |
2443 | |
2444 octave_idx_type m = rows (); | |
2445 octave_idx_type n = cols (); | |
458 | 2446 |
6924 | 2447 if (m != b.length ()) |
1948 | 2448 (*current_liboctave_error_handler) |
6924 | 2449 ("matrix dimension mismatch solution of linear equations"); |
2450 else if (m == 0 || n == 0) | |
2451 retval = ColumnVector (n, 0.0); | |
1948 | 2452 else |
458 | 2453 { |
7072 | 2454 volatile octave_idx_type minmn = (m < n ? m : n); |
2455 octave_idx_type maxmn = m > n ? m : n; | |
7788 | 2456 rcon = -1.0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2457 |
7072 | 2458 if (m != n) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2459 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2460 retval = ColumnVector (maxmn, 0.0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2461 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2462 for (octave_idx_type i = 0; i < m; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2463 retval.elem (i) = b.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2464 } |
7072 | 2465 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2466 retval = b; |
7072 | 2467 |
1948 | 2468 Matrix atmp = *this; |
2469 double *tmp_data = atmp.fortran_vec (); | |
2470 | |
7072 | 2471 double *pretval = retval.fortran_vec (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2472 Array<double> s (dim_vector (minmn, 1)); |
7071 | 2473 double *ps = s.fortran_vec (); |
1948 | 2474 |
7072 | 2475 // Ask DGELSD what the dimension of WORK should be. |
5275 | 2476 octave_idx_type lwork = -1; |
3752 | 2477 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2478 Array<double> work (dim_vector (1, 1)); |
3752 | 2479 |
7544
f9983d2761df
more xGELSD workspace fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
7532
diff
changeset
|
2480 octave_idx_type smlsiz; |
f9983d2761df
more xGELSD workspace fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
7532
diff
changeset
|
2481 F77_FUNC (xilaenv, XILAENV) (9, F77_CONST_CHAR_ARG2 ("DGELSD", 6), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2482 F77_CONST_CHAR_ARG2 (" ", 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2483 0, 0, 0, 0, smlsiz |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2484 F77_CHAR_ARG_LEN (6) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2485 F77_CHAR_ARG_LEN (1)); |
7079 | 2486 |
2487 // We compute the size of iwork because DGELSD in older versions | |
2488 // of LAPACK does not return it on a query call. | |
7124 | 2489 double dminmn = static_cast<double> (minmn); |
2490 double dsmlsizp1 = static_cast<double> (smlsiz+1); | |
7079 | 2491 #if defined (HAVE_LOG2) |
7544
f9983d2761df
more xGELSD workspace fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
7532
diff
changeset
|
2492 double tmp = log2 (dminmn / dsmlsizp1); |
7079 | 2493 #else |
7544
f9983d2761df
more xGELSD workspace fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
7532
diff
changeset
|
2494 double tmp = log (dminmn / dsmlsizp1) / log (2.0); |
7079 | 2495 #endif |
7544
f9983d2761df
more xGELSD workspace fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
7532
diff
changeset
|
2496 octave_idx_type nlvl = static_cast<octave_idx_type> (tmp) + 1; |
7079 | 2497 if (nlvl < 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2498 nlvl = 0; |
7079 | 2499 |
2500 octave_idx_type liwork = 3 * minmn * nlvl + 11 * minmn; | |
2501 if (liwork < 1) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2502 liwork = 1; |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2503 Array<octave_idx_type> iwork (dim_vector (liwork, 1)); |
7072 | 2504 octave_idx_type* piwork = iwork.fortran_vec (); |
2505 | |
2506 F77_XFCN (dgelsd, DGELSD, (m, n, nrhs, tmp_data, m, pretval, maxmn, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2507 ps, rcon, rank, work.fortran_vec (), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2508 lwork, piwork, info)); |
1948 | 2509 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2510 lwork = static_cast<octave_idx_type> (work(0)); |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2511 work.resize (dim_vector (lwork, 1)); |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2512 |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2513 F77_XFCN (dgelsd, DGELSD, (m, n, nrhs, tmp_data, m, pretval, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2514 maxmn, ps, rcon, rank, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2515 work.fortran_vec (), lwork, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2516 piwork, info)); |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2517 |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2518 if (rank < minmn) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2519 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2520 if (s.elem (0) == 0.0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2521 rcon = 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2522 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2523 rcon = s.elem (minmn - 1) / s.elem (0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2524 } |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2525 |
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
2526 retval.resize (n, nrhs); |
458 | 2527 } |
2528 | |
2529 return retval; | |
2530 } | |
2531 | |
2532 ComplexColumnVector | |
2533 Matrix::lssolve (const ComplexColumnVector& b) const | |
2534 { | |
2535 ComplexMatrix tmp (*this); | |
7076 | 2536 octave_idx_type info; |
2537 octave_idx_type rank; | |
7788 | 2538 double rcon; |
2539 return tmp.lssolve (b, info, rank, rcon); | |
458 | 2540 } |
2541 | |
2542 ComplexColumnVector | |
5275 | 2543 Matrix::lssolve (const ComplexColumnVector& b, octave_idx_type& info) const |
458 | 2544 { |
2545 ComplexMatrix tmp (*this); | |
7076 | 2546 octave_idx_type rank; |
7788 | 2547 double rcon; |
2548 return tmp.lssolve (b, info, rank, rcon); | |
458 | 2549 } |
2550 | |
2551 ComplexColumnVector | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2552 Matrix::lssolve (const ComplexColumnVector& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2553 octave_idx_type& rank) const |
458 | 2554 { |
2555 ComplexMatrix tmp (*this); | |
7788 | 2556 double rcon; |
2557 return tmp.lssolve (b, info, rank, rcon); | |
7076 | 2558 } |
2559 | |
2560 ComplexColumnVector | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2561 Matrix::lssolve (const ComplexColumnVector& b, octave_idx_type& info, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2562 octave_idx_type& rank, double &rcon) const |
7076 | 2563 { |
2564 ComplexMatrix tmp (*this); | |
7788 | 2565 return tmp.lssolve (b, info, rank, rcon); |
458 | 2566 } |
2567 | |
2568 Matrix& | |
2569 Matrix::operator += (const DiagMatrix& a) | |
2570 { | |
5275 | 2571 octave_idx_type nr = rows (); |
2572 octave_idx_type nc = cols (); | |
2573 | |
2574 octave_idx_type a_nr = a.rows (); | |
2575 octave_idx_type a_nc = a.cols (); | |
2385 | 2576 |
2577 if (nr != a_nr || nc != a_nc) | |
458 | 2578 { |
2385 | 2579 gripe_nonconformant ("operator +=", nr, nc, a_nr, a_nc); |
458 | 2580 return *this; |
2581 } | |
2582 | |
5275 | 2583 for (octave_idx_type i = 0; i < a.length (); i++) |
458 | 2584 elem (i, i) += a.elem (i, i); |
2585 | |
2586 return *this; | |
2587 } | |
2588 | |
2589 Matrix& | |
2590 Matrix::operator -= (const DiagMatrix& a) | |
2591 { | |
5275 | 2592 octave_idx_type nr = rows (); |
2593 octave_idx_type nc = cols (); | |
2594 | |
2595 octave_idx_type a_nr = a.rows (); | |
2596 octave_idx_type a_nc = a.cols (); | |
2385 | 2597 |
2598 if (nr != a_nr || nc != a_nc) | |
458 | 2599 { |
2385 | 2600 gripe_nonconformant ("operator -=", nr, nc, a_nr, a_nc); |
458 | 2601 return *this; |
2602 } | |
2603 | |
5275 | 2604 for (octave_idx_type i = 0; i < a.length (); i++) |
458 | 2605 elem (i, i) -= a.elem (i, i); |
2606 | |
2607 return *this; | |
2608 } | |
2609 | |
2610 // unary operations | |
2611 | |
2964 | 2612 boolMatrix |
458 | 2613 Matrix::operator ! (void) const |
2614 { | |
11130
7c573eb981eb
consistently give error for operator not applied to NaN values
John W. Eaton <jwe@octave.org>
parents:
11010
diff
changeset
|
2615 if (any_element_is_nan ()) |
7c573eb981eb
consistently give error for operator not applied to NaN values
John W. Eaton <jwe@octave.org>
parents:
11010
diff
changeset
|
2616 gripe_nan_to_logical_conversion (); |
7c573eb981eb
consistently give error for operator not applied to NaN values
John W. Eaton <jwe@octave.org>
parents:
11010
diff
changeset
|
2617 |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
2618 return do_mx_unary_op<bool, double> (*this, mx_inline_not); |
458 | 2619 } |
2620 | |
1205 | 2621 // column vector by row vector -> matrix operations |
458 | 2622 |
1205 | 2623 Matrix |
2624 operator * (const ColumnVector& v, const RowVector& a) | |
458 | 2625 { |
1948 | 2626 Matrix retval; |
2627 | |
5275 | 2628 octave_idx_type len = v.length (); |
3233 | 2629 |
2630 if (len != 0) | |
1205 | 2631 { |
5275 | 2632 octave_idx_type a_len = a.length (); |
3233 | 2633 |
9359
be6867ba8104
avoid useless zero initialization when doing matrix multiply
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
2634 retval = Matrix (len, a_len); |
3233 | 2635 double *c = retval.fortran_vec (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
2636 |
4552 | 2637 F77_XFCN (dgemm, DGEMM, (F77_CONST_CHAR_ARG2 ("N", 1), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2638 F77_CONST_CHAR_ARG2 ("N", 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2639 len, a_len, 1, 1.0, v.data (), len, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2640 a.data (), 1, 0.0, c, len |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2641 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2642 F77_CHAR_ARG_LEN (1))); |
1205 | 2643 } |
458 | 2644 |
1948 | 2645 return retval; |
458 | 2646 } |
2647 | |
2648 // other operations. | |
2649 | |
2385 | 2650 bool |
4431 | 2651 Matrix::any_element_is_negative (bool neg_zero) const |
2385 | 2652 { |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
11008
diff
changeset
|
2653 return (neg_zero ? test_all (xnegative_sign) |
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
11008
diff
changeset
|
2654 : do_mx_check<double> (*this, mx_inline_any_negative)); |
2385 | 2655 } |
2656 | |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7803
diff
changeset
|
2657 bool |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7803
diff
changeset
|
2658 Matrix::any_element_is_nan (void) const |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7803
diff
changeset
|
2659 { |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
11008
diff
changeset
|
2660 return do_mx_check<double> (*this, mx_inline_any_nan); |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7803
diff
changeset
|
2661 } |
2385 | 2662 |
2663 bool | |
2664 Matrix::any_element_is_inf_or_nan (void) const | |
2665 { | |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
11008
diff
changeset
|
2666 return ! do_mx_check<double> (*this, mx_inline_all_finite); |
2385 | 2667 } |
2668 | |
2669 bool | |
5943 | 2670 Matrix::any_element_not_one_or_zero (void) const |
2671 { | |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
11008
diff
changeset
|
2672 return ! test_all (xis_one_or_zero); |
5943 | 2673 } |
2674 | |
2675 bool | |
2385 | 2676 Matrix::all_elements_are_int_or_inf_or_nan (void) const |
2677 { | |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
11008
diff
changeset
|
2678 return test_all (xis_int_or_inf_or_nan); |
2385 | 2679 } |
2680 | |
1968 | 2681 // Return nonzero if any element of M is not an integer. Also extract |
2682 // the largest and smallest values and return them in MAX_VAL and MIN_VAL. | |
2683 | |
2385 | 2684 bool |
1968 | 2685 Matrix::all_integers (double& max_val, double& min_val) const |
2686 { | |
5275 | 2687 octave_idx_type nel = nelem (); |
4634 | 2688 |
2689 if (nel > 0) | |
1968 | 2690 { |
4634 | 2691 max_val = elem (0); |
2692 min_val = elem (0); | |
1968 | 2693 } |
2694 else | |
2385 | 2695 return false; |
1968 | 2696 |
5275 | 2697 for (octave_idx_type i = 0; i < nel; i++) |
4634 | 2698 { |
2699 double val = elem (i); | |
2700 | |
2701 if (val > max_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2702 max_val = val; |
4634 | 2703 |
2704 if (val < min_val) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2705 min_val = val; |
4634 | 2706 |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
11008
diff
changeset
|
2707 if (! xisinteger (val)) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2708 return false; |
4634 | 2709 } |
2385 | 2710 |
2711 return true; | |
1968 | 2712 } |
2713 | |
2385 | 2714 bool |
1968 | 2715 Matrix::too_large_for_float (void) const |
2716 { | |
11010
9478b216752e
simplify more array tests
Jaroslav Hajek <highegg@gmail.com>
parents:
11008
diff
changeset
|
2717 return test_all (xtoo_large_for_float); |
1968 | 2718 } |
2719 | |
5775 | 2720 // FIXME Do these really belong here? Maybe they should be |
4015 | 2721 // in a base class? |
458 | 2722 |
2832 | 2723 boolMatrix |
4015 | 2724 Matrix::all (int dim) const |
458 | 2725 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
2726 return do_mx_red_op<bool, double> (*this, dim, mx_inline_all); |
458 | 2727 } |
2728 | |
2832 | 2729 boolMatrix |
4015 | 2730 Matrix::any (int dim) const |
458 | 2731 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
2732 return do_mx_red_op<bool, double> (*this, dim, mx_inline_any); |
458 | 2733 } |
2734 | |
2735 Matrix | |
3723 | 2736 Matrix::cumprod (int dim) const |
458 | 2737 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
2738 return do_mx_cum_op<double, double> (*this, dim, mx_inline_cumprod); |
458 | 2739 } |
2740 | |
2741 Matrix | |
3723 | 2742 Matrix::cumsum (int dim) const |
458 | 2743 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
2744 return do_mx_cum_op<double, double> (*this, dim, mx_inline_cumsum); |
458 | 2745 } |
2746 | |
2747 Matrix | |
3723 | 2748 Matrix::prod (int dim) const |
458 | 2749 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
2750 return do_mx_red_op<double, double> (*this, dim, mx_inline_prod); |
458 | 2751 } |
2752 | |
2753 Matrix | |
3723 | 2754 Matrix::sum (int dim) const |
458 | 2755 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
2756 return do_mx_red_op<double, double> (*this, dim, mx_inline_sum); |
458 | 2757 } |
2758 | |
2759 Matrix | |
3723 | 2760 Matrix::sumsq (int dim) const |
458 | 2761 { |
10362
b47ab50a6aa8
simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
2762 return do_mx_red_op<double, double> (*this, dim, mx_inline_sumsq); |
458 | 2763 } |
2764 | |
2385 | 2765 Matrix |
2766 Matrix::abs (void) const | |
2767 { | |
10363
a0728e81ed25
improve diag matrix interface & implementation
Jaroslav Hajek <highegg@gmail.com>
parents:
10362
diff
changeset
|
2768 return do_mx_unary_map<double, double, std::abs> (*this); |
2385 | 2769 } |
2770 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7544
diff
changeset
|
2771 Matrix |
5275 | 2772 Matrix::diag (octave_idx_type k) const |
458 | 2773 { |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10314
diff
changeset
|
2774 return MArray<double>::diag (k); |
458 | 2775 } |
2776 | |
2777 ColumnVector | |
2778 Matrix::row_min (void) const | |
2779 { | |
5275 | 2780 Array<octave_idx_type> dummy_idx; |
4587 | 2781 return row_min (dummy_idx); |
458 | 2782 } |
2783 | |
2784 ColumnVector | |
5275 | 2785 Matrix::row_min (Array<octave_idx_type>& idx_arg) const |
458 | 2786 { |
2787 ColumnVector result; | |
2788 | |
5275 | 2789 octave_idx_type nr = rows (); |
2790 octave_idx_type nc = cols (); | |
458 | 2791 |
2792 if (nr > 0 && nc > 0) | |
2793 { | |
2794 result.resize (nr); | |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2795 idx_arg.resize (dim_vector (nr, 1)); |
458 | 2796 |
5275 | 2797 for (octave_idx_type i = 0; i < nr; i++) |
458 | 2798 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2799 octave_idx_type idx_j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2800 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2801 double tmp_min = octave_NaN; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2802 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2803 for (idx_j = 0; idx_j < nc; idx_j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2804 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2805 tmp_min = elem (i, idx_j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2806 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2807 if (! xisnan (tmp_min)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2808 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2809 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2810 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2811 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
|
2812 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2813 double tmp = elem (i, j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2814 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2815 if (xisnan (tmp)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2816 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2817 else if (tmp < tmp_min) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2818 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2819 idx_j = j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2820 tmp_min = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2821 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2822 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2823 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2824 result.elem (i) = tmp_min; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2825 idx_arg.elem (i) = xisnan (tmp_min) ? 0 : idx_j; |
458 | 2826 } |
2827 } | |
2828 | |
2829 return result; | |
2830 } | |
2831 | |
2832 ColumnVector | |
2833 Matrix::row_max (void) const | |
2834 { | |
5275 | 2835 Array<octave_idx_type> dummy_idx; |
4587 | 2836 return row_max (dummy_idx); |
458 | 2837 } |
2838 | |
2839 ColumnVector | |
5275 | 2840 Matrix::row_max (Array<octave_idx_type>& idx_arg) const |
458 | 2841 { |
2842 ColumnVector result; | |
2843 | |
5275 | 2844 octave_idx_type nr = rows (); |
2845 octave_idx_type nc = cols (); | |
458 | 2846 |
2847 if (nr > 0 && nc > 0) | |
2848 { | |
2849 result.resize (nr); | |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2850 idx_arg.resize (dim_vector (nr, 1)); |
458 | 2851 |
5275 | 2852 for (octave_idx_type i = 0; i < nr; i++) |
458 | 2853 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2854 octave_idx_type idx_j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2855 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2856 double tmp_max = octave_NaN; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2857 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2858 for (idx_j = 0; idx_j < nc; idx_j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2859 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2860 tmp_max = elem (i, idx_j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2861 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2862 if (! xisnan (tmp_max)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2863 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2864 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2865 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2866 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
|
2867 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2868 double tmp = elem (i, j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2869 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2870 if (xisnan (tmp)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2871 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2872 else if (tmp > tmp_max) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2873 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2874 idx_j = j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2875 tmp_max = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2876 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2877 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2878 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2879 result.elem (i) = tmp_max; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2880 idx_arg.elem (i) = xisnan (tmp_max) ? 0 : idx_j; |
458 | 2881 } |
2882 } | |
2883 | |
2884 return result; | |
2885 } | |
2886 | |
2887 RowVector | |
2888 Matrix::column_min (void) const | |
2889 { | |
5275 | 2890 Array<octave_idx_type> dummy_idx; |
4587 | 2891 return column_min (dummy_idx); |
458 | 2892 } |
2354 | 2893 |
458 | 2894 RowVector |
5275 | 2895 Matrix::column_min (Array<octave_idx_type>& idx_arg) const |
458 | 2896 { |
2897 RowVector result; | |
2898 | |
5275 | 2899 octave_idx_type nr = rows (); |
2900 octave_idx_type nc = cols (); | |
458 | 2901 |
2902 if (nr > 0 && nc > 0) | |
2903 { | |
2904 result.resize (nc); | |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2905 idx_arg.resize (dim_vector (1, nc)); |
458 | 2906 |
5275 | 2907 for (octave_idx_type j = 0; j < nc; j++) |
458 | 2908 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2909 octave_idx_type idx_i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2910 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2911 double tmp_min = octave_NaN; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2912 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2913 for (idx_i = 0; idx_i < nr; idx_i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2914 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2915 tmp_min = elem (idx_i, j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2916 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2917 if (! xisnan (tmp_min)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2918 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2919 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2920 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2921 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
|
2922 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2923 double tmp = elem (i, j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2924 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2925 if (xisnan (tmp)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2926 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2927 else if (tmp < tmp_min) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2928 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2929 idx_i = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2930 tmp_min = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2931 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2932 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2933 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2934 result.elem (j) = tmp_min; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2935 idx_arg.elem (j) = xisnan (tmp_min) ? 0 : idx_i; |
458 | 2936 } |
2937 } | |
2938 | |
2939 return result; | |
2940 } | |
2941 | |
2354 | 2942 RowVector |
2943 Matrix::column_max (void) const | |
2944 { | |
5275 | 2945 Array<octave_idx_type> dummy_idx; |
4587 | 2946 return column_max (dummy_idx); |
2354 | 2947 } |
458 | 2948 |
2949 RowVector | |
5275 | 2950 Matrix::column_max (Array<octave_idx_type>& idx_arg) const |
458 | 2951 { |
2952 RowVector result; | |
2953 | |
5275 | 2954 octave_idx_type nr = rows (); |
2955 octave_idx_type nc = cols (); | |
458 | 2956 |
2957 if (nr > 0 && nc > 0) | |
2958 { | |
2959 result.resize (nc); | |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2960 idx_arg.resize (dim_vector (1, nc)); |
458 | 2961 |
5275 | 2962 for (octave_idx_type j = 0; j < nc; j++) |
458 | 2963 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2964 octave_idx_type idx_i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2965 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2966 double tmp_max = octave_NaN; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2967 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2968 for (idx_i = 0; idx_i < nr; idx_i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2969 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2970 tmp_max = elem (idx_i, j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2971 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2972 if (! xisnan (tmp_max)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2973 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2974 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2975 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2976 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
|
2977 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2978 double tmp = elem (i, j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2979 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2980 if (xisnan (tmp)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2981 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2982 else if (tmp > tmp_max) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2983 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2984 idx_i = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2985 tmp_max = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2986 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2987 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2988 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2989 result.elem (j) = tmp_max; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
2990 idx_arg.elem (j) = xisnan (tmp_max) ? 0 : idx_i; |
458 | 2991 } |
2992 } | |
2993 | |
2994 return result; | |
2995 } | |
2996 | |
3504 | 2997 std::ostream& |
2998 operator << (std::ostream& os, const Matrix& a) | |
458 | 2999 { |
5275 | 3000 for (octave_idx_type i = 0; i < a.rows (); i++) |
458 | 3001 { |
5275 | 3002 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
|
3003 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3004 os << " "; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3005 octave_write_double (os, a.elem (i, j)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3006 } |
458 | 3007 os << "\n"; |
3008 } | |
3009 return os; | |
3010 } | |
3011 | |
3504 | 3012 std::istream& |
3013 operator >> (std::istream& is, Matrix& a) | |
458 | 3014 { |
5275 | 3015 octave_idx_type nr = a.rows (); |
3016 octave_idx_type nc = a.cols (); | |
458 | 3017 |
8999
dc07bc4157b8
allow empty matrices in stream input operators
Jaroslav Hajek <highegg@gmail.com>
parents:
8956
diff
changeset
|
3018 if (nr > 0 && nc > 0) |
458 | 3019 { |
3020 double tmp; | |
5275 | 3021 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
|
3022 for (octave_idx_type j = 0; j < nc; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3023 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3024 tmp = octave_read_value<double> (is); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3025 if (is) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3026 a.elem (i, j) = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3027 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3028 goto done; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3029 } |
458 | 3030 } |
3031 | |
2795 | 3032 done: |
3033 | |
458 | 3034 return is; |
3035 } | |
3036 | |
1819 | 3037 Matrix |
3038 Givens (double x, double y) | |
3039 { | |
3040 double cc, s, temp_r; | |
3041 | |
3887 | 3042 F77_FUNC (dlartg, DLARTG) (x, y, cc, s, temp_r); |
1819 | 3043 |
3044 Matrix g (2, 2); | |
3045 | |
3046 g.elem (0, 0) = cc; | |
3047 g.elem (1, 1) = cc; | |
3048 g.elem (0, 1) = s; | |
3049 g.elem (1, 0) = -s; | |
3050 | |
3051 return g; | |
3052 } | |
3053 | |
3054 Matrix | |
3055 Sylvester (const Matrix& a, const Matrix& b, const Matrix& c) | |
3056 { | |
3057 Matrix retval; | |
3058 | |
5775 | 3059 // FIXME -- need to check that a, b, and c are all the same |
1819 | 3060 // size. |
3061 | |
3062 // Compute Schur decompositions. | |
3063 | |
3064 SCHUR as (a, "U"); | |
3065 SCHUR bs (b, "U"); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
3066 |
1819 | 3067 // Transform c to new coordinates. |
3068 | |
3069 Matrix ua = as.unitary_matrix (); | |
3070 Matrix sch_a = as.schur_matrix (); | |
3071 | |
3072 Matrix ub = bs.unitary_matrix (); | |
3073 Matrix sch_b = bs.schur_matrix (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
3074 |
1819 | 3075 Matrix cx = ua.transpose () * c * ub; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
3076 |
1819 | 3077 // Solve the sylvester equation, back-transform, and return the |
3078 // solution. | |
3079 | |
5275 | 3080 octave_idx_type a_nr = a.rows (); |
3081 octave_idx_type b_nr = b.rows (); | |
1819 | 3082 |
3083 double scale; | |
5275 | 3084 octave_idx_type info; |
1819 | 3085 |
1950 | 3086 double *pa = sch_a.fortran_vec (); |
3087 double *pb = sch_b.fortran_vec (); | |
3088 double *px = cx.fortran_vec (); | |
3089 | |
4552 | 3090 F77_XFCN (dtrsyl, DTRSYL, (F77_CONST_CHAR_ARG2 ("N", 1), |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3091 F77_CONST_CHAR_ARG2 ("N", 1), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3092 1, a_nr, b_nr, pa, a_nr, pb, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3093 b_nr, px, a_nr, scale, info |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3094 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3095 F77_CHAR_ARG_LEN (1))); |
1950 | 3096 |
3097 | |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
3098 // FIXME -- check info? |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
3099 |
7482
29980c6b8604
don't check f77_exception_encountered
John W. Eaton <jwe@octave.org>
parents:
7478
diff
changeset
|
3100 retval = -ua*cx*ub.transpose (); |
1819 | 3101 |
3102 return retval; | |
3103 } | |
3104 | |
2828 | 3105 // matrix by matrix -> matrix operations |
3106 | |
6162 | 3107 /* Simple Dot Product, Matrix-Vector and Matrix-Matrix Unit tests |
3108 %!assert([1 2 3] * [ 4 ; 5 ; 6], 32, 1e-14) | |
3109 %!assert([1 2 ; 3 4 ] * [5 ; 6], [17 ; 39 ], 1e-14) | |
3110 %!assert([1 2 ; 3 4 ] * [5 6 ; 7 8], [19 22; 43 50], 1e-14) | |
3111 */ | |
3112 | |
3113 /* Test some simple identities | |
3114 %!shared M, cv, rv | |
3115 %! M = randn(10,10); | |
3116 %! cv = randn(10,1); | |
3117 %! rv = randn(1,10); | |
3118 %!assert([M*cv,M*cv],M*[cv,cv],1e-14) | |
9528
ec066ba012c8
more fixes & tests for matrix multiply
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
3119 %!assert([M'*cv,M'*cv],M'*[cv,cv],1e-14) |
6162 | 3120 %!assert([rv*M;rv*M],[rv;rv]*M,1e-14) |
9528
ec066ba012c8
more fixes & tests for matrix multiply
Jaroslav Hajek <highegg@gmail.com>
parents:
9523
diff
changeset
|
3121 %!assert([rv*M';rv*M'],[rv;rv]*M',1e-14) |
6162 | 3122 %!assert(2*rv*cv,[rv,rv]*[cv;cv],1e-14) |
3123 */ | |
3124 | |
11516 | 3125 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
|
3126 get_blas_trans_arg (bool trans) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3127 { |
11516 | 3128 return trans ? '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
|
3129 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3130 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3131 // 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
|
3132 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
3133 Matrix |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
3134 xgemm (const Matrix& a, const Matrix& b, |
9665
1dba57e9d08d
use blas_trans_type for xgemm
Jaroslav Hajek <highegg@gmail.com>
parents:
9662
diff
changeset
|
3135 blas_trans_type transa, blas_trans_type transb) |
2828 | 3136 { |
3137 Matrix retval; | |
3138 | |
9665
1dba57e9d08d
use blas_trans_type for xgemm
Jaroslav Hajek <highegg@gmail.com>
parents:
9662
diff
changeset
|
3139 bool tra = transa != blas_no_trans, trb = transb != blas_no_trans; |
1dba57e9d08d
use blas_trans_type for xgemm
Jaroslav Hajek <highegg@gmail.com>
parents:
9662
diff
changeset
|
3140 |
1dba57e9d08d
use blas_trans_type for xgemm
Jaroslav Hajek <highegg@gmail.com>
parents:
9662
diff
changeset
|
3141 octave_idx_type a_nr = tra ? a.cols () : a.rows (); |
1dba57e9d08d
use blas_trans_type for xgemm
Jaroslav Hajek <highegg@gmail.com>
parents:
9662
diff
changeset
|
3142 octave_idx_type a_nc = tra ? a.rows () : a.cols (); |
1dba57e9d08d
use blas_trans_type for xgemm
Jaroslav Hajek <highegg@gmail.com>
parents:
9662
diff
changeset
|
3143 |
1dba57e9d08d
use blas_trans_type for xgemm
Jaroslav Hajek <highegg@gmail.com>
parents:
9662
diff
changeset
|
3144 octave_idx_type b_nr = trb ? b.cols () : b.rows (); |
1dba57e9d08d
use blas_trans_type for xgemm
Jaroslav Hajek <highegg@gmail.com>
parents:
9662
diff
changeset
|
3145 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
|
3146 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3147 if (a_nc != b_nr) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3148 gripe_nonconformant ("operator *", a_nr, a_nc, b_nr, b_nc); |
2828 | 3149 else |
3150 { | |
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
|
3151 if (a_nr == 0 || a_nc == 0 || b_nc == 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3152 retval = Matrix (a_nr, b_nc, 0.0); |
9665
1dba57e9d08d
use blas_trans_type for xgemm
Jaroslav Hajek <highegg@gmail.com>
parents:
9662
diff
changeset
|
3153 else if (a.data () == b.data () && a_nr == b_nc && tra != trb) |
7801
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
3154 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3155 octave_idx_type lda = a.rows (); |
7801
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
3156 |
9359
be6867ba8104
avoid useless zero initialization when doing matrix multiply
Jaroslav Hajek <highegg@gmail.com>
parents:
9227
diff
changeset
|
3157 retval = Matrix (a_nr, b_nc); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3158 double *c = retval.fortran_vec (); |
7801
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
3159 |
11516 | 3160 const char ctra = get_blas_trans_arg (tra); |
7801
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
3161 F77_XFCN (dsyrk, DSYRK, (F77_CONST_CHAR_ARG2 ("U", 1), |
11516 | 3162 F77_CONST_CHAR_ARG2 (&ctra, 1), |
7801
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
3163 a_nr, a_nc, 1.0, |
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
3164 a.data (), lda, 0.0, c, a_nr |
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
3165 F77_CHAR_ARG_LEN (1) |
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
3166 F77_CHAR_ARG_LEN (1))); |
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
3167 for (int j = 0; j < a_nr; j++) |
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
3168 for (int i = 0; i < j; i++) |
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
3169 retval.xelem (j,i) = retval.xelem (i,j); |
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
3170 |
776791438957
map symmetric cases to xHERK, xSYRK
Jaroslav Hajek <highegg@gmail.com>
parents:
7800
diff
changeset
|
3171 } |
2828 | 3172 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3173 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3174 octave_idx_type lda = a.rows (), tda = a.cols (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3175 octave_idx_type ldb = b.rows (), tdb = b.cols (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3176 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3177 retval = Matrix (a_nr, b_nc); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3178 double *c = retval.fortran_vec (); |
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 if (b_nc == 1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3181 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3182 if (a_nr == 1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3183 F77_FUNC (xddot, XDDOT) (a_nc, a.data (), 1, b.data (), 1, *c); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3184 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3185 { |
11516 | 3186 const char ctra = get_blas_trans_arg (tra); |
3187 F77_XFCN (dgemv, DGEMV, (F77_CONST_CHAR_ARG2 (&ctra, 1), | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3188 lda, tda, 1.0, a.data (), lda, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3189 b.data (), 1, 0.0, c, 1 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3190 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3191 } |
5983 | 3192 } |
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
|
3193 else if (a_nr == 1) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3194 { |
11516 | 3195 const char crevtrb = get_blas_trans_arg (! trb); |
3196 F77_XFCN (dgemv, DGEMV, (F77_CONST_CHAR_ARG2 (&crevtrb, 1), | |
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
|
3197 ldb, tdb, 1.0, b.data (), ldb, |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3198 a.data (), 1, 0.0, c, 1 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3199 F77_CHAR_ARG_LEN (1))); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3200 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3201 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3202 { |
11516 | 3203 const char ctra = get_blas_trans_arg (tra); |
3204 const char ctrb = get_blas_trans_arg (trb); | |
3205 F77_XFCN (dgemm, DGEMM, (F77_CONST_CHAR_ARG2 (&ctra, 1), | |
3206 F77_CONST_CHAR_ARG2 (&ctrb, 1), | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3207 a_nr, b_nc, a_nc, 1.0, a.data (), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3208 lda, b.data (), ldb, 0.0, c, a_nr |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3209 F77_CHAR_ARG_LEN (1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3210 F77_CHAR_ARG_LEN (1))); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3211 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3212 } |
2828 | 3213 } |
3214 | |
3215 return retval; | |
3216 } | |
3217 | |
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
|
3218 Matrix |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3219 operator * (const Matrix& a, const Matrix& 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
|
3220 { |
9665
1dba57e9d08d
use blas_trans_type for xgemm
Jaroslav Hajek <highegg@gmail.com>
parents:
9662
diff
changeset
|
3221 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
|
3222 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
3223 |
5775 | 3224 // FIXME -- it would be nice to share code among the min/max |
4309 | 3225 // functions below. |
3226 | |
3227 #define EMPTY_RETURN_CHECK(T) \ | |
3228 if (nr == 0 || nc == 0) \ | |
3229 return T (nr, nc); | |
3230 | |
3231 Matrix | |
3232 min (double d, const Matrix& m) | |
3233 { | |
5275 | 3234 octave_idx_type nr = m.rows (); |
3235 octave_idx_type nc = m.columns (); | |
4309 | 3236 |
3237 EMPTY_RETURN_CHECK (Matrix); | |
3238 | |
3239 Matrix result (nr, nc); | |
3240 | |
5275 | 3241 for (octave_idx_type j = 0; j < nc; j++) |
3242 for (octave_idx_type i = 0; i < nr; i++) | |
4309 | 3243 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3244 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3245 result (i, j) = xmin (d, m (i, j)); |
4309 | 3246 } |
3247 | |
3248 return result; | |
3249 } | |
3250 | |
3251 Matrix | |
3252 min (const Matrix& m, double d) | |
3253 { | |
5275 | 3254 octave_idx_type nr = m.rows (); |
3255 octave_idx_type nc = m.columns (); | |
4309 | 3256 |
3257 EMPTY_RETURN_CHECK (Matrix); | |
3258 | |
3259 Matrix result (nr, nc); | |
3260 | |
5275 | 3261 for (octave_idx_type j = 0; j < nc; j++) |
3262 for (octave_idx_type i = 0; i < nr; i++) | |
4309 | 3263 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3264 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3265 result (i, j) = xmin (m (i, j), d); |
4309 | 3266 } |
3267 | |
3268 return result; | |
3269 } | |
3270 | |
3271 Matrix | |
3272 min (const Matrix& a, const Matrix& b) | |
3273 { | |
5275 | 3274 octave_idx_type nr = a.rows (); |
3275 octave_idx_type nc = a.columns (); | |
4309 | 3276 |
3277 if (nr != b.rows () || nc != b.columns ()) | |
3278 { | |
3279 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3280 ("two-arg min expecting args of same size"); |
4309 | 3281 return Matrix (); |
3282 } | |
3283 | |
3284 EMPTY_RETURN_CHECK (Matrix); | |
3285 | |
3286 Matrix result (nr, nc); | |
3287 | |
5275 | 3288 for (octave_idx_type j = 0; j < nc; j++) |
3289 for (octave_idx_type i = 0; i < nr; i++) | |
4309 | 3290 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3291 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3292 result (i, j) = xmin (a (i, j), b (i, j)); |
4309 | 3293 } |
3294 | |
3295 return result; | |
3296 } | |
3297 | |
3298 Matrix | |
3299 max (double d, const Matrix& m) | |
3300 { | |
5275 | 3301 octave_idx_type nr = m.rows (); |
3302 octave_idx_type nc = m.columns (); | |
4309 | 3303 |
3304 EMPTY_RETURN_CHECK (Matrix); | |
3305 | |
3306 Matrix result (nr, nc); | |
3307 | |
5275 | 3308 for (octave_idx_type j = 0; j < nc; j++) |
3309 for (octave_idx_type i = 0; i < nr; i++) | |
4309 | 3310 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3311 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3312 result (i, j) = xmax (d, m (i, j)); |
4309 | 3313 } |
3314 | |
3315 return result; | |
3316 } | |
3317 | |
3318 Matrix | |
3319 max (const Matrix& m, double d) | |
3320 { | |
5275 | 3321 octave_idx_type nr = m.rows (); |
3322 octave_idx_type nc = m.columns (); | |
4309 | 3323 |
3324 EMPTY_RETURN_CHECK (Matrix); | |
3325 | |
3326 Matrix result (nr, nc); | |
3327 | |
5275 | 3328 for (octave_idx_type j = 0; j < nc; j++) |
3329 for (octave_idx_type i = 0; i < nr; i++) | |
4309 | 3330 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3331 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3332 result (i, j) = xmax (m (i, j), d); |
4309 | 3333 } |
3334 | |
3335 return result; | |
3336 } | |
3337 | |
3338 Matrix | |
3339 max (const Matrix& a, const Matrix& b) | |
3340 { | |
5275 | 3341 octave_idx_type nr = a.rows (); |
3342 octave_idx_type nc = a.columns (); | |
4309 | 3343 |
3344 if (nr != b.rows () || nc != b.columns ()) | |
3345 { | |
3346 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3347 ("two-arg max expecting args of same size"); |
4309 | 3348 return Matrix (); |
3349 } | |
3350 | |
3351 EMPTY_RETURN_CHECK (Matrix); | |
3352 | |
3353 Matrix result (nr, nc); | |
3354 | |
5275 | 3355 for (octave_idx_type j = 0; j < nc; j++) |
3356 for (octave_idx_type i = 0; i < nr; i++) | |
4309 | 3357 { |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3358 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10213
diff
changeset
|
3359 result (i, j) = xmax (a (i, j), b (i, j)); |
4309 | 3360 } |
3361 | |
3362 return result; | |
3363 } | |
3364 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
3365 Matrix linspace (const ColumnVector& x1, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
3366 const ColumnVector& x2, |
9653
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3367 octave_idx_type n) |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3368 |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3369 { |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3370 if (n < 1) n = 1; |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3371 |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3372 octave_idx_type m = x1.length (); |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3373 |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3374 if (x2.length () != m) |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3375 (*current_liboctave_error_handler) ("linspace: vectors must be of equal length"); |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3376 |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3377 NoAlias<Matrix> retval; |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3378 |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3379 retval.clear (m, n); |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3380 for (octave_idx_type i = 0; i < m; i++) |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3381 retval(i, 0) = x1(i); |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3382 |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3383 // The last column is not needed while using delta. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
3384 double *delta = &retval(0, n-1); |
9653
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3385 for (octave_idx_type i = 0; i < m; i++) |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3386 delta[i] = (x2(i) - x1(i)) / (n - 1); |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3387 |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3388 for (octave_idx_type j = 1; j < n-1; j++) |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3389 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
|
3390 retval(i, j) = x1(i) + j*delta[i]; |
9653
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3391 |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3392 for (octave_idx_type i = 0; i < m; i++) |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3393 retval(i, n-1) = x2(i); |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3394 |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3395 return retval; |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3396 } |
e087d7c77ff9
improve linspace in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
3397 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
3398 MS_CMP_OPS (Matrix, double) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9528
diff
changeset
|
3399 MS_BOOL_OPS (Matrix, double) |
2870 | 3400 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
3401 SM_CMP_OPS (double, Matrix) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9528
diff
changeset
|
3402 SM_BOOL_OPS (double, Matrix) |
2870 | 3403 |
9578
7dafdb8b062f
refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents:
9553
diff
changeset
|
3404 MM_CMP_OPS (Matrix, Matrix) |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9528
diff
changeset
|
3405 MM_BOOL_OPS (Matrix, Matrix) |