Skip to content

Commit

Permalink
Rename Range to AbstractRange (#23570)
Browse files Browse the repository at this point in the history
* Rename Range to AbstractRange

* Change "a" to "an" before AbstractRange

* Update syntax files under contrib/

Rename Range to AbstractRange, and Range1 to UnitRange (which should
have been done before).

* Add deprecation and NEWS entry

* Fix incorrect replacements

* Address review comments
  • Loading branch information
nalimilan authored and mbauman committed Sep 8, 2017
1 parent ca01a0b commit 02fba85
Show file tree
Hide file tree
Showing 40 changed files with 161 additions and 157 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ Deprecated or removed
* `select`, `select!`, `selectperm` and `selectperm!` have been renamed respectively to
`partialsort`, `partialsort!`, `partialsortperm` and `partialsortperm!` ([#23051]).

* The `Range` abstract type has been renamed to `AbstractRange` ([#23570]).

Command-line option changes
---------------------------

Expand Down
32 changes: 16 additions & 16 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ indices1(A::AbstractArray) = (@_inline_meta; indices(A)[1])
indices1(iter) = OneTo(length(iter))

unsafe_indices(A) = indices(A)
unsafe_indices(r::Range) = (OneTo(unsafe_length(r)),) # Ranges use checked_sub for size
unsafe_indices(r::AbstractRange) = (OneTo(unsafe_length(r)),) # Ranges use checked_sub for size

"""
linearindices(A)
Expand Down Expand Up @@ -171,8 +171,8 @@ first(a::AbstractArray) = a[first(eachindex(a))]
"""
first(coll)
Get the first element of an iterable collection. Returns the start point of a
`Range` even if it is empty.
Get the first element of an iterable collection. Returns the start point of an
`AbstractRange` even if it is empty.
# Examples
```jldoctest
Expand All @@ -194,7 +194,7 @@ end
Get the last element of an ordered collection, if it can be computed in O(1) time. This is
accomplished by calling [`endof`](@ref) to get the last index. Returns the end
point of a `Range` even if it is empty.
point of an `AbstractRange` even if it is empty.
# Examples
```jldoctest
Expand Down Expand Up @@ -324,7 +324,7 @@ IndexStyle(A::AbstractArray) = IndexStyle(typeof(A))
IndexStyle(::Type{Union{}}) = IndexLinear()
IndexStyle(::Type{<:AbstractArray}) = IndexCartesian()
IndexStyle(::Type{<:Array}) = IndexLinear()
IndexStyle(::Type{<:Range}) = IndexLinear()
IndexStyle(::Type{<:AbstractRange}) = IndexLinear()

IndexStyle(A::AbstractArray, B::AbstractArray) = IndexStyle(IndexStyle(A), IndexStyle(B))
IndexStyle(A::AbstractArray, B::AbstractArray...) = IndexStyle(IndexStyle(A), IndexStyle(B...))
Expand Down Expand Up @@ -457,7 +457,7 @@ checkindex(::Type{Bool}, inds::AbstractUnitRange, i) =
checkindex(::Type{Bool}, inds::AbstractUnitRange, i::Real) = (first(inds) <= i) & (i <= last(inds))
checkindex(::Type{Bool}, inds::AbstractUnitRange, ::Colon) = true
checkindex(::Type{Bool}, inds::AbstractUnitRange, ::Slice) = true
function checkindex(::Type{Bool}, inds::AbstractUnitRange, r::Range)
function checkindex(::Type{Bool}, inds::AbstractUnitRange, r::AbstractRange)
@_propagate_inbounds_meta
isempty(r) | (checkindex(Bool, inds, first(r)) & checkindex(Bool, inds, last(r)))
end
Expand Down Expand Up @@ -700,8 +700,8 @@ function copy(a::AbstractArray)
copymutable(a)
end

function copy!(B::AbstractVecOrMat{R}, ir_dest::Range{Int}, jr_dest::Range{Int},
A::AbstractVecOrMat{S}, ir_src::Range{Int}, jr_src::Range{Int}) where {R,S}
function copy!(B::AbstractVecOrMat{R}, ir_dest::AbstractRange{Int}, jr_dest::AbstractRange{Int},
A::AbstractVecOrMat{S}, ir_src::AbstractRange{Int}, jr_src::AbstractRange{Int}) where {R,S}
if length(ir_dest) != length(ir_src)
throw(ArgumentError(string("source and destination must have same size (got ",
length(ir_src)," and ",length(ir_dest),")")))
Expand Down Expand Up @@ -895,7 +895,7 @@ end
getindex(A, inds...)
Return a subset of array `A` as specified by `inds`, where each `ind` may be an
`Int`, a `Range`, or a [`Vector`](@ref). See the manual section on
`Int`, an `AbstractRange`, or a [`Vector`](@ref). See the manual section on
[array indexing](@ref man-array-indexing) for details.
# Examples
Expand Down Expand Up @@ -1045,14 +1045,14 @@ end

## get (getindex with a default value) ##

RangeVecIntList{A<:AbstractVector{Int}} = Union{Tuple{Vararg{Union{Range, AbstractVector{Int}}}},
AbstractVector{UnitRange{Int}}, AbstractVector{Range{Int}}, AbstractVector{A}}
RangeVecIntList{A<:AbstractVector{Int}} = Union{Tuple{Vararg{Union{AbstractRange, AbstractVector{Int}}}},
AbstractVector{UnitRange{Int}}, AbstractVector{AbstractRange{Int}}, AbstractVector{A}}

get(A::AbstractArray, i::Integer, default) = checkbounds(Bool, A, i) ? A[i] : default
get(A::AbstractArray, I::Tuple{}, default) = similar(A, typeof(default), 0)
get(A::AbstractArray, I::Dims, default) = checkbounds(Bool, A, I...) ? A[I...] : default

function get!(X::AbstractVector{T}, A::AbstractVector, I::Union{Range,AbstractVector{Int}}, default::T) where T
function get!(X::AbstractVector{T}, A::AbstractVector, I::Union{AbstractRange,AbstractVector{Int}}, default::T) where T
# 1d is not linear indexing
ind = findin(I, indices1(A))
X[ind] = A[I[ind]]
Expand All @@ -1061,7 +1061,7 @@ function get!(X::AbstractVector{T}, A::AbstractVector, I::Union{Range,AbstractVe
X[last(ind)+1:last(Xind)] = default
X
end
function get!(X::AbstractArray{T}, A::AbstractArray, I::Union{Range,AbstractVector{Int}}, default::T) where T
function get!(X::AbstractArray{T}, A::AbstractArray, I::Union{AbstractRange,AbstractVector{Int}}, default::T) where T
# Linear indexing
ind = findin(I, 1:length(A))
X[ind] = A[I[ind]]
Expand All @@ -1070,7 +1070,7 @@ function get!(X::AbstractArray{T}, A::AbstractArray, I::Union{Range,AbstractVect
X
end

get(A::AbstractArray, I::Range, default) = get!(similar(A, typeof(default), index_shape(I)), A, I, default)
get(A::AbstractArray, I::AbstractRange, default) = get!(similar(A, typeof(default), index_shape(I)), A, I, default)

# TODO: DEPRECATE FOR #14770 (just the partial linear indexing part)
function get!(X::AbstractArray{T}, A::AbstractArray, I::RangeVecIntList, default::T) where T
Expand Down Expand Up @@ -1559,7 +1559,7 @@ function isequal(A::AbstractArray, B::AbstractArray)
if indices(A) != indices(B)
return false
end
if isa(A,Range) != isa(B,Range)
if isa(A,AbstractRange) != isa(B,AbstractRange)
return false
end
for (a, b) in zip(A, B)
Expand All @@ -1582,7 +1582,7 @@ function (==)(A::AbstractArray, B::AbstractArray)
if indices(A) != indices(B)
return false
end
if isa(A,Range) != isa(B,Range)
if isa(A,AbstractRange) != isa(B,AbstractRange)
return false
end
for (a, b) in zip(A, B)
Expand Down
4 changes: 2 additions & 2 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ elements of type `T`. Alias for [`AbstractArray{T,2}`](@ref).
"""
const AbstractMatrix{T} = AbstractArray{T,2}
const AbstractVecOrMat{T} = Union{AbstractVector{T}, AbstractMatrix{T}}
const RangeIndex = Union{Int, Range{Int}, AbstractUnitRange{Int}}
const RangeIndex = Union{Int, AbstractRange{Int}, AbstractUnitRange{Int}}
const DimOrInd = Union{Integer, AbstractUnitRange}
const IntOrInd = Union{Int, AbstractUnitRange}
const DimsOrInds{N} = NTuple{N,DimOrInd}
Expand Down Expand Up @@ -789,7 +789,7 @@ function getindex(A::Array, c::Colon)
end

# This is redundant with the abstract fallbacks, but needed for bootstrap
function getindex(A::Array{S}, I::Range{Int}) where S
function getindex(A::Array{S}, I::AbstractRange{Int}) where S
return S[ A[i] for i in I ]
end

Expand Down
2 changes: 1 addition & 1 deletion base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ bswap(z::Complex) = Complex(bswap(real(z)), bswap(imag(z)))

isequal(z::Complex, w::Complex) = isequal(real(z),real(w)) & isequal(imag(z),imag(w))

in(x::Complex, r::Range{<:Real}) = isreal(x) && real(x) in r
in(x::Complex, r::AbstractRange{<:Real}) = isreal(x) && real(x) in r

if UInt === UInt64
const h_imag = 0x32a7a07f3e7cd1f9
Expand Down
2 changes: 1 addition & 1 deletion base/dates/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ end

# AbstractArray{TimeType}, AbstractArray{TimeType}
(-)(x::OrdinalRange{T}, y::OrdinalRange{T}) where {T<:TimeType} = collect(x) - collect(y)
(-)(x::Range{T}, y::Range{T}) where {T<:TimeType} = collect(x) - collect(y)
(-)(x::AbstractRange{T}, y::AbstractRange{T}) where {T<:TimeType} = collect(x) - collect(y)
6 changes: 3 additions & 3 deletions base/dates/ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ Base.start(r::StepRange{<:TimeType}) = 0
Base.next(r::StepRange{<:TimeType}, i::Int) = (r.start + r.step*i, i + 1)
Base.done(r::StepRange{<:TimeType,<:Period}, i::Integer) = length(r) <= i

+(x::Period, r::Range{<:TimeType}) = (x + first(r)):step(r):(x + last(r))
+(r::Range{<:TimeType}, x::Period) = x + r
-(r::Range{<:TimeType}, x::Period) = (first(r)-x):step(r):(last(r)-x)
+(x::Period, r::AbstractRange{<:TimeType}) = (x + first(r)):step(r):(x + last(r))
+(r::AbstractRange{<:TimeType}, x::Period) = x + r
-(r::AbstractRange{<:TimeType}, x::Period) = (first(r)-x):step(r):(last(r)-x)
6 changes: 4 additions & 2 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ export $
@deprecate is (===)

# midpoints of intervals
@deprecate midpoints(r::Range) r[1:length(r)-1] + 0.5*step(r)
@deprecate midpoints(r::AbstractRange) r[1:length(r)-1] + 0.5*step(r)
@deprecate midpoints(v::AbstractVector) [0.5*(v[i] + v[i+1]) for i in 1:length(v)-1]

@deprecate_binding Filter Iterators.Filter
Expand Down Expand Up @@ -1149,7 +1149,7 @@ end
## the replacement StepRangeLen also has 4 real-valued fields, which
## makes deprecation tricky. See #20506.

struct Use_StepRangeLen_Instead{T<:AbstractFloat} <: Range{T}
struct Use_StepRangeLen_Instead{T<:AbstractFloat} <: AbstractRange{T}
start::T
step::T
len::T
Expand Down Expand Up @@ -1754,6 +1754,8 @@ import .Iterators.enumerate
@deprecate enumerate(i::IndexLinear, A::AbstractArray) pairs(i, A)
@deprecate enumerate(i::IndexCartesian, A::AbstractArray) pairs(i, A)

@deprecate_binding Range AbstractRange

# END 0.7 deprecations

# BEGIN 1.0 deprecations
Expand Down
2 changes: 1 addition & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export
# Types
AbstractChannel,
AbstractMatrix,
AbstractRange,
AbstractSet,
AbstractUnitRange,
AbstractVector,
Expand Down Expand Up @@ -87,7 +88,6 @@ export
PermutedDimsArray,
PollingFileWatcher,
QuickSort,
Range,
RangeIndex,
Rational,
Regex,
Expand Down
2 changes: 1 addition & 1 deletion base/hashing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ hash(x::QuoteNode, h::UInt) = hash(x.value, hash(QuoteNode, h))

# hashing ranges by component at worst leads to collisions for very similar ranges
const hashr_seed = UInt === UInt64 ? 0x80707b6821b70087 : 0x21b70087
function hash(r::Range, h::UInt)
function hash(r::AbstractRange, h::UInt)
h += hashr_seed
h = hash(first(r), h)
h = hash(step(r), h)
Expand Down
8 changes: 4 additions & 4 deletions base/linalg/blas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,8 @@ function axpy!(alpha::Number, x::Union{DenseArray{T},StridedVector{T}}, y::Union
y
end

function axpy!(alpha::Number, x::Array{T}, rx::Union{UnitRange{Ti},Range{Ti}},
y::Array{T}, ry::Union{UnitRange{Ti},Range{Ti}}) where {T<:BlasFloat,Ti<:Integer}
function axpy!(alpha::Number, x::Array{T}, rx::Union{UnitRange{Ti},AbstractRange{Ti}},
y::Array{T}, ry::Union{UnitRange{Ti},AbstractRange{Ti}}) where {T<:BlasFloat,Ti<:Integer}
if length(rx) != length(ry)
throw(DimensionMismatch("ranges of differing lengths"))
end
Expand Down Expand Up @@ -1515,8 +1515,8 @@ end

end # module

function copy!(dest::Array{T}, rdest::Union{UnitRange{Ti},Range{Ti}},
src::Array{T}, rsrc::Union{UnitRange{Ti},Range{Ti}}) where {T<:BlasFloat,Ti<:Integer}
function copy!(dest::Array{T}, rdest::Union{UnitRange{Ti},AbstractRange{Ti}},
src::Array{T}, rsrc::Union{UnitRange{Ti},AbstractRange{Ti}}) where {T<:BlasFloat,Ti<:Integer}
if minimum(rdest) < 1 || maximum(rdest) > length(dest)
throw(ArgumentError("range out of bounds for dest, of length $(length(dest))"))
end
Expand Down
4 changes: 2 additions & 2 deletions base/linalg/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ isposdef(x::Number) = imag(x)==0 && real(x) > 0
stride1(x::Array) = 1
stride1(x::StridedVector) = stride(x, 1)::Int

function norm(x::StridedVector{T}, rx::Union{UnitRange{TI},Range{TI}}) where {T<:BlasFloat,TI<:Integer}
function norm(x::StridedVector{T}, rx::Union{UnitRange{TI},AbstractRange{TI}}) where {T<:BlasFloat,TI<:Integer}
if minimum(rx) < 1 || maximum(rx) > length(x)
throw(BoundsError(x, rx))
end
Expand Down Expand Up @@ -240,7 +240,7 @@ end
"""
diagind(M, k::Integer=0)
A `Range` giving the indices of the `k`th diagonal of the matrix `M`.
An `AbstractRange` giving the indices of the `k`th diagonal of the matrix `M`.
# Examples
```jldoctest
Expand Down
4 changes: 2 additions & 2 deletions base/linalg/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ end
vecdot(x::Union{DenseArray{T},StridedVector{T}}, y::Union{DenseArray{T},StridedVector{T}}) where {T<:BlasReal} = BLAS.dot(x, y)
vecdot(x::Union{DenseArray{T},StridedVector{T}}, y::Union{DenseArray{T},StridedVector{T}}) where {T<:BlasComplex} = BLAS.dotc(x, y)

function dot(x::Vector{T}, rx::Union{UnitRange{TI},Range{TI}}, y::Vector{T}, ry::Union{UnitRange{TI},Range{TI}}) where {T<:BlasReal,TI<:Integer}
function dot(x::Vector{T}, rx::Union{UnitRange{TI},AbstractRange{TI}}, y::Vector{T}, ry::Union{UnitRange{TI},AbstractRange{TI}}) where {T<:BlasReal,TI<:Integer}
if length(rx) != length(ry)
throw(DimensionMismatch("length of rx, $(length(rx)), does not equal length of ry, $(length(ry))"))
end
Expand All @@ -54,7 +54,7 @@ function dot(x::Vector{T}, rx::Union{UnitRange{TI},Range{TI}}, y::Vector{T}, ry:
BLAS.dot(length(rx), pointer(x)+(first(rx)-1)*sizeof(T), step(rx), pointer(y)+(first(ry)-1)*sizeof(T), step(ry))
end

function dot(x::Vector{T}, rx::Union{UnitRange{TI},Range{TI}}, y::Vector{T}, ry::Union{UnitRange{TI},Range{TI}}) where {T<:BlasComplex,TI<:Integer}
function dot(x::Vector{T}, rx::Union{UnitRange{TI},AbstractRange{TI}}, y::Vector{T}, ry::Union{UnitRange{TI},AbstractRange{TI}}) where {T<:BlasComplex,TI<:Integer}
if length(rx) != length(ry)
throw(DimensionMismatch("length of rx, $(length(rx)), does not equal length of ry, $(length(ry))"))
end
Expand Down
4 changes: 2 additions & 2 deletions base/linalg/transpose.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ end
@inline adjoint(A::AbstractVector{<:Real}) = transpose(A)
@inline adjoint(A::AbstractMatrix{<:Real}) = transpose(A)

function copy_transpose!(B::AbstractVecOrMat, ir_dest::Range{Int}, jr_dest::Range{Int},
A::AbstractVecOrMat, ir_src::Range{Int}, jr_src::Range{Int})
function copy_transpose!(B::AbstractVecOrMat, ir_dest::AbstractRange{Int}, jr_dest::AbstractRange{Int},
A::AbstractVecOrMat, ir_src::AbstractRange{Int}, jr_src::AbstractRange{Int})
if length(ir_dest) != length(jr_src)
throw(ArgumentError(string("source and destination must have same size (got ",
length(jr_src)," and ",length(ir_dest),")")))
Expand Down
Loading

0 comments on commit 02fba85

Please sign in to comment.