Skip to content

Implement BroadcastStyle using Adapt's unwrap_type #378

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions ext/OffsetArraysAdaptExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# To support Adapt 3.0 which doesn't have parent_type defined
Adapt.parent_type(::Type{OffsetArray{T,N,AA}}) where {T,N,AA} = AA
Adapt.unwrap_type(W::Type{<:OffsetArray}) = unwrap_type(parent_type(W))

Base.Broadcast.BroadcastStyle(W::Type{<:OffsetArray}) = Base.Broadcast.BroadcastStyle(unwrap_type(W))

Check warning on line 16 in ext/OffsetArraysAdaptExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/OffsetArraysAdaptExt.jl#L16

Added line #L16 was not covered by tests
end

end
6 changes: 0 additions & 6 deletions src/OffsetArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,6 @@ parenttype(A::OffsetArray) = parenttype(typeof(A))

Base.parent(A::OffsetArray) = A.parent

# TODO: Ideally we would delegate to the parent's broadcasting implementation, but that
# is currently broken in sufficiently many implementation, namely RecursiveArrayTools, DistributedArrays
# and StaticArrays, that it will take concentrated effort to get this working across the ecosystem.
# The goal would be to have `OffsetArray(CuArray) .+ 1 == OffsetArray{CuArray}`.
# Base.Broadcast.BroadcastStyle(::Type{<:OffsetArray{<:Any, <:Any, AA}}) where AA = Base.Broadcast.BroadcastStyle(AA)

@inline Base.size(A::OffsetArray) = size(parent(A))
# specializing length isn't necessary, as length(A) = prod(size(A)),
# but specializing length enables constant-propagation for statically sized arrays
Expand Down
Loading