Skip to content

Commit cb299dc

Browse files
authored
implement unwrap_type from Adapt (#377)
1 parent 73f7acd commit cb299dc

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

ext/OffsetArraysAdaptExt.jl

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Adapt.adapt_structure(to, O::OffsetArray) = OffsetArrays.parent_call(x -> Adapt.
1111
@static if isdefined(Adapt, :parent_type)
1212
# To support Adapt 3.0 which doesn't have parent_type defined
1313
Adapt.parent_type(::Type{OffsetArray{T,N,AA}}) where {T,N,AA} = AA
14+
Adapt.unwrap_type(W::Type{<:OffsetArray}) = unwrap_type(parent_type(W))
1415
end
1516

1617
end

test/runtests.jl

+4
Original file line numberDiff line numberDiff line change
@@ -2507,8 +2507,12 @@ end
25072507
@test parent(s_arr) isa SArray
25082508
@test arr == adapt(Array, s_arr)
25092509

2510+
arr2 = OffsetArray(view(rand(5, 5), 2:4, 2:4), -1:1, -1:1)
2511+
25102512
if isdefined(Adapt, :parent_type)
25112513
@test Adapt.parent_type(typeof(arr)) == typeof(arr.parent)
2514+
@test Adapt.unwrap_type(typeof(arr)) == typeof(arr.parent)
2515+
@test Adapt.unwrap_type(typeof(arr2)) == typeof(arr.parent)
25122516
end
25132517
end
25142518

0 commit comments

Comments
 (0)