Using the Wikipedia definition of Kronecker sum, it seems that we can define it in terms of the Kronecker products, which is built in:
Clear[kroneckersum]
kroneckersum[a_, b_ /; Dimensions[a] == Dimensions[b]] :=
KroneckerProduct[a, IdentityMatrix[Length[a]]] +
KroneckerProduct[IdentityMatrix[Length[b]], b]
a = RandomInteger[{0, 10}, {5, 5}]
b = RandomInteger[{0, 10}, {5, 5}]
kroneckersum[a, b]
An alternative implementation that has the significant advantage of retaining the use of SparseArrays
for large matrices was proposed by Henrik in comments:
kroneckersum[a_?SquareMatrixQ, b_?SquareMatrixQ] :=
KroneckerProduct[a, IdentityMatrix[Length[b], SparseArray]] +
KroneckerProduct[IdentityMatrix[Length[a], SparseArray], b]
This also reminded me of SquareMatrixQ
, a convenient bit of syntactic sugar which I'd seen used before, but keep forgetting.