Skip to content

Commit

Permalink
Mark GenericMemory as IndexLinear (JuliaLang#52082)
Browse files Browse the repository at this point in the history
  • Loading branch information
N5N3 committed Nov 9, 2023
1 parent f99e6bf commit 1b967b8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions base/genericmemory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ size(a::GenericMemory, d::Int) =
size(a::GenericMemory, d::Integer) = size(a, convert(d, Int))
size(a::GenericMemory) = (length(a),)

IndexStyle(::Type{<:GenericMemory}) = IndexLinear()

pointer(mem::GenericMemoryRef) = unsafe_convert(Ptr{Cvoid}, mem) # no bounds check, even for empty array

_unsetindex!(A::Memory, i::Int) = (@_propagate_inbounds_meta; _unsetindex!(GenericMemoryRef(A, i)); A)
Expand Down
1 change: 1 addition & 0 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,7 @@ end
@testset "IndexStyle for various types" begin
@test Base.IndexStyle(UpperTriangular) == IndexCartesian() # subtype of AbstractArray, not of Array
@test Base.IndexStyle(Vector) == IndexLinear()
@test Base.IndexStyle(Memory) == IndexLinear()
@test Base.IndexStyle(UnitRange) == IndexLinear()
@test Base.IndexStyle(UpperTriangular(rand(3, 3)), [1; 2; 3]) == IndexCartesian()
@test Base.IndexStyle(UpperTriangular(rand(3, 3)), rand(3, 3), [1; 2; 3]) == IndexCartesian()
Expand Down

0 comments on commit 1b967b8

Please sign in to comment.