From 6f1e0c603ac34253e1f610522430ef039819a9f9 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Wed, 14 Sep 2016 14:07:10 -0700 Subject: [PATCH] Deprecate manually vectorized big methods in favor of compact broadcast syntax. --- base/complex.jl | 3 --- base/deprecated.jl | 16 ++++++++++++++++ base/float.jl | 14 +++++++++++--- base/linalg/bidiag.jl | 2 +- base/linalg/triangular.jl | 2 +- base/rational.jl | 1 - test/bigint.jl | 6 +++--- test/linalg/arnoldi.jl | 6 +++--- test/linalg/bidiag.jl | 2 +- test/linalg/generic.jl | 2 +- test/linalg/qr.jl | 4 ++-- test/linalg/triangular.jl | 4 ++-- test/numbers.jl | 4 ++-- test/random.jl | 8 ++++---- test/ranges.jl | 2 +- 15 files changed, 48 insertions(+), 28 deletions(-) diff --git a/base/complex.jl b/base/complex.jl index 95ca6ae4cdec2..4c1f837fb1f86 100644 --- a/base/complex.jl +++ b/base/complex.jl @@ -864,9 +864,6 @@ 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) - ## promotion to complex ## _default_type(T::Type{Complex}) = Complex{Int} diff --git a/base/deprecated.jl b/base/deprecated.jl index 02781b4948114..4e03698800a9e 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -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 diff --git a/base/float.jl b/base/float.jl index b89ec91e7c909..9183bb6a5eb35 100644 --- a/base/float.jl +++ b/base/float.jl @@ -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)) @@ -748,5 +748,13 @@ 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(::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 diff --git a/base/linalg/bidiag.jl b/base/linalg/bidiag.jl index 2dc1882f4e16e..cb025daa243e1 100644 --- a/base/linalg/bidiag.jl +++ b/base/linalg/bidiag.jl @@ -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) diff --git a/base/linalg/triangular.jl b/base/linalg/triangular.jl index a58e11eb57e57..869fc37489c95 100644 --- a/base/linalg/triangular.jl +++ b/base/linalg/triangular.jl @@ -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)) diff --git a/base/rational.jl b/base/rational.jl index 3304247d9783e..8066ecff200df 100644 --- a/base/rational.jl +++ b/base/rational.jl @@ -80,7 +80,6 @@ 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) 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)} diff --git a/test/bigint.jl b/test/bigint.jl index 0527f0bd9f49a..0e791a7be82e2 100644 --- a/test/bigint.jl +++ b/test/bigint.jl @@ -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 diff --git a/test/linalg/arnoldi.jl b/test/linalg/arnoldi.jl index 26e6653835c1f..84f43d3cdf764 100644 --- a/test/linalg/arnoldi.jl +++ b/test/linalg/arnoldi.jl @@ -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 diff --git a/test/linalg/bidiag.jl b/test/linalg/bidiag.jl index b5b8110a49b6e..86ec81adc80d2 100644 --- a/test/linalg/bidiag.jl +++ b/test/linalg/bidiag.jl @@ -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)) diff --git a/test/linalg/generic.jl b/test/linalg/generic.jl index 296e7f02fc2f0..f31b099a05fcd 100644 --- a/test/linalg/generic.jl +++ b/test/linalg/generic.jl @@ -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 diff --git a/test/linalg/qr.jl b/test/linalg/qr.jl index 8df1097b926d6..5e42c2375a614 100644 --- a/test/linalg/qr.jl +++ b/test/linalg/qr.jl @@ -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 diff --git a/test/linalg/triangular.jl b/test/linalg/triangular.jl index 3cb032ed9aa35..a20e9d0ae65c4 100644 --- a/test/linalg/triangular.jl +++ b/test/linalg/triangular.jl @@ -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) x̂ = 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)*γ) @@ -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) x̂ = 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)*γ) diff --git a/test/numbers.jl b/test/numbers.jl index d09f15a276394..c7a63156dd43f 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -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 diff --git a/test/random.jl b/test/random.jl index f988ae08f61a6..6d2e9ebcfc52e 100644 --- a/test/random.jl +++ b/test/random.jl @@ -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 diff --git a/test/ranges.jl b/test/ranges.jl index e75624be37ffc..4d8161da0a627 100644 --- a/test/ranges.jl +++ b/test/ranges.jl @@ -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))