blitz  Version 0.9
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mstruct.h
Go to the documentation of this file.
1 /***************************************************************************
2  * blitz/mstruct.h Matrix structure classes
3  *
4  * $Id: mstruct.h,v 1.4 2003/12/11 03:44:22 julianc Exp $
5  *
6  * Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  *
19  * Suggestions: blitz-dev@oonumerics.org
20  * Bugs: blitz-bugs@oonumerics.org
21  *
22  * For more information, please see the Blitz++ Home Page:
23  * http://oonumerics.org/blitz/
24  *
25  ***************************************************************************/
26 
27 #ifndef BZ_MSTRUCT_H
28 #define BZ_MSTRUCT_H
29 
30 #ifndef BZ_BLITZ_H
31  #include <blitz/blitz.h>
32 #endif
33 
34 #ifndef BZ_ZERO_H
35  #include <blitz/zero.h>
36 #endif
37 
38 /*
39  * Each matrix structure class encapsulates a storage format for matrix
40  * data. It is responsible for:
41  * - Storing the size of the matrix
42  * - Calculating how many unique elements the matrix will have
43  * - Mapping indices (i,j) onto memory locations
44  * - Performing any sign reversals or conjugations when matrix
45  * elements are retrieved (e.g. in a Hermitian or Skew symmetric
46  * matrix)
47  *
48  * Every matrix structure class must provide these methods:
49  *
50  * ctor()
51  * ctor(unsigned rows, unsigned cols)
52  * unsigned columns() const;
53  * unsigned cols() const;
54  * unsigned firstInRow() const;
55  * unsigned firstInCol() const;
56  * template<typename T> T& get(T* data, unsigned i, unsigned j);
57  * template<typename T> T get(const T* data, unsigned i, unsigned j) const;
58  * bool inRange(unsigned i, unsigned j) const
59  * unsigned lastInRow() const;
60  * unsigned lastInCol() const;
61  * unsigned numElements() const;
62  * void resize(unsigned rows, unsigned cols);
63  * unsigned rows() const;
64  *
65  * Each matrix structure class must declare a public type
66  * T_iterator which is an iterator to scan through the unique
67  * entries of the matrix. The iterator class must provide
68  * these methods:
69  *
70  * ctor(unsigned rows, unsigned cols)
71  * unsigned offset() const
72  * operator bool() const
73  * unsigned row() const
74  * unsigned col() const
75  */
76 
77 BZ_NAMESPACE(blitz)
78 
79 class MatrixStructure { };
80 
82 public:
84  : rows_(0), cols_(0)
85  { }
86 
87  AsymmetricMatrix(unsigned rows, unsigned cols)
88  : rows_(rows), cols_(cols)
89  { }
90 
91  unsigned columns() const { return cols_; }
92 
93  unsigned cols() const { return cols_; }
94 
95  bool inRange(const unsigned i,const unsigned j) const {
96  return (i<rows_) && (j<cols_);
97  }
98 
99  void resize(unsigned rows, unsigned cols) {
100  rows_ = rows;
101  cols_ = cols;
102  }
103 
104  unsigned rows() const { return rows_; }
105 
106 protected:
107  unsigned rows_, cols_;
108 };
109 
110 // Still to be implemented:
111 // SkewSymmetric
112 // Hermitian
113 // Tridiagonal
114 // Banded<L,H>
115 // Upper bidiagonal
116 // Lower bidiagonal
117 // Upper Hessenberg
118 // Lower Hessenberg
119 
121 
122 #include <blitz/matgen.h> // RowMajor and ColumnMajor general matrices
123 #include <blitz/matsymm.h> // Symmetric
124 #include <blitz/matdiag.h> // Diagonal
125 #include <blitz/mattoep.h> // Toeplitz
126 #include <blitz/matltri.h> // Lower triangular
127 #include <blitz/matutri.h> // Upper triangular
128 
129 #endif // BZ_MSTRUCT_H