Skip to content

Commit

Permalink
Deprecate manually vectorized clamp methods in favor of compact broad…
Browse files Browse the repository at this point in the history
…cast syntax.
  • Loading branch information
Sacha0 committed Sep 20, 2016
1 parent 47fbd9c commit 467010c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
3 changes: 3 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1000,4 +1000,7 @@ macro vectorize_2arg(S,f)
end
export @vectorize_1arg, @vectorize_2arg

# Deprecate manually vectorized clamp methods in favor of compact broadcast syntax
@deprecate clamp(A::AbstractArray, lo, hi) clamp.(A, lo, hi)

# End deprecations scheduled for 0.6
11 changes: 2 additions & 9 deletions base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ import Core.Intrinsics: sqrt_llvm, box, unbox, powi_llvm
clamp(x, lo, hi)
Return `x` if `lo <= x <= hi`. If `x < lo`, return `lo`. If `x > hi`, return `hi`. Arguments
are promoted to a common type. Operates elementwise over `x` if `x` is an array.
are promoted to a common type.
```jldoctest
julia> clamp([pi, 1.0, big(10.)], 2., 9.)
julia> clamp.([pi, 1.0, big(10.)], 2., 9.)
3-element Array{BigFloat,1}:
3.141592653589793238462643383279502884197169399375105820974944592307816406286198
2.000000000000000000000000000000000000000000000000000000000000000000000000000000
Expand All @@ -54,13 +54,6 @@ clamp{X,L,H}(x::X, lo::L, hi::H) =
convert(promote_type(X,L,H), lo),
convert(promote_type(X,L,H), x)))

clamp{T}(x::AbstractArray{T,1}, lo, hi) = [clamp(xx, lo, hi) for xx in x]
clamp{T}(x::AbstractArray{T,2}, lo, hi) =
[clamp(x[i,j], lo, hi) for i in indices(x,1), j in indices(x,2)]

clamp{T}(x::AbstractArray{T}, lo, hi) =
reshape([clamp(xx, lo, hi) for xx in x], size(x))

"""
clamp!(array::AbstractArray, lo, hi)
Expand Down
4 changes: 2 additions & 2 deletions test/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
@test clamp(3.0, 1, 3) == 3.0
@test clamp(4.0, 1, 3) == 3.0

@test clamp([0, 1, 2, 3, 4], 1.0, 3.0) == [1.0, 1.0, 2.0, 3.0, 3.0]
@test clamp([0 1; 2 3], 1.0, 3.0) == [1.0 1.0; 2.0 3.0]
@test clamp.([0, 1, 2, 3, 4], 1.0, 3.0) == [1.0, 1.0, 2.0, 3.0, 3.0]
@test clamp.([0 1; 2 3], 1.0, 3.0) == [1.0 1.0; 2.0 3.0]

@test !(pi == e)
@test !(e == 1//2)
Expand Down
2 changes: 1 addition & 1 deletion test/offsetarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ seek(io, 0)
@test readdlm(io, eltype(A)) == parent(A)

amin, amax = extrema(parent(A))
@test clamp(A, (amax+amin)/2, amax) == clamp(parent(A), (amax+amin)/2, amax)
@test clamp.(A, (amax+amin)/2, amax).parent == clamp.(parent(A), (amax+amin)/2, amax)

@test unique(A, 1) == parent(A)
@test unique(A, 2) == parent(A)
Expand Down

0 comments on commit 467010c

Please sign in to comment.