Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more efficient array indexing with AbstractUnitRange #39896

Merged
merged 21 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ function getindex end
@eval getindex(A::Array, i1::Int, i2::Int, I::Int...) = (@_inline_meta; arrayref($(Expr(:boundscheck)), A, i1, i2, I...))

# Faster contiguous indexing using copyto! for UnitRange and Colon
function getindex(A::Array, I::UnitRange{Int})
function getindex(A::Array, I::AbstractUnitRange{<:Integer})
@_inline_meta
@boundscheck checkbounds(A, I)
lI = length(I)
Expand Down
12 changes: 12 additions & 0 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1280,3 +1280,15 @@ end
@test Int[0 t...; t... 0] == [0 1 2; 1 2 0]
@test_throws ArgumentError Int[t...; 3 4 5]
end

@testset "issue #39896, modified getindex " begin
a=ones(20000)
ax=axes(a,1)
@test a==a[ax]
ax=UnitRange(1,10)
@test a[ax]==ones(10)
a=ones(BigInt(20000))
ax=UnitRange(1,20000)
@test a[ax]== ones(BigInt(20000))

end
sanjibansg marked this conversation as resolved.
Show resolved Hide resolved