What I have is diagonal matrix of type Eigen::MatrixXi
. I need elements on the diagonal to be sorted in ascending order. For example like this:
2 0 0 1 0 0
0 7 0 >>> 0 2 0
0 0 1 0 0 7
I thought I would simply do:
std::sort(matrix.diagonal().begin(), matrix.diagonal().end());
But apparently Eigen::Diagonal
does not have begin nor end function. So the question is, is there any way of sorting elements on diagonal using internal std::sort or anything similarly elegant?
I went through official documentation but did not find anything useful.
diagonal_iterator begin(Eigen::Diagonal& d)
anddiagonal_iterator end(Eigen::Diagonal& d)
. Then callstd::sort(begin(matrix.diagonal()), end(matrix.diagonal())
– Biauriculate