0

I am trying to remove elements from an ArrayFire array (af::array) iteratively in a loop. Say I have:

af::array arr = af::range(af::dim4(4), -1, u32) + 1);
// arr = [1 2 3 4] (it's a column vector, though shown as a row vector here)

At each iteration of the loop, I have to remove a value from the array. The value to be removed depends on a computation, the result of which is not always the same. So in 4 iterations of the loop, the process can look like:

// Iter 1: arr = [1 3 4] (removed 2)
// Iter 2: arr = [1 4]   (removed 3)
// Iter 3: arr = [4]     (removed 1)
// Iter 4: arr = empty   (removed 4)

I was wondering if someone had a suggestion on how best to accomplish this. I have a technique working that requires a conversion of arr to a C-array, removing an element, and re-conversion back to a device af::array. Is there a more idiomatic/efficient way to accomplish this?

endbegin
  • 1,610
  • 1
  • 17
  • 18

1 Answers1

1

Assuming the code in your example using columns, I would do the following since there doesn't appear to be any kind of row / column delete function.

i is set to the row we wish to delete, numbering starts at 0:

int i=2;
arr = af::join(0,arr.rows(0,i-1), arr.rows(i+1,end));
af::af_print(arr);

prints:

 arr [3 1 1 1]
          1
          2
          4

If you wish to have your data in a column vector, change the 'rows' function to the 'cols' function.

Ed King
  • 444
  • 2
  • 10