-
Notifications
You must be signed in to change notification settings - Fork 15
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 tangent type of arrays of (named) tuples from FD #224
Conversation
Codecov Report
@@ Coverage Diff @@
## main #224 +/- ##
==========================================
+ Coverage 90.75% 90.84% +0.08%
==========================================
Files 11 11
Lines 303 295 -8
==========================================
- Hits 275 268 -7
+ Misses 28 27 -1
Continue to review full report at Codecov.
|
I wonder if we can do this with |
Nice, this seems to fix the issue in ChangesOfVariables as well. Great if we can use existing functionality. I'm currently checking if it breaks any tests in CRTestUtils (and if successful, I'll push and we can see if it breaks any downstream packages). |
Hmm, tests passed locally but it seems doctests fail since |
@oxinabox would it be OK to add a |
it is here, no? |
Oh wow, now I'm confused. The error message clearly stated that it is missing: https://github.com/JuliaDiff/ChainRulesTestUtils.jl/runs/4153868239?check_suite_focus=true#step:4:214 |
Ah the docs use an old version of CRCore: https://github.com/JuliaDiff/ChainRulesTestUtils.jl/runs/4153868239?check_suite_focus=true#step:4:57 |
Looks good to me. |
There's one test error in ChainRules: https://github.com/JuliaDiff/ChainRulesTestUtils.jl/runs/4154680040?check_suite_focus=true#step:6:162 It is caused by the test in https://github.com/JuliaDiff/ChainRules.jl/blob/edf3a1f48fb5c9af01820aeca6ced94d4f97fa1a/test/rulesets/Base/array.jl#L35 More concretely, the problem is that julia> using ChainRulesCore # v 1.11.1
julia> ProjectTo((; y = randn(3)))
identity (generic function with 1 method) I guess this is a bug and has to be fixed in ChainRulesCore since it differs e.g. from julia> ProjectTo((randn(3),))
ProjectTo{Tangent{Tuple{Vector{Float64}}, T} where T}(elements = (ProjectTo{AbstractArray}(element = ProjectTo{Float64}(), axes = (Base.OneTo(3),)),),) which projects to a |
I assume the ChainRules.jl test errors will be fixed by JuliaDiff/ChainRules.jl#550. |
yep, merge when happy |
Currently, arrays of tuples and named tuples as a result from FiniteDifferences are not converted to the correct
Tangent
types. This causes the issue in JuliaMath/ChangesOfVariables.jl#4 (comment) and is fixed by this PR (confirmed locally).Deeply nested arrays of (named) tuples will still have an incorrect, so maybe a (better?) alternative would be to always recurse arrays until one hits aAbstractArray{<:Real}
(which would be returned unmodified, also to avoid copies in this case) or a non-array base case such asTuple
,NamedTuple
, andAny
.The PR replaces the
_maybe_fix_to_composite
withProjectTo
.It also seems that the function is not tested currently. Should I add some tests?