Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tmatrix.h
Go to the documentation of this file.
1 /*
2  * tmatrix.h - simple matrix template class definitions
3  *
4  * Copyright (C) 2004, 2005, 2006 Stefan Jahn <stefan@lkcc.org>
5  *
6  * This is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * This software is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this package; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  * $Id$
22  *
23  */
24 
25 #ifndef __TMATRIX_H__
26 #define __TMATRIX_H__
27 
28 #include <assert.h>
29 
30 namespace qucs {
31 
32 template <class nr_type_t>
33 class tmatrix;
34 
35 // Forward declarations of friend functions.
36 template <class nr_type_t>
38 template <class nr_type_t>
40 template <class nr_type_t>
42 template <class nr_type_t>
44 template <class nr_type_t>
46 
47 template <class nr_type_t>
48 class tmatrix
49 {
50  public:
51  tmatrix ();
52  tmatrix (int);
53  tmatrix (int, int);
54  tmatrix (const tmatrix &);
55  const tmatrix& operator = (const tmatrix &);
56  ~tmatrix ();
57  nr_type_t get (int, int);
58  void set (int, int, nr_type_t);
59  void set (nr_type_t);
60  int getCols (void) { return cols; }
61  int getRows (void) { return rows; }
62  nr_type_t * getData (void) { return data; }
63  tvector<nr_type_t> getRow (int);
64  void setRow (int, tvector<nr_type_t>);
65  tvector<nr_type_t> getCol (int);
66  void setCol (int, tvector<nr_type_t>);
67  void exchangeRows (int, int);
68  void exchangeCols (int, int);
69  void transpose (void);
70  int isFinite (void);
71  void print (bool realonly = false);
72 
73  // some basic matrix operations
74 #ifndef _MSC_VER
75  friend tmatrix inverse<> (tmatrix);
76  friend tmatrix teye<nr_type_t> (int);
77  friend tmatrix operator *<> (tmatrix, tmatrix);
78  friend tvector<nr_type_t> operator *<> (tmatrix, tvector<nr_type_t>);
79  friend tvector<nr_type_t> operator *<> (tvector<nr_type_t>, tmatrix);
80 #endif
81 
82  // intrinsic operators
85 
86  // easy accessor operators
87  nr_type_t operator () (int r, int c) const {
88  assert (r >= 0 && r < rows && c >= 0 && c < cols);
89  return data[r * cols + c]; }
90  nr_type_t& operator () (int r, int c) {
91  assert (r >= 0 && r < rows && c >= 0 && c < cols);
92  return data[r * cols + c]; }
93 
94  private:
95  int cols;
96  int rows;
97  nr_type_t * data;
98 };
99 
100 } // namespace qucs
101 
102 #include "tmatrix.cpp"
103 
104 #endif /* __TMATRIX_H__ */
matrix inverse(matrix a)
Compute inverse matrix.
Definition: matrix.cpp:847
matrix operator*(matrix a, nr_complex_t z)
Matrix scaling complex version.
Definition: matrix.cpp:298
void setRow(int, tvector< nr_type_t >)
Definition: tmatrix.cpp:144
int isFinite(void)
Definition: tmatrix.cpp:333
void set(int, int, nr_type_t)
Definition: tmatrix.cpp:120
nr_type_t operator()(int r, int c) const
Definition: tmatrix.h:87
nr_type_t * getData(void)
Definition: tmatrix.h:62
void exchangeRows(int, int)
Definition: tmatrix.cpp:173
r
Definition: parse_mdl.y:515
tmatrix< nr_type_t > teye(int n)
Definition: tmatrix.cpp:247
tvector< nr_type_t > getRow(int)
Definition: tmatrix.cpp:133
void setCol(int, tvector< nr_type_t >)
Definition: tmatrix.cpp:164
const tmatrix & operator=(const tmatrix &)
Definition: tmatrix.cpp:92
tmatrix operator-=(tmatrix)
Definition: tmatrix.cpp:265
tmatrix operator+=(tmatrix)
Definition: tmatrix.cpp:255
void print(bool realonly=false)
tvector< nr_type_t > getCol(int)
Definition: tmatrix.cpp:153
List int
Definition: parse_citi.y:183
void exchangeCols(int, int)
Definition: tmatrix.cpp:185
nr_type_t * data
Definition: tmatrix.h:97
int getCols(void)
Definition: tmatrix.h:60
void transpose(void)
Definition: tmatrix.cpp:321
int getRows(void)
Definition: tmatrix.h:61