You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Learning from my experiments on #745 i looked back at the missing support for vector indexing in setindex.
@inlinefunctionsetindex(a::SVector{L}, v::AbstractArray, indices::AbstractArray) where L
out =MVector(a)
for (i, x) inzip(indices, v)
# Do boundscheck here to allow Julia to fully elide the dynamic allocation.@boundscheckif (i <1|| i > L)
throw(BoundsError(a, i))
end@inbounds out[i] = x
endreturnSVector(out)
end
while we're at it, looks like setindex for scalars can easily be written this way as well.
@inlinefunctionsetindex2(a::SVector{L}, x, index::Integer) where L
out =MVector(a)
# Do boundscheck here to allow Julia to fully elide the dynamic allocation.@boundscheckif (index <1|| index > L)
throw(BoundsError(a, index))
end@inbounds out[index] = x
returnSVector(out)
end
Looking at assembly, it looks nicer for this implementation. I have had some mixed results trying to benchmark this; peaking at @code_native looked very efficient, but benchmark times still fell a bit short. Perhaps my benchmarks were lacking, or i missed something.
So is this interesting?
The text was updated successfully, but these errors were encountered:
It could be interesting. I had been waiting until the dust settles on non-scalar indexing in Julia where we may prefer a distinct generic function for non-scalar indexing (perhaps with syntax like a.[b] .= c) but there's no real reason to hold off too long...
Off topic... but do we really have an "arrays" label for StaticArrays? I'm amused. :)
Learning from my experiments on #745 i looked back at the missing support for vector indexing in
setindex
.while we're at it, looks like setindex for scalars can easily be written this way as well.
Looking at assembly, it looks nicer for this implementation. I have had some mixed results trying to benchmark this; peaking at
@code_native
looked very efficient, but benchmark times still fell a bit short. Perhaps my benchmarks were lacking, or i missed something.So is this interesting?
The text was updated successfully, but these errors were encountered: