make it compile with modern C++
[prop.git] / include / AD / numeric / matrix.h
blob4b9ad7d5ee18e917cec2baebfd95e681fde9e3e9
1 //////////////////////////////////////////////////////////////////////////////
2 // NOTICE:
3 //
4 // ADLib, Prop and their related set of tools and documentation are in the
5 // public domain. The author(s) of this software reserve no copyrights on
6 // the source code and any code generated using the tools. You are encouraged
7 // to use ADLib and Prop to develop software, in both academic and commercial
8 // settings, and are free to incorporate any part of ADLib and Prop into
9 // your programs.
11 // Although you are under no obligation to do so, we strongly recommend that
12 // you give away all software developed using our tools.
14 // We also ask that credit be given to us when ADLib and/or Prop are used in
15 // your programs, and that this notice be preserved intact in all the source
16 // code.
18 // This software is still under development and we welcome any suggestions
19 // and help from the users.
21 // Allen Leung
22 // 1994
23 //////////////////////////////////////////////////////////////////////////////
25 #ifndef floating_point_matrix_h
26 #define floating_point_matrix_h
28 #include <iostream>
29 #include <AD/contain/array2.h> // two dimensional arrays
31 //////////////////////////////////////////////////////////////////////
32 // Class Matrix is inherited from the two dimensional array class
33 // |Array2<double>|.
34 //////////////////////////////////////////////////////////////////////
35 class Matrix : public Array2<double> {
37 void can_add(const Matrix&) const; // check whether addition is defined.
38 void can_mult(const Matrix&) const; // check whether multiplication is defined.
40 public:
42 //////////////////////////////////////////////////////////////////
43 // Default error handler
44 //////////////////////////////////////////////////////////////////
45 static void (*error)(const char [], ...);
47 //////////////////////////////////////////////////////////////////
48 // Constructor and destructors
49 //////////////////////////////////////////////////////////////////
50 Matrix() {}
51 Matrix(int m, int n) : Array2<double>(m,n) {}
52 Matrix(int m, int n, double e) : Array2<double>(m,n,e) {}
53 Matrix(const Matrix& m) : Array2<double>(m) {}
54 ~Matrix() {}
56 //////////////////////////////////////////////////////////////////
57 // Assignment
58 //////////////////////////////////////////////////////////////////
59 Matrix& operator = (const Matrix& a) { Array2<double>::operator = (a); return *this; }
60 Matrix& operator = (double e) { Array2<double>::operator = (e); return *this; }
62 //////////////////////////////////////////////////////////////////
63 // Selectors, indexing etc.
64 // Inherited from base class
65 //////////////////////////////////////////////////////////////////
66 // int rows() const;
67 // int columns() const;
68 // const double * operator [] (int i) const;
69 // double * operator [] (int i);
71 //////////////////////////////////////////////////////////////////
72 // Scalar operations
73 //////////////////////////////////////////////////////////////////
74 Matrix operator - ();
75 friend Matrix operator + (double, const Matrix&);
76 friend Matrix operator + (const Matrix&, double);
77 friend Matrix operator - (double, const Matrix&);
78 friend Matrix operator - (const Matrix&, double);
79 friend Matrix operator * (double, const Matrix&);
80 friend Matrix operator * (const Matrix&, double);
81 friend Matrix operator / (const Matrix&, double);
83 //////////////////////////////////////////////////////////////////
84 // In place scalar operations
85 //////////////////////////////////////////////////////////////////
86 Matrix& negate();
87 Matrix& operator += (double);
88 Matrix& operator -= (double);
89 Matrix& operator *= (double);
90 Matrix& operator /= (double);
92 //////////////////////////////////////////////////////////////////
93 // Matrix operations
94 //////////////////////////////////////////////////////////////////
95 friend Matrix operator + (const Matrix&, const Matrix&);
96 friend Matrix operator - (const Matrix&, const Matrix&);
97 friend Matrix operator * (const Matrix&, const Matrix&);
98 double det() const;
99 Matrix inverse() const;
101 //////////////////////////////////////////////////////////////////
102 // In place matrix operations
103 //////////////////////////////////////////////////////////////////
104 Matrix& operator += (const Matrix& m);
105 Matrix& operator -= (const Matrix& m);
106 Matrix& operator *= (const Matrix& m);
107 Matrix& invert();
109 //////////////////////////////////////////////////////////////////
110 // Linear algebra stuff
111 //////////////////////////////////////////////////////////////////
112 Matrix& LU (const Matrix&);
113 Matrix& simplex();
114 Matrix& ellipsoid();
116 //////////////////////////////////////////////////////////////////
117 // Comparisons
118 //////////////////////////////////////////////////////////////////
119 friend Bool operator == (const Matrix& a, const Matrix& b);
120 friend Bool operator != (const Matrix& a, const Matrix& b)
121 { return ! (a == b); }
123 //////////////////////////////////////////////////////////////////
124 // Submatrices and slicing
125 //////////////////////////////////////////////////////////////////
127 //////////////////////////////////////////////////////////////////
128 // I/O
129 //////////////////////////////////////////////////////////////////
130 friend std::ostream& operator << (std::ostream&, const Matrix&);
131 friend std::istream& operator >> (std::istream&, Matrix&);
134 #endif