Kronecker product of matrices

Hello, let
A_i=\begin{bmatrix} a_i & b_i \\ c_i & d_i \end{bmatrix}
where i=1,...,5

Is there a way to obtain
C=A_1\otimes A_2\otimes...\otimes A_5,
That is the Kronecker product of matrices? Cheers.

1 Like

No. It may be worth to implement it in Stan (Eigen has a module for it) but it has a large memory footprint even for a matrix of moderate size. Often writing out the product explicitly is not necessary when it’s used as a represention of operations. That being said, in your case it’s probably sufficient to roll a naive implementation in UDF.


You can find code for Kronecker product in Stan language in Section 4.9.5. of State Space Models in Stan by @jrnold

1 Like

Dear @avehtari, I encountered this thread and spotted an error in the section 4.9.5 where

      col_end = (j - 1) * q + 1;

should be

      col_end = (j - 1) * q + q;

and also vdots is not properly displayed.
Thank you.