matrix_sparse/Matrix_ArrayComplexSparse.hxx

00001 // Copyright (C) 2003-2009 Marc Duruflé
00002 //
00003 // This file is part of the linear-algebra library Seldon,
00004 // http://seldon.sourceforge.net/.
00005 //
00006 // Seldon is free software; you can redistribute it and/or modify it under the
00007 // terms of the GNU Lesser General Public License as published by the Free
00008 // Software Foundation; either version 2.1 of the License, or (at your option)
00009 // any later version.
00010 //
00011 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
00012 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00013 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
00014 // more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public License
00017 // along with Seldon. If not, see http://www.gnu.org/licenses/.
00018 
00019 
00020 // To be included by Seldon.hxx
00021 
00022 #ifndef SELDON_FILE_MATRIX_ARRAY_COMPLEX_SPARSE_HXX
00023 
00024 namespace Seldon
00025 {
00026 
00028 
00035   template <class T, class Prop, class Storage,
00036             class Allocator = SELDON_DEFAULT_ALLOCATOR<T> >
00037   class Matrix_ArrayComplexSparse
00038   {
00039     // typedef declaration.
00040   public:
00041     typedef typename Allocator::value_type value_type;
00042     typedef typename Allocator::pointer pointer;
00043     typedef typename Allocator::const_pointer const_pointer;
00044     typedef typename Allocator::reference reference;
00045     typedef typename Allocator::const_reference const_reference;
00046     typedef complex<T> entry_type;
00047     typedef complex<T> access_type;
00048     typedef complex<T> const_access_type;
00049 
00050     // Attributes.
00051   protected:
00053     int m_;
00055     int n_;
00057     Vector<Vector<T, VectSparse, Allocator>, VectFull,
00058            NewAlloc<Vector<T, VectSparse, Allocator> > > val_real_;
00060     Vector<Vector<T, VectSparse, Allocator>, VectFull,
00061            NewAlloc<Vector<T, VectSparse, Allocator> > > val_imag_;
00062 
00063     // Methods.
00064   public:
00065     // Constructors.
00066     Matrix_ArrayComplexSparse();
00067     Matrix_ArrayComplexSparse(int i, int j);
00068 
00069     // Destructor.
00070     ~Matrix_ArrayComplexSparse();
00071     void Clear();
00072 
00073     // Memory management.
00074     void Reallocate(int i, int j);
00075     void Resize(int i, int j);
00076 
00077     // Basic methods.
00078     int GetM() const;
00079     int GetN() const;
00080     int GetM(const SeldonTranspose& status) const;
00081     int GetN(const SeldonTranspose& status) const;
00082     int GetRealNonZeros() const;
00083     int GetImagNonZeros() const;
00084     int GetRealDataSize() const;
00085     int GetImagDataSize() const;
00086     int GetDataSize() const;
00087     int* GetRealInd(int i) const;
00088     int* GetImagInd(int i) const;
00089     T* GetRealData(int i) const;
00090     T* GetImagData(int i) const;
00091     Vector<T, VectSparse, Allocator>* GetRealData() const;
00092     Vector<T, VectSparse, Allocator>* GetImagData() const;
00093 
00094     // Element acess and affectation.
00095     complex<T> operator() (int i, int j) const;
00096     complex<T>& Val(int i, int j);
00097     const complex<T>& Val(int i, int j) const;
00098     const T& ValueReal(int num_row,int i) const;
00099     T& ValueReal(int num_row,int i);
00100     int IndexReal(int num_row,int i) const;
00101     int& IndexReal(int num_row,int i);
00102     const T& ValueImag(int num_row,int i) const;
00103     T& ValueImag(int num_row,int i);
00104     int IndexImag(int num_row,int i) const;
00105     int& IndexImag(int num_row,int i);
00106 
00107     void SetRealData(int, int, Vector<T, VectSparse, Allocator>*);
00108     void SetImagData(int, int, Vector<T, VectSparse, Allocator>*);
00109     void SetRealData(int, int, T*, int*);
00110     void SetImagData(int, int, T*, int*);
00111     void NullifyReal(int i);
00112     void NullifyImag(int i);
00113     void NullifyReal();
00114     void NullifyImag();
00115 
00116     // Convenient functions.
00117     void Print() const;
00118     void WriteText(string FileName) const;
00119     void WriteText(ostream& FileStream) const;
00120     void Assemble();
00121     template<class T0>
00122     void RemoveSmallEntry(const T0& epsilon);
00123 
00124     void SetIdentity();
00125     void Zero();
00126     void Fill();
00127     template <class T0>
00128     void Fill(const complex<T0>& x);
00129     template <class T0>
00130     Matrix_ArrayComplexSparse<T, Prop, Storage, Allocator>& operator=
00131     (const complex<T0>& x);
00132     void FillRand();
00133 
00134   };
00135 
00136 
00138   template <class T, class Prop, class Allocator>
00139   class Matrix<T, Prop, ArrayColComplexSparse, Allocator> :
00140     public Matrix_ArrayComplexSparse<T, Prop, ArrayColComplexSparse, Allocator>
00141   {
00142     // typedef declaration.
00143   public:
00144     typedef typename Allocator::value_type value_type;
00145     typedef Prop property;
00146     typedef ArrayColComplexSparse storage;
00147     typedef Allocator allocator;
00148 
00149   public:
00150     Matrix()  throw();
00151     Matrix(int i, int j);
00152 
00153     // Memory management.
00154     void ClearRealColumn(int i);
00155     void ClearImagColumn(int i);
00156     void ReallocateRealColumn(int i, int j);
00157     void ReallocateImagColumn(int i, int j);
00158     void ResizeRealColumn(int i, int j);
00159     void ResizeImagColumn(int i, int j);
00160     void SwapRealColumn(int i, int i_);
00161     void SwapImagColumn(int i, int i_);
00162     void ReplaceRealIndexColumn(int i, IVect& new_index);
00163     void ReplaceImagIndexColumn(int i, IVect& new_index);
00164 
00165     int GetRealColumnSize(int i) const;
00166     int GetImagColumnSize(int i) const;
00167     void PrintRealColumn(int i) const;
00168     void PrintImagColumn(int i) const;
00169     void AssembleRealColumn(int i);
00170     void AssembleImagColumn(int i);
00171 
00172     void AddInteraction(int i, int j, const complex<T>& val);
00173 
00174     template<class Alloc1>
00175     void AddInteractionRow(int i, int nb, const IVect& col,
00176                            const Vector<complex<T>, VectFull, Alloc1>& val);
00177     template<class Alloc1>
00178     void AddInteractionColumn(int i, int nb, const IVect& row,
00179                               const Vector<complex<T>, VectFull,
00180                               Alloc1>& val);
00181   };
00182 
00183 
00185   template <class T, class Prop, class Allocator>
00186   class Matrix<T, Prop, ArrayRowComplexSparse, Allocator> :
00187     public Matrix_ArrayComplexSparse<T, Prop, ArrayRowComplexSparse, Allocator>
00188   {
00189     // typedef declaration.
00190   public:
00191     typedef typename Allocator::value_type value_type;
00192     typedef Prop property;
00193     typedef ArrayRowComplexSparse storage;
00194     typedef Allocator allocator;
00195 
00196   public:
00197     Matrix()  throw();
00198     Matrix(int i, int j);
00199 
00200     // Memory management.
00201     void ClearRealRow(int i);
00202     void ClearImagRow(int i);
00203     void ReallocateRealRow(int i, int j);
00204     void ReallocateImagRow(int i, int j);
00205     void ResizeRealRow(int i, int j);
00206     void ResizeImagRow(int i, int j);
00207     void SwapRealRow(int i, int i_);
00208     void SwapImagRow(int i, int i_);
00209     void ReplaceRealIndexRow(int i, IVect& new_index);
00210     void ReplaceImagIndexRow(int i, IVect& new_index);
00211 
00212     int GetRealRowSize(int i) const;
00213     int GetImagRowSize(int i) const;
00214     void PrintRealRow(int i) const;
00215     void PrintImagRow(int i) const;
00216     void AssembleRealRow(int i);
00217     void AssembleImagRow(int i);
00218 
00219     void AddInteraction(int i, int j, const complex<T>& val);
00220 
00221     template<class Alloc1>
00222     void AddInteractionRow(int i, int nb, const IVect& col,
00223                            const Vector<complex<T>, VectFull, Alloc1>& val);
00224     template<class Alloc1>
00225     void AddInteractionColumn(int i, int nb, const IVect& row,
00226                               const Vector<complex<T>, VectFull,
00227                               Alloc1>& val);
00228   };
00229 
00230 
00232   template <class T, class Prop, class Allocator>
00233   class Matrix<T, Prop, ArrayColSymComplexSparse, Allocator>:
00234     public Matrix_ArrayComplexSparse<T, Prop, ArrayColSymComplexSparse, Allocator>
00235   {
00236     // typedef declaration.
00237   public:
00238     typedef typename Allocator::value_type value_type;
00239     typedef Prop property;
00240     typedef ArrayColSymComplexSparse storage;
00241     typedef Allocator allocator;
00242 
00243   public:
00244     Matrix()  throw();
00245     Matrix(int i, int j);
00246 
00247     complex<T> operator() (int i, int j) const;
00248 
00249     // Memory management.
00250     void ClearRealColumn(int i);
00251     void ClearImagColumn(int i);
00252     void ReallocateRealColumn(int i, int j);
00253     void ReallocateImagColumn(int i, int j);
00254     void ResizeRealColumn(int i, int j);
00255     void ResizeImagColumn(int i, int j);
00256     void SwapRealColumn(int i, int i_);
00257     void SwapImagColumn(int i, int i_);
00258     void ReplaceRealIndexColumn(int i, IVect& new_index);
00259     void ReplaceImagIndexColumn(int i, IVect& new_index);
00260 
00261     int GetRealColumnSize(int i) const;
00262     int GetImagColumnSize(int i) const;
00263     void PrintRealColumn(int i) const;
00264     void PrintImagColumn(int i) const;
00265     void AssembleRealColumn(int i);
00266     void AssembleImagColumn(int i);
00267 
00268     void AddInteraction(int i, int j, const complex<T>& val);
00269 
00270     template<class Alloc1>
00271     void AddInteractionRow(int i, int nb, const IVect& col,
00272                            const Vector<complex<T>, VectFull, Alloc1>& val);
00273     template<class Alloc1>
00274     void AddInteractionColumn(int i, int nb, const IVect& row,
00275                               const Vector<complex<T>, VectFull,
00276                               Alloc1>& val);
00277   };
00278 
00279 
00281   template <class T, class Prop, class Allocator>
00282   class Matrix<T, Prop, ArrayRowSymComplexSparse, Allocator>:
00283     public Matrix_ArrayComplexSparse<T, Prop, ArrayRowSymComplexSparse, Allocator>
00284   {
00285     // typedef declaration.
00286   public:
00287     typedef typename Allocator::value_type value_type;
00288     typedef Prop property;
00289     typedef ArrayRowSymComplexSparse storage;
00290     typedef Allocator allocator;
00291 
00292   public:
00293     Matrix()  throw();
00294     Matrix(int i, int j);
00295 
00296     complex<T> operator() (int i, int j) const;
00297 
00298     // Memory management.
00299     void ClearRealRow(int i);
00300     void ClearImagRow(int i);
00301     void ReallocateRealRow(int i, int j);
00302     void ReallocateImagRow(int i, int j);
00303     void ResizeRealRow(int i, int j);
00304     void ResizeImagRow(int i, int j);
00305     void SwapRealRow(int i, int i_);
00306     void SwapImagRow(int i, int i_);
00307     void ReplaceRealIndexRow(int i, IVect& new_index);
00308     void ReplaceImagIndexRow(int i, IVect& new_index);
00309 
00310     int GetRealRowSize(int i) const;
00311     int GetImagRowSize(int i) const;
00312     void PrintRealRow(int i) const;
00313     void PrintImagRow(int i) const;
00314     void AssembleRealRow(int i);
00315     void AssembleImagRow(int i);
00316 
00317     void AddInteraction(int i, int j, const complex<T>& val);
00318 
00319     template<class Alloc1>
00320     void AddInteractionRow(int i, int nb, const IVect& col,
00321                            const Vector<complex<T>, VectFull, Alloc1>& val);
00322     template<class Alloc1>
00323     void AddInteractionColumn(int i, int nb, const IVect& row,
00324                               const Vector<complex<T>, VectFull,
00325                               Alloc1>& val);
00326   };
00327 
00328 
00329 } // namespace Seldon
00330 
00331 #define SELDON_FILE_MATRIX_ARRAY_COMPLEX_SPARSE_HXX
00332 #endif