I have a vector of integers and I want to build a diagonal matrix with the vectos element as the diagonal elements of the matrix. For example: if the vector is 1 2 3 , the diagonal matrix will be:
1 0 0 0 2 0 0 0 3
The naive way to do this is to simply iterate over it and set the elements one by one. There is no other direct way to do this in eigen . In addition, after constructing the diagonal, I want to calculate the inversion (which simply changes the diagonal entries), but there seems to be no way to do this either (directly, which would also be optimized) in the library itself.
I looked through the documentation of diagonal matrices in the eigen library, but it seems that there is no way. If I missed something obvious while reading the documentation, please indicate.
Any help was appreciated.
source share