How to calculate the transpose of external, row ma

2019-07-30 02:26发布

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?

标签: eigen
1条回答
Deceive 欺骗
2楼-- · 2019-07-30 02:45

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() 
查看更多
登录 后发表回答