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

/home/vivien/public_html/.src_seldon/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     // typedef declaration.
00147   public:
00148     typedef T value_type;
00149     typedef Prop property;
00150     typedef ColMajorCollection storage;
00151     typedef Allocator allocator;
00152 
00153   public:
00154     Matrix();
00155     Matrix(int i, int j);
00156   };
00157 
00158 
00160   template <class T, class Prop, class Allocator>
00161   class Matrix<T, Prop, RowMajorCollection, Allocator>:
00162     public MatrixCollection<T, Prop, RowMajor, Allocator>
00163   {
00164     // typedef declaration.
00165   public:
00166     typedef T value_type;
00167     typedef Prop property;
00168     typedef RowMajorCollection storage;
00169     typedef Allocator allocator;
00170 
00171   public:
00172     Matrix();
00173     Matrix(int i, int j);
00174   };
00175 
00176 
00178   template <class T, class Prop, class Allocator>
00179   class Matrix<T, Prop, ColSymPackedCollection, Allocator>:
00180     public MatrixCollection<T, Prop, ColSymPacked, Allocator>
00181   {
00182     // typedef declaration.
00183   public:
00184     typedef T value_type;
00185     typedef Prop property;
00186     typedef ColSymPackedCollection storage;
00187     typedef Allocator allocator;
00188 
00189   public:
00190     Matrix();
00191     Matrix(int i, int j);
00192   };
00193 
00194 
00196   template <class T, class Prop, class Allocator>
00197   class Matrix<T, Prop, RowSymPackedCollection, Allocator>:
00198     public MatrixCollection<T, Prop, RowSymPacked, Allocator>
00199   {
00200     // typedef declaration.
00201   public:
00202     typedef T value_type;
00203     typedef Prop property;
00204     typedef RowSymPackedCollection storage;
00205     typedef Allocator allocator;
00206 
00207   public:
00208     Matrix();
00209     Matrix(int i, int j);
00210   };
00211 
00212 
00213 
00214 } // namespace Seldon.
00215 
00216 
00217 #define SELDON_FILE_MATRIX_COLLECTION_HXX
00218 #endif