Matrix_TriangPacked.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_TRIANGPACKED_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_TriangPacked: 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  // Attributes.
52  protected:
53 
54  // Methods.
55  public:
56  // Constructor.
58  explicit Matrix_TriangPacked(int i, int j = 0);
59  Matrix_TriangPacked(const Matrix_TriangPacked<T, Prop, Storage,
60  Allocator>& A);
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 
75  // Element access and affectation.
76  const value_type operator() (int i, int j) const;
77  reference Val(int i, int j);
78  const_reference Val(int i, int j) const;
79  reference Get(int i, int j);
80  const_reference Get(int i, int j) const;
81  reference operator[] (int i);
82  const_reference operator[] (int i) const;
85  void Set(int i, int j, const T& x);
87 
88  // Convenient functions.
89  void Zero();
90  void SetIdentity();
91  void Fill();
92  template <class T0>
93  void Fill(const T0& x);
94  template <class T0>
96  void FillRand();
97  void Print() const;
98  void Print(int a, int b, int m, int n) const;
99  void Print(int l) const;
100 
101  // Input/output functions.
102  void Write(string FileName) const;
103  void Write(ostream& FileStream) const;
104  void WriteText(string FileName) const;
105  void WriteText(ostream& FileStream) const;
106  void Read(string FileName);
107  void Read(istream& FileStream);
108  void ReadText(string FileName);
109  void ReadText(istream& FileStream);
110 
111 #ifdef SELDON_WITH_VIRTUAL
112  typedef typename ClassComplexType<T>::Treal Treal;
113  typedef typename ClassComplexType<T>::Tcplx Tcplx;
114 
115  virtual void MltAddVector(const Treal& alpha, const Vector<Treal>& x,
116  const Treal& beta, Vector<Treal>& y) const;
117 
118  virtual void MltAddVector(const Tcplx& alpha, const Vector<Tcplx>& x,
119  const Tcplx& beta, Vector<Tcplx>& y) const;
120 
121  virtual void MltAddVector(const Treal& alpha, const SeldonTranspose&,
122  const Vector<Treal>& x,
123  const Treal& beta, Vector<Treal>& y) const;
124 
125  virtual void MltAddVector(const Tcplx& alpha, const SeldonTranspose&,
126  const Vector<Tcplx>& x,
127  const Tcplx& beta, Vector<Tcplx>& y) const;
128 
129  virtual void MltVector(const Vector<Treal>& x, Vector<Treal>& y) const;
130  virtual void MltVector(const Vector<Tcplx>& x, Vector<Tcplx>& y) const;
131 
132  virtual void MltVector(const SeldonTranspose&,
133  const Vector<Treal>& x, Vector<Treal>& y) const;
134 
135  virtual void MltVector(const SeldonTranspose&,
136  const Vector<Tcplx>& x, Vector<Tcplx>& y) const;
137 
138  virtual bool IsSymmetric() const;
139 #endif
140 
141  };
142 
143 
145  template <class T, class Prop, class Allocator>
146  class Matrix<T, Prop, ColUpTriangPacked, Allocator>:
147  public Matrix_TriangPacked<T, Prop, ColUpTriangPacked, Allocator>
148  {
149  // typedef declaration.
150  public:
151  typedef typename Allocator::value_type value_type;
152  typedef Prop property;
153  typedef ColUpTriangPacked storage;
154  typedef Allocator allocator;
155 
156  public:
157  Matrix();
158  explicit Matrix(int i, int j = 0);
159  void Resize(int i, int j);
160 
161  template <class T0>
162  Matrix<T, Prop, ColUpTriangPacked, Allocator>& operator= (const T0& x);
165  template <class T0>
166  Matrix<T, Prop, ColUpTriangPacked, Allocator>& operator*= (const T0& x);
167  };
168 
169 
171  template <class T, class Prop, class Allocator>
172  class Matrix<T, Prop, ColLoTriangPacked, Allocator>:
173  public Matrix_TriangPacked<T, Prop, ColLoTriangPacked, Allocator>
174  {
175  // typedef declaration.
176  public:
177  typedef typename Allocator::value_type value_type;
178  typedef Prop property;
179  typedef ColLoTriangPacked storage;
180  typedef Allocator allocator;
181 
182  public:
183  Matrix();
184  Matrix(int i, int j = 0);
185  void Resize(int i, int j);
186 
187  template <class T0>
188  Matrix<T, Prop, ColLoTriangPacked, Allocator>& operator= (const T0& x);
191  template<class T0>
192  Matrix<T, Prop, ColLoTriangPacked, Allocator>& operator*= (const T0& x);
193  };
194 
195 
197  template <class T, class Prop, class Allocator>
198  class Matrix<T, Prop, RowUpTriangPacked, Allocator>:
199  public Matrix_TriangPacked<T, Prop, RowUpTriangPacked, Allocator>
200  {
201  // typedef declaration.
202  public:
203  typedef typename Allocator::value_type value_type;
204  typedef Prop property;
205  typedef RowUpTriangPacked storage;
206  typedef Allocator allocator;
207 
208  public:
209  Matrix();
210  explicit Matrix(int i, int j = 0);
211  void Resize(int i, int j);
212 
213  template <class T0>
214  Matrix<T, Prop, RowUpTriangPacked, Allocator>& operator= (const T0& x);
217  template<class T0>
218  Matrix<T, Prop, RowUpTriangPacked, Allocator>& operator*= (const T0& x);
219  };
220 
221 
223  template <class T, class Prop, class Allocator>
224  class Matrix<T, Prop, RowLoTriangPacked, Allocator>:
225  public Matrix_TriangPacked<T, Prop, RowLoTriangPacked, Allocator>
226  {
227  // typedef declaration.
228  public:
229  typedef typename Allocator::value_type value_type;
230  typedef Prop property;
231  typedef RowLoTriangPacked storage;
232  typedef Allocator allocator;
233 
234  public:
235  Matrix();
236  explicit Matrix(int i, int j = 0);
237  void Resize(int i, int j);
238 
239  template <class T0>
240  Matrix<T, Prop, RowLoTriangPacked, Allocator>& operator= (const T0& x);
243  template<class T0>
244  Matrix<T, Prop, RowLoTriangPacked, Allocator>& operator*= (const T0& x);
245  };
246 
247 
248 } // namespace Seldon.
249 
250 #define SELDON_FILE_MATRIX_TRIANGPACKED_HXX
251 #endif
Seldon::Matrix_TriangPacked::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_TriangPacked.cxx:190
Seldon::SeldonTranspose
Definition: MatrixFlag.hxx:32
Seldon::Matrix_Base
Base class for all matrices.
Definition: Matrix_Base.hxx:143
Seldon::Matrix_TriangPacked::Zero
void Zero()
Sets all elements to zero.
Definition: Matrix_TriangPacked.cxx:228
Seldon::Matrix_TriangPacked::WriteText
void WriteText(string FileName) const
Writes the matrix in a file.
Definition: Matrix_TriangPacked.cxx:476
Seldon::Matrix_TriangPacked::GetMemorySize
size_t GetMemorySize() const
Returns size of A in bytes used to store the matrix.
Definition: Matrix_TriangPackedInline.cxx:77
Seldon::Vector< Treal >
Seldon::Matrix_TriangPacked::Val
reference Val(int i, int j)
Direct access method.
Definition: Matrix_TriangPackedInline.cxx:137
Seldon::Matrix_TriangPacked::operator=
Matrix_TriangPacked< T, Prop, Storage, Allocator > & operator=(const Matrix_TriangPacked< T, Prop, Storage, Allocator > &A)
Duplicates a matrix (assignment operator).
Definition: Matrix_TriangPackedInline.cxx:265
Seldon::Matrix_TriangPacked::Nullify
void Nullify()
Clears the matrix without releasing memory.
Definition: Matrix_TriangPacked.cxx:209
Seldon::Matrix_TriangPacked::Write
void Write(string FileName) const
Writes the matrix in a file.
Definition: Matrix_TriangPacked.cxx:408
Seldon::Matrix
Definition: SeldonHeader.hxx:226
Seldon::Matrix_TriangPacked::Fill
void Fill()
Fills the matrix with 0, 1, 2, ...
Definition: Matrix_TriangPacked.cxx:282
Seldon::Matrix_TriangPacked::SetIdentity
void SetIdentity()
Sets the matrix to the identity.
Definition: Matrix_TriangPacked.cxx:237
Seldon::Matrix_TriangPacked::Clear
void Clear()
Clears the matrix.
Definition: Matrix_TriangPacked.cxx:88
Seldon::Matrix_TriangPacked::operator()
const value_type operator()(int i, int j) const
Access operator.
Definition: Matrix_TriangPackedInline.cxx:100
Seldon::Matrix_TriangPacked::FillRand
void FillRand()
Fills the matrix randomly.
Definition: Matrix_TriangPacked.cxx:324
Seldon::Matrix_TriangPacked
Triangular packed matrix class.
Definition: Matrix_TriangPacked.hxx:38
Seldon::Matrix< T, Prop, RowUpTriangPacked, Allocator >
Row-major upper-triangular packed matrix class.
Definition: Matrix_TriangPacked.hxx:198
Seldon::RowUpTriangPacked
Definition: Storage.hxx:318
Seldon::Matrix_TriangPacked::Copy
void Copy(const Matrix_TriangPacked< T, Prop, Storage, Allocator > &A)
Duplicates a matrix.
Definition: Matrix_TriangPackedInline.cxx:295
Seldon::Matrix< T, Prop, ColUpTriangPacked, Allocator >
Column-major upper-triangular packed matrix class.
Definition: Matrix_TriangPacked.hxx:146
Seldon::Matrix_TriangPacked::Set
void Set(int i, int j, const T &x)
Sets an element of the matrix.
Definition: Matrix_TriangPackedInline.cxx:281
Seldon::Matrix_TriangPacked::Get
reference Get(int i, int j)
Returns the element (i, j)
Definition: Matrix_TriangPackedInline.cxx:195
Seldon::ColUpTriangPacked
Definition: Storage.hxx:294
Seldon::Matrix_TriangPacked::GetDataSize
long GetDataSize() const
Returns the number of elements stored in memory.
Definition: Matrix_TriangPackedInline.cxx:69
Seldon::Matrix_TriangPacked::Read
void Read(string FileName)
Reads the matrix from a file.
Definition: Matrix_TriangPacked.cxx:545
Seldon::Matrix_TriangPacked::ReadText
void ReadText(string FileName)
Reads the matrix from a file.
Definition: Matrix_TriangPacked.cxx:609
Seldon::Matrix_TriangPacked::~Matrix_TriangPacked
~Matrix_TriangPacked()
Destructor.
Definition: Matrix_TriangPackedInline.cxx:53
Seldon::RowLoTriangPacked
Definition: Storage.hxx:330
Seldon::Matrix_TriangPacked::Print
void Print() const
Displays the matrix on the standard output.
Definition: Matrix_TriangPacked.cxx:341
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::Matrix_TriangPacked::Matrix_TriangPacked
Matrix_TriangPacked()
Default constructor.
Definition: Matrix_TriangPackedInline.cxx:40
Seldon::Matrix< T, Prop, RowLoTriangPacked, Allocator >
Row-major lower-triangular packed matrix class.
Definition: Matrix_TriangPacked.hxx:224
Seldon::ColLoTriangPacked
Definition: Storage.hxx:306
Seldon::Matrix_TriangPacked::Reallocate
void Reallocate(int i, int j)
Reallocates memory to resize the matrix.
Definition: Matrix_TriangPacked.cxx:132
Seldon::Matrix< T, Prop, ColLoTriangPacked, Allocator >
Column-major lower-triangular packed matrix class.
Definition: Matrix_TriangPacked.hxx:172
Seldon::Matrix_TriangPacked::operator[]
reference operator[](int i)
Access to elements of the data array.
Definition: Matrix_TriangPackedInline.cxx:225