-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Broadcasting and constructors #119
Comments
Maybe https://github.com/JuliaStats/Distributions.jl/blob/master/src/common.jl#L149 messes with Tracker's broadcasting? What happens if you add the same definition for your custom struct? |
Looks fine: julia> using Tracker
julia> struct TwoFields{T1,T2}
x::T1
y::T2
end
julia> Broadcast.broadcastable(d::TwoFields) = Ref(d)
julia> TwoFields.(first(param(zeros(1))), first(param(zeros(1))))
TwoFields{Float64, Float64}(0.0, 0.0) |
OK, I figured out why this is happening: It's caused by the heuristic in Line 558 in 043da25
eltype(::Normal{T}) = T (well, actually Distributions defines it on types as recommended in the Julia docs since instances fall back to it).
If one defines julia> Base.eltype(::Type{TwoFields{T1,T2}}) where {T1,T2} = Base.promote_type(T1, T2)
julia> typeof(TwoFields.(first(param(zeros(1))), first(param(zeros(1)))))
Tracker.Tracked{TwoFields{Float64, Float64}} |
Aaaah.. So is the fix to also check |
I'm not completely sure about the motivation of this check but to me it seems the heuristic is supposed to drop tracking information in cases where the output is known to be non-differentiable. I think the heuristic should rather be too strict and avoid dropping tracking information silently. Maybe eg it could be restricted to |
Anything with eltype |
The fix for Distributions (and e.g. samplers in general: https://docs.julialang.org/en/v1/stdlib/Random/#A-simple-sampler-without-pre-computed-data) requires to change, i.e., probably restrict, the conditional - |
I don't quite understand what |
There seems to be something weird going on when broadcasting over
Real
:But the strange thing is that the following seems to work just fine:
Possibly related to: #65
The text was updated successfully, but these errors were encountered: