Skip to content

Commit

Permalink
one(::CartesianIndex) => oneunit(::CartesianIndex) (#29442)
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy authored Oct 5, 2018
1 parent 1968b23 commit 50c27fd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
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

0 comments on commit 50c27fd

Please sign in to comment.