v2DM-DOCI  1.0
helpers.h
Go to the documentation of this file.
1 /* Copyright (C) 2014 Ward Poelmans
2 
3  This file is part of Hubbard-GPU.
4 
5  Hubbard-GPU is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  Hubbard-GPU is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with Hubbard-GPU. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef HELPER_MATRIX_H
20 #define HELPER_MATRIX_H
21 
22 #include <memory>
23 #include <complex>
24 
25 namespace helpers {
26 
31 class matrix
32 {
33  public:
34  matrix();
35 
36  matrix(int n_, int m_);
37 
38  matrix(const matrix &orig);
39 
40  matrix(matrix &&orig);
41 
42  virtual ~matrix() { }
43 
44  matrix& operator=(const matrix &orig);
45 
46  matrix& operator=(double val);
47 
48  int getn() const;
49 
50  int getm() const;
51 
52  double operator()(int x,int y) const;
53 
54  double& operator()(int x,int y);
55 
56  double& operator[](int x);
57 
58  double operator[](int x) const;
59 
60  double* getpointer() const;
61 
62  matrix& prod(matrix const &A, matrix const &B);
63 
64  std::unique_ptr<double []> svd();
65 
66  std::unique_ptr<double []> sym_eig();
67 
68  void Print() const;
69 
70  double trace() const;
71 
72  void SaveToFile(std::string filename) const;
73 
74  void ReadFromFile(std::string filename) const;
75 
76  private:
78  std::unique_ptr<double []> mat;
80  int n;
82  int m;
83 };
84 
89 class cmatrix
90 {
91  public:
92  cmatrix();
93 
94  cmatrix(int n_, int m_);
95 
96  cmatrix(const cmatrix &orig);
97 
98  cmatrix(cmatrix &&orig);
99 
100  virtual ~cmatrix() { }
101 
102  cmatrix& operator=(const cmatrix &orig);
103 
104  cmatrix& operator=(std::complex<double> val);
105 
106  int getn() const;
107 
108  int getm() const;
109 
110  std::complex<double> operator()(int x,int y) const;
111 
112  std::complex<double>& operator()(int x,int y);
113 
114  std::complex<double>& operator[](int x);
115 
116  std::complex<double> operator[](int x) const;
117 
118  std::complex<double>* getpointer() const;
119 
120  matrix& prod(cmatrix const &A, cmatrix const &B);
121 
122  void Print() const;
123 
124  private:
126  std::unique_ptr<std::complex<double> []> mat;
128  int n;
130  int m;
131 };
132 
133 template<typename T>
134 class tmatrix
135 {
136  public:
137  tmatrix();
138 
139  tmatrix(int n_, int m_);
140 
141  tmatrix(const tmatrix<T> &orig);
142 
143  tmatrix(tmatrix<T> &&orig);
144 
145  virtual ~tmatrix() { }
146 
147  tmatrix<T>& operator=(const tmatrix<T> &orig);
148 
149  tmatrix<T>& operator=(T val);
150 
151  unsigned int getn() const;
152 
153  unsigned int getm() const;
154 
155  T operator()(int x,int y) const;
156 
157  T& operator()(int x,int y);
158 
159  T& operator[](int x);
160 
161  T operator[](int x) const;
162 
163  T* getpointer() const;
164 
165  void Print() const;
166 
167  private:
169  std::unique_ptr<T []> mat;
171  unsigned int n;
173  unsigned int m;
174 };
175 
176 }
177 
178 #endif /* HELPER_MATRIX_H */
179 
180 /* vim: set ts=8 sw=4 tw=0 expandtab :*/
cmatrix & operator=(const cmatrix &orig)
Definition: helpers.cpp:380
void SaveToFile(std::string filename) const
Definition: helpers.cpp:246
matrix & operator=(const matrix &orig)
Definition: helpers.cpp:83
tmatrix< T > & operator=(const tmatrix< T > &orig)
Definition: helpers.cpp:503
void ReadFromFile(std::string filename) const
Definition: helpers.cpp:291
int getm() const
Definition: helpers.cpp:412
void Print() const
Definition: helpers.cpp:228
int getn() const
Definition: helpers.cpp:107
T & operator[](int x)
Definition: helpers.cpp:558
int getm() const
Definition: helpers.cpp:115
matrix & prod(matrix const &A, matrix const &B)
Definition: helpers.cpp:154
void Print() const
Definition: helpers.cpp:446
unsigned int getn() const
Definition: helpers.cpp:529
std::unique_ptr< double[]> mat
n by m array of double
Definition: helpers.h:78
unsigned int m
number of columns
Definition: helpers.h:173
virtual ~cmatrix()
Definition: helpers.h:100
std::unique_ptr< double[]> svd()
Definition: helpers.cpp:173
int n
number of rows
Definition: helpers.h:80
matrix & prod(cmatrix const &A, cmatrix const &B)
std::complex< double > & operator[](int x)
Definition: helpers.cpp:429
std::complex< double > operator()(int x, int y) const
Definition: helpers.cpp:417
int m
number of columns
Definition: helpers.h:130
std::unique_ptr< double[]> sym_eig()
Definition: helpers.cpp:206
std::unique_ptr< std::complex< double >[]> mat
n by m array of complex
Definition: helpers.h:126
int n
number of rows
Definition: helpers.h:128
std::unique_ptr< T[]> mat
n by m array of double
Definition: helpers.h:169
void Print() const
Definition: helpers.cpp:578
virtual ~matrix()
Definition: helpers.h:42
double operator()(int x, int y) const
Definition: helpers.cpp:120
double & operator[](int x)
Definition: helpers.cpp:132
T operator()(int x, int y) const
Definition: helpers.cpp:544
virtual ~tmatrix()
Definition: helpers.h:145
int m
number of columns
Definition: helpers.h:82
T * getpointer() const
Definition: helpers.cpp:572
unsigned int getm() const
Definition: helpers.cpp:538
double trace() const
Definition: helpers.cpp:235
std::complex< double > * getpointer() const
Definition: helpers.cpp:441
double * getpointer() const
Definition: helpers.cpp:144
unsigned int n
number of rows
Definition: helpers.h:171
int getn() const
Definition: helpers.cpp:404