Skip to content

Commit e5a07f9

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

File tree

16 files changed

+56
-28
lines changed

16 files changed

+56
-28
lines changed

base/broadcast.jl

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 16 additions & 0 deletions
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

Lines changed: 13 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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))

0 commit comments

Comments
 (0)