Matrix_Hermitian.hxx
1 // Copyright (C) 2001-2011 Vivien Mallet
2 // Copyright (C) 2003-2011 Marc DuruflĂ©
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 // To be included by Seldon.hxx
22 
23 #ifndef SELDON_FILE_MATRIX_HERMITIAN_HXX
24 
25 #include "../share/Common.hxx"
26 #include "../share/Properties.hxx"
27 #include "../share/Storage.hxx"
28 #include "../share/Errors.hxx"
29 #include "../share/Allocator.hxx"
30 
31 namespace Seldon
32 {
33 
34 
36  template <class T, class Prop, class Storage, class Allocator
37  = typename SeldonDefaultAllocator<Storage, T>::allocator>
38  class Matrix_Hermitian: public Matrix_Base<T, Allocator>
39  {
40  // typedef declaration.
41  public:
42  typedef typename Allocator::value_type value_type;
43  typedef typename Allocator::pointer pointer;
44  typedef typename Allocator::const_pointer const_pointer;
45  typedef typename Allocator::reference reference;
46  typedef typename Allocator::const_reference const_reference;
47  typedef typename Allocator::value_type entry_type;
48  typedef typename Allocator::value_type access_type;
49  typedef typename Allocator::value_type const_access_type;
50 
51  // Attributes.
52  protected:
53  pointer* me_;
54 
55  // Methods.
56  public:
57  // Constructor.
59  explicit Matrix_Hermitian(int i, int j = 0);
61 
62  // Destructor.
64  void Clear();
65 
66  // Basic methods.
67  long GetDataSize() const;
68  size_t GetMemorySize() const;
69 
70  // Memory management.
71  void Reallocate(int i, int j);
72  void SetData(int i, int j, pointer data);
73  void Nullify();
74  void Resize(int i, int j);
75 
76  // Element access and affectation.
77  const value_type operator() (int i, int j) const;
78  const_reference Val(int i, int j) const;
79  reference Val(int i, int j);
80  const_reference Get(int i, int j) const;
81  reference Get(int i, int j);
82  reference operator[] (int i);
83  const_reference operator[] (int i) const;
84 
87 
88  void Set(int i, int j, const T& x);
90 
91  // Convenient functions.
92  void Zero();
93  void SetIdentity();
94  void Fill();
95  template <class T0>
96  void Fill(const T0& x);
97  template <class T0>
99  operator= (const T0& x);
100  void FillRand();
101  void Print() const;
102  void Print(int a, int b, int m, int n) const;
103  void Print(int l) const;
104 
105  // Input/output functions.
106  void Write(string FileName) const;
107  void Write(ostream& FileStream) const;
108  void WriteText(string FileName) const;
109  void WriteText(ostream& FileStream) const;
110  void Read(string FileName);
111  void Read(istream& FileStream);
112  void ReadText(string FileName);
113  void ReadText(istream& FileStream);
114 
115 #ifdef SELDON_WITH_VIRTUAL
116  typedef typename ClassComplexType<T>::Treal Treal;
117  typedef typename ClassComplexType<T>::Tcplx Tcplx;
118 
119  virtual void AddInteraction(int, int, const T&);
120  virtual void AddInteractionRow(int, int, const Vector<int>&,
121  const Vector<T>& val, bool sorted = false);
122 
123  virtual void AddInteractionColumn(int, int, const Vector<int>&,
124  const Vector<T>& val, bool sorted = false);
125 
126  virtual void ClearRow(int i);
127 
128  virtual void ApplySor(const SeldonTranspose&, Vector<Treal>& x, const Vector<Treal>& r,
129  const typename ClassComplexType<T>::Treal& omega,
130  int nb_iter, int stage_ssor) const;
131 
132  virtual void ApplySor(const SeldonTranspose&, Vector<Tcplx>& x, const Vector<Tcplx>& r,
133  const typename ClassComplexType<T>::Treal& omega,
134  int nb_iter, int stage_ssor) const;
135 
136  virtual void MltAddVector(const Treal& alpha, const Vector<Treal>& x,
137  const Treal& beta, Vector<Treal>& y) const;
138 
139  virtual void MltAddVector(const Tcplx& alpha, const Vector<Tcplx>& x,
140  const Tcplx& beta, Vector<Tcplx>& y) const;
141 
142  virtual void MltAddVector(const Treal& alpha, const SeldonTranspose&,
143  const Vector<Treal>& x,
144  const Treal& beta, Vector<Treal>& y) const;
145 
146  virtual void MltAddVector(const Tcplx& alpha, const SeldonTranspose&,
147  const Vector<Tcplx>& x,
148  const Tcplx& beta, Vector<Tcplx>& y) const;
149 
150  virtual void MltVector(const Vector<Treal>& x, Vector<Treal>& y) const;
151  virtual void MltVector(const Vector<Tcplx>& x, Vector<Tcplx>& y) const;
152 
153  virtual void MltVector(const SeldonTranspose&,
154  const Vector<Treal>& x, Vector<Treal>& y) const;
155 
156  virtual void MltVector(const SeldonTranspose&,
157  const Vector<Tcplx>& x, Vector<Tcplx>& y) const;
158 
159  virtual bool IsSymmetric() const;
160 #endif
161 
162  };
163 
164 
166  template <class T, class Prop, class Allocator>
167  class Matrix<T, Prop, ColHerm, Allocator>:
168  public Matrix_Hermitian<T, Prop, ColHerm, Allocator>
169  {
170  // typedef declaration.
171  public:
172  typedef typename Allocator::value_type value_type;
173  typedef Prop property;
174  typedef ColHerm storage;
175  typedef Allocator allocator;
176 
177  public:
178  Matrix();
179  explicit Matrix(int i, int j = 0);
180 
181  template <class T0>
182  Matrix<T, Prop, ColHerm, Allocator>& operator= (const T0& x);
183  Matrix<T, Prop, ColHerm, Allocator>& operator= (const Matrix<T, Prop,
184  ColHerm,
185  Allocator>& A);
186  template<class T0>
187  Matrix<T, Prop, ColHerm, Allocator>& operator*= (const T0& x);
188 
189  };
190 
191 
193  template <class T, class Prop, class Allocator>
194  class Matrix<T, Prop, RowHerm, Allocator>:
195  public Matrix_Hermitian<T, Prop, RowHerm, Allocator>
196  {
197  // typedef declaration.
198  public:
199  typedef typename Allocator::value_type value_type;
200  typedef Prop property;
201  typedef RowHerm storage;
202  typedef Allocator allocator;
203 
204  public:
205  Matrix();
206  explicit Matrix(int i, int j = 0);
207 
208  template <class T0>
209  Matrix<T, Prop, RowHerm, Allocator>& operator= (const T0& x);
210  Matrix<T, Prop, RowHerm, Allocator>& operator= (const Matrix<T, Prop,
211  RowHerm,
212  Allocator>& A);
213  template<class T0>
214  Matrix<T, Prop, RowHerm, Allocator>& operator*= (const T0& x);
215 
216  };
217 
218 
219 } // namespace Seldon.
220 
221 #define SELDON_FILE_MATRIX_HERMITIAN_HXX
222 #endif
Seldon::Matrix_Hermitian::WriteText
void WriteText(string FileName) const
Writes the matrix in a file.
Definition: Matrix_Hermitian.cxx:656
Seldon::Matrix_Hermitian::Nullify
void Nullify()
Clears the matrix without releasing memory.
Definition: Matrix_Hermitian.cxx:385
Seldon::ColHerm
Definition: Storage.hxx:196
Seldon::Matrix_Hermitian::operator[]
reference operator[](int i)
Access to elements of the data array.
Definition: Matrix_HermitianInline.cxx:209
Seldon::Matrix_Hermitian::ReadText
void ReadText(string FileName)
Reads the matrix from a file.
Definition: Matrix_Hermitian.cxx:789
Seldon::SeldonTranspose
Definition: MatrixFlag.hxx:32
Seldon::Matrix_Base
Base class for all matrices.
Definition: Matrix_Base.hxx:143
Seldon::Matrix_Hermitian::operator=
Matrix_Hermitian< T, Prop, Storage, Allocator > & operator=(const Matrix_Hermitian< T, Prop, Storage, Allocator > &A)
Duplicates a matrix (assignement operator).
Definition: Matrix_HermitianInline.cxx:266
Seldon::Vector< int >
Seldon::Matrix_Hermitian::Get
const_reference Get(int i, int j) const
Returns access to an element (i, j)
Definition: Matrix_HermitianInline.cxx:170
Seldon::Matrix
Definition: SeldonHeader.hxx:226
Seldon::Matrix_Hermitian::operator()
const value_type operator()(int i, int j) const
Access operator.
Definition: Matrix_HermitianInline.cxx:104
Seldon::Matrix< T, Prop, ColHerm, Allocator >
Column-major hermitian full-matrix class.
Definition: Matrix_Hermitian.hxx:167
Seldon::Matrix_Hermitian::Reallocate
void Reallocate(int i, int j)
Reallocates memory to resize the matrix.
Definition: Matrix_Hermitian.cxx:229
Seldon::Matrix_Hermitian
Hermitian matrix stored in a full matrix.
Definition: Matrix_Hermitian.hxx:38
Seldon::Matrix< T, Prop, RowHerm, Allocator >
Row-major hermitian full-matrix class.
Definition: Matrix_Hermitian.hxx:194
Seldon::Matrix_Hermitian::SetData
void SetData(int i, int j, pointer data)
Changes the size of the matrix and sets its data array (low level method).
Definition: Matrix_Hermitian.cxx:334
Seldon::Matrix_Hermitian::GetDataSize
long GetDataSize() const
Returns the number of elements stored in memory.
Definition: Matrix_HermitianInline.cxx:72
Seldon::RowHerm
Definition: Storage.hxx:207
Seldon::Matrix_Hermitian::Set
void Set(int i, int j, const T &x)
Sets an element of the matrix.
Definition: Matrix_HermitianInline.cxx:248
Seldon::Matrix_Hermitian::Read
void Read(string FileName)
Reads the matrix from a file.
Definition: Matrix_Hermitian.cxx:725
Seldon::Matrix_Hermitian::GetMemorySize
size_t GetMemorySize() const
Returns size of A in bytes used to store the matrix.
Definition: Matrix_HermitianInline.cxx:80
Seldon::Matrix_Hermitian::Clear
void Clear()
Clears the matrix.
Definition: Matrix_Hermitian.cxx:173
Seldon::Matrix_Hermitian::FillRand
void FillRand()
Fills the matrix randomly.
Definition: Matrix_Hermitian.cxx:504
Seldon::Matrix_Hermitian::Zero
void Zero()
Sets all elements to zero.
Definition: Matrix_Hermitian.cxx:426
Seldon::Matrix_Hermitian::Write
void Write(string FileName) const
Writes the matrix in a file.
Definition: Matrix_Hermitian.cxx:588
Seldon::Matrix_Hermitian::Val
const_reference Val(int i, int j) const
Access operator.
Definition: Matrix_HermitianInline.cxx:129
Seldon::Matrix_Hermitian::~Matrix_Hermitian
~Matrix_Hermitian()
Destructor.
Definition: Matrix_HermitianInline.cxx:53
Seldon::Matrix_Hermitian::Print
void Print() const
Displays the matrix on the standard output.
Definition: Matrix_Hermitian.cxx:521
Seldon::Matrix_Hermitian::Fill
void Fill()
Fills the matrix with 0, 1, 2, ...
Definition: Matrix_Hermitian.cxx:458
Seldon::Matrix_Hermitian::SetIdentity
void SetIdentity()
Sets the matrix to the identity.
Definition: Matrix_Hermitian.cxx:439
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::Matrix_Hermitian::Resize
void Resize(int i, int j)
Reallocates memory to resize the matrix and keeps previous entries.
Definition: Matrix_Hermitian.cxx:144
Seldon::Matrix_Hermitian::Copy
void Copy(const Matrix_Hermitian< T, Prop, Storage, Allocator > &A)
Duplicates a matrix.
Definition: Matrix_HermitianInline.cxx:282
Seldon::Matrix_Hermitian::Matrix_Hermitian
Matrix_Hermitian()
Default constructor.
Definition: Matrix_HermitianInline.cxx:39