Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Matrix.hpp
00001 //------------------------------------------------------------------------------ 00002 // Generic 2-dimensional array class ---- Matrix 00003 // 00004 // 2016/05/22, Copyright (c) 2016 MIKAMI, Naoki 00005 //------------------------------------------------------------------------------ 00006 00007 #ifndef MIKAMI_MATRIX_HPP 00008 #define MIKAMI_MATRIX_HPP 00009 00010 #include "Array.hpp" 00011 00012 namespace Mikami 00013 { 00014 template <class T> class Matrix 00015 { 00016 public: 00017 explicit Matrix(int rows = 1, int cols = 1); 00018 Matrix(int rows, int cols, T initialValue); 00019 void Fill(T val); 00020 void SetSize(int rows, int cols); // setting size 00021 Array<T>& operator[](int i) { return vv_[i]; } // assign by element 00022 const Array<T>& operator[](int i) const { return vv_[i]; } //get element 00023 int Rows() const { return vv_.Length(); } 00024 int Cols() const { return vv_[0].Length(); } 00025 private: 00026 Array< Array<T> > vv_; 00027 }; 00028 00029 //----------------------------------------------------------------------- 00030 // implementation of generic 2-dimensional array class 00031 //----------------------------------------------------------------------- 00032 template <class T> Matrix<T>::Matrix(int rows, int cols): vv_(rows) 00033 { 00034 Array<T> a(cols); 00035 for (int i=0; i<rows; i++) vv_[i] = a; 00036 } 00037 00038 template <class T> Matrix<T>::Matrix(int rows, int cols, T initialValue) 00039 : vv_(rows) 00040 { 00041 Array<T> a(cols, initialValue); 00042 for (int i=0; i<rows; i++) vv_[i] = a; 00043 } 00044 00045 template <class T> void Matrix<T>::Fill(T val) 00046 { 00047 for (int n=0; n<Rows(); n++) vv_[n].Fill(val); 00048 } 00049 00050 template <class T> void Matrix<T>::SetSize(int rows, int cols) 00051 { 00052 Array<T> a(cols); 00053 vv_.SetSize(rows); 00054 for (int i=0; i<rows; i++) vv_[i] = a; 00055 } 00056 } 00057 #endif // MIKAMI_MATRIX_HPP 00058
Generated on Tue Jul 12 2022 15:39:21 by
1.7.2