# Strange behavior of vec() in Julia 0.7

I just got bitten by some unexpected behavior of `vec()` in julia 0.7. When I run the code below

``````N = 3
A = randn(N,N) + im .* randn(N,N)
x = randn(N)
z = x'*A
vec(z)
``````

I get this:

``````julia> N = 3
3

julia> A = randn(N,N) + im .* randn(N,N)
3×3 Array{Complex{Float64},2}:
0.382542-0.266179im   -1.69847+1.86236im    1.28885+0.694938im
-0.177623-0.213032im  -0.607246+0.719279im  -2.87126+1.34141im
0.565711-0.303921im   -1.38508+0.684031im  0.416797-0.26476im

julia> x = randn(N)
3-element Array{Float64,1}:
-0.00922375082321524
-0.0683463031968038
-0.29722269002054613

julia> z = x'*A
-0.159531+0.107347im  0.468845-0.269648im  0.0604705-0.0193976im

julia> vec(z)
3-element Array{Complex{Float64},1}:
-0.1595307578638994 - 0.10734716516787285im
0.4688454575032254 + 0.2696475874174454im
0.060470534170491766 + 0.019397566097290375im
``````

Notice that `vec()`, besides reshaping `z`, also computes its conjugate. Things work differently in 1.1 though:

``````julia> N = 3
3

julia> A = randn(N,N) + im .* randn(N,N)
3×3 Array{Complex{Float64},2}:
2.30835+1.173im       0.777158-2.76038im   -0.434369+1.84468im
-0.0812661-0.674808im      1.3555+0.468595im  -0.104688+0.238554im
-0.649005+0.0857933im  -0.556948-0.524496im   -1.19101+0.45196im

julia> x = randn(N)
3-element Array{Float64,1}:
-0.10756799853360234
-1.5958910088917135
-0.9507274395938174

julia> z = x'*A
0.498415+0.869177im  -1.71732+0.0477544im  1.34612-1.00883im

julia> vec(z)
3-element reshape(::LinearAlgebra.Adjoint{Complex{Float64},Array{Complex{Float64},1}}, 3) with eltype Complex{Float64}:
0.4984145172595025 + 0.8691770844949784im
-1.717324546759147 + 0.047754399003301196im
1.3461160206833889 - 1.0088254082365649im
``````

Since the behavior of `vec()` changed from 0.7 to 1.1 (I didn’t test this on 1.0), I guess this has been discussed somewhere. I did a quick search but couldn’t find anything though. Does anybody know anything about this?

This was a bug and fixed shortly after 1.0 was released. I think it was incorporated into 1.0.1.

1 Like

I see. Thanks!!!