ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
matrix.h
Go to the documentation of this file.
1#ifndef MATRIX_H
2#define MATRIX_H
3
4// Peize Lin update 2018-07-29
5
6#include <ostream>
7#include<cassert>
8
9#include <fstream> // test
10
11namespace ModuleBase
12{
13
14class matrix
15{
16 /* data */
17public:
18
19 int nr=0;
20 int nc=0; /* Number of rows and columns */
21 double *c=nullptr; /* Holds the data */
22
23 /* Constructors and destructor */
24 matrix(): nr(0), nc(0), c(nullptr){}
25 matrix( const int nrows, const int ncols, const bool flag_zero=true ); // Peize Lin add flag_zero 2018-07-02
26 matrix( const matrix &m1 ); /* copy constructor */
27 matrix( matrix && m1 ); // Peize Lin add 2016-08-05
28 ~matrix();
29
30 void create( const int nrow, const int ncol, const bool flag_zero=true ); // Peize Lin add flag_zero 2018-07-02
31 matrix& operator=(const matrix &m1); // Peize Lin change 2018-03-12
32 matrix& operator=( matrix && m1 ); // Peize Lin add 2016-08-05
33
34 double &operator()(const int ir,const int ic)
35 {
36 assert(ir>=0); assert(ir<nr); assert(ic>=0); assert(ic<nc);
37 return c[ir*nc+ic];
38 }
39
40 const double &operator()(const int ir,const int ic) const
41 {
42 assert(ir>=0); assert(ir<nr); assert(ic>=0); assert(ic<nc);
43 return c[ir*nc+ic];
44 }
45
46// inline double &operator()(int i,int j) const
47// { return c[nc*i+j]; }
48
49 void operator*=(const double &s);
50 void operator+=(const matrix &m);
51 void operator-=(const matrix &m);
52
53 /* member function: */
55
56 double det(void);
57
58 // mohan add 2011-01-13
59 double trace_on(void) const;
60
61 /* zero out all the entries */
62 void zero_out(void);
63
64 /* fill all entries with number */
65 void fill_out(const double x);
66
67 void get_extreme_eigen_values(double &ev_lower, double &ev_upper) const; // mohan add 2011-01-13
68
69 void reshape( const int nr_new, const int nc_new, const bool flag_zero = true ); // Peize Lin add 2017-05-27
70
71 double max() const; // Peize Lin add 2016-09-08
72 double min() const; // Peize Lin add 2016-09-08
73 double absmax() const; // Peize Lin add 2018-07-02
74
75 double norm() const; // Peize Lin add 2018-08-12
76
77 std::ostream & print( std::ostream & os, const double threshold=0.0 ) const; // Peize Lin add 2021.09.08
78
79 using type=double; // Peize Lin add 2022.08.08 for template
80};
81
82matrix operator-(const matrix& m1); // unary minus
83matrix operator+(const matrix &m1, const matrix &m2);
84matrix operator-(const matrix &m1, const matrix &m2);
85matrix operator*(const matrix &m1, const matrix &m2);
86matrix operator*(const double &s, const matrix &m);
87matrix operator*(const matrix &m, const double &s);
88
89matrix transpose(const matrix &m);
90double trace_on(const matrix &A, const matrix &B); // mohan add 2011-01-13
91double mdot(const matrix &A, const matrix &B); // mohan add 2011-01-13
92
93//std::ostream & operator<<( std::ostream & os, const matrix & m ); // Peize Lin add 2016-09-08
94
95}
96
97#endif // MATRIX_H
Definition matrix.h:15
~matrix()
Definition matrix.cpp:118
void zero_out(void)
Definition matrix.cpp:312
matrix()
Definition matrix.h:24
void reshape(const int nr_new, const int nc_new, const bool flag_zero=true)
Definition matrix.cpp:358
int nr
Definition matrix.h:19
double * c
Definition matrix.h:21
double trace_on(void) const
Definition matrix.cpp:344
std::ostream & print(std::ostream &os, const double threshold=0.0) const
Definition matrix.cpp:412
int nc
Definition matrix.h:20
matrix & operator=(const matrix &m1)
Definition matrix.cpp:76
void operator-=(const matrix &m)
Definition matrix.cpp:295
double absmax() const
Definition matrix.cpp:451
void operator+=(const matrix &m)
Definition matrix.cpp:277
double type
Definition matrix.h:79
double norm() const
Definition matrix.cpp:462
matrix Inverse(void)
double max() const
Definition matrix.cpp:429
double & operator()(const int ir, const int ic)
Definition matrix.h:34
void get_extreme_eigen_values(double &ev_lower, double &ev_upper) const
double det(void)
double min() const
Definition matrix.cpp:439
void fill_out(const double x)
Definition matrix.cpp:324
const double & operator()(const int ir, const int ic) const
Definition matrix.h:40
void create(const int nrow, const int ncol, const bool flag_zero=true)
Definition matrix.cpp:131
void operator*=(const double &s)
Definition matrix.cpp:269
Definition clebsch_gordan_coeff.cpp:8
double trace_on(const matrix &A, const matrix &B)
Definition matrix.cpp:367
ComplexMatrix operator-(const ComplexMatrix &m1, const ComplexMatrix &m2)
Definition complexmatrix.cpp:154
ComplexArray operator*(const double r, const ComplexArray &cd)
Scale a ComplexArray cd by real r.
Definition complexarray.cpp:173
ComplexMatrix transpose(const ComplexMatrix &m, const bool &conjugate)
Definition complexmatrix.cpp:394
ComplexMatrix operator+(const ComplexMatrix &m1, const ComplexMatrix &m2)
Definition complexmatrix.cpp:143
double mdot(const matrix &A, const matrix &B)
Definition matrix.cpp:379
#define threshold
Definition sph_bessel_rec_test.cpp:4