Skip to content

Commit e5a07f9

Browse files
committed
Deprecate manually vectorized big methods in favor of compact broadcast syntax.
1 parent 155147e commit e5a07f9

16 files changed

+56
-28
lines changed

base/broadcast.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ module Broadcast
55
using Base.Cartesian
66
using Base: promote_eltype_op, @get!, _msk_end, unsafe_bitgetindex, linearindices, tail, OneTo, to_shape
77
import Base: .+, .-, .*, ./, .\, .//, .==, .<, .!=, .<=, , .%, .<<, .>>, .^
8-
export broadcast, broadcast!, bitbroadcast, dotview
8+
import Base: broadcast
9+
export broadcast!, bitbroadcast, dotview
910
export broadcast_getindex, broadcast_setindex!
1011

1112
## Broadcasting utilities ##

base/complex.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -828,8 +828,8 @@ function complex{T}(A::AbstractArray{T})
828828
convert(AbstractArray{typeof(complex(zero(T)))}, A)
829829
end
830830

831-
big{T<:Integer,N}(A::AbstractArray{Complex{T},N}) = convert(AbstractArray{Complex{BigInt},N}, A)
832-
big{T<:AbstractFloat,N}(A::AbstractArray{Complex{T},N}) = convert(AbstractArray{Complex{BigFloat},N}, A)
831+
broadcast{T<:Integer,N}(::typeof(big), A::AbstractArray{Complex{T},N}) = convert(AbstractArray{Complex{BigInt},N}, A)
832+
broadcast{T<:AbstractFloat,N}(::typeof(big), A::AbstractArray{Complex{T},N}) = convert(AbstractArray{Complex{BigFloat},N}, A)
833833

834834
## promotion to complex ##
835835

base/deprecated.jl

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

1003+
# Deprecate manually vectorized `big` methods in favor of compact broadcast syntax
1004+
@deprecate big(r::UnitRange) big.(r)
1005+
@deprecate big(r::StepRange) big.(r)
1006+
@deprecate big(r::FloatRange) big.(r)
1007+
@deprecate big(r::LinSpace) big.(r)
1008+
@deprecate big{T<:Integer,N}(x::AbstractArray{T,N}) big.(x)
1009+
@deprecate big{T<:AbstractFloat,N}(x::AbstractArray{T,N}) big.(x)
1010+
@deprecate big(A::LowerTriangular) big.(A)
1011+
@deprecate big(A::UpperTriangular) big.(A)
1012+
@deprecate big(A::Base.LinAlg.UnitLowerTriangular) big.(A)
1013+
@deprecate big(A::Base.LinAlg.UnitUpperTriangular) big.(A)
1014+
@deprecate big(B::Bidiagonal) big.(B)
1015+
@deprecate big{T<:Integer,N}(A::AbstractArray{Complex{T},N}) big.(A)
1016+
@deprecate big{T<:AbstractFloat,N}(A::AbstractArray{Complex{T},N}) big.(A)
1017+
@deprecate big{T<:Integer,N}(x::AbstractArray{Complex{Rational{T}},N}) big.(A)
1018+
10031019
# End deprecations scheduled for 0.6

base/float.jl

+13-3
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ function float{T}(A::AbstractArray{T})
541541
convert(AbstractArray{typeof(float(zero(T)))}, A)
542542
end
543543

544-
for fn in (:float,:big)
544+
for fn in (:float,)
545545
@eval begin
546546
$fn(r::StepRange) = $fn(r.start):$fn(r.step):$fn(last(r))
547547
$fn(r::UnitRange) = $fn(r.start):$fn(last(r))
@@ -554,5 +554,15 @@ for fn in (:float,:big)
554554
end
555555
end
556556

557-
big{T<:AbstractFloat,N}(x::AbstractArray{T,N}) = convert(AbstractArray{BigFloat,N}, x)
558-
big{T<:Integer,N}(x::AbstractArray{T,N}) = convert(AbstractArray{BigInt,N}, x)
557+
# big, broadcast over arrays
558+
# TODO: do the definitions below primarily pertaining to integers belong in float.jl?
559+
function big end # no prior definitions of big in sysimg.jl, necessitating this
560+
broadcast{T<:Integer,N}(::typeof(big), x::AbstractArray{T,N}) = convert(AbstractArray{BigInt,N}, x)
561+
broadcast{T<:AbstractFloat,N}(::typeof(big), x::AbstractArray{T,N}) = convert(AbstractArray{BigFloat,N}, x)
562+
broadcast(::typeof(big), r::UnitRange) = big(r.start):big(last(r))
563+
broadcast(::typeof(big), r::StepRange) = big(r.start):big(r.step):big(last(r))
564+
broadcast(::typeof(big), r::FloatRange) = FloatRange(big(r.start), big(r.step), r.len, big(r.divisor))
565+
function broadcast(::typeof(big), r::LinSpace)
566+
big(r.len) == r.len || throw(ArgumentError(string(r, ": too long for ", big)))
567+
LinSpace(big(r.start), big(r.stop), big(r.len), big(r.divisor))
568+
end

