Skip to content

Commit 898c512

Browse files
committed
Deprecate vectorized functions in base/math.jl in favor of compact broadcast syntax.
1 parent 7003a9d commit 898c512

17 files changed

+43
-46
lines changed

base/deprecated.jl

+8
Original file line numberDiff line numberDiff line change
@@ -888,13 +888,15 @@ for f in (
888888
:gamma, :lfact, :digamma, :trigamma, :zeta, :eta,# base/special/gamma.jl
889889
:erfcx, :erfi, :dawson, # base/special/erf.jl
890890
:airyprime, :airyai, :airyaiprime, :airybi, :airybiprime, :airy, :airyx, :besselj0, :besselj1, :bessely0, :bessely1, # base/special/bessel.jl
891+
:cbrt, :sinh, :cosh, :tanh, :atan, :asinh, :exp, :erf, :erfc, :exp2, :expm1, :exp10, :sin, :cos, :tan, :asin, :acos, :acosh, :atanh, #=:log,=# :log2, :log10, :lgamma, #=:log1p,=# :sqrt, # base/math.jl
891892
)
892893
@eval @dep_vectorize_1arg Number $f
893894
end
894895
for f in (
895896
:sind, :cosd, :tand, :asind, :acosd, :atand, :asecd, :acscd, :acotd, # base/special/trig.jl
896897
:invdigamma, # base/special/gamma.jl
897898
:erfinc, :erfcinv, # base/special/erf.jl
899+
:rad2deg, :deg2rad, :exponent, :significand, # base/math.jl
898900
)
899901
@eval @dep_vectorize_1arg Real $f
900902
end
@@ -903,8 +905,14 @@ end
903905
for f in (
904906
:polygamma, :zeta, :beta, :lbeta, # base/special/gamma.jl
905907
:airy, :airyx, :besseli, :besselix, :besselj, :besseljx, :besselk, :besselkx, :bessely, :besselyx, :besselh, :besselhx, :hankelh1, :hankelh2, :hankelh1x, :hankelh2x, # base/special/bessel.jl
908+
:log, :hypot, :atan2, # base/math.jl
906909
)
907910
@eval @dep_vectorize_2arg Number $f
908911
end
912+
for f in (
913+
:max, :min, # base/math.jl
914+
)
915+
@eval @dep_vectorize_2arg Real $f
916+
end
909917

910918
# End deprecations scheduled for 0.6

base/irrationals.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ for T in (Irrational, Rational, Integer, Number)
174174
^(::Irrational{:e}, x::T) = exp(x)
175175
end
176176
for T in (Range, BitArray, StridedArray, AbstractArray)
177-
.^(::Irrational{:e}, x::T) = exp(x)
177+
.^(::Irrational{:e}, x::T) = exp.(x)
178178
end
179179

180180
log(::Irrational{:e}) = 1 # use 1 to correctly promote expressions like log(x)/log(e)

base/linalg/diagonal.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,9 @@ end
239239
# identity matrices via eye(Diagonal{type},n)
240240
eye{T}(::Type{Diagonal{T}}, n::Int) = Diagonal(ones(T,n))
241241

242-
expm(D::Diagonal) = Diagonal(exp(D.diag))
242+
expm(D::Diagonal) = Diagonal(exp.(D.diag))
243243
logm(D::Diagonal) = Diagonal(log.(D.diag))
244-
sqrtm(D::Diagonal) = Diagonal(sqrt(D.diag))
244+
sqrtm(D::Diagonal) = Diagonal(sqrt.(D.diag))
245245

246246
#Linear solver
247247
function A_ldiv_B!(D::Diagonal, B::StridedVecOrMat)

base/markdown/GitHub/table.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ end
7878
mapmap(f, xss) = map(xs->map(f, xs), xss)
7979

8080
colwidths(rows; len = length, min = 0) =
81-
reduce(max, [min; convert(Vector{Vector{Int}}, mapmap(len, rows))])
81+
reduce((x,y) -> max.(x,y), [min; convert(Vector{Vector{Int}}, mapmap(len, rows))])
8282

8383
padding(width, twidth, a) =
8484
a == :l ? (0, twidth - width) :

base/math.jl

-14
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,6 @@ julia> deg2rad(90)
146146
deg2rad(z::AbstractFloat) = z * (oftype(z, pi) / 180)
147147
rad2deg(z::Real) = rad2deg(float(z))
148148
deg2rad(z::Real) = deg2rad(float(z))
149-
@vectorize_1arg Real rad2deg
150-
@vectorize_1arg Real deg2rad
151149

152150
log{T<:Number}(b::T, x::T) = log(x)/log(b)
153151

@@ -165,7 +163,6 @@ julia> log(4,2)
165163
```
166164
"""
167165
log(b::Number, x::Number) = log(promote(b,x)...)
168-
@vectorize_2arg Number log
169166

170167
# type specific math functions
171168

@@ -178,7 +175,6 @@ for f in (:cbrt, :sinh, :cosh, :tanh, :atan, :asinh, :exp, :erf, :erfc, :exp2, :
178175
($f)(x::Float64) = ccall(($(string(f)),libm), Float64, (Float64,), x)
179176
($f)(x::Float32) = ccall(($(string(f,"f")),libm), Float32, (Float32,), x)
180177
($f)(x::Real) = ($f)(float(x))
181-
@vectorize_1arg Number $f
182178
end
183179
end
184180

@@ -230,7 +226,6 @@ end
230226
exp10(x::Float64) = 10.0^x
231227
exp10(x::Float32) = 10.0f0^x
232228
exp10(x::Integer) = exp10(float(x))
233-
@vectorize_1arg Number exp10
234229

235230
# utility for converting NaN return to DomainError
236231
@inline nan_dom_err(f, x) = isnan(f) & !isnan(x) ? throw(DomainError()) : f
@@ -242,7 +237,6 @@ for f in (:sin, :cos, :tan, :asin, :acos, :acosh, :atanh, :log, :log2, :log10,
242237
($f)(x::Float64) = nan_dom_err(ccall(($(string(f)),libm), Float64, (Float64,), x), x)
243238
($f)(x::Float32) = nan_dom_err(ccall(($(string(f,"f")),libm), Float32, (Float32,), x), x)
244239
($f)(x::Real) = ($f)(float(x))
245-
@vectorize_1arg Number $f
246240
end
247241
end
248242

@@ -256,7 +250,6 @@ Return ``\\sqrt{x}``. Throws `DomainError` for negative `Real` arguments. Use co
256250
negative arguments instead. The prefix operator `√` is equivalent to `sqrt`.
257251
"""
258252
sqrt(x::Real) = sqrt(float(x))
259-
@vectorize_1arg Number sqrt
260253

261254
"""
262255
hypot(x, y)
@@ -288,7 +281,6 @@ function hypot{T<:Number}(x::T, y::T)
288281
return rr
289282
end
290283
end
291-
@vectorize_2arg Number hypot
292284

293285
"""
294286
hypot(x...)
@@ -308,16 +300,13 @@ atan2{T<:AbstractFloat}(y::T, x::T) = Base.no_op_err("atan2", T)
308300

309301
atan2(y::Float64, x::Float64) = ccall((:atan2,libm), Float64, (Float64, Float64,), y, x)
310302
atan2(y::Float32, x::Float32) = ccall((:atan2f,libm), Float32, (Float32, Float32), y, x)
311-
@vectorize_2arg Number atan2
312303

313304
max{T<:AbstractFloat}(x::T, y::T) = ifelse((y > x) | (signbit(y) < signbit(x)),
314305
ifelse(isnan(y), x, y), ifelse(isnan(x), y, x))
315306

316-
@vectorize_2arg Real max
317307

318308
min{T<:AbstractFloat}(x::T, y::T) = ifelse((y < x) | (signbit(y) > signbit(x)),
319309
ifelse(isnan(y), x, y), ifelse(isnan(x), y, x))
320-
@vectorize_2arg Real min
321310

322311
minmax{T<:AbstractFloat}(x::T, y::T) = ifelse(isnan(x-y), ifelse(isnan(x), (y, y), (x, x)),
323312
ifelse((y < x) | (signbit(y) > signbit(x)), (y, x),
@@ -332,7 +321,6 @@ Compute ``x \\times 2^n``.
332321
"""
333322
ldexp(x::Float64,e::Integer) = ccall((:scalbn,libm), Float64, (Float64,Int32), x, Int32(e))
334323
ldexp(x::Float32,e::Integer) = ccall((:scalbnf,libm), Float32, (Float32,Int32), x, Int32(e))
335-
# TODO: vectorize ldexp
336324

337325
"""
338326
exponent(x) -> Int
@@ -353,7 +341,6 @@ function exponent{T<:AbstractFloat}(x::T)
353341
end
354342
k - exponent_bias(T)
355343
end
356-
@vectorize_1arg Real exponent
357344

358345
"""
359346
significand(x)
@@ -386,7 +373,6 @@ function significand{T<:AbstractFloat}(x::T)
386373
xu = (xu & ~exponent_mask(T)) | exponent_one(T)
387374
reinterpret(T,xu)
388375
end
389-
@vectorize_1arg Real significand
390376

391377
"""
392378
frexp(val)

test/bitarray.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -1092,8 +1092,8 @@ q[[1,3]] = true
10921092
@test map(^, p, q) == map((x,y)->x^y, p, q) == p .^ q
10931093
@test map(*, p, q) == map((x,y)->x*y, p, q) == p .* q
10941094

1095-
@test map(min, p, q) == map((x,y)->min(x,y), p, q) == min(p, q)
1096-
@test map(max, p, q) == map((x,y)->max(x,y), p, q) == max(p, q)
1095+
@test map(min, p, q) == map((x,y)->min(x,y), p, q) == min.(p, q)
1096+
@test map(max, p, q) == map((x,y)->max(x,y), p, q) == max.(p, q)
10971097

10981098
@test map(<, p, q) == map((x,y)->x<y, p, q) == (p .< q)
10991099
@test map(<=, p, q) == map((x,y)->x<=y, p, q) == (p .<= q)
@@ -1117,8 +1117,8 @@ r = falses(4)
11171117
@test map!(^, r, p, q) == map!((x,y)->x^y, r, p, q) == p .^ q == r
11181118
@test map!(*, r, p, q) == map!((x,y)->x*y, r, p, q) == p .* q == r
11191119

1120-
@test map!(min, r, p, q) == map!((x,y)->min(x,y), r, p, q) == min(p, q) == r
1121-
@test map!(max, r, p, q) == map!((x,y)->max(x,y), r, p, q) == max(p, q) == r
1120+
@test map!(min, r, p, q) == map!((x,y)->min(x,y), r, p, q) == min.(p, q) == r
1121+
@test map!(max, r, p, q) == map!((x,y)->max(x,y), r, p, q) == max.(p, q) == r
11221122

11231123
@test map!(<, r, p, q) == map!((x,y)->x<y, r, p, q) == (p .< q) == r
11241124
@test map!(<=, r, p, q) == map!((x,y)->x<=y, r, p, q) == (p .<= q) == r

test/broadcast.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ let A = [sqrt(i)+j for i = 1:3, j=1:4]
220220
@test atan2.(log.(A), sum(A,1)) == broadcast(atan2, broadcast(log, A), sum(A, 1))
221221
end
222222
let x = sin.(1:10)
223-
@test atan2.((x->x+1).(x), (x->x+2).(x)) == atan2(x+1, x+2) == atan2(x.+1, x.+2)
223+
@test atan2.((x->x+1).(x), (x->x+2).(x)) == broadcast(atan2, x+1, x+2) == broadcast(atan2, x.+1, x.+2)
224224
@test sin.(atan2.([x+1,x+2]...)) == sin.(atan2.(x+1,x+2))
225225
@test sin.(atan2.(x, 3.7)) == broadcast(x -> sin(atan2(x,3.7)), x)
226226
@test atan2.(x, 3.7) == broadcast(x -> atan2(x,3.7), x) == broadcast(atan2, x, 3.7)
@@ -235,7 +235,7 @@ end
235235
let x = sin.(1:10), a = [x]
236236
@test cos.(x) == cos.(a...)
237237
@test atan2.(x,x) == atan2.(a..., a...) == atan2.([x, x]...)
238-
@test atan2.(x, cos.(x)) == atan2.(a..., cos.(x)) == atan2(x, cos.(a...)) == atan2(a..., cos.(a...))
238+
@test atan2.(x, cos.(x)) == atan2.(a..., cos.(x)) == broadcast(atan2, x, cos.(a...)) == broadcast(atan2, a..., cos.(a...))
239239
@test ((args...)->cos(args[1])).(x) == cos.(x) == ((y,args...)->cos(y)).(x)
240240
end
241241
@test atan2.(3,4) == atan2(3,4) == (() -> atan2(3,4)).()

test/fft.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,14 @@ function fft_test{T<:Complex}(p::Base.DFT.Plan{T}, ntrials=4,
254254
z = zeros(T, n)
255255
i = rand(0:n-1)
256256
z[i+1] = 1
257-
X = exp(twopi_i*i)
257+
X = exp.(twopi_i*i)
258258
err = norm(p*z - X, Inf) / norm(X, Inf)
259259
err <= tol || error("impulse-response error $err in $p")
260260

261261
# time-shift:
262262
if n > 1
263263
s = rand(1:n-1)
264-
X = (p*x).*exp(twopi_i*s)
264+
X = (p*x).*exp.(twopi_i*s)
265265
err = norm(p*circshift(x,s) - X, Inf) / norm(X, Inf)
266266
err <= tol || error("time-shift error $err in $p")
267267
end

test/functional.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# TODO: @test map!() much more thoroughly
88
let a = [1.0, 2.0]
99
map!(sin, a)
10-
@test isequal(a, sin([1.0, 2.0]))
10+
@test isequal(a, sin.([1.0, 2.0]))
1111
end
1212
# map -- ranges.jl
1313
@test isequal(map(sqrt, 1:5), [sqrt(i) for i in 1:5])

test/linalg/arnoldi.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ end
193193

194194
debug && println("complex svds")
195195
let # complex svds test
196-
A = sparse([1, 1, 2, 3, 4], [2, 1, 1, 3, 1], exp(im*[2.0:2:10;]))
196+
A = sparse([1, 1, 2, 3, 4], [2, 1, 1, 3, 1], exp.(im*[2.0:2:10;]))
197197
S1 = svds(A, nsv = 2)
198198
S2 = svd(full(A))
199199

test/linalg/lapack.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ end
178178

179179
#gebal/gebak
180180
for elty in (Float32, Float64, Complex64, Complex128)
181-
A = rand(elty,10,10) * Diagonal(exp10(linspace(-10,10,10)))
181+
A = rand(elty,10,10) * Diagonal(exp10.(linspace(-10,10,10)))
182182
B = copy(A)
183183
ilo, ihi, scale = LAPACK.gebal!('S',B)
184184
Bvs = eigvecs(B)

test/math.jl

+7-7
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ end
196196
TAA = rand(2,2)
197197
TAA = (TAA + TAA.')/2.
198198
STAA = Symmetric(TAA)
199-
@test full(atanh(STAA)) == atanh(TAA)
200-
@test full(asinh(STAA)) == asinh(TAA)
201-
@test full(acosh(STAA+Symmetric(ones(TAA)))) == acosh(TAA+ones(TAA))
202-
@test full(acsch(STAA+Symmetric(ones(TAA)))) == acsch(TAA+ones(TAA))
203-
@test full(acoth(STAA+Symmetric(ones(TAA)))) == acoth(TAA+ones(TAA))
199+
@test full(atanh.(STAA)) == atanh.(TAA)
200+
@test full(asinh.(STAA)) == asinh.(TAA)
201+
@test full(acosh.(STAA+Symmetric(ones(TAA)))) == acosh.(TAA+ones(TAA))
202+
@test full(acsch.(STAA+Symmetric(ones(TAA)))) == acsch.(TAA+ones(TAA))
203+
@test full(acoth.(STAA+Symmetric(ones(TAA)))) == acoth.(TAA+ones(TAA))
204204

205205
# check exp2(::Integer) matches exp2(::Float)
206206
for ii in -2048:2048
@@ -220,8 +220,8 @@ end
220220

221221
for T in (Int, Float64, BigFloat)
222222
@test deg2rad(T(180)) 1pi
223-
@test deg2rad(T[45, 60]) [pi/T(4), pi/T(3)]
224-
@test rad2deg([pi/T(4), pi/T(3)]) [45, 60]
223+
@test deg2rad.(T[45, 60]) [pi/T(4), pi/T(3)]
224+
@test rad2deg.([pi/T(4), pi/T(3)]) [45, 60]
225225
@test rad2deg(T(1)*pi) 180
226226
@test rad2deg(T(1)) rad2deg(true)
227227
@test deg2rad(T(1)) deg2rad(true)

test/offsetarray.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,10 @@ e = eye(5)
349349
a = [e[:,1], e[:,2], e[:,3], e[:,4], e[:,5]]
350350
a1 = zeros(5)
351351
c = [ones(Complex{Float64}, 5),
352-
exp(-2*pi*im*(0:4)/5),
353-
exp(-4*pi*im*(0:4)/5),
354-
exp(-6*pi*im*(0:4)/5),
355-
exp(-8*pi*im*(0:4)/5)]
352+
exp.(-2*pi*im*(0:4)/5),
353+
exp.(-4*pi*im*(0:4)/5),
354+
exp.(-6*pi*im*(0:4)/5),
355+
exp.(-8*pi*im*(0:4)/5)]
356356
for s = -5:5
357357
for i = 1:5
358358
thisa = OffsetArray(a[i], (s,))

test/operators.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ p = 1=>:foo
5252
# issue #13144: max() with 4 or more array arguments
5353
let xs = [[i:i+4;] for i in 1:10]
5454
for n in 2:10
55-
@test max(xs[1:n]...) == [n:n+4;]
55+
@test max.(xs[1:n]...) == [n:n+4;]
5656
end
5757
end

test/reduce.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fz = float(z)
5555
@test sum(sin, [3]) == sin(3.0)
5656
a = sum(sin, z)
5757
@test a sum(sin, fz)
58-
@test a sum(sin(fz))
58+
@test a sum(sin.(fz))
5959

6060
z = [-4, -3, 2, 5]
6161
fz = float(z)

test/sparsedir/sparse.jl

+5-2
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ for f in (sum, prod, minimum, maximum)
377377
end
378378

379379
# case where f(0) would throw
380-
@test f(x->sqrt(x-1), pA+1) f(sqrt(pA))
380+
@test f(x->sqrt(x-1), pA+1) f(sqrt.(pA))
381381
# these actually throw due to #10533
382382
# @test f(x->sqrt(x-1), pA+1, 1) ≈ f(sqrt(pA), 1)
383383
# @test f(x->sqrt(x-1), pA+1, 2) ≈ f(sqrt(pA), 2)
@@ -1486,9 +1486,12 @@ let
14861486
@test min(A13024, B13024) == sparse([1,2,5], [1,2,5], fill(true,3))
14871487
@test typeof(min(A13024, B13024)) == SparseMatrixCSC{Bool,Int}
14881488

1489-
for op in (+, -, &, |, $, max, min)
1489+
for op in (+, -, &, |, $)
14901490
@test op(A13024, B13024) == op(full(A13024), full(B13024))
14911491
end
1492+
for op in (max, min)
1493+
@test op(A13024, B13024) == op.(full(A13024), full(B13024))
1494+
end
14921495
end
14931496

14941497
let A = 2. * speye(5,5)

test/statistics.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ X = [2 3 1 -1; 7 4 5 -4]
141141
@test std((1,2,3); mean=0) sqrt(7.0)
142142
@test std((1,2,3); mean=0, corrected=false) sqrt(14.0/3)
143143

144-
@test std([1 2 3 4 5; 6 7 8 9 10], 2) sqrt([2.5 2.5]')
145-
@test std([1 2 3 4 5; 6 7 8 9 10], 2; corrected=false) sqrt([2.0 2.0]')
144+
@test std([1 2 3 4 5; 6 7 8 9 10], 2) sqrt.([2.5 2.5]')
145+
@test std([1 2 3 4 5; 6 7 8 9 10], 2; corrected=false) sqrt.([2.0 2.0]')
146146

147147
A = Complex128[exp(i*im) for i in 1:10^4]
148148
@test varm(A,0.) sum(map(abs2,A))/(length(A)-1)

0 commit comments

Comments
 (0)