Registered Member
|
Hello,
I'm trying to compute Tr(AB) efficiently where A, B are Hermitian (self-adjoint) matrices and Tr is the matrix trace. The current code I've got is:
Noting that Tr(AB) = AB_{ii} = A_{ij}B_{ji} = A_{ij}B_{ij}, via Einstein's index convention. I'd like to use this trick since it doesn't use matrix multiplication. Furthermore, I'd like to use the triangularView mechanism to exploit the fact that A and B are Hermitian. I want to sum the lower off-diagonal terms, multiply that by 2, and add the sum of the diagonal terms. How does one go about this? |
Moderator
|
In theory you could write something like:
but reductions on triangular-views are not implemented yet. Note that because of the overhead to vectorize a reduction on a triangular part, speedup would be expected for large matrices only, like larger than 100x100. |
Moderator
|
To get an idea of what could be the speed up, you can try a manual for loop:
Let us know if you get a significant speed up. If so, this might motivate us to implement triangular reductions! |
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]