Converting arrays of matrices into a matrix

Hi, in a related post [Programming a Block Diagonal] I came across a problem that might be of independent interest for many (I hope it is ok to dedicate a new post to it). While writing a function, I came across a significant problem: I have an array[J,J] of matrices[K,K], i.e.:

 matrix[K,K] A[J,J];
 matrix[J*K,J*K] B;

Ideally, what I would like to do is to obtain a matrix[JK,JK], i.e. converting the whole array into a big matrix. I naively tried to use the to_matrix() function, but it is only defined on arrays of reals. What should I do? Thanks in advance for the help.

1 Like

Hi,
sorry for not getting to you earlier. I don’t think there is any built-in way to do this easily. I think the best way is to actually implement the conversion yourself using a bunch of for loops - there is only very small performance penalty for doing it this way and you’ll be able to be sure that the transformation is exactly as you want it (i.e. do you want to iterate over rows or columns first?).

Best of luck with your model!