Skip to content
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

Merged
merged 9 commits into from
Dec 16, 2020

Conversation

sethaxen
Copy link
Member

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.

Comment on lines +185 to +189
function _norm1_back(x, y, Δy)
∂x = similar(x)
∂x .= sign.(x) .* real(Δy)
return ∂x
end
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

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]).

Copy link
Member

@oxinabox oxinabox left a 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-io
Copy link

codecov-io commented Dec 16, 2020

Codecov Report

Merging #329 (504e30b) into master (abfe271) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
src/rulesets/LinearAlgebra/blas.jl 92.41% <ø> (-0.06%) ⬇️
src/rulesets/Base/array.jl 100.00% <100.00%> (ø)
src/rulesets/Base/fastmath_able.jl 96.96% <100.00%> (+0.09%) ⬆️
src/rulesets/Base/indexing.jl 100.00% <100.00%> (ø)
src/rulesets/LinearAlgebra/norm.jl 100.00% <100.00%> (ø)
src/rulesets/LinearAlgebra/structured.jl 98.87% <100.00%> (-0.03%) ⬇️
src/rulesets/LinearAlgebra/symmetric.jl 100.00% <100.00%> (ø)
src/rulesets/LinearAlgebra/utils.jl 86.66% <100.00%> (+0.95%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update abfe271...504e30b. Read the comment docs.

@sethaxen sethaxen merged commit 721d89b into JuliaDiff:master Dec 16, 2020
@sethaxen sethaxen deleted the fixtypeinstabilities branch December 16, 2020 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants