| [221] | 1 | /***************************************************************************
 | 
|---|
 | 2 |  * blitz/mattoep.h      Declarations for Toeplitz matrices
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  * $Id: mattoep.h,v 1.1.1.1 1999-04-09 17:59:00 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.3  1998/03/14 00:04:47  tveldhui
 | 
|---|
 | 27 |  * 0.2-alpha-05
 | 
|---|
 | 28 |  *
 | 
|---|
 | 29 |  * Revision 1.2  1997/01/24 14:42:00  tveldhui
 | 
|---|
 | 30 |  * Periodic RCS update
 | 
|---|
 | 31 |  *
 | 
|---|
 | 32 |  * Revision 1.1  1997/01/13 22:19:58  tveldhui
 | 
|---|
 | 33 |  * Periodic RCS update
 | 
|---|
 | 34 |  *
 | 
|---|
 | 35 |  *
 | 
|---|
 | 36 |  */
 | 
|---|
 | 37 | 
 | 
|---|
 | 38 | #ifndef BZ_MATTOEP_H
 | 
|---|
 | 39 | #define BZ_MATTOEP_H
 | 
|---|
 | 40 | 
 | 
|---|
 | 41 | #ifndef BZ_MSTRUCT_H
 | 
|---|
 | 42 |  #error <blitz/mattoep.h> must be included via <blitz/mstruct.h>
 | 
|---|
 | 43 | #endif
 | 
|---|
 | 44 | 
 | 
|---|
 | 45 | BZ_NAMESPACE(blitz)
 | 
|---|
 | 46 | 
 | 
|---|
 | 47 | // Toeplitz matrix
 | 
|---|
 | 48 | // [ 0 1 2 3 ]
 | 
|---|
 | 49 | // [ 1 2 3 4 ]
 | 
|---|
 | 50 | // [ 2 3 4 5 ]
 | 
|---|
 | 51 | // [ 3 4 5 6 ]
 | 
|---|
 | 52 | 
 | 
|---|
 | 53 | class ToeplitzIterator {
 | 
|---|
 | 54 | public:
 | 
|---|
 | 55 |     ToeplitzIterator(unsigned rows, unsigned cols)
 | 
|---|
 | 56 |     {
 | 
|---|
 | 57 |         rows_ = rows;
 | 
|---|
 | 58 |         cols_ = cols;
 | 
|---|
 | 59 |         i_ = 0;
 | 
|---|
 | 60 |         j_ = 0;
 | 
|---|
 | 61 |         good_ = true;
 | 
|---|
 | 62 |         offset_ = 0;
 | 
|---|
 | 63 |     }
 | 
|---|
 | 64 | 
 | 
|---|
 | 65 |     operator _bz_bool() const
 | 
|---|
 | 66 |     {
 | 
|---|
 | 67 |         return good_;
 | 
|---|
 | 68 |     }
 | 
|---|
 | 69 | 
 | 
|---|
 | 70 |     void operator++()
 | 
|---|
 | 71 |     {
 | 
|---|
 | 72 |         ++offset_;
 | 
|---|
 | 73 |         if (i_ < rows_ - 1)
 | 
|---|
 | 74 |             ++i_;
 | 
|---|
 | 75 |         else if (j_ < cols_ - 1)
 | 
|---|
 | 76 |             ++j_;
 | 
|---|
 | 77 |         else
 | 
|---|
 | 78 |             good_ = false;
 | 
|---|
 | 79 |     }
 | 
|---|
 | 80 | 
 | 
|---|
 | 81 |     unsigned row() const
 | 
|---|
 | 82 |     { return i_; }
 | 
|---|
 | 83 | 
 | 
|---|
 | 84 |     unsigned col() const
 | 
|---|
 | 85 |     { return j_; }
 | 
|---|
 | 86 | 
 | 
|---|
 | 87 |     unsigned offset() const
 | 
|---|
 | 88 |     { return offset_; }
 | 
|---|
 | 89 | 
 | 
|---|
 | 90 | protected:
 | 
|---|
 | 91 |     unsigned offset_;
 | 
|---|
 | 92 |     unsigned i_, j_;
 | 
|---|
 | 93 |     unsigned rows_, cols_;
 | 
|---|
 | 94 |     _bz_bool good_;
 | 
|---|
 | 95 | };
 | 
|---|
 | 96 | 
 | 
