Turns out Flatten.jl has something similar: Flatten.modify(CuArray, obj, Array). Doesn't use rules, instead eagerly tries to reconstruct objects by calling constructure. That doesn't always work of course:
julia> Flatten.modify(CuArray, view(rand(2,2),:,:), Array)
ERROR: MethodError: no method matching SubArray(::CuArray{Float64,2}, ::Tuple{Base.Slice{Base.OneTo{Int64}},Base.Slice{Base.OneTo{Int64}}}, ::Int64, ::Int64)
Furthermore, we currently need the WrappedArray dispatch rules, but once we have Base.AbstractWrappedArray (JuliaLang/julia#31563) we should investigate using this.
Turns out Flatten.jl has something similar:
Flatten.modify(CuArray, obj, Array). Doesn't use rules, instead eagerly tries to reconstruct objects by calling constructure. That doesn't always work of course:Furthermore, we currently need the
WrappedArraydispatch rules, but once we haveBase.AbstractWrappedArray(JuliaLang/julia#31563) we should investigate using this.