source: Sophya/trunk/Poubelle/DPC:FitsIOServer/Blitz/blitz/matdiag.h@ 1036

Last change on this file since 1036 was 658, checked in by ansari, 26 years ago

no message

File size: 3.9 KB
Line 
1/***************************************************************************
2 * blitz/matdiag.h Declarations for Diagonal matrices
3 *
4 * $Id: matdiag.h,v 1.1.1.1 1999-11-26 16:37:03 ansari Exp $
5 *
6 * Copyright (C) 1997,1998 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca>
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 * Suggestions: blitz-suggest@cybervision.com
19 * Bugs: blitz-bugs@cybervision.com
20 *
21 * For more information, please see the Blitz++ Home Page:
22 * http://seurat.uwaterloo.ca/blitz/
23 *
24 ***************************************************************************
25 * $Log: not supported by cvs2svn $
26 * Revision 1.1.1.1 1999/04/09 17:59:00 ansari
27 * Creation module DPC/Blitz (blitz 0.4) Reza 09/04/99
28 *
29 * Revision 1.3 1998/03/14 00:04:47 tveldhui
30 * 0.2-alpha-05
31 *
32 * Revision 1.2 1997/01/24 14:42:00 tveldhui
33 * Periodic RCS update
34 *
35 * Revision 1.1 1997/01/13 22:19:58 tveldhui
36 * Periodic RCS update
37 *
38 *
39 */
40
41#ifndef BZ_MATDIAG_H
42#define BZ_MATDIAG_H
43
44#ifndef BZ_MSTRUCT_H
45 #error <blitz/matdiag.h> must be included via <blitz/mstruct.h>
46#endif
47
48BZ_NAMESPACE(blitz)
49
50// Diagonal matrix
51// [ 0 . . . ]
52// [ . 1 . . ]
53// [ . . 2 . ]
54// [ . . . 3 ]
55
56class DiagonalIterator {
57public:
58 DiagonalIterator(unsigned rows, unsigned cols)
59 {
60 BZPRECONDITION(rows == cols);
61 size_ = rows;
62 i_ = 0;
63 }
64
65 operator _bz_bool() const
66 {
67 return i_ < size_;
68 }
69
70 void operator++()
71 {
72 ++i_;
73 }
74
75 unsigned row() const
76 { return i_; }
77
78 unsigned col() const
79 { return i_; }
80
81 unsigned offset() const
82 { return i_; }
83
84protected:
85 unsigned i_, size_;
86};
87
88class Diagonal : public MatrixStructure {
89
90public:
91 typedef DiagonalIterator T_iterator;
92
93 Diagonal()
94 : size_(0)
95 { }
96
97 Diagonal(unsigned size)
98 : size_(size)
99 { }
100
101 Diagonal(unsigned rows, unsigned cols)
102 : size_(rows)
103 {
104 BZPRECONDITION(rows == cols);
105 }
106
107 unsigned columns() const
108 { return size_; }
109
110 unsigned coordToOffset(unsigned i, unsigned j) const
111 {
112 BZPRECONDITION(inRange(i,j));
113 BZPRECONDITION(i == j);
114 return i;
115 }
116
117 unsigned firstInRow(unsigned i) const
118 { return i; }
119
120 template<class T_numtype>
121 T_numtype get(const T_numtype * _bz_restrict data,
122 unsigned i, unsigned j) const
123 {
124 BZPRECONDITION(inRange(i,j));
125 if (i == j)
126 return data[coordToOffset(i,j)];
127 else
128 return ZeroElement<T_numtype>::zero();
129 }
130
131 template<class T_numtype>
132 T_numtype& get(T_numtype * _bz_restrict data, unsigned i, unsigned j)
133 {
134 BZPRECONDITION(inRange(i,j));
135 if (i == j)
136 return data[coordToOffset(i,j)];
137 else
138 return ZeroElement<T_numtype>::zero();
139 }
140
141 unsigned lastInRow(unsigned i) const
142 { return i; }
143
144 unsigned firstInCol(unsigned j) const
145 { return j; }
146
147 unsigned lastInCol(unsigned j) const
148 { return j; }
149
150 _bz_bool inRange(unsigned i, unsigned j) const
151 {
152 return (i < size_) && (j < size_);
153 }
154
155 unsigned numElements() const
156 { return size_; }
157
158 unsigned rows() const
159 { return size_; }
160
161 void resize(unsigned size)
162 {
163 size_ = size;
164 }
165
166 void resize(unsigned rows, unsigned cols)
167 {
168 BZPRECONDITION(rows == cols);
169 size_ = rows;
170 }
171
172private:
173 unsigned size_;
174};
175
176BZ_NAMESPACE_END
177
178#endif // BZ_MATSYMM_H
179
Note: See TracBrowser for help on using the repository browser.