base/linalg/bidiag.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ convert{Tnew,Told}(::Type{Bidiagonal{Tnew}}, A::Bidiagonal{Told}) = Bidiagonal(c
148148
# When asked to convert Bidiagonal{Told} to AbstractMatrix{Tnew}, preserve structure by converting to Bidiagonal{Tnew} <: AbstractMatrix{Tnew}
149149
convert{Tnew,Told}(::Type{AbstractMatrix{Tnew}}, A::Bidiagonal{Told}) = convert(Bidiagonal{Tnew}, A)
150150

151-
big(B::Bidiagonal) = Bidiagonal(big(B.dv), big(B.ev), B.isupper)
151+
broadcast(::typeof(big), B::Bidiagonal) = Bidiagonal(big.(B.dv), big.(B.ev), B.isupper)
152152

153153
similar{T}(B::Bidiagonal, ::Type{T}) = Bidiagonal{T}(similar(B.dv, T), similar(B.ev, T), B.isupper)
154154

base/linalg/triangular.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ for t in (:LowerTriangular, :UnitLowerTriangular, :UpperTriangular,
3232

3333
copy(A::$t) = $t(copy(A.data))
3434

35-
big(A::$t) = $t(big(A.data))
35+
broadcast(::typeof(big), A::$t) = $t(big.(A.data))
3636

3737
real{T<:Real}(A::$t{T}) = A
3838
real{T<:Complex}(A::$t{T}) = (B = real(A.data); $t(B))

base/rational.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ convert(::Type{Rational}, x::Float64) = convert(Rational{Int64}, x)
8282
convert(::Type{Rational}, x::Float32) = convert(Rational{Int}, x)
8383

8484
big{T<:Integer}(z::Complex{Rational{T}}) = Complex{Rational{BigInt}}(z)
85-
big{T<:Integer,N}(x::AbstractArray{Complex{Rational{T}},N}) = convert(AbstractArray{Complex{Rational{BigInt}},N}, x)
85+
broadcast{T<:Integer,N}(::typeof(big), x::AbstractArray{Complex{Rational{T}},N}) =
86+
convert(AbstractArray{Complex{Rational{BigInt}},N}, x)
8687

8788
promote_rule{T<:Integer,S<:Integer}(::Type{Rational{T}}, ::Type{S}) = Rational{promote_type(T,S)}
8889
promote_rule{T<:Integer,S<:Integer}(::Type{Rational{T}}, ::Type{Rational{S}}) = Rational{promote_type(T,S)}

test/bigint.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,10 @@ ndigits_mismatch(n) = ndigits(n) != ndigits(BigInt(n))
275275
@test !any(ndigits_mismatch, 8192:9999)
276276

277277
# The following should not crash (#16579)
278-
ndigits(rand(big(-999:999)), rand(63:typemax(Int)))
279-
ndigits(rand(big(-999:999)), big(2)^rand(2:999))
278+
ndigits(rand(big.(-999:999)), rand(63:typemax(Int)))
279+
ndigits(rand(big.(-999:999)), big(2)^rand(2:999))
280280

281-
for i in big([-20:-1;1:20])
281+
for i in big.([-20:-1;1:20])
282282
for b in -10:1
283283
@test_throws DomainError ndigits(i, b)
284284
end

test/linalg/arnoldi.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ end
228228
eigs(rand(1:10, 10, 10))
229229
eigs(rand(1:10, 10, 10), rand(1:10, 10, 10) |> t -> t't)
230230
svds(rand(1:10, 10, 8))
231-
@test_throws MethodError eigs(big(rand(1:10, 10, 10)))
232-
@test_throws MethodError eigs(big(rand(1:10, 10, 10)), rand(1:10, 10, 10))
233-
@test_throws MethodError svds(big(rand(1:10, 10, 8)))
231+
@test_throws MethodError eigs(big.(rand(1:10, 10, 10)))
232+
@test_throws MethodError eigs(big.(rand(1:10, 10, 10)), rand(1:10, 10, 10))
233+
@test_throws MethodError svds(big.(rand(1:10, 10, 8)))
234234

235235
# Symmetric generalized with singular B
236236
let

test/linalg/bidiag.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ for relty in (Int, Float32, Float64, BigFloat), elty in (relty, Complex{relty})
6464
@test size(T) == (n, n)
6565
@test full(T) == diagm(dv) + diagm(ev, isupper?1:-1)
6666
@test Bidiagonal(full(T), isupper) == T
67-
@test big(T) == T
67+
@test big.(T) == T
6868
@test full(abs.(T)) == abs.(diagm(dv)) + abs.(diagm(ev, isupper?1:-1))
6969
@test full(real(T)) == real(diagm(dv)) + real(diagm(ev, isupper?1:-1))
7070
@test full(imag(T)) == imag(diagm(dv)) + imag(diagm(ev, isupper?1:-1))

test/linalg/generic.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ for elty in [Float32,Float64,Complex64,Complex128]
224224
end
225225

226226
@test rank([1.0 0.0; 0.0 0.9],0.95) == 1
227-
@test qr(big([0 1; 0 0]))[2] == [0 1; 0 0]
227+
@test qr(big.([0 1; 0 0]))[2] == [0 1; 0 0]
228228

229229
@test norm([2.4e-322, 4.4e-323]) 2.47e-322
230230
@test norm([2.4e-322, 4.4e-323], 3) 2.4e-322

test/linalg/qr.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ end
148148
@test_throws ErrorException ctranspose(qrfact(randn(3,3)))
149149
@test_throws ErrorException transpose(qrfact(randn(3,3), Val{false}))
150150
@test_throws ErrorException ctranspose(qrfact(randn(3,3), Val{false}))
151-
@test_throws ErrorException transpose(qrfact(big(randn(3,3))))
152-
@test_throws ErrorException ctranspose(qrfact(big(randn(3,3))))
151+
@test_throws ErrorException transpose(qrfact(big.(randn(3,3))))
152+
@test_throws ErrorException ctranspose(qrfact(big.(randn(3,3))))
153153

154154
# Issue 7304
155155
let

test/linalg/triangular.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int)
417417
x = Atri \ b
418418
γ = n*ε/(1 - n*ε)
419419
if eltya != BigFloat
420-
bigA = big(Atri)
420+
bigA = big.(Atri)
421421
= ones(n, 2)
422422
for i = 1:size(b, 2)
423423
@test norm(x̂[:,i] - x[:,i], Inf)/norm(x̂[:,i], Inf) <= condskeel(bigA, x̂[:,i])*γ/(1 - condskeel(bigA)*γ)
@@ -446,7 +446,7 @@ for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int)
446446
x = Atri \ b
447447
γ = n*ε/(1 - n*ε)
448448
if eltya != BigFloat
449-
bigA = big(Atri)
449+
bigA = big.(Atri)
450450
= ones(n, 2)
451451
for i = 1:size(b, 2)
452452
@test norm(x̂[:,i] - x[:,i], Inf)/norm(x̂[:,i], Inf) <= condskeel(bigA, x̂[:,i])*γ/(1 - condskeel(bigA)*γ)

test/numbers.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -2603,8 +2603,8 @@ end
26032603
for (d,B) in ((4//2+1im,Rational{BigInt}),(3.0+1im,BigFloat),(2+1im,BigInt))
26042604
@test typeof(big(d)) == Complex{B}
26052605
@test big(d) == d
2606-
@test typeof(big([d])) == Vector{Complex{B}}
2607-
@test big([d]) == [d]
2606+
@test typeof(big.([d])) == Vector{Complex{B}}
2607+
@test big.([d]) == [d]
26082608
end
26092609

26102610
# issue #12536

test/random.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ ke = Array{UInt64}(ziggurat_table_size)
133133
we = Array{Float64}(ziggurat_table_size)
134134
fe = Array{Float64}(ziggurat_table_size)
135135
function randmtzig_fill_ziggurat_tables() # Operates on the global arrays
136-
wib = big(wi)
137-
fib = big(fi)
138-
web = big(we)
139-
feb = big(fe)
136+
wib = big.(wi)
137+
fib = big.(fi)
138+
web = big.(we)
139+
feb = big.(fe)
140140
# Ziggurat tables for the normal distribution
141141
x1 = ziggurat_nor_r
142142
wib[256] = x1/nmantissa

test/ranges.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ test_linspace_identity(linspace(1f0, 1f0, 1), linspace(-1f0, -1f0, 1))
659659
for _r in (1:2:100, 1:100, 1f0:2f0:100f0, 1.0:2.0:100.0,
660660
linspace(1, 100, 10), linspace(1f0, 100f0, 10))
661661
float_r = float(_r)
662-
big_r = big(_r)
662+
big_r = big.(_r)
663663
@test typeof(big_r).name === typeof(_r).name
664664
if eltype(_r) <: AbstractFloat
665665
@test isa(float_r, typeof(_r))

0 commit comments

Comments
 (0)