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#ifdef _MCD_CHECK
7#endif
8
9#include <ostream>
10#include<cassert>
11
12#include <fstream> // test
13
14namespace ModuleBase
15{
16
17class matrix
18{
19 /* data */
20public:
21
22 int nr=0;
23 int nc=0; /* Number of rows and columns */
24 double *c=nullptr; /* Holds the data */
25
26 /* Constructors and destructor */
27 matrix(): nr(0), nc(0), c(nullptr){}
28 matrix( const int nrows, const int ncols, const bool flag_zero=true ); // Peize Lin add flag_zero 2018-07-02
29 matrix( const matrix &m1 ); /* copy constructor */
30 matrix( matrix && m1 ); // Peize Lin add 2016-08-05
31 ~matrix();
32
33 void create( const int nrow, const int ncol, const bool flag_zero=true ); // Peize Lin add flag_zero 2018-07-02
34 matrix& operator=(const matrix &m1); // Peize Lin change 2018-03-12
35 matrix& operator=( matrix && m1 ); // Peize Lin add 2016-08-05
36
37 double &operator()(const int ir,const int ic)
38 {
39 assert(ir>=0); assert(ir<nr); assert(ic>=0); assert(ic<nc);
40 return c[ir*nc+ic];
41 }
42
43 const double &operator()(const int ir,const int ic) const
44 {
45 assert(ir>=0); assert(ir<nr); assert(ic>=0); assert(ic<nc);
46 return c[ir*nc+ic];
47 }
48
49// inline double &operator()(int i,int j) const
50// { return c[nc*i+j]; }
51
52 void operator*=(const double &s);
53 void operator+=(const matrix &m);
54 void operator-=(const matrix &m);
55
56 /* member function: */
58
59 double det(void);
60
61 // mohan add 2011-01-13
62 double trace_on(void) const;
63
64 /* zero out all the entries */
65 void zero_out(void);
66
67 /* fill all entries with number */
68 void fill_out(const double x);
69
70 void get_extreme_eigen_values(double &ev_lower, double &ev_upper) const; // mohan add 2011-01-13
71
72 void reshape( const int nr_new, const int nc_new, const bool flag_zero = true ); // Peize Lin add 2017-05-27
73
74 double max() const; // Peize Lin add 2016-09-08
75 double min() const; // Peize Lin add 2016-09-08
76 double absmax() const; // Peize Lin add 2018-07-02
77
78 double norm() const; // Peize Lin add 2018-08-12
79
80 std::ostream & print( std::ostream & os, const double threshold=0.0 ) const; // Peize Lin add 2021.09.08
81
82 using type=double; // Peize Lin add 2022.08.08 for template
83};
84
85
86matrix operator+(const matrix &m1, const matrix &m2);
87matrix operator-(const matrix &m1, const matrix &m2);
88matrix operator*(const matrix &m1, const matrix &m2);
89matrix operator*(const double &s, const matrix &m);
90matrix operator*(const matrix &m, const double &s);
91
92matrix transpose(const matrix &m);
93double trace_on(const matrix &A, const matrix &B); // mohan add 2011-01-13
94double mdot(const matrix &A, const matrix &B); // mohan add 2011-01-13
95
96//std::ostream & operator<<( std::ostream & os, const matrix & m ); // Peize Lin add 2016-09-08
97
98}
99
100#endif // MATRIX_H
Definition matrix.h:18
~matrix()
Definition matrix.cpp:112
void zero_out(void)
Definition matrix.cpp:296
matrix()
Definition matrix.h:27
void reshape(const int nr_new, const int nc_new, const bool flag_zero=true)
Definition matrix.cpp:342
int nr
Definition matrix.h:22
double * c
Definition matrix.h:24
double trace_on(void) const
Definition matrix.cpp:328
std::ostream & print(std::ostream &os, const double threshold=0.0) const
Definition matrix.cpp:396
int nc
Definition matrix.h:23
matrix & operator=(const matrix &m1)
Definition matrix-inl.h:45
void operator-=(const matrix &m)
Definition matrix.cpp:279
double absmax() const
Definition matrix.cpp:435
void operator+=(const matrix &m)
Definition matrix.cpp:261
double norm() const
Definition matrix.cpp:446
matrix Inverse(void)
double max() const
Definition matrix.cpp:413
double & operator()(const int ir, const int ic)
Definition matrix.h:37
void get_extreme_eigen_values(double &ev_lower, double &ev_upper) const
double det(void)
double min() const
Definition matrix.cpp:423
void fill_out(const double x)
Definition matrix.cpp:308
double type
Definition matrix.h:82
const double & operator()(const int ir, const int ic) const
Definition matrix.h:43
void create(const int nrow, const int ncol, const bool flag_zero=true)
Definition matrix.cpp:125
void operator*=(const double &s)
Definition matrix.cpp:253
Definition clebsch_gordan_coeff.cpp:8
double trace_on(const matrix &A, const matrix &B)
Definition matrix.cpp:351
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:363
#define threshold
Definition sph_bessel_recursive_test.cpp:4