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

one(::CartesianIndex) => oneunit(::CartesianIndex) #29442

Merged
merged 2 commits into from
Oct 5, 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
6 changes: 3 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ New language features
Language changes
----------------


Standard Library Changes
------------------------

Expand All @@ -21,8 +20,9 @@ Compiler/Runtime improvements

Deprecated or removed
---------------------

* `one(i::CartesianIndex)` should be replaced with `oneunit(i::CartesianIndex)` ([#29442]).

<!--- generated by NEWS-update.jl: -->
[#29440]: https://github.com/JuliaLang/julia/issues/29440
[#28156]: https://github.com/JuliaLang/julia/issues/28156
[#29440]: https://github.com/JuliaLang/julia/issues/29440
[#29442]: https://github.com/JuliaLang/julia/issues/29442
6 changes: 6 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,10 @@ function promote_eltype_op end

# BEGIN 1.0 deprecations

# @deprecate one(i::CartesianIndex) oneunit(i)
# @deprecate one(::Type{I}) where I<:CartesianIndex oneunit(I)
# TODO: deprecate these
one(::CartesianIndex{N}) where {N} = one(CartesianIndex{N})
one(::Type{CartesianIndex{N}}) where {N} = CartesianIndex(ntuple(x -> 1, Val(N)))

# END 1.0 deprecations
6 changes: 3 additions & 3 deletions base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
### Multidimensional iterators
module IteratorsMD
import .Base: eltype, length, size, first, last, in, getindex,
setindex!, IndexStyle, min, max, zero, one, isless, eachindex,
setindex!, IndexStyle, min, max, zero, oneunit, isless, eachindex,
ndims, IteratorSize, convert, show, iterate, promote_rule

import .Base: +, -, *, (:)
Expand Down Expand Up @@ -97,8 +97,8 @@ module IteratorsMD
# zeros and ones
zero(::CartesianIndex{N}) where {N} = zero(CartesianIndex{N})
zero(::Type{CartesianIndex{N}}) where {N} = CartesianIndex(ntuple(x -> 0, Val(N)))
one(::CartesianIndex{N}) where {N} = one(CartesianIndex{N})
one(::Type{CartesianIndex{N}}) where {N} = CartesianIndex(ntuple(x -> 1, Val(N)))
oneunit(::CartesianIndex{N}) where {N} = oneunit(CartesianIndex{N})
oneunit(::Type{CartesianIndex{N}}) where {N} = CartesianIndex(ntuple(x -> 1, Val(N)))

# arithmetic, min/max
@inline (-)(index::CartesianIndex{N}) where {N} =
Expand Down
8 changes: 4 additions & 4 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1691,13 +1691,13 @@ 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*one(I1) == CartesianIndex((3,4,1))
@test I1 - 2*one(I1) == CartesianIndex((0,1,-2))
@test I1 + 1*oneunit(I1) == CartesianIndex((3,4,1))
@test I1 - 2*oneunit(I1) == CartesianIndex((0,1,-2))

@test zero(CartesianIndex{2}) == CartesianIndex((0,0))
@test zero(CartesianIndex((2,3))) == CartesianIndex((0,0))
@test one(CartesianIndex{2}) == CartesianIndex((1,1))
@test one(CartesianIndex((2,3))) == CartesianIndex((1,1))
@test oneunit(CartesianIndex{2}) == CartesianIndex((1,1))
@test oneunit(CartesianIndex((2,3))) == CartesianIndex((1,1))

@test min(CartesianIndex((2,3)), CartesianIndex((5,2))) == CartesianIndex((2,2))
@test max(CartesianIndex((2,3)), CartesianIndex((5,2))) == CartesianIndex((5,3))
Expand Down