diff --git a/ext/OffsetArraysAdaptExt.jl b/ext/OffsetArraysAdaptExt.jl index 88e9b719..55969fdb 100644 --- a/ext/OffsetArraysAdaptExt.jl +++ b/ext/OffsetArraysAdaptExt.jl @@ -11,6 +11,7 @@ Adapt.adapt_structure(to, O::OffsetArray) = OffsetArrays.parent_call(x -> Adapt. @static if isdefined(Adapt, :parent_type) # 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)) end end diff --git a/test/runtests.jl b/test/runtests.jl index c1a272eb..5e953112 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2507,8 +2507,12 @@ end @test parent(s_arr) isa SArray @test arr == adapt(Array, s_arr) + arr2 = OffsetArray(view(rand(5, 5), 2:4, 2:4), -1:1, -1:1) + if isdefined(Adapt, :parent_type) @test Adapt.parent_type(typeof(arr)) == typeof(arr.parent) + @test Adapt.unwrap_type(typeof(arr)) == typeof(arr.parent) + @test Adapt.unwrap_type(typeof(arr2)) == typeof(arr.parent) end end