Mercurial > octave
comparison liboctave/DiagMatrix.cc @ 227:1a48a1b91489
[project @ 1993-11-15 10:10:35 by jwe]
author | jwe |
---|---|
date | Mon, 15 Nov 1993 10:11:59 +0000 |
parents | 6259f4ed7285 |
children | 780cbbc57b7c |
comparison
equal
deleted
inserted
replaced
226:c4027b057786 | 227:1a48a1b91489 |
---|---|
28 // #pragma implementation "Matrix.h" | 28 // #pragma implementation "Matrix.h" |
29 // #endif | 29 // #endif |
30 | 30 |
31 #include "Matrix.h" | 31 #include "Matrix.h" |
32 #include "mx-inlines.cc" | 32 #include "mx-inlines.cc" |
33 #include "lo-error.h" | |
33 | 34 |
34 /* | 35 /* |
35 * Diagonal Matrix class. | 36 * Diagonal Matrix class. |
36 */ | 37 */ |
37 | 38 |
38 DiagMatrix::DiagMatrix (int n) | 39 DiagMatrix::DiagMatrix (int n) |
39 { | 40 { |
40 if (n < 0) | 41 if (n < 0) |
41 FAIL; | 42 { |
43 (*current_liboctave_error_handler) | |
44 ("can't create matrix with negative dimensions"); | |
45 nr = 0; | |
46 nc = 0; | |
47 len = 0; | |
48 data = (double *) NULL; | |
49 return; | |
50 } | |
42 | 51 |
43 nr = n; | 52 nr = n; |
44 nc = n; | 53 nc = n; |
45 len = n; | 54 len = n; |
46 if (len > 0) | 55 if (len > 0) |
50 } | 59 } |
51 | 60 |
52 DiagMatrix::DiagMatrix (int n, double val) | 61 DiagMatrix::DiagMatrix (int n, double val) |
53 { | 62 { |
54 if (n < 0) | 63 if (n < 0) |
55 FAIL; | 64 { |
65 (*current_liboctave_error_handler) | |
66 ("can't create matrix with negative dimensions"); | |
67 nr = 0; | |
68 nc = 0; | |
69 len = 0; | |
70 data = (double *) NULL; | |
71 return; | |
72 } | |
56 | 73 |
57 nr = n; | 74 nr = n; |
58 nc = n; | 75 nc = n; |
59 len = n; | 76 len = n; |
60 if (len > 0) | 77 if (len > 0) |
67 } | 84 } |
68 | 85 |
69 DiagMatrix::DiagMatrix (int r, int c) | 86 DiagMatrix::DiagMatrix (int r, int c) |
70 { | 87 { |
71 if (r < 0 || c < 0) | 88 if (r < 0 || c < 0) |
72 FAIL; | 89 { |
90 (*current_liboctave_error_handler) | |
91 ("can't create matrix with negative dimensions"); | |
92 nr = 0; | |
93 nc = 0; | |
94 len = 0; | |
95 data = (double *) NULL; | |
96 return; | |
97 } | |
73 | 98 |
74 nr = r; | 99 nr = r; |
75 nc = c; | 100 nc = c; |
76 len = r < c ? r : c; | 101 len = r < c ? r : c; |
77 if (len > 0) | 102 if (len > 0) |
81 } | 106 } |
82 | 107 |
83 DiagMatrix::DiagMatrix (int r, int c, double val) | 108 DiagMatrix::DiagMatrix (int r, int c, double val) |
84 { | 109 { |
85 if (r < 0 || c < 0) | 110 if (r < 0 || c < 0) |
86 FAIL; | 111 { |
112 (*current_liboctave_error_handler) | |
113 ("can't create matrix with negative dimensions"); | |
114 nr = 0; | |
115 nc = 0; | |
116 len = 0; | |
117 data = (double *) NULL; | |
118 return; | |
119 } | |
87 | 120 |
88 nr = r; | 121 nr = r; |
89 nc = c; | 122 nc = c; |
90 len = r < c ? r : c; | 123 len = r < c ? r : c; |
91 if (len > 0) | 124 if (len > 0) |
166 data = (double *) NULL; | 199 data = (double *) NULL; |
167 } | 200 } |
168 return *this; | 201 return *this; |
169 } | 202 } |
170 | 203 |
204 double& | |
205 DiagMatrix::checkelem (int r, int c) | |
206 { | |
207 #ifndef NO_RANGE_CHECK | |
208 if (r < 0 || r >= nr || c < 0 || c >= nc) | |
209 { | |
210 (*current_liboctave_error_handler) ("range error"); | |
211 static double foo = 0.0; | |
212 return foo; | |
213 } | |
214 #endif | |
215 | |
216 return elem (r, c); | |
217 } | |
218 | |
219 double | |
220 DiagMatrix::checkelem (int r, int c) const | |
221 { | |
222 #ifndef NO_RANGE_CHECK | |
223 if (r < 0 || r >= nr || c < 0 || c >= nc) | |
224 { | |
225 (*current_liboctave_error_handler) ("range error"); | |
226 return 0.0; | |
227 } | |
228 #endif | |
229 | |
230 return elem (r, c); | |
231 } | |
232 | |
171 DiagMatrix& | 233 DiagMatrix& |
172 DiagMatrix::resize (int r, int c) | 234 DiagMatrix::resize (int r, int c) |
173 { | 235 { |
174 if (r < 0 || c < 0) | 236 if (r < 0 || c < 0) |
175 FAIL; | 237 { |
238 (*current_liboctave_error_handler) | |
239 ("can't resize to negative dimensions"); | |
240 return *this; | |
241 } | |
176 | 242 |
177 int new_len = r < c ? r : c; | 243 int new_len = r < c ? r : c; |
178 double *new_data = (double *) NULL; | 244 double *new_data = (double *) NULL; |
179 if (new_len > 0) | 245 if (new_len > 0) |
180 { | 246 { |
197 | 263 |
198 DiagMatrix& | 264 DiagMatrix& |
199 DiagMatrix::resize (int r, int c, double val) | 265 DiagMatrix::resize (int r, int c, double val) |
200 { | 266 { |
201 if (r < 0 || c < 0) | 267 if (r < 0 || c < 0) |
202 FAIL; | 268 { |
269 (*current_liboctave_error_handler) | |
270 ("can't resize to negative dimensions"); | |
271 return *this; | |
272 } | |
203 | 273 |
204 int new_len = r < c ? r : c; | 274 int new_len = r < c ? r : c; |
205 double *new_data = (double *) NULL; | 275 double *new_data = (double *) NULL; |
206 if (new_len > 0) | 276 if (new_len > 0) |
207 { | 277 { |
252 | 322 |
253 DiagMatrix& | 323 DiagMatrix& |
254 DiagMatrix::fill (double val, int beg, int end) | 324 DiagMatrix::fill (double val, int beg, int end) |
255 { | 325 { |
256 if (beg < 0 || end >= len || end < beg) | 326 if (beg < 0 || end >= len || end < beg) |
257 FAIL; | 327 { |
328 (*current_liboctave_error_handler) ("range error for fill"); | |
329 return *this; | |
330 } | |
258 | 331 |
259 if (end > beg) | 332 if (end > beg) |
260 copy (data+beg, beg-end, val); | 333 copy (data+beg, beg-end, val); |
261 return *this; | 334 return *this; |
262 } | 335 } |
263 | 336 |
264 DiagMatrix& | 337 DiagMatrix& |
265 DiagMatrix::fill (const ColumnVector& a) | 338 DiagMatrix::fill (const ColumnVector& a) |
266 { | 339 { |
267 if (a.len != len) | 340 if (a.len != len) |
268 FAIL; | 341 { |
342 (*current_liboctave_error_handler) ("range error for fill"); | |
343 return *this; | |
344 } | |
269 | 345 |
270 copy (data, a.data, len); | 346 copy (data, a.data, len); |
271 return *this; | 347 return *this; |
272 } | 348 } |
273 | 349 |
274 DiagMatrix& | 350 DiagMatrix& |
275 DiagMatrix::fill (const RowVector& a) | 351 DiagMatrix::fill (const RowVector& a) |
276 { | 352 { |
277 if (a.len != len) | 353 if (a.len != len) |
278 FAIL; | 354 { |
355 (*current_liboctave_error_handler) ("range error for fill"); | |
356 return *this; | |
357 } | |
279 | 358 |
280 copy (data, a.data, len); | 359 copy (data, a.data, len); |
281 return *this; | 360 return *this; |
282 } | 361 } |
283 | 362 |
284 DiagMatrix& | 363 DiagMatrix& |
285 DiagMatrix::fill (const ColumnVector& a, int beg) | 364 DiagMatrix::fill (const ColumnVector& a, int beg) |
286 { | 365 { |
287 if (beg < 0 || beg + a.len >= len) | 366 if (beg < 0 || beg + a.len >= len) |
288 FAIL; | 367 { |
368 (*current_liboctave_error_handler) ("range error for fill"); | |
369 return *this; | |
370 } | |
289 | 371 |
290 copy (data+beg, a.data, a.len); | 372 copy (data+beg, a.data, a.len); |
291 return *this; | 373 return *this; |
292 } | 374 } |
293 | 375 |
294 DiagMatrix& | 376 DiagMatrix& |
295 DiagMatrix::fill (const RowVector& a, int beg) | 377 DiagMatrix::fill (const RowVector& a, int beg) |
296 { | 378 { |
297 if (beg < 0 || beg + a.len >= len) | 379 if (beg < 0 || beg + a.len >= len) |
298 FAIL; | 380 { |
381 (*current_liboctave_error_handler) ("range error for fill"); | |
382 return *this; | |
383 } | |
299 | 384 |
300 copy (data+beg, a.data, a.len); | 385 copy (data+beg, a.data, a.len); |
301 return *this; | 386 return *this; |
302 } | 387 } |
303 | 388 |
329 | 414 |
330 RowVector | 415 RowVector |
331 DiagMatrix::row (int i) const | 416 DiagMatrix::row (int i) const |
332 { | 417 { |
333 if (i < 0 || i >= nr) | 418 if (i < 0 || i >= nr) |
334 FAIL; | 419 { |
420 (*current_liboctave_error_handler) ("invalid row selection"); | |
421 return RowVector (); | |
422 } | |
335 | 423 |
336 RowVector retval (nc, 0.0); | 424 RowVector retval (nc, 0.0); |
337 if (nr <= nc || (nr > nc && i < nc)) | 425 if (nr <= nc || (nr > nc && i < nc)) |
338 retval.data [i] = data[i]; | 426 retval.data [i] = data[i]; |
339 | 427 |
342 | 430 |
343 RowVector | 431 RowVector |
344 DiagMatrix::row (char *s) const | 432 DiagMatrix::row (char *s) const |
345 { | 433 { |
346 if (s == (char *) NULL) | 434 if (s == (char *) NULL) |
347 FAIL; | 435 { |
436 (*current_liboctave_error_handler) ("invalid row selection"); | |
437 return RowVector (); | |
438 } | |
348 | 439 |
349 char c = *s; | 440 char c = *s; |
350 if (c == 'f' || c == 'F') | 441 if (c == 'f' || c == 'F') |
351 return row (0); | 442 return row (0); |
352 else if (c == 'l' || c == 'L') | 443 else if (c == 'l' || c == 'L') |
353 return row (nr - 1); | 444 return row (nr - 1); |
354 else | 445 else |
355 FAIL; | 446 { |
447 (*current_liboctave_error_handler) ("invalid row selection"); | |
448 return RowVector (); | |
449 } | |
356 } | 450 } |
357 | 451 |
358 ColumnVector | 452 ColumnVector |
359 DiagMatrix::column (int i) const | 453 DiagMatrix::column (int i) const |
360 { | 454 { |
361 if (i < 0 || i >= nc) | 455 if (i < 0 || i >= nc) |
362 FAIL; | 456 { |
457 (*current_liboctave_error_handler) ("invalid column selection"); | |
458 return ColumnVector (); | |
459 } | |
363 | 460 |
364 ColumnVector retval (nr, 0.0); | 461 ColumnVector retval (nr, 0.0); |
365 if (nr >= nc || (nr < nc && i < nr)) | 462 if (nr >= nc || (nr < nc && i < nr)) |
366 retval.data [i] = data[i]; | 463 retval.data [i] = data[i]; |
367 | 464 |
370 | 467 |
371 ColumnVector | 468 ColumnVector |
372 DiagMatrix::column (char *s) const | 469 DiagMatrix::column (char *s) const |
373 { | 470 { |
374 if (s == (char *) NULL) | 471 if (s == (char *) NULL) |
375 FAIL; | 472 { |
473 (*current_liboctave_error_handler) ("invalid column selection"); | |
474 return ColumnVector (); | |
475 } | |
376 | 476 |
377 char c = *s; | 477 char c = *s; |
378 if (c == 'f' || c == 'F') | 478 if (c == 'f' || c == 'F') |
379 return column (0); | 479 return column (0); |
380 else if (c == 'l' || c == 'L') | 480 else if (c == 'l' || c == 'L') |
381 return column (nc - 1); | 481 return column (nc - 1); |
382 else | 482 else |
383 FAIL; | 483 { |
484 (*current_liboctave_error_handler) ("invalid column selection"); | |
485 return ColumnVector (); | |
486 } | |
384 } | 487 } |
385 | 488 |
386 DiagMatrix | 489 DiagMatrix |
387 DiagMatrix::inverse (int &info) const | 490 DiagMatrix::inverse (int &info) const |
388 { | 491 { |
389 if (nr != nc) | 492 if (nr != nc) |
390 FAIL; | 493 { |
494 (*current_liboctave_error_handler) ("inverse requires square matrix"); | |
495 return DiagMatrix (); | |
496 } | |
391 | 497 |
392 info = 0; | 498 info = 0; |
393 double *tmp_data = dup (data, len); | 499 double *tmp_data = dup (data, len); |
394 for (int i = 0; i < len; i++) | 500 for (int i = 0; i < len; i++) |
395 { | 501 { |
503 | 609 |
504 ColumnVector | 610 ColumnVector |
505 DiagMatrix::operator * (const ColumnVector& a) const | 611 DiagMatrix::operator * (const ColumnVector& a) const |
506 { | 612 { |
507 if (nc != a.len) | 613 if (nc != a.len) |
508 FAIL; | 614 { |
615 (*current_liboctave_error_handler) | |
616 ("nonconformant matrix multiplication attempted"); | |
617 return ColumnVector (); | |
618 } | |
509 | 619 |
510 if (nc == 0 || nr == 0) | 620 if (nc == 0 || nr == 0) |
511 return ColumnVector (0); | 621 return ColumnVector (0); |
512 | 622 |
513 ColumnVector result (nr); | 623 ColumnVector result (nr); |
523 | 633 |
524 ComplexColumnVector | 634 ComplexColumnVector |
525 DiagMatrix::operator * (const ComplexColumnVector& a) const | 635 DiagMatrix::operator * (const ComplexColumnVector& a) const |
526 { | 636 { |
527 if (nc != a.len) | 637 if (nc != a.len) |
528 FAIL; | 638 { |
639 (*current_liboctave_error_handler) | |
640 ("nonconformant matrix multiplication attempted"); | |
641 return ColumnVector (); | |
642 } | |
529 | 643 |
530 if (nc == 0 || nr == 0) | 644 if (nc == 0 || nr == 0) |
531 return ComplexColumnVector (0); | 645 return ComplexColumnVector (0); |
532 | 646 |
533 ComplexColumnVector result (nr); | 647 ComplexColumnVector result (nr); |
545 | 659 |
546 DiagMatrix | 660 DiagMatrix |
547 DiagMatrix::operator + (const DiagMatrix& a) const | 661 DiagMatrix::operator + (const DiagMatrix& a) const |
548 { | 662 { |
549 if (nr != a.nr || nc != a.nc) | 663 if (nr != a.nr || nc != a.nc) |
550 FAIL; | 664 { |
665 (*current_liboctave_error_handler) | |
666 ("nonconformant matrix addition attempted"); | |
667 return DiagMatrix (); | |
668 } | |
551 | 669 |
552 if (nc == 0 || nr == 0) | 670 if (nc == 0 || nr == 0) |
553 return DiagMatrix (nr, nc); | 671 return DiagMatrix (nr, nc); |
554 | 672 |
555 return DiagMatrix (add (data, a.data, len), nr , nc); | 673 return DiagMatrix (add (data, a.data, len), nr , nc); |
557 | 675 |
558 DiagMatrix | 676 DiagMatrix |
559 DiagMatrix::operator - (const DiagMatrix& a) const | 677 DiagMatrix::operator - (const DiagMatrix& a) const |
560 { | 678 { |
561 if (nr != a.nr || nc != a.nc) | 679 if (nr != a.nr || nc != a.nc) |
562 FAIL; | 680 { |
681 (*current_liboctave_error_handler) | |
682 ("nonconformant matrix subtraction attempted"); | |
683 return DiagMatrix (); | |
684 } | |
563 | 685 |
564 if (nc == 0 || nr == 0) | 686 if (nc == 0 || nr == 0) |
565 return DiagMatrix (nr, nc); | 687 return DiagMatrix (nr, nc); |
566 | 688 |
567 return DiagMatrix (subtract (data, a.data, len), nr, nc); | 689 return DiagMatrix (subtract (data, a.data, len), nr, nc); |
569 | 691 |
570 DiagMatrix | 692 DiagMatrix |
571 DiagMatrix::operator * (const DiagMatrix& a) const | 693 DiagMatrix::operator * (const DiagMatrix& a) const |
572 { | 694 { |
573 if (nr != a.nr || nc != a.nc) | 695 if (nr != a.nr || nc != a.nc) |
574 FAIL; | 696 { |
697 (*current_liboctave_error_handler) | |
698 ("nonconformant matrix multiplication attempted"); | |
699 return DiagMatrix (); | |
700 } | |
575 | 701 |
576 if (nc == 0 || nr == 0) | 702 if (nc == 0 || nr == 0) |
577 return DiagMatrix (nr, nc); | 703 return DiagMatrix (nr, nc); |
578 | 704 |
579 return DiagMatrix (multiply (data, a.data, len), nr, nc); | 705 return DiagMatrix (multiply (data, a.data, len), nr, nc); |
581 | 707 |
582 ComplexDiagMatrix | 708 ComplexDiagMatrix |
583 DiagMatrix::operator + (const ComplexDiagMatrix& a) const | 709 DiagMatrix::operator + (const ComplexDiagMatrix& a) const |
584 { | 710 { |
585 if (nr != a.nr || nc != a.nc) | 711 if (nr != a.nr || nc != a.nc) |
586 FAIL; | 712 { |
713 (*current_liboctave_error_handler) | |
714 ("nonconformant matrix addition attempted"); | |
715 return ComplexDiagMatrix (); | |
716 } | |
587 | 717 |
588 if (nc == 0 || nr == 0) | 718 if (nc == 0 || nr == 0) |
589 return ComplexDiagMatrix (nr, nc); | 719 return ComplexDiagMatrix (nr, nc); |
590 | 720 |
591 return ComplexDiagMatrix (add (data, a.data, len), nr , nc); | 721 return ComplexDiagMatrix (add (data, a.data, len), nr , nc); |
593 | 723 |
594 ComplexDiagMatrix | 724 ComplexDiagMatrix |
595 DiagMatrix::operator - (const ComplexDiagMatrix& a) const | 725 DiagMatrix::operator - (const ComplexDiagMatrix& a) const |
596 { | 726 { |
597 if (nr != a.nr || nc != a.nc) | 727 if (nr != a.nr || nc != a.nc) |
598 FAIL; | 728 { |
729 (*current_liboctave_error_handler) | |
730 ("nonconformant matrix subtraction attempted"); | |
731 return ComplexDiagMatrix (); | |
732 } | |
599 | 733 |
600 if (nc == 0 || nr == 0) | 734 if (nc == 0 || nr == 0) |
601 return ComplexDiagMatrix (nr, nc); | 735 return ComplexDiagMatrix (nr, nc); |
602 | 736 |
603 return ComplexDiagMatrix (subtract (data, a.data, len), nr, nc); | 737 return ComplexDiagMatrix (subtract (data, a.data, len), nr, nc); |
605 | 739 |
606 ComplexDiagMatrix | 740 ComplexDiagMatrix |
607 DiagMatrix::operator * (const ComplexDiagMatrix& a) const | 741 DiagMatrix::operator * (const ComplexDiagMatrix& a) const |
608 { | 742 { |
609 if (nr != a.nr || nc != a.nc) | 743 if (nr != a.nr || nc != a.nc) |
610 FAIL; | 744 { |
745 (*current_liboctave_error_handler) | |
746 ("nonconformant matrix multiplication attempted"); | |
747 return ComplexDiagMatrix (); | |
748 } | |
611 | 749 |
612 if (nc == 0 || nr == 0) | 750 if (nc == 0 || nr == 0) |
613 return ComplexDiagMatrix (nr, nc); | 751 return ComplexDiagMatrix (nr, nc); |
614 | 752 |
615 return ComplexDiagMatrix (multiply (data, a.data, len), nr, nc); | 753 return ComplexDiagMatrix (multiply (data, a.data, len), nr, nc); |
617 | 755 |
618 DiagMatrix | 756 DiagMatrix |
619 DiagMatrix::product (const DiagMatrix& a) const | 757 DiagMatrix::product (const DiagMatrix& a) const |
620 { | 758 { |
621 if (nr != a.nr || nc != a.nc) | 759 if (nr != a.nr || nc != a.nc) |
622 FAIL; | 760 { |
761 (*current_liboctave_error_handler) | |
762 ("nonconformant matrix product attempted"); | |
763 return DiagMatrix (); | |
764 } | |
623 | 765 |
624 if (nc == 0 || nr == 0) | 766 if (nc == 0 || nr == 0) |
625 return DiagMatrix (nr, nc); | 767 return DiagMatrix (nr, nc); |
626 | 768 |
627 return DiagMatrix (multiply (data, a.data, len), nr, nc); | 769 return DiagMatrix (multiply (data, a.data, len), nr, nc); |
629 | 771 |
630 DiagMatrix | 772 DiagMatrix |
631 DiagMatrix::quotient (const DiagMatrix& a) const | 773 DiagMatrix::quotient (const DiagMatrix& a) const |
632 { | 774 { |
633 if (nr != a.nr || nc != a.nc) | 775 if (nr != a.nr || nc != a.nc) |
634 FAIL; | 776 { |
777 (*current_liboctave_error_handler) | |
778 ("nonconformant matrix quotient attempted"); | |
779 return DiagMatrix (); | |
780 } | |
635 | 781 |
636 if (nc == 0 || nr == 0) | 782 if (nc == 0 || nr == 0) |
637 return DiagMatrix (nr, nc); | 783 return DiagMatrix (nr, nc); |
638 | 784 |
639 return DiagMatrix (divide (data, a.data, len), nr, nc); | 785 return DiagMatrix (divide (data, a.data, len), nr, nc); |
641 | 787 |
642 ComplexDiagMatrix | 788 ComplexDiagMatrix |
643 DiagMatrix::product (const ComplexDiagMatrix& a) const | 789 DiagMatrix::product (const ComplexDiagMatrix& a) const |
644 { | 790 { |
645 if (nr != a.nr || nc != a.nc) | 791 if (nr != a.nr || nc != a.nc) |
646 FAIL; | 792 { |
793 (*current_liboctave_error_handler) | |
794 ("nonconformant matrix product attempted"); | |
795 return ComplexDiagMatrix (); | |
796 } | |
647 | 797 |
648 if (nc == 0 || nr == 0) | 798 if (nc == 0 || nr == 0) |
649 return ComplexDiagMatrix (nr, nc); | 799 return ComplexDiagMatrix (nr, nc); |
650 | 800 |
651 return ComplexDiagMatrix (multiply (data, a.data, len), nr, nc); | 801 return ComplexDiagMatrix (multiply (data, a.data, len), nr, nc); |
653 | 803 |
654 ComplexDiagMatrix | 804 ComplexDiagMatrix |
655 DiagMatrix::quotient (const ComplexDiagMatrix& a) const | 805 DiagMatrix::quotient (const ComplexDiagMatrix& a) const |
656 { | 806 { |
657 if (nr != a.nr || nc != a.nc) | 807 if (nr != a.nr || nc != a.nc) |
658 FAIL; | 808 { |
809 (*current_liboctave_error_handler) | |
810 ("nonconformant matrix quotient attempted"); | |
811 return ComplexDiagMatrix (); | |
812 } | |
659 | 813 |
660 if (nc == 0 || nr == 0) | 814 if (nc == 0 || nr == 0) |
661 return ComplexDiagMatrix (nr, nc); | 815 return ComplexDiagMatrix (nr, nc); |
662 | 816 |
663 return ComplexDiagMatrix (divide (data, a.data, len), nr, nc); | 817 return ComplexDiagMatrix (divide (data, a.data, len), nr, nc); |
665 | 819 |
666 DiagMatrix& | 820 DiagMatrix& |
667 DiagMatrix::operator += (const DiagMatrix& a) | 821 DiagMatrix::operator += (const DiagMatrix& a) |
668 { | 822 { |
669 if (nr != a.nr || nc != a.nc) | 823 if (nr != a.nr || nc != a.nc) |
670 FAIL; | 824 { |
825 (*current_liboctave_error_handler) | |
826 ("nonconformant matrix += operation attempted"); | |
827 return *this; | |
828 } | |
671 | 829 |
672 if (nc == 0 || nr == 0) | 830 if (nc == 0 || nr == 0) |
673 return *this; | 831 return *this; |
674 | 832 |
675 add2 (data, a.data, len); | 833 add2 (data, a.data, len); |
678 | 836 |
679 DiagMatrix& | 837 DiagMatrix& |
680 DiagMatrix::operator -= (const DiagMatrix& a) | 838 DiagMatrix::operator -= (const DiagMatrix& a) |
681 { | 839 { |
682 if (nr != a.nr || nc != a.nc) | 840 if (nr != a.nr || nc != a.nc) |
683 FAIL; | 841 { |
842 (*current_liboctave_error_handler) | |
843 ("nonconformant matrix -= operation attempted"); | |
844 return *this; | |
845 } | |
684 | 846 |
685 if (nr == 0 || nc == 0) | 847 if (nr == 0 || nc == 0) |
686 | 848 |
687 subtract2 (data, a.data, len); | 849 subtract2 (data, a.data, len); |
688 return *this; | 850 return *this; |
692 | 854 |
693 Matrix | 855 Matrix |
694 DiagMatrix::operator + (const Matrix& a) const | 856 DiagMatrix::operator + (const Matrix& a) const |
695 { | 857 { |
696 if (nr != a.nr || nc != a.nc) | 858 if (nr != a.nr || nc != a.nc) |
697 FAIL; | 859 { |
860 (*current_liboctave_error_handler) | |
861 ("nonconformant matrix addition attempted"); | |
862 return Matrix (); | |
863 } | |
698 | 864 |
699 if (nr == 0 || nc == 0) | 865 if (nr == 0 || nc == 0) |
700 return Matrix (nr, nc); | 866 return Matrix (nr, nc); |
701 | 867 |
702 Matrix result (a); | 868 Matrix result (a); |
708 | 874 |
709 Matrix | 875 Matrix |
710 DiagMatrix::operator - (const Matrix& a) const | 876 DiagMatrix::operator - (const Matrix& a) const |
711 { | 877 { |
712 if (nr != a.nr || nc != a.nc) | 878 if (nr != a.nr || nc != a.nc) |
713 FAIL; | 879 { |
880 (*current_liboctave_error_handler) | |
881 ("nonconformant matrix subtraction attempted"); | |
882 return Matrix (); | |
883 } | |
714 | 884 |
715 if (nr == 0 || nc == 0) | 885 if (nr == 0 || nc == 0) |
716 return Matrix (nr, nc); | 886 return Matrix (nr, nc); |
717 | 887 |
718 Matrix result (-a); | 888 Matrix result (-a); |
724 | 894 |
725 Matrix | 895 Matrix |
726 DiagMatrix::operator * (const Matrix& a) const | 896 DiagMatrix::operator * (const Matrix& a) const |
727 { | 897 { |
728 if (nc != a.nr) | 898 if (nc != a.nr) |
729 FAIL; | 899 { |
900 (*current_liboctave_error_handler) | |
901 ("nonconformant matrix multiplication attempted"); | |
902 return Matrix (); | |
903 } | |
730 | 904 |
731 if (nr == 0 || nc == 0 || a.nc == 0) | 905 if (nr == 0 || nc == 0 || a.nc == 0) |
732 return Matrix (nr, a.nc, 0.0); | 906 return Matrix (nr, a.nc, 0.0); |
733 | 907 |
734 Matrix c (nr, a.nc); | 908 Matrix c (nr, a.nc); |
764 | 938 |
765 ComplexMatrix | 939 ComplexMatrix |
766 DiagMatrix::operator + (const ComplexMatrix& a) const | 940 DiagMatrix::operator + (const ComplexMatrix& a) const |
767 { | 941 { |
768 if (nr != a.nr || nc != a.nc) | 942 if (nr != a.nr || nc != a.nc) |
769 FAIL; | 943 { |
944 (*current_liboctave_error_handler) | |
945 ("nonconformant matrix addition attempted"); | |
946 return ComplexMatrix (); | |
947 } | |
770 | 948 |
771 if (nr == 0 || nc == 0) | 949 if (nr == 0 || nc == 0) |
772 return ComplexMatrix (nr, nc); | 950 return ComplexMatrix (nr, nc); |
773 | 951 |
774 ComplexMatrix result (a); | 952 ComplexMatrix result (a); |
780 | 958 |
781 ComplexMatrix | 959 ComplexMatrix |
782 DiagMatrix::operator - (const ComplexMatrix& a) const | 960 DiagMatrix::operator - (const ComplexMatrix& a) const |
783 { | 961 { |
784 if (nr != a.nr || nc != a.nc) | 962 if (nr != a.nr || nc != a.nc) |
785 FAIL; | 963 { |
964 (*current_liboctave_error_handler) | |
965 ("nonconformant matrix subtraction attempted"); | |
966 return ComplexMatrix (); | |
967 } | |
786 | 968 |
787 if (nr == 0 || nc == 0) | 969 if (nr == 0 || nc == 0) |
788 return ComplexMatrix (nr, nc); | 970 return ComplexMatrix (nr, nc); |
789 | 971 |
790 ComplexMatrix result (-a); | 972 ComplexMatrix result (-a); |
796 | 978 |
797 ComplexMatrix | 979 ComplexMatrix |
798 DiagMatrix::operator * (const ComplexMatrix& a) const | 980 DiagMatrix::operator * (const ComplexMatrix& a) const |
799 { | 981 { |
800 if (nc != a.nr) | 982 if (nc != a.nr) |
801 FAIL; | 983 { |
984 (*current_liboctave_error_handler) | |
985 ("nonconformant matrix multiplication attempted"); | |
986 return ComplexMatrix (); | |
987 } | |
802 | 988 |
803 if (nr == 0 || nc == 0 || a.nc == 0) | 989 if (nr == 0 || nc == 0 || a.nc == 0) |
804 return ComplexMatrix (nr, nc, 0.0); | 990 return ComplexMatrix (nr, nc, 0.0); |
805 | 991 |
806 ComplexMatrix c (nr, a.nc); | 992 ComplexMatrix c (nr, a.nc); |
914 */ | 1100 */ |
915 | 1101 |
916 ComplexDiagMatrix::ComplexDiagMatrix (int n) | 1102 ComplexDiagMatrix::ComplexDiagMatrix (int n) |
917 { | 1103 { |
918 if (n < 0) | 1104 if (n < 0) |
919 FAIL; | 1105 { |
1106 (*current_liboctave_error_handler) | |
1107 ("can't create matrix with negative dimensions"); | |
1108 nr = 0; | |
1109 nc = 0; | |
1110 len = 0; | |
1111 data = (Complex *) NULL; | |
1112 return; | |
1113 } | |
920 | 1114 |
921 nr = n; | 1115 nr = n; |
922 nc = n; | 1116 nc = n; |
923 len = n; | 1117 len = n; |
924 if (len > 0) | 1118 if (len > 0) |
928 } | 1122 } |
929 | 1123 |
930 ComplexDiagMatrix::ComplexDiagMatrix (int n, double val) | 1124 ComplexDiagMatrix::ComplexDiagMatrix (int n, double val) |
931 { | 1125 { |
932 if (n < 0) | 1126 if (n < 0) |
933 FAIL; | 1127 { |
1128 (*current_liboctave_error_handler) | |
1129 ("can't create matrix with negative dimensions"); | |
1130 nr = 0; | |
1131 nc = 0; | |
1132 len = 0; | |
1133 data = (Complex *) NULL; | |
1134 return; | |
1135 } | |
934 | 1136 |
935 nr = n; | 1137 nr = n; |
936 nc = n; | 1138 nc = n; |
937 len = n; | 1139 len = n; |
938 if (len > 0) | 1140 if (len > 0) |
945 } | 1147 } |
946 | 1148 |
947 ComplexDiagMatrix::ComplexDiagMatrix (int n, const Complex& val) | 1149 ComplexDiagMatrix::ComplexDiagMatrix (int n, const Complex& val) |
948 { | 1150 { |
949 if (n < 0) | 1151 if (n < 0) |
950 FAIL; | 1152 { |
1153 (*current_liboctave_error_handler) | |
1154 ("can't create matrix with negative dimensions"); | |
1155 nr = 0; | |
1156 nc = 0; | |
1157 len = 0; | |
1158 data = (Complex *) NULL; | |
1159 return; | |
1160 } | |
951 | 1161 |
952 nr = n; | 1162 nr = n; |
953 nc = n; | 1163 nc = n; |
954 len = n; | 1164 len = n; |
955 if (len > 0) | 1165 if (len > 0) |
962 } | 1172 } |
963 | 1173 |
964 ComplexDiagMatrix::ComplexDiagMatrix (int r, int c) | 1174 ComplexDiagMatrix::ComplexDiagMatrix (int r, int c) |
965 { | 1175 { |
966 if (r < 0 || c < 0) | 1176 if (r < 0 || c < 0) |
967 FAIL; | 1177 { |
1178 (*current_liboctave_error_handler) | |
1179 ("can't create matrix with negative dimensions"); | |
1180 nr = 0; | |
1181 nc = 0; | |
1182 len = 0; | |
1183 data = (Complex *) NULL; | |
1184 return; | |
1185 } | |
968 | 1186 |
969 nr = r; | 1187 nr = r; |
970 nc = c; | 1188 nc = c; |
971 len = r < c ? r : c; | 1189 len = r < c ? r : c; |
972 if (len > 0) | 1190 if (len > 0) |
976 } | 1194 } |
977 | 1195 |
978 ComplexDiagMatrix::ComplexDiagMatrix (int r, int c, double val) | 1196 ComplexDiagMatrix::ComplexDiagMatrix (int r, int c, double val) |
979 { | 1197 { |
980 if (r < 0 || c < 0) | 1198 if (r < 0 || c < 0) |
981 FAIL; | 1199 { |
1200 (*current_liboctave_error_handler) | |
1201 ("can't create matrix with negative dimensions"); | |
1202 nr = 0; | |
1203 nc = 0; | |
1204 len = 0; | |
1205 data = (Complex *) NULL; | |
1206 return; | |
1207 } | |
982 | 1208 |
983 nr = r; | 1209 nr = r; |
984 nc = c; | 1210 nc = c; |
985 len = r < c ? r : c; | 1211 len = r < c ? r : c; |
986 if (len > 0) | 1212 if (len > 0) |
993 } | 1219 } |
994 | 1220 |
995 ComplexDiagMatrix::ComplexDiagMatrix (int r, int c, const Complex& val) | 1221 ComplexDiagMatrix::ComplexDiagMatrix (int r, int c, const Complex& val) |
996 { | 1222 { |
997 if (r < 0 || c < 0) | 1223 if (r < 0 || c < 0) |
998 FAIL; | 1224 { |
1225 (*current_liboctave_error_handler) | |
1226 ("can't create matrix with negative dimensions"); | |
1227 nr = 0; | |
1228 nc = 0; | |
1229 len = 0; | |
1230 data = (Complex *) NULL; | |
1231 return; | |
1232 } | |
999 | 1233 |
1000 nr = r; | 1234 nr = r; |
1001 nc = c; | 1235 nc = c; |
1002 len = r < c ? r : c; | 1236 len = r < c ? r : c; |
1003 if (len > 0) | 1237 if (len > 0) |
1147 data = (Complex *) NULL; | 1381 data = (Complex *) NULL; |
1148 } | 1382 } |
1149 return *this; | 1383 return *this; |
1150 } | 1384 } |
1151 | 1385 |
1386 Complex& | |
1387 ComplexDiagMatrix::checkelem (int r, int c) | |
1388 { | |
1389 #ifndef NO_RANGE_CHECK | |
1390 if (r < 0 || r >= nr || c < 0 || c >= nc) | |
1391 { | |
1392 (*current_liboctave_error_handler) ("range error"); | |
1393 static Complex foo (0.0); | |
1394 return foo; | |
1395 } | |
1396 #endif | |
1397 | |
1398 return elem (r, c); | |
1399 } | |
1400 | |
1401 Complex | |
1402 ComplexDiagMatrix::checkelem (int r, int c) const | |
1403 { | |
1404 #ifndef NO_RANGE_CHECK | |
1405 if (r < 0 || r >= nr || c < 0 || c >= nc) | |
1406 { | |
1407 (*current_liboctave_error_handler) ("range error"); | |
1408 return Complex (0.0); | |
1409 } | |
1410 #endif | |
1411 | |
1412 return elem (r, c); | |
1413 } | |
1414 | |
1152 ComplexDiagMatrix& | 1415 ComplexDiagMatrix& |
1153 ComplexDiagMatrix::resize (int r, int c) | 1416 ComplexDiagMatrix::resize (int r, int c) |
1154 { | 1417 { |
1155 if (r < 0 || c < 0) | 1418 if (r < 0 || c < 0) |
1156 FAIL; | 1419 { |
1420 (*current_liboctave_error_handler) | |
1421 ("can't resize to negative dimensions"); | |
1422 return *this; | |
1423 } | |
1157 | 1424 |
1158 int new_len = r < c ? r : c; | 1425 int new_len = r < c ? r : c; |
1159 Complex *new_data = (Complex *) NULL; | 1426 Complex *new_data = (Complex *) NULL; |
1160 if (new_len > 0) | 1427 if (new_len > 0) |
1161 { | 1428 { |
1178 | 1445 |
1179 ComplexDiagMatrix& | 1446 ComplexDiagMatrix& |
1180 ComplexDiagMatrix::resize (int r, int c, double val) | 1447 ComplexDiagMatrix::resize (int r, int c, double val) |
1181 { | 1448 { |
1182 if (r < 0 || c < 0) | 1449 if (r < 0 || c < 0) |
1183 FAIL; | 1450 { |
1451 (*current_liboctave_error_handler) | |
1452 ("can't resize to negative dimensions"); | |
1453 return *this; | |
1454 } | |
1184 | 1455 |
1185 int new_len = r < c ? r : c; | 1456 int new_len = r < c ? r : c; |
1186 Complex *new_data = (Complex *) NULL; | 1457 Complex *new_data = (Complex *) NULL; |
1187 if (new_len > 0) | 1458 if (new_len > 0) |
1188 { | 1459 { |
1208 | 1479 |
1209 ComplexDiagMatrix& | 1480 ComplexDiagMatrix& |
1210 ComplexDiagMatrix::resize (int r, int c, const Complex& val) | 1481 ComplexDiagMatrix::resize (int r, int c, const Complex& val) |
1211 { | 1482 { |
1212 if (r < 0 || c < 0) | 1483 if (r < 0 || c < 0) |
1213 FAIL; | 1484 { |
1485 (*current_liboctave_error_handler) | |
1486 ("can't resize to negative dimensions"); | |
1487 return *this; | |
1488 } | |
1214 | 1489 |
1215 int new_len = r < c ? r : c; | 1490 int new_len = r < c ? r : c; |
1216 Complex *new_data = (Complex *) NULL; | 1491 Complex *new_data = (Complex *) NULL; |
1217 if (new_len > 0) | 1492 if (new_len > 0) |
1218 { | 1493 { |
1276 | 1551 |
1277 ComplexDiagMatrix& | 1552 ComplexDiagMatrix& |
1278 ComplexDiagMatrix::fill (double val, int beg, int end) | 1553 ComplexDiagMatrix::fill (double val, int beg, int end) |
1279 { | 1554 { |
1280 if (beg < 0 || end >= len || end < beg) | 1555 if (beg < 0 || end >= len || end < beg) |
1281 FAIL; | 1556 { |
1557 (*current_liboctave_error_handler) ("range error for fill"); | |
1558 return *this; | |
1559 } | |
1282 | 1560 |
1283 if (end > beg) | 1561 if (end > beg) |
1284 copy (data+beg, beg-end, val); | 1562 copy (data+beg, beg-end, val); |
1285 return *this; | 1563 return *this; |
1286 } | 1564 } |
1287 | 1565 |
1288 ComplexDiagMatrix& | 1566 ComplexDiagMatrix& |
1289 ComplexDiagMatrix::fill (const Complex& val, int beg, int end) | 1567 ComplexDiagMatrix::fill (const Complex& val, int beg, int end) |
1290 { | 1568 { |
1291 if (beg < 0 || end >= len || end < beg) | 1569 if (beg < 0 || end >= len || end < beg) |
1292 FAIL; | 1570 { |
1571 (*current_liboctave_error_handler) ("range error for fill"); | |
1572 return *this; | |
1573 } | |
1293 | 1574 |
1294 if (end > beg) | 1575 if (end > beg) |
1295 copy (data+beg, beg-end, val); | 1576 copy (data+beg, beg-end, val); |
1296 return *this; | 1577 return *this; |
1297 } | 1578 } |
1298 | 1579 |
1299 ComplexDiagMatrix& | 1580 ComplexDiagMatrix& |
1300 ComplexDiagMatrix::fill (const ColumnVector& a) | 1581 ComplexDiagMatrix::fill (const ColumnVector& a) |
1301 { | 1582 { |
1302 if (a.len != len) | 1583 if (a.len != len) |
1303 FAIL; | 1584 { |
1585 (*current_liboctave_error_handler) ("range error for fill"); | |
1586 return *this; | |
1587 } | |
1304 | 1588 |
1305 copy (data, a.data, len); | 1589 copy (data, a.data, len); |
1306 return *this; | 1590 return *this; |
1307 } | 1591 } |
1308 | 1592 |
1309 ComplexDiagMatrix& | 1593 ComplexDiagMatrix& |
1310 ComplexDiagMatrix::fill (const ComplexColumnVector& a) | 1594 ComplexDiagMatrix::fill (const ComplexColumnVector& a) |
1311 { | 1595 { |
1312 if (a.len != len) | 1596 if (a.len != len) |
1313 FAIL; | 1597 { |
1598 (*current_liboctave_error_handler) ("range error for fill"); | |
1599 return *this; | |
1600 } | |
1314 | 1601 |
1315 copy (data, a.data, len); | 1602 copy (data, a.data, len); |
1316 return *this; | 1603 return *this; |
1317 } | 1604 } |
1318 | 1605 |
1319 ComplexDiagMatrix& | 1606 ComplexDiagMatrix& |
1320 ComplexDiagMatrix::fill (const RowVector& a) | 1607 ComplexDiagMatrix::fill (const RowVector& a) |
1321 { | 1608 { |
1322 if (a.len != len) | 1609 if (a.len != len) |
1323 FAIL; | 1610 { |
1611 (*current_liboctave_error_handler) ("range error for fill"); | |
1612 return *this; | |
1613 } | |
1324 | 1614 |
1325 copy (data, a.data, len); | 1615 copy (data, a.data, len); |
1326 return *this; | 1616 return *this; |
1327 } | 1617 } |
1328 | 1618 |
1329 ComplexDiagMatrix& | 1619 ComplexDiagMatrix& |
1330 ComplexDiagMatrix::fill (const ComplexRowVector& a) | 1620 ComplexDiagMatrix::fill (const ComplexRowVector& a) |
1331 { | 1621 { |
1332 if (a.len != len) | 1622 if (a.len != len) |
1333 FAIL; | 1623 { |
1624 (*current_liboctave_error_handler) ("range error for fill"); | |
1625 return *this; | |
1626 } | |
1334 | 1627 |
1335 copy (data, a.data, len); | 1628 copy (data, a.data, len); |
1336 return *this; | 1629 return *this; |
1337 } | 1630 } |
1338 | 1631 |
1339 ComplexDiagMatrix& | 1632 ComplexDiagMatrix& |
1340 ComplexDiagMatrix::fill (const ColumnVector& a, int beg) | 1633 ComplexDiagMatrix::fill (const ColumnVector& a, int beg) |
1341 { | 1634 { |
1342 if (beg < 0 || beg + a.len >= len) | 1635 if (beg < 0 || beg + a.len >= len) |
1343 FAIL; | 1636 { |
1637 (*current_liboctave_error_handler) ("range error for fill"); | |
1638 return *this; | |
1639 } | |
1344 | 1640 |
1345 copy (data+beg, a.data, a.len); | 1641 copy (data+beg, a.data, a.len); |
1346 return *this; | 1642 return *this; |
1347 } | 1643 } |
1348 | 1644 |
1349 ComplexDiagMatrix& | 1645 ComplexDiagMatrix& |
1350 ComplexDiagMatrix::fill (const ComplexColumnVector& a, int beg) | 1646 ComplexDiagMatrix::fill (const ComplexColumnVector& a, int beg) |
1351 { | 1647 { |
1352 if (beg < 0 || beg + a.len >= len) | 1648 if (beg < 0 || beg + a.len >= len) |
1353 FAIL; | 1649 { |
1650 (*current_liboctave_error_handler) ("range error for fill"); | |
1651 return *this; | |
1652 } | |
1354 | 1653 |
1355 copy (data+beg, a.data, a.len); | 1654 copy (data+beg, a.data, a.len); |
1356 return *this; | 1655 return *this; |
1357 } | 1656 } |
1358 | 1657 |
1359 ComplexDiagMatrix& | 1658 ComplexDiagMatrix& |
1360 ComplexDiagMatrix::fill (const RowVector& a, int beg) | 1659 ComplexDiagMatrix::fill (const RowVector& a, int beg) |
1361 { | 1660 { |
1362 if (beg < 0 || beg + a.len >= len) | 1661 if (beg < 0 || beg + a.len >= len) |
1363 FAIL; | 1662 { |
1663 (*current_liboctave_error_handler) ("range error for fill"); | |
1664 return *this; | |
1665 } | |
1364 | 1666 |
1365 copy (data+beg, a.data, a.len); | 1667 copy (data+beg, a.data, a.len); |
1366 return *this; | 1668 return *this; |
1367 } | 1669 } |
1368 | 1670 |
1369 ComplexDiagMatrix& | 1671 ComplexDiagMatrix& |
1370 ComplexDiagMatrix::fill (const ComplexRowVector& a, int beg) | 1672 ComplexDiagMatrix::fill (const ComplexRowVector& a, int beg) |
1371 { | 1673 { |
1372 if (beg < 0 || beg + a.len >= len) | 1674 if (beg < 0 || beg + a.len >= len) |
1373 FAIL; | 1675 { |
1676 (*current_liboctave_error_handler) ("range error for fill"); | |
1677 return *this; | |
1678 } | |
1374 | 1679 |
1375 copy (data+beg, a.data, a.len); | 1680 copy (data+beg, a.data, a.len); |
1376 return *this; | 1681 return *this; |
1377 } | 1682 } |
1378 | 1683 |
1433 | 1738 |
1434 ComplexRowVector | 1739 ComplexRowVector |
1435 ComplexDiagMatrix::row (int i) const | 1740 ComplexDiagMatrix::row (int i) const |
1436 { | 1741 { |
1437 if (i < 0 || i >= nr) | 1742 if (i < 0 || i >= nr) |
1438 FAIL; | 1743 { |
1744 (*current_liboctave_error_handler) ("invalid row selection"); | |
1745 return RowVector (); | |
1746 } | |
1439 | 1747 |
1440 ComplexRowVector retval (nc, 0.0); | 1748 ComplexRowVector retval (nc, 0.0); |
1441 if (nr <= nc || (nr > nc && i < nc)) | 1749 if (nr <= nc || (nr > nc && i < nc)) |
1442 retval.data [i] = data[i]; | 1750 retval.data [i] = data[i]; |
1443 | 1751 |
1446 | 1754 |
1447 ComplexRowVector | 1755 ComplexRowVector |
1448 ComplexDiagMatrix::row (char *s) const | 1756 ComplexDiagMatrix::row (char *s) const |
1449 { | 1757 { |
1450 if (s == (char *) NULL) | 1758 if (s == (char *) NULL) |
1451 FAIL; | 1759 { |
1760 (*current_liboctave_error_handler) ("invalid row selection"); | |
1761 return ComplexRowVector (); | |
1762 } | |
1452 | 1763 |
1453 char c = *s; | 1764 char c = *s; |
1454 if (c == 'f' || c == 'F') | 1765 if (c == 'f' || c == 'F') |
1455 return row (0); | 1766 return row (0); |
1456 else if (c == 'l' || c == 'L') | 1767 else if (c == 'l' || c == 'L') |
1457 return row (nr - 1); | 1768 return row (nr - 1); |
1458 else | 1769 else |
1459 FAIL; | 1770 { |
1771 (*current_liboctave_error_handler) ("invalid row selection"); | |
1772 return ComplexRowVector (); | |
1773 } | |
1460 } | 1774 } |
1461 | 1775 |
1462 ComplexColumnVector | 1776 ComplexColumnVector |
1463 ComplexDiagMatrix::column (int i) const | 1777 ComplexDiagMatrix::column (int i) const |
1464 { | 1778 { |
1465 if (i < 0 || i >= nc) | 1779 if (i < 0 || i >= nc) |
1466 FAIL; | 1780 { |
1781 (*current_liboctave_error_handler) ("invalid column selection"); | |
1782 return ColumnVector (); | |
1783 } | |
1467 | 1784 |
1468 ComplexColumnVector retval (nr, 0.0); | 1785 ComplexColumnVector retval (nr, 0.0); |
1469 if (nr >= nc || (nr < nc && i < nr)) | 1786 if (nr >= nc || (nr < nc && i < nr)) |
1470 retval.data [i] = data[i]; | 1787 retval.data [i] = data[i]; |
1471 | 1788 |
1474 | 1791 |
1475 ComplexColumnVector | 1792 ComplexColumnVector |
1476 ComplexDiagMatrix::column (char *s) const | 1793 ComplexDiagMatrix::column (char *s) const |
1477 { | 1794 { |
1478 if (s == (char *) NULL) | 1795 if (s == (char *) NULL) |
1479 FAIL; | 1796 { |
1797 (*current_liboctave_error_handler) ("invalid column selection"); | |
1798 return ColumnVector (); | |
1799 } | |
1480 | 1800 |
1481 char c = *s; | 1801 char c = *s; |
1482 if (c == 'f' || c == 'F') | 1802 if (c == 'f' || c == 'F') |
1483 return column (0); | 1803 return column (0); |
1484 else if (c == 'l' || c == 'L') | 1804 else if (c == 'l' || c == 'L') |
1485 return column (nc - 1); | 1805 return column (nc - 1); |
1486 else | 1806 else |
1487 FAIL; | 1807 { |
1808 (*current_liboctave_error_handler) ("invalid column selection"); | |
1809 return ColumnVector (); | |
1810 } | |
1488 } | 1811 } |
1489 | 1812 |
1490 ComplexDiagMatrix | 1813 ComplexDiagMatrix |
1491 ComplexDiagMatrix::inverse (int& info) const | 1814 ComplexDiagMatrix::inverse (int& info) const |
1492 { | 1815 { |
1493 if (nr != nc) | 1816 if (nr != nc) |
1494 FAIL; | 1817 { |
1818 (*current_liboctave_error_handler) ("inverse requires square matrix"); | |
1819 return DiagMatrix (); | |
1820 } | |
1495 | 1821 |
1496 info = 0; | 1822 info = 0; |
1497 for (int i = 0; i < len; i++) | 1823 for (int i = 0; i < len; i++) |
1498 { | 1824 { |
1499 if (data[i] == 0.0) | 1825 if (data[i] == 0.0) |
1627 | 1953 |
1628 ComplexColumnVector | 1954 ComplexColumnVector |
1629 ComplexDiagMatrix::operator * (const ColumnVector& a) const | 1955 ComplexDiagMatrix::operator * (const ColumnVector& a) const |
1630 { | 1956 { |
1631 if (nc != a.len) | 1957 if (nc != a.len) |
1632 FAIL; | 1958 { |
1959 (*current_liboctave_error_handler) | |
1960 ("nonconformant matrix muliplication attempted"); | |
1961 return ComplexColumnVector (); | |
1962 } | |
1633 | 1963 |
1634 if (nc == 0 || nr == 0) | 1964 if (nc == 0 || nr == 0) |
1635 return ComplexColumnVector (0); | 1965 return ComplexColumnVector (0); |
1636 | 1966 |
1637 ComplexColumnVector result (nr); | 1967 ComplexColumnVector result (nr); |
1647 | 1977 |
1648 ComplexColumnVector | 1978 ComplexColumnVector |
1649 ComplexDiagMatrix::operator * (const ComplexColumnVector& a) const | 1979 ComplexDiagMatrix::operator * (const ComplexColumnVector& a) const |
1650 { | 1980 { |
1651 if (nc != a.len) | 1981 if (nc != a.len) |
1652 FAIL; | 1982 { |
1983 (*current_liboctave_error_handler) | |
1984 ("nonconformant matrix muliplication attempted"); | |
1985 return ComplexColumnVector (); | |
1986 } | |
1653 | 1987 |
1654 if (nc == 0 || nr == 0) | 1988 if (nc == 0 || nr == 0) |
1655 return ComplexColumnVector (0); | 1989 return ComplexColumnVector (0); |
1656 | 1990 |
1657 ComplexColumnVector result (nr); | 1991 ComplexColumnVector result (nr); |
1669 | 2003 |
1670 ComplexDiagMatrix | 2004 ComplexDiagMatrix |
1671 ComplexDiagMatrix::operator + (const DiagMatrix& a) const | 2005 ComplexDiagMatrix::operator + (const DiagMatrix& a) const |
1672 { | 2006 { |
1673 if (nr != a.nr || nc != a.nc) | 2007 if (nr != a.nr || nc != a.nc) |
1674 FAIL; | 2008 { |
2009 (*current_liboctave_error_handler) | |
2010 ("nonconformant matrix addition attempted"); | |
2011 return ComplexDiagMatrix (); | |
2012 } | |
1675 | 2013 |
1676 if (nr == 0 || nc == 0) | 2014 if (nr == 0 || nc == 0) |
1677 return ComplexDiagMatrix (nr, nc); | 2015 return ComplexDiagMatrix (nr, nc); |
1678 | 2016 |
1679 return ComplexDiagMatrix (add (data, a.data, len), nr , nc); | 2017 return ComplexDiagMatrix (add (data, a.data, len), nr , nc); |
1681 | 2019 |
1682 ComplexDiagMatrix | 2020 ComplexDiagMatrix |
1683 ComplexDiagMatrix::operator - (const DiagMatrix& a) const | 2021 ComplexDiagMatrix::operator - (const DiagMatrix& a) const |
1684 { | 2022 { |
1685 if (nr != a.nr || nc != a.nc) | 2023 if (nr != a.nr || nc != a.nc) |
1686 FAIL; | 2024 { |
2025 (*current_liboctave_error_handler) | |
2026 ("nonconformant matrix subtraction attempted"); | |
2027 return ComplexDiagMatrix (); | |
2028 } | |
1687 | 2029 |
1688 if (nr == 0 || nc == 0) | 2030 if (nr == 0 || nc == 0) |
1689 return ComplexDiagMatrix (nr, nc); | 2031 return ComplexDiagMatrix (nr, nc); |
1690 | 2032 |
1691 return ComplexDiagMatrix (subtract (data, a.data, len), nr, nc); | 2033 return ComplexDiagMatrix (subtract (data, a.data, len), nr, nc); |
1693 | 2035 |
1694 ComplexDiagMatrix | 2036 ComplexDiagMatrix |
1695 ComplexDiagMatrix::operator * (const DiagMatrix& a) const | 2037 ComplexDiagMatrix::operator * (const DiagMatrix& a) const |
1696 { | 2038 { |
1697 if (nr != a.nr || nc != a.nc) | 2039 if (nr != a.nr || nc != a.nc) |
1698 FAIL; | 2040 { |
2041 (*current_liboctave_error_handler) | |
2042 ("nonconformant matrix multiplication attempted"); | |
2043 return ComplexDiagMatrix (); | |
2044 } | |
1699 | 2045 |
1700 if (nr == 0 || nc == 0) | 2046 if (nr == 0 || nc == 0) |
1701 return ComplexDiagMatrix (nr, nc); | 2047 return ComplexDiagMatrix (nr, nc); |
1702 | 2048 |
1703 return ComplexDiagMatrix (multiply (data, a.data, len), nr, nc); | 2049 return ComplexDiagMatrix (multiply (data, a.data, len), nr, nc); |
1705 | 2051 |
1706 ComplexDiagMatrix | 2052 ComplexDiagMatrix |
1707 ComplexDiagMatrix::operator + (const ComplexDiagMatrix& a) const | 2053 ComplexDiagMatrix::operator + (const ComplexDiagMatrix& a) const |
1708 { | 2054 { |
1709 if (nr != a.nr || nc != a.nc) | 2055 if (nr != a.nr || nc != a.nc) |
1710 FAIL; | 2056 { |
2057 (*current_liboctave_error_handler) | |
2058 ("nonconformant matrix addition attempted"); | |
2059 return ComplexDiagMatrix (); | |
2060 } | |
1711 | 2061 |
1712 if (nr == 0 || nc == 0) | 2062 if (nr == 0 || nc == 0) |
1713 return ComplexDiagMatrix (nr, nc); | 2063 return ComplexDiagMatrix (nr, nc); |
1714 | 2064 |
1715 return ComplexDiagMatrix (add (data, a.data, len), nr , nc); | 2065 return ComplexDiagMatrix (add (data, a.data, len), nr , nc); |
1717 | 2067 |
1718 ComplexDiagMatrix | 2068 ComplexDiagMatrix |
1719 ComplexDiagMatrix::operator - (const ComplexDiagMatrix& a) const | 2069 ComplexDiagMatrix::operator - (const ComplexDiagMatrix& a) const |
1720 { | 2070 { |
1721 if (nr != a.nr || nc != a.nc) | 2071 if (nr != a.nr || nc != a.nc) |
1722 FAIL; | 2072 { |
2073 (*current_liboctave_error_handler) | |
2074 ("nonconformant matrix subtraction attempted"); | |
2075 return ComplexDiagMatrix (); | |
2076 } | |
1723 | 2077 |
1724 if (nr == 0 || nc == 0) | 2078 if (nr == 0 || nc == 0) |
1725 return ComplexDiagMatrix (nr, nc); | 2079 return ComplexDiagMatrix (nr, nc); |
1726 | 2080 |
1727 return ComplexDiagMatrix (subtract (data, a.data, len), nr, nc); | 2081 return ComplexDiagMatrix (subtract (data, a.data, len), nr, nc); |
1729 | 2083 |
1730 ComplexDiagMatrix | 2084 ComplexDiagMatrix |
1731 ComplexDiagMatrix::operator * (const ComplexDiagMatrix& a) const | 2085 ComplexDiagMatrix::operator * (const ComplexDiagMatrix& a) const |
1732 { | 2086 { |
1733 if (nr != a.nr || nc != a.nc) | 2087 if (nr != a.nr || nc != a.nc) |
1734 FAIL; | 2088 { |
2089 (*current_liboctave_error_handler) | |
2090 ("nonconformant matrix multiplication attempted"); | |
2091 return ComplexDiagMatrix (); | |
2092 } | |
1735 | 2093 |
1736 if (nr == 0 || nc == 0) | 2094 if (nr == 0 || nc == 0) |
1737 return ComplexDiagMatrix (nr, nc); | 2095 return ComplexDiagMatrix (nr, nc); |
1738 | 2096 |
1739 return ComplexDiagMatrix (multiply (data, a.data, len), nr, nc); | 2097 return ComplexDiagMatrix (multiply (data, a.data, len), nr, nc); |
1741 | 2099 |
1742 ComplexDiagMatrix | 2100 ComplexDiagMatrix |
1743 ComplexDiagMatrix::product (const DiagMatrix& a) const | 2101 ComplexDiagMatrix::product (const DiagMatrix& a) const |
1744 { | 2102 { |
1745 if (nr != a.nr || nc != a.nc) | 2103 if (nr != a.nr || nc != a.nc) |
1746 FAIL; | 2104 { |
2105 (*current_liboctave_error_handler) | |
2106 ("nonconformant matrix product attempted"); | |
2107 return ComplexDiagMatrix (); | |
2108 } | |
1747 | 2109 |
1748 if (nr == 0 || nc == 0) | 2110 if (nr == 0 || nc == 0) |
1749 return ComplexDiagMatrix (nr, nc); | 2111 return ComplexDiagMatrix (nr, nc); |
1750 | 2112 |
1751 return ComplexDiagMatrix (multiply (data, a.data, len), nr, nc); | 2113 return ComplexDiagMatrix (multiply (data, a.data, len), nr, nc); |
1753 | 2115 |
1754 ComplexDiagMatrix | 2116 ComplexDiagMatrix |
1755 ComplexDiagMatrix::quotient (const DiagMatrix& a) const | 2117 ComplexDiagMatrix::quotient (const DiagMatrix& a) const |
1756 { | 2118 { |
1757 if (nr != a.nr || nc != a.nc) | 2119 if (nr != a.nr || nc != a.nc) |
1758 FAIL; | 2120 { |
2121 (*current_liboctave_error_handler) | |
2122 ("nonconformant matrix quotient attempted"); | |
2123 return ComplexDiagMatrix (); | |
2124 } | |
1759 | 2125 |
1760 if (nr == 0 || nc == 0) | 2126 if (nr == 0 || nc == 0) |
1761 return ComplexDiagMatrix (nr, nc); | 2127 return ComplexDiagMatrix (nr, nc); |
1762 | 2128 |
1763 return ComplexDiagMatrix (divide (data, a.data, len), nr, nc); | 2129 return ComplexDiagMatrix (divide (data, a.data, len), nr, nc); |
1765 | 2131 |
1766 ComplexDiagMatrix | 2132 ComplexDiagMatrix |
1767 ComplexDiagMatrix::product (const ComplexDiagMatrix& a) const | 2133 ComplexDiagMatrix::product (const ComplexDiagMatrix& a) const |
1768 { | 2134 { |
1769 if (nr != a.nr || nc != a.nc) | 2135 if (nr != a.nr || nc != a.nc) |
1770 FAIL; | 2136 { |
2137 (*current_liboctave_error_handler) | |
2138 ("nonconformant matrix product attempted"); | |
2139 return ComplexDiagMatrix (); | |
2140 } | |
1771 | 2141 |
1772 if (nr == 0 || nc == 0) | 2142 if (nr == 0 || nc == 0) |
1773 return ComplexDiagMatrix (nr, nc); | 2143 return ComplexDiagMatrix (nr, nc); |
1774 | 2144 |
1775 return ComplexDiagMatrix (multiply (data, a.data, len), nr, nc); | 2145 return ComplexDiagMatrix (multiply (data, a.data, len), nr, nc); |
1777 | 2147 |
1778 ComplexDiagMatrix | 2148 ComplexDiagMatrix |
1779 ComplexDiagMatrix::quotient (const ComplexDiagMatrix& a) const | 2149 ComplexDiagMatrix::quotient (const ComplexDiagMatrix& a) const |
1780 { | 2150 { |
1781 if (nr != a.nr || nc != a.nc) | 2151 if (nr != a.nr || nc != a.nc) |
1782 FAIL; | 2152 { |
2153 (*current_liboctave_error_handler) | |
2154 ("nonconformant matrix quotient attempted"); | |
2155 return ComplexDiagMatrix (); | |
2156 } | |
1783 | 2157 |
1784 if (nr == 0 || nc == 0) | 2158 if (nr == 0 || nc == 0) |
1785 return ComplexDiagMatrix (nr, nc); | 2159 return ComplexDiagMatrix (nr, nc); |
1786 | 2160 |
1787 return ComplexDiagMatrix (divide (data, a.data, len), nr, nc); | 2161 return ComplexDiagMatrix (divide (data, a.data, len), nr, nc); |
1789 | 2163 |
1790 ComplexDiagMatrix& | 2164 ComplexDiagMatrix& |
1791 ComplexDiagMatrix::operator += (const DiagMatrix& a) | 2165 ComplexDiagMatrix::operator += (const DiagMatrix& a) |
1792 { | 2166 { |
1793 if (nr != a.nr || nc != a.nc) | 2167 if (nr != a.nr || nc != a.nc) |
1794 FAIL; | 2168 { |
2169 (*current_liboctave_error_handler) | |
2170 ("nonconformant matrix += operation attempted"); | |
2171 return *this; | |
2172 } | |
1795 | 2173 |
1796 if (nr == 0 || nc == 0) | 2174 if (nr == 0 || nc == 0) |
1797 return *this; | 2175 return *this; |
1798 | 2176 |
1799 add2 (data, a.data, len); | 2177 add2 (data, a.data, len); |
1802 | 2180 |
1803 ComplexDiagMatrix& | 2181 ComplexDiagMatrix& |
1804 ComplexDiagMatrix::operator -= (const DiagMatrix& a) | 2182 ComplexDiagMatrix::operator -= (const DiagMatrix& a) |
1805 { | 2183 { |
1806 if (nr != a.nr || nc != a.nc) | 2184 if (nr != a.nr || nc != a.nc) |
1807 FAIL; | 2185 { |
2186 (*current_liboctave_error_handler) | |
2187 ("nonconformant matrix -= operation attempted"); | |
2188 return *this; | |
2189 } | |
1808 | 2190 |
1809 if (nr == 0 || nc == 0) | 2191 if (nr == 0 || nc == 0) |
1810 return *this; | 2192 return *this; |
1811 | 2193 |
1812 subtract2 (data, a.data, len); | 2194 subtract2 (data, a.data, len); |
1815 | 2197 |
1816 ComplexDiagMatrix& | 2198 ComplexDiagMatrix& |
1817 ComplexDiagMatrix::operator += (const ComplexDiagMatrix& a) | 2199 ComplexDiagMatrix::operator += (const ComplexDiagMatrix& a) |
1818 { | 2200 { |
1819 if (nr != a.nr || nc != a.nc) | 2201 if (nr != a.nr || nc != a.nc) |
1820 FAIL; | 2202 { |
2203 (*current_liboctave_error_handler) | |
2204 ("nonconformant matrix += operation attempted"); | |
2205 return *this; | |
2206 } | |
1821 | 2207 |
1822 if (nr == 0 || nc == 0) | 2208 if (nr == 0 || nc == 0) |
1823 return *this; | 2209 return *this; |
1824 | 2210 |
1825 add2 (data, a.data, len); | 2211 add2 (data, a.data, len); |
1828 | 2214 |
1829 ComplexDiagMatrix& | 2215 ComplexDiagMatrix& |
1830 ComplexDiagMatrix::operator -= (const ComplexDiagMatrix& a) | 2216 ComplexDiagMatrix::operator -= (const ComplexDiagMatrix& a) |
1831 { | 2217 { |
1832 if (nr != a.nr || nc != a.nc) | 2218 if (nr != a.nr || nc != a.nc) |
1833 FAIL; | 2219 { |
2220 (*current_liboctave_error_handler) | |
2221 ("nonconformant matrix -= operation attempted"); | |
2222 return *this; | |
2223 } | |
1834 | 2224 |
1835 if (nr == 0 || nc == 0) | 2225 if (nr == 0 || nc == 0) |
1836 return *this; | 2226 return *this; |
1837 | 2227 |
1838 subtract2 (data, a.data, len); | 2228 subtract2 (data, a.data, len); |
1843 | 2233 |
1844 ComplexMatrix | 2234 ComplexMatrix |
1845 ComplexDiagMatrix::operator + (const Matrix& a) const | 2235 ComplexDiagMatrix::operator + (const Matrix& a) const |
1846 { | 2236 { |
1847 if (nr != a.nr || nc != a.nc) | 2237 if (nr != a.nr || nc != a.nc) |
1848 FAIL; | 2238 { |
2239 (*current_liboctave_error_handler) | |
2240 ("nonconformant matrix addition attempted"); | |
2241 return ComplexMatrix (); | |
2242 } | |
1849 | 2243 |
1850 if (nr == 0 || nc == 0) | 2244 if (nr == 0 || nc == 0) |
1851 return ComplexMatrix (nr, nc); | 2245 return ComplexMatrix (nr, nc); |
1852 | 2246 |
1853 ComplexMatrix result (a); | 2247 ComplexMatrix result (a); |
1859 | 2253 |
1860 ComplexMatrix | 2254 ComplexMatrix |
1861 ComplexDiagMatrix::operator - (const Matrix& a) const | 2255 ComplexDiagMatrix::operator - (const Matrix& a) const |
1862 { | 2256 { |
1863 if (nr != a.nr || nc != a.nc) | 2257 if (nr != a.nr || nc != a.nc) |
1864 FAIL; | 2258 { |
2259 (*current_liboctave_error_handler) | |
2260 ("nonconformant matrix subtraction attempted"); | |
2261 return ComplexMatrix (); | |
2262 } | |
1865 | 2263 |
1866 if (nr == 0 || nc == 0) | 2264 if (nr == 0 || nc == 0) |
1867 return ComplexMatrix (nr, nc); | 2265 return ComplexMatrix (nr, nc); |
1868 | 2266 |
1869 ComplexMatrix result (-a); | 2267 ComplexMatrix result (-a); |
1875 | 2273 |
1876 ComplexMatrix | 2274 ComplexMatrix |
1877 ComplexDiagMatrix::operator * (const Matrix& a) const | 2275 ComplexDiagMatrix::operator * (const Matrix& a) const |
1878 { | 2276 { |
1879 if (nc != a.nr) | 2277 if (nc != a.nr) |
1880 FAIL; | 2278 { |
2279 (*current_liboctave_error_handler) | |
2280 ("nonconformant matrix multiplication attempted"); | |
2281 return ComplexMatrix (); | |
2282 } | |
1881 | 2283 |
1882 if (nr == 0 || nc == 0 || a.nc == 0) | 2284 if (nr == 0 || nc == 0 || a.nc == 0) |
1883 return ComplexMatrix (nr, a.nc, 0.0); | 2285 return ComplexMatrix (nr, a.nc, 0.0); |
1884 | 2286 |
1885 ComplexMatrix c (nr, a.nc); | 2287 ComplexMatrix c (nr, a.nc); |
1915 | 2317 |
1916 ComplexMatrix | 2318 ComplexMatrix |
1917 ComplexDiagMatrix::operator + (const ComplexMatrix& a) const | 2319 ComplexDiagMatrix::operator + (const ComplexMatrix& a) const |
1918 { | 2320 { |
1919 if (nr != a.nr || nc != a.nc) | 2321 if (nr != a.nr || nc != a.nc) |
1920 FAIL; | 2322 { |
2323 (*current_liboctave_error_handler) | |
2324 ("nonconformant matrix addition attempted"); | |
2325 return ComplexMatrix (); | |
2326 } | |
1921 | 2327 |
1922 if (nr == 0 || nc == 0) | 2328 if (nr == 0 || nc == 0) |
1923 return ComplexMatrix (nr, nc); | 2329 return ComplexMatrix (nr, nc); |
1924 | 2330 |
1925 ComplexMatrix result (a); | 2331 ComplexMatrix result (a); |
1931 | 2337 |
1932 ComplexMatrix | 2338 ComplexMatrix |
1933 ComplexDiagMatrix::operator - (const ComplexMatrix& a) const | 2339 ComplexDiagMatrix::operator - (const ComplexMatrix& a) const |
1934 { | 2340 { |
1935 if (nr != a.nr || nc != a.nc) | 2341 if (nr != a.nr || nc != a.nc) |
1936 FAIL; | 2342 { |
2343 (*current_liboctave_error_handler) | |
2344 ("nonconformant matrix subtraction attempted"); | |
2345 return ComplexMatrix (); | |
2346 } | |
1937 | 2347 |
1938 if (nr == 0 || nc == 0) | 2348 if (nr == 0 || nc == 0) |
1939 return ComplexMatrix (nr, nc); | 2349 return ComplexMatrix (nr, nc); |
1940 | 2350 |
1941 ComplexMatrix result (-a); | 2351 ComplexMatrix result (-a); |
1947 | 2357 |
1948 ComplexMatrix | 2358 ComplexMatrix |
1949 ComplexDiagMatrix::operator * (const ComplexMatrix& a) const | 2359 ComplexDiagMatrix::operator * (const ComplexMatrix& a) const |
1950 { | 2360 { |
1951 if (nc != a.nr) | 2361 if (nc != a.nr) |
1952 FAIL; | 2362 { |
2363 (*current_liboctave_error_handler) | |
2364 ("nonconformant matrix multiplication attempted"); | |
2365 return ComplexMatrix (); | |
2366 } | |
1953 | 2367 |
1954 if (nr == 0 || nc == 0 || a.nc == 0) | 2368 if (nr == 0 || nc == 0 || a.nc == 0) |
1955 return ComplexMatrix (nr, a.nc, 0.0); | 2369 return ComplexMatrix (nr, a.nc, 0.0); |
1956 | 2370 |
1957 ComplexMatrix c (nr, a.nc); | 2371 ComplexMatrix c (nr, a.nc); |