Open marius311 opened 3 years ago
Great issue! Ideally @set x[...]
would just call Base.setindex(x, ...)
. However Base.setindex
is only defined for very few containers. And we can't increase coverage here without piracy. The best way to solve this would be
setindex(::OffsetArray, ...)
Do a PR to OffsetArrays, that overloads setindex(::OffsetArray, ...)
I actually tried defining this locally, but Base.setindex(::OffsetArray)
didnt work (if thats what you meant), however defining Setfield.setindex
did work (and I suppose wouldn't be considered piracy?) Here's what I had for reference:
@inline function Setfield.setindex(A::OffsetVector{T,S}, val, i::Int) where {T,S<:StaticArray}
@boundscheck checkbounds(A, i)
OffsetVector{T,S}(setindex(parent(A), val, OffsetArrays.parentindex(Base.axes1(A), i)), A.offsets)
end
Anyway, you certainly know better than me, but thought I'd mention that.
Yes it is fine to do that. I will only break, if the issue is fixed properly.
@set!
is awesome for StaticArrays,but if the array if
OffsetArray(::StaticArray)
, it seems to fall back toOffsetArray(::Array)
.Is there some special-case I could define in my session to handle this? Could this be fixed generally?
Julia 1.6 / Setfield v0.7.0 / StaticArrays v1.0.1 / OffsetArrays v1.5.3