does eigen have self transpose multiply optimization like H.transpose()*H

后端 未结 1 1873
被撕碎了的回忆
被撕碎了的回忆 2021-01-07 06:22

I have browsed the tutorial of eigen at https://eigen.tuxfamily.org/dox-devel/group__TutorialMatrixArithmetic.html

it said \"Note: for BLAS users worried about per

相关标签:
1条回答
  • 2021-01-07 07:25

    You are right, you need to tell Eigen that the result is symmetric this way:

    Eigen::MatrixXd H = Eigen::MatrixXd::Random(m,n);
    Eigen::MatrixXd Z = Eigen::MatrixXd::Zero(n,n);
    Z.template selfadjointView<Eigen::Lower>().rankUpdate(H.transpose());
    

    The last line computes Z += H * H^T within the lower triangular part. The upper part is left unchanged. You want a full matrix, then copy the lower part to the upper one:

    Z.template triangularView<Eigen::Upper>() = Z.transpose();
    

    This rankUpdate routine is fully vectorized and comparable to the BLAS equivalent. For small matrices, better perform the full product.

    See also the respective doc.

    0 讨论(0)
提交回复
热议问题