[英]Re-insertion of sparse matrix of Eigen library
I have used sparse matrix of Eigen library in my c++ code. 我在我的C ++代码中使用了Eigen库的稀疏矩阵。 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)).
在此迭代开始之前,我初始化了一个定义的稀疏矩阵(S是线性方程式的系数矩阵(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:
但是,当我使用“ S.insert(ii,ii)= new_value”执行此操作时,它将返回此错误:
...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... 断言`(p <= startId || m_data.index(p-1)!= inner)&&“您不能插入已经存在的元素,必须为此调用coeffRef””失败...
How can I do this re-insertion correctly? 如何正确重新插入?
I found the correct way in the Eigen library quick reference pages. 我在Eigen库快速参考页中找到了正确的方法。 I must use "S.coeffRef(ii,ii)=new_value" instead of "S.insert(ii,ii)=new_value".
我必须使用“ S.coeffRef(ii,ii)= new_value”而不是“ S.insert(ii,ii)= new_value”。 It says :"insert() assumes that the element does not already exist; otherwise, use coeffRef()".
它说:“ insert()假定该元素尚不存在;否则,使用coeffRef()”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.