i using eigen project working on, runtime performance absolutely crucial (needs meet real-time constraints).
so far, eigen gives me reasonably performance. however, need evaluate kronecker product. using eigen's unsupported kroneckerproduct module, thinking suboptimal needs.
the 2 matrices computing kronecker product of fixed size (known @ compile time), , structure. 1 matrix square , diagonal, let's assume identity matrix. other small, square matrix. in code, this:
matrixxf = matrixxf::identity(4,4); matrixxf x = matrixxf::random(8,8); matrixxf p = kroneckerproduct(i,x);
since diagonal, guessing can make faster since need evaluate 4 matrix scalar multiplications in order compute of elements (since many zero).
what fastest , efficient way eigen?
in eigen 3.3 beta there (unsupported) support sparse kronecker products. being said, if performance critical, not yet recommend moving 3.3 beta. additionally, if know i
diagonal matrix, better performance writing own. plus, if size known @ compile time (and not large), can replace matrixxf
matrix4f
(fixed size, allocated on stack, not heap). roll , get:
matrix4f i4 = matrix4f::identity(); matrixxf p2(i4.rows() * x.rows(), i4.cols() * x.cols()); p2.setzero(); (int = 0; < i4.rowsatcompiletime; i++) { p2.block(i*x.rows(), i*x.cols(), x.rows(), x.cols()) = i4(i, i) * x; }
Comments
Post a Comment