@@ -451,11 +451,11 @@ Base.checkindex(::Type{Bool}, inds::AbstractUnitRange, or::OffsetRange) = Base.c
451
451
452
452
# If both the arguments are offset, we may unwrap the indices to call (::OffsetArray)[::AbstractRange{Int}]
453
453
@propagate_inbounds function Base. getindex (A:: OffsetArray , r:: OffsetRange{Int} )
454
- _maybewrapoffset (A[parent (r)], axes (r))
454
+ _indexedby (A[parent (r)], axes (r))
455
455
end
456
456
# If the indices are offset, we may unwrap them and pass the parent to getindex
457
457
@propagate_inbounds function Base. getindex (A:: AbstractRange , r:: OffsetRange{Int} )
458
- _maybewrapoffset (A[parent (r)], axes (r))
458
+ _indexedby (A[parent (r)], axes (r))
459
459
end
460
460
461
461
# An OffsetUnitRange might use the rapid getindex(::Array, ::AbstractUnitRange{Int}) for contiguous indexing
469
469
if VERSION <= v " 1.7.0-DEV.1039"
470
470
@propagate_inbounds function Base. getindex (A:: Array , r:: Union{IdOffsetRange, IIUR} )
471
471
B = A[_contiguousindexingtype (r)]
472
- _maybewrapoffset (B, axes (r))
472
+ _indexedby (B, axes (r))
473
473
end
474
474
end
475
475
@@ -478,20 +478,20 @@ end
478
478
@boundscheck checkbounds (A, r)
479
479
# nD OffsetArrays do not have their linear indices shifted, so we may forward the indices provided to the parent
480
480
@inbounds B = parent (A)[_contiguousindexingtype (r)]
481
- _maybewrapoffset (B, axes (r))
481
+ _indexedby (B, axes (r))
482
482
end
483
483
@inline function Base. getindex (A:: OffsetVector , r:: AbstractUnitRange{Int} )
484
484
@boundscheck checkbounds (A, r)
485
485
# OffsetVectors may have their linear indices shifted, so we subtract the offset from the indices provided
486
486
@inbounds B = parent (A)[_subtractoffset (r, A. offsets[1 ])]
487
- _maybewrapoffset (B, axes (r))
487
+ _indexedby (B, axes (r))
488
488
end
489
489
490
490
# This method added mainly to index an OffsetRange with another range
491
491
@inline function Base. getindex (A:: OffsetVector , r:: AbstractRange{Int} )
492
492
@boundscheck checkbounds (A, r)
493
493
@inbounds B = parent (A)[_subtractoffset (r, A. offsets[1 ])]
494
- _maybewrapoffset (B, axes (r))
494
+ _indexedby (B, axes (r))
495
495
end
496
496
497
497
# 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]
508
508
@eval @inline function Base. getindex (r:: $R , s:: $OR )
509
509
@boundscheck checkbounds (r, s)
510
510
@inbounds pr = r[UnitRange (s)]
511
- _maybewrapoffset (pr, axes (s, 1 ))
511
+ _indexedby (pr, axes (s))
512
512
end
513
513
end
514
514
515
515
# this method is needed for ambiguity resolution
516
516
@eval @inline function Base. getindex (r:: StepRangeLen{T,<:Base.TwicePrecision,<:Base.TwicePrecision} , s:: $OR ) where T
517
517
@boundscheck checkbounds (r, s)
518
518
@inbounds pr = r[UnitRange (s)]
519
- _maybewrapoffset (pr, axes (s, 1 ))
519
+ _indexedby (pr, axes (s))
520
520
end
521
521
end
522
522
523
523
# eltype conversion
524
524
# This may use specialized map methods for the parent
525
525
Base. 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
526
531
527
532
# mapreduce is faster with an IdOffsetRange than with an OffsetUnitRange
528
533
# We therefore convert OffsetUnitRanges to IdOffsetRanges with the same values and axes
0 commit comments