Search code examples
arrayfire

Can I use broadcasting in ArrayFire?


Can I do something like this:

auto minEl = min(a);
a -= minEl;

?

I get an unknown af::exception when I do that. For now, I'm doing this:

auto minEl = *min(a).host<float>();
a -= minEl;

But of course, it does an unnecessary download.

I borrow the term "broadcasting" from numpy, because there it works perfectly :)


Solution

  • ArrayFire does not currrently support broadcasting. You would have to manually tile the array to match the required dimensions.
    auto minEl = min(a); a -= tile(minEl, a.dims(0));

    This method also avoids the copy of the scalar to host memory.