4141end
4242
4343@testset " IdOffsetRange" begin
44-
44+
4545 function check_indexed_by (r, rindx)
4646 for i in rindx
4747 r[i]
@@ -1403,6 +1403,7 @@ end
14031403Base. parent (x:: PointlessWrapper ) = x. parent
14041404Base. size (x:: PointlessWrapper ) = size (parent (x))
14051405Base. axes (x:: PointlessWrapper ) = axes (parent (x))
1406+ Base. getindex (x:: PointlessWrapper , i... ) = x. parent[i... ]
14061407
14071408@testset " no offset view" begin
14081409 # OffsetArray fallback
@@ -1415,21 +1416,56 @@ Base.axes(x::PointlessWrapper) = axes(parent(x))
14151416 @inferred no_offset_view (O2)
14161417
14171418 P = PointlessWrapper (A)
1418- @test no_offset_view (P) ≡ P
1419+ @test @inferred (no_offset_view (P)) === P
1420+ @test @inferred (no_offset_view (A)) === A
1421+ a0 = reshape ([1 ])
1422+ @test @inferred (no_offset_view (a0)) === a0
1423+ a0v = view (a0)
1424+ @test @inferred (no_offset_view (a0v)) === a0v
14191425
14201426 # generic fallback
14211427 A = collect (reshape (1 : 12 , 3 , 4 ))
14221428 N = NegativeArray (A)
14231429 @test N[- 3 , - 4 ] == 1
14241430 V = no_offset_view (N)
14251431 @test collect (V) == A
1432+ A = reshape (view ([5 ], 1 , 1 ))
1433+ @test no_offset_view (A) == A
14261434
14271435 # bidirectional
14281436 B = BidirectionalVector ([1 , 2 , 3 ])
14291437 pushfirst! (B, 0 )
14301438 OB = OffsetArrays. no_offset_view (B)
14311439 @test axes (OB, 1 ) == 1 : 4
14321440 @test collect (OB) == 0 : 3
1441+
1442+ # issue #198
1443+ offax = axes (OffsetVector (1 : 10 , - 5 ), 1 )
1444+ noffax = OffsetArrays. no_offset_view (offax)
1445+ @test noffax == - 4 : 5
1446+ @test axes (noffax, 1 ) == 1 : 10 # ideally covered by the above, but current it isn't
1447+ @test isa (noffax, AbstractUnitRange)
1448+
1449+ # SubArrays
1450+ A = reshape (1 : 12 , 3 , 4 )
1451+ V = view (A, OffsetArrays. IdentityUnitRange (2 : 3 ), OffsetArrays. IdentityUnitRange (2 : 3 ))
1452+ if collect (V) == [5 8 ; 6 9 ] # julia 1.0 has a bug here
1453+ @test OffsetArrays. no_offset_view (V) == [5 8 ; 6 9 ]
1454+ end
1455+ V = view (A, OffsetArrays. IdentityUnitRange (2 : 3 ), 2 )
1456+ @test V != [5 ;6 ]
1457+ if collect (V) == [5 ;6 ]
1458+ @test OffsetArrays. no_offset_view (V) == [5 ;6 ]
1459+ end
1460+ O = OffsetArray (A, - 1 : 1 , 0 : 3 )
1461+ V = view (O, 0 : 1 , 1 : 2 )
1462+ @test V == OffsetArrays. no_offset_view (V) == [5 8 ; 6 9 ]
1463+ r1, r2 = OffsetArrays. IdOffsetRange (1 : 3 , - 2 ), OffsetArrays. IdentityUnitRange (2 : 3 )
1464+ V = view (O, r1, r2)
1465+ @test V != collect (V)
1466+ @test OffsetArrays. no_offset_view (V) == collect (V)
1467+ V = @view O[:,:]
1468+ @test IndexStyle (A) == IndexStyle (O) == IndexStyle (V) == IndexStyle (OffsetArrays. no_offset_view (V)) == IndexLinear ()
14331469end
14341470
14351471@testset " no nesting" begin
@@ -1490,6 +1526,7 @@ end
14901526@testset " Adapt" begin
14911527 # We need another storage type, CUDA.jl defines one but we can't use that for CI
14921528 # let's define an appropriate method for SArrays
1529+ Adapt. adapt_storage (:: Type{SA} , xs:: Array ) where SA<: SArray = convert (SA, xs) # ambiguity
14931530 Adapt. adapt_storage (:: Type{SA} , xs:: AbstractArray ) where SA<: SArray = convert (SA, xs)
14941531 arr = OffsetArray (rand (3 , 3 ), - 1 : 1 , - 1 : 1 )
14951532 s_arr = adapt (SMatrix{3 ,3 }, arr)
0 commit comments