Skip to content

Commit f383276

Browse files
yurivishtimholy
authored andcommitted
Remove default value 50 from linspace and logspace n arguments (#24805)
* Remove default value 50 from linspace and logspace `n` arguments Fixes #24794.
1 parent 116fbce commit f383276

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,8 @@ Deprecated or removed
13061306
13071307
* `EnvHash` has been renamed to `EnvDict` ([#24167]).
13081308
1309+
* `linspace` and `logspace` now require an explicit number of elements to be supplied rather than defaulting to `50`.
1310+
13091311
Command-line option changes
13101312
---------------------------
13111313

base/deprecated.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,6 +2133,9 @@ finalizer(f::Ptr{Void}, o::Function) = invoke(finalizer, Tuple{Ptr{Void}, Any},
21332133
Base.@deprecate_binding broadcast_t broadcast false ", broadcast_t(f, ::Type{ElType}, shape, iter, As...)` should become `broadcast(f, Broadcast.DefaultArrayStyle{N}(), ElType, shape, As...))` (see the manual chapter Interfaces)"
21342134
end
21352135

2136+
# issue #24794
2137+
@deprecate linspace(start, stop) linspace(start, stop, 50)
2138+
@deprecate logspace(start, stop) logspace(start, stop, 50)
21362139

21372140
# END 0.7 deprecations
21382141

base/range.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ function LinSpace(start, stop, len::Integer)
232232
end
233233

234234
"""
235-
linspace(start, stop, n=50)
235+
linspace(start, stop, n)
236236
237237
Construct a range of `n` linearly spaced elements from `start` to `stop`.
238238
@@ -241,8 +241,8 @@ julia> linspace(1.3,2.9,9)
241241
1.3:0.2:2.9
242242
```
243243
"""
244-
linspace(start, stop, len::Real=50) = linspace(promote(start, stop)..., Int(len))
245-
linspace(start::T, stop::T, len::Real=50) where {T} = linspace(start, stop, Int(len))
244+
linspace(start, stop, len::Real) = linspace(promote(start, stop)..., Int(len))
245+
linspace(start::T, stop::T, len::Real) where {T} = linspace(start, stop, Int(len))
246246

247247
linspace(start::Real, stop::Real, len::Integer) = linspace(promote(start, stop)..., len)
248248
linspace(start::T, stop::T, len::Integer) where {T<:Integer} = linspace(Float64, start, stop, len, 1)
@@ -318,7 +318,7 @@ function print_range(io::IO, r::AbstractRange,
318318
end
319319

320320
"""
321-
logspace(start::Real, stop::Real, n::Integer=50; base=10)
321+
logspace(start::Real, stop::Real, n::Integer; base=10)
322322
323323
Construct a vector of `n` logarithmically spaced numbers from `base^start` to `base^stop`.
324324
@@ -340,7 +340,7 @@ julia> logspace(1.,10.,5,base=2)
340340
1024.0
341341
```
342342
"""
343-
logspace(start::Real, stop::Real, n::Integer=50; base=10) = base.^linspace(start, stop, n)
343+
logspace(start::Real, stop::Real, n::Integer; base=10) = base.^linspace(start, stop, n)
344344

345345
## interface implementations
346346

test/ranges.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ let r = @inferred(colon(big(1.0),big(2.0),big(5.0)))
11391139
end
11401140

11411141
@testset "issue #14420" begin
1142-
for r in (linspace(0.10000000000000045, 1), 0.10000000000000045:(1-0.10000000000000045)/49:1)
1142+
for r in (linspace(0.10000000000000045, 1, 50), 0.10000000000000045:(1-0.10000000000000045)/49:1)
11431143
local r
11441144
@test r[1] === 0.10000000000000045
11451145
@test r[end] === 1.0
@@ -1191,11 +1191,11 @@ end
11911191

11921192
@testset "logspace" begin
11931193
n = 10; a = 2; b = 4
1194-
# test default values; n = 50, base = 10
1195-
@test logspace(a, b) == logspace(a, b, 50) == 10 .^ linspace(a, b, 50)
1194+
# test default values; base = 10
1195+
@test logspace(a, b, 50) == 10 .^ linspace(a, b, 50)
11961196
@test logspace(a, b, n) == 10 .^ linspace(a, b, n)
11971197
for base in (10, 2, ℯ)
1198-
@test logspace(a, b, base=base) == logspace(a, b, 50, base=base) == base.^linspace(a, b, 50)
1198+
@test logspace(a, b, 50, base=base) == base.^linspace(a, b, 50)
11991199
@test logspace(a, b, n, base=base) == base.^linspace(a, b, n)
12001200
end
12011201
end

0 commit comments

Comments
 (0)