Adapt.jl icon indicating copy to clipboard operation
Adapt.jl copied to clipboard

Adapt SubArray indices

Open maleadt opened this issue 6 years ago • 1 comments

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

maleadt avatar Jun 28 '19 12:06 maleadt

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

maleadt avatar Jul 12 '19 08:07 maleadt