Adding a diagonal matrix to a sparse matrix causes assertion failed
Submitted by tar..@..ok.com
Assigned to Nobody
Link to original bugzilla bug (#1574)
Version: 3.4 (development)
Description
I am not able to convert a diagonal matrix to sparse matrix. Nor can I add a diagonal matrix to sparse matrix.
For example, the code:
#include <Eigen/Dense>
#include <Eigen/Sparse>
int main() {
int n = 10;
SparseMatrix<double> A(n, n);
A += VectorXd::Ones(n).asDiagonal();
}
The program stopped and outputs
Assertion failed: p!=Dynamic && "written coefficient does not exist", file path\to\eigen\src\sparsecore\sparsecompressedbase.h, line 312
This problem exists both in Version 3.3 and in git head (currently 991ece51446ebb9214393bed838879536c800fe2). The compiler used is Microsoft Visual Studio.
I am also surprised that I cannot find a method to view a diagonal matrix as a sparse matrix (method sparseView does not exist). In my opinion, viewing a triangular matrix as a sparse matrix should be trivial (at least simpler than viewing a dense matrix as a sparse matrix).
If that is not a bug, how could I update the diagonal of a sparse matrix, given that the coefficients at diagonal does not exist?