Mercurial > hg > octave-nkf
annotate liboctave/array/CDiagMatrix.cc @ 17769:49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
* liboctave/array/Array-C.cc, liboctave/array/Array-b.cc,
liboctave/array/Array-ch.cc, liboctave/array/Array-d.cc,
liboctave/array/Array-f.cc, liboctave/array/Array-fC.cc,
liboctave/array/Array-util.cc, liboctave/array/Array-util.h,
liboctave/array/Array.cc, liboctave/array/Array.h, liboctave/array/Array3.h,
liboctave/array/CColVector.cc, liboctave/array/CColVector.h,
liboctave/array/CDiagMatrix.cc, liboctave/array/CDiagMatrix.h,
liboctave/array/CMatrix.cc, liboctave/array/CMatrix.h,
liboctave/array/CNDArray.cc, liboctave/array/CNDArray.h,
liboctave/array/CRowVector.cc, liboctave/array/CRowVector.h,
liboctave/array/CSparse.cc, liboctave/array/CSparse.h,
liboctave/array/DiagArray2.h, liboctave/array/MArray.cc,
liboctave/array/MArray.h, liboctave/array/MDiagArray2.cc,
liboctave/array/MDiagArray2.h, liboctave/array/MSparse.cc,
liboctave/array/MSparse.h, liboctave/array/MatrixType.cc,
liboctave/array/MatrixType.h, liboctave/array/PermMatrix.h,
liboctave/array/Range.cc, liboctave/array/Range.h, liboctave/array/Sparse.cc,
liboctave/array/Sparse.h, liboctave/array/boolMatrix.cc,
liboctave/array/boolMatrix.h, liboctave/array/boolNDArray.cc,
liboctave/array/boolNDArray.h, liboctave/array/boolSparse.cc,
liboctave/array/boolSparse.h, liboctave/array/chMatrix.cc,
liboctave/array/chMatrix.h, liboctave/array/chNDArray.cc,
liboctave/array/chNDArray.h, liboctave/array/dColVector.h,
liboctave/array/dDiagMatrix.cc, liboctave/array/dDiagMatrix.h,
liboctave/array/dMatrix.cc, liboctave/array/dMatrix.h,
liboctave/array/dNDArray.cc, liboctave/array/dNDArray.h,
liboctave/array/dRowVector.h, liboctave/array/dSparse.cc,
liboctave/array/dSparse.h, liboctave/array/dim-vector.cc,
liboctave/array/dim-vector.h, liboctave/array/fCColVector.cc,
liboctave/array/fCColVector.h, liboctave/array/fCDiagMatrix.cc,
liboctave/array/fCDiagMatrix.h, liboctave/array/fCMatrix.cc,
liboctave/array/fCMatrix.h, liboctave/array/fCNDArray.cc,
liboctave/array/fCNDArray.h, liboctave/array/fCRowVector.cc,
liboctave/array/fCRowVector.h, liboctave/array/fColVector.h,
liboctave/array/fDiagMatrix.cc, liboctave/array/fDiagMatrix.h,
liboctave/array/fMatrix.cc, liboctave/array/fMatrix.h,
liboctave/array/fNDArray.cc, liboctave/array/fNDArray.h,
liboctave/array/fRowVector.h, liboctave/array/idx-vector.cc,
liboctave/array/idx-vector.h, liboctave/array/intNDArray.cc,
liboctave/array/intNDArray.h, liboctave/cruft/misc/blaswrap.c,
liboctave/cruft/misc/quit.cc, liboctave/numeric/CmplxCHOL.cc,
liboctave/numeric/CmplxCHOL.h, liboctave/numeric/CmplxGEPBAL.cc,
liboctave/numeric/CmplxGEPBAL.h, liboctave/numeric/CmplxHESS.h,
liboctave/numeric/CmplxLU.cc, liboctave/numeric/CmplxLU.h,
liboctave/numeric/CmplxQR.cc, liboctave/numeric/CmplxQRP.cc,
liboctave/numeric/CmplxQRP.h, liboctave/numeric/CmplxSCHUR.h,
liboctave/numeric/CmplxSVD.cc, liboctave/numeric/CmplxSVD.h,
liboctave/numeric/CollocWt.h, liboctave/numeric/DAE.h,
liboctave/numeric/DAEFunc.h, liboctave/numeric/DAERT.h,
liboctave/numeric/DAERTFunc.h, liboctave/numeric/DASPK.cc,
liboctave/numeric/DASRT.cc, liboctave/numeric/DASRT.h,
liboctave/numeric/DASSL.cc, liboctave/numeric/DET.h, liboctave/numeric/EIG.cc,
liboctave/numeric/EIG.h, liboctave/numeric/LSODE.cc, liboctave/numeric/ODE.h,
liboctave/numeric/ODEFunc.h, liboctave/numeric/ODES.h,
liboctave/numeric/ODESFunc.h, liboctave/numeric/Quad.cc,
liboctave/numeric/Quad.h, liboctave/numeric/SparseCmplxCHOL.h,
liboctave/numeric/SparseCmplxLU.cc, liboctave/numeric/SparseCmplxLU.h,
liboctave/numeric/SparseCmplxQR.cc, liboctave/numeric/SparseCmplxQR.h,
liboctave/numeric/SparseQR.cc, liboctave/numeric/SparseQR.h,
liboctave/numeric/SparsedbleCHOL.h, liboctave/numeric/SparsedbleLU.cc,
liboctave/numeric/SparsedbleLU.h, liboctave/numeric/base-aepbal.h,
liboctave/numeric/base-dae.h, liboctave/numeric/base-de.h,
liboctave/numeric/base-lu.cc, liboctave/numeric/base-lu.h,
liboctave/numeric/base-min.h, liboctave/numeric/base-qr.h,
liboctave/numeric/bsxfun.h, liboctave/numeric/dbleCHOL.cc,
liboctave/numeric/dbleCHOL.h, liboctave/numeric/dbleGEPBAL.h,
liboctave/numeric/dbleHESS.h, liboctave/numeric/dbleLU.cc,
liboctave/numeric/dbleLU.h, liboctave/numeric/dbleQR.cc,
liboctave/numeric/dbleQRP.cc, liboctave/numeric/dbleQRP.h,
liboctave/numeric/dbleSCHUR.cc, liboctave/numeric/dbleSCHUR.h,
liboctave/numeric/dbleSVD.cc, liboctave/numeric/dbleSVD.h,
liboctave/numeric/eigs-base.cc, liboctave/numeric/fCmplxAEPBAL.cc,
liboctave/numeric/fCmplxAEPBAL.h, liboctave/numeric/fCmplxCHOL.cc,
liboctave/numeric/fCmplxCHOL.h, liboctave/numeric/fCmplxGEPBAL.cc,
liboctave/numeric/fCmplxGEPBAL.h, liboctave/numeric/fCmplxHESS.h,
liboctave/numeric/fCmplxLU.cc, liboctave/numeric/fCmplxLU.h,
liboctave/numeric/fCmplxQR.cc, liboctave/numeric/fCmplxQR.h,
liboctave/numeric/fCmplxQRP.cc, liboctave/numeric/fCmplxQRP.h,
liboctave/numeric/fCmplxSCHUR.cc, liboctave/numeric/fCmplxSCHUR.h,
liboctave/numeric/fCmplxSVD.h, liboctave/numeric/fEIG.cc,
liboctave/numeric/fEIG.h, liboctave/numeric/floatCHOL.cc,
liboctave/numeric/floatCHOL.h, liboctave/numeric/floatGEPBAL.cc,
liboctave/numeric/floatGEPBAL.h, liboctave/numeric/floatHESS.h,
liboctave/numeric/floatLU.cc, liboctave/numeric/floatLU.h,
liboctave/numeric/floatQR.cc, liboctave/numeric/floatQRP.cc,
liboctave/numeric/floatQRP.h, liboctave/numeric/floatSCHUR.cc,
liboctave/numeric/floatSCHUR.h, liboctave/numeric/floatSVD.cc,
liboctave/numeric/floatSVD.h, liboctave/numeric/lo-mappers.cc,
liboctave/numeric/lo-mappers.h, liboctave/numeric/lo-specfun.cc,
liboctave/numeric/lo-specfun.h, liboctave/numeric/oct-convn.cc,
liboctave/numeric/oct-fftw.cc, liboctave/numeric/oct-fftw.h,
liboctave/numeric/oct-norm.cc, liboctave/numeric/oct-rand.cc,
liboctave/numeric/oct-rand.h, liboctave/numeric/randgamma.c,
liboctave/numeric/randgamma.h, liboctave/numeric/randmtzig.c,
liboctave/numeric/randpoisson.c, liboctave/numeric/randpoisson.h,
liboctave/numeric/sparse-base-chol.h, liboctave/numeric/sparse-base-lu.h,
liboctave/numeric/sparse-dmsolve.cc, liboctave/operators/Sparse-diag-op-defs.h,
liboctave/operators/Sparse-op-defs.h, liboctave/operators/mx-inlines.cc,
liboctave/system/dir-ops.h, liboctave/system/file-ops.cc,
liboctave/system/file-stat.cc, liboctave/system/file-stat.h,
liboctave/system/lo-sysdep.cc, liboctave/system/lo-sysdep.h,
liboctave/system/mach-info.cc, liboctave/system/mach-info.h,
liboctave/system/oct-env.cc, liboctave/system/oct-group.cc,
liboctave/system/oct-syscalls.cc, liboctave/system/oct-syscalls.h,
liboctave/system/oct-time.h, liboctave/system/tempname.c,
liboctave/util/action-container.h, liboctave/util/base-list.h,
liboctave/util/cmd-edit.cc, liboctave/util/cmd-edit.h,
liboctave/util/cmd-hist.cc, liboctave/util/cmd-hist.h,
liboctave/util/data-conv.cc, liboctave/util/data-conv.h,
liboctave/util/kpse.cc, liboctave/util/lo-array-gripes.cc,
liboctave/util/lo-cieee.c, liboctave/util/lo-regexp.cc,
liboctave/util/lo-utils.cc, liboctave/util/oct-alloc.cc,
liboctave/util/oct-base64.cc, liboctave/util/oct-binmap.h,
liboctave/util/oct-cmplx.h, liboctave/util/oct-glob.cc,
liboctave/util/oct-inttypes.cc, liboctave/util/oct-inttypes.h,
liboctave/util/oct-locbuf.cc, liboctave/util/oct-locbuf.h,
liboctave/util/oct-mem.h, liboctave/util/oct-mutex.cc,
liboctave/util/oct-refcount.h, liboctave/util/oct-shlib.cc,
liboctave/util/oct-shlib.h, liboctave/util/oct-sort.cc,
liboctave/util/oct-sort.h, liboctave/util/pathsearch.cc,
liboctave/util/pathsearch.h, liboctave/util/sparse-util.cc,
liboctave/util/str-vec.cc, liboctave/util/str-vec.h,
liboctave/util/unwind-prot.h, liboctave/util/url-transfer.cc,
liboctave/util/url-transfer.h: Use GNU style coding conventions.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 26 Oct 2013 18:57:05 -0700 |
parents | d63878346099 |
children | 8e056300994b |
rev | line source |
---|---|
1993 | 1 // DiagMatrix manipulations. |
458 | 2 /* |
3 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17663
diff
changeset
|
4 Copyright (C) 1994-2013 John W. Eaton |
9601
a9b37bae1802
add a couple of missing copyright statements
Jaroslav Hajek <highegg@gmail.com>
parents:
9550
diff
changeset
|
5 Copyright (C) 2009 VZLU Prague |
458 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
458 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
458 | 22 |
23 */ | |
24 | |
25 #ifdef HAVE_CONFIG_H | |
1192 | 26 #include <config.h> |
458 | 27 #endif |
28 | |
3503 | 29 #include <iostream> |
458 | 30 |
4669 | 31 #include "Array-util.h" |
1368 | 32 #include "lo-error.h" |
9003
0631d397fbe0
replace lo_ieee_isnan by xisnan, add missing includes
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
33 #include "lo-ieee.h" |
458 | 34 #include "mx-base.h" |
35 #include "mx-inlines.cc" | |
1650 | 36 #include "oct-cmplx.h" |
458 | 37 |
1360 | 38 // Complex Diagonal Matrix class |
458 | 39 |
40 ComplexDiagMatrix::ComplexDiagMatrix (const DiagMatrix& a) | |
1989 | 41 : MDiagArray2<Complex> (a.rows (), a.cols ()) |
458 | 42 { |
5275 | 43 for (octave_idx_type i = 0; i < length (); i++) |
458 | 44 elem (i, i) = a.elem (i, i); |
45 } | |
46 | |
2386 | 47 bool |
458 | 48 ComplexDiagMatrix::operator == (const ComplexDiagMatrix& a) const |
49 { | |
50 if (rows () != a.rows () || cols () != a.cols ()) | |
51 return 0; | |
52 | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9003
diff
changeset
|
53 return mx_inline_equal (length (), data (), a.data ()); |
458 | 54 } |
55 | |
2386 | 56 bool |
458 | 57 ComplexDiagMatrix::operator != (const ComplexDiagMatrix& a) const |
58 { | |
59 return !(*this == a); | |
60 } | |
61 | |
62 ComplexDiagMatrix& | |
63 ComplexDiagMatrix::fill (double val) | |
64 { | |
5275 | 65 for (octave_idx_type i = 0; i < length (); i++) |
458 | 66 elem (i, i) = val; |
67 return *this; | |
68 } | |
69 | |
70 ComplexDiagMatrix& | |
71 ComplexDiagMatrix::fill (const Complex& val) | |
72 { | |
5275 | 73 for (octave_idx_type i = 0; i < length (); i++) |
458 | 74 elem (i, i) = val; |
75 return *this; | |
76 } | |
77 | |
78 ComplexDiagMatrix& | |
5275 | 79 ComplexDiagMatrix::fill (double val, octave_idx_type beg, octave_idx_type end) |
458 | 80 { |
81 if (beg < 0 || end >= length () || end < beg) | |
82 { | |
83 (*current_liboctave_error_handler) ("range error for fill"); | |
84 return *this; | |
85 } | |
86 | |
5275 | 87 for (octave_idx_type i = beg; i <= end; i++) |
458 | 88 elem (i, i) = val; |
89 | |
90 return *this; | |
91 } | |
92 | |
93 ComplexDiagMatrix& | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
94 ComplexDiagMatrix::fill (const Complex& val, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
95 octave_idx_type beg, octave_idx_type end) |
458 | 96 { |
97 if (beg < 0 || end >= length () || end < beg) | |
98 { | |
99 (*current_liboctave_error_handler) ("range error for fill"); | |
100 return *this; | |
101 } | |
102 | |
5275 | 103 for (octave_idx_type i = beg; i <= end; i++) |
458 | 104 elem (i, i) = val; |
105 | |
106 return *this; | |
107 } | |
108 | |
109 ComplexDiagMatrix& | |
110 ComplexDiagMatrix::fill (const ColumnVector& a) | |
111 { | |
5275 | 112 octave_idx_type len = length (); |
458 | 113 if (a.length () != len) |
114 { | |
115 (*current_liboctave_error_handler) ("range error for fill"); | |
116 return *this; | |
117 } | |
118 | |
5275 | 119 for (octave_idx_type i = 0; i < len; i++) |
458 | 120 elem (i, i) = a.elem (i); |
121 | |
122 return *this; | |
123 } | |
124 | |
125 ComplexDiagMatrix& | |
126 ComplexDiagMatrix::fill (const ComplexColumnVector& a) | |
127 { | |
5275 | 128 octave_idx_type len = length (); |
458 | 129 if (a.length () != len) |
130 { | |
131 (*current_liboctave_error_handler) ("range error for fill"); | |
132 return *this; | |
133 } | |
134 | |
5275 | 135 for (octave_idx_type i = 0; i < len; i++) |
458 | 136 elem (i, i) = a.elem (i); |
137 | |
138 return *this; | |
139 } | |
140 | |
141 ComplexDiagMatrix& | |
142 ComplexDiagMatrix::fill (const RowVector& a) | |
143 { | |
5275 | 144 octave_idx_type len = length (); |
458 | 145 if (a.length () != len) |
146 { | |
147 (*current_liboctave_error_handler) ("range error for fill"); | |
148 return *this; | |
149 } | |
150 | |
5275 | 151 for (octave_idx_type i = 0; i < len; i++) |
458 | 152 elem (i, i) = a.elem (i); |
153 | |
154 return *this; | |
155 } | |
156 | |
157 ComplexDiagMatrix& | |
158 ComplexDiagMatrix::fill (const ComplexRowVector& a) | |
159 { | |
5275 | 160 octave_idx_type len = length (); |
458 | 161 if (a.length () != len) |
162 { | |
163 (*current_liboctave_error_handler) ("range error for fill"); | |
164 return *this; | |
165 } | |
166 | |
5275 | 167 for (octave_idx_type i = 0; i < len; i++) |
458 | 168 elem (i, i) = a.elem (i); |
169 | |
170 return *this; | |
171 } | |
172 | |
173 ComplexDiagMatrix& | |
5275 | 174 ComplexDiagMatrix::fill (const ColumnVector& a, octave_idx_type beg) |
458 | 175 { |
5275 | 176 octave_idx_type a_len = a.length (); |
458 | 177 if (beg < 0 || beg + a_len >= length ()) |
178 { | |
179 (*current_liboctave_error_handler) ("range error for fill"); | |
180 return *this; | |
181 } | |
182 | |
5275 | 183 for (octave_idx_type i = 0; i < a_len; i++) |
458 | 184 elem (i+beg, i+beg) = a.elem (i); |
185 | |
186 return *this; | |
187 } | |
188 | |
189 ComplexDiagMatrix& | |
5275 | 190 ComplexDiagMatrix::fill (const ComplexColumnVector& a, octave_idx_type beg) |
458 | 191 { |
5275 | 192 octave_idx_type a_len = a.length (); |
458 | 193 if (beg < 0 || beg + a_len >= length ()) |
194 { | |
195 (*current_liboctave_error_handler) ("range error for fill"); | |
196 return *this; | |
197 } | |
198 | |
5275 | 199 for (octave_idx_type i = 0; i < a_len; i++) |
458 | 200 elem (i+beg, i+beg) = a.elem (i); |
201 | |
202 return *this; | |
203 } | |
204 | |
205 ComplexDiagMatrix& | |
5275 | 206 ComplexDiagMatrix::fill (const RowVector& a, octave_idx_type beg) |
458 | 207 { |
5275 | 208 octave_idx_type a_len = a.length (); |
458 | 209 if (beg < 0 || beg + a_len >= length ()) |
210 { | |
211 (*current_liboctave_error_handler) ("range error for fill"); | |
212 return *this; | |
213 } | |
214 | |
5275 | 215 for (octave_idx_type i = 0; i < a_len; i++) |
458 | 216 elem (i+beg, i+beg) = a.elem (i); |
217 | |
218 return *this; | |
219 } | |
220 | |
221 ComplexDiagMatrix& | |
5275 | 222 ComplexDiagMatrix::fill (const ComplexRowVector& a, octave_idx_type beg) |
458 | 223 { |
5275 | 224 octave_idx_type a_len = a.length (); |
458 | 225 if (beg < 0 || beg + a_len >= length ()) |
226 { | |
227 (*current_liboctave_error_handler) ("range error for fill"); | |
228 return *this; | |
229 } | |
230 | |
5275 | 231 for (octave_idx_type i = 0; i < a_len; i++) |
458 | 232 elem (i+beg, i+beg) = a.elem (i); |
233 | |
234 return *this; | |
235 } | |
236 | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
237 DiagMatrix |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
238 ComplexDiagMatrix::abs (void) const |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
239 { |
15448
0a0912a9ab6e
Replace deprecated DiagArray2<T>::diag calls with DiagArray2<T>::extract_diag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15271
diff
changeset
|
240 return DiagMatrix (extract_diag ().abs (), rows (), columns ()); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
241 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
242 |
458 | 243 ComplexDiagMatrix |
244 conj (const ComplexDiagMatrix& a) | |
245 { | |
15448
0a0912a9ab6e
Replace deprecated DiagArray2<T>::diag calls with DiagArray2<T>::extract_diag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15271
diff
changeset
|
246 return ComplexDiagMatrix (conj (a.extract_diag ()), a.rows (), a.columns ()); |
458 | 247 } |
248 | |
249 // resize is the destructive analog for this one | |
250 | |
251 ComplexMatrix | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
252 ComplexDiagMatrix::extract (octave_idx_type r1, octave_idx_type c1, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
253 octave_idx_type r2, octave_idx_type c2) const |
458 | 254 { |
17663
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
15448
diff
changeset
|
255 if (r1 > r2) { std::swap (r1, r2); } |
7975d75f933c
Use std::swap in liboctave instead of temporary variable.
Rik <rik@octave.org>
parents:
15448
diff
changeset
|
256 if (c1 > c2) { std::swap (c1, c2); } |
458 | 257 |
5275 | 258 octave_idx_type new_r = r2 - r1 + 1; |
259 octave_idx_type new_c = c2 - c1 + 1; | |
458 | 260 |
261 ComplexMatrix result (new_r, new_c); | |
262 | |
5275 | 263 for (octave_idx_type j = 0; j < new_c; j++) |
264 for (octave_idx_type i = 0; i < new_r; i++) | |
458 | 265 result.elem (i, j) = elem (r1+i, c1+j); |
266 | |
267 return result; | |
268 } | |
269 | |
270 // extract row or column i. | |
271 | |
272 ComplexRowVector | |
5275 | 273 ComplexDiagMatrix::row (octave_idx_type i) const |
458 | 274 { |
5275 | 275 octave_idx_type r = rows (); |
276 octave_idx_type c = cols (); | |
3504 | 277 if (i < 0 || i >= r) |
458 | 278 { |
279 (*current_liboctave_error_handler) ("invalid row selection"); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
280 return ComplexRowVector (); |
458 | 281 } |
282 | |
3504 | 283 ComplexRowVector retval (c, 0.0); |
284 if (r <= c || (r > c && i < c)) | |
458 | 285 retval.elem (i) = elem (i, i); |
286 | |
287 return retval; | |
288 } | |
289 | |
290 ComplexRowVector | |
291 ComplexDiagMatrix::row (char *s) const | |
292 { | |
533 | 293 if (! s) |
458 | 294 { |
295 (*current_liboctave_error_handler) ("invalid row selection"); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
296 return ComplexRowVector (); |
458 | 297 } |
298 | |
299 char c = *s; | |
300 if (c == 'f' || c == 'F') | |
5275 | 301 return row (static_cast<octave_idx_type>(0)); |
458 | 302 else if (c == 'l' || c == 'L') |
303 return row (rows () - 1); | |
304 else | |
305 { | |
306 (*current_liboctave_error_handler) ("invalid row selection"); | |
307 return ComplexRowVector (); | |
308 } | |
309 } | |
310 | |
311 ComplexColumnVector | |
5275 | 312 ComplexDiagMatrix::column (octave_idx_type i) const |
458 | 313 { |
5275 | 314 octave_idx_type r = rows (); |
315 octave_idx_type c = cols (); | |
3504 | 316 if (i < 0 || i >= c) |
458 | 317 { |
318 (*current_liboctave_error_handler) ("invalid column selection"); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
319 return ComplexColumnVector (); |
458 | 320 } |
321 | |
3504 | 322 ComplexColumnVector retval (r, 0.0); |
323 if (r >= c || (r < c && i < r)) | |
458 | 324 retval.elem (i) = elem (i, i); |
325 | |
326 return retval; | |
327 } | |
328 | |
329 ComplexColumnVector | |
330 ComplexDiagMatrix::column (char *s) const | |
331 { | |
533 | 332 if (! s) |
458 | 333 { |
334 (*current_liboctave_error_handler) ("invalid column selection"); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
335 return ComplexColumnVector (); |
458 | 336 } |
337 | |
338 char c = *s; | |
339 if (c == 'f' || c == 'F') | |
5275 | 340 return column (static_cast<octave_idx_type>(0)); |
458 | 341 else if (c == 'l' || c == 'L') |
342 return column (cols () - 1); | |
343 else | |
344 { | |
345 (*current_liboctave_error_handler) ("invalid column selection"); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
346 return ComplexColumnVector (); |
458 | 347 } |
348 } | |
349 | |
350 ComplexDiagMatrix | |
351 ComplexDiagMatrix::inverse (void) const | |
352 { | |
8811 | 353 octave_idx_type info; |
458 | 354 return inverse (info); |
355 } | |
356 | |
357 ComplexDiagMatrix | |
8811 | 358 ComplexDiagMatrix::inverse (octave_idx_type& info) const |
458 | 359 { |
5275 | 360 octave_idx_type r = rows (); |
361 octave_idx_type c = cols (); | |
3504 | 362 if (r != c) |
458 | 363 { |
364 (*current_liboctave_error_handler) ("inverse requires square matrix"); | |
3585 | 365 return ComplexDiagMatrix (); |
458 | 366 } |
367 | |
3504 | 368 ComplexDiagMatrix retval (r, c); |
458 | 369 |
370 info = 0; | |
5275 | 371 for (octave_idx_type i = 0; i < length (); i++) |
458 | 372 { |
373 if (elem (i, i) == 0.0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
374 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
375 info = -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
376 return *this; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
377 } |
458 | 378 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
379 retval.elem (i, i) = 1.0 / elem (i, i); |
458 | 380 } |
381 | |
1627 | 382 return retval; |
458 | 383 } |
384 | |
8840
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
385 ComplexDiagMatrix |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
386 ComplexDiagMatrix::pseudo_inverse (void) const |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
387 { |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
388 octave_idx_type r = rows (); |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
389 octave_idx_type c = cols (); |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
390 octave_idx_type len = length (); |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
391 |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
392 ComplexDiagMatrix retval (c, r); |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
393 |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
394 for (octave_idx_type i = 0; i < len; i++) |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
395 { |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
396 if (elem (i, i) != 0.0) |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
397 retval.elem (i, i) = 1.0 / elem (i, i); |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
398 else |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
399 retval.elem (i, i) = 0.0; |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
400 } |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
401 |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
402 return retval; |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
403 } |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
404 |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
405 bool |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
406 ComplexDiagMatrix::all_elements_are_real (void) const |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
407 { |
9825
7483fe200fab
narrow complex values with negative zero imaginary parts
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
408 return mx_inline_all_real (length (), data ()); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
409 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
410 |
458 | 411 // diagonal matrix by diagonal matrix -> diagonal matrix operations |
412 | |
413 ComplexDiagMatrix& | |
414 ComplexDiagMatrix::operator += (const DiagMatrix& a) | |
415 { | |
5275 | 416 octave_idx_type r = rows (); |
417 octave_idx_type c = cols (); | |
2386 | 418 |
5275 | 419 octave_idx_type a_nr = a.rows (); |
420 octave_idx_type a_nc = a.cols (); | |
2386 | 421 |
3504 | 422 if (r != a_nr || c != a_nc) |
458 | 423 { |
3504 | 424 gripe_nonconformant ("operator +=", r, c, a_nr, a_nc); |
458 | 425 return *this; |
426 } | |
427 | |
3504 | 428 if (r == 0 || c == 0) |
458 | 429 return *this; |
430 | |
431 Complex *d = fortran_vec (); // Ensures only one reference to my privates! | |
432 | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
9003
diff
changeset
|
433 mx_inline_add2 (length (), d, a.data ()); |
458 | 434 return *this; |
435 } | |
436 | |
437 ComplexDiagMatrix | |
438 operator * (const ComplexDiagMatrix& a, const DiagMatrix& b) | |
439 { | |
5275 | 440 octave_idx_type a_nr = a.rows (); |
441 octave_idx_type a_nc = a.cols (); | |
2386 | 442 |
5275 | 443 octave_idx_type b_nr = b.rows (); |
444 octave_idx_type b_nc = b.cols (); | |
2386 | 445 |
3504 | 446 if (a_nc != b_nr) |
9698
7c6d5d8c8d37
fix diag*diag multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
447 gripe_nonconformant ("operator *", a_nr, a_nc, b_nr, b_nc); |
458 | 448 |
3504 | 449 ComplexDiagMatrix c (a_nr, b_nc); |
458 | 450 |
9698
7c6d5d8c8d37
fix diag*diag multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
451 octave_idx_type len = c.length (), lenm = len < a_nc ? len : a_nc; |
458 | 452 |
9698
7c6d5d8c8d37
fix diag*diag multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
453 for (octave_idx_type i = 0; i < lenm; i++) |
7c6d5d8c8d37
fix diag*diag multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
454 c.dgxelem (i) = a.dgelem (i) * b.dgelem (i); |
7c6d5d8c8d37
fix diag*diag multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
455 for (octave_idx_type i = lenm; i < len; i++) |
7c6d5d8c8d37
fix diag*diag multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
456 c.dgxelem (i) = 0.0; |
458 | 457 |
458 return c; | |
459 } | |
460 | |
461 ComplexDiagMatrix | |
1205 | 462 operator * (const DiagMatrix& a, const ComplexDiagMatrix& b) |
463 { | |
5275 | 464 octave_idx_type a_nr = a.rows (); |
465 octave_idx_type a_nc = a.cols (); | |
2386 | 466 |
5275 | 467 octave_idx_type b_nr = b.rows (); |
468 octave_idx_type b_nc = b.cols (); | |
2386 | 469 |
3504 | 470 if (a_nc != b_nr) |
1205 | 471 { |
3504 | 472 gripe_nonconformant ("operator *", a_nr, a_nc, b_nr, b_nc); |
1205 | 473 return ComplexDiagMatrix (); |
474 } | |
475 | |
3504 | 476 if (a_nr == 0 || a_nc == 0 || b_nc == 0) |
477 return ComplexDiagMatrix (a_nr, a_nc, 0.0); | |
1205 | 478 |
3504 | 479 ComplexDiagMatrix c (a_nr, b_nc); |
1205 | 480 |
5275 | 481 octave_idx_type len = a_nr < b_nc ? a_nr : b_nc; |
1205 | 482 |
5275 | 483 for (octave_idx_type i = 0; i < len; i++) |
1205 | 484 { |
485 double a_element = a.elem (i, i); | |
486 Complex b_element = b.elem (i, i); | |
487 | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
488 c.elem (i, i) = a_element * b_element; |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
489 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
490 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
491 return c; |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
492 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
493 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
494 ComplexDiagMatrix |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
495 operator * (const ComplexDiagMatrix& a, const ComplexDiagMatrix& b) |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
496 { |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
497 octave_idx_type a_nr = a.rows (); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
498 octave_idx_type a_nc = a.cols (); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
499 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
500 octave_idx_type b_nr = b.rows (); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
501 octave_idx_type b_nc = b.cols (); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
502 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
503 if (a_nc != b_nr) |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
504 { |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
505 gripe_nonconformant ("operator *", a_nr, a_nc, b_nr, b_nc); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
506 return ComplexDiagMatrix (); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
507 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
508 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
509 if (a_nr == 0 || a_nc == 0 || b_nc == 0) |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
510 return ComplexDiagMatrix (a_nr, a_nc, 0.0); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
511 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
512 ComplexDiagMatrix c (a_nr, b_nc); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
513 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
514 octave_idx_type len = a_nr < b_nc ? a_nr : b_nc; |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
515 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
516 for (octave_idx_type i = 0; i < len; i++) |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
517 { |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
518 Complex a_element = a.elem (i, i); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
519 Complex b_element = b.elem (i, i); |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
520 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
521 c.elem (i, i) = a_element * b_element; |
1205 | 522 } |
523 | |
524 return c; | |
525 } | |
526 | |
458 | 527 // other operations |
528 | |
8371
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
529 ComplexDET |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
530 ComplexDiagMatrix::determinant (void) const |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
531 { |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
532 ComplexDET det (1.0); |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
533 if (rows () != cols ()) |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
534 { |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
535 (*current_liboctave_error_handler) ("determinant requires square matrix"); |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
536 det = ComplexDET (0.0); |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
537 } |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
538 else |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
539 { |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
540 octave_idx_type len = length (); |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
541 for (octave_idx_type i = 0; i < len; i++) |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
542 det *= elem (i, i); |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
543 } |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
544 |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
545 return det; |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
546 } |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
547 |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
548 double |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
549 ComplexDiagMatrix::rcond (void) const |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
550 { |
15448
0a0912a9ab6e
Replace deprecated DiagArray2<T>::diag calls with DiagArray2<T>::extract_diag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15271
diff
changeset
|
551 ColumnVector av = extract_diag (0).map<double> (std::abs); |
8371
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
552 double amx = av.max (), amn = av.min (); |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
553 return amx == 0 ? 0.0 : amn / amx; |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
554 } |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
555 |
458 | 556 // i/o |
557 | |
3504 | 558 std::ostream& |
559 operator << (std::ostream& os, const ComplexDiagMatrix& a) | |
458 | 560 { |
561 Complex ZERO (0.0); | |
562 // int field_width = os.precision () + 7; | |
5275 | 563 for (octave_idx_type i = 0; i < a.rows (); i++) |
458 | 564 { |
5275 | 565 for (octave_idx_type j = 0; j < a.cols (); j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
566 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
567 if (i == j) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
568 os << " " /* setw (field_width) */ << a.elem (i, i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
569 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
570 os << " " /* setw (field_width) */ << ZERO; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
571 } |
458 | 572 os << "\n"; |
573 } | |
574 return os; | |
575 } |