comparison liboctave/Matrix.h @ 227:1a48a1b91489

[project @ 1993-11-15 10:10:35 by jwe]
author jwe
date Mon, 15 Nov 1993 10:11:59 +0000
parents 7947b7a6b6da
children e1b072bcffb9
comparison
equal deleted inserted replaced
226:c4027b057786 227:1a48a1b91489
44 #include <values.h> 44 #include <values.h>
45 #include <assert.h> 45 #include <assert.h>
46 #include <iostream.h> 46 #include <iostream.h>
47 // #include <iomanip.h> // We don\'t use this yet. 47 // #include <iomanip.h> // We don\'t use this yet.
48 #include <Complex.h> 48 #include <Complex.h>
49
50 #define FAIL assert(0) /* XXX FIXME XXX */
51 49
52 #ifndef MAPPER_FCN_TYPEDEFS 50 #ifndef MAPPER_FCN_TYPEDEFS
53 #define MAPPER_FCN_TYPEDEFS 1 51 #define MAPPER_FCN_TYPEDEFS 1
54 52
55 typedef double (*d_d_Mapper)(double); 53 typedef double (*d_d_Mapper)(double);
552 inline int Matrix::cols (void) const { return nc; } 550 inline int Matrix::cols (void) const { return nc; }
553 inline int Matrix::columns (void) const { return nc; } 551 inline int Matrix::columns (void) const { return nc; }
554 552
555 inline double& Matrix::elem (int r, int c) { return data[nr*c+r]; } 553 inline double& Matrix::elem (int r, int c) { return data[nr*c+r]; }
556 554
557 inline double& Matrix::checkelem (int r, int c)
558 {
559 #ifndef NO_RANGE_CHECK
560 if (r < 0 || r >= nr || c < 0 || c >= nc)
561 FAIL;
562 #endif
563
564 return elem (r, c);
565 }
566
567 inline double& Matrix::operator () (int r, int c) 555 inline double& Matrix::operator () (int r, int c)
568 { return checkelem (r, c); } 556 { return checkelem (r, c); }
569 557
570 inline double Matrix::elem (int r, int c) const { return data[nr*c+r]; } 558 inline double Matrix::elem (int r, int c) const { return data[nr*c+r]; }
571
572 inline double Matrix::checkelem (int r, int c) const
573 {
574 #ifndef NO_RANGE_CHECK
575 if (r < 0 || r >= nr || c < 0 || c >= nc)
576 FAIL;
577 #endif
578
579 return elem (r, c);
580 }
581 559
582 inline double Matrix::operator () (int r, int c) const 560 inline double Matrix::operator () (int r, int c) const
583 { return checkelem (r, c); } 561 { return checkelem (r, c); }
584 562
585 inline double *Matrix::fortran_vec (void) const { return data; } 563 inline double *Matrix::fortran_vec (void) const { return data; }
713 inline int ColumnVector::capacity (void) const { return len; } 691 inline int ColumnVector::capacity (void) const { return len; }
714 inline int ColumnVector::length (void) const { return len; } 692 inline int ColumnVector::length (void) const { return len; }
715 693
716 inline double& ColumnVector::elem (int n) { return data[n]; } 694 inline double& ColumnVector::elem (int n) { return data[n]; }
717 695
718 inline double&
719 ColumnVector::checkelem (int n)
720 {
721 #ifndef NO_RANGE_CHECK
722 if (n < 0 || n >= len)
723 FAIL;
724 #endif
725
726 return elem (n);
727 }
728
729 inline double& ColumnVector::operator () (int n) { return checkelem (n); } 696 inline double& ColumnVector::operator () (int n) { return checkelem (n); }
730 697
731 inline double ColumnVector::elem (int n) const { return data[n]; } 698 inline double ColumnVector::elem (int n) const { return data[n]; }
732
733 inline double
734 ColumnVector::checkelem (int n) const
735 {
736 #ifndef NO_RANGE_CHECK
737 if (n < 0 || n >= len)
738 FAIL;
739 #endif
740
741 return elem (n);
742 }
743 699
744 inline double ColumnVector::operator () (int n) const { return checkelem (n); } 700 inline double ColumnVector::operator () (int n) const { return checkelem (n); }
745 701
746 inline double *ColumnVector::fortran_vec (void) const { return data; } 702 inline double *ColumnVector::fortran_vec (void) const { return data; }
747 703
880 inline int RowVector::capacity (void) const { return len; } 836 inline int RowVector::capacity (void) const { return len; }
881 inline int RowVector::length (void) const { return len; } 837 inline int RowVector::length (void) const { return len; }
882 838
883 inline double& RowVector::elem (int n) { return data[n]; } 839 inline double& RowVector::elem (int n) { return data[n]; }
884 840
885 inline double&
886 RowVector::checkelem (int n)
887 {
888 #ifndef NO_RANGE_CHECK
889 if (n < 0 || n >= len)
890 FAIL;
891 #endif
892
893 return elem (n);
894 }
895
896 inline double& RowVector::operator () (int n) { return checkelem (n); } 841 inline double& RowVector::operator () (int n) { return checkelem (n); }
897 842
898 inline double RowVector::elem (int n) const { return data[n]; } 843 inline double RowVector::elem (int n) const { return data[n]; }
899
900 inline double
901 RowVector::checkelem (int n) const
902 {
903 #ifndef NO_RANGE_CHECK
904 if (n < 0 || n >= len)
905 FAIL;
906 #endif
907
908 return elem (n);
909 }
910 844
911 inline double RowVector::operator () (int n) const { return checkelem (n); } 845 inline double RowVector::operator () (int n) const { return checkelem (n); }
912 846
913 inline double *RowVector::fortran_vec (void) const { return data; } 847 inline double *RowVector::fortran_vec (void) const { return data; }
914 848
1074 // Would be nice to be able to avoid compiler warning and make this 1008 // Would be nice to be able to avoid compiler warning and make this
1075 // fail on assignment. 1009 // fail on assignment.
1076 inline double& DiagMatrix::elem (int r, int c) 1010 inline double& DiagMatrix::elem (int r, int c)
1077 { return (r == c) ? data[r] : 0; } 1011 { return (r == c) ? data[r] : 0; }
1078 1012
1079 inline double& DiagMatrix::checkelem (int r, int c)
1080 {
1081 #ifndef NO_RANGE_CHECK
1082 if (r < 0 || r >= nr || c < 0 || c >= nc)
1083 FAIL;
1084 #endif
1085
1086 return elem (r, c);
1087 }
1088
1089 inline double& DiagMatrix::operator () (int r, int c) 1013 inline double& DiagMatrix::operator () (int r, int c)
1090 { return checkelem (r, c); } 1014 { return checkelem (r, c); }
1091 1015
1092 inline double DiagMatrix::elem (int r, int c) const 1016 inline double DiagMatrix::elem (int r, int c) const
1093 { return (r == c) ? data[r] : 0; } 1017 { return (r == c) ? data[r] : 0; }
1094
1095 inline double DiagMatrix::checkelem (int r, int c) const
1096 {
1097 #ifndef NO_RANGE_CHECK
1098 if (r < 0 || r >= nr || c < 0 || c >= nc)
1099 FAIL;
1100 #endif
1101
1102 return elem (r, c);
1103 }
1104 1018
1105 inline double DiagMatrix::operator () (int r, int c) const 1019 inline double DiagMatrix::operator () (int r, int c) const
1106 { return checkelem (r, c); } 1020 { return checkelem (r, c); }
1107 1021
1108 /* 1022 /*
1396 inline int ComplexMatrix::cols (void) const { return nc; } 1310 inline int ComplexMatrix::cols (void) const { return nc; }
1397 inline int ComplexMatrix::columns (void) const { return nc; } 1311 inline int ComplexMatrix::columns (void) const { return nc; }
1398 1312
1399 inline Complex& ComplexMatrix::elem (int r, int c) { return data[nr*c+r]; } 1313 inline Complex& ComplexMatrix::elem (int r, int c) { return data[nr*c+r]; }
1400 1314
1401 inline Complex& ComplexMatrix::checkelem (int r, int c)
1402 {
1403 #ifndef NO_RANGE_CHECK
1404 if (r < 0 || r >= nr || c < 0 || c >= nc)
1405 FAIL;
1406 #endif
1407
1408 return elem (r, c);
1409 }
1410
1411 inline Complex& ComplexMatrix::operator () (int r, int c) 1315 inline Complex& ComplexMatrix::operator () (int r, int c)
1412 { return checkelem (r, c); } 1316 { return checkelem (r, c); }
1413 1317
1414 inline Complex ComplexMatrix::elem (int r, int c) const 1318 inline Complex ComplexMatrix::elem (int r, int c) const
1415 { return data[nr*c+r]; } 1319 { return data[nr*c+r]; }
1416
1417 inline Complex ComplexMatrix::checkelem (int r, int c) const
1418 {
1419 #ifndef NO_RANGE_CHECK
1420 if (r < 0 || r >= nr || c < 0 || c >= nc)
1421 FAIL;
1422 #endif
1423
1424 return elem (r, c);
1425 }
1426 1320
1427 inline Complex ComplexMatrix::operator () (int r, int c) const 1321 inline Complex ComplexMatrix::operator () (int r, int c) const
1428 { return checkelem (r, c); } 1322 { return checkelem (r, c); }
1429 1323
1430 inline Complex *ComplexMatrix::fortran_vec (void) const { return data; } 1324 inline Complex *ComplexMatrix::fortran_vec (void) const { return data; }
1589 inline int ComplexColumnVector::capacity (void) const { return len; } 1483 inline int ComplexColumnVector::capacity (void) const { return len; }
1590 inline int ComplexColumnVector::length (void) const { return len; } 1484 inline int ComplexColumnVector::length (void) const { return len; }
1591 1485
1592 inline Complex& ComplexColumnVector::elem (int n) { return data[n]; } 1486 inline Complex& ComplexColumnVector::elem (int n) { return data[n]; }
1593 1487
1594 inline Complex&
1595 ComplexColumnVector::checkelem (int n)
1596 {
1597 #ifndef NO_RANGE_CHECK
1598 if (n < 0 || n >= len)
1599 FAIL;
1600 #endif
1601
1602 return elem (n);
1603 }
1604
1605 inline Complex& ComplexColumnVector::operator () (int n) 1488 inline Complex& ComplexColumnVector::operator () (int n)
1606 { return checkelem (n); } 1489 { return checkelem (n); }
1607 1490
1608 inline Complex ComplexColumnVector::elem (int n) const { return data[n]; } 1491 inline Complex ComplexColumnVector::elem (int n) const { return data[n]; }
1609
1610 inline Complex
1611 ComplexColumnVector::checkelem (int n) const
1612 {
1613 #ifndef NO_RANGE_CHECK
1614 if (n < 0 || n >= len)
1615 FAIL;
1616 #endif
1617
1618 return elem (n);
1619 }
1620 1492
1621 inline Complex ComplexColumnVector::operator () (int n) const 1493 inline Complex ComplexColumnVector::operator () (int n) const
1622 { return checkelem (n); } 1494 { return checkelem (n); }
1623 1495
1624 inline Complex *ComplexColumnVector::fortran_vec (void) const { return data; } 1496 inline Complex *ComplexColumnVector::fortran_vec (void) const { return data; }
1784 inline int ComplexRowVector::capacity (void) const { return len; } 1656 inline int ComplexRowVector::capacity (void) const { return len; }
1785 inline int ComplexRowVector::length (void) const { return len; } 1657 inline int ComplexRowVector::length (void) const { return len; }
1786 1658
1787 inline Complex& ComplexRowVector::elem (int n) { return data[n]; } 1659 inline Complex& ComplexRowVector::elem (int n) { return data[n]; }
1788 1660
1789 inline Complex&
1790 ComplexRowVector::checkelem (int n)
1791 {
1792 #ifndef NO_RANGE_CHECK
1793 if (n < 0 || n >= len)
1794 FAIL;
1795 #endif
1796
1797 return elem (n);
1798 }
1799
1800 inline Complex& ComplexRowVector::operator () (int n) { return checkelem (n); } 1661 inline Complex& ComplexRowVector::operator () (int n) { return checkelem (n); }
1801 1662
1802 inline Complex ComplexRowVector::elem (int n) const { return data[n]; } 1663 inline Complex ComplexRowVector::elem (int n) const { return data[n]; }
1803
1804 inline Complex
1805 ComplexRowVector::checkelem (int n) const
1806 {
1807 #ifndef NO_RANGE_CHECK
1808 if (n < 0 || n >= len)
1809 FAIL;
1810 #endif
1811
1812 return elem (n);
1813 }
1814 1664
1815 inline Complex ComplexRowVector::operator () (int n) const 1665 inline Complex ComplexRowVector::operator () (int n) const
1816 { return checkelem (n); } 1666 { return checkelem (n); }
1817 1667
1818 inline Complex *ComplexRowVector::fortran_vec (void) const { return data; } 1668 inline Complex *ComplexRowVector::fortran_vec (void) const { return data; }
2012 // Would be nice to be able to avoid compiler warning and make this 1862 // Would be nice to be able to avoid compiler warning and make this
2013 // fail on assignment. 1863 // fail on assignment.
2014 inline Complex& ComplexDiagMatrix::elem (int r, int c) 1864 inline Complex& ComplexDiagMatrix::elem (int r, int c)
2015 { Complex czero (0.0, 0.0); return (r == c) ? data[r] : czero; } 1865 { Complex czero (0.0, 0.0); return (r == c) ? data[r] : czero; }
2016 1866
2017 inline Complex& ComplexDiagMatrix::checkelem (int r, int c)
2018 {
2019 #ifndef NO_RANGE_CHECK
2020 if (r < 0 || r >= nr || c < 0 || c >= nc)
2021 FAIL;
2022 #endif
2023
2024 return elem (r, c);
2025 }
2026
2027 inline Complex& ComplexDiagMatrix::operator () (int r, int c) 1867 inline Complex& ComplexDiagMatrix::operator () (int r, int c)
2028 { return checkelem (r, c); } 1868 { return checkelem (r, c); }
2029 1869
2030 inline Complex ComplexDiagMatrix::elem (int r, int c) const 1870 inline Complex ComplexDiagMatrix::elem (int r, int c) const
2031 { Complex czero (0.0, 0.0); return (r == c) ? data[r] : czero; } 1871 { Complex czero (0.0, 0.0); return (r == c) ? data[r] : czero; }
2032
2033 inline Complex ComplexDiagMatrix::checkelem (int r, int c) const
2034 {
2035 #ifndef NO_RANGE_CHECK
2036 if (r < 0 || r >= nr || c < 0 || c >= nc)
2037 FAIL;
2038 #endif
2039
2040 return elem (r, c);
2041 }
2042 1872
2043 inline Complex ComplexDiagMatrix::operator () (int r, int c) const 1873 inline Complex ComplexDiagMatrix::operator () (int r, int c) const
2044 { return checkelem (r, c); } 1874 { return checkelem (r, c); }
2045 1875
2046 /* 1876 /*
2070 Matrix balancing_mat; 1900 Matrix balancing_mat;
2071 }; 1901 };
2072 1902
2073 inline AEPBALANCE::AEPBALANCE (const Matrix& a,const char * balance_job) 1903 inline AEPBALANCE::AEPBALANCE (const Matrix& a,const char * balance_job)
2074 { 1904 {
2075 init (a,balance_job); 1905 init (a, balance_job);
2076 } 1906 }
2077 1907
2078 inline AEPBALANCE::AEPBALANCE (const AEPBALANCE& a) 1908 inline AEPBALANCE::AEPBALANCE (const AEPBALANCE& a)
2079 { 1909 {
2080 balanced_mat = a.balanced_mat; 1910 balanced_mat = a.balanced_mat;
2121 }; 1951 };
2122 1952
2123 inline ComplexAEPBALANCE::ComplexAEPBALANCE (const ComplexMatrix& a, 1953 inline ComplexAEPBALANCE::ComplexAEPBALANCE (const ComplexMatrix& a,
2124 const char * balance_job) 1954 const char * balance_job)
2125 { 1955 {
2126 init(a,balance_job); 1956 init(a, balance_job);
2127 } 1957 }
2128 1958
2129 inline ComplexAEPBALANCE::ComplexAEPBALANCE (const ComplexAEPBALANCE& a) 1959 inline ComplexAEPBALANCE::ComplexAEPBALANCE (const ComplexAEPBALANCE& a)
2130 { 1960 {
2131 balanced_mat = a.balanced_mat; 1961 balanced_mat = a.balanced_mat;
2274 }; 2104 };
2275 2105
2276 inline GEPBALANCE::GEPBALANCE (const Matrix& a, const Matrix& b, 2106 inline GEPBALANCE::GEPBALANCE (const Matrix& a, const Matrix& b,
2277 const char * balance_job) 2107 const char * balance_job)
2278 { 2108 {
2279 init (a,b,balance_job); 2109 init (a, b, balance_job);
2280 } 2110 }
2281 2111
2282 inline GEPBALANCE::GEPBALANCE (const GEPBALANCE& a) 2112 inline GEPBALANCE::GEPBALANCE (const GEPBALANCE& a)
2283 { 2113 {
2284 balanced_a_mat = a.balanced_a_mat; 2114 balanced_a_mat = a.balanced_a_mat;