Search code examples
arrayfire

Acessing a value on an ArrayFire array


I had a af::array and need to acess the value in a row, like z(8), e.g. But, when i try to do this, in a loop with a incremental i, the compiler returns

    cannot convert from 'af::array::array_proxy' to 'double'

Someone knows how can I acess the value inside the array? Thanks.


Solution

  • Take a look at scalar in the arrayfire documentation here.

    For your use case, you can access the element like this :

    float val = z(8).scalar<float>();
    

    Could you talk about why you need to do this? In many cases, transferring values to the host from the GPU is unnecessary and avoidable.