GPUArrays.jl
GPUArrays.jl copied to clipboard
mean fails with views
A = gpu(rand(3, 5, 2))
mean(@views A[1, :, :]; dims=2)
# ERROR: Scalar indexing is disallowed.
However, the following all work:
sum(@views A[1, :, :]; dims=2)
mean(A[1, :, :]; dims=2)
sum(A[1, :, :]; dims=2)
As I commented on Slack:
that view is not contiguous, so it results in a SubArray object instead of a CuArray object. and not all array abstractions have type signatures that cover SubArray
we could extend GPUArrays’ mean implementation to use AnyGPUArray (which includes SubArray) instead of AbstractGPUArray (only CuArray), but I’m hesitant to do that, because the horrible Union that is AnyGPUArray is bad for load time and creates lots of ambiguities. This needs a fix in Base, really