I came across this strange behavior in 0.6 where the type of an array slice isn’t inferred when it is assigned in a function. Consider this MWE.
test(A::Array{Float64, 2}, i::Int64) = A[i,:]
test2(A::Array{Float64, 2}, i::Int64) = Ai = A[i,:]
A = reshape(1:16, 4, 4)
When I run @code_warntype test(A, 2)
I get (with the Body
section omitted)
Variables:
#self#::#test
A::Array{Float64,2}
i::Int64
Body:
...
end::Array{Float64,1}
The types of the inputs and output are correctly inferred.
However, when I run @code_warntype test2(A, 2)
I get
Variables:
#self#::#test2
A::Array{Float64,2}
i::Int64
Ai::Any
Body:
...
end::Array{Float64,1}
The types of the inputs and output are still correctly inferred, but the temporary variable Ai
is type Any
even though it is the same as the output. In 0.5 Ai
is inferred correctly as Ai::Array{Float64,1}
. Does anyone know what causes this behavior?