Skip to content

Commit 92cb220

Browse files
martinholtersKristofferC
authored andcommitted
Add Tuple(::CartesianIndex) (#23719)
1 parent 0b0cd8c commit 92cb220

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

base/multidimensional.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ module IteratorsMD
8888

8989
# indexing
9090
getindex(index::CartesianIndex, i::Integer) = index.I[i]
91+
eltype(index::CartesianIndex) = eltype(index.I)
92+
93+
# access to index tuple
94+
Tuple(index::CartesianIndex) = index.I
9195

9296
# zeros and ones
9397
zero(::CartesianIndex{N}) where {N} = zero(CartesianIndex{N})

test/arrayops.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,8 @@ end
15541554
@test min(CartesianIndex((2,3)), CartesianIndex((5,2))) == CartesianIndex((2,2))
15551555
@test max(CartesianIndex((2,3)), CartesianIndex((5,2))) == CartesianIndex((5,3))
15561556

1557+
@test Tuple(I1) == (2,3,0)
1558+
15571559
# CartesianIndex allows construction at a particular dimensionality
15581560
@test length(CartesianIndex{3}()) == 3
15591561
@test length(CartesianIndex{3}(1,2)) == 3

0 commit comments

Comments
 (0)