You are running into a syntax quirk.
For an array
of rank larger than 1, operator[]
with integral parameter returns an array_view
referring to the slice of the original array
. The subsequent operator[]
operates on the array_view
object, which is allowed on the host -- and in your case causes an implicit data copy before returning a reference to the element.
For an array
of rank 1 operator[]
with integral parameter, or operator[]
with index
parameter for any array
, return a reference to the element. Both are allowed only on the location where the array
is resident - by default it is the default accelerator_view
, however you can request to create the array
in the CPU memory as well.
Unless you want to have fine-grained control on the data movement between the host and the accelerator_view
, it is suggested to use the array_view
type ubiquitously.