Repository navigation
SparseArrays: Resolve ArrayDomain indexing for sparse vectors - #865
Open
SwayamBorateIIT wants to merge 1 commit into
Open
SwayamBorateIIT wants to merge 1 commit into
SwayamBorateIIT wants to merge 1 commit into
Conversation
On Julia nightly (1.15.0-DEV.1070), `distribute(sprand(100, 0.1), Blocks(10))` throws `MethodError: getindex(::SparseVector, ::ArrayDomain) is ambiguous`. SparseArrays now defines `getindex(x::AbstractSparseVector, I...)`. That is more specific than Dagger's `getindex(::AbstractArray, ::ArrayDomain)` in the first argument and less specific in the second, so neither method wins. `distribute` reaches it when it slices each block out of the source vector. Julia 1.13 is not affected. Add an `AbstractSparseVector` method for `ArrayDomain` that slices with the domain's ranges, next to the existing `AbstractSparseMatrixCSC` one (428a54f). It is more specific than both candidates, which settles the call. An `ArrayDomain` is not an index and SparseArrays cannot lower it, so the method has to live on Dagger's side. The `distribute` testset covered a sparse matrix but not a sparse vector, so CI did not show this. Add a sparse-vector case next to it. Refs JuliaParallel#786 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Contributor
Author
|
Hi, when you have a moment, could you approve the CI workflows for this PR? Happy to adjust anything. Thanks! |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
distributeof a sparse vector fails on Julia nightly, because thegetindexcall it makes on each block is ambiguous:Reproduced on current master (
c3352d72) with Julia 1.15.0-DEV.1070. Julia 1.13.0 is not affected.Why
SparseArrays' method is more specific than Dagger's in the first argument (
AbstractSparseVectoragainstAbstractArray), and Dagger's is more specific in the second (ArrayDomainagainst the untypedI...), so neither wins. Forcing SparseArrays' method to take anArrayDomainfails withArgumentError: invalid index, because anArrayDomainis not an index, so the fix has to be on Dagger's side.#780 fixed the matrix half of this (428a54f). The vector method was not added and no test distributed a sparse vector, so CI did not show it. Refs #786.
The change
One method in
ext/SparseArraysExt.jl, next to the matrix one:It is more specific than each of the two candidates, which settles the call. A test in the
distributetestset oftest/array/allocation.jldistributes a sparse vector and checks the round trip.Tests
Each run was
julia --project=test test/runtests.jl --test array/allocation, after deletingtest/Manifest.tomland instantiating, on one Linux machine. I ran these three:getindex(::SparseVector, ::ArrayDomain) is ambiguousatallocation.jl:150The last row is the negative control: with the method removed, the new test fails on nightly, and only the
distributetestset is affected.Claude Code also ran the same file on a separate copy of the branch, on both versions, with and without the method. Those four runs gave the same numbers as mine. The one I did not repeat is 1.13.0 with the method removed (983 / 983 pass), which is where "Julia 1.13.0 is not affected" comes from.
Not covered
I did not run Julia 1.10 or 1.14 (
pre), or the MPI and GPU jobs; I am leaving those to CI. The method is defined only when SparseArrays is loaded and does not touch scheduling, but I have not measured speed or allocations.AI disclosure
I used Claude Code (Opus 5, later Sonnet 5.5) for this change.