JuliaLang/julia
View on GitHubSupport `convert(AbstractArray{T}, ::AbstractRange)` and variants
Open
#27,138 opened on May 17, 2018
arrayshelp wanted
Repository metrics
- Stars
- (48,709 stars)
- PR merge metrics
- (Avg merge 20d 6h) (157 merged PRs in 30d)
Description
I'm surprised that converting the type of a range constructs a dense vector:
julia> AbstractVector{Float64}(1:10)
10-element Array{Float64,1}:
1.0
2.0
3.0
4.0
5.0
6.0
7.0
8.0
9.0
10.0
julia> convert(AbstractVector{Float64},1:10)
10-element Array{Float64,1}:
1.0
2.0
3.0
4.0
5.0
6.0
7.0
8.0
9.0
10.0
julia> convert(AbstractRange{Float64},1:10)
ERROR: MethodError: no method matching AbstractRange{Float64}(::UnitRange{Int64})
Closest candidates are:
AbstractRange{Float64}(::Any) where T<:AbstractArray at abstractarray.jl:22
Stacktrace:
[1] Type at ./abstractarray.jl:22 [inlined]
[2] convert(::Type{AbstractRange{Float64}}, ::UnitRange{Int64}) at ./range.jl:100
[3] top-level scope
I would expect all of the above to return 1.0:1.0:10.0.