1574
2018-07-17 13:25:55 +0000
Adding a diagonal matrix to a sparse matrix causes assertion failed
2019-12-04 17:48:39 +0000
1
1
1
Unclassified
Eigen
Core - general
3.4 (development)
All
All
CONFIRMED
Normal
Crash
---
814
1
taroxd
eigen.nobody
chtz
gael.guennebaud
jacob.benoit.1
oldest_to_newest
7383
0
taroxd
2018-07-17 13:25:55 +0000
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?
7386
1
chtz
2018-07-18 11:41:19 +0000
Not super-urgent, but should be fixable until 3.4.
A similar issue is Bug 610.
7548
2
gael.guennebaud
2018-10-08 21:07:30 +0000
This was on purpose and this limitation is documented:
https://eigen.tuxfamily.org/dox/classEigen_1_1SparseMatrix.html#title16
Removing this limitation is not straightforward regarding the strategy to adopt regarding memory reallocation and copies.
7895
3
gael.guennebaud
2019-01-25 10:52:54 +0000
I implemented an evaluator for Diagonal* so that vec.asDiagonal().sparseView() can work. Sadly, this only works with column-major sparse matrices because mixing row and column major sparse expressions is not allowed, e.g.:
row_major_sparse += vec.asDiagonal().sparseView()
won't work because by default vec.asDiagonal() is seen as column-major expression. This is a pity because here we really don't care about the storage order. This could be handled through a "symmetric" bit flag stating that calling coeff(i,j) or coeff(j,i) is exactly the same.
Actually, we already have a similar problem with sparseView on dense expressions:
row_major_sparse + col_major_dense.sparseView()
is not allowed though it could easily be accomplished as dense expressions can be traversed row-wise or column-wise. Here the fix would be more complicated as the col_major_dense.sparseView() would has to say "can be traversed in both direction", and the iterator should have to be instantiated with the chosen order.
In both cases, that's a lot of internal design changes, so not asDiagonal().sparseView() for 3.4.
7911
4
gael.guennebaud
2019-01-29 08:13:53 +0000
The code is quite sophisticated but it could be reused to implement smarter versions of SparseMatrix's =, +=, -= working in-place if possible.
https://bitbucket.org/eigen/eigen/commits/06d261957e675
10018
5
eigen.nobody
2019-12-04 17:48:39 +0000
-- GitLab Migration Automatic Message --
This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity.
You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/1574.