Closed dlfivefifty closed 3 years ago
The PR that changed this is https://github.com/JuliaLang/julia/pull/40320
One quick solution would be to only use StepRangeLen
if length is an integer:
_steprangelength(a, st, n::Int) = StepRangeLen(a, st, n)
_steprangelength(a, st, n) = range(a; step=st, length=n)
broadcasted(::DefaultArrayStyle{1}, ::typeof(*), x::Number, r::AbstractRange) = _steprangelength(x*first(r), x*step(r), length(r))
@mcabbott
That's a pity, we wondered if there would be edge cases. Re "only use StepRangeLen
if length is an Int
" [surely] this would mean they can't have zero step. Maybe nobody would ever want both at once?
Do many other things assume length(::AbstractVector)::Int
? Arrays too long to fit in 64 bits are pretty big. On Julia 1.6:
julia> ans'
1×100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 adjoint(::StepRange{BigInt, BigInt}) with eltype BigInt:
Error showing value of type Adjoint{BigInt, StepRange{BigInt, BigInt}}:
ERROR: InexactError: Int64(100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)
Stacktrace:
[1] Type
@ ./gmp.jl:362 [inlined]
[2] convert
@ ./number.jl:7 [inlined]
[3] to_index
@ ./indices.jl:292 [inlined]
Note the related commit that fixed many of these issues: https://github.com/JuliaLang/julia/pull/37741
I ran into this particular problem in InfiniteArrays.jl, where the length of the array is infinite. This has become an accepted use case:
I believe I can work around this particular issue as-is, albeit _steprangelength
function would be slightly cleaner. The other solution would be to add a type parameter for the length in StepRangeLen
, but that might count as a breaking change.
Though I have to say I don't understand why you didn't change Base.range_start_step_length
to return a StepRangeLen
?
From triage:
StepRangeLen
for the type of the length. That is generally not breaking, but it can turn a concrete type into an abstract type so some kinds of issues are possible. (@vtjnash is exploring this)
In Julia v1.7-beta:
Previously:
The issue is that
StepRangeLen
only allowsInt
lengths.