-
Notifications
You must be signed in to change notification settings - Fork 37
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
Remove unnecessary methods from setindex
#305
Conversation
This PR also fixes Before this PR julia> a = ones(3,3)
3×3 Matrix{Float64}:
1.0 1.0 1.0
1.0 1.0 1.0
1.0 1.0 1.0
julia> Base.setindex(a,0.0,3,2)
3×3 Matrix{Float64}:
1.0 1.0 1.0
1.0 1.0 1.0
0.0 0.0 0.0
julia> a = ones(3,4)
3×4 Matrix{Float64}:
1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0
julia> Base.setindex(a,0.0,3,2)
ERROR: DimensionMismatch("arrays could not be broadcast to a common size; got a dimension with lengths 4 and 2")
Stacktrace:
[1] _bcs1
@ ./broadcast.jl:516 [inlined]
[2] _bcs (repeats 2 times)
@ ./broadcast.jl:510 [inlined]
[3] broadcast_shape
@ ./broadcast.jl:504 [inlined]
[4] combine_axes
@ ./broadcast.jl:499 [inlined]
[5] _axes
@ ./broadcast.jl:224 [inlined]
[6] axes
@ ./broadcast.jl:222 [inlined]
[7] combine_axes
@ ./broadcast.jl:499 [inlined]
[8] instantiate
@ ./broadcast.jl:281 [inlined]
[9] materialize
@ ./broadcast.jl:860 [inlined]
[10] setindex(x::Matrix{Float64}, v::Float64, i::Int64, j::Int64)
@ ArrayInterfaceCore ~/.julia/packages/ArrayInterfaceCore/wwYvJ/src/ArrayInterfaceCore.jl:131
[11] top-level scope
@ REPL[10]:1 After this PR julia> a = ones(3,3)
3×3 Matrix{Float64}:
1.0 1.0 1.0
1.0 1.0 1.0
1.0 1.0 1.0
julia> Base.setindex(a,0.0,3,2)
3×3 Matrix{Float64}:
1.0 1.0 1.0
1.0 1.0 1.0
1.0 0.0 1.0
julia> a = ones(3,4)
3×4 Matrix{Float64}:
1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0
julia> Base.setindex(a,0.0,3,2)
3×4 Matrix{Float64}:
1.0 1.0 1.0 1.0
1.0 1.0 1.0 1.0
1.0 0.0 1.0 1.0 |
IIRC, this will break codes that need to be non-mutating on |
Codecov Report
@@ Coverage Diff @@
## master #305 +/- ##
=======================================
Coverage 91.79% 91.79%
=======================================
Files 9 9
Lines 1413 1413
=======================================
Hits 1297 1297
Misses 116 116 Continue to review full report at Codecov.
|
Julia doesn't have this yet (see JuliaLang/julia#33495 ). Anyway, that PR looks much better to me than the code here. Zygote compatibility should be easily possible by adding an rrule for |
We can add the code from the PR here. Or @tkf do you think you can get this finished for Base? |
It's not AD compatible so it would cause downstream failures.
That would be fine. If someone defines an rrule to delete these that's probably a better option. But I don't think we should merge something that we know is going to be downstream breaking like this, we should at least wait until a safer version is made, however it's done. |
I'm not much familiar with Zygote.jl and related AD systems. I have some questions:
|
I have tested FiniteDiff/test/runtests.jl with changes in this PR in my local PC, but the test didn't produce errors. |
Yes, of course that doesn't because it doesn't hit Zygote/ReverseDiff on the finite differencing in that test suite. But there are some clear cases where this will cause failures. If you differentiate the solver in OOP form and put it into finite difference mode then a mutating setindex will cause a failure. So probably the clearest example of this would be one of the DiffEqSensitivity.jl in the oop function adjoint test with
We should probably expand the downstream tests to include DiffEqSensitivity Core1/2/3/4/5 because those tests would probably be the most prone to catching interface breaks since they rely on the interfaces being correct (since they need to impose AD + GPU + ... constraints all at once). |
As described in #305 (comment), these tests are probably the most reliant on abstract interfaces being correct, and so they would catch some of these details that the current downstream tests are missing, like the interface break caused by #305
Rebase after #313 for the new tests, and that might see the break. Otherwise I'll explicitly add something to show the break (but I'm traveling right now so it might now happen ASAP) |
I just rebased to the current |
The simplest thing to do might be to add a ChainRules.rrule for |
Downstream has been handled. |
Thanks for the merging! |
The current implementation of
setindex
is problematic for the following reasons:OffsetArrays
.Array{string}
.setindex
isn't compatible with ArrayInterfaceCoresetindex
StaticArrays.jl#1039).Before this PR
After this PR
Before this PR
After this PR