-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Check bounds for indexing tuples by logical masks #19737
Conversation
Also deprecate indexing tuples by non-vectors since that should increase the dimensionality of the tuple, but tuples are 1-d only structures. Fix JuliaLang#19719
getindex(t::Tuple, r::AbstractArray) = tuple([t[ri] for ri in r]...) | ||
getindex(t::Tuple, b::AbstractArray{Bool}) = getindex(t,find(b)) | ||
getindex{T}(t::Tuple, r::AbstractArray{T,1}) = tuple([t[ri] for ri in r]...) | ||
getindex(t::Tuple, b::AbstractArray{Bool,1}) = length(b) == length(t) ? getindex(t,find(b)) : throw(BoundsError(t, b)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apparently it's never been size-checked for as long as this getindex signature has existed 66ae77a, wonder if there was a reason not to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh, I'd bet it was just an oversight. Bounds checking back then was less picky and no tests broke with this change.
just in case this might somehow be a hotspot? @nanosoldier |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
benchmark results are noise, lgtm
@@ -15,8 +15,8 @@ endof(t::Tuple) = length(t) | |||
size(t::Tuple, d) = d==1 ? length(t) : throw(ArgumentError("invalid tuple dimension $d")) | |||
getindex(t::Tuple, i::Int) = getfield(t, i) | |||
getindex(t::Tuple, i::Real) = getfield(t, convert(Int, i)) | |||
getindex(t::Tuple, r::AbstractArray) = tuple([t[ri] for ri in r]...) | |||
getindex(t::Tuple, b::AbstractArray{Bool}) = getindex(t,find(b)) | |||
getindex{T}(t::Tuple, r::AbstractArray{T,1}) = tuple([t[ri] for ri in r]...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r::AbstractVector
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not defined at this point in bootstrap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
be sure to squash on merge then, if the first commit wouldn't build
Lots of PRs adding stuff at the end of |
Also deprecate indexing tuples by non-vectors since that should increase the
dimensionality of the tuple, but tuples are 1-d only structures.
Fix #19719