Skip to content

Commit 58168b8

Browse files
committed
Retain sparsity in A[inds...] = x
1 parent b58bee1 commit 58168b8

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/auxiliary/sparsetensorarray.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,24 @@ Base.@propagate_inbounds function Base.copyto!(
107107
return t
108108
end
109109

110+
Base.@propagate_inbounds function Base.copyto!(
111+
t::SubArray{T,N,A}, v::SparseTensorArray
112+
) where {T,N,A<:SparseTensorArray}
113+
undropped_parentindices = map(Base.parentindices(t)) do I
114+
I isa Base.ScalarIndex ? (I:I) : I
115+
end
116+
117+
for I in eachindex(IndexCartesian(), v)
118+
if haskey(v, I)
119+
t[I] = v[I]
120+
else
121+
parentI = CartesianIndex(Base.reindex(undropped_parentindices, I.I))
122+
delete!(parent(t), parentI)
123+
end
124+
end
125+
return t
126+
end
127+
110128
Base.@propagate_inbounds function Base.copyto!(
111129
dest::SparseTensorArray,
112130
Rdest::CartesianIndices,

0 commit comments

Comments
 (0)