Skip to content

Commit

Permalink
Merge pull request #102 from JuliaArrays/remove-tuple-indexing
Browse files Browse the repository at this point in the history
Remove indexing of AbstractArray with Tuple
  • Loading branch information
c42f committed Feb 13, 2017
2 parents cc22922 + 9c97716 commit 7f610e0
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 38 deletions.
25 changes: 0 additions & 25 deletions src/indexing.jl
Expand Up @@ -13,31 +13,6 @@
end
end

# Tuple indexing into AbstractArray. TODO, move into base
@generated function getindex{S}(a::AbstractArray, inds::NTuple{S,Integer})
exprs = [:(a[inds[$i]]) for i = 1:S]
return quote
$(Expr(:meta, :inline, :propagate_inbounds))
return $(Expr(:tuple, exprs...))
end
end
# Convert to StaticArrays using tuples
# TODO think about bounds checks here.
@generated function getindex{S,T}(m::AbstractArray{T}, inds1::NTuple{S, Integer}, i2::Integer)
exprs = [:(m[inds1[$j], i2]) for j = 1:S]
return Expr(:tuple, exprs...)
end

@generated function getindex{S,T}(m::AbstractArray{T}, i1::Integer, inds2::NTuple{S, Integer})
exprs = [:(m[i1, inds2[$j]]) for j = 1:S]
return Expr(:tuple, exprs...)
end

@generated function getindex{S1,S2,T}(m::AbstractArray{T}, inds1::NTuple{S1, Integer}, inds2::NTuple{S2, Integer})
exprs = [:(m[inds1[$j1], inds2[$j2]]) for j1 = 1:S1, j2 = 1:S2]
return Expr(:call, SMatrix{S1,S2,T}, Expr(:tuple, exprs...)) # TODO decision: return tuple? Leave it?
end

# Static Vector indexing into AbstractArrays
@generated function getindex{T, I <: Integer}(
a::AbstractArray{T}, inds::StaticVector{I}
Expand Down
13 changes: 0 additions & 13 deletions test/indexing.jl
Expand Up @@ -23,13 +23,8 @@

@testset "Linear getindex()/setindex!() with a SVector on an Array" begin
v = [11,12,13]
m = [1.0 2.0; 3.0 4.0]

@test v[(2,3)] === (12, 13)
@test m[(2,3)] === (3.0, 2.0)

@test (v[SVector(2,3)] = [22,23]; (v[2] == 22) & (v[3] == 23))

end

@testset "2D getindex() on SMatrix" begin
Expand Down Expand Up @@ -70,14 +65,6 @@
@test (mm = MMatrix{2,2,Int}(); mm[:,1] = sm[:,1]; (@inferred getindex(mm, :, 1))::MVector == @MVector [1,2])
end

@testset "2D getindex() with tuples on an Array" begin
m = [1.0 2.0; 3.0 4.0]

@test m[(1,2), (1,2)] === @SMatrix [1.0 2.0; 3.0 4.0]
@test m[1, (1,2)] === (1.0, 2.0)
@test m[(1,2), 1] === (1.0, 3.0)
end

@testset "3D scalar indexing" begin
sa = SArray{(2,2,2), Int}([i*j*k for i = 1:2, j = 2:3, k=3:4])

Expand Down

0 comments on commit 7f610e0

Please sign in to comment.