-
Notifications
You must be signed in to change notification settings - Fork 89
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
Fix various type-instabilities #329
Conversation
function _norm1_back(x, y, Δy) | ||
∂x = similar(x) | ||
∂x .= sign.(x) .* real(Δy) | ||
return ∂x | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels bad that we have to do this.
Should we open an issue on JuliaLang/julia about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I think this is necessarily type-unstable, e.g.
julia> x = Diagonal([1.0, 2.0, 3.0]);
julia> x .* 0
3×3 Diagonal{Float64,Array{Float64,1}}:
0.0 ⋅ ⋅
⋅ 0.0 ⋅
⋅ ⋅ 0.0
julia> x .* 10
3×3 Diagonal{Float64,Array{Float64,1}}:
10.0 ⋅ ⋅
⋅ 20.0 ⋅
⋅ ⋅ 30.0
julia> x .* Inf
3×3 Array{Float64,2}:
Inf NaN NaN
NaN Inf NaN
NaN NaN Inf
julia> x .* NaN
3×3 Array{Float64,2}:
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this breaks gradient(norm, [1,2,3])
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work.
A few points but once those a cleared up, merge when ready.
Thanks
Codecov Report
@@ Coverage Diff @@
## master #329 +/- ##
==========================================
+ Coverage 97.62% 97.64% +0.01%
==========================================
Files 18 18
Lines 1011 1018 +7
==========================================
+ Hits 987 994 +7
Misses 24 24
Continue to review full report at Codecov.
|
This PR fixes most of the type-instabilities identified by JuliaDiff/ChainRulesTestUtils.jl#78, the remainder being documented in #328 and JuliaDiff/ChainRulesCore.jl#265 or for type-unstable primals. I'm not yet adding any new tests because that would be redundant with the above PR. Until it is merged, this PR just checks that our current functionality tests still pass.