Qucs-core  0.0.19
tmatrix.h
Go to the documentation of this file.
00001 /*
00002  * tmatrix.h - simple matrix template class definitions
00003  *
00004  * Copyright (C) 2004, 2005, 2006 Stefan Jahn <stefan@lkcc.org>
00005  *
00006  * This is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2, or (at your option)
00009  * any later version.
00010  *
00011  * This software is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this package; see the file COPYING.  If not, write to
00018  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  *
00021  * $Id$
00022  *
00023  */
00024 
00025 #ifndef __TMATRIX_H__
00026 #define __TMATRIX_H__
00027 
00028 #include <assert.h>
00029 
00030 namespace qucs {
00031 
00032 template <class nr_type_t>
00033 class tmatrix;
00034 
00035 // Forward declarations of friend functions.
00036 template <class nr_type_t>
00037 tmatrix<nr_type_t> inverse (tmatrix<nr_type_t>);
00038 template <class nr_type_t>
00039 tmatrix<nr_type_t> teye (int);
00040 template <class nr_type_t>
00041 tmatrix<nr_type_t> operator * (tmatrix<nr_type_t>, tmatrix<nr_type_t>);
00042 template <class nr_type_t>
00043 tvector<nr_type_t> operator * (tmatrix<nr_type_t>, tvector<nr_type_t>);
00044 template <class nr_type_t>
00045 tvector<nr_type_t> operator * (tvector<nr_type_t>, tmatrix<nr_type_t>);
00046 
00047 template <class nr_type_t>
00048 class tmatrix
00049 {
00050  public:
00051   tmatrix ();
00052   tmatrix (int);
00053   tmatrix (int, int);
00054   tmatrix (const tmatrix &);
00055   const tmatrix& operator = (const tmatrix &);
00056   ~tmatrix ();
00057   nr_type_t get (int, int);
00058   void set (int, int, nr_type_t);
00059   void set (nr_type_t);
00060   int  getCols (void) { return cols; }
00061   int  getRows (void) { return rows; }
00062   nr_type_t * getData (void) { return data; }
00063   tvector<nr_type_t> getRow (int);
00064   void setRow (int, tvector<nr_type_t>);
00065   tvector<nr_type_t> getCol (int);
00066   void setCol (int, tvector<nr_type_t>);
00067   void exchangeRows (int, int);
00068   void exchangeCols (int, int);
00069   void transpose (void);
00070   int  isFinite (void);
00071   void print (bool realonly = false);
00072 
00073   // some basic matrix operations
00074 #ifndef _MSC_VER
00075   friend tmatrix inverse<> (tmatrix);
00076   friend tmatrix teye<nr_type_t> (int);
00077   friend tmatrix operator *<> (tmatrix, tmatrix);
00078   friend tvector<nr_type_t> operator *<> (tmatrix, tvector<nr_type_t>);
00079   friend tvector<nr_type_t> operator *<> (tvector<nr_type_t>, tmatrix);
00080 #endif
00081 
00082   // intrinsic operators
00083   tmatrix operator += (tmatrix);
00084   tmatrix operator -= (tmatrix);
00085 
00086   // easy accessor operators
00087   nr_type_t  operator () (int r, int c) const {
00088     assert (r >= 0 && r < rows && c >= 0 && c < cols);
00089     return data[r * cols + c]; }
00090   nr_type_t& operator () (int r, int c) {
00091     assert (r >= 0 && r < rows && c >= 0 && c < cols);
00092     return data[r * cols + c]; }
00093 
00094  private:
00095   int cols;
00096   int rows;
00097   nr_type_t * data;
00098 };
00099 
00100 } // namespace qucs
00101 
00102 #include "tmatrix.cpp"
00103 
00104 #endif /* __TMATRIX_H__ */