From c98436ba67be9fa97ecc54a9d27aa6380378772a Mon Sep 17 00:00:00 2001 From: mtfishman Date: Tue, 12 Nov 2024 21:56:30 -0500 Subject: [PATCH] Sparse array slicing --- .../src/sparsearrayinterface/indexing.jl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/indexing.jl b/NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/indexing.jl index ae0f6f6d61..e7fe9462b2 100644 --- a/NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/indexing.jl +++ b/NDTensors/src/lib/SparseArrayInterface/src/sparsearrayinterface/indexing.jl @@ -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)