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

Only support multi-dimensional DL indexing in Julia 1.11 #2027

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Changes from all 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
68 changes: 35 additions & 33 deletions src/DataLayouts/DataLayouts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1181,39 +1181,41 @@ end
)
end

### --------------- Support for multi-dimensional indexing
# TODO: can we remove this? It's not needed for Julia 1.10,
# but seems needed in Julia 1.11.
@inline Base.getindex(
data::Union{IJF, IJFH, IFH, VIJFH, VIFH, VF, IF},
I::Vararg{Int, N},
) where {N} = Base.getindex(data, to_universal_index(data, I))

@inline Base.setindex!(
data::Union{IJF, IJFH, IFH, VIJFH, VIFH, VF, IF},
val,
I::Vararg{Int, N},
) where {N} = Base.setindex!(data, val, to_universal_index(data, I))

@inline to_universal_index(data::AbstractData, I::Tuple) =
CartesianIndex(_to_universal_index(data, I))

# Certain datalayouts support special indexing.
# Like VF datalayouts with `getindex(::VF, v::Integer)`
#! format: off
@inline _to_universal_index(::VF, I::NTuple{1, T}) where {T} = (T(1), T(1), T(1), I[1], T(1))
@inline _to_universal_index(::IF, I::NTuple{1, T}) where {T} = (I[1], T(1), T(1), T(1), T(1))
@inline _to_universal_index(::IF, I::NTuple{2, T}) where {T} = (I[1], T(1), T(1), T(1), T(1))
@inline _to_universal_index(::IF, I::NTuple{3, T}) where {T} = (I[1], T(1), T(1), T(1), T(1))
@inline _to_universal_index(::IF, I::NTuple{4, T}) where {T} = (I[1], T(1), T(1), T(1), T(1))
@inline _to_universal_index(::IF, I::NTuple{5, T}) where {T} = (I[1], T(1), T(1), T(1), T(1))
@inline _to_universal_index(::IJF, I::NTuple{2, T}) where {T} = (I[1], I[2], T(1), T(1), T(1))
@inline _to_universal_index(::IJF, I::NTuple{3, T}) where {T} = (I[1], I[2], T(1), T(1), T(1))
@inline _to_universal_index(::IJF, I::NTuple{4, T}) where {T} = (I[1], I[2], T(1), T(1), T(1))
@inline _to_universal_index(::IJF, I::NTuple{5, T}) where {T} = (I[1], I[2], T(1), T(1), T(1))
@inline _to_universal_index(::AbstractData, I::NTuple{5}) = I
#! format: on
### ---------------
if VERSION v"1.11.0-beta"
### --------------- Support for multi-dimensional indexing
# TODO: can we remove this? It's not needed for Julia 1.10,
# but seems needed in Julia 1.11.
@inline Base.getindex(
data::Union{IJF, IJFH, IFH, VIJFH, VIFH, VF, IF},
I::Vararg{Int, N},
) where {N} = Base.getindex(data, to_universal_index(data, I))

@inline Base.setindex!(
data::Union{IJF, IJFH, IFH, VIJFH, VIFH, VF, IF},
val,
I::Vararg{Int, N},
) where {N} = Base.setindex!(data, val, to_universal_index(data, I))

@inline to_universal_index(data::AbstractData, I::Tuple) =
CartesianIndex(_to_universal_index(data, I))

# Certain datalayouts support special indexing.
# Like VF datalayouts with `getindex(::VF, v::Integer)`
#! format: off
@inline _to_universal_index(::VF, I::NTuple{1, T}) where {T} = (T(1), T(1), T(1), I[1], T(1))
@inline _to_universal_index(::IF, I::NTuple{1, T}) where {T} = (I[1], T(1), T(1), T(1), T(1))
@inline _to_universal_index(::IF, I::NTuple{2, T}) where {T} = (I[1], T(1), T(1), T(1), T(1))
@inline _to_universal_index(::IF, I::NTuple{3, T}) where {T} = (I[1], T(1), T(1), T(1), T(1))
@inline _to_universal_index(::IF, I::NTuple{4, T}) where {T} = (I[1], T(1), T(1), T(1), T(1))
@inline _to_universal_index(::IF, I::NTuple{5, T}) where {T} = (I[1], T(1), T(1), T(1), T(1))
@inline _to_universal_index(::IJF, I::NTuple{2, T}) where {T} = (I[1], I[2], T(1), T(1), T(1))
@inline _to_universal_index(::IJF, I::NTuple{3, T}) where {T} = (I[1], I[2], T(1), T(1), T(1))
@inline _to_universal_index(::IJF, I::NTuple{4, T}) where {T} = (I[1], I[2], T(1), T(1), T(1))
@inline _to_universal_index(::IJF, I::NTuple{5, T}) where {T} = (I[1], I[2], T(1), T(1), T(1))
@inline _to_universal_index(::AbstractData, I::NTuple{5}) = I
#! format: on
### ---------------
end

"""
data2array(::AbstractData)
Expand Down
Loading