-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Range-indexing FixedSizeArrays must/could return other FixedSizeArrays or "SubFixedSizeArray"s #17
Comments
+1 |
I just ran into this as well. We should definitely return a fixed size array for slices, at the moment a tuple comes out: julia> Vec(1,2,3)[1:2]
(1,2) |
Then, there is also the question of type stability of such indexing. A workaround I've been using (told by @SimonDanisch ) is using @generated function Base.getindex{R}(v::Vec, i::Type{Val{R}})
:(Vec(tuple($([:(v._[$i]) for i in R]...))))
end
@generated function Base.getindex{Ri, Rj}(m::Mat, ::Type{Val{Ri}}, ::Type{Val{Rj}})
if isa(Rj, Integer)
:(Vec(tuple($([:(m._[$Rj][$i]) for i in Ri]...))))
else
:(Mat(tuple($([:(tuple($([:(m._[$j][$i]) for i in Ri]...))) for j in Rj]...))))
end
end |
But for a first approach we may have to forget about type stability, and just improve current |
BTW, this |
I could give it another go now that we have a "better" similar function ;) |
Good point about the type problems. The tuple approach seems like the best thing we can do at the moment IMHO, though for anything larger than 3 or 4-vectors, the Constant propagation has been discussed a little at JuliaLang/julia#5560 - I imagine even one pass of this would solve a whole raft of what are currently tricky design problems. Unfortunately doesn't look like it's coming any time soon! |
No description provided.
The text was updated successfully, but these errors were encountered: