Matrix class implementation file. More...
Functions | |
Matrix | operator+ (const Matrix &lhs, const Matrix &rhs) |
Matrix | operator- (const Matrix &lhs, const Matrix &rhs) |
Matrix | operator* (const Matrix &lhs, const Matrix &rhs) |
Matrix | operator* (double s, const Matrix &mat) |
Matrix | operator* (const Matrix &mat, double s) |
Matrix | operator/ (const Matrix &mat, double s) |
std::ostream & | operator<< (std::ostream &outputStream, const Matrix &mat) |
Stream insertion operator. | |
std::istream & | operator>> (std::istream &inputStream, Matrix &mat) |
Stream extraction operator. | |
Matrix class implementation file.
This creates the product of two Matrices. The first Matrix must have the same number of columns as the second Matrix has rows.
Note that multiplication is declared as a friend. It could be declared as a normal method Matrix operator*(const Matrix& rhs);
. The friend form provides a more symmetric view of the two Matrices being multiplied.
lhs | The Matrix on the left hand side of the *. |
rhs | The Matrix on the right hand side of the *. |
This performs addition of two Matrices. The two Matrices must have the same size
Note that addition is declared as a friend. It could be declared as a normal method Matrix operator+(const Matrix& rhs);
. The friend form provides a more symmetric view of the two Matrices being added.
lhs | The Matrix on the left hand side of the +. |
rhs | The Matrix on the right hand side of the +. |
This performs subtraction of two Matrices. The two Matrices must have the same size
Note that subtraction is declared as a friend. It could be declared as a normal method Matrix operator-(const Matrix& rhs);
. The friend form provides a more symmetric view of the two Matrices being subtracted.
lhs | The Matrix on the left hand side of the -. |
rhs | The Matrix on the right hand side of the -. |
This creates the result of a Matrix divided by a scalar. Division by a scalar, s, is essentially the same as multiplcation (or scaling) by 1/s. Division by numbers close to 0 will result in NaN
and Inf
values and wildly unstable results as normal.
Note that division is declared as a friend. In this case a normal method Matrix operator/(const scalar s);
would be probably OK, but inconsistent with other operators.
std::ostream& operator<< | ( | std::ostream & | outputStream, |
const Matrix & | mat | ||
) |
Stream insertion operator.
Provides the ability to output Matrices to C++ streams, including std::cout
and filestreams
.
Note that the stream operators do not require special access to the Matrix internals, so are not members or friends.
outputStream | the stream to send the Matrix to. |
mat | the matrix to send to the stream. |
std::istream& operator>> | ( | std::istream & | inputStream, |
Matrix & | mat | ||
) |
Stream extraction operator.
Provides the ability to read Matrices from C++ streams, including std::cin
and filestreams
. The size of the Matrix determines how much data is read from the stream.
Note that the stream operators do not require special access to the Matrix internals, so are not members or friends.
inputStream | the stream to read the Matrix from. |
mat | the matrix to read from the stream. |