-
Notifications
You must be signed in to change notification settings - Fork 62
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
ProjectTo(::AbstractArray)
does not infer
#407
Comments
Lyndon says "It is a union of <=4 elements. It is fine." My reply:
I’ve heard small unions are fine, but never understood this really. Does this mean that a thing happens (JIT?) for each of the elements, and not all possible elements? i.e. something like julia> inner(x) = x > 0 ? 3.0 : 3
inner (generic function with 1 method)
julia> wrapper(x::Int) = x > 0 ? rand(2, 3) : Diagonal(rand(2))
wrapper (generic function with 1 method)
julia> wrapper(x::Float64) = x > 0 ? "hello" : :world
wrapper (generic function with 2 methods)
julia> together(x) = wrapper(inner(x))
together (generic function with 1 method)
julia> @code_warntype together(2.0)
Variables
#self#::Core.Const(together)
x::Float64
Body::Any
1 ─ %1 = Main.inner(x)::Union{Float64, Int64}
│ %2 = Main.wrapper(%1)::Any
└── return %2 where the result is actually Any rather than a Union of four types |
I wonder if we actually only want the |
Surely this can be made to infer. The trick |
e.g. see
the reason for the failure is
ChainRulesCore.jl/src/projection.jl
Lines 174 to 183 in 6efb2d2
which decides whether to
dy
isdx
or areshape(dx, ...)
based on the values of the axes.We could instead do
which does infer, but throws an error for the arrays that need to be reshaped. In practice, this only means that only
test fails in ChainRulesCore
and all the rrule inference tests (but not the one where inplaceablethunk inference fails) in JuliaDiff/ChainRules.jl#459 (comment) are fixed.
do we want this tradeoff or not?
The text was updated successfully, but these errors were encountered: