Skip to content

Commit 467010c

Browse files
committed
Deprecate manually vectorized clamp methods in favor of compact broadcast syntax.
1 parent 47fbd9c commit 467010c

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

base/deprecated.jl

+3
Original file line numberDiff line numberDiff line change
@@ -1000,4 +1000,7 @@ macro vectorize_2arg(S,f)
10001000
end
10011001
export @vectorize_1arg, @vectorize_2arg
10021002

1003+
# Deprecate manually vectorized clamp methods in favor of compact broadcast syntax
1004+
@deprecate clamp(A::AbstractArray, lo, hi) clamp.(A, lo, hi)
1005+
10031006
# End deprecations scheduled for 0.6

base/math.jl

+2-9
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ import Core.Intrinsics: sqrt_llvm, box, unbox, powi_llvm
3838
clamp(x, lo, hi)
3939
4040
Return `x` if `lo <= x <= hi`. If `x < lo`, return `lo`. If `x > hi`, return `hi`. Arguments
41-
are promoted to a common type. Operates elementwise over `x` if `x` is an array.
41+
are promoted to a common type.
4242
4343
```jldoctest
44-
julia> clamp([pi, 1.0, big(10.)], 2., 9.)
44+
julia> clamp.([pi, 1.0, big(10.)], 2., 9.)
4545
3-element Array{BigFloat,1}:
4646
3.141592653589793238462643383279502884197169399375105820974944592307816406286198
4747
2.000000000000000000000000000000000000000000000000000000000000000000000000000000
@@ -54,13 +54,6 @@ clamp{X,L,H}(x::X, lo::L, hi::H) =
5454
convert(promote_type(X,L,H), lo),
5555
convert(promote_type(X,L,H), x)))
5656

57-
clamp{T}(x::AbstractArray{T,1}, lo, hi) = [clamp(xx, lo, hi) for xx in x]
58-
clamp{T}(x::AbstractArray{T,2}, lo, hi) =
59-
[clamp(x[i,j], lo, hi) for i in indices(x,1), j in indices(x,2)]
60-
61-
clamp{T}(x::AbstractArray{T}, lo, hi) =
62-
reshape([clamp(xx, lo, hi) for xx in x], size(x))
63-
6457
"""
6558
clamp!(array::AbstractArray, lo, hi)
6659

test/math.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
@test clamp(3.0, 1, 3) == 3.0
1313
@test clamp(4.0, 1, 3) == 3.0
1414

15-
@test clamp([0, 1, 2, 3, 4], 1.0, 3.0) == [1.0, 1.0, 2.0, 3.0, 3.0]
16-
@test clamp([0 1; 2 3], 1.0, 3.0) == [1.0 1.0; 2.0 3.0]
15+
@test clamp.([0, 1, 2, 3, 4], 1.0, 3.0) == [1.0, 1.0, 2.0, 3.0, 3.0]
16+
@test clamp.([0 1; 2 3], 1.0, 3.0) == [1.0 1.0; 2.0 3.0]
1717

1818
@test !(pi == e)
1919
@test !(e == 1//2)

test/offsetarray.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ seek(io, 0)
313313
@test readdlm(io, eltype(A)) == parent(A)
314314

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

318318
@test unique(A, 1) == parent(A)
319319
@test unique(A, 2) == parent(A)

0 commit comments

Comments
 (0)