HeterogeneousMatrixCollectionInline.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_HETEROGENEOUS_MATRIX_COLLECTION_INLINE_CXX
22 
23 #include "HeterogeneousMatrixCollection.hxx"
24 
25 namespace Seldon
26 {
27 
28 
30  // HETEROGENEOUSMATRIXCOLLECTION //
32 
33 
35 
40  template <class Prop0, class Storage0,
41  class Prop1, class Storage1,
42  template <class U> class Allocator> inline
45  Storage0, Prop1, Storage1, Allocator>& A):
46  Matrix_Base<double, Allocator<double> >()
47  {
48  this->Copy(A);
49  }
50 
51 
52  /**************
53  * DESTRUCTOR *
54  **************/
55 
56 
58  template <class Prop0, class Storage0,
59  class Prop1, class Storage1,
60  template <class U> class Allocator> inline
63  {
64  this->Clear();
65  }
66 
67 
68  /*******************
69  * BASIC FUNCTIONS *
70  *******************/
71 
72 
74 
78  template <class Prop0, class Storage0,
79  class Prop1, class Storage1,
80  template <class U> class Allocator> inline int
82  ::GetM() const
83  {
84  return this->m_;
85  }
86 
87 
89 
93  template <class Prop0, class Storage0,
94  class Prop1, class Storage1,
95  template <class U> class Allocator> inline int
98  {
99  return Mmatrix_;
100  }
101 
102 
104 
108  template <class Prop0, class Storage0,
109  class Prop1, class Storage1,
110  template <class U> class Allocator> inline int
112  ::GetM(int i) const
113  {
114 #ifdef SELDON_CHECK_BOUNDS
115  if (i < 0 || i >= Mmatrix_)
116  throw WrongRow("HeterogeneousMatrixCollection::GetM()",
117  string("Index should be in [0, ")
118  + to_str(Mmatrix_ - 1) + "], but is equal to "
119  + to_str(i) + ".");
120 #endif
121 
122  return Mlocal_(i);
123  }
124 
125 
127 
131  template <class Prop0, class Storage0,
132  class Prop1, class Storage1,
133  template <class U> class Allocator> inline int
135  ::GetN() const
136  {
137  return this->n_;
138  }
139 
140 
142 
146  template <class Prop0, class Storage0,
147  class Prop1, class Storage1,
148  template <class U> class Allocator> inline int
151  {
152  return Nmatrix_;
153  }
154 
155 
157 
162  template <class Prop0, class Storage0,
163  class Prop1, class Storage1,
164  template <class U> class Allocator> inline int
166  ::GetN(int j) const
167  {
168 #ifdef SELDON_CHECK_BOUNDS
169  if (j < 0 || j >= Nmatrix_)
170  throw WrongCol("HeterogeneousMatrixCollection::GetN()",
171  string("Index should be in [0, ")
172  + to_str(Nmatrix_ - 1) + "], but is equal to "
173  + to_str(j) + ".");
174 #endif
175 
176  return Nlocal_(j);
177  }
178 
179 
181 
184  template <class Prop0, class Storage0,
185  class Prop1, class Storage1,
186  template <class U> class Allocator> inline int
188  ::GetSize() const
189  {
190  return this->m_ * this->n_;
191  }
192 
193 
195 
198  template <class Prop0, class Storage0,
199  class Prop1, class Storage1,
200  template <class U> class Allocator>
201  inline int
204  {
205  return nz_;
206  }
207 
208 
210  template <class Prop0, class Storage0,
211  class Prop1, class Storage1,
212  template <class U> class Allocator>
213  inline size_t
216  {
217  // to implement
218  return 0;
219  }
220 
221 
222 
224 
233  template <class Prop0, class Storage0,
234  class Prop1, class Storage1,
235  template <class U> class Allocator>
236  inline int
238  ::GetType(int i, int j) const
239  {
240 #ifdef SELDON_CHECK_BOUNDS
241  if (i < 0 || i >= Mmatrix_)
242  throw WrongRow("HeterogeneousMatrixCollection::GetType()",
243  string("Index should be in [0, ")
244  + to_str(Mmatrix_ - 1) + "], but is equal to "
245  + to_str(i) + ".");
246  if (j < 0 || j >= Nmatrix_)
247  throw WrongCol("HeterogeneousMatrixCollection::GetType()",
248  string("Index should be in [0, ")
249  + to_str(Nmatrix_ - 1) + "], but is equal to "
250  + to_str(j) + ".");
251 #endif
252  return collection_(i, j);
253  }
254 
255 
256 
258 
261  template <class Prop0, class Storage0,
262  class Prop1, class Storage1,
263  template <class U> class Allocator> inline typename
265  ::float_dense_c&
268  {
269  return float_dense_c_;
270  }
271 
272 
274 
277  template <class Prop0, class Storage0,
278  class Prop1, class Storage1,
279  template <class U> class Allocator> inline const typename
281  ::float_dense_c&
283  ::GetFloatDense() const
284  {
285  return float_dense_c_;
286  }
287 
288 
290 
293  template <class Prop0, class Storage0,
294  class Prop1, class Storage1,
295  template <class U> class Allocator> inline typename
296  HeterogeneousMatrixCollection<Prop0, Storage0, Prop1, Storage1, Allocator>
297  ::float_sparse_c&
300  {
301  return float_sparse_c_;
302  }
303 
304 
306 
309  template <class Prop0, class Storage0,
310  class Prop1, class Storage1,
311  template <class U> class Allocator> inline const typename
313  ::float_sparse_c&
315  ::GetFloatSparse() const
316  {
317  return float_sparse_c_;
318  }
319 
320 
322 
325  template <class Prop0, class Storage0,
326  class Prop1, class Storage1,
327  template <class U> class Allocator> inline typename
328  HeterogeneousMatrixCollection<Prop0, Storage0, Prop1, Storage1, Allocator>
329  ::double_dense_c&
332  {
333  return double_dense_c_;
334  }
335 
336 
338 
341  template <class Prop0, class Storage0,
342  class Prop1, class Storage1,
343  template <class U> class Allocator> inline const typename
345  ::double_dense_c&
347  ::GetDoubleDense() const
348  {
349  return double_dense_c_;
350  }
351 
352 
354 
357  template <class Prop0, class Storage0,
358  class Prop1, class Storage1,
359  template <class U> class Allocator> inline typename
360  HeterogeneousMatrixCollection<Prop0, Storage0, Prop1, Storage1, Allocator>
361  ::double_sparse_c&
364  {
365  return double_sparse_c_;
366  }
367 
368 
370 
373  template <class Prop0, class Storage0,
374  class Prop1, class Storage1,
375  template <class U> class Allocator> inline const typename
377  ::double_sparse_c&
379  ::GetDoubleSparse() const
380  {
381  return double_sparse_c_;
382  }
383 
384 
385  /****************
386  * CONSTRUCTORS *
387  ****************/
388 
389 
391 
394  template <template <class U> class Allocator>
395  inline
396  Matrix<FloatDouble, General, DenseSparseCollection, Allocator<double> >
399  RowSparse, Allocator>()
400  {
401  }
402 
403 
405 
409  template <template <class U> class Allocator>
410  inline
412  ::Matrix(int i, int j):
414  RowSparse, Allocator>(i, j)
415  {
416  }
417 
418 
419 } // namespace Seldon.
420 
421 #define SELDON_FILE_MATRIX_HETEROGENEOUS_COLLECTION_INLINE_CXX
422 #endif
Seldon::HeterogeneousMatrixCollection::GetFloatSparse
float_sparse_c & GetFloatSparse()
Returns the collection of float sparse underlying matrices.
Definition: HeterogeneousMatrixCollectionInline.cxx:299
Seldon::RowMajor
Definition: Storage.hxx:45
Seldon::HeterogeneousMatrixCollection::GetDoubleSparse
double_sparse_c & GetDoubleSparse()
Returns the collection of double sparse underlying matrices.
Definition: HeterogeneousMatrixCollectionInline.cxx:363
Seldon::Matrix_Base
Base class for all matrices.
Definition: Matrix_Base.hxx:143
Seldon::HeterogeneousMatrixCollection::GetSize
int GetSize() const
Returns the number of elements stored in memory.
Definition: HeterogeneousMatrixCollectionInline.cxx:188
Seldon::to_str
std::string to_str(const T &input)
Converts most types to string.
Definition: CommonInline.cxx:137
Seldon::WrongCol
Definition: Errors.hxx:138
Seldon::Matrix
Definition: SeldonHeader.hxx:226
Seldon::HeterogeneousMatrixCollection::GetMemorySize
size_t GetMemorySize() const
Returns size of A in bytes used to store the matrix.
Definition: HeterogeneousMatrixCollectionInline.cxx:215
Seldon::WrongRow
Definition: Errors.hxx:126
Seldon::HeterogeneousMatrixCollection
Matrix class made of an heterogeneous collection of matrices.
Definition: HeterogeneousMatrixCollection.hxx:42
Seldon::HeterogeneousMatrixCollection::HeterogeneousMatrixCollection
HeterogeneousMatrixCollection()
Default constructor.
Definition: HeterogeneousMatrixCollection.cxx:47
Seldon::HeterogeneousMatrixCollection::GetNmatrix
int GetNmatrix() const
Returns the number of columns.
Definition: HeterogeneousMatrixCollectionInline.cxx:150
Seldon::HeterogeneousMatrixCollection::GetM
int GetM() const
Returns the number of rows.
Definition: HeterogeneousMatrixCollectionInline.cxx:82
Seldon::General
Definition: Properties.hxx:26
Seldon::HeterogeneousMatrixCollection::GetType
int GetType(int i, int j) const
Returns the type of a given underlying matrix.
Definition: HeterogeneousMatrixCollectionInline.cxx:238
Seldon::HeterogeneousMatrixCollection::GetDoubleDense
double_dense_c & GetDoubleDense()
Returns the collection of double dense underlying matrices.
Definition: HeterogeneousMatrixCollectionInline.cxx:331
Seldon::HeterogeneousMatrixCollection::GetFloatDense
float_dense_c & GetFloatDense()
Returns the collection of float dense underlying matrices.
Definition: HeterogeneousMatrixCollectionInline.cxx:267
Seldon::HeterogeneousMatrixCollection::GetMmatrix
int GetMmatrix() const
Returns the number of rows.
Definition: HeterogeneousMatrixCollectionInline.cxx:97
Seldon::HeterogeneousMatrixCollection::~HeterogeneousMatrixCollection
~HeterogeneousMatrixCollection()
Destructor.
Definition: HeterogeneousMatrixCollectionInline.cxx:62
Seldon::RowSparse
Definition: Storage.hxx:91
Seldon::HeterogeneousMatrixCollection::GetN
int GetN() const
Returns the number of columns.
Definition: HeterogeneousMatrixCollectionInline.cxx:135
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::HeterogeneousMatrixCollection::GetDataSize
int GetDataSize() const
Returns the number of elements stored in memory.
Definition: HeterogeneousMatrixCollectionInline.cxx:203