#ifndef MATRIX_H #define MATRIX_H #include #include #include class matrix_proxy; // forward reference as place holder using namespace std; /***************************************************** * range class ****************************************************/ class range { private: int _start; int _stop; int _stride; public: // supports construction such as range(3) for the singleton set {3} range(int start); // supports construction such as range(3,6), which includes values {3, 4, 5} range(int start, int stop); // supports construction such as range(3,2,8), which includes values {3, 5, 7} range(int start, int stride, int stop); // Returns starting index int start() const; // Returns stopping index int stop() const; // Returns stopping index int stride() const; // Returns the number of values included within the range int size() const; }; /***************************************************** * matrix class ****************************************************/ class matrix { private: int _nr; /* number of rows */ int _nc; /* number of columns */ vector _data; /* underlying data storage */ public: matrix(); matrix(int numRows, int numColumns, double value=0); int numRows() const; int numColumns() const; matrix size() const; void reshape(int r, int c); bool operator==(const matrix &other) const; bool operator!=(const matrix &other) const; // provides read-only access to a matrix entry double operator()(int r, int c) const; // provides write access to a matrix entry (albeit, without expansion) double& operator()(int r, int c); // provides write access to a submatrix as a proxy matrix_proxy operator()(range rows, range cols); //----------------------------------------------- // addition //----------------------------------------------- matrix operator+(const matrix& other) const; matrix operator+(double scalar) const; //----------------------------------------------- // multiplication //----------------------------------------------- matrix operator*(double scalar) const; matrix operator*(const matrix& other) const; }; //------------------------------------------------------ // define additional support for reading/writing matrices //------------------------------------------------------ ostream& operator<<(ostream& out, const matrix& m); istream& operator>>(istream& in, matrix& m); #include "matrix_proxy.h" // time to get the full class definition #endif