Adapt.jl
Adapt.jl copied to clipboard
Adapt SubArray indices
julia> view(CuArray([1]), CuArray([1]))
1-element view(::CuArray{Int64,1}, [1]) with eltype Int64:
1
julia> parentindices(ans)
([1],)
julia> typeof(ans)
Tuple{CuArray{Int64,1}}
The indices needs an adapt as well:
Adapt.adapt_structure(to, A::SubArray{<:Any,<:Any,AT}) where {AT} = SubArray(adapt(to, parent(A)), adapt.(Ref(to), parentindices(A)))
Reported by @ali-ramadhan
This is actually a little more complex, because the view constructor does bounds checking:
julia> view(CuArray([1]), CuArray([1]))
ERROR: scalar getindex is disallowed