Skip to content

Commit 9c97716

Browse files
author
Chris Foster
committed
Remove indexing of AbstractArray with Tuple
Two pirates walk into a bar dragging a heavy chest. As they open it the barman reels back in horror, glimpsing the unchanging rectangular pattern inside. "Get out you filthy scum, we don't serve your type of pirates here" Resolves #101
1 parent cc22922 commit 9c97716

File tree

2 files changed

+0
-38
lines changed

2 files changed

+0
-38
lines changed

src/indexing.jl

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,6 @@
1313
end
1414
end
1515

16-
# Tuple indexing into AbstractArray. TODO, move into base
17-
@generated function getindex{S}(a::AbstractArray, inds::NTuple{S,Integer})
18-
exprs = [:(a[inds[$i]]) for i = 1:S]
19-
return quote
20-
$(Expr(:meta, :inline, :propagate_inbounds))
21-
return $(Expr(:tuple, exprs...))
22-
end
23-
end
24-
# Convert to StaticArrays using tuples
25-
# TODO think about bounds checks here.
26-
@generated function getindex{S,T}(m::AbstractArray{T}, inds1::NTuple{S, Integer}, i2::Integer)
27-
exprs = [:(m[inds1[$j], i2]) for j = 1:S]
28-
return Expr(:tuple, exprs...)
29-
end
30-
31-
@generated function getindex{S,T}(m::AbstractArray{T}, i1::Integer, inds2::NTuple{S, Integer})
32-
exprs = [:(m[i1, inds2[$j]]) for j = 1:S]
33-
return Expr(:tuple, exprs...)
34-
end
35-
36-
@generated function getindex{S1,S2,T}(m::AbstractArray{T}, inds1::NTuple{S1, Integer}, inds2::NTuple{S2, Integer})
37-
exprs = [:(m[inds1[$j1], inds2[$j2]]) for j1 = 1:S1, j2 = 1:S2]
38-
return Expr(:call, SMatrix{S1,S2,T}, Expr(:tuple, exprs...)) # TODO decision: return tuple? Leave it?
39-
end
40-
4116
# Static Vector indexing into AbstractArrays
4217
@generated function getindex{T, I <: Integer}(
4318
a::AbstractArray{T}, inds::StaticVector{I}

test/indexing.jl

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,8 @@
2323

2424
@testset "Linear getindex()/setindex!() with a SVector on an Array" begin
2525
v = [11,12,13]
26-
m = [1.0 2.0; 3.0 4.0]
27-
28-
@test v[(2,3)] === (12, 13)
29-
@test m[(2,3)] === (3.0, 2.0)
3026

3127
@test (v[SVector(2,3)] = [22,23]; (v[2] == 22) & (v[3] == 23))
32-
3328
end
3429

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

73-
@testset "2D getindex() with tuples on an Array" begin
74-
m = [1.0 2.0; 3.0 4.0]
75-
76-
@test m[(1,2), (1,2)] === @SMatrix [1.0 2.0; 3.0 4.0]
77-
@test m[1, (1,2)] === (1.0, 2.0)
78-
@test m[(1,2), 1] === (1.0, 3.0)
79-
end
80-
8168
@testset "3D scalar indexing" begin
8269
sa = SArray{(2,2,2), Int}([i*j*k for i = 1:2, j = 2:3, k=3:4])
8370

0 commit comments

Comments
 (0)