Spectral analysis.
Fork of Array_Matrix by
Matrix.hpp@3:48ec80041973, 2017-08-30 (annotated)
- Committer:
- mladjo1993
- Date:
- Wed Aug 30 07:43:07 2017 +0000
- Revision:
- 3:48ec80041973
- Parent:
- 0:efe9b1f01090
Final version.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 0:efe9b1f01090 | 1 | //------------------------------------------------------------------------------ |
MikamiUitOpen | 0:efe9b1f01090 | 2 | // Generic 2-dimensional array class ---- Matrix |
MikamiUitOpen | 0:efe9b1f01090 | 3 | // |
MikamiUitOpen | 0:efe9b1f01090 | 4 | // 2016/05/22, Copyright (c) 2016 MIKAMI, Naoki |
MikamiUitOpen | 0:efe9b1f01090 | 5 | //------------------------------------------------------------------------------ |
MikamiUitOpen | 0:efe9b1f01090 | 6 | |
MikamiUitOpen | 0:efe9b1f01090 | 7 | #ifndef MIKAMI_MATRIX_HPP |
MikamiUitOpen | 0:efe9b1f01090 | 8 | #define MIKAMI_MATRIX_HPP |
MikamiUitOpen | 0:efe9b1f01090 | 9 | |
MikamiUitOpen | 0:efe9b1f01090 | 10 | #include "Array.hpp" |
MikamiUitOpen | 0:efe9b1f01090 | 11 | |
mladjo1993 | 3:48ec80041973 | 12 | namespace etf |
MikamiUitOpen | 0:efe9b1f01090 | 13 | { |
MikamiUitOpen | 0:efe9b1f01090 | 14 | template <class T> class Matrix |
MikamiUitOpen | 0:efe9b1f01090 | 15 | { |
MikamiUitOpen | 0:efe9b1f01090 | 16 | public: |
MikamiUitOpen | 0:efe9b1f01090 | 17 | explicit Matrix(int rows = 1, int cols = 1); |
MikamiUitOpen | 0:efe9b1f01090 | 18 | Matrix(int rows, int cols, T initialValue); |
MikamiUitOpen | 0:efe9b1f01090 | 19 | void Fill(T val); |
MikamiUitOpen | 0:efe9b1f01090 | 20 | void SetSize(int rows, int cols); // setting size |
MikamiUitOpen | 0:efe9b1f01090 | 21 | Array<T>& operator[](int i) { return vv_[i]; } // assign by element |
MikamiUitOpen | 0:efe9b1f01090 | 22 | const Array<T>& operator[](int i) const { return vv_[i]; } //get element |
MikamiUitOpen | 0:efe9b1f01090 | 23 | int Rows() const { return vv_.Length(); } |
MikamiUitOpen | 0:efe9b1f01090 | 24 | int Cols() const { return vv_[0].Length(); } |
MikamiUitOpen | 0:efe9b1f01090 | 25 | private: |
MikamiUitOpen | 0:efe9b1f01090 | 26 | Array< Array<T> > vv_; |
MikamiUitOpen | 0:efe9b1f01090 | 27 | }; |
MikamiUitOpen | 0:efe9b1f01090 | 28 | |
MikamiUitOpen | 0:efe9b1f01090 | 29 | //----------------------------------------------------------------------- |
MikamiUitOpen | 0:efe9b1f01090 | 30 | // implementation of generic 2-dimensional array class |
MikamiUitOpen | 0:efe9b1f01090 | 31 | //----------------------------------------------------------------------- |
MikamiUitOpen | 0:efe9b1f01090 | 32 | template <class T> Matrix<T>::Matrix(int rows, int cols): vv_(rows) |
MikamiUitOpen | 0:efe9b1f01090 | 33 | { |
MikamiUitOpen | 0:efe9b1f01090 | 34 | Array<T> a(cols); |
MikamiUitOpen | 0:efe9b1f01090 | 35 | for (int i=0; i<rows; i++) vv_[i] = a; |
MikamiUitOpen | 0:efe9b1f01090 | 36 | } |
MikamiUitOpen | 0:efe9b1f01090 | 37 | |
MikamiUitOpen | 0:efe9b1f01090 | 38 | template <class T> Matrix<T>::Matrix(int rows, int cols, T initialValue) |
MikamiUitOpen | 0:efe9b1f01090 | 39 | : vv_(rows) |
MikamiUitOpen | 0:efe9b1f01090 | 40 | { |
MikamiUitOpen | 0:efe9b1f01090 | 41 | Array<T> a(cols, initialValue); |
MikamiUitOpen | 0:efe9b1f01090 | 42 | for (int i=0; i<rows; i++) vv_[i] = a; |
MikamiUitOpen | 0:efe9b1f01090 | 43 | } |
MikamiUitOpen | 0:efe9b1f01090 | 44 | |
MikamiUitOpen | 0:efe9b1f01090 | 45 | template <class T> void Matrix<T>::Fill(T val) |
MikamiUitOpen | 0:efe9b1f01090 | 46 | { |
MikamiUitOpen | 0:efe9b1f01090 | 47 | for (int n=0; n<Rows(); n++) vv_[n].Fill(val); |
MikamiUitOpen | 0:efe9b1f01090 | 48 | } |
MikamiUitOpen | 0:efe9b1f01090 | 49 | |
MikamiUitOpen | 0:efe9b1f01090 | 50 | template <class T> void Matrix<T>::SetSize(int rows, int cols) |
MikamiUitOpen | 0:efe9b1f01090 | 51 | { |
MikamiUitOpen | 0:efe9b1f01090 | 52 | Array<T> a(cols); |
MikamiUitOpen | 0:efe9b1f01090 | 53 | vv_.SetSize(rows); |
MikamiUitOpen | 0:efe9b1f01090 | 54 | for (int i=0; i<rows; i++) vv_[i] = a; |
MikamiUitOpen | 0:efe9b1f01090 | 55 | } |
MikamiUitOpen | 0:efe9b1f01090 | 56 | } |
MikamiUitOpen | 0:efe9b1f01090 | 57 | #endif // MIKAMI_MATRIX_HPP |
MikamiUitOpen | 0:efe9b1f01090 | 58 |