Odd behaviour with kron, transpose and sparse matrices


#1

This is related to https://github.com/JuliaLang/julia/issues/28432

kron returns a dense matrix if the adjoint is provided, example

id = spzeros(2,2)+I
kron(id,id')

this returns

4×4 Array{Float64,2}:
 1.0  0.0  0.0  0.0
 0.0  1.0  0.0  0.0
 0.0  0.0  1.0  0.0
 0.0  0.0  0.0  1.0

while it should output

4×4 SparseMatrixCSC{Float64,Int64} with 4 stored entries:
  [1, 1]  =  1.0
  [2, 2]  =  1.0
  [3, 3]  =  1.0
  [4, 4]  =  1.0

is this behaviour expected?


#2

Probably just no one wrote the relevant method specialized for sparse matrices yet. You might want to make a PR.


#3

Consider materializing the lazy adjoint with copy:

julia> using LinearAlgebra, SparseArrays

julia> id = sparse(1.0I, 2, 2);

julia> kron(id, copy(id'))
4×4 SparseMatrixCSC{Float64,Int64} with 4 stored entries:
  [1, 1]  =  1.0
  [2, 2]  =  1.0
  [3, 3]  =  1.0
  [4, 4]  =  1.0