synaps/linalg/toeplitz.h

00001 /*********************************************************************
00002 *      This file is part of the source code of SYNAPS kernel.        *
00003 *   Author(s): B. Mourrain, GALAAD, INRIA                            *
00004 **********************************************************************
00005 History:
00006 $Id: toeplitz.h,v 1.1 2005/07/11 08:33:37 mourrain Exp $
00007 **********************************************************************/
00008 #ifndef toeplitz_H
00009 #define toeplitz_H
00010 //----------------------------------------------------------------------
00011 #include <synaps/init.h>
00012 #include <synaps/arithm/GENERIC.h>
00013 #include <synaps/linalg/rep1d.h>
00014 #include <synaps/base/Range.h>
00015 #include <synaps/linalg/FFT.h>
00016 
00017 
00018 __BEGIN_NAMESPACE_SYNAPS
00019 
00020 
00021 template<char O,class A, class B> struct OP;
00022 //----------------------------------------------------------------------
00023 //OPEN
00024 namespace linalg {
00025 //----------------------------------------------------------------------
00034 template<class C> 
00035 struct toeplitz : public linalg::rep1d<C> 
00036 {
00037 
00038   unsigned int nbrow_, nbcol_;
00039 
00040   typedef C                coeff_t;
00041   typedef typename linalg::rep1d<C>::size_type   size_type;
00042   typedef linalg::rep1d<C>   row_t;
00043   typedef linalg::rep1d<C>   col_t;
00044 
00045   toeplitz(): linalg::rep1d<C>(){}
00046   toeplitz(const toeplitz<C> & v):linalg::rep1d<C>(v),
00047     nbrow_(v.nbrow_),nbcol_(v.nbcol_){}
00048   toeplitz(unsigned int i, unsigned int j): 
00049     linalg::rep1d<C>(i+j-1),nbrow_(i),nbcol_(j) {}
00050   toeplitz(unsigned int i, unsigned int j, C* t): 
00051     linalg::rep1d<C>(i+j-1,t),nbrow_(i),nbcol_(j){}
00052 
00053   void resize(unsigned int i) {this->linalg::rep1d<C>::resize(i);}
00054   void resize(unsigned int i, unsigned int j);
00055 
00056   C   operator()(unsigned int i, unsigned int j) const 
00057         {return this->tab_[i-j+nbcol_-1];} 
00058 
00059   void transpose() ;
00060   
00061   size_type nbrow() const {return nbrow_;}
00062   size_type nbcol() const {return nbcol_;}
00063 };
00064 //----------------------------------------------------------------------
00065 // template<class C>
00066 // void assign(toeplitz<C> & r, const toeplitz<C>* v) 
00067 // {
00068 //   assign((linalg::rep1d<C> &)r, (linalg::rep1d<C>*) v);
00069 //   r.nbrow_=v->nbrow_;
00070 //   r.nbcol_=v->nbcol_;
00071 // }
00072 //----------------------------------------------------------------------
00073   template<class C, class M>
00074   void submatrix(toeplitz<C> & r, const M & m, const Range2d & rg)
00075   {
00076     typedef typename toeplitz<C>::size_type size_type;
00077     
00078     for(size_type i=rg.j1; i< rg.j2+1; i++)
00079       r.tab_[-i+rg.j2]=m(rg.i1,i);
00080     
00081     for(size_type i=rg.i1+1; i< rg.i2+1; i++) 
00082         r.tab_[i-rg.i1+rg.j2-rg.j1]=m(i,rg.j1);
00083   }
00084   
00085 //---------------------------------------------------------------
00086 // Assignment of a matrix to a container {\tt toeplitz}
00087 template<class S, class C>
00088 inline void assign(toeplitz<C> & r, const S & M)
00089 {
00090   for(unsigned int i=0;i<M.nbcol();i++) r(0,i)=M(0,i);  
00091   for(unsigned int i=1;i<M.nbrow();i++) r(i,0)=M(i,0);  
00092 }
00093 //----------------------------------------------------------------------
00094 } //CLOSE linalg
00095 
00096 
00097 __END_NAMESPACE_SYNAPS
00098 
00099 //======================================================================
00100 #ifndef SEPARATE_COMPILATION
00101 #include "synaps/linalg/toeplitz.C"
00102 #endif
00103 
00104 
00105 #endif //toeplitz_H
00106 
00107 

SYNAPS DOCUMENTATION
logo