How to Kronecker by row (one dimension only)

Yes, you can do this just by reshaping and broadcasting:

X, Y = rand(Int8, 2,2), ones(Int, 2,3);
kronrow(X, Y)

using TensorCast
@cast K[r,(j,i)] := X[r,i] * Y[r,j]  # (j,i) to match kron

hkron(X::AbstractMatrix, Y::AbstractMatrix) = reshape(reshape(X, size(X,1), 1, size(X,2)) .* Y, size(X,1), size(X,2) * size(Y,2))
hkron(X,Y)
3 Likes