00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef BZ_MATTOEP_H
00027 #define BZ_MATTOEP_H
00028
00029 #ifndef BZ_MSTRUCT_H
00030 #error <blitz/mattoep.h> must be included via <blitz/mstruct.h>
00031 #endif
00032
00033 BZ_NAMESPACE(blitz)
00034
00035
00036
00037
00038
00039
00040
00041 class ToeplitzIterator {
00042 public:
00043 ToeplitzIterator(unsigned rows, unsigned cols)
00044 {
00045 rows_ = rows;
00046 cols_ = cols;
00047 i_ = 0;
00048 j_ = 0;
00049 good_ = true;
00050 offset_ = 0;
00051 }
00052
00053 operator bool() const { return good_; }
00054
00055 void operator++()
00056 {
00057 ++offset_;
00058 if (i_ < rows_ - 1)
00059 ++i_;
00060 else if (j_ < cols_ - 1)
00061 ++j_;
00062 else
00063 good_ = false;
00064 }
00065
00066 unsigned row() const
00067 { return i_; }
00068
00069 unsigned col() const
00070 { return j_; }
00071
00072 unsigned offset() const
00073 { return offset_; }
00074
00075 protected:
00076 unsigned offset_;
00077 unsigned i_, j_;
00078 unsigned rows_, cols_;
00079 bool good_;
00080 };
00081
00082 class Toeplitz : public GeneralMatrix {
00083
00084 public:
00085 typedef ToeplitzIterator T_iterator;
00086
00087 Toeplitz()
00088 : rows_(0), cols_(0)
00089 { }
00090
00091 Toeplitz(unsigned rows, unsigned cols)
00092 : rows_(rows), cols_(cols)
00093 { }
00094
00095 unsigned columns() const
00096 { return cols_; }
00097
00098 unsigned coordToOffset(unsigned i, unsigned j) const
00099 {
00100 BZPRECONDITION(inRange(i,j));
00101 return i + j;
00102 }
00103
00104 unsigned firstInRow(unsigned i) const
00105 { return 0; }
00106
00107 template<typename T_numtype>
00108 T_numtype get(const T_numtype * restrict data,
00109 unsigned i, unsigned j) const
00110 {
00111 BZPRECONDITION(inRange(i,j));
00112 return data[coordToOffset(i,j)];
00113 }
00114
00115 template<typename T_numtype>
00116 T_numtype& get(T_numtype * restrict data, unsigned i, unsigned j)
00117 {
00118 BZPRECONDITION(inRange(i,j));
00119 return data[coordToOffset(i,j)];
00120 }
00121
00122 unsigned lastInRow(const unsigned) const { return cols_ - 1; }
00123 unsigned firstInCol(const unsigned) const { return 0; }
00124 unsigned lastInCol(const unsigned) const { return rows_ - 1; }
00125
00126 bool inRange(const unsigned i,const unsigned j) const { return (i<rows_) && (j<cols_); }
00127
00128 unsigned numElements() const { return rows_ + cols_ - 1; }
00129
00130 unsigned rows() const { return rows_; }
00131
00132 void resize(const unsigned rows,const unsigned cols) {
00133 rows_ = rows;
00134 cols_ = cols;
00135 }
00136
00137 private:
00138 unsigned rows_, cols_;
00139 };
00140
00141 BZ_NAMESPACE_END
00142
00143 #endif // BZ_MATSYMM_H
00144