简体   繁体   中英

Re-insertion of sparse matrix of Eigen library

I have used sparse matrix of Eigen library in my c++ code. I have a main iteration in my code. Before the start of this iteration, I initialize a defined sparse matrix (S that is the coefficient matrix of a linear equation(S*x=b)). Some of elements of this matrix must be changed in every iteration. But when I do this using "S.insert(ii,ii)=new_value" it returns this error:

...Assertion `(p<=startId || m_data.index(p-1)!=inner) && "you cannot insert an element that already exist, you must call coeffRef to this end"' failed...

How can I do this re-insertion correctly?

I found the correct way in the Eigen library quick reference pages. I must use "S.coeffRef(ii,ii)=new_value" instead of "S.insert(ii,ii)=new_value". It says :"insert() assumes that the element does not already exist; otherwise, use coeffRef()".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM