Mercurial > hg > octave-nkf
annotate liboctave/array/dDiagMatrix.cc @ 16660:cbb1bb7a5c3d
Added tag ss-3-7-5 for changeset 608e307b4914
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 14 May 2013 05:23:53 -0400 |
parents | 0a0912a9ab6e |
children | 7975d75f933c |
rev | line source |
---|---|
1993 | 1 // DiagMatrix manipulations. |
458 | 2 /* |
3 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
4 Copyright (C) 1994-2012 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" |
458 | 33 #include "mx-base.h" |
34 #include "mx-inlines.cc" | |
1650 | 35 #include "oct-cmplx.h" |
458 | 36 |
1360 | 37 // Diagonal Matrix class. |
458 | 38 |
2385 | 39 bool |
458 | 40 DiagMatrix::operator == (const DiagMatrix& a) const |
41 { | |
42 if (rows () != a.rows () || cols () != a.cols ()) | |
43 return 0; | |
44 | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
45 return mx_inline_equal (length (), data (), a.data ()); |
458 | 46 } |
47 | |
2385 | 48 bool |
458 | 49 DiagMatrix::operator != (const DiagMatrix& a) const |
50 { | |
51 return !(*this == a); | |
52 } | |
53 | |
54 DiagMatrix& | |
55 DiagMatrix::fill (double val) | |
56 { | |
5275 | 57 for (octave_idx_type i = 0; i < length (); i++) |
458 | 58 elem (i, i) = val; |
59 return *this; | |
60 } | |
61 | |
62 DiagMatrix& | |
5275 | 63 DiagMatrix::fill (double val, octave_idx_type beg, octave_idx_type end) |
458 | 64 { |
65 if (beg < 0 || end >= length () || end < beg) | |
66 { | |
67 (*current_liboctave_error_handler) ("range error for fill"); | |
68 return *this; | |
69 } | |
70 | |
5275 | 71 for (octave_idx_type i = beg; i <= end; i++) |
458 | 72 elem (i, i) = val; |
73 | |
74 return *this; | |
75 } | |
76 | |
77 DiagMatrix& | |
78 DiagMatrix::fill (const ColumnVector& a) | |
79 { | |
5275 | 80 octave_idx_type len = length (); |
458 | 81 if (a.length () != len) |
82 { | |
83 (*current_liboctave_error_handler) ("range error for fill"); | |
84 return *this; | |
85 } | |
86 | |
5275 | 87 for (octave_idx_type i = 0; i < len; i++) |
458 | 88 elem (i, i) = a.elem (i); |
89 | |
90 return *this; | |
91 } | |
92 | |
93 DiagMatrix& | |
94 DiagMatrix::fill (const RowVector& a) | |
95 { | |
5275 | 96 octave_idx_type len = length (); |
458 | 97 if (a.length () != len) |
98 { | |
99 (*current_liboctave_error_handler) ("range error for fill"); | |
100 return *this; | |
101 } | |
102 | |
5275 | 103 for (octave_idx_type i = 0; i < len; i++) |
458 | 104 elem (i, i) = a.elem (i); |
105 | |
106 return *this; | |
107 } | |
108 | |
109 DiagMatrix& | |
5275 | 110 DiagMatrix::fill (const ColumnVector& a, octave_idx_type beg) |
458 | 111 { |
5275 | 112 octave_idx_type a_len = a.length (); |
458 | 113 if (beg < 0 || beg + a_len >= length ()) |
114 { | |
115 (*current_liboctave_error_handler) ("range error for fill"); | |
116 return *this; | |
117 } | |
118 | |
5275 | 119 for (octave_idx_type i = 0; i < a_len; i++) |
458 | 120 elem (i+beg, i+beg) = a.elem (i); |
121 | |
122 return *this; | |
123 } | |
124 | |
125 DiagMatrix& | |
5275 | 126 DiagMatrix::fill (const RowVector& a, octave_idx_type beg) |
458 | 127 { |
5275 | 128 octave_idx_type a_len = a.length (); |
458 | 129 if (beg < 0 || beg + a_len >= length ()) |
130 { | |
131 (*current_liboctave_error_handler) ("range error for fill"); | |
132 return *this; | |
133 } | |
134 | |
5275 | 135 for (octave_idx_type i = 0; i < a_len; i++) |
458 | 136 elem (i+beg, i+beg) = a.elem (i); |
137 | |
138 return *this; | |
139 } | |
140 | |
141 DiagMatrix | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7924
diff
changeset
|
142 DiagMatrix::abs (void) const |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7924
diff
changeset
|
143 { |
15448
0a0912a9ab6e
Replace deprecated DiagArray2<T>::diag calls with DiagArray2<T>::extract_diag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15271
diff
changeset
|
144 return DiagMatrix (extract_diag ().abs (), rows (), columns ()); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7924
diff
changeset
|
145 } |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7924
diff
changeset
|
146 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
7924
diff
changeset
|
147 DiagMatrix |
1205 | 148 real (const ComplexDiagMatrix& a) |
149 { | |
15448
0a0912a9ab6e
Replace deprecated DiagArray2<T>::diag calls with DiagArray2<T>::extract_diag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15271
diff
changeset
|
150 return DiagMatrix (real (a.extract_diag ()), a.rows (), a.cols ()); |
1205 | 151 } |
152 | |
153 DiagMatrix | |
154 imag (const ComplexDiagMatrix& a) | |
155 { | |
15448
0a0912a9ab6e
Replace deprecated DiagArray2<T>::diag calls with DiagArray2<T>::extract_diag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15271
diff
changeset
|
156 return DiagMatrix (imag (a.extract_diag ()), a.rows (), a.cols ()); |
1205 | 157 } |
158 | |
458 | 159 Matrix |
5275 | 160 DiagMatrix::extract (octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const |
458 | 161 { |
5275 | 162 if (r1 > r2) { octave_idx_type tmp = r1; r1 = r2; r2 = tmp; } |
163 if (c1 > c2) { octave_idx_type tmp = c1; c1 = c2; c2 = tmp; } | |
458 | 164 |
5275 | 165 octave_idx_type new_r = r2 - r1 + 1; |
166 octave_idx_type new_c = c2 - c1 + 1; | |
458 | 167 |
168 Matrix result (new_r, new_c); | |
169 | |
5275 | 170 for (octave_idx_type j = 0; j < new_c; j++) |
171 for (octave_idx_type i = 0; i < new_r; i++) | |
458 | 172 result.elem (i, j) = elem (r1+i, c1+j); |
173 | |
174 return result; | |
175 } | |
176 | |
177 // extract row or column i. | |
178 | |
179 RowVector | |
5275 | 180 DiagMatrix::row (octave_idx_type i) const |
458 | 181 { |
5275 | 182 octave_idx_type r = rows (); |
183 octave_idx_type c = cols (); | |
3504 | 184 if (i < 0 || i >= r) |
458 | 185 { |
186 (*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
|
187 return RowVector (); |
458 | 188 } |
189 | |
3504 | 190 RowVector retval (c, 0.0); |
191 if (r <= c || (r > c && i < c)) | |
458 | 192 retval.elem (i) = elem (i, i); |
193 | |
194 return retval; | |
195 } | |
196 | |
197 RowVector | |
198 DiagMatrix::row (char *s) const | |
199 { | |
533 | 200 if (! s) |
458 | 201 { |
202 (*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
|
203 return RowVector (); |
458 | 204 } |
205 | |
206 char c = *s; | |
207 if (c == 'f' || c == 'F') | |
5275 | 208 return row (static_cast<octave_idx_type>(0)); |
458 | 209 else if (c == 'l' || c == 'L') |
210 return row (rows () - 1); | |
211 else | |
212 { | |
213 (*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
|
214 return RowVector (); |
458 | 215 } |
216 } | |
217 | |
218 ColumnVector | |
5275 | 219 DiagMatrix::column (octave_idx_type i) const |
458 | 220 { |
5275 | 221 octave_idx_type r = rows (); |
222 octave_idx_type c = cols (); | |
3504 | 223 if (i < 0 || i >= c) |
458 | 224 { |
225 (*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
|
226 return ColumnVector (); |
458 | 227 } |
228 | |
3504 | 229 ColumnVector retval (r, 0.0); |
230 if (r >= c || (r < c && i < r)) | |
458 | 231 retval.elem (i) = elem (i, i); |
232 | |
233 return retval; | |
234 } | |
235 | |
236 ColumnVector | |
237 DiagMatrix::column (char *s) const | |
238 { | |
533 | 239 if (! s) |
458 | 240 { |
241 (*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
|
242 return ColumnVector (); |
458 | 243 } |
244 | |
245 char c = *s; | |
246 if (c == 'f' || c == 'F') | |
5275 | 247 return column (static_cast<octave_idx_type>(0)); |
458 | 248 else if (c == 'l' || c == 'L') |
249 return column (cols () - 1); | |
250 else | |
251 { | |
252 (*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
|
253 return ColumnVector (); |
458 | 254 } |
255 } | |
256 | |
257 DiagMatrix | |
258 DiagMatrix::inverse (void) const | |
259 { | |
8811 | 260 octave_idx_type info; |
458 | 261 return inverse (info); |
262 } | |
263 | |
264 DiagMatrix | |
8811 | 265 DiagMatrix::inverse (octave_idx_type &info) const |
458 | 266 { |
5275 | 267 octave_idx_type r = rows (); |
268 octave_idx_type c = cols (); | |
269 octave_idx_type len = length (); | |
3504 | 270 if (r != c) |
458 | 271 { |
272 (*current_liboctave_error_handler) ("inverse requires square matrix"); | |
273 return DiagMatrix (); | |
274 } | |
275 | |
3504 | 276 DiagMatrix retval (r, c); |
1627 | 277 |
458 | 278 info = 0; |
5275 | 279 for (octave_idx_type i = 0; i < len; i++) |
458 | 280 { |
281 if (elem (i, i) == 0.0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
282 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
283 info = -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
284 return *this; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
285 } |
458 | 286 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
287 retval.elem (i, i) = 1.0 / elem (i, i); |
458 | 288 } |
289 | |
1627 | 290 return retval; |
458 | 291 } |
292 | |
8840
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
293 DiagMatrix |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
294 DiagMatrix::pseudo_inverse (void) const |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
295 { |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
296 octave_idx_type r = rows (); |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
297 octave_idx_type c = cols (); |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
298 octave_idx_type len = length (); |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
299 |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
300 DiagMatrix retval (c, r); |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
301 |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
302 for (octave_idx_type i = 0; i < len; i++) |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
303 { |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
304 if (elem (i, i) != 0.0) |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
305 retval.elem (i, i) = 1.0 / elem (i, i); |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
306 else |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
307 retval.elem (i, i) = 0.0; |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
308 } |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
309 |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
310 return retval; |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
311 } |
c690e3772583
support diagonal matrices in pinv
Jaroslav Hajek <highegg@gmail.com>
parents:
8811
diff
changeset
|
312 |
458 | 313 // diagonal matrix by diagonal matrix -> diagonal matrix operations |
314 | |
315 // diagonal matrix by diagonal matrix -> diagonal matrix operations | |
316 | |
317 DiagMatrix | |
318 operator * (const DiagMatrix& a, const DiagMatrix& b) | |
319 { | |
5275 | 320 octave_idx_type a_nr = a.rows (); |
321 octave_idx_type a_nc = a.cols (); | |
2385 | 322 |
5275 | 323 octave_idx_type b_nr = b.rows (); |
324 octave_idx_type b_nc = b.cols (); | |
2385 | 325 |
3504 | 326 if (a_nc != b_nr) |
9698
7c6d5d8c8d37
fix diag*diag multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
327 gripe_nonconformant ("operator *", a_nr, a_nc, b_nr, b_nc); |
458 | 328 |
3504 | 329 DiagMatrix c (a_nr, b_nc); |
458 | 330 |
9698
7c6d5d8c8d37
fix diag*diag multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
331 octave_idx_type len = c.length (), lenm = len < a_nc ? len : a_nc; |
458 | 332 |
9698
7c6d5d8c8d37
fix diag*diag multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
333 for (octave_idx_type i = 0; i < lenm; i++) |
7c6d5d8c8d37
fix diag*diag multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
334 c.dgxelem (i) = a.dgelem (i) * b.dgelem (i); |
7c6d5d8c8d37
fix diag*diag multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
335 for (octave_idx_type i = lenm; i < len; i++) |
7c6d5d8c8d37
fix diag*diag multiplication
Jaroslav Hajek <highegg@gmail.com>
parents:
9601
diff
changeset
|
336 c.dgxelem (i) = 0.0; |
458 | 337 |
338 return c; | |
339 } | |
340 | |
341 // other operations | |
342 | |
8371
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
343 DET |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
344 DiagMatrix::determinant (void) const |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
345 { |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
346 DET det (1.0); |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
347 if (rows () != cols ()) |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
348 { |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
349 (*current_liboctave_error_handler) ("determinant requires square matrix"); |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
350 det = 0.0; |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
351 } |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
352 else |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
353 { |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
354 octave_idx_type len = length (); |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
355 for (octave_idx_type i = 0; i < len; i++) |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
356 det *= elem (i, i); |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
357 } |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
358 |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
359 return det; |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
360 } |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
361 |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
362 double |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
363 DiagMatrix::rcond (void) const |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
364 { |
15448
0a0912a9ab6e
Replace deprecated DiagArray2<T>::diag calls with DiagArray2<T>::extract_diag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15271
diff
changeset
|
365 ColumnVector av = extract_diag (0).map<double> (fabs); |
8371
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
366 double amx = av.max (), amn = av.min (); |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
367 return amx == 0 ? 0.0 : amn / amx; |
c3f7e2549abb
make det & inv aware of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
368 } |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
369 |
3504 | 370 std::ostream& |
371 operator << (std::ostream& os, const DiagMatrix& a) | |
458 | 372 { |
373 // int field_width = os.precision () + 7; | |
1360 | 374 |
5275 | 375 for (octave_idx_type i = 0; i < a.rows (); i++) |
458 | 376 { |
5275 | 377 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
|
378 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
379 if (i == j) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
380 os << " " /* setw (field_width) */ << a.elem (i, i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
381 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
382 os << " " /* setw (field_width) */ << 0.0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
383 } |
458 | 384 os << "\n"; |
385 } | |
386 return os; | |
387 } |