Skip to content

Commit 30b51e4

Browse files
authored
Merge pull request #691 from pxlxingliang/complexmatrix
test: add the comments and unit test for module_base/complexmatrix.h
2 parents 1a7deae + 4df9983 commit 30b51e4

File tree

3 files changed

+573
-4
lines changed

3 files changed

+573
-4
lines changed

source/module_base/complexmatrix.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,20 @@ class ComplexMatrix
4848
ComplexMatrix& operator*=(const std::complex<double> &s);
4949
ComplexMatrix& operator+=(const ComplexMatrix &m);
5050
ComplexMatrix& operator-=(const ComplexMatrix &m);
51+
//return a matrix whose element is the real part of element of the ComplexMatrix.
5152
matrix real() const; // Peize Lin add 2017-03-29
5253

5354
//==================
5455
// member function:
5556
//==================
57+
//set all elements to be complex<double> {0.0,0.0}
5658
void zero_out(void);
59+
//set to be a unit matrix,
5760
void set_as_identity_matrix(void);
5861

5962
std::ostream & print( std::ostream & os, const double threshold_abs=0.0, const double threshold_imag=0.0 ) const; // Peize Lin add 2021.09.08
6063

64+
// check if all the elements are real
6165
bool checkreal(void);
6266
};
6367

@@ -68,35 +72,47 @@ ComplexMatrix operator*(const std::complex<double> &s, const ComplexMatrix &m);
6872
ComplexMatrix operator*(const ComplexMatrix &m, const std::complex<double> &s);
6973
ComplexMatrix operator*(const double &s, const ComplexMatrix &m);
7074
ComplexMatrix operator*(const ComplexMatrix &m, const double &s);
71-
75+
76+
//calculate the trace
7277
std::complex<double> trace(const ComplexMatrix &m);
7378

74-
double abs2_row(const ComplexMatrix &m,const int ir); // mohan add 2008-7-1
75-
double abs2_column(const ComplexMatrix &m,const int ic); // mohan add 2008-7-1
79+
//calculate the sum of the square of the modulus of the elements in ir row.
80+
double abs2_row(const ComplexMatrix &m,const int ir); // mohan add 2008-7-1
81+
82+
//calculate the sum of the square of the modulus of the elements in ic-th column.
83+
double abs2_column(const ComplexMatrix &m,const int ic); // mohan add 2008-7-1
84+
85+
// calculate the sum of the square of the modulus of all elements.
7686
double abs2(const ComplexMatrix &m);
87+
88+
// calculate the sum of the square of the modulus of all elements of an array of ComplexMatrix.
7789
double abs2(const int nmat, ComplexMatrix **m);
7890

7991
ComplexMatrix transpose(const ComplexMatrix &m, const bool &conjugate);
8092
ComplexMatrix conj(const ComplexMatrix &m); // Peize Lin add 2019-05-13
8193

94+
//do mout += s*min
8295
void scale_accumulate(
8396
const std::complex<double> &s,
8497
const ComplexMatrix &min,
8598
ComplexMatrix &mout);
8699

100+
//do (*mout[i]) += s * (*min[i]); int i<nmat
87101
void scale_accumulate(
88102
const int &nmat,
89103
const std::complex<double> &s,
90104
ComplexMatrix **min,
91105
ComplexMatrix **mout);
92106

107+
// Do mout = s1*m1 + s2*m2
93108
void scaled_sum(
94109
const std::complex<double> &s1,
95110
const ComplexMatrix &m1,
96111
const std::complex<double> &s2,
97112
const ComplexMatrix &m2,
98113
ComplexMatrix &mout);
99114

115+
// Do (*mout[i]) = s1 * (*m1[i]) + s2 * (*m2[i])
100116
void scaled_sum(
101117
const int &nmat,
102118
const std::complex<double> &s1,

source/module_base/test/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,9 @@ AddTest(
3232
AddTest(
3333
TARGET base_integral
3434
SOURCES math_integral_test.cpp ../math_integral.cpp
35-
)
35+
)
36+
AddTest(
37+
TARGET base_complexmatrix
38+
LIBS ${math_libs}
39+
SOURCES complexmatrix_test.cpp ../complexmatrix.cpp ../matrix.cpp
40+
)

0 commit comments

Comments
 (0)