Skip to content

Commit

Permalink
Convert AbstractUnitRange to OrdinalRange
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Jul 4, 2021
1 parent 09252b6 commit e5221b7
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 8 deletions.
5 changes: 0 additions & 5 deletions base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,6 @@ module IteratorsMD
indices = map(r->convert(OrdinalRangeInt, r), inds)
CartesianIndices{N, typeof(indices)}(indices)
end
# specialized method in case conversion to an OrdinalRange is not defined for the indices (see issue #40035)
function CartesianIndices(inds::NTuple{N,AbstractUnitRange{<:Integer}}) where {N}
indices = map(r->convert(AbstractUnitRange{Int}, r), inds)
CartesianIndices{N, typeof(indices)}(indices)
end

CartesianIndices(index::CartesianIndex) = CartesianIndices(index.I)
CartesianIndices(inds::NTuple{N,Union{<:Integer,OrdinalRange{<:Integer}}}) where {N} =
Expand Down
4 changes: 1 addition & 3 deletions base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1187,9 +1187,7 @@ AbstractUnitRange{T}(r::UnitRange) where {T} = UnitRange{T}(r)
AbstractUnitRange{T}(r::OneTo) where {T} = OneTo{T}(r)

OrdinalRange{T1, T2}(r::StepRange) where {T1, T2<: Integer} = StepRange{T1, T2}(r)
OrdinalRange{T1, T2}(r::AbstractUnitRange{T1}) where {T1, T2<:Integer} = r
OrdinalRange{T1, T2}(r::UnitRange) where {T1, T2<:Integer} = UnitRange{T1}(r)
OrdinalRange{T1, T2}(r::OneTo) where {T1, T2<:Integer} = OneTo{T1}(r)
OrdinalRange{T, T}(r::AbstractUnitRange) where {T<:Integer} = AbstractUnitRange{T}(r)

promote_rule(::Type{StepRange{T1a,T1b}}, ::Type{StepRange{T2a,T2b}}) where {T1a,T1b,T2a,T2b} =
el_same(promote_type(T1a,T2a),
Expand Down

0 comments on commit e5221b7

Please sign in to comment.