diff --git a/ext/SparseArraysExt.jl b/ext/SparseArraysExt.jl index c3136653d..6f8a1c998 100644 --- a/ext/SparseArraysExt.jl +++ b/ext/SparseArraysExt.jl @@ -6,10 +6,13 @@ import LinearAlgebra import Dagger import Dagger: Blocks, AutoBlocks, BlocksOrAuto, AssignmentType, DSparseArray, DSparseMatrix -# SparseArrays' vararg CSC indexing and Dagger's AbstractArray domain indexing -# each constrain a different argument. Resolve their intersection explicitly. +# SparseArrays' vararg CSC and sparse-vector indexing and Dagger's AbstractArray +# domain indexing each constrain a different argument. Resolve their +# intersection explicitly. Base.getindex(A::SparseArrays.AbstractSparseMatrixCSC, d::Dagger.ArrayDomain) = A[Dagger.indexes(d)...] +Base.getindex(x::SparseArrays.AbstractSparseVector, d::Dagger.ArrayDomain) = + x[Dagger.indexes(d)...] # Keep tiles sparse through `collect`/`cat`; the outer `collect` densifies. Dagger._sparse_collect(M::SparseMatrixCSC) = copy(M) diff --git a/test/array/allocation.jl b/test/array/allocation.jl index 4548f3ed1..5bfec4f50 100644 --- a/test/array/allocation.jl +++ b/test/array/allocation.jl @@ -146,6 +146,11 @@ end test_dist(rand(100, 100)) test_dist(sprand(100, 100, 0.1)) + v = sprand(100, 0.1) + Dv = distribute(v, Blocks(10)) + @test Dv isa DArray{eltype(v),1} + @test collect(Dv) == v + x = distribute(rand(10), 2) @test collect(distribute(x, 3)) == collect(x) end