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