Skip to content
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

Merged
merged 4 commits into from
Dec 29, 2016

Conversation

mbauman
Copy link
Member

@mbauman mbauman commented Dec 28, 2016

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

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))
Copy link
Contributor

@tkelman tkelman Dec 28, 2016

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

Copy link
Member Author

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.

@tkelman
Copy link
Contributor

tkelman commented Dec 28, 2016

just in case this might somehow be a hotspot? @nanosoldier runbenchmarks(ALL, vs = ":master")

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels

Copy link
Contributor

@tkelman tkelman left a 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]...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r::AbstractVector ?

Copy link
Member Author

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.

Copy link
Contributor

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

@JeffBezanson
Copy link
Member

Lots of PRs adding stuff at the end of deprecated.jl. Frustrating :(

@tkelman tkelman merged commit d7b6ac3 into JuliaLang:master Dec 29, 2016
@Sacha0 Sacha0 added deprecation This change introduces or involves a deprecation needs news A NEWS entry is required for this change labels May 20, 2017
Sacha0 added a commit to Sacha0/julia that referenced this pull request May 20, 2017
@Sacha0 Sacha0 removed the needs news A NEWS entry is required for this change label May 23, 2017
tkelman pushed a commit that referenced this pull request Jun 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecation This change introduces or involves a deprecation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants