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