Skip to content

Commit

Permalink
Add Tuple(::CartesianIndex)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholters committed Sep 19, 2017
1 parent e34dba1 commit ae256f7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ module IteratorsMD

# indexing
getindex(index::CartesianIndex, i::Integer) = index.I[i]
eltype(index::CartesianIndex) = eltype(index.I)

# access to index tuple
Tuple(index::CartesianIndex) = index.I

# zeros and ones
zero(::CartesianIndex{N}) where {N} = zero(CartesianIndex{N})
Expand Down
2 changes: 2 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,8 @@ end
@test min(CartesianIndex((2,3)), CartesianIndex((5,2))) == CartesianIndex((2,2))
@test max(CartesianIndex((2,3)), CartesianIndex((5,2))) == CartesianIndex((5,3))

@test Tuple(I1) == (2,3,0)

# CartesianIndex allows construction at a particular dimensionality
@test length(CartesianIndex{3}()) == 3
@test length(CartesianIndex{3}(1,2)) == 3
Expand Down

0 comments on commit ae256f7

Please sign in to comment.