Skip to content

Commit 1ceca51

Browse files
authored
Merge pull request #660 from pxlxingliang/matix
Fix: assertion bug in class matrix
2 parents 0be11cb + e35c936 commit 1ceca51

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
@@ -166,7 +166,7 @@ void matrix::create( const int nrow, const int ncol, const bool flag_zero )
166166
matrix operator+(const matrix &m1, const matrix &m2)
167167
{
168168
assert(m1.nr == m2.nr);
169-
assert(m2.nc == m2.nc);
169+
assert(m1.nc == m2.nc);
170170

171171
matrix tm(m1);
172172
const int size = m1.nr*m1.nc;
@@ -179,7 +179,7 @@ matrix operator+(const matrix &m1, const matrix &m2)
179179
matrix operator-(const matrix &m1, const matrix &m2)
180180
{
181181
assert(m1.nr == m2.nr);
182-
assert(m2.nc == m2.nc);
182+
assert(m1.nc == m2.nc);
183183

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

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

0 commit comments

Comments
 (0)