MatrixCollection.hxx
1 // Copyright (C) 2010 INRIA
2 // Author(s): Marc Fragu
3 //
4 // This file is part of the linear-algebra library Seldon,
5 // http://seldon.sourceforge.net/.
6 //
7 // Seldon is free software; you can redistribute it and/or modify it under the
8 // terms of the GNU Lesser General Public License as published by the Free
9 // Software Foundation; either version 2.1 of the License, or (at your option)
10 // any later version.
11 //
12 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15 // more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with Seldon. If not, see http://www.gnu.org/licenses/.
19 
20 
21 #ifndef SELDON_FILE_MATRIX_COLLECTION_HXX
22 
23 
24 #include "../share/Common.hxx"
25 #include "../share/Properties.hxx"
26 #include "../share/Storage.hxx"
27 #include "../share/Errors.hxx"
28 #include "../share/Allocator.hxx"
29 
30 namespace Seldon
31 {
32 
33 
35  template <class T, class Prop, class Storage,
36  class Allocator = NewAlloc<T> >
37  class MatrixCollection: public Matrix_Base<T, Allocator>
38  {
39  // Typedef declaration.
40  public:
41  typedef typename T::value_type value_type;
42  typedef typename T::pointer pointer;
43  typedef typename T::const_pointer const_pointer;
44  typedef typename T::reference reference;
45  typedef typename T::const_reference const_reference;
46 
47  typedef T matrix_type;
48  typedef matrix_type* matrix_pointer;
49  typedef const matrix_type* const_matrix_pointer;
50  typedef matrix_type& matrix_reference;
51  typedef const matrix_type& const_matrix_reference;
52 
54  typedef const collection_type const_collection_type;
56  typedef const collection_type& const_collection_reference;
57 
58 
59  // Attributes.
60  protected:
62  int nz_;
64  int Mmatrix_;
66  int Nmatrix_;
75 
78 
79 
80  // Methods.
81  public:
82  // Constructor.
84  MatrixCollection(int i, int j);
86 
87  // Destructor.
89  void Clear();
90  void Nullify();
91  void Nullify(int i, int j);
92 
93  void Deallocate();
94 
95  // Basic methods.
96  int GetM() const;
97  int GetMmatrix() const;
98  int GetM(int i) const;
99  int GetN() const;
100  int GetNmatrix() const;
101  int GetN(int j) const;
102  int GetSize() const;
103  int GetDataSize() const;
104  size_t GetMemorySize() const;
105 
106  // Memory management.
107  void Reallocate(int i, int j);
108 
109  // Management of the matrices.
110  template <class T0, class Prop0, class Storage0, class Allocator0>
111  void SetMatrix(int m, int n,
113  template <class T0, class Prop0, class Allocator0>
114  void SetMatrix(int m, int n,
116 
117  // Element access and affectation.
118  matrix_reference GetMatrix(int i, int j);
119  const_matrix_reference GetMatrix(int i, int j) const;
120 
121  value_type operator() (int i, int j) const;
122 
126 
127  // Convenient functions.
128  void Print() const;
129  void Print(int m, int n) const;
130 
131  // Input/output functions.
132  void Write(string FileName, bool with_size) const;
133  void Write(ostream& FileStream, bool with_size) const;
134  void WriteText(string FileName) const;
135  void WriteText(ostream& FileStream) const;
136 
137  void Read(string FileName);
138  void Read(istream& FileStream);
139  };
140 
141 
143  template <class T, class Prop, class Allocator>
144  class Matrix<T, Prop, ColMajorCollection, Allocator>:
145  public MatrixCollection<T, Prop, ColMajor, Allocator>
146  {
147  // typedef declaration.
148  public:
149  typedef T value_type;
150  typedef Prop property;
151  typedef ColMajorCollection storage;
152  typedef Allocator allocator;
153 
154  public:
155  Matrix();
156  Matrix(int i, int j);
157  };
158 
159 
161  template <class T, class Prop, class Allocator>
162  class Matrix<T, Prop, RowMajorCollection, Allocator>:
163  public MatrixCollection<T, Prop, RowMajor, Allocator>
164  {
165  // typedef declaration.
166  public:
167  typedef T value_type;
168  typedef Prop property;
169  typedef RowMajorCollection storage;
170  typedef Allocator allocator;
171 
172  public:
173  Matrix();
174  Matrix(int i, int j);
175  };
176 
177 
179  template <class T, class Prop, class Allocator>
180  class Matrix<T, Prop, ColSymPackedCollection, Allocator>:
181  public MatrixCollection<T, Prop, ColSymPacked, Allocator>
182  {
183  // typedef declaration.
184  public:
185  typedef T value_type;
186  typedef Prop property;
188  typedef Allocator allocator;
189 
190  public:
191  Matrix();
192  Matrix(int i, int j);
193  };
194 
195 
197  template <class T, class Prop, class Allocator>
198  class Matrix<T, Prop, RowSymPackedCollection, Allocator>:
199  public MatrixCollection<T, Prop, RowSymPacked, Allocator>
200  {
201  // typedef declaration.
202  public:
203  typedef T value_type;
204  typedef Prop property;
206  typedef Allocator allocator;
207 
208  public:
209  Matrix();
210  Matrix(int i, int j);
211  };
212 
213 
214 
215 } // namespace Seldon.
216 
217 
218 #define SELDON_FILE_MATRIX_COLLECTION_HXX
219 #endif
Seldon::ColMajorCollection
Definition: Storage.hxx:375
Seldon::MatrixCollection::Nullify
void Nullify()
Clears the matrix.
Definition: MatrixCollection.cxx:109
Seldon::Matrix_Base
Base class for all matrices.
Definition: Matrix_Base.hxx:143
Seldon::MatrixCollection::Read
void Read(string FileName)
Reads the matrix collection from a file.
Definition: MatrixCollection.cxx:575
Seldon::MatrixCollection::Mlocal_sum_
Vector< int, VectFull, CallocAlloc< int > > Mlocal_sum_
Cumulative number of rows in the underlying matrices.
Definition: MatrixCollection.hxx:70
Seldon::MatrixCollection
Matrix class made of a collection of matrices.
Definition: MatrixCollection.hxx:37
Seldon::Vector
Definition: SeldonHeader.hxx:207
Seldon::MatrixCollection::matrix_
collection_type matrix_
Pointers of the underlying matrices.
Definition: MatrixCollection.hxx:77
Seldon::MatrixCollection::Nmatrix_
int Nmatrix_
Number of columns of matrices.
Definition: MatrixCollection.hxx:66
Seldon::Matrix
Definition: SeldonHeader.hxx:226
Seldon::MatrixCollection::~MatrixCollection
~MatrixCollection()
Destructor.
Definition: MatrixCollectionInline.cxx:52
Seldon::MatrixCollection::operator=
MatrixCollection< T, Prop, Storage, Allocator > & operator=(const MatrixCollection< T, Prop, Storage, Allocator > &A)
Duplicates a matrix collection (assignment operator).
Definition: MatrixCollection.cxx:343
Seldon::MatrixCollection::SetMatrix
void SetMatrix(int m, int n, const Matrix< T0, Prop0, Storage0, Allocator0 > &)
Sets an underlying matrix in the matrix collection.
Definition: MatrixCollection.cxx:190
Seldon::RowMajorCollection
Definition: Storage.hxx:380
Seldon::MatrixCollection::GetM
int GetM() const
Returns the number of rows.
Definition: MatrixCollectionInline.cxx:69
Seldon::MatrixCollection::Write
void Write(string FileName, bool with_size) const
Writes the matrix collection in a file.
Definition: MatrixCollection.cxx:438
Seldon::MatrixCollection::WriteText
void WriteText(string FileName) const
Writes the matrix collection in a file.
Definition: MatrixCollection.cxx:510
Seldon::MatrixCollection::operator()
value_type operator()(int i, int j) const
Access operator.
Definition: MatrixCollection.cxx:303
Seldon::MatrixCollection::Nlocal_
Vector< int, VectFull, CallocAlloc< int > > Nlocal_
Number of columns in the underlying matrices.
Definition: MatrixCollection.hxx:72
Seldon::ColSymPackedCollection
Definition: Storage.hxx:385
Seldon::MatrixCollection::GetMatrix
matrix_reference GetMatrix(int i, int j)
Access to an underlying matrix.
Definition: MatrixCollectionInline.cxx:198
Seldon::MatrixCollection::Reallocate
void Reallocate(int i, int j)
Reallocates memory to resize the matrix collection.
Definition: MatrixCollection.cxx:164
Seldon::MatrixCollection::GetNmatrix
int GetNmatrix() const
Returns the number of columns.
Definition: MatrixCollectionInline.cxx:125
Seldon::MatrixCollection::MatrixCollection
MatrixCollection()
Default constructor.
Definition: MatrixCollection.cxx:45
Seldon::MatrixCollection::GetMmatrix
int GetMmatrix() const
Returns the number of rows.
Definition: MatrixCollectionInline.cxx:81
Seldon::MatrixCollection::Mlocal_
Vector< int, VectFull, CallocAlloc< int > > Mlocal_
Number of rows in the underlying matrices.
Definition: MatrixCollection.hxx:68
Seldon::MatrixCollection::GetN
int GetN() const
Returns the number of columns.
Definition: MatrixCollectionInline.cxx:113
Seldon::MatrixCollection::GetMemorySize
size_t GetMemorySize() const
Returns size of A in bytes used to store the matrix.
Definition: MatrixCollectionInline.cxx:176
Seldon::MatrixCollection::GetDataSize
int GetDataSize() const
Returns the number of elements stored in memory.
Definition: MatrixCollectionInline.cxx:168
Seldon::MatrixCollection::nz_
int nz_
Number of non-zero elements.
Definition: MatrixCollection.hxx:62
Seldon::MatrixCollection::Nlocal_sum_
Vector< int, VectFull, CallocAlloc< int > > Nlocal_sum_
Cumulative number of columns in the underlying matrices.
Definition: MatrixCollection.hxx:74
Seldon::MatrixCollection::Deallocate
void Deallocate()
Deallocates underlying the matrices.
Definition: MatrixCollection.cxx:141
Seldon::MatrixCollection::Clear
void Clear()
Clears the matrix.
Definition: MatrixCollection.cxx:85
Seldon::MatrixCollection::Print
void Print() const
Displays the matrix collection on the standard output.
Definition: MatrixCollection.cxx:390
Seldon::MatrixCollection::Copy
void Copy(const MatrixCollection< T, Prop, Storage, Allocator > &A)
Duplicates a matrix collection.
Definition: MatrixCollection.cxx:358
Seldon::MatrixCollection::GetSize
int GetSize() const
Returns the number of elements stored in memory.
Definition: MatrixCollectionInline.cxx:157
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::RowSymPackedCollection
Definition: Storage.hxx:390
Seldon::MatrixCollection::Mmatrix_
int Mmatrix_
Number of rows of matrices.
Definition: MatrixCollection.hxx:64