From a2cddffec8bbfc00c23f044b68ca272b17c7ceb7 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Tue, 13 Feb 2018 15:24:34 -0800 Subject: [PATCH] Deprecate logspace to its definition --- NEWS.md | 2 ++ base/deprecated.jl | 3 ++- base/exports.jl | 1 - base/range.jl | 27 +-------------------------- doc/src/base/arrays.md | 1 - examples/lru_test.jl | 2 +- test/compiler/compiler.jl | 5 +++-- test/ranges.jl | 11 ----------- 8 files changed, 9 insertions(+), 43 deletions(-) diff --git a/NEWS.md b/NEWS.md index 2c7596d62ff6e..d55352225dde4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1042,6 +1042,8 @@ Deprecated or removed * `LinSpace` has been renamed to `LinRange` ([#25896]). + * `logspace` has been deprecated to its definition ([#25896]). + * `endof(a)` has been renamed to `lastindex(a)`, and the `end` keyword in indexing expressions now lowers to either `lastindex(a)` (in the case with only one index) or `lastindex(a, d)` (in cases where there is more than one index and `end` appears at dimension `d`) ([#23554], [#25763]). diff --git a/base/deprecated.jl b/base/deprecated.jl index 3fa7c9e97ef16..5c8b575b9b745 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -841,7 +841,7 @@ end # issue #24794 @deprecate linspace(start, stop) range(start, stop=stop, length=50) -@deprecate logspace(start, stop) logspace(start, stop, 50) +@deprecate logspace(start, stop) exp10.(range(start, stop=stop, length=50)) # 24490 - warnings and messages const log_info_to = Dict{Tuple{Union{Module,Nothing},Union{Symbol,Nothing}},IO}() @@ -1318,6 +1318,7 @@ export readandwrite @deprecate linspace(start, stop, length::Integer) range(start, stop=stop, length=length) @deprecate linspace(start, stop, length::Real) range(start, stop=stop, length=Int(length)) @deprecate_binding LinSpace LinRange +@deprecate logspace(start, stop, n; base=10) base.^range(start, stop=stop, length=n) @deprecate runtests(tests, ncores; kw...) runtests(tests; ncores = ncores, kw...) false @deprecate code_lowered(f, types, generated) code_lowered(f, types, generated = generated) diff --git a/base/exports.jl b/base/exports.jl index 6c51c57e48d35..7c53e12a1b858 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -395,7 +395,6 @@ export issorted, last, linearindices, - logspace, mapslices, max, maximum!, diff --git a/base/range.jl b/base/range.jl index 1ee8ea84a1eeb..26f994a0d14d9 100644 --- a/base/range.jl +++ b/base/range.jl @@ -235,7 +235,7 @@ StepRangeLen(ref::R, step::S, len::Integer, offset::Integer = 1) where {R,S} = StepRangeLen{T}(ref::R, step::S, len::Integer, offset::Integer = 1) where {T,R,S} = StepRangeLen{T,R,S}(ref, step, len, offset) -## range with computed step, and logspace +## range with computed step struct LinRange{T} <: AbstractRange{T} start::T @@ -335,31 +335,6 @@ function print_range(io::IO, r::AbstractRange, end end -""" - logspace(start::Real, stop::Real, n::Integer; base=10) - -Construct a vector of `n` logarithmically spaced numbers from `base^start` to `base^stop`. - -```jldoctest -julia> logspace(1.,10.,5) -5-element Array{Float64,1}: - 10.0 - 1778.2794100389228 - 316227.7660168379 - 5.623413251903491e7 - 1.0e10 - -julia> logspace(1.,10.,5,base=2) -5-element Array{Float64,1}: - 2.0 - 9.513656920021768 - 45.254833995939045 - 215.2694823049509 - 1024.0 -``` -""" -logspace(start::Real, stop::Real, n::Integer; base=10) = base.^range(start, stop=stop, length=n) - ## interface implementations size(r::AbstractRange) = (length(r),) diff --git a/doc/src/base/arrays.md b/doc/src/base/arrays.md index 399f5b6d4244e..6ea60b55c4d19 100644 --- a/doc/src/base/arrays.md +++ b/doc/src/base/arrays.md @@ -32,7 +32,6 @@ Base.fill Base.fill! Base.similar(::AbstractArray) Base.similar(::Any, ::Tuple) -Base.logspace ``` ## Basic functions diff --git a/examples/lru_test.jl b/examples/lru_test.jl index 21b4e5b668cdc..5c797c2a57906 100644 --- a/examples/lru_test.jl +++ b/examples/lru_test.jl @@ -10,7 +10,7 @@ get_str(i) = String(vcat(map(x->[x>>4; x&0x0F], reinterpret(UInt8, [Int32(i)])). isbounded(::Type{L}) where {L<:LRUExample.LRU} = any(map(n->n==:maxsize, fieldnames(L))) isbounded(l::L) where {L<:LRUExample.LRU} = isbounded(L) -nmax = round.(Int, logspace(2, 5, 4)) +nmax = map(x->round(Int, exp10(x)), range(2, stop=5, length=4)) function lrutest() #println("LRU consistency tests") diff --git a/test/compiler/compiler.jl b/test/compiler/compiler.jl index 4a398562a708a..0e98dd31d242d 100644 --- a/test/compiler/compiler.jl +++ b/test/compiler/compiler.jl @@ -585,8 +585,9 @@ tpara18457(::Type{A}) where {A<:AbstractMyType18457} = tpara18457(supertype(A)) function FOO_19322(Y::AbstractMatrix; frac::Float64=0.3, nbins::Int=100, n_sims::Int=100) num_iters, num_chains = size(Y) - start_iters = unique([1; [round(Int64, s) for s in logspace(log(10,100), - log(10,num_iters/2),nbins-1)]]) + start_iters = unique([1; map(s->round(Int64, exp10(s)), range(log(10,100), + stop=log(10,num_iters/2), + length=nbins-1))]) result = zeros(Float64, 10, length(start_iters) * num_chains) j=1 for c in 1:num_chains diff --git a/test/ranges.jl b/test/ranges.jl index 3c69148f88253..570570638e107 100644 --- a/test/ranges.jl +++ b/test/ranges.jl @@ -1209,17 +1209,6 @@ end @test Float32(linsp.ref) ≈ linsp.ref.hi + linsp.ref.lo end -@testset "logspace" begin - n = 10; a = 2; b = 4 - # test default values; base = 10 - @test logspace(a, b, 50) == 10 .^ range(a, stop=b, length=50) - @test logspace(a, b, n) == 10 .^ range(a, stop=b, length=n) - for base in (10, 2, ℯ) - @test logspace(a, b, 50, base=base) == base.^range(a, stop=b, length=50) - @test logspace(a, b, n, base=base) == base.^range(a, stop=b, length=n) - end -end - @testset "issue #23300" begin x = -5:big(1.0):5 @test map(Float64, x) === -5.0:1.0:5.0