-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@code_warntype shows the following code is type unstable #49970
Labels
compiler:inference
Type inference
Comments
atbug
changed the title
@code_warntype show the following code as type unstable
@code_warntype shows the following code as type unstable
May 28, 2023
atbug
changed the title
@code_warntype shows the following code as type unstable
@code_warntype shows the following code is type unstable
May 28, 2023
The interesting thing is that if you call using LinearAlgebra
function hey(q)
A = kron([1 1; 1 1], [1 1; 1 1])
B = kron([1 1; 1 1], [1 0; 0 1])
if norm(q) > 1.0
return A
else
return A - B
end
end
hey([1.0, 1.0]);
# @code_warntype hey([1.0, 1.0])
# @code_warntype hey([1.0, 0.0])
function foo(f)
return f.([[1.0, 1.0], [1.0, 0.0]])
end
@code_warntype foo(hey) julia> @code_warntype foo(hey)
MethodInstance for foo(::typeof(hey))
from foo(f) @ Main REPL[6]:1
Arguments
#self#::Core.Const(foo)
f::Core.Const(hey)
Body::Vector{Matrix{Int64}}
1 ─ %1 = Base.vect(1.0, 1.0)::Vector{Float64}
│ %2 = Base.vect(1.0, 0.0)::Vector{Float64}
│ %3 = Base.vect(%1, %2)::Vector{Vector{Float64}}
│ %4 = Base.broadcasted(f, %3)::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1}, Nothing, typeof(hey), Tuple{Vector{Vector{Float64}}}}
│ %5 = Base.materialize(%4)::Vector{Matrix{Int64}}
└── return %5 Or add a type assert
|
Probably similar to #35800 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running the following code with
julia test.jl
shows type instability, but I believe the code is type stable.test.jl
The output is
However, uncomment the line
hey([1.0, 0.0])
fix the issue.This has been tested on 1.9.0, 1.8.5 and 1.6.7.
The text was updated successfully, but these errors were encountered: