-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Description
julia> a = [1 2; 3 4]
julia> function f1(arr)
for x in eachcol(arr) end
end
julia> function f2(arr)
for x in eachslice(arr; dims=2) end
end
Now, if I do:
julia> @code_warntype f1(a)
Variables
#self#::Core.Compiler.Const(f1, false)
arr::Array{Int64,2}
@_3::Union{Nothing, Tuple{SubArray{Int64,1,Array{Int64,2},Tuple{Base.Slice{Base.OneTo{Int64}},Int64},true},Int64}}
x::SubArray{Int64,1,Array{Int64,2},Tuple{Base.Slice{Base.OneTo{Int64}},Int64},true}
(...)
However:
julia> @code_warntype f2(a)
Variables
#self#::Core.Compiler.Const(f2, false)
arr::Array{Int64,2}
@_3::Union{Nothing, Tuple{Any,Int64}}
x::Any
(...)
Shouldn't these two functions be equivalent in terms of type stability, and the compiler know that x is a SubArray in the second case?
It isn't just this case though, eachslice seems to have the same behavior for other array eltypes and dimensions.
Sorry if this isn't an issue, I'm somewhat new to Julia.
marius311 and adrhill
Metadata
Metadata
Assignees
Labels
No labels