src/biu/Matrix.hh
Go to the documentation of this file.00001 #ifndef MATRIX_HH
00002 #define MATRIX_HH
00003
00004 #include <iostream>
00005 #include <vector>
00006 #include <cassert>
00007 #include "biu/assertbiu.hh"
00008
00009
00010 namespace biu {
00011
00012
00015 template <class T> class Matrix {
00016 protected:
00018 size_t rows;
00020 size_t cols;
00022 T **v;
00023 public:
00024
00026 Matrix();
00030 Matrix(const size_t r, const size_t c);
00035 Matrix(const size_t r, const size_t c, const T &val);
00042 Matrix(const size_t r, const size_t c, const T mat[]);
00045 Matrix(const Matrix<T> &mat);
00049 Matrix& operator = (const Matrix<T> &mat);
00053 Matrix& operator = (const T &val);
00058 Matrix<T> operator + (const Matrix<T> &mat);
00062 Matrix<T> operator + (const T &c);
00067 Matrix<T> operator - (const Matrix<T> &mat);
00071 Matrix<T> operator - (const T &c);
00076 Matrix<T> operator * (const Matrix<T> &mat) const;
00080 Matrix<T> operator * (const T &c) const;
00085 std::vector<T> operator * (const std::vector<T> &vec) const;
00090 Matrix<T>& operator *= (const Matrix<T> &mat);
00094 Matrix<T>& operator *= (const T& c);
00099 inline bool operator == (const Matrix<T> &mat) const;
00104 inline bool operator == (const T &val) const;
00109 inline bool operator != (const Matrix<T> &mat) const;
00114 inline bool operator != (const T &val) const;
00118 inline T* const operator[](const size_t row);
00122 inline const T* const operator[](const size_t row) const;
00127 inline T at(const size_t r, const size_t c) const;
00132 inline T& at(const size_t r, const size_t c);
00135 inline size_t numRows() const;
00138 inline size_t numColumns() const;
00142 std::vector<T> columnVec(const size_t col) const;
00147 void resize(const size_t row, const size_t col);
00153 void resize(const size_t row, const size_t col, const T& defVal);
00155 ~Matrix();
00156
00157 };
00158
00159 }
00160
00166 template <class T> inline
00167 std::istream&
00168 operator>>(std::istream& in, biu::Matrix<T>& m);
00169
00174 template <class T> inline
00175 std::ostream&
00176 operator << (std::ostream& out, const biu::Matrix<T>& m);
00177
00178 #include "biu/Matrix.icc"
00179
00180 #endif // define MATRIX_HH