|---|
 | 97 | class Toeplitz : public GeneralMatrix {
 | 
|---|
 | 98 | 
 | 
|---|
 | 99 | public:
 | 
|---|
 | 100 |     typedef ToeplitzIterator T_iterator;
 | 
|---|
 | 101 | 
 | 
|---|
 | 102 |     Toeplitz()
 | 
|---|
 | 103 |         : rows_(0), cols_(0)
 | 
|---|
 | 104 |     { }
 | 
|---|
 | 105 | 
 | 
|---|
 | 106 |     Toeplitz(unsigned rows, unsigned cols)
 | 
|---|
 | 107 |         : rows_(rows), cols_(cols)
 | 
|---|
 | 108 |     { }
 | 
|---|
 | 109 | 
 | 
|---|
 | 110 |     unsigned columns() const
 | 
|---|
 | 111 |     { return cols_; }
 | 
|---|
 | 112 | 
 | 
|---|
 | 113 |     unsigned coordToOffset(unsigned i, unsigned j) const
 | 
|---|
 | 114 |     {
 | 
|---|
 | 115 |         BZPRECONDITION(inRange(i,j));
 | 
|---|
 | 116 |         return i + j;
 | 
|---|
 | 117 |     }
 | 
|---|
 | 118 | 
 | 
|---|
 | 119 |     unsigned firstInRow(unsigned i) const
 | 
|---|
 | 120 |     { return 0; }
 | 
|---|
 | 121 | 
 | 
|---|
 | 122 |     template<class T_numtype>
 | 
|---|
 | 123 |     T_numtype get(const T_numtype * _bz_restrict data,
 | 
|---|
 | 124 |         unsigned i, unsigned j) const
 | 
|---|
 | 125 |     {
 | 
|---|
 | 126 |         BZPRECONDITION(inRange(i,j));
 | 
|---|
 | 127 |         return data[coordToOffset(i,j)];
 | 
|---|
 | 128 |     }
 | 
|---|
 | 129 | 
 | 
|---|
 | 130 |     template<class T_numtype>
 | 
|---|
 | 131 |     T_numtype& get(T_numtype * _bz_restrict data, unsigned i, unsigned j)
 | 
|---|
 | 132 |     {
 | 
|---|
 | 133 |         BZPRECONDITION(inRange(i,j));
 | 
|---|
 | 134 |         return data[coordToOffset(i,j)];
 | 
|---|
 | 135 |     }
 | 
|---|
 | 136 | 
 | 
|---|
 | 137 |     unsigned lastInRow(unsigned i) const
 | 
|---|
 | 138 |     { return cols_ - 1; }
 | 
|---|
 | 139 | 
 | 
|---|
 | 140 |     unsigned firstInCol(unsigned j) const
 | 
|---|
 | 141 |     { return 0; }
 | 
|---|
 | 142 | 
 | 
|---|
 | 143 |     unsigned lastInCol(unsigned j) const
 | 
|---|
 | 144 |     { return rows_ - 1; }
 | 
|---|
 | 145 | 
 | 
|---|
 | 146 |     _bz_bool inRange(unsigned i, unsigned j) const
 | 
|---|
 | 147 |     {
 | 
|---|
 | 148 |         return (i < rows_) && (j < cols_);
 | 
|---|
 | 149 |     }
 | 
|---|
 | 150 | 
 | 
|---|
 | 151 |     unsigned numElements() const
 | 
|---|
 | 152 |     { return rows_ + cols_ - 1; }
 | 
|---|
 | 153 | 
 | 
|---|
 | 154 |     unsigned rows() const
 | 
|---|
 | 155 |     { return rows_; }
 | 
|---|
 | 156 | 
 | 
|---|
 | 157 |     void resize(unsigned rows, unsigned cols)
 | 
|---|
 | 158 |     {
 | 
|---|
 | 159 |         rows_ = rows;
 | 
|---|
 | 160 |         cols_ = cols;
 | 
|---|
 | 161 |     }
 | 
|---|
 | 162 | 
 | 
|---|
 | 163 | private:
 | 
|---|
 | 164 |     unsigned rows_, cols_;
 | 
|---|
 | 165 | };
 | 
|---|
 | 166 | 
 | 
|---|
 | 167 | BZ_NAMESPACE_END
 | 
|---|
 | 168 | 
 | 
|---|
 | 169 | #endif // BZ_MATSYMM_H
 | 
|---|
 | 170 | 
 | 
|---|