HeterogeneousMatrixCollection.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_HETEROGENEOUS_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 
39  template <class Prop0, class Storage0,
40  class Prop1, class Storage1,
41  template <class U> class Allocator>
43  public Matrix_Base<double, Allocator<double> >
44  {
45 
46  // Typedef declarations.
47  public:
54 
63 
64  // Attributes.
65  protected:
67  int nz_;
69  int Mmatrix_;
71  int Nmatrix_;
80 
82 
89 
98 
99 
100  // Methods.
101  public:
102  // Constructor.
104  HeterogeneousMatrixCollection(int i, int j);
106  (const HeterogeneousMatrixCollection<Prop0, Storage0, Prop1,
107  Storage1, Allocator>& A);
108 
109  // Destructor.
111  void Clear();
112  void Nullify();
113  void Nullify(int i, int j);
114  void Deallocate();
115 
116  // Basic methods. (inline)
117  int GetM() const;
118  int GetMmatrix() const;
119  int GetM(int i) const;
120  int GetN() const;
121  int GetNmatrix() const;
122  int GetN(int j) const;
123  int GetSize() const;
124  int GetDataSize() const;
125  size_t GetMemorySize() const;
126  int GetType(int i, int j) const;
127 
129  const float_dense_c& GetFloatDense() const;
131  const float_sparse_c& GetFloatSparse() const;
133  const double_dense_c& GetDoubleDense() const;
135  const double_sparse_c& GetDoubleSparse() const;
136 
137  // Memory management.
138  void Reallocate(int i, int j);
139 
140  // Management of the matrices.
141  void SetMatrix(int m, int n, const float_dense_m&);
142  void SetMatrix(int m, int n, const float_sparse_m&);
143  void SetMatrix(int m, int n, const double_dense_m&);
144  void SetMatrix(int m, int n, const double_sparse_m&);
145 
146  // Element access and affectation.
147  void GetMatrix(int m, int n, float_dense_m&) const;
148  void GetMatrix(int m, int n, float_sparse_m&) const;
149  void GetMatrix(int m, int n, double_dense_m&) const;
150  void GetMatrix(int m, int n, double_sparse_m&) const;
151 
152 
153  double operator() (int i, int j) const;
154 
155  HeterogeneousMatrixCollection<Prop0, Storage0, Prop1,
156  Storage1, Allocator>&
157  operator= (const HeterogeneousMatrixCollection<Prop0, Storage0,
158  Prop1, Storage1, Allocator>& A);
159 
160  void Copy(const HeterogeneousMatrixCollection<Prop0, Storage0,
161  Prop1, Storage1, Allocator>& A);
162 
163  // Convenient functions.
164  void Print() const;
165 
166  // Input/output functions.
167  void Write(string FileName, bool with_size) const;
168  void Write(ostream& FileStream, bool with_size) const;
169  void WriteText(string FileName) const;
170  void WriteText(ostream& FileStream) const;
171 
172  void Read(string FileName);
173  void Read(istream& FileStream);
174 
175  };
176 
177 
179  template <template <class U> class Allocator>
181  DenseSparseCollection, Allocator<double> >:
182  public HeterogeneousMatrixCollection<General, RowMajor, General,
183  RowSparse, Allocator >
184  {
185  // typedef declaration.
186  public:
187  typedef General property;
189  typedef Allocator<double> allocator;
190 
191  public:
192  Matrix();
193  Matrix(int i, int j);
194  };
195 
196 
197 } // namespace Seldon.
198 
199 
200 #define SELDON_FILE_HETEROGENEOUS_MATRIX_COLLECTION_HXX
201 #endif
Seldon::HeterogeneousMatrixCollection::GetFloatSparse
float_sparse_c & GetFloatSparse()
Returns the collection of float sparse underlying matrices.
Definition: HeterogeneousMatrixCollectionInline.cxx:299
Seldon::HeterogeneousMatrixCollection::WriteText
void WriteText(string FileName) const
Writes the matrix collection in a file.
Definition: HeterogeneousMatrixCollection.cxx:1063
Seldon::HeterogeneousMatrixCollection::Print
void Print() const
Displays the matrix collection on the standard output.
Definition: HeterogeneousMatrixCollection.cxx:925
Seldon::FloatDouble
Definition: Storage.hxx:365
Seldon::HeterogeneousMatrixCollection::GetDoubleSparse
double_sparse_c & GetDoubleSparse()
Returns the collection of double sparse underlying matrices.
Definition: HeterogeneousMatrixCollectionInline.cxx:363
Seldon::HeterogeneousMatrixCollection::double_sparse_c_
double_sparse_c double_sparse_c_
Pointers of the underlying double sparse matrices.
Definition: HeterogeneousMatrixCollection.hxx:97
Seldon::Matrix_Base
Base class for all matrices.
Definition: Matrix_Base.hxx:143
Seldon::HeterogeneousMatrixCollection::operator()
double operator()(int i, int j) const
Access operator.
Definition: HeterogeneousMatrixCollection.cxx:764
Seldon::HeterogeneousMatrixCollection::float_dense_c_
float_dense_c float_dense_c_
Pointers of the underlying float dense matrices.
Definition: HeterogeneousMatrixCollection.hxx:91
Seldon::HeterogeneousMatrixCollection::GetSize
int GetSize() const
Returns the number of elements stored in memory.
Definition: HeterogeneousMatrixCollectionInline.cxx:188
Seldon::DenseSparseCollection
Definition: StorageInline.cxx:89
Seldon::HeterogeneousMatrixCollection::Read
void Read(string FileName)
Reads the matrix collection from a file.
Definition: HeterogeneousMatrixCollection.cxx:1169
Seldon::Vector< int >
Seldon::Matrix
Definition: SeldonHeader.hxx:226
Seldon::NewAlloc
Definition: Allocator.hxx:91
Seldon::HeterogeneousMatrixCollection::GetMemorySize
size_t GetMemorySize() const
Returns size of A in bytes used to store the matrix.
Definition: HeterogeneousMatrixCollectionInline.cxx:215
Seldon::RowMajorCollection
Definition: Storage.hxx:380
Seldon::HeterogeneousMatrixCollection::Reallocate
void Reallocate(int i, int j)
Reallocates memory to resize the matrix collection.
Definition: HeterogeneousMatrixCollection.cxx:211
Seldon::HeterogeneousMatrixCollection::operator=
HeterogeneousMatrixCollection< Prop0, Storage0, Prop1, Storage1, Allocator > & operator=(const HeterogeneousMatrixCollection< Prop0, Storage0, Prop1, Storage1, Allocator > &A)
Duplicates a matrix collection (assignment operator).
Definition: HeterogeneousMatrixCollection.cxx:832
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::nz_
int nz_
Number of non-zero elements.
Definition: HeterogeneousMatrixCollection.hxx:67
Seldon::HeterogeneousMatrixCollection::GetM
int GetM() const
Returns the number of rows.
Definition: HeterogeneousMatrixCollectionInline.cxx:82
Seldon::HeterogeneousMatrixCollection::Mmatrix_
int Mmatrix_
Number of rows of matrices.
Definition: HeterogeneousMatrixCollection.hxx:69
Seldon::General
Definition: Properties.hxx:26
Seldon::HeterogeneousMatrixCollection::Write
void Write(string FileName, bool with_size) const
Writes the matrix collection in a file.
Definition: HeterogeneousMatrixCollection.cxx:949
Seldon::HeterogeneousMatrixCollection::Mlocal_
Vector< int > Mlocal_
Number of rows in the underlying matrices.
Definition: HeterogeneousMatrixCollection.hxx:73
Seldon::HeterogeneousMatrixCollection::GetType
int GetType(int i, int j) const
Returns the type of a given underlying matrix.
Definition: HeterogeneousMatrixCollectionInline.cxx:238
Seldon::HeterogeneousMatrixCollection::Copy
void Copy(const HeterogeneousMatrixCollection< Prop0, Storage0, Prop1, Storage1, Allocator > &A)
Duplicates a matrix collection (assignment operator).
Definition: HeterogeneousMatrixCollection.cxx:850
Seldon::HeterogeneousMatrixCollection::Nlocal_
Vector< int > Nlocal_
Number of columns in the underlying matrices.
Definition: HeterogeneousMatrixCollection.hxx:77
Seldon::HeterogeneousMatrixCollection::Mlocal_sum_
Vector< int > Mlocal_sum_
Cumulative number of rows in the underlying matrices.
Definition: HeterogeneousMatrixCollection.hxx:75
Seldon::HeterogeneousMatrixCollection::Clear
void Clear()
Clears the matrix collection without releasing memory.
Definition: HeterogeneousMatrixCollection.cxx:92
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::Nmatrix_
int Nmatrix_
Number of columns of matrices.
Definition: HeterogeneousMatrixCollection.hxx:71
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::HeterogeneousMatrixCollection::GetN
int GetN() const
Returns the number of columns.
Definition: HeterogeneousMatrixCollectionInline.cxx:135
Seldon::HeterogeneousMatrixCollection::Nlocal_sum_
Vector< int > Nlocal_sum_
Cumulative number of columns in the underlying matrices.
Definition: HeterogeneousMatrixCollection.hxx:79
Seldon::HeterogeneousMatrixCollection::Deallocate
void Deallocate()
Deallocates underlying the matrices.
Definition: HeterogeneousMatrixCollection.cxx:185
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::HeterogeneousMatrixCollection::double_dense_c_
double_dense_c double_dense_c_
Pointers of the underlying double dense matrices.
Definition: HeterogeneousMatrixCollection.hxx:95
Seldon::HeterogeneousMatrixCollection::GetDataSize
int GetDataSize() const
Returns the number of elements stored in memory.
Definition: HeterogeneousMatrixCollectionInline.cxx:203
Seldon::HeterogeneousMatrixCollection::float_sparse_c_
float_sparse_c float_sparse_c_
Pointers of the underlying float sparse matrices.
Definition: HeterogeneousMatrixCollection.hxx:93
Seldon::HeterogeneousMatrixCollection::collection_
Matrix< int, General, RowMajor > collection_
Type of the underlying matrices.
Definition: HeterogeneousMatrixCollection.hxx:88
Seldon::HeterogeneousMatrixCollection::Nullify
void Nullify()
Clears the matrix collection without releasing memory.
Definition: HeterogeneousMatrixCollection.cxx:115