I have a sparse matrix A
in Eigen C++. Now I want to symmetrize it to another sparse matrix Asym
:
I was hoping that it would be as simple as:
Eigen::SparseMatrix<FLOATDATA> A;
...
Eigen::SparseMatrix<FLOATDATA> Asym = 0.5*(A+A.transpose()); // error here
But due to obvious reasons, it gives the following assert failure error:
error: static assertion failed: THE_STORAGE_ORDER_OF_BOTH_SIDES_MUST_MATCH
My question is how to neatly do the above operation in Eigen C++?
The easiest way to make your code compile is to evaluate the transposed matrix into a temporary of the correct storage order: