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