@@ -451,11 +451,11 @@ Base.checkindex(::Type{Bool}, inds::AbstractUnitRange, or::OffsetRange) = Base.c
451451
452452# If both the arguments are offset, we may unwrap the indices to call (::OffsetArray)[::AbstractRange{Int}]
453453@propagate_inbounds function Base. getindex (A:: OffsetArray , r:: OffsetRange{Int} )
454- _maybewrapoffset (A[parent (r)], axes (r))
454+ _indexedby (A[parent (r)], axes (r))
455455end
456456# If the indices are offset, we may unwrap them and pass the parent to getindex
457457@propagate_inbounds function Base. getindex (A:: AbstractRange , r:: OffsetRange{Int} )
458- _maybewrapoffset (A[parent (r)], axes (r))
458+ _indexedby (A[parent (r)], axes (r))
459459end
460460
461461# An OffsetUnitRange might use the rapid getindex(::Array, ::AbstractUnitRange{Int}) for contiguous indexing
469469if VERSION <= v " 1.7.0-DEV.1039"
470470 @propagate_inbounds function Base. getindex (A:: Array , r:: Union{IdOffsetRange, IIUR} )
471471 B = A[_contiguousindexingtype (r)]
472- _maybewrapoffset (B, axes (r))
472+ _indexedby (B, axes (r))
473473 end
474474end
475475
@@ -478,20 +478,20 @@ end
478478 @boundscheck checkbounds (A, r)
479479 # nD OffsetArrays do not have their linear indices shifted, so we may forward the indices provided to the parent
480480 @inbounds B = parent (A)[_contiguousindexingtype (r)]
481- _maybewrapoffset (B, axes (r))
481+ _indexedby (B, axes (r))
482482end
483483@inline function Base. getindex (A:: OffsetVector , r:: AbstractUnitRange{Int} )
484484 @boundscheck checkbounds (A, r)
485485 # OffsetVectors may have their linear indices shifted, so we subtract the offset from the indices provided
486486 @inbounds B = parent (A)[_subtractoffset (r, A. offsets[1 ])]
487- _maybewrapoffset (B, axes (r))
487+ _indexedby (B, axes (r))
488488end
489489
490490# This method added mainly to index an OffsetRange with another range
491491@inline function Base. getindex (A:: OffsetVector , r:: AbstractRange{Int} )
492492 @boundscheck checkbounds (A, r)
493493 @inbounds B = parent (A)[_subtractoffset (r, A. offsets[1 ])]
494- _maybewrapoffset (B, axes (r))
494+ _indexedby (B, axes (r))
495495end
496496
497497# In general we would pass through getindex(A, I...) which calls to_indices(A, I) and finally to_index(I)
@@ -508,21 +508,26 @@ for OR in [:IIUR, :IdOffsetRange]
508508 @eval @inline function Base. getindex (r:: $R , s:: $OR )
509509 @boundscheck checkbounds (r, s)
510510 @inbounds pr = r[UnitRange (s)]
511- _maybewrapoffset (pr, axes (s, 1 ))
511+ _indexedby (pr, axes (s))
512512 end
513513 end
514514
515515 # this method is needed for ambiguity resolution
516516 @eval @inline function Base. getindex (r:: StepRangeLen{T,<:Base.TwicePrecision,<:Base.TwicePrecision} , s:: $OR ) where T
517517 @boundscheck checkbounds (r, s)
518518 @inbounds pr = r[UnitRange (s)]
519- _maybewrapoffset (pr, axes (s, 1 ))
519+ _indexedby (pr, axes (s))
520520 end
521521end
522522
523523# eltype conversion
524524# This may use specialized map methods for the parent
525525Base. map (:: Type{T} , O:: OffsetArray ) where {T} = parent_call (x -> map (T, x), O)
526+ Base. map (:: Type{T} , r:: IdOffsetRange ) where {T<: Real } = _indexedby (map (T, UnitRange (r)), axes (r))
527+ if eltype (IIUR) === Int
528+ # This is type-piracy, but there is no way to convert an IdentityUnitRange to a non-Int type in Base
529+ Base. map (:: Type{T} , r:: IdentityUnitRange ) where {T<: Real } = _indexedby (map (T, UnitRange (r)), axes (r))
530+ end
526531
527532# mapreduce is faster with an IdOffsetRange than with an OffsetUnitRange
528533# We therefore convert OffsetUnitRanges to IdOffsetRanges with the same values and axes
0 commit comments