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 rrules for Symmetric and Diagonal constructors #23
Conversation
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.
Great job @ararslan . Could you please add a test which would have broken the old implementation before merging though, just to prevent accidental reversion at some point?
I had thought of doing so but wasn't able to determine how to formulate such a test. The only way I can think to properly catch this case would be to add more matrix constructor sensitivities, which would show method overwriting warnings for |
I was just thinking something simple like checking that rrule(Diagonal{Float64}, x)
rrule(Diagonal, x) should do sensible things. Wouldn't generalise to new types of course, but would at least prevent these particular ones from reverting. Update: perhaps update the |
Update them in what way? |
Sorry, I was just thinking something along the lines of changing this and related to rrule_test(typeof(Diagonal(randn(rng, N))), randn(rng, N, N), (randn(rng, N), randn(rng, N))) |
Currently these definitions are extending `rrule(::typeof(T), x)` where `T` is a type. However, `typeof(Diagonal) == UnionAll`, which means this is not defining the method it looks like it might be defining. The only reason this worked when originally implemented was that one of the `rrule` definitions was for `rrule(UnionAll, Matrix)` and the other for `rrule(UnionAll, Vector)`, so dispatch still worked. This replaces these problematic `::typeof(T)`s with `::Type{<:T}`.
c54821c
to
a610fb3
Compare
Okay, I've implemented that for |
Is |
Well it is, but that's covered by the existing |
Ahh I see what you mean. Good point -- we should probably sort this out in another PR as we'll probably have more of these things to check in the future. Would you mind raising an issue regarding this? I'm happy with the PR now though. Thanks for sorting this out. |
Issue in #24. |
Currently these definitions are extending
rrule(::typeof(T), x)
whereT
is a type. However,typeof(Diagonal) == UnionAll
, which means this is not defining the method it looks like it might be defining. The only reason this worked when originally implemented was that one of therrule
definitions was forrrule(UnionAll, Matrix)
and the other forrrule(UnionAll, Vector)
, so dispatch still worked.This replaces these problematic
::typeof(T)
s with::Type{<:T}
.