How to calculate the transpose of external, row major matrix in eigen

人走茶凉 提交于 2019-12-24 08:38:33

问题


Having an external, row-major matrix A(m x n), and having already created the external, row-major matrix B(n x m) for the result, for getting the transpose I do:

Map<MatrixXd,RowMajor> (B,n,m) = Map<MatrixXd,RowMajor> (A,m,n).transpose()

where A and B point to the data buffers. This works fine in the default case of col-major matrices, but for row-major matrices the result is correct only for m == n, for m <> n the numbers are skewed up. Am I misinterpreting how to map row-major external data?


回答1:


The second template argument of Map is for alignment control. The row-major layout must be specified through the matrix type:

typedef Matrix<double,Dynamic,Dynamic,RowMajor> RowMajorMatrixXd;
Map<RowMajorMatrixXd>(B,n,m) = Map<RowMajorMatrixXd>(A,m,n).transpose() 


来源:https://stackoverflow.com/questions/40188947/how-to-calculate-the-transpose-of-external-row-major-matrix-in-eigen

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!