diff --git a/base/deprecated.jl b/base/deprecated.jl index 02781b4948114..cabb751149f40 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1168,4 +1168,7 @@ for (dep, f, op) in [(:sumabs!, :sum!, :abs), end end +# 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 diff --git a/base/math.jl b/base/math.jl index 3a66be8ba45dd..235448a1fbe1b 100644 --- a/base/math.jl +++ b/base/math.jl @@ -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 @@ -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) diff --git a/test/math.jl b/test/math.jl index e3ae942dc4664..139e2b06319c8 100644 --- a/test/math.jl +++ b/test/math.jl @@ -13,8 +13,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] begin x = [0.0, 1.0, 2.0, 3.0, 4.0] clamp!(x, 1, 3) diff --git a/test/offsetarray.jl b/test/offsetarray.jl index 5698aa34cef0f..4890b9de84e4c 100644 --- a/test/offsetarray.jl +++ b/test/offsetarray.jl @@ -340,7 +340,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)