Skip to content

Commit e35c936

Browse files
committed
fix bug: assert bug in class matrix
. wrong assert in operator +/- fcuntion of class matrix . add assert in function trace_on range: module_base/matrix.cpp
1 parent 958a190 commit e35c936

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

source/module_base/matrix.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ void matrix::create( const int nrow, const int ncol, const bool flag_zero )
165165
matrix operator+(const matrix &m1, const matrix &m2)
166166
{
167167
assert(m1.nr == m2.nr);
168-
assert(m2.nc == m2.nc);
168+
assert(m1.nc == m2.nc);
169169

170170
matrix tm(m1);
171171
const int size = m1.nr*m1.nc;
@@ -178,7 +178,7 @@ matrix operator+(const matrix &m1, const matrix &m2)
178178
matrix operator-(const matrix &m1, const matrix &m2)
179179
{
180180
assert(m1.nr == m2.nr);
181-
assert(m2.nc == m2.nc);
181+
assert(m1.nc == m2.nc);
182182

183183
matrix tm(m1);
184184
const int size = m1.nr*m1.nc;
@@ -345,6 +345,9 @@ void matrix::reshape( const double nr_new, const double nc_new )
345345

346346
double trace_on(const matrix &A, const matrix &B)
347347
{
348+
assert(A.nr == B.nc);
349+
assert(A.nc == B.nr);
350+
348351
double tr = 0.0;
349352
for (int i = 0; i < A.nr; ++i)
350353
for (int k = 0; k < A.nc; ++k)

0 commit comments

Comments
 (0)