DOCI-Exact  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 MATRIX_H
20 #define MATRIX_H
21 
22 #include <iostream>
23 #include <memory>
24 #include <vector>
25 #include <cstring>
26 #include <assert.h>
27 
32 namespace helpers {
33 
38 class matrix
39 {
40  public:
41  matrix();
42 
43  matrix(int n_, int m_);
44 
45  matrix(const matrix &orig);
46 
47  matrix(matrix &&orig);
48 
49  virtual ~matrix() { }
50 
51  matrix& operator=(const matrix &orig);
52 
53  matrix& operator=(double val);
54 
55  matrix& operator+=(const matrix &orig);
56 
57  matrix& operator-=(const matrix &orig);
58 
59  int getn() const;
60 
61  int getm() const;
62 
63  double operator()(int x,int y) const;
64 
65  double& operator()(int x,int y);
66 
67  double& operator[](int x);
68 
69  double operator[](int x) const;
70 
71  double* getpointer() const;
72 
73  matrix& prod(matrix const &A, matrix const &B);
74 
75  std::unique_ptr<double []> svd();
76 
77  void mvprod(const double *x, double *y, double beta) const;
78 
79  void Print() const;
80 
81  double trace() const;
82 
83  std::vector<double> GetColumn(unsigned int) const;
84 
85  const double* GetColumnRaw(unsigned int idx) const;
86 
87  void SaveToFile(std::string filename) const;
88 
89  void ReadFromFile(std::string filename) const;
90 
91  private:
93  std::unique_ptr<double []> mat;
95  int n;
97  int m;
98 };
99 
100 }
101 
102 #endif /* MATRIX_H */
103 
104 /* vim: set ts=8 sw=4 tw=0 expandtab :*/
void SaveToFile(std::string filename) const
Definition: helpers.cpp:280
matrix & operator=(const matrix &orig)
Definition: helpers.cpp:82
void ReadFromFile(std::string filename) const
Definition: helpers.cpp:325
void Print() const
Definition: helpers.cpp:233
int getn() const
Definition: helpers.cpp:128
int getm() const
Definition: helpers.cpp:136
matrix & prod(matrix const &A, matrix const &B)
Definition: helpers.cpp:175
const double * GetColumnRaw(unsigned int idx) const
Definition: helpers.cpp:272
std::unique_ptr< double[]> svd()
Definition: helpers.cpp:194
std::vector< double > GetColumn(unsigned int) const
Definition: helpers.cpp:255
virtual ~matrix()
Definition: helpers.h:49
double operator()(int x, int y) const
Definition: helpers.cpp:141
double & operator[](int x)
Definition: helpers.cpp:153
double trace() const
Definition: helpers.cpp:240
double * getpointer() const
Definition: helpers.cpp:165
matrix & operator-=(const matrix &orig)
Definition: helpers.cpp:114
matrix & operator+=(const matrix &orig)
Definition: helpers.cpp:103
void mvprod(const double *x, double *y, double beta) const
Definition: helpers.cpp:223