Skip to content

Conversation

@mbauman
Copy link
Member

@mbauman mbauman commented Aug 6, 2015

This is my take on #12486. Easiest to just show what this enables:

julia> immutable SymInt{T} <: AbstractArray{T,2}
          a::Vector{T}
          b::Vector{T}
          c::Vector{T}
       end
julia> Base.size(A::SymInt) = (length(A.a), 3)
julia> Base.getindex(A::SymInt, f::Symbol, i::Int) = getfield(A, f)[i]
julia> Base.checkbounds(A::SymInt, I::AbstractVector{Symbol}, J::AbstractVector{Int}) = true # punt

julia> A = SymInt([1,2,3,4],[11,12,13,14],[21,22,23,24]);

julia> A[[:a, :b, :c], [1,2,3]]
3x3 Array{Int64,2}:
  1   2   3
 11  12  13
 21  22  23

julia> using Interpolations

julia> itp = interpolate(reshape(1:20., 4, 5), BSpline{Linear}, OnGrid);

julia> itp[linspace(1,4,1001), linspace(1,5,1001)]
1001x1001 Array{Float64,2}: 

But there are two problems:

julia> A[:b, :]
ERROR: indexing SymInt{Int64} with types Tuple{Symbol,Colon} is not supported
 in error at ./error.jl:21
 in _getindex at abstractarray.jl:480
 in getindex at abstractarray.jl:462
 in eval at REPL.jl:3

julia> (1:100)[1.:100.]
WARNING: indexing with non Integer Reals is deprecated
 in depwarn at ./deprecated.jl:63
 in _unsafe_getindex at multidimensional.jl:205
 in getindex at abstractarray.jl:462
while loading no file, in expression starting on line 0
WARNING: indexing with non Integer Reals is deprecated
 in depwarn at ./deprecated.jl:63
 in _unsafe_getindex at multidimensional.jl:205
 in getindex at abstractarray.jl:462
while loading no file, in expression starting on line 0
WARNING: indexing with non Integer Reals is deprecated
 in depwarn at ./deprecated.jl:63
 in _unsafe_getindex at multidimensional.jl:205
 in getindex at abstractarray.jl:462
while loading no file, in expression starting on line 0
# … (100x)

The first commit is definitely correct. We should do that no matter what. The second commit means that we get N deprecation warnings for indexing with an N-element array of floats. And I don't know how to structure dispatch so we can pass along unknown non-Array types to multidimensional indexing without ending up with stack overflows.

I need to stop working on this for now, but I wanted to push this so y'all can see what I'm thinking.

mbauman added 2 commits August 6, 2015 10:53
Simply pass everything straight through to the safe versions.
These two functions do very different things.  Multidimensional indexing only needs to call find on AbstractArray{Bool}, whereas scalar indexing needs to do the deprecated conversion from Real to Int.
@StefanKarpinski
Copy link
Member

Would it make sense to make a separate PR for the commit that should definitely be done and just merge that as soon as tests pass?

@timholy
Copy link
Member

timholy commented Aug 6, 2015

I'll play around with this a bit more, but like you maybe later 😄.

@mbauman
Copy link
Member Author

mbauman commented Aug 11, 2015

Superseded by #12540 and #12567.

@mbauman mbauman closed this Aug 11, 2015
@mbauman mbauman deleted the mb/generalizeindexing branch August 11, 2015 17:33
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

Successfully merging this pull request may close these issues.

4 participants