Matrix_Base.hxx
1 // Copyright (C) 2001-2009 Vivien Mallet
2 //
3 // This file is part of the linear-algebra library Seldon,
4 // http://seldon.sourceforge.net/.
5 //
6 // Seldon is free software; you can redistribute it and/or modify it under the
7 // terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 2.1 of the License, or (at your option)
9 // any later version.
10 //
11 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
12 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
14 // more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with Seldon. If not, see http://www.gnu.org/licenses/.
18 
19 
20 // To be included by Seldon.hxx
21 
22 #ifndef SELDON_FILE_MATRIX_BASE_HXX
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 
41  template<class T>
43  {
44  // Attributes.
45  protected:
46  // Number of rows.
47  int m_;
48  // Number of columns.
49  int n_;
50 
51  // Methods.
52  public:
53  // Constructors.
54  VirtualMatrix();
55  explicit VirtualMatrix(int i, int j);
56 
57  // Basic methods.
58  int GetM() const;
59  int GetN() const;
60  int GetM(const Seldon::SeldonTranspose& status) const;
61  int GetN(const Seldon::SeldonTranspose& status) const;
62  int GetM(const CBLAS_TRANSPOSE& status) const;
63  int GetN(const CBLAS_TRANSPOSE& status) const;
64  long GetSize() const;
65 
66 #ifdef SELDON_WITH_VIRTUAL
67  virtual ~VirtualMatrix();
68 
69  protected:
70  typedef typename ClassComplexType<T>::Treal Treal;
71  typedef typename ClassComplexType<T>::Tcplx Tcplx;
72 
73  public:
74  // basic manipulation of matrix
75  virtual void Reallocate(int, int);
76  virtual void Zero();
77  virtual void SetEntry(int, int, const T&);
78  virtual void AddInteraction(int, int, const T&);
79  virtual void AddInteractionRow(int, int, const Vector<int>&,
80  const Vector<T>& val, bool sorted = false);
81 
82  virtual void AddInteractionColumn(int, int, const Vector<int>&,
83  const Vector<T>& val,
84  bool sorted = false);
85 
86  virtual void AddDistantInteraction(int i, int jglob, int proc,
87  const T& val);
88 
89  virtual void AddRowDistantInteraction(int iglob, int j, int proc,
90  const T& val);
91 
92  virtual size_t GetMemorySize() const;
93  virtual void Clear();
94  virtual void ClearRow(int i);
95 
96  // methods used for iterative solvers
97  virtual void ApplySor(const SeldonTranspose&, Vector<Treal>& x, const Vector<Treal>& r,
98  const typename ClassComplexType<T>::Treal& omega,
99  int nb_iter, int stage_ssor) const;
100 
101  virtual void ApplySor(const SeldonTranspose&, Vector<Tcplx>& x, const Vector<Tcplx>& r,
102  const typename ClassComplexType<T>::Treal& omega,
103  int nb_iter, int stage_ssor) const;
104 
105  virtual void MltAddVector(const Treal& alpha, const Vector<Treal>& x,
106  const Treal& beta, Vector<Treal>& y) const;
107 
108  virtual void MltAddVector(const Tcplx& alpha, const Vector<Tcplx>& x,
109  const Tcplx& beta, Vector<Tcplx>& y) const;
110 
111  virtual void MltAddVector(const Treal& alpha, const SeldonTranspose&,
112  const Vector<Treal>& x,
113  const Treal& beta, Vector<Treal>& y) const;
114 
115  virtual void MltAddVector(const Tcplx& alpha, const SeldonTranspose&,
116  const Vector<Tcplx>& x,
117  const Tcplx& beta, Vector<Tcplx>& y) const;
118 
119  virtual void MltVector(const Vector<Treal>& x, Vector<Treal>& y) const;
120  virtual void MltVector(const Vector<Tcplx>& x, Vector<Tcplx>& y) const;
121 
122  virtual void MltVector(const SeldonTranspose&,
123  const Vector<Treal>& x, Vector<Treal>& y) const;
124 
125  virtual void MltVector(const SeldonTranspose&,
126  const Vector<Tcplx>& x, Vector<Tcplx>& y) const;
127 
128  // methods for eigensolvers
129  virtual bool IsSymmetric() const;
130  bool IsComplex() const;
131 #endif
132 
133  };
134 
135 
137 
141  template <class T, class Allocator
143  class Matrix_Base : public VirtualMatrix<T>
144  {
145  // typdef declarations.
146  public:
147  typedef typename Allocator::value_type value_type;
148  typedef typename Allocator::pointer pointer;
149  typedef typename Allocator::const_pointer const_pointer;
150  typedef typename Allocator::reference reference;
151  typedef typename Allocator::const_reference const_reference;
152 
153  // Attributes.
154  protected:
155  // Pointer to stored elements.
156  pointer data_;
157 
158  // Methods.
159  public:
160  // Constructors.
161  Matrix_Base();
162  explicit Matrix_Base(int i, int j);
164 
165  // Destructor.
166  ~Matrix_Base();
167 
168  pointer GetData() const;
169  const_pointer GetDataConst() const;
170  void* GetDataVoid() const;
171  const void* GetDataConstVoid() const;
172 
173  };
174 
175 
176  template <class T, class Prop, class Storage, class Allocator>
177  ostream& operator << (ostream& out,
179 
180 
181 } // namespace Seldon.
182 
183 #define SELDON_FILE_MATRIX_BASE_HXX
184 #endif
Seldon::SeldonDefaultAllocator
Selection of default allocator depending on storage and value type.
Definition: Allocator.hxx:174
Seldon::SeldonTranspose
Definition: MatrixFlag.hxx:32
Seldon::Matrix_Base
Base class for all matrices.
Definition: Matrix_Base.hxx:143
Seldon::Vector< int >
Seldon::Matrix
Definition: SeldonHeader.hxx:226
Seldon::Matrix_Base::GetDataConstVoid
const void * GetDataConstVoid() const
Returns a pointer of type "const void*" to the data array.
Definition: Matrix_BaseInline.cxx:280
Seldon::Matrix_Base::GetDataVoid
void * GetDataVoid() const
Returns a pointer of type "void*" to the data array.
Definition: Matrix_BaseInline.cxx:267
Seldon::Matrix_Base::GetDataConst
const_pointer GetDataConst() const
Returns a const pointer to the data array.
Definition: Matrix_BaseInline.cxx:254
Seldon::Matrix_Base::GetData
pointer GetData() const
Returns a pointer to the data array.
Definition: Matrix_BaseInline.cxx:241
Seldon::VirtualMatrix::GetN
int GetN() const
Returns the number of columns.
Definition: Matrix_BaseInline.cxx:80
Seldon::VirtualMatrix::GetM
int GetM() const
Returns the number of rows.
Definition: Matrix_BaseInline.cxx:69
Seldon::Matrix_Base::~Matrix_Base
~Matrix_Base()
Destructor.
Definition: Matrix_BaseInline.cxx:223
Seldon::VirtualMatrix::GetSize
long GetSize() const
Returns the number of elements in the matrix.
Definition: Matrix_BaseInline.cxx:153
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::operator<<
ostream & operator<<(ostream &out, const Array< T, N, Allocator > &A)
operator<< overloaded for a 3D array.
Definition: Array.cxx:1617
Seldon::Matrix_Base::Matrix_Base
Matrix_Base()
Default constructor.
Definition: Matrix_BaseInline.cxx:178
Seldon::VirtualMatrix::VirtualMatrix
VirtualMatrix()
Default constructor.
Definition: Matrix_BaseInline.cxx:37
Seldon::VirtualMatrix
Abstract base class for all matrices.
Definition: Matrix_Base.hxx:42