1

What is the best way to add a vector to all columns of a Matrix with ArrayFire?

At the moment i'm using a gfor loop, but that seems wrong for such a simple task.

gfor(af::seq i, M.dims(1)) {
    M(af::span, i) += VECTOR;
}

Is there a better way?

MaPePeR
  • 931
  • 9
  • 18

1 Answers1

1

You can use tile. Since you are tiling a singleton dimension (VECTOR.dims(1) = 1), this will be done as a JIT operation (in the same kernel) and not call a different kernel.

M += af::tile(VECTOR, 1, M.dims(1));
shehzan
  • 331
  • 1
  • 5