blitz Version 0.9
|
00001 /*************************************************************************** 00002 * blitz/mattoep.h Declarations for Toeplitz matrices 00003 * 00004 * $Id: mattoep.h,v 1.4 2003/12/11 03:44:22 julianc Exp $ 00005 * 00006 * Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org> 00007 * 00008 * This program is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU General Public License 00010 * as published by the Free Software Foundation; either version 2 00011 * of the License, or (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * Suggestions: blitz-dev@oonumerics.org 00019 * Bugs: blitz-bugs@oonumerics.org 00020 * 00021 * For more information, please see the Blitz++ Home Page: 00022 * http://oonumerics.org/blitz/ 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 // Toeplitz matrix 00036 // [ 0 1 2 3 ] 00037 // [ 1 2 3 4 ] 00038 // [ 2 3 4 5 ] 00039 // [ 3 4 5 6 ] 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