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

Ensure elision of require_one_based_indexing with high-dim array views #53091

Merged
merged 18 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
5912bb6
Merge pull request #1 from JuliaLang/master
pablosanjose Sep 3, 2018
cc454a4
Merge remote-tracking branch 'origin/master'
pablosanjose Sep 5, 2019
c4a23fe
Merge remote-tracking branch 'origin/master'
pablosanjose Oct 16, 2019
65f07ea
Merge branch 'master' of https://github.com/pablosanjose/julia
pablosanjose Dec 8, 2019
9f99104
Merge remote-tracking branch 'origin/master'
pablosanjose Feb 26, 2020
44a06a0
Merge branch 'master' of https://github.com/pablosanjose/julia
pablosanjose Feb 26, 2020
eb412dc
Merge branch 'master' of https://github.com/pablosanjose/julia
pablosanjose Jul 15, 2020
72aa279
Merge branch 'master' of https://github.com/pablosanjose/julia
pablosanjose Jan 27, 2021
255a16f
Merge branch 'JuliaLang:master' into master
pablosanjose Mar 28, 2022
4466f5d
Merge branch 'master' of https://github.com/pablosanjose/Julia
pablosanjose Jan 27, 2024
3afea44
Merge branch 'master' of https://github.com/pablosanjose/Julia
pablosanjose Jan 28, 2024
6dfea23
ensure elision of `require_one_based_indexing` on high-dim array views
pablosanjose Jan 28, 2024
7172c20
further simplify has_offset_axes dispatch
pablosanjose Jan 28, 2024
02c14e8
Merge branch 'master' into has_offset_axes
pablosanjose Jan 29, 2024
a2247b5
Merge branch 'master' into has_offset_axes
pablosanjose Jan 29, 2024
5240b5a
add comments with details
pablosanjose Jan 29, 2024
cc21e72
update docstring for has_offset_axes
pablosanjose Jan 29, 2024
24c6236
fix typo in comment [skip CI]
pablosanjose Jan 29, 2024
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
9 changes: 6 additions & 3 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,16 @@ If multiple arguments are passed, equivalent to `has_offset_axes(A) | has_offset

See also [`require_one_based_indexing`](@ref).
"""
has_offset_axes() = false
has_offset_axes(A) = _any_tuple(x->Int(first(x))::Int != 1, false, axes(A)...)
has_offset_axes(A::AbstractVector) = Int(firstindex(A))::Int != 1 # improve performance of a common case (ranges)
# Use `_any_tuple` to avoid unneeded invoke.
# note: this could call `any` directly if the compiler can infer it
has_offset_axes(As...) = _any_tuple(has_offset_axes, false, As...)
has_offset_axes(::Colon) = false
has_offset_axes(::Array) = false
# note: this could call `any` directly if the compiler can infer it. We don't use _any_tuple
# here because it stops full elision in sone cases (#49332) and we don't need handling of
pablosanjose marked this conversation as resolved.
Show resolved Hide resolved
# `missing` (has_offset_axes(A) always returns a Bool)
has_offset_axes(A, As...) = has_offset_axes(A) || has_offset_axes(As...)


"""
require_one_based_indexing(A::AbstractArray)
Expand Down
4 changes: 4 additions & 0 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1907,13 +1907,17 @@ end

@testset "type-based offset axes check" begin
a = randn(ComplexF64, 10)
b = randn(ComplexF64, 4, 4, 4, 4)
ta = reinterpret(Float64, a)
tb = reinterpret(Float64, view(a, 1:2:10))
tc = reinterpret(Float64, reshape(view(a, 1:3:10), 2, 2, 1))
td = view(b, :, :, 1, 1)
# Issue #44040
@test IRUtils.fully_eliminated(Base.require_one_based_indexing, Base.typesof(ta, tc))
@test IRUtils.fully_eliminated(Base.require_one_based_indexing, Base.typesof(tc, tc))
@test IRUtils.fully_eliminated(Base.require_one_based_indexing, Base.typesof(ta, tc, tb))
# Issue #49332
@test IRUtils.fully_eliminated(Base.require_one_based_indexing, Base.typesof(td, td, td))
# Ranges && CartesianIndices
@test IRUtils.fully_eliminated(Base.require_one_based_indexing, Base.typesof(1:10, Base.OneTo(10), 1.0:2.0, LinRange(1.0, 2.0, 2), 1:2:10, CartesianIndices((1:2:10, 1:2:10))))
# Remind us to call `any` in `Base.has_offset_axes` once our compiler is ready.
Expand Down