source: XMLIO_V2/external/include/blitz/mattoep.h @ 73

Last change on this file since 73 was 73, checked in by ymipsl, 14 years ago
  • Property svn:eol-style set to native
File size: 3.4 KB
Line 
1/***************************************************************************
2 * blitz/mattoep.h      Declarations for Toeplitz matrices
3 *
4 * $Id: mattoep.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 * Suggestions:          blitz-dev@oonumerics.org
19 * Bugs:                 blitz-bugs@oonumerics.org
20 *
21 * For more information, please see the Blitz++ Home Page:
22 *    http://oonumerics.org/blitz/
23 *
24 ***************************************************************************/
25
26#ifndef BZ_MATTOEP_H
27#define BZ_MATTOEP_H
28
29#ifndef BZ_MSTRUCT_H
30 #error <blitz/mattoep.h> must be included via <blitz/mstruct.h>
31#endif
32
33BZ_NAMESPACE(blitz)
34
35// Toeplitz matrix
36// [ 0 1 2 3 ]
37// [ 1 2 3 4 ]
38// [ 2 3 4 5 ]
39// [ 3 4 5 6 ]
40
41class ToeplitzIterator {
42public:
43    ToeplitzIterator(unsigned rows, unsigned cols)
44    {
45        rows_ = rows;
46        cols_ = cols;
47        i_ = 0;
48        j_ = 0;
49        good_ = true;
50        offset_ = 0;
51    }
52
53    operator bool() const { return good_; }
54
55    void operator++()
56    {
57        ++offset_;
58        if (i_ < rows_ - 1)
59            ++i_;
60        else if (j_ < cols_ - 1)
61            ++j_;
62        else
63            good_ = false;
64    }
65
66    unsigned row() const
67    { return i_; }
68
69    unsigned col() const
70    { return j_; }
71
72    unsigned offset() const
73    { return offset_; }
74
75protected:
76    unsigned offset_;
77    unsigned i_, j_;
78    unsigned rows_, cols_;
79    bool     good_;
80};
81
82class Toeplitz : public GeneralMatrix {
83
84public:
85    typedef ToeplitzIterator T_iterator;
86
87    Toeplitz()
88        : rows_(0), cols_(0)
89    { }
90
91    Toeplitz(unsigned rows, unsigned cols)
92        : rows_(rows), cols_(cols)
93    { }
94
95    unsigned columns() const
96    { return cols_; }
97
98    unsigned coordToOffset(unsigned i, unsigned j) const
99    {
100        BZPRECONDITION(inRange(i,j));
101        return i + j;
102    }
103
104    unsigned firstInRow(unsigned i) const
105    { return 0; }
106
107    template<typename T_numtype>
108    T_numtype get(const T_numtype * restrict data,
109        unsigned i, unsigned j) const
110    {
111        BZPRECONDITION(inRange(i,j));
112        return data[coordToOffset(i,j)];
113    }
114
115    template<typename T_numtype>
116    T_numtype& get(T_numtype * restrict data, unsigned i, unsigned j)
117    {
118        BZPRECONDITION(inRange(i,j));
119        return data[coordToOffset(i,j)];
120    }
121
122    unsigned lastInRow(const unsigned)  const { return cols_ - 1; }
123    unsigned firstInCol(const unsigned) const { return 0; }
124    unsigned lastInCol(const unsigned)  const { return rows_ - 1; }
125
126    bool inRange(const unsigned i,const unsigned j) const { return (i<rows_) && (j<cols_); }
127
128    unsigned numElements() const { return rows_ + cols_ - 1; }
129
130    unsigned rows() const { return rows_; }
131
132    void resize(const unsigned rows,const unsigned cols) {
133        rows_ = rows;
134        cols_ = cols;
135    }
136
137private:
138    unsigned rows_, cols_;
139};
140
141BZ_NAMESPACE_END
142
143#endif // BZ_MATSYMM_H
144
Note: See TracBrowser for help on using the repository browser.