We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1263513 commit 97cef1aCopy full SHA for 97cef1a
src/OffsetArrays.jl
@@ -507,6 +507,12 @@ if VERSION < v"1.1.0-DEV.783"
507
Base.copyfirst!(dest::OffsetArray, src::OffsetArray) = (maximum!(parent(dest), parent(src)); return dest)
508
end
509
510
+if VERSION <= v"1.7.0-DEV.400"
511
+ # https://github.com/JuliaLang/julia/pull/39393
512
+ # index for zero-argument getindex should be first linear index instead of 1 (#194)
513
+ Base._to_linear_index(A::OffsetArray) = first(LinearIndices(A))
514
+end
515
+
516
##
517
# Adapt allows for automatic conversion of CPU OffsetArrays to GPU OffsetArrays
518
src/axes.jl
@@ -179,16 +179,6 @@ Base.show(io::IO, r::IdOffsetRange) = print(io, "OffsetArrays.IdOffsetRange(",fi
179
# Optimizations
180
@inline Base.checkindex(::Type{Bool}, inds::IdOffsetRange, i::Real) = Base.checkindex(Bool, inds.parent, i - inds.offset)
181
182
-# issue 194
183
-# The indexing operation A[] gets mapped to A[1].
184
-# The bounds-checking for this needs to be handled separately for AbstractVectors
185
-# See https://github.com/JuliaLang/julia/issues/39379 for this issue reported in Base
186
-# Once a PR fixing it is merged, we may limit our fix to earlier Julia versions
187
-@inline function Base.checkbounds_indices(::Type{Bool}, IA::Tuple{IdOffsetRange}, ::Tuple{})
188
- x = IA[1]
189
- length(x) == 1 && first(x) == one(eltype(x))
190
-end
191
-
192
if VERSION < v"1.5.2"
193
# issue 100, 133: IdOffsetRange as another index-preserving case shouldn't comtribute offsets
194
# fixed by https://github.com/JuliaLang/julia/pull/37204
test/runtests.jl
@@ -712,20 +712,13 @@ end
712
@test A[4] == 2
713
714
715
- @testset "issue 194" begin
716
- A = OffsetArray([0], 1);
717
- @test Base.checkbounds_indices(Bool, axes(A), ()) == false
718
- @test_throws BoundsError A[]
719
- A = OffsetArray([6], 1:1)
720
- @test A[] == 6
721
722
- A = OffsetArray(reshape(1:4, 2, 2), 2, 2);
723
724
725
- A = OffsetArray(reshape([6], 1, 1), 1:1, 1:1);
726
727
- A = OffsetArray(A, 1:1, 2:2);
728
+ @testset "Zero-index indexing (#194)" begin
+ @test OffsetArray([6], 2:2)[] == 6
+ @test OffsetArray(fill(6, 1, 1), 2:2, 3:3)[] == 6
+ @test OffsetArray(fill(6))[] == 6
+ @test_throws BoundsError OffsetArray([6,7], 2:3)[]
+ @test_throws BoundsError OffsetArray([6 7], 2:2, 2:3)[]
+ @test_throws BoundsError OffsetArray([], 2:1)[]
729
730
731
0 commit comments