Skip to content

Commit

Permalink
Unary + operator for a single CartesianIndex (#54355)
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub authored May 20, 2024
1 parent 25227c1 commit 7b3072e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ module IteratorsMD
oneunit(::Type{CartesianIndex{N}}) where {N} = CartesianIndex(ntuple(Returns(1), Val(N)))

# arithmetic, min/max
@inline (+)(index::CartesianIndex) = index
@inline (-)(index::CartesianIndex{N}) where {N} =
CartesianIndex{N}(map(-, index.I))
@inline (+)(index1::CartesianIndex{N}, index2::CartesianIndex{N}) where {N} =
Expand Down
1 change: 1 addition & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2072,6 +2072,7 @@ end

I1 = CartesianIndex((2,3,0))
I2 = CartesianIndex((-1,5,2))
@test +I1 == I1
@test -I1 == CartesianIndex((-2,-3,0))
@test I1 + I2 == CartesianIndex((1,8,2))
@test I2 + I1 == CartesianIndex((1,8,2))
Expand Down

0 comments on commit 7b3072e

Please sign in to comment.