Skip to content

Commit

Permalink
Sparse array slicing
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed Nov 13, 2024
1 parent cf050da commit c98436b
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ function sparse_setindex!(a::AbstractArray, value, I::CartesianIndex{1})
return a
end

# Slicing
function sparse_setindex!(a::AbstractArray, value, I::AbstractUnitRange...)
inds = CartesianIndices(I)
for i in stored_indices(value)
if i in CartesianIndices(inds)
a[inds[i]] = value[i]
end
end
return a
end

# Handle trailing indices
function sparse_setindex!(a::AbstractArray, value, I::CartesianIndex)
t = Tuple(I)
Expand Down

0 comments on commit c98436b

Please sign in to comment.