Indexing adjoints of CuArrays

I was surprised by the following behaviour when indexing CuArrays:

using CUDA
CUDA.allowscalar(false)
x = CUDA.fill(1.0f0, 3, 3)
x[1:2, :] # works 
y = x'
y[1:2, :] # error: scalar indexing is disallowed

Is there a reason that adjoints of CuArrays cannot be indexed in this manner, or is this a bug?

That’s because y is a Transpose object, and not all CuArray operations have been implemented for it (even though it often only involves forwarding the operation to the contained CuArray).

Thanks for your answer. In this case would you convert y to a CuArray to allow indexing, or is there a better approach?

Yes, you could materialize the Transpose, that’s probably the easiest solution. Depending on what you want to do with y, you can also e.g. write a custom kernel that indexes the Transpose on the device: Transpose objects are supported on the GPU, it’s just this specific getindex call that isn’t implemented. You could of course also look into implementing or extending the relevant getindex method to Transpose objects.

I’m surprised there aren’t already getindex(::Transpose... methods that forward the reversed sequence of indices of whatever type to the parent array and re-transpose the result, must be some reason that wouldn’t work?