From e98df5facfd34ccd5fbeff593512b5ea5b66ebc9 Mon Sep 17 00:00:00 2001 From: Jan Weidner Date: Mon, 27 Mar 2017 20:30:07 +0200 Subject: [PATCH 1/2] deprecate `zeros(T, array)` and `ones(T, array)` --- base/deprecated.jl | 12 ++++++++++++ test/arrayops.jl | 11 +++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/base/deprecated.jl b/base/deprecated.jl index 7649120d70e2a..dc95156ebffb8 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1307,6 +1307,18 @@ end end end +# #19635 +for fname in (:ones, :zeros) + @eval @deprecate ($fname)(T::Type, arr) ($fname)(T, size(arr)) + @eval ($fname)(T::Type, i::Integer) = ($fname)(T, (i,)) + @eval function ($fname){T}(::Type{T}, arr::Array{T}) + msg = string("`", $fname, "{T}(::Type{T}, arr::Array{T})` is deprecated, use ", + "`", $fname , "(T, size(arr))` instead. ", + ) + error(msg) + end +end + # END 0.6 deprecations # BEGIN 1.0 deprecations diff --git a/test/arrayops.jl b/test/arrayops.jl index 4ad942d900bba..ca9bc0636ad2b 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -2054,12 +2054,11 @@ end zs = zeros(SparseMatrixCSC([1 2; 3 4]), Complex{Float64}, (2,3)) test_zeros(zs, SparseMatrixCSC{Complex{Float64}}, (2, 3)) - @testset "#19265" begin - @test_throws MethodError zeros(Float64, [1.]) - x = [1.] - test_zeros(zeros(x, Float64), Vector{Float64}, (1,)) - @test x == [1.] - end + # #19265" + @test_throws ErrorException zeros(Float64, [1.]) # TODO change to MethodError, when v0.6 deprecations are done + x = [1.] + test_zeros(zeros(x, Float64), Vector{Float64}, (1,)) + @test x == [1.] # exotic indexing oarr = zeros(randn(3), UInt16, 1:3, -1:0) From 5e54876fc6af1d74d8ba6e2c5c6aa59fab5598b1 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Mon, 3 Apr 2017 14:19:07 -0500 Subject: [PATCH 2/2] Adjust zeros, ones deprecations --- base/array.jl | 1 + base/deprecated.jl | 7 ------- test/arrayops.jl | 1 - 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/base/array.jl b/base/array.jl index 5de013272a606..f7209d34c0b79 100644 --- a/base/array.jl +++ b/base/array.jl @@ -247,6 +247,7 @@ for (fname, felt) in ((:zeros,:zero), (:ones,:one)) $fname(a::AbstractArray, T::Type, dims...) = fill!(similar(a,T,dims...), $felt(T)) $fname(a::AbstractArray, T::Type=eltype(a)) = fill!(similar(a,T), $felt(T)) + $fname(T::Type, n::Integer) = fill!(Vector{T}(n), $felt(T)) $fname(T::Type, dims::Tuple) = fill!(Array{T}(Dims(dims)), $felt(T)) $fname(dims::Tuple) = ($fname)(Float64, dims) $fname(T::Type, dims...) = $fname(T, dims) diff --git a/base/deprecated.jl b/base/deprecated.jl index dc95156ebffb8..8307a0d926a54 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1310,13 +1310,6 @@ end # #19635 for fname in (:ones, :zeros) @eval @deprecate ($fname)(T::Type, arr) ($fname)(T, size(arr)) - @eval ($fname)(T::Type, i::Integer) = ($fname)(T, (i,)) - @eval function ($fname){T}(::Type{T}, arr::Array{T}) - msg = string("`", $fname, "{T}(::Type{T}, arr::Array{T})` is deprecated, use ", - "`", $fname , "(T, size(arr))` instead. ", - ) - error(msg) - end end # END 0.6 deprecations diff --git a/test/arrayops.jl b/test/arrayops.jl index ca9bc0636ad2b..8d62250b53293 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -2055,7 +2055,6 @@ end test_zeros(zs, SparseMatrixCSC{Complex{Float64}}, (2, 3)) # #19265" - @test_throws ErrorException zeros(Float64, [1.]) # TODO change to MethodError, when v0.6 deprecations are done x = [1.] test_zeros(zeros(x, Float64), Vector{Float64}, (1,)) @test x == [1.]