Skip to content

Commit 3962686

Browse files
authored
Merge pull request #148 from JuliaArrays/restore-fancy-indexing
Restore fancy APL indexing
2 parents e15b6a9 + 693e73b commit 3962686

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/indexing.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ end
9595
end
9696
end
9797

98-
@propagate_inbounds function getindex(a::StaticArray, inds::StaticArray{<:Any, Int})
98+
@propagate_inbounds function getindex(a::StaticArray, inds::StaticVector{<:Any, Int})
9999
_getindex(a, Length(inds), inds)
100100
end
101101

102-
@generated function _getindex(a::StaticArray, ::Length{L}, inds::StaticArray{<:Any, Int}) where {L}
102+
@generated function _getindex(a::StaticArray, ::Length{L}, inds::StaticVector{<:Any, Int}) where {L}
103103
exprs = [:(a[inds[$i]]) for i = 1:L]
104104
return quote
105105
@_propagate_inbounds_meta
@@ -142,20 +142,20 @@ end
142142
end
143143
end
144144

145-
@propagate_inbounds function setindex!(a::StaticArray, v, inds::StaticArray{<:Any, Int})
145+
@propagate_inbounds function setindex!(a::StaticArray, v, inds::StaticVector{<:Any, Int})
146146
_setindex!(a, v, Length(inds), inds)
147147
return v
148148
end
149149

150-
@generated function _setindex!(a::StaticArray, v, ::Length{L}, inds::StaticArray{<:Any, Int}) where {L}
150+
@generated function _setindex!(a::StaticArray, v, ::Length{L}, inds::StaticVector{<:Any, Int}) where {L}
151151
exprs = [:(a[inds[$i]] = v) for i = 1:L]
152152
return quote
153153
@_propagate_inbounds_meta
154154
similar_type(a, Size(L))(tuple($(exprs...)))
155155
end
156156
end
157157

158-
@generated function _setindex!(a::StaticArray, v::AbstractArray, ::Length{L}, inds::StaticArray{<:Any, Int}) where {L}
158+
@generated function _setindex!(a::StaticArray, v::AbstractArray, ::Length{L}, inds::StaticVector{<:Any, Int}) where {L}
159159
exprs = [:(a[$i] = v[$i]) for i = 1:L]
160160
return quote
161161
@_propagate_inbounds_meta
@@ -166,7 +166,7 @@ end
166166
end
167167
end
168168

169-
@generated function _setindex!(a::StaticArray, v::StaticArray, ::Length{L}, inds::StaticArray{<:Any, Int}) where {L}
169+
@generated function _setindex!(a::StaticArray, v::StaticArray, ::Length{L}, inds::StaticVector{<:Any, Int}) where {L}
170170
exprs = [:(a[$i] = v[$i]) for i = 1:L]
171171
return quote
172172
@_propagate_inbounds_meta

test/indexing.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
@test (v[SVector(2,3)] = [22,23]; (v[2] == 22) & (v[3] == 23))
5151
end
5252

53+
@testset "Fancy APL indexing" begin
54+
@test @SVector([1,2,3,4])[@SMatrix([1 2; 3 4])] === @SMatrix([1 2; 3 4])
55+
end
56+
5357
@testset "2D getindex() on SMatrix" begin
5458
sm = @SMatrix [1 3; 2 4]
5559

0 commit comments

Comments
 (0)