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

Boolean mask indexing of a tuple #19719

Closed
cstjean opened this issue Dec 25, 2016 · 1 comment
Closed

Boolean mask indexing of a tuple #19719

cstjean opened this issue Dec 25, 2016 · 1 comment

Comments

@cstjean
Copy link
Contributor

cstjean commented Dec 25, 2016

Boolean indexing of tuples doesn't check bounds, but boolean indexing of vectors does.

julia> (1,2,3)[[true, false]]
(1,)

julia> (1,2,3)[[true, true, false, false, false]]
(1,2)

julia> [1,2,3][[true, false]]
ERROR: BoundsError: attempt to access 3-element Array{Int64,1} at index [Bool[true,false]]
 in throw_boundserror(::Array{Int64,1}, ::Tuple{Array{Bool,1}}) at ./abstractarray.jl:355
 in checkbounds at ./abstractarray.jl:284 [inlined]
 in _getindex at ./multidimensional.jl:270 [inlined]
 in getindex(::Array{Int64,1}, ::Array{Bool,1}) at ./abstractarray.jl:752

I can see a parallel with tuple assignment, so perhaps this was intentional? Is there an upside to allowing that? I could not find any discussion of it.

@tkelman
Copy link
Contributor

tkelman commented Dec 27, 2016

Seems to me like it should be bounds checking and this is a bug?

mbauman added a commit to mbauman/julia that referenced this issue 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 JuliaLang#19719
tkelman pushed a commit that referenced this issue Dec 29, 2016
* Check bounds for indexing tuples by logical masks

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

* Don't use the AbstractVector typealias
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants