matrix/MatrixCollection.hxx

00001 // Copyright (C) 2010 INRIA
00002 // Author(s): Marc Fragu
00003 //
00004 // This file is part of the linear-algebra library Seldon,
00005 // http://seldon.sourceforge.net/.
00006 //
00007 // Seldon is free software; you can redistribute it and/or modify it under the
00008 // terms of the GNU Lesser General Public License as published by the Free
00009 // Software Foundation; either version 2.1 of the License, or (at your option)
00010 // any later version.
00011 //
00012 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
00013 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
00015 // more details.
00016 //
00017 // You should have received a copy of the GNU Lesser General Public License
00018 // along with Seldon. If not, see http://www.gnu.org/licenses/.
00019 
00020 
00021 #ifndef SELDON_FILE_MATRIX_COLLECTION_HXX
00022 
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   template <class T, class Prop, class Storage,
00036             class Allocator = NewAlloc<T> >
00037   class MatrixCollection: public Matrix_Base<T, Allocator>
00038   {
00039     // Typedef declaration.
00040   public:
00041     typedef typename T::value_type value_type;
00042     typedef typename T::pointer pointer;
00043     typedef typename T::const_pointer const_pointer;
00044     typedef typename T::reference reference;
00045     typedef typename T::const_reference const_reference;
00046 
00047     typedef T matrix_type;
00048     typedef matrix_type* matrix_pointer;
00049     typedef const matrix_type* const_matrix_pointer;
00050     typedef matrix_type& matrix_reference;
00051     typedef const matrix_type& const_matrix_reference;
00052 
00053     typedef Matrix<matrix_type, Prop, Storage, NewAlloc<T> > collection_type;
00054     typedef const collection_type const_collection_type;
00055     typedef collection_type& collection_reference;
00056     typedef const collection_type& const_collection_reference;
00057 
00058 
00059     // Attributes.
00060   protected:
00062     int nz_;
00064     int Mmatrix_;
00066     int Nmatrix_;
00068     Vector<int, VectFull, CallocAlloc<int> > Mlocal_;
00070     Vector<int, VectFull, CallocAlloc<int> > Mlocal_sum_;
00072     Vector<int, VectFull, CallocAlloc<int> > Nlocal_;
00074     Vector<int, VectFull, CallocAlloc<int> > Nlocal_sum_;
00075 
00077     collection_type matrix_;
00078 
00079 
00080     // Methods.
00081   public:
00082     // Constructor.
00083     MatrixCollection();
00084     MatrixCollection(int i, int j);
00085     MatrixCollection(const MatrixCollection<T, Prop, Storage, Allocator>& A);
00086 
00087     // Destructor.
00088     ~MatrixCollection();
00089     void Clear();
00090     void Nullify();
00091     void Nullify(int i, int j);
00092 
00093     void Deallocate();
00094 
00095     // Basic methods.
00096     int GetM() const;
00097     int GetMmatrix() const;
00098     int GetM(int i) const;
00099     int GetN() const;
00100     int GetNmatrix() const;
00101     int GetN(int j) const;
00102     int GetSize() const;
00103     int GetDataSize() const;
00104 
00105     // Memory management.
00106     void Reallocate(int i, int j);
00107 
00108     // Management of the matrices.
00109     template <class T0, class Prop0, class Storage0, class Allocator0>
00110     void SetMatrix(int m, int n,
00111                    const Matrix<T0, Prop0, Storage0, Allocator0>&);
00112     template <class T0, class Prop0, class Allocator0>
00113     void SetMatrix(int m, int n,
00114                    const Matrix<T0, Prop0, RowSparse, Allocator0>&);
00115 
00116     // Element access and affectation.
00117     matrix_reference GetMatrix(int i, int j);
00118     const_matrix_reference GetMatrix(int i, int j) const;
00119 
00120     value_type operator() (int i, int j) const;
00121 
00122     MatrixCollection<T, Prop, Storage, Allocator>&
00123     operator= (const MatrixCollection<T, Prop, Storage, Allocator>& A);
00124     void Copy(const MatrixCollection<T, Prop, Storage, Allocator>& A);
00125 
00126     // Convenient functions.
00127     void Print() const;
00128     void Print(int m, int n) const;
00129 
00130     // Input/output functions.
00131     void Write(string FileName, bool with_size) const;
00132     void Write(ostream& FileStream, bool with_size) const;
00133     void WriteText(string FileName) const;
00134     void WriteText(ostream& FileStream) const;
00135 
00136     void Read(string FileName);
00137     void Read(istream& FileStream);
00138   };
00139 
00140 
00142   template <class T, class Prop, class Allocator>
00143   class Matrix<T, Prop, ColMajorCollection, Allocator>:
00144     public MatrixCollection<T, Prop, ColMajor, Allocator>
00145   {
00146   public:
00147     Matrix();
00148     Matrix(int i, int j);
00149   };
00150 
00151 
00153   template <class T, class Prop, class Allocator>
00154   class Matrix<T, Prop, RowMajorCollection, Allocator>:
00155     public MatrixCollection<T, Prop, RowMajor, Allocator>
00156   {
00157   public:
00158     Matrix();
00159     Matrix(int i, int j);
00160   };
00161 
00162 
00164   template <class T, class Prop, class Allocator>
00165   class Matrix<T, Prop, ColSymPackedCollection, Allocator>:
00166     public MatrixCollection<T, Prop, ColSymPacked, Allocator>
00167   {
00168   public:
00169     Matrix();
00170     Matrix(int i, int j);
00171   };
00172 
00173 
00175   template <class T, class Prop, class Allocator>
00176   class Matrix<T, Prop, RowSymPackedCollection, Allocator>:
00177     public MatrixCollection<T, Prop, RowSymPacked, Allocator>
00178   {
00179   public:
00180     Matrix();
00181     Matrix(int i, int j);
00182   };
00183 
00184 
00185 
00186 } // namespace Seldon.
00187 
00188 
00189 #define SELDON_FILE_MATRIX_COLLECTION_HXX
00190 #endif