Skip to content

Commit

Permalink
make view(::Memory, ::Colon) produce a Vector (#54005)
Browse files Browse the repository at this point in the history
  • Loading branch information
LilithHafner authored Apr 9, 2024
1 parent 7099bdd commit 97ac3ec
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/genericmemory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,4 @@ end
$(Expr(:new, :(Array{T, 1}), :ref, :dims))
end
end
view(m::GenericMemory, inds::Colon) = view(m, eachindex(m))
2 changes: 2 additions & 0 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3203,6 +3203,7 @@ end
@test @inferred(view(mem, 3:8))::Vector{Int} == 13:18
@test @inferred(view(mem, 20:19))::Vector{Int} == []
@test @inferred(view(mem, -5:-7))::Vector{Int} == []
@test @inferred(view(mem, :))::Vector{Int} == mem
@test @inferred(reshape(mem, 5, 2))::Matrix{Int} == reshape(11:20, 5, 2)

# 53990
Expand All @@ -3217,6 +3218,7 @@ end

@test @inferred(view(empty_mem, 1:0))::Vector{Module} == []
@test @inferred(view(empty_mem, 10:3))::Vector{Module} == []
@test @inferred(view(empty_mem, :))::Vector{Module} == empty_mem
@test isempty(@inferred(reshape(empty_mem, 0, 7, 1))::Array{Module, 3})

offset_inds = OffsetArrays.IdOffsetRange(values=3:6, indices=53:56)
Expand Down

0 comments on commit 97ac3ec

Please sign in to comment.