Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate adding integers to CartesianIndex #26284

Merged
merged 1 commit into from
Mar 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Deprecate adding integers to CartesianIndex
fixes #26227
  • Loading branch information
mbauman committed Mar 1, 2018
commit e721972be9a4c6908eba214468fc8fa5d9c4c84f
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,9 @@ Library improvements
collection `A`. There are also two other methods with a different API, and
a mutating variant, `replace!` ([#22324]).

* Adding integers to `CartesianIndex` objects is now deprecated. Instead of
`i::Int + x::CartesianIndex`, use `i*one(x) + x` ([#26284]).

* `CartesianRange` changes ([#24715]):
- Inherits from `AbstractArray`, and linear indexing can be used to provide
linear-to-cartesian conversion ([#24715])
Expand Down
6 changes: 6 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,12 @@ end
@deprecate reprmime(mime, x) repr(mime, x)
@deprecate mimewritable(mime, x) showable(mime, x)

# PR #26284
@deprecate (+)(i::Integer, index::CartesianIndex) (i*one(index) + index)
@deprecate (+)(index::CartesianIndex, i::Integer) (index + i*one(index))
@deprecate (-)(i::Integer, index::CartesianIndex) (i*one(index) - index)
@deprecate (-)(index::CartesianIndex, i::Integer) (index - i*one(index))

# PR #23332
@deprecate ^(x, p::Integer) Base.power_by_squaring(x,p)

Expand Down
6 changes: 1 addition & 5 deletions base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ module IteratorsMD
@inline max(index1::CartesianIndex{N}, index2::CartesianIndex{N}) where {N} =
CartesianIndex{N}(map(max, index1.I, index2.I))

@inline (+)(i::Integer, index::CartesianIndex) = index+i
@inline (+)(index::CartesianIndex{N}, i::Integer) where {N} = CartesianIndex{N}(map(x->x+i, index.I))
@inline (-)(index::CartesianIndex{N}, i::Integer) where {N} = CartesianIndex{N}(map(x->x-i, index.I))
@inline (-)(i::Integer, index::CartesianIndex{N}) where {N} = CartesianIndex{N}(map(x->i-x, index.I))
@inline (*)(a::Integer, index::CartesianIndex{N}) where {N} = CartesianIndex{N}(map(x->a*x, index.I))
@inline (*)(index::CartesianIndex, a::Integer) = *(a,index)

Expand Down Expand Up @@ -279,7 +275,7 @@ module IteratorsMD
@inline function start(iter::CartesianIndices)
iterfirst, iterlast = first(iter), last(iter)
if any(map(>, iterfirst.I, iterlast.I))
return iterlast+1
return iterlast+one(iterlast)
end
iterfirst
end
Expand Down
4 changes: 2 additions & 2 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1616,8 +1616,8 @@ end
@test I2 + I1 == CartesianIndex((1,8,2))
@test I1 - I2 == CartesianIndex((3,-2,-2))
@test I2 - I1 == CartesianIndex((-3,2,2))
@test I1 + 1 == CartesianIndex((3,4,1))
@test I1 - 2 == CartesianIndex((0,1,-2))
@test I1 + 1*one(I1) == CartesianIndex((3,4,1))
@test I1 - 2*one(I1) == CartesianIndex((0,1,-2))

@test zero(CartesianIndex{2}) == CartesianIndex((0,0))
@test zero(CartesianIndex((2,3))) == CartesianIndex((0,0))
Expand Down