The kron
function on vectors seems to be inappropriately holding on to its input. As a simple example, the input
s = [2,5]; k=kron(s,[3,1]); push!(s,4)
produces the error:
cannot resize array with shared data
Stacktrace:
[1] _growend! at ./array.jl:892 [inlined]
[2] push!(::Array{Int64,1}, ::Int64) at ./array.jl:935
[3] top-level scope at In[71]:4
[4] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1091
while
s = [2,5]; k=kron(copy(s),[1,0]); push!(s,4)
behaves as I would have expected the initial input to. So it would appear that the output of kron
somehow shares data with it’s input.
By way of contrast:
s = [2,5]; k=kron(s,[1,0]); s .= [3,7]; k
shows that the output of kron
only depends on the initial value of s
. It seems like the restrictions from the sharing of s
are thus unnecessary.
I would have expected kron
to either always use a copy of its input, in which case the first input wouldn’t produce an error, or for it’s output to be some clever construct that maintains a reference to the input vectors, in which case the third input produces surprising results.
Is this just an unavoidable side effect of the fact that kron
for vectors is implemented in terms of kron
for matrices? It seems like the culprit is that Matrix created by the reshape(s,length(s),1)
function argument isn’t properly transient.