Matrices  1.0
Basic matrix library
 All Classes Files Functions Variables Friends
Matrix.h
Go to the documentation of this file.
1 #pragma once
2 
3 #ifndef MATRIX_H_INCLUDED
4 #define MATRIX_H_INCLUDED
5 
10 #include <vector>
11 #include <iostream>
12 
22 class Matrix {
23 
24 public:
25 
34  Matrix(size_t size=1);
35 
45  Matrix(size_t rows, size_t cols);
46 
55  Matrix(const Matrix& mat);
56 
63  virtual ~Matrix();
64 
74  Matrix& operator=(const Matrix& mat);
75 
76  // Handy factory methods
77 
89  static Matrix identity(size_t rows, size_t cols);
90 
101  static Matrix zero(size_t rows, size_t cols);
102 
115  double& operator()(size_t row, size_t col);
116 
128  const double& operator()(size_t row, size_t col) const;
129 
135  size_t numRows() const;
136 
142  size_t numCols() const;
143 
149  size_t numElements() const;
150 
159  Matrix operator-() const;
160 
175  friend Matrix operator+(const Matrix& lhs, const Matrix& rhs);
176 
186  Matrix& operator+=(const Matrix& mat);
187 
202  friend Matrix operator-(const Matrix& lhs, const Matrix& rhs);
203 
213  Matrix& operator-=(const Matrix& mat);
214 
229  friend Matrix operator*(const Matrix& lhs, const Matrix& rhs);
230 
243  friend Matrix operator*(double s, const Matrix& mat);
244 
257  friend Matrix operator*(const Matrix& mat, double s);
258 
259 
273  Matrix& operator*=(double s);
274 
289  friend Matrix operator/(const Matrix& mat, double s);
290 
299  Matrix& operator/=(double s);
300 
308  Matrix transpose() const;
309 
310 protected:
311 
312  size_t rows_;
313  size_t cols_;
314  std::vector<double> data_;
315 
316 };
317 
329 std::ostream& operator<<(std::ostream& outputStream, const Matrix& mat);
330 
331 
344 std::istream& operator>>(std::istream& inputStream, Matrix& mat);
345 
346 #endif // MATRIX_H_INCLUDED