#include <Matrix.h>
Public Member Functions | ||||
Matrix | transpose () const | |||
Transpose the matrix. | ||||
Matrix | operator~ () const | |||
Another denotation for transpose. | ||||
Contructors, destructor, and conversions | ||||
| ||||
Matrix (int nl=0, int nc=0, double x=0.0) | ||||
Constructor (also usable as default constructor). | ||||
Matrix (MVector mv, bool transp=false) | ||||
Constructor creating a Matrix from a MVector. | ||||
operator MVector () const | ||||
Conversion operator creating a MVector from a Matrix. | ||||
MVector | column (int j) const | |||
Extract a column. | ||||
MVector | line (int i) const | |||
Extract a line. | ||||
Assignments | ||||
| ||||
Matrix & | operator+= (const Matrix &mat) | |||
Matrix & | operator-= (const Matrix &mat) | |||
Matrix & | operator *= (const Matrix &mat) | |||
Accessors | ||||
int | nlines () const | |||
Number of lines. | ||||
int | ncols () const | |||
Number of columns. | ||||
Subscript | ||||
| ||||
MVector & | operator[] (int i) | |||
A reference to the line at index i (version for a non-constant matrix). | ||||
const MVector & | operator[] (int i) const | |||
A reference to the line at index i (version for a constant matrix). | ||||
double & | operator() (int i, int j) | |||
Access to element at indexes (i,j) (version for a non-constant matrix). | ||||
double | operator() (int i, int j) const | |||
Access to element at indexes (i,j) (version for aconstant matrix). | ||||
double & | at (int i, int j) | |||
Another denotation for at(i,j) (version for a non-constant matrix). | ||||
double | at (int i, int j) const | |||
Another denotation for at(i,j) (version for a constant matrix). | ||||
Private Attributes | ||||
int | _nlines | |||
Number of lines. | ||||
int | _ncols | |||
Number of columns. | ||||
vector< MVector > | _lines | |||
The elements themselves. | ||||
Friends | ||||
ostream & | operator<< (ostream &os, const Matrix &mat) | |||
IO operation: just display the contents. | ||||
Arithmetic operations | ||||
Matrix | operator+ (const Matrix &mat1, const Matrix &mat2) | |||
Addition. | ||||
Matrix | operator- (const Matrix &mat1, const Matrix &mat2) | |||
Subtraction. | ||||
Matrix | operator * (const Matrix &mat1, const Matrix &mat2) | |||
Product. | ||||
Relational operations | ||||
bool | operator== (const Matrix &mat1, const Matrix &mat2) | |||
Equality. | ||||
bool | operator!= (const Matrix &mat1, const Matrix &mat2) | |||
Unequality. | ||||
Classes | ||||
class | Bad_Dimensions | |||
class | Out_Of_Bounds |
A Matrix is implemented as an STL vector (std::vector) of MVector's.
Definition at line 24 of file Matrix.h.
|
Constructor (also usable as default constructor). The matrix is implemented as a std::vector of MVector's. Each MVector represents a line of the matrix. They have all the same size (which is the number of columns). All MVector's are first created empty, then they are assigned to a temporary MVector (mv) with the correct initial values.
Definition at line 25 of file Matrix.cpp.
|
|
Constructor creating a Matrix from a MVector. When called with only one parameter, this constructor aims at converting implicitely an MVector into a Matrix.
Definition at line 39 of file Matrix.cpp. References _lines, and transpose(). 00040 : _nlines(1), 00041 _ncols(mv.size()), 00042 _lines(_ncols) 00043 { 00044 _lines[0] = mv; 00045 if (transp) 00046 transpose(); 00047 }
Here is the call graph for this function: ![]() |
|
Another denotation for at(i,j) (version for a constant matrix).
Definition at line 142 of file Matrix.h.
|
|
Another denotation for at(i,j) (version for a non-constant matrix).
Definition at line 140 of file Matrix.h.
|
|
Extract a column. Return a copy of the column at index j, as an MVector.
Definition at line 68 of file Matrix.cpp. References _lines, _ncols, and _nlines. Referenced by main(), operator *(), operator MVector(), and transpose(). 00069 { 00070 if (j < 0 || j >= _ncols) throw Out_Of_Bounds(); 00071 MVector mv(_nlines); 00072 for (int i = 0; i < _nlines; ++i) 00073 mv[i] = _lines[i][j]; 00074 return mv; 00075 }
|
|
Extract a line. Return a copy of the line at index i, as an MVector.
Definition at line 82 of file Matrix.cpp. References _lines, and _nlines. Referenced by main(), and operator *().
|
|
Number of columns.
Definition at line 85 of file Matrix.h. References _ncols. 00085 {return _ncols;}
|
|
Number of lines.
Definition at line 83 of file Matrix.h. References _nlines. 00083 {return _nlines;}
|
|
Definition at line 74 of file Matrix.h.
|
|
Conversion operator creating a MVector from a Matrix. This operator creates an MVector from a Matrix, provided that one dimension of the matrix is exactly 1.
Definition at line 55 of file Matrix.cpp. References _lines, _ncols, _nlines, and column(). 00056 { 00057 if (_nlines == 1) return _lines[0]; 00058 else if (_ncols == 1) 00059 return column(0); 00060 else throw Bad_Dimensions(); 00061 }
Here is the call graph for this function: ![]() |
|
Access to element at indexes (i,j) (version for aconstant matrix).
Definition at line 186 of file Matrix.cpp. References _lines, _ncols, and _nlines. 00187 { 00188 if (i < 0 || i >= _nlines || j < 0 || j >= _ncols) throw Out_Of_Bounds(); 00189 return _lines[i][j]; 00190 }
|
|
Access to element at indexes (i,j) (version for a non-constant matrix).
Definition at line 180 of file Matrix.cpp. References _lines, _ncols, and _nlines. 00181 { 00182 if (i < 0 || i >= _nlines || j < 0 || j >= _ncols) throw Out_Of_Bounds(); 00183 return _lines[i][j]; 00184 }
|
|
Definition at line 72 of file Matrix.h.
|
|
Definition at line 73 of file Matrix.h.
|
|
A reference to the line at index i (version for a constant matrix). This operator makes it possible to use double indexing with a Matrix (mat[i][ j]) Definition at line 173 of file Matrix.cpp. References _lines, and _nlines.
|
|
A reference to the line at index i (version for a non-constant matrix). This operator makes it possible to use double indexing with a Matrix (mat[i][ j]) Definition at line 163 of file Matrix.cpp. References _lines, and _nlines.
|
|
Another denotation for transpose.
Definition at line 95 of file Matrix.h. References transpose(). 00095 {return transpose();}
Here is the call graph for this function: ![]() |
|
Transpose the matrix.
Definition at line 91 of file Matrix.cpp. References _lines, _ncols, _nlines, and column(). Referenced by main(), Matrix(), and operator~(). 00092 { 00093 Matrix mat(_ncols, _nlines); 00094 for (int i = 0; i < _ncols; ++i) 00095 mat._lines[i] = column(i); 00096 return mat; 00097 }
Here is the call graph for this function: ![]() |
|
Product.
Definition at line 134 of file Matrix.cpp. 00135 { 00136 if (mat1._ncols != mat2._nlines) 00137 throw Matrix::Bad_Dimensions(); 00138 00139 int nl = mat1._nlines; 00140 int nc = mat2._ncols; 00141 Matrix mat(nl, nc); 00142 for (int i = 0; i < nl; ++i) 00143 for (int j = 0; j < nc; ++j) 00144 mat._lines[i][j] = mat1.line(i) * mat2.column(j); 00145 return mat; 00146 }
|
|
Unequality.
Definition at line 117 of file Matrix.h.
|
|
Addition.
Definition at line 102 of file Matrix.cpp. 00103 { 00104 if (mat1._nlines != mat2._nlines || mat1._ncols != mat2._ncols) 00105 throw Matrix::Bad_Dimensions(); 00106 00107 int nl = mat1._nlines; 00108 int nc = mat1._ncols; 00109 Matrix mat(nl, nc); 00110 for (int i = 0; i < nl; ++i) 00111 mat._lines[i] = mat1._lines[i] + mat2._lines[i]; 00112 return mat; 00113 }
|
|
Subtraction.
Definition at line 118 of file Matrix.cpp. 00119 { 00120 if (mat1._nlines != mat2._nlines || mat1._ncols != mat2._ncols) 00121 throw Matrix::Bad_Dimensions(); 00122 00123 int nl = mat1._nlines; 00124 int nc = mat1._ncols; 00125 Matrix mat(nl, nc); 00126 for (int i = 0; i < nl; ++i) 00127 mat._lines[i] = mat1._lines[i] - mat2._lines[i]; 00128 return mat; 00129 }
|
|
IO operation: just display the contents. We print each line of the matrix as an MVector on a single line. The whole matrix is also encolsed within square brackets. Definition at line 196 of file Matrix.cpp. 00197 { 00198 os << "[\n"; 00199 for (int i = 0; i < mat._nlines; ++i) 00200 os << " " << mat._lines[i] << '\n'; 00201 os << ']'; 00202 return os; 00203 }
|
|
Equality.
Definition at line 151 of file Matrix.cpp. 00152 { 00153 if (mat1._nlines != mat2._nlines) return false; 00154 for (int i = 0; i < mat1._nlines; ++i) 00155 if (mat1._lines[i] != mat2._lines[i]) return false; 00156 return true; 00157 }
|
|
The elements themselves.
Definition at line 30 of file Matrix.h. Referenced by column(), line(), Matrix(), operator *(), operator MVector(), operator()(), operator+(), operator-(), operator<<(), operator==(), operator[](), and transpose(). |
|
Number of columns.
Definition at line 29 of file Matrix.h. Referenced by column(), ncols(), operator *(), operator MVector(), operator()(), operator+(), operator-(), and transpose(). |
|
Number of lines.
Definition at line 28 of file Matrix.h. Referenced by column(), line(), nlines(), operator *(), operator MVector(), operator()(), operator+(), operator-(), operator<<(), operator==(), operator[](), and transpose(). |