Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add default constructors for AbstractRange #48894

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e6784b9
add default constructors for AbstractRange
putianyi889 Mar 4, 2023
25f2021
Update range.jl
putianyi889 Mar 9, 2023
9f89130
whitespace
putianyi889 Mar 9, 2023
bc35354
add tests
putianyi889 Mar 10, 2023
0d588d4
whitespace
putianyi889 Mar 10, 2023
023b619
Merge branch 'JuliaLang:master' into patch-1
putianyi889 Mar 16, 2023
be8943e
add AbstractVector and AbstractArray constructor
putianyi889 Mar 16, 2023
52e7177
add tests
putianyi889 Mar 16, 2023
4e9740d
Update range.jl
putianyi889 Mar 17, 2023
32d838f
fix
putianyi889 Mar 17, 2023
7eb8b63
Update test/ranges.jl
putianyi889 Mar 25, 2024
5224278
Merge branch 'master' into patch-1
jishnub Aug 17, 2024
77a5a54
Update range.jl
putianyi889 Oct 30, 2024
6f16b36
add tests
putianyi889 Oct 30, 2024
7e53aa3
Merge branch 'master' into patch-1
putianyi889 Oct 30, 2024
db47bb9
support `StepRangeLen`, `LinRange`, move codes to promotion section
putianyi889 Oct 30, 2024
d148d2d
add tests
putianyi889 Oct 30, 2024
80c70af
Update ranges.jl
putianyi889 Oct 31, 2024
c13c97c
fix
putianyi889 Oct 31, 2024
3c01806
add tests
putianyi889 Oct 31, 2024
57854ee
Update range.jl
putianyi889 Oct 31, 2024
2e76189
whitespace
putianyi889 Oct 31, 2024
9324d21
Update ranges.jl
putianyi889 Oct 31, 2024
02b3d2f
Update range.jl
putianyi889 Oct 31, 2024
fdabcb5
fix
putianyi889 Oct 31, 2024
ebe820e
Update range.jl
putianyi889 Oct 31, 2024
ed0c891
Merge branch 'master' into patch-1
putianyi889 Nov 1, 2024
466ad24
Merge branch 'master' into patch-1
putianyi889 Nov 2, 2024
c28f960
Update abstractarray.jl
putianyi889 Nov 2, 2024
ba37c5f
Merge branch 'master' into patch-1
putianyi889 Nov 4, 2024
00905cb
Merge branch 'master' into patch-1
putianyi889 Nov 7, 2024
1163642
Merge branch 'master' into patch-1
putianyi889 Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ RangeStepStyle(::Type{<:AbstractRange{<:Integer}}) = RangeStepRegular()

convert(::Type{T}, r::AbstractRange) where {T<:AbstractRange} = r isa T ? r : T(r)::T

# there is no complex range
putianyi889 marked this conversation as resolved.
Show resolved Hide resolved
AbstractRange{T}(r::AbstractRange) where T<:Real = T(first(r)):T(step(r)):T(last(r))
AbstractArray{T,1}(r::AbstractRange) where T<:Real = AbstractRange{T}(r)
putianyi889 marked this conversation as resolved.
Show resolved Hide resolved
AbstractArray{T}(r::AbstractRange) where T<:Real = AbstractRange{T}(r)

## ordinal ranges

"""
Expand All @@ -287,6 +292,8 @@ Supertype for ranges with a step size of [`oneunit(T)`](@ref) with elements of t
"""
abstract type AbstractUnitRange{T} <: OrdinalRange{T,T} end

AbstractRange{T}(r::AbstractUnitRange) where {T<:Integer} = AbstractUnitRange{T}(r)

"""
StepRange{T, S} <: OrdinalRange{T, S}

Expand Down
3 changes: 3 additions & 0 deletions test/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,9 @@ end
@test convert(LinRange, 0.0:0.1:0.3) === LinRange{Float64}(0.0, 0.3, 4)
@test convert(LinRange, 0:3) === LinRange{Int}(0, 3, 4)

@test convert(AbstractRange{Int8},0:5) === convert(AbstractVector{Int8},0:5) ===convert(AbstractArray{Int8},0:5) === Int8(0):Int8(5)
putianyi889 marked this conversation as resolved.
Show resolved Hide resolved
@test convert(AbstractRange{Float64},0:5) === convert(AbstractVector{Float64},0:5) === convert(AbstractArray{Float64},0:5) === 0.:1.:5.

@test promote('a':'z', 1:2) === ('a':'z', 1:1:2)
@test eltype(['a':'z', 1:2]) == (StepRange{T,Int} where T)
end
Expand Down