How to calculate the transpose of external, row ma

2019-07-30 02:15发布

问题:

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() 


标签: eigen