fix sparse matrix error