blitz Version 0.10
blitz/mattoep.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  * blitz/mattoep.h      Declarations for Toeplitz matrices
00004  *
00005  * $Id: mattoep.h,v 1.5 2011/03/25 22:41:16 julianc Exp $
00006  *
00007  * Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
00008  *
00009  * This file is a part of Blitz.
00010  *
00011  * Blitz is free software: you can redistribute it and/or modify 
00012  * it under the terms of the GNU Lesser General Public License
00013  * as published by the Free Software Foundation, either version 3
00014  * of the License, or (at your option) any later version.
00015  *
00016  * Blitz is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Lesser General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Lesser General Public 
00022  * License along with Blitz.  If not, see <http://www.gnu.org/licenses/>.
00023  * 
00024  * Suggestions:          blitz-devel@lists.sourceforge.net
00025  * Bugs:                 blitz-support@lists.sourceforge.net    
00026  *
00027  * For more information, please see the Blitz++ Home Page:
00028  *    https://sourceforge.net/projects/blitz/
00029  *
00030  ***************************************************************************/
00031 
00032 #ifndef BZ_MATTOEP_H
00033 #define BZ_MATTOEP_H
00034 
00035 #ifndef BZ_MSTRUCT_H
00036  #error <blitz/mattoep.h> must be included via <blitz/mstruct.h>
00037 #endif
00038 
00039 BZ_NAMESPACE(blitz)
00040 
00041 // Toeplitz matrix
00042 // [ 0 1 2 3 ]
00043 // [ 1 2 3 4 ]
00044 // [ 2 3 4 5 ]
00045 // [ 3 4 5 6 ]
00046 
00047 class ToeplitzIterator {
00048 public:
00049     ToeplitzIterator(unsigned rows, unsigned cols)
00050     {
00051         rows_ = rows;
00052         cols_ = cols;
00053         i_ = 0;
00054         j_ = 0;
00055         good_ = true;
00056         offset_ = 0;
00057     }
00058 
00059     operator bool() const { return good_; }
00060 
00061     void operator++()
00062     {
00063         ++offset_;
00064         if (i_ < rows_ - 1)
00065             ++i_;
00066         else if (j_ < cols_ - 1)
00067             ++j_;
00068         else
00069             good_ = false;
00070     }
00071 
00072     unsigned row() const
00073     { return i_; }
00074 
00075     unsigned col() const
00076     { return j_; }
00077 
00078     unsigned offset() const
00079     { return offset_; }
00080 
00081 protected:
00082     unsigned offset_;
00083     unsigned i_, j_;
00084     unsigned rows_, cols_;
00085     bool     good_;
00086 };
00087 
00088 class Toeplitz : public GeneralMatrix {
00089 
00090 public:
00091     typedef ToeplitzIterator T_iterator;
00092 
00093     Toeplitz()
00094         : rows_(0), cols_(0)
00095     { }
00096 
00097     Toeplitz(unsigned rows, unsigned cols)
00098         : rows_(rows), cols_(cols)
00099     { }
00100 
00101     unsigned columns() const
00102     { return cols_; }
00103 
00104     unsigned coordToOffset(unsigned i, unsigned j) const
00105     {
00106         BZPRECONDITION(inRange(i,j));
00107         return i + j;
00108     }
00109 
00110     unsigned firstInRow(unsigned i) const
00111     { return 0; }
00112 
00113     template<typename T_numtype>
00114     T_numtype get(const T_numtype * restrict data,
00115         unsigned i, unsigned j) const
00116     {
00117         BZPRECONDITION(inRange(i,j));
00118         return data[coordToOffset(i,j)];
00119     }
00120 
00121     template<typename T_numtype>
00122     T_numtype& get(T_numtype * restrict data, unsigned i, unsigned j)
00123     {
00124         BZPRECONDITION(inRange(i,j));
00125         return data[coordToOffset(i,j)];
00126     }
00127 
00128     unsigned lastInRow(const unsigned)  const { return cols_ - 1; }
00129     unsigned firstInCol(const unsigned) const { return 0; }
00130     unsigned lastInCol(const unsigned)  const { return rows_ - 1; }
00131 
00132     bool inRange(const unsigned i,const unsigned j) const { return (i<rows_) && (j<cols_); }
00133 
00134     unsigned numElements() const { return rows_ + cols_ - 1; }
00135 
00136     unsigned rows() const { return rows_; }
00137 
00138     void resize(const unsigned rows,const unsigned cols) {
00139         rows_ = rows;
00140         cols_ = cols;
00141     }
00142 
00143 private:
00144     unsigned rows_, cols_;
00145 };
00146 
00147 BZ_NAMESPACE_END
00148 
00149 #endif // BZ_MATSYMM_H
00150 
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines