Skip to content

Commit

Permalink
Deprecate manually vectorized big methods in favor of compact broadca…
Browse files Browse the repository at this point in the history
…st syntax.
  • Loading branch information
Sacha0 committed Dec 24, 2016
1 parent 44d7677 commit be04eb4
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 27 deletions.
4 changes: 2 additions & 2 deletions base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -864,8 +864,8 @@ function complex{T}(A::AbstractArray{T})
convert(AbstractArray{typeof(complex(zero(T)))}, A)
end

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

## promotion to complex ##

Expand Down
16 changes: 16 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1168,4 +1168,20 @@ for (dep, f, op) in [(:sumabs!, :sum!, :abs),
end
end

# Deprecate manually vectorized `big` methods in favor of compact broadcast syntax
@deprecate big(r::UnitRange) big.(r)
@deprecate big(r::StepRange) big.(r)
@deprecate big(r::FloatRange) big.(r)
@deprecate big(r::LinSpace) big.(r)
@deprecate big{T<:Integer,N}(x::AbstractArray{T,N}) big.(x)
@deprecate big{T<:AbstractFloat,N}(x::AbstractArray{T,N}) big.(x)
@deprecate big(A::LowerTriangular) big.(A)
@deprecate big(A::UpperTriangular) big.(A)
@deprecate big(A::Base.LinAlg.UnitLowerTriangular) big.(A)
@deprecate big(A::Base.LinAlg.UnitUpperTriangular) big.(A)
@deprecate big(B::Bidiagonal) big.(B)
@deprecate big{T<:Integer,N}(A::AbstractArray{Complex{T},N}) big.(A)
@deprecate big{T<:AbstractFloat,N}(A::AbstractArray{Complex{T},N}) big.(A)
@deprecate big{T<:Integer,N}(x::AbstractArray{Complex{Rational{T}},N}) big.(A)

# End deprecations scheduled for 0.6
16 changes: 13 additions & 3 deletions base/float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ function float{T}(A::AbstractArray{T})
convert(AbstractArray{typeof(float(zero(T)))}, A)
end

for fn in (:float,:big)
for fn in (:float,)
@eval begin
$fn(r::StepRange) = $fn(r.start):$fn(r.step):$fn(last(r))
$fn(r::UnitRange) = $fn(r.start):$fn(last(r))
Expand All @@ -748,5 +748,15 @@ for fn in (:float,:big)
end
end

big{T<:AbstractFloat,N}(x::AbstractArray{T,N}) = convert(AbstractArray{BigFloat,N}, x)
big{T<:Integer,N}(x::AbstractArray{T,N}) = convert(AbstractArray{BigInt,N}, x)
# big, broadcast over arrays
# TODO: do the definitions below primarily pertaining to integers belong in float.jl?
function big end # no prior definitions of big in sysimg.jl, necessitating this
broadcast{T<:Integer,N}(::typeof(big), x::AbstractArray{T,N}) = convert(AbstractArray{BigInt,N}, x)
broadcast{T<:AbstractFloat,N}(::typeof(big), x::AbstractArray{T,N}) = convert(AbstractArray{BigFloat,N}, x)
broadcast(::typeof(big), r::UnitRange) = big(r.start):big(last(r))
broadcast(::typeof(big), r::StepRange) = big(r.start):big(r.step):big(last(r))
broadcast(::typeof(big), r::FloatRange) = FloatRange(big(r.start), big(r.step), r.len, big(r.divisor))
function broadcast(::typeof(big), r::LinSpace)
big(r.len) == r.len || throw(ArgumentError(string(r, ": too long for ", big)))
LinSpace(big(r.start), big(r.stop), big(r.len), big(r.divisor))
end
2 changes: 1 addition & 1 deletion base/linalg/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ convert{Tnew,Told}(::Type{Bidiagonal{Tnew}}, A::Bidiagonal{Told}) = Bidiagonal(c
# When asked to convert Bidiagonal{Told} to AbstractMatrix{Tnew}, preserve structure by converting to Bidiagonal{Tnew} <: AbstractMatrix{Tnew}
convert{Tnew,Told}(::Type{AbstractMatrix{Tnew}}, A::Bidiagonal{Told}) = convert(Bidiagonal{Tnew}, A)

big(B::Bidiagonal) = Bidiagonal(big(B.dv), big(B.ev), B.isupper)
broadcast(::typeof(big), B::Bidiagonal) = Bidiagonal(big.(B.dv), big.(B.ev), B.isupper)

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

Expand Down
2 changes: 1 addition & 1 deletion base/linalg/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ for t in (:LowerTriangular, :UnitLowerTriangular, :UpperTriangular,

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

big(A::$t) = $t(big(A.data))
broadcast(::typeof(big), A::$t) = $t(big.(A.data))

real{T<:Real}(A::$t{T}) = A
real{T<:Complex}(A::$t{T}) = (B = real(A.data); $t(B))
Expand Down
3 changes: 2 additions & 1 deletion base/rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ convert(::Type{Rational}, x::Float64) = convert(Rational{Int64}, x)
convert(::Type{Rational}, x::Float32) = convert(Rational{Int}, x)

big{T<:Integer}(z::Complex{Rational{T}}) = Complex{Rational{BigInt}}(z)
big{T<:Integer,N}(x::AbstractArray{Complex{Rational{T}},N}) = convert(AbstractArray{Complex{Rational{BigInt}},N}, x)
broadcast{T<:Integer,N}(::typeof(big), x::AbstractArray{Complex{Rational{T}},N}) =
convert(AbstractArray{Complex{Rational{BigInt}},N}, x)

promote_rule{T<:Integer,S<:Integer}(::Type{Rational{T}}, ::Type{S}) = Rational{promote_type(T,S)}
promote_rule{T<:Integer,S<:Integer}(::Type{Rational{T}}, ::Type{Rational{S}}) = Rational{promote_type(T,S)}
Expand Down
6 changes: 3 additions & 3 deletions test/bigint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ ndigits_mismatch(n) = ndigits(n) != ndigits(BigInt(n))
@test !any(ndigits_mismatch, 8192:9999)

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

for i in big([-20:-1;1:20])
for i in big.([-20:-1;1:20])
for b in -10:1
@test_throws DomainError ndigits(i, b)
end
Expand Down
6 changes: 3 additions & 3 deletions test/linalg/arnoldi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ end
eigs(rand(1:10, 10, 10))
eigs(rand(1:10, 10, 10), rand(1:10, 10, 10) |> t -> t't)
svds(rand(1:10, 10, 8))
@test_throws MethodError eigs(big(rand(1:10, 10, 10)))
@test_throws MethodError eigs(big(rand(1:10, 10, 10)), rand(1:10, 10, 10))
@test_throws MethodError svds(big(rand(1:10, 10, 8)))
@test_throws MethodError eigs(big.(rand(1:10, 10, 10)))
@test_throws MethodError eigs(big.(rand(1:10, 10, 10)), rand(1:10, 10, 10))
@test_throws MethodError svds(big.(rand(1:10, 10, 8)))
end

# Symmetric generalized with singular B
Expand Down
2 changes: 1 addition & 1 deletion test/linalg/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ srand(1)
@test size(T) == (n, n)
@test Array(T) == diagm(dv) + diagm(ev, isupper?1:-1)
@test Bidiagonal(Array(T), isupper) == T
@test big(T) == T
@test big.(T) == T
@test Array(abs.(T)) == abs.(diagm(dv)) + abs.(diagm(ev, isupper?1:-1))
@test Array(real(T)) == real(diagm(dv)) + real(diagm(ev, isupper?1:-1))
@test Array(imag(T)) == imag(diagm(dv)) + imag(diagm(ev, isupper?1:-1))
Expand Down
2 changes: 1 addition & 1 deletion test/linalg/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ end
@test !issymmetric(NaN)

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

@test norm([2.4e-322, 4.4e-323]) 2.47e-322
@test norm([2.4e-322, 4.4e-323], 3) 2.4e-322
Expand Down
4 changes: 2 additions & 2 deletions test/linalg/qr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ end
@test_throws ErrorException ctranspose(qrfact(randn(3,3)))
@test_throws ErrorException transpose(qrfact(randn(3,3), Val{false}))
@test_throws ErrorException ctranspose(qrfact(randn(3,3), Val{false}))
@test_throws ErrorException transpose(qrfact(big(randn(3,3))))
@test_throws ErrorException ctranspose(qrfact(big(randn(3,3))))
@test_throws ErrorException transpose(qrfact(big.(randn(3,3))))
@test_throws ErrorException ctranspose(qrfact(big.(randn(3,3))))

# Issue 7304
let
Expand Down
4 changes: 2 additions & 2 deletions test/linalg/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int)
x = Atri \ b
γ = n*ε/(1 - n*ε)
if eltya != BigFloat
bigA = big(Atri)
bigA = big.(Atri)
= ones(n, 2)
for i = 1:size(b, 2)
@test norm(x̂[:,i] - x[:,i], Inf)/norm(x̂[:,i], Inf) <= condskeel(bigA, x̂[:,i])*γ/(1 - condskeel(bigA)*γ)
Expand Down Expand Up @@ -446,7 +446,7 @@ for eltya in (Float32, Float64, Complex64, Complex128, BigFloat, Int)
x = Atri \ b
γ = n*ε/(1 - n*ε)
if eltya != BigFloat
bigA = big(Atri)
bigA = big.(Atri)
= ones(n, 2)
for i = 1:size(b, 2)
@test norm(x̂[:,i] - x[:,i], Inf)/norm(x̂[:,i], Inf) <= condskeel(bigA, x̂[:,i])*γ/(1 - condskeel(bigA)*γ)
Expand Down
4 changes: 2 additions & 2 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2624,8 +2624,8 @@ end
for (d,B) in ((4//2+1im,Rational{BigInt}),(3.0+1im,BigFloat),(2+1im,BigInt))
@test typeof(big(d)) == Complex{B}
@test big(d) == d
@test typeof(big([d])) == Vector{Complex{B}}
@test big([d]) == [d]
@test typeof(big.([d])) == Vector{Complex{B}}
@test big.([d]) == [d]
end

# issue #12536
Expand Down
8 changes: 4 additions & 4 deletions test/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ ke = Array{UInt64}(ziggurat_table_size)
we = Array{Float64}(ziggurat_table_size)
fe = Array{Float64}(ziggurat_table_size)
function randmtzig_fill_ziggurat_tables() # Operates on the global arrays
wib = big(wi)
fib = big(fi)
web = big(we)
feb = big(fe)
wib = big.(wi)
fib = big.(fi)
web = big.(we)
feb = big.(fe)
# Ziggurat tables for the normal distribution
x1 = ziggurat_nor_r
wib[256] = x1/nmantissa
Expand Down
2 changes: 1 addition & 1 deletion test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ test_linspace_identity(linspace(1f0, 1f0, 1), linspace(-1f0, -1f0, 1))
for _r in (1:2:100, 1:100, 1f0:2f0:100f0, 1.0:2.0:100.0,
linspace(1, 100, 10), linspace(1f0, 100f0, 10))
float_r = float(_r)
big_r = big(_r)
big_r = big.(_r)
@test typeof(big_r).name === typeof(_r).name
if eltype(_r) <: AbstractFloat
@test isa(float_r, typeof(_r))
Expand Down

0 comments on commit be04eb4

Please sign in to comment.