Registered Member
|
Hi,
What is the most efficient way to compute the Kronecker product of two matrices with Eigen? The code below does the job and seems straightforward for me, but maybe it is not the most efficient approach?
Thanks Frank |
Registered Member
|
Actually, your code is pretty good, it doesn't create an unneeded temporary, and I think that it allows eigen to vectorize (for large enough matrices). You might want to check by adding asm comments as explained in the Eigen FAQ.
Your code has also the merit of reading each entry of m1 only once. Entries of m2 are reread n^2 times but i don't know if there's much to do about it. Remember, if your matrices have fixed size, it's always beneficial to use fixed-size matrix types and the fixed-size variants of block(). If your matrices are guaranteed to be of size nxn with n a multiple of 4, and not too big, then there is room for improvement if you can tell eigen that all packets are aligned so it doesn't need to care about unaligned boundaries.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
For those who may want use this code, there is some mistakes into the loops initializations.
|
Registered users: Bing [Bot], Google [Bot], Sogou [Bot]