-
Notifications
You must be signed in to change notification settings - Fork 40
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
Consistently specialize one, zero on args of type Zeros, Ones, Eye #173
Comments
On Julia v1.8, the julia> zero(Eye(3))
3×3 Diagonal{Float64, Fill{Float64, 1, Tuple{Base.OneTo{Int64}}}}:
0.0 ⋅ ⋅
⋅ 0.0 ⋅
⋅ ⋅ 0.0 I'll try to work on a fix for |
Can |
Is there an advantage to using |
I think |
I would have expected constant propagation to handle this, but some experimentation shows that you may be right. However, I'll hold off on this for now and wait for the opinions of others, as changing the return type may increase compilation times. This is indeed not being constant-propagated: julia> f = Fill(4,3,3)
3×3 Fill{Int64}, with entries equal to 4
julia> @code_warntype (x -> (s = zero(one(x)) * x; s[1]))(f)
MethodInstance for (::var"#1#2")(::Fill{Int64, 2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}})
from (::var"#1#2")(x) in Main at REPL[3]:1
Arguments
#self#::Core.Const(var"#1#2"())
x::Fill{Int64, 2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}
Locals
s::Fill{Int64, 2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}
Body::Int64
1 ─ %1 = Main.one(x)::LinearAlgebra.Diagonal{Int64, Ones{Int64, 1, Tuple{Base.OneTo{Int64}}}}
│ %2 = Main.zero(%1)::Core.PartialStruct(LinearAlgebra.Diagonal{Int64, Fill{Int64, 1, Tuple{Base.OneTo{Int64}}}}, Any[Core.PartialStruct(Fill{Int64, 1, Tuple{Base.OneTo{Int64}}}, Any[Core.Const(0), Tuple{Base.OneTo{Int64}}])])
│ (s = %2 * x)
│ %4 = Base.getindex(s, 1)::Int64
└── return %4 although the result of |
These should be specialized to return FillArrays types:
Compare with:
The text was updated successfully, but these errors were encountered: