Warning: this documentation for the development version is under construction.

/home/vivien/public_html/.src_seldon/matrix_sparse/Matrix_ComplexSparse.hxx

00001 // Copyright (C) 2001-2009 Vivien Mallet
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_COMPLEXSPARSE_HXX
00023 
00024 #include "../share/Common.hxx"
00025 #include "../share/Properties.hxx"
00026 #include "../share/Storage.hxx"
00027 #include "../share/Errors.hxx"
00028 #include "../share/Allocator.hxx"
00029 
00030 namespace Seldon
00031 {
00032 
00033 
00035 
00046   template <class T, class Prop, class Storage,
00047             class Allocator = SELDON_DEFAULT_ALLOCATOR<T> >
00048   class Matrix_ComplexSparse: public Matrix_Base<T, Allocator>
00049   {
00050     // typedef declaration.
00051   public:
00052     typedef typename Allocator::value_type value_type;
00053     typedef typename Allocator::pointer pointer;
00054     typedef typename Allocator::const_pointer const_pointer;
00055     typedef typename Allocator::reference reference;
00056     typedef typename Allocator::const_reference const_reference;
00057     typedef complex<value_type> entry_type;
00058     typedef complex<value_type> access_type;
00059     typedef complex<value_type> const_access_type;
00060 
00061     // Attributes.
00062   protected:
00063     // Number of non-zero elements.
00064     int real_nz_;
00065     int imag_nz_;
00066     // Index (in data_) of first element stored for each row or column.
00067     int* real_ptr_;
00068     int* imag_ptr_;
00069     // Column or row index (in the matrix) each element.
00070     int* real_ind_;
00071     int* imag_ind_;
00072 
00073     // Data.
00074     T* real_data_;
00075     T* imag_data_;
00076 
00077     // Methods.
00078   public:
00079     // Constructors.
00080     Matrix_ComplexSparse();
00081     Matrix_ComplexSparse(int i, int j);
00082     Matrix_ComplexSparse(int i, int j, int real_nz, int imag_nz);
00083     template <class Storage0, class Allocator0,
00084               class Storage1, class Allocator1,
00085               class Storage2, class Allocator2>
00086     Matrix_ComplexSparse(int i, int j,
00087                          Vector<T, Storage0, Allocator0>& real_values,
00088                          Vector<int, Storage1, Allocator1>& real_ptr,
00089                          Vector<int, Storage2, Allocator2>& real_ind,
00090                          Vector<T, Storage0, Allocator0>& imag_values,
00091                          Vector<int, Storage1, Allocator1>& imag_ptr,
00092                          Vector<int, Storage2, Allocator2>& imag_ind);
00093     Matrix_ComplexSparse(const Matrix_ComplexSparse<T, Prop,
00094                          Storage, Allocator>& A);
00095 
00096     // Destructor.
00097     ~Matrix_ComplexSparse();
00098     void Clear();
00099 
00100     // Memory management.
00101     template <class Storage0, class Allocator0,
00102               class Storage1, class Allocator1,
00103               class Storage2, class Allocator2>
00104     void SetData(int i, int j,
00105                  Vector<T, Storage0, Allocator0>& real_values,
00106                  Vector<int, Storage1, Allocator1>& real_ptr,
00107                  Vector<int, Storage2, Allocator2>& real_ind,
00108                  Vector<T, Storage0, Allocator0>& imag_values,
00109                  Vector<int, Storage1, Allocator1>& imag_ptr,
00110                  Vector<int, Storage2, Allocator2>& imag_ind);
00111     void SetData(int i, int j,
00112                  int real_nz, pointer real_values, int* real_ptr,
00113                  int* real_ind,
00114                  int imag_nz, pointer imag_values, int* imag_ptr,
00115                  int* imag_ind);
00116     void Nullify();
00117     void Reallocate(int i, int j);
00118     void Reallocate(int i, int j, int real_nz, int imag_nz);
00119     void Resize(int i, int j);
00120     void Resize(int i, int j, int real_nz, int imag_nz);
00121     void Copy(const Matrix_ComplexSparse<T, Prop, Storage, Allocator>& A);
00122 
00123     // Basic methods.
00124     int GetNonZeros() const;
00125     int GetDataSize() const;
00126     int* GetRealPtr() const;
00127     int* GetImagPtr() const;
00128     int* GetRealInd() const;
00129     int* GetImagInd() const;
00130     int GetRealPtrSize() const;
00131     int GetImagPtrSize() const;
00132     int GetRealIndSize() const;
00133     int GetImagIndSize() const;
00134     int GetRealDataSize() const;
00135     int GetImagDataSize() const;
00136     T* GetRealData() const;
00137     T* GetImagData() const;
00138 
00139     // Element acess and affectation.
00140     complex<value_type> operator() (int i, int j) const;
00141     value_type& ValReal(int i, int j);
00142     const value_type& ValReal(int i, int j) const;
00143     value_type& ValImag(int i, int j);
00144     const value_type& ValImag(int i, int j) const;
00145     value_type& GetReal(int i, int j);
00146     const value_type& GetReal(int i, int j) const;
00147     value_type& GetImag(int i, int j);
00148     const value_type& GetImag(int i, int j) const;
00149     void Set(int i, int j, const complex<T>& x);
00150     void AddInteraction(int i, int j, const complex<T>& x);
00151     Matrix_ComplexSparse<T, Prop, Storage, Allocator>&
00152     operator= (const Matrix_ComplexSparse<T, Prop, Storage, Allocator>& A);
00153 
00154     // Convenient functions.
00155     void Zero();
00156     void SetIdentity();
00157     void Fill();
00158     void Fill(const complex<T>& x);
00159     void FillRand();
00160 
00161     void Print() const;
00162     void Write(string FileName) const;
00163     void Write(ostream& FileStream) const;
00164     void WriteText(string FileName) const;
00165     void WriteText(ostream& FileStream) const;
00166     void Read(string FileName);
00167     void Read(istream& FileStream);
00168     void ReadText(string FileName);
00169     void ReadText(istream& FileStream);
00170   };
00171 
00172 
00174   template <class T, class Prop, class Allocator>
00175   class Matrix<T, Prop, ColComplexSparse, Allocator>:
00176     public Matrix_ComplexSparse<T, Prop, ColComplexSparse, Allocator>
00177   {
00178     // typedef declaration.
00179   public:
00180     typedef typename Allocator::value_type value_type;
00181     typedef Prop property;
00182     typedef ColComplexSparse storage;
00183     typedef Allocator allocator;
00184 
00185   public:
00186     Matrix();
00187     Matrix(int i, int j);
00188     Matrix(int i, int j, int real_nz, int imag_nz);
00189     template <class Storage0, class Allocator0,
00190               class Storage1, class Allocator1,
00191               class Storage2, class Allocator2>
00192     Matrix(int i, int j,
00193            Vector<T, Storage0, Allocator0>& real_values,
00194            Vector<int, Storage1, Allocator1>& real_ptr,
00195            Vector<int, Storage2, Allocator2>& real_ind,
00196            Vector<T, Storage0, Allocator0>& imag_values,
00197            Vector<int, Storage1, Allocator1>& imag_ptr,
00198            Vector<int, Storage2, Allocator2>& imag_ind);
00199   };
00200 
00201 
00203   template <class T, class Prop, class Allocator>
00204   class Matrix<T, Prop, RowComplexSparse, Allocator>:
00205     public Matrix_ComplexSparse<T, Prop, RowComplexSparse, Allocator>
00206   {
00207     // typedef declaration.
00208   public:
00209     typedef typename Allocator::value_type value_type;
00210     typedef Prop property;
00211     typedef RowComplexSparse storage;
00212     typedef Allocator allocator;
00213 
00214   public:
00215     Matrix();
00216     Matrix(int i, int j);
00217     Matrix(int i, int j, int real_nz, int imag_nz);
00218     template <class Storage0, class Allocator0,
00219               class Storage1, class Allocator1,
00220               class Storage2, class Allocator2>
00221     Matrix(int i, int j,
00222            Vector<T, Storage0, Allocator0>& values,
00223            Vector<int, Storage1, Allocator1>& ptr,
00224            Vector<int, Storage2, Allocator2>& ind,
00225            Vector<T, Storage0, Allocator0>& imag_values,
00226            Vector<int, Storage1, Allocator1>& imag_ptr,
00227            Vector<int, Storage2, Allocator2>& imag_ind);
00228   };
00229 
00230 
00231 } // namespace Seldon.
00232 
00233 #define SELDON_FILE_MATRIX_COMPLEXSPARSE_HXX
00234 #endif