-
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
WIP: handle zero_tangent in presence of cyclic structures (v1) #654
Conversation
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
format self-refrential (squash me into prev) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
is_defined_mask = Expr(:tuple, map(fieldnames(primal)) do fname | ||
:(isdefined(primal, $(QuoteNode(fname)))) | ||
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.
[JuliaFormatter] reported by reviewdog 🐶
$( | ||
map(fieldnames(primal), zfield_exprs) do fname, fval_expr | ||
:(setproperty!(tangent, $(QuoteNode(fname)), $fval_expr)) | ||
end... | ||
) | ||
return tangent |
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.
[JuliaFormatter] reported by reviewdog 🐶
$( | |
map(fieldnames(primal), zfield_exprs) do fname, fval_expr | |
:(setproperty!(tangent, $(QuoteNode(fname)), $fval_expr)) | |
end... | |
) | |
return tangent | |
$(map(fieldnames(primal), zfield_exprs) do fname, fval_expr | |
:(setproperty!(tangent, $(QuoteNode(fname)), $fval_expr)) | |
end...) | |
return tangent |
else | ||
:($Tangent{$primal}($(Expr(:parameters, zfield_exprs...)))) | ||
:($Tangent{$primal}($(Expr(:parameters, Expr.(:kw, fieldnames(primal), zfield_exprs)...)))) |
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.
[JuliaFormatter] reported by reviewdog 🐶
:($Tangent{$primal}($(Expr(:parameters, Expr.(:kw, fieldnames(primal), zfield_exprs)...)))) | |
:($Tangent{$primal}( | |
$(Expr(:parameters, Expr.(:kw, fieldnames(primal), zfield_exprs)...)) | |
)) |
# The following will fall back to `Any` if it is hard to infer | ||
function guess_zero_tangent_type(::Type{T}) where {T} | ||
return Core.Compiler.return_type(zero_tangent, Tuple{T}) | ||
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.
[JuliaFormatter] reported by reviewdog 🐶
end | |
end |
global function _MutableTangent(::Val{P}, is_defined_mask, tangent_types) where {P} | ||
backing_vals = map(is_defined_mask, tangent_types) do is_def, tangent_type | ||
ref = if !is_def | ||
Ref{Union{ZeroTangent, tangent_type}} # allow a Zero which will be used for uninitialized values |
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.
[JuliaFormatter] reported by reviewdog 🐶
Ref{Union{ZeroTangent, tangent_type}} # allow a Zero which will be used for uninitialized values | |
Ref{Union{ZeroTangent,tangent_type}} # allow a Zero which will be used for uninitialized values |
return ref() # undefined, but it will be filled later | ||
end | ||
backing = NamedTuple{fieldnames(P)}(backing_vals) | ||
return new{P, typeof(backing)}(backing) |
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.
[JuliaFormatter] reported by reviewdog 🐶
return new{P, typeof(backing)}(backing) | |
return new{P,typeof(backing)}(backing) |
|
||
function MutableTangent{P}(fvals) where P |
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.
[JuliaFormatter] reported by reviewdog 🐶
function MutableTangent{P}(fvals) where P | |
function MutableTangent{P}(fvals) where {P} |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## ox/mutabletangent #654 +/- ##
=====================================================
+ Coverage 94.15% 94.34% +0.18%
=====================================================
Files 15 15
Lines 976 991 +15
=====================================================
+ Hits 919 935 +16
+ Misses 57 56 -1 ☔ View full report in Codecov by Sentry. |
f9ade6e
to
95e63d0
Compare
Closing in favor of #655 (comment) |
Follow on to #626
this was my first take at it.
I do not like it because it depends on
Core.Compiler.return_type
which is unreliable for getting tight types and in real cases I have tried falls back to returningAny
.and this code adds a lot of complexity and still doesn't catch everything.