synaps/linalg/rep2d.h

00001 #ifndef SYNAPS_LINALG_ARRAY2D_H
00002 #define SYNAPS_LINALG_ARRAY2D_H
00003 //======================================================================
00004 #include <synaps/init.h>
00005 #include <synaps/arithm/Norm.h>
00006 #include <synaps/linalg/MethodName.h>
00007 #include <synaps/base/stride_iterator.h>
00008 #include <synaps/linalg/rep1d.h>
00009 
00010 
00011 __BEGIN_NAMESPACE_SYNAPS
00012 
00013 //======================================================================
00014 namespace linalg {
00015 //----------------------------------------------------------------------
00016   typedef unsigned size_type;
00017   //extern double TOL;
00018 //----------------------------------------------------------------------
00026 template <class C>
00027 struct rep2d : public rep1d<C> {
00028   typedef C*                              col_iterator;
00029   typedef stride_iterator<C,C*,size_type> row_iterator;
00030  
00031   size_type nbrow_, nbcol_;
00032  
00033   rep2d() {}
00034   rep2d(const rep2d<C> & v): 
00035     linalg::rep1d<C>(v), nbrow_(v.nbrow_), nbcol_(v.nbcol_) {}
00036   rep2d(size_type i,size_type j=1): 
00037     linalg::rep1d<C>(i*j), nbrow_(i),nbcol_(j) {}
00038   rep2d(size_type i, size_type j, C* t): 
00039     linalg::rep1d<C>(i*j,t), nbrow_(i), nbcol_(j) {}
00040   rep2d(const char * nm);
00041 
00042   rep2d<C> & operator=(const rep2d<C> & v);
00043  
00044   C &       operator()(size_type i, size_type j) 
00045   {
00046     assert(i < nbrow_ && j < nbcol_);
00047     return this->tab_[i+nbrow_*j];
00048   }
00049 
00050   const C & operator()(size_type i, size_type j) const 
00051   {
00052     return this->tab_[i+nbrow_*j];
00053   }  
00054   size_type nbrow() const {return nbrow_;}
00055   size_type nbcol() const {return nbcol_;}
00056 
00057   void resize(size_type i,size_type j)
00058     {
00059       nbrow_=i; nbcol_=j;
00060       this->linalg::rep1d<C>::resize(i*j); 
00061     }
00062   
00063 };
00064 
00065 //----------------------------------------------------------------------
00066 template<class C>
00067 typename linalg::rep2d<C>::col_iterator 
00068   create(typename linalg::rep2d<C>::col_iterator s,
00069          const linalg::rep2d<C> & a, unsigned int i, unsigned int j) 
00070 {
00071   typedef  typename linalg::rep2d<C>::col_iterator iterator;
00072   return iterator(&a(i,j));
00073 }
00074 //----------------------------------------------------------------------
00075 template<class C>
00076 typename linalg::rep2d<C>::row_iterator 
00077   create(typename linalg::rep2d<C>::row_iterator s,
00078          const linalg::rep2d<C> & a, unsigned int i, unsigned int j) 
00079 {
00080   typedef  typename linalg::rep2d<C>::row_iterator iterator;
00081   return iterator((C*)(&a(i,j)),a.nbrow());
00082 }
00083 //----------------------------------------------------------------------
00084 template<class C>
00085 typename linalg::rep2d<C>::row_iterator 
00086   begin_row(const linalg::rep2d<C> & a, unsigned int i) 
00087 {
00088   return linalg::rep2d<C>::row_iterator(&a(i,0));
00089 }
00090 //----------------------------------------------------------------------
00091 template<class C>
00092 typename linalg::rep2d<C>::col_iterator 
00093   begin_col(const linalg::rep2d<C> & a, unsigned int i) 
00094 {
00095   return linalg::rep2d<C>::col_iterator(&a(0,i));
00096 }
00097 //----------------------------------------------------------------------
00098 template<class C>
00099 typename linalg::rep2d<C>::row_iterator 
00100   end_row(const linalg::rep2d<C> & a, unsigned int i) 
00101 {
00102   return linalg::rep2d<C>::row_iterator(&a(i,a.nbcol()));
00103 }
00104 //----------------------------------------------------------------------
00105 template<class C>
00106 typename linalg::rep2d<C>::col_iterator 
00107   end_col(const linalg::rep2d<C> & a, unsigned int i) 
00108 {
00109   return linalg::rep2d<C>::col_iterator(&a(a.nbrow(),i));
00110 }
00111 //====================================================================
00112 } //CLOSE linalg
00113 __END_NAMESPACE_SYNAPS
00114 
00115 //----------------------------------------------------------------------
00116 #include "synaps/linalg/array2d.C"
00117 //----------------------------------------------------------------------
00118 #endif // SYNAPS_LINALG_ARRAY2D_H
00119 

SYNAPS DOCUMENTATION
logo