本征是否具有像H.transpose()* H的自转置乘法优化 [英] does eigen have self transpose multiply optimization like H.transpose()*H

查看:137
本文介绍了本征是否具有像H.transpose()* H的自转置乘法优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在浏览了本征教程 https://eigen.tuxfamily.org/dox-devel/group__TutorialMatrixArithmetic.html

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

它说 注意:对于担心性能的BLAS用户,诸如c.noalias()-= 2 * a.adjoint()* b;之类的表达式已完全优化,并触发了一个类似于gemm的函数调用."

it said "Note: for BLAS users worried about performance, expressions such as c.noalias() -= 2 * a.adjoint() * b; are fully optimized and trigger a single gemm-like function call."

但是像H.transpose()* H这样的计算又如何呢,因为它的结果是一个对称矩阵,所以它只需要正常A * B的一半时间,但是在我的测试中,H.transpose()* H花费了相同的时间时间为H.transpose()* B.本征对此情况是否有特殊的优化,例如opencv,它具有类似的功能.

but how about computation like H.transpose() * H , because it's result is a symmetric matrix so it should only need half time as normal A*B, but in my test, H.transpose() * H spend same time as H.transpose() * B. does eigen have special optimization for this situation , like opencv, it has similar function.

我知道对称优化会破坏向量化,我只想知道本征是否具有可以同时提供对称优化和向量化的解决方案

I know symmetric optimization will break the vectorization , I just want to know if eigen have solution which could provide both symmetric optimization and vectorization

推荐答案

是的,您需要以这种方式告诉Eigen结果是对称的:

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

最后一行在下三角部分内计算Z += H * H^T.上部保持不变.您需要一个完整的矩阵,然后将下部复制到上部:

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

rankUpdate例程已完全向量化,可与BLAS等效项进行比较.对于较小的矩阵,最好执行完整的产品.

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

另请参见相应的 doc .

这篇关于本征是否具有像H.transpose()* H的自转置乘法优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