Skip to content

Commit 62af376

Browse files
authored
deprecate the roundmode method for centered (#251)
1 parent 2a678a7 commit 62af376

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/OffsetArrays.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ function center(A::AbstractArray, r::RoundingMode=RoundDown)
694694
end
695695

696696
"""
697-
centered(A, r::RoundingMode=RoundDown) -> Ao
697+
centered(A, cp=center(A)) -> Ao
698698
699699
Shift the center coordinate of array `A` to `(0, 0, ...)`. If `size(A, k)`
700700
is even, a rounding procedure will be applied with mode `r`.
@@ -718,10 +718,9 @@ Aoo[0, 0] == 5 # true
718718
true
719719
```
720720
721-
To query the center coordinate of the given array, you can
722-
instead use [`center`](@ref OffsetArrays.center).
721+
See also [`center`](@ref OffsetArrays.center).
723722
"""
724-
centered(A::AbstractArray, r::RoundingMode=RoundDown) = OffsetArray(A, .-center(A, r))
723+
centered(A::AbstractArray, cp::Dims=center(A)) = OffsetArray(A, .-cp)
725724

726725

727726
####
@@ -814,4 +813,12 @@ if Base.VERSION >= v"1.4.2"
814813
_precompile_()
815814
end
816815

816+
817+
##
818+
# Deprecations
819+
##
820+
821+
# This is a bad API design as it introduces counter intuitive results (#250)
822+
@deprecate centered(A::AbstractArray, r::RoundingMode) OffsetArray(A, .-center(A, r))
823+
817824
end # module

test/runtests.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2505,20 +2505,21 @@ end
25052505
@testset "centered" begin
25062506
A = reshape(collect(1:9), 3, 3)
25072507
Ao = OffsetArrays.centered(A)
2508+
@test OffsetArrays.centered(Ao) === Ao
2509+
@test OffsetArrays.centered(Ao, OffsetArrays.center(Ao)) === Ao
25082510
@test typeof(Ao) <: OffsetArray
25092511
@test parent(Ao) === A
25102512
@test Ao.offsets == (-2, -2)
25112513
@test Ao[0, 0] == 5
2512-
@test OffsetArrays.centered(A, RoundDown) == OffsetArrays.centered(A, RoundUp)
25132514

25142515
A = reshape(collect(1:6), 2, 3)
25152516
Ao = OffsetArrays.centered(A)
2516-
@test OffsetArrays.centered(A, RoundDown) == Ao
2517+
@test OffsetArrays.centered(A, OffsetArrays.center(A, RoundDown)) == Ao
25172518
@test typeof(Ao) <: OffsetArray
25182519
@test parent(Ao) === A
25192520
@test Ao.offsets == (-1, -2)
25202521
@test Ao[0, 0] == 3
2521-
Ao = OffsetArrays.centered(A, RoundUp)
2522+
Ao = OffsetArrays.centered(A, OffsetArrays.center(A, RoundUp))
25222523
@test typeof(Ao) <: OffsetArray
25232524
@test parent(Ao) === A
25242525
@test Ao.offsets == (-2, -2)
@@ -2546,3 +2547,9 @@ include("origin.jl")
25462547
@test OffsetArrays._addoffset(3:2:9, 1) isa AbstractRange{Int}
25472548
@test OffsetArrays._addoffset(3:2:9, 1) == 4:2:10
25482549
end
2550+
2551+
@info "Following deprecations are expected"
2552+
@testset "deprecations" begin
2553+
A = reshape(collect(1:9), 3, 3)
2554+
@test OffsetArrays.centered(A, RoundDown) == OffsetArrays.centered(A, RoundUp)
2555+
end

0 commit comments

Comments
 (0)