From c4aba4d3cf268a558e7911038d014a2308b57a63 Mon Sep 17 00:00:00 2001 From: Rafael Fourquet Date: Sat, 6 Jan 2018 10:40:36 +0100 Subject: [PATCH] deprecate rand(::Tuple) --- NEWS.md | 3 +++ stdlib/Random/src/Random.jl | 9 ++++----- stdlib/Random/src/deprecated.jl | 4 ++++ stdlib/Random/test/runtests.jl | 1 - stdlib/SharedArrays/test/runtests.jl | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/NEWS.md b/NEWS.md index df52fca162530..678025904dd18 100644 --- a/NEWS.md +++ b/NEWS.md @@ -941,6 +941,9 @@ Deprecated or removed have been deprecated. Subtypes of `AbstractArray` that implement the newly introduced strided array interface should define their own `strides` method ([#25321]). + * `rand(t::Tuple{Vararg{Int}})` is deprecated in favor of `rand(Float64, t)` or `rand(t...)`; + `rand(::Tuple)` will have another meaning in the future ([#25429], [#25278]). + Command-line option changes --------------------------- diff --git a/stdlib/Random/src/Random.jl b/stdlib/Random/src/Random.jl index 7ce0802274353..20ea4f923c472 100644 --- a/stdlib/Random/src/Random.jl +++ b/stdlib/Random/src/Random.jl @@ -220,10 +220,8 @@ function rand!(rng::AbstractRNG, A::AbstractArray{T}, sp::Sampler) where T A end -rand(r::AbstractRNG, dims::Dims) = rand(r, Float64, dims) -rand( dims::Dims) = rand(GLOBAL_RNG, dims) -rand(r::AbstractRNG, dims::Integer...) = rand(r, Dims(dims)) -rand( dims::Integer...) = rand(Dims(dims)) +rand(r::AbstractRNG, dims::Integer...) = rand(r, Float64, Dims(dims)) +rand( dims::Integer...) = rand(Float64, Dims(dims)) rand(r::AbstractRNG, X, dims::Dims) = rand!(r, Array{eltype(X)}(uninitialized, dims), X) rand( X, dims::Dims) = rand(GLOBAL_RNG, X, dims) @@ -273,7 +271,8 @@ Pick a random element or array of random elements from the set of values specifi integers (this is not applicable to [`BigInt`](@ref)), and to ``[0, 1)`` for floating point numbers; -`S` defaults to [`Float64`](@ref). +`S` defaults to [`Float64`](@ref) +(except when `dims` is a tuple of integers, in which case `S` must be specified). # Examples ```julia-repl diff --git a/stdlib/Random/src/deprecated.jl b/stdlib/Random/src/deprecated.jl index 1f6883275cdf1..c126d40ab5437 100644 --- a/stdlib/Random/src/deprecated.jl +++ b/stdlib/Random/src/deprecated.jl @@ -15,3 +15,7 @@ end @deprecate convert(::Type{UInt128}, u::UUID) UInt128(u) @deprecate convert(::Type{UUID}, s::AbstractString) UUID(s) + +# PR #25429 +@deprecate rand(r::AbstractRNG, dims::Dims) rand(r, Float64, dims) +@deprecate rand( dims::Dims) rand(Float64, dims) diff --git a/stdlib/Random/test/runtests.jl b/stdlib/Random/test/runtests.jl index 79856927a8ef3..2f4865c857389 100644 --- a/stdlib/Random/test/runtests.jl +++ b/stdlib/Random/test/runtests.jl @@ -355,7 +355,6 @@ for rng in ([], [MersenneTwister(0)], [RandomDevice()]) f(rng..., 5) ::Vector{Float64} f(rng..., 2, 3) ::Array{Float64, 2} f(rng..., b2, u3) ::Array{Float64, 2} - f(rng..., (2, 3)) ::Array{Float64, 2} for T in functypes[f] a0 = f(rng..., T) ::T a1 = f(rng..., T, 5) ::Vector{T} diff --git a/stdlib/SharedArrays/test/runtests.jl b/stdlib/SharedArrays/test/runtests.jl index f0ce9ad960114..9230a6b2e204c 100644 --- a/stdlib/SharedArrays/test/runtests.jl +++ b/stdlib/SharedArrays/test/runtests.jl @@ -78,7 +78,7 @@ copyto!(s, d) s = SharedArrays.shmem_rand(dims) copyto!(s, sdata(d)) @test s == d -a = rand(dims) +a = rand(Float64, dims) @test sdata(a) == a d = SharedArray{Int}(dims, init = D->fill!(D.loc_subarr_1d, myid()))