Matrix_HermPacked.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_HERMPACKED_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_HermPacked: 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::reference access_type;
49  typedef typename Allocator::const_reference const_access_type;
50 
51  // Methods.
52  public:
53  // Constructor.
55  explicit Matrix_HermPacked(int i, int j = 0);
57  Storage, Allocator>& A);
58 
59  // Destructor.
61  void Clear();
62 
63  // Basic methods.
64  long GetDataSize() const;
65  size_t GetMemorySize() const;
66 
67  // Memory management.
68  void Reallocate(int i, int j);
69  void SetData(int i, int j, pointer data);
70  void Nullify();
71 
72  // Element access and affectation.
73  const value_type operator() (int i, int j) const;
74  reference Val(int i, int j);
75  const_reference Val(int i, int j) const;
76  reference Get(int i, int j);
77  const_reference Get(int i, int j) const;
78  reference operator[] (int i);
79  const_reference operator[] (int i) const;
82  void Set(int i, int j, const T& val);
84 
85  // Convenient functions.
86  void Zero();
87  void SetIdentity();
88  void Fill();
89  template <class T0>
90  void Fill(const T0& x);
91  template <class T0>
93  void FillRand();
94  void Print() const;
95  void Print(int a, int b, int m, int n) const;
96  void Print(int l) const;
97 
98  // Input/output functions.
99  void Write(string FileName) const;
100  void Write(ostream& FileStream) const;
101  void WriteText(string FileName) const;
102  void WriteText(ostream& FileStream) const;
103  void Read(string FileName);
104  void Read(istream& FileStream);
105  void ReadText(string FileName);
106  void ReadText(istream& FileStream);
107 
108 #ifdef SELDON_WITH_VIRTUAL
109  typedef typename ClassComplexType<T>::Treal Treal;
110  typedef typename ClassComplexType<T>::Tcplx Tcplx;
111 
112  virtual void AddInteraction(int, int, const T&);
113  virtual void AddInteractionRow(int, int, const Vector<int>&,
114  const Vector<T>& val, bool s = false);
115 
116  virtual void AddInteractionColumn(int, int, const Vector<int>&,
117  const Vector<T>& val, bool s = false);
118 
119  virtual void ClearRow(int i);
120 
121  virtual void ApplySor(const SeldonTranspose&, Vector<Treal>& x, const Vector<Treal>& r,
122  const typename ClassComplexType<T>::Treal& omega,
123  int nb_iter, int stage_ssor) const;
124 
125  virtual void ApplySor(const SeldonTranspose&, Vector<Tcplx>& x, const Vector<Tcplx>& r,
126  const typename ClassComplexType<T>::Treal& omega,
127  int nb_iter, int stage_ssor) const;
128 
129  virtual void MltAddVector(const Treal& alpha, const Vector<Treal>& x,
130  const Treal& beta, Vector<Treal>& y) const;
131 
132  virtual void MltAddVector(const Tcplx& alpha, const Vector<Tcplx>& x,
133  const Tcplx& beta, Vector<Tcplx>& y) const;
134 
135  virtual void MltAddVector(const Treal& alpha, const SeldonTranspose&,
136  const Vector<Treal>& x,
137  const Treal& beta, Vector<Treal>& y) const;
138 
139  virtual void MltAddVector(const Tcplx& alpha, const SeldonTranspose&,
140  const Vector<Tcplx>& x,
141  const Tcplx& beta, Vector<Tcplx>& y) const;
142 
143  virtual void MltVector(const Vector<Treal>& x, Vector<Treal>& y) const;
144  virtual void MltVector(const Vector<Tcplx>& x, Vector<Tcplx>& y) const;
145 
146  virtual void MltVector(const SeldonTranspose&,
147  const Vector<Treal>& x, Vector<Treal>& y) const;
148 
149  virtual void MltVector(const SeldonTranspose&,
150  const Vector<Tcplx>& x, Vector<Tcplx>& y) const;
151 
152  virtual bool IsSymmetric() const;
153 #endif
154 
155  };
156 
157 
159  template <class T, class Prop, class Allocator>
160  class Matrix<T, Prop, ColHermPacked, Allocator>:
161  public Matrix_HermPacked<T, Prop, ColHermPacked, Allocator>
162  {
163  // typedef declaration.
164  public:
165  typedef typename Allocator::value_type value_type;
166  typedef Prop property;
167  typedef ColHermPacked storage;
168  typedef Allocator allocator;
169 
170  public:
171  Matrix();
172  explicit Matrix(int i, int j = 0);
173 
174  template <class T0>
175  Matrix<T, Prop, ColHermPacked, Allocator>& operator= (const T0& x);
176  Matrix<T, Prop, ColHermPacked, Allocator>& operator= (const Matrix<T, Prop,
178  Allocator>& A);
179  template<class T0>
180  Matrix<T, Prop, ColHermPacked, Allocator>& operator*= (const T0& x);
181 
182  void Resize(int i, int j);
183 
184  };
185 
186 
188  template <class T, class Prop, class Allocator>
189  class Matrix<T, Prop, RowHermPacked, Allocator>:
190  public Matrix_HermPacked<T, Prop, RowHermPacked, Allocator>
191  {
192  // typedef declaration.
193  public:
194  typedef typename Allocator::value_type value_type;
195  typedef Prop property;
196  typedef RowHermPacked storage;
197  typedef Allocator allocator;
198 
199  public:
200  Matrix();
201  explicit Matrix(int i, int j = 0);
202 
203  template <class T0>
204  Matrix<T, Prop, RowHermPacked, Allocator>& operator= (const T0& x);
205  Matrix<T, Prop, RowHermPacked, Allocator>& operator= (const Matrix<T, Prop,
207  Allocator>& A);
208  template<class T0>
209  Matrix<T, Prop, RowHermPacked, Allocator>& operator*= (const T0& x);
210 
211  void Resize(int i, int j);
212 
213  };
214 
215 
216 } // namespace Seldon.
217 
218 #define SELDON_FILE_MATRIX_HERMPACKED_HXX
219 #endif
Seldon::Matrix_HermPacked::Nullify
void Nullify()
Clears the matrix without releasing memory.
Definition: Matrix_HermPacked.cxx:211
Seldon::Matrix_HermPacked::Set
void Set(int i, int j, const T &val)
Sets an element of the matrix.
Definition: Matrix_HermPackedInline.cxx:254
Seldon::SeldonTranspose
Definition: MatrixFlag.hxx:32
Seldon::Matrix_Base
Base class for all matrices.
Definition: Matrix_Base.hxx:143
Seldon::Matrix_HermPacked::Zero
void Zero()
Sets all elements to zero.
Definition: Matrix_HermPacked.cxx:230
Seldon::Vector< int >
Seldon::Matrix_HermPacked::Matrix_HermPacked
Matrix_HermPacked()
Default constructor.
Definition: Matrix_HermPackedInline.cxx:39
Seldon::Matrix_HermPacked::Reallocate
void Reallocate(int i, int j)
Reallocates memory to resize the matrix.
Definition: Matrix_HermPacked.cxx:133
Seldon::Matrix_HermPacked
Hermitian packed matrix class.
Definition: Matrix_HermPacked.hxx:38
Seldon::Matrix_HermPacked::operator=
Matrix_HermPacked< T, Prop, Storage, Allocator > & operator=(const Matrix_HermPacked< T, Prop, Storage, Allocator > &A)
Duplicates a matrix (assignment operator).
Definition: Matrix_HermPackedInline.cxx:238
Seldon::Matrix_HermPacked::Val
reference Val(int i, int j)
Direct access method.
Definition: Matrix_HermPackedInline.cxx:126
Seldon::Matrix
Definition: SeldonHeader.hxx:226
Seldon::Matrix< T, Prop, ColHermPacked, Allocator >
Column-major hermitian packed matrix class.
Definition: Matrix_HermPacked.hxx:160
Seldon::Matrix_HermPacked::Print
void Print() const
Displays the matrix on the standard output.
Definition: Matrix_HermPacked.cxx:323
Seldon::Matrix_HermPacked::GetDataSize
long GetDataSize() const
Returns the number of elements stored in memory.
Definition: Matrix_HermPackedInline.cxx:68
Seldon::Matrix_HermPacked::operator()
const value_type operator()(int i, int j) const
Access operator.
Definition: Matrix_HermPackedInline.cxx:99
Seldon::Matrix< T, Prop, RowHermPacked, Allocator >
Row-major hermitian packed matrix class.
Definition: Matrix_HermPacked.hxx:189
Seldon::Matrix_HermPacked::Copy
void Copy(const Matrix_HermPacked< T, Prop, Storage, Allocator > &A)
Duplicates a matrix.
Definition: Matrix_HermPackedInline.cxx:271
Seldon::Matrix_HermPacked::Clear
void Clear()
Clears the matrix.
Definition: Matrix_HermPacked.cxx:89
Seldon::Matrix_HermPacked::Read
void Read(string FileName)
Reads the matrix from a file.
Definition: Matrix_HermPacked.cxx:529
Seldon::ColHermPacked
Definition: Storage.hxx:218
Seldon::Matrix_HermPacked::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_HermPacked.cxx:192
Seldon::RowHermPacked
Definition: Storage.hxx:229
Seldon::Matrix_HermPacked::SetIdentity
void SetIdentity()
Sets the matrix to the identity.
Definition: Matrix_HermPacked.cxx:239
Seldon::Matrix_HermPacked::GetMemorySize
size_t GetMemorySize() const
Returns size of A in bytes used to store the matrix.
Definition: Matrix_HermPackedInline.cxx:76
Seldon::Matrix_HermPacked::Get
reference Get(int i, int j)
Returns access to an element (i, j)
Definition: Matrix_HermPackedInline.cxx:169
Seldon::Matrix_HermPacked::WriteText
void WriteText(string FileName) const
Writes the matrix in a file.
Definition: Matrix_HermPacked.cxx:460
Seldon::Matrix_HermPacked::ReadText
void ReadText(string FileName)
Reads the matrix from a file.
Definition: Matrix_HermPacked.cxx:593
Seldon::Matrix_HermPacked::~Matrix_HermPacked
~Matrix_HermPacked()
Destructor.
Definition: Matrix_HermPackedInline.cxx:52
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::Matrix_HermPacked::FillRand
void FillRand()
Fills the matrix randomly.
Definition: Matrix_HermPacked.cxx:305
Seldon::Matrix_HermPacked::Fill
void Fill()
Fills the matrix with 0, 1, 2, ...
Definition: Matrix_HermPacked.cxx:258
Seldon::Matrix_HermPacked::Write
void Write(string FileName) const
Writes the matrix in a file.
Definition: Matrix_HermPacked.cxx:390
Seldon::Matrix_HermPacked::operator[]
reference operator[](int i)
Access to elements of the data array.
Definition: Matrix_HermPackedInline.cxx:198