MatrixCollectionInline.cxx
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_INLINE_CXX
22 
23 #include "MatrixCollection.hxx"
24 
25 
26 namespace Seldon
27 {
28 
29 
31  // MATRIXCOLLECTION //
33 
34 
36  template <class T, class Prop, class Storage, class Allocator>
39  : Matrix_Base<T, Allocator>()
40  {
41  this->Copy(A);
42  }
43 
44 
45  /**************
46  * DESTRUCTOR *
47  **************/
48 
49 
51  template <class T, class Prop, class Storage, class Allocator>
53  {
54  Clear();
55  }
56 
57 
58  /*******************
59  * BASIC FUNCTIONS *
60  *******************/
61 
62 
64 
68  template <class T, class Prop, class Storage, class Allocator>
70  {
71  return this->m_;
72  }
73 
74 
76 
80  template <class T, class Prop, class Storage, class Allocator>
82  {
83  return Mmatrix_;
84  }
85 
86 
88 
92  template <class T, class Prop, class Storage, class Allocator>
94  {
95 #ifdef SELDON_CHECK_BOUNDS
96  if (i < 0 || i >= Mmatrix_)
97  throw WrongRow("MatrixCollection::GetM()",
98  string("Index should be in [0, ")
99  + to_str(Mmatrix_ - 1) + "], but is equal to "
100  + to_str(i) + ".");
101 #endif
102 
103  return Mlocal_(i);
104  }
105 
106 
108 
112  template <class T, class Prop, class Storage, class Allocator>
114  {
115  return this->n_;
116  }
117 
118 
120 
124  template <class T, class Prop, class Storage, class Allocator>
126  {
127  return Nmatrix_;
128  }
129 
130 
132 
137  template <class T, class Prop, class Storage, class Allocator>
139  {
140 #ifdef SELDON_CHECK_BOUNDS
141  if (j < 0 || j >= Nmatrix_)
142  throw WrongCol("MatrixCollection::GetN()",
143  string("Index should be in [0, ")
144  + to_str(Nmatrix_ - 1) + "], but is equal to "
145  + to_str(j) + ".");
146 #endif
147 
148  return Nlocal_(j);
149  }
150 
151 
153 
156  template <class T, class Prop, class Storage, class Allocator>
158  {
159  return this->m_ * this->n_;
160  }
161 
162 
164 
167  template <class T, class Prop, class Storage, class Allocator>
169  {
170  return nz_;
171  }
172 
173 
175  template <class T, class Prop, class Storage, class Allocator>
177  {
178  size_t taille = size_t(nz_)*sizeof(T);
179  return taille;
180  }
181 
182 
183  /**********************************
184  * ELEMENT ACCESS AND AFFECTATION *
185  **********************************/
186 
187 
189 
195  template <class T, class Prop, class Storage, class Allocator>
196  inline
197  typename MatrixCollection<T, Prop, Storage, Allocator>::matrix_reference
199  {
200 #ifdef SELDON_CHECK_BOUNDS
201  if (i < 0 || i >= Mmatrix_)
202  throw WrongRow("MatrixCollection::GetMatrix(int, int)",
203  string("Row index should be in [0, ")
204  + to_str(Mmatrix_ - 1) + "], but is equal to "
205  + to_str(i) + ".");
206  if (j < 0 || j >= Nmatrix_)
207  throw WrongCol("MatrixCollection::GetMatrix(int, int)",
208  string("Column index should be in [0, ")
209  + to_str(Nmatrix_ - 1) + "], but is equal to "
210  + to_str(j) + ".");
211 #endif
212 
213  return matrix_(i, j);
214  }
215 
216 
218 
224  template <class T, class Prop, class Storage, class Allocator>
226  ::const_matrix_reference
228  int j) const
229  {
230 #ifdef SELDON_CHECK_BOUNDS
231  if (i < 0 || i >= Mmatrix_)
232  throw WrongRow("MatrixCollection::GetMatrix(int, int)",
233  string("Row index should be in [0, ")
234  + to_str(Mmatrix_ - 1) + "], but is equal to "
235  + to_str(i) + ".");
236  if (j < 0 || j >= Nmatrix_)
237  throw WrongCol("MatrixCollection::GetMatrix(int, int)",
238  string("Column index should be in [0, ")
239  + to_str(Nmatrix_ - 1) + "], but is equal to "
240  + to_str(j) + ".");
241 #endif
242 
243  return matrix_(i, j);
244  }
245 
246 
248  // COLMAJORCOLLECTION //
250 
251 
252  /****************
253  * CONSTRUCTORS *
254  ****************/
255 
256 
258 
261  template <class T, class Prop, class Allocator>
263  MatrixCollection<T, Prop, ColMajor, Allocator>()
264  {
265  }
266 
267 
269 
273  template <class T, class Prop, class Allocator>
275  MatrixCollection<T, Prop, ColMajor, Allocator>(i, j)
276  {
277  }
278 
279 
281  // ROWMAJORCOLLECTION //
283 
284 
285  /****************
286  * CONSTRUCTORS *
287  ****************/
288 
289 
291 
294  template <class T, class Prop, class Allocator>
296  MatrixCollection<T, Prop, RowMajor, Allocator>()
297  {
298  }
299 
300 
302 
306  template <class T, class Prop, class Allocator>
308  MatrixCollection<T, Prop, RowMajor, Allocator>(i, j)
309  {
310  }
311 
312 
314  // COLSYMPACKEDCOLLECTION //
316 
317 
318  /****************
319  * CONSTRUCTORS *
320  ****************/
321 
322 
324 
327  template <class T, class Prop, class Allocator>
329  MatrixCollection<T, Prop, ColSymPacked, Allocator>()
330  {
331  }
332 
333 
335 
339  template <class T, class Prop, class Allocator>
341  ::Matrix(int i, int j):
342  MatrixCollection<T, Prop, ColSymPacked, Allocator>(i, j)
343  {
344  }
345 
346 
348  // ROWSYMPACKEDCOLLECTION //
350 
351 
352  /****************
353  * CONSTRUCTORS *
354  ****************/
355 
356 
358 
361  template <class T, class Prop, class Allocator>
363  MatrixCollection<T, Prop, RowSymPacked, Allocator>()
364  {
365  }
366 
367 
369 
373  template <class T, class Prop, class Allocator>
375  ::Matrix(int i, int j):
376  MatrixCollection<T, Prop, RowSymPacked, Allocator>(i, j)
377  {
378  }
379 
380 
381 } // namespace Seldon.
382 
383 
384 #define SELDON_FILE_MATRIX_COLLECTION_INLINE_CXX
385 #endif
Seldon::RowMajor
Definition: Storage.hxx:45
Seldon::Matrix_Base
Base class for all matrices.
Definition: Matrix_Base.hxx:143
Seldon::to_str
std::string to_str(const T &input)
Converts most types to string.
Definition: CommonInline.cxx:137
Seldon::MatrixCollection
Matrix class made of a collection of matrices.
Definition: MatrixCollection.hxx:37
Seldon::WrongCol
Definition: Errors.hxx:138
Seldon::Matrix
Definition: SeldonHeader.hxx:226
Seldon::MatrixCollection::~MatrixCollection
~MatrixCollection()
Destructor.
Definition: MatrixCollectionInline.cxx:52
Seldon::MatrixCollection::GetM
int GetM() const
Returns the number of rows.
Definition: MatrixCollectionInline.cxx:69
Seldon::WrongRow
Definition: Errors.hxx:126
Seldon::RowSymPacked
Definition: Storage.hxx:157
Seldon::ColSymPacked
Definition: Storage.hxx:146
Seldon::MatrixCollection::GetMatrix
matrix_reference GetMatrix(int i, int j)
Access to an underlying matrix.
Definition: MatrixCollectionInline.cxx:198
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::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::GetSize
int GetSize() const
Returns the number of elements stored in memory.
Definition: MatrixCollectionInline.cxx:157
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::ColMajor
Definition: Storage.hxx:33