Hi Adrien,
thanks for the quick answer!
As you said, there are workarounds but I have a library which has an
Eigen type as its basic storage. Its actually a template<typename
MatrixType> and I have use cases for Dense, Sparse and (rarely) for
Diagonal matrices. So I would need to handle all these workaround cases
with a if constexpr() to be able to compile the code for the different
matrix types. Thus, it would be more convenient if at least the most
common operations are present for DiagonalMatrix.
Best regards,
Matthias
On 10/20/20 10:15 AM, Adrien Escande wrote:
Hi Matthias,
I can't be sure of the real reasons for that, but my take is that:
- the methods you are referring to are not meaningful at the level of
the common base class for DiagonalMatrix and Matrix (i.e. EigenBase),
so they are not implemented there and DiagonalMatrix does not inherit them
- there are easy workarounds to achieve the same goal, that are
usually as efficient as a special implementation would be.
In your case, you can achieve what you want with:
DiagonalMatrix<double, Dynamic> M(10);
M.diagonal().setOnes();
std::cout << M.toDenseMatrix() << std::endl;
Idem for M.diagonal().setRandom()
Best regards,
Adrien
On Tue, Oct 20, 2020 at 4:38 PM Matthias Peschke
<[email protected]
<mailto:[email protected]>> wrote:
I recently start using the type Eigen::DiagonalMatrix but it seems
that
some methods for this type are missing. This includes the stream
operator which is not present so that the following does not compile:
Eigen::DiagonalMatrix<double,-1> M(10); M.setIdentity();
std::cout << M << std::endl;
Another example is setRandom() which is not implemented and there
are no
block operations present.
Is there a special reason for this or it is because
Eigen::DiagonalMatrix is rarely used?
Best regards,
Matthias