Registered Member
|
Hello,
I am new to Eigen and have been experimenting with the triangular view in parts of my code and I am a little surprised at the time it takes to compute a triangular part compared to the full matrix. I came with the following example:
leading to this output:
I can buy that my example does not really make sense on small matrices. However, for larger matrices, I am confused to see that computing the upper triangular part of M1^t*M1 leads to a time benefit close to what is expected (over computing the full result), when it does not for M1^t*M2 + M2^t*M1. Am I missing something fundamental here? I am running Eigen 3.0, GCC 4.1.2 (Redhat 4.1.2-50) and compiling with -O3 and -msse2 Thanks! |
Moderator
|
this is because the products have to be evaluated into temporaries thus discarding the efficient triangular = general_matrix_matrix_product path. For best efficiency you should write:
S1.triangularView<Eigen::Upper>() = M1.transpose()*M2; S1.triangularView<Eigen::Upper>() += M2.transpose()*M1; In the future we should be able to do such expression level optimization for you, but currently you have to understand that matrix products are a bit special and it is better to write expressions containing no more than a single matrix product. Here is an updated benchmark:
|
Registered Member
|
I effectively overlooked that one.
Thanks! |
Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], q.ignora