Skip to content

Commit ba36f16

Browse files
Fix (colon,j...) indexing of ArrayPartition
Because ArrayPartition is an AbstractVector but allows a non-square indexing scheme, this confuses the defaults and thus this requires a specialization.
1 parent 8f61ca4 commit ba36f16

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/array_partition.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,18 @@ Base.@propagate_inbounds function Base.getindex(A::ArrayPartition, i::Int, j...)
219219
@inbounds return b[j...]
220220
end
221221

222+
"""
223+
getindex(A::ArrayPartition, i::Colon, j...)
224+
225+
Returns the entry at index `j...` of every partition of `A`.
226+
"""
227+
Base.@propagate_inbounds function Base.getindex(A::ArrayPartition, i::Colon, j...)
228+
@boundscheck 0 < i <= length(A.x) || throw(BoundsError(A.x, i))
229+
@inbounds b = A.x[i]
230+
@boundscheck checkbounds(b, j...)
231+
@inbounds return b[j...]
232+
end
233+
222234
"""
223235
getindex(A::ArrayPartition, ::Colon)
224236

test/partitions_test.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ copyto!(p,c)
5858
## inference tests
5959

6060
x = ArrayPartition([1, 2], [3.0, 4.0])
61+
@test x[:,1] == (1,3.0)
6162

6263
# similar partitions
6364
@inferred similar(x)

0 commit comments

Comments
 (0)