I am trying to achieve the following in ArrayFire:
Inputs:
Indices: [ 0, 0, 1, 1, 1, 2, 2]
Values : [1.0, 2.0, 3.0, 1.0, 2.0, 3.0, 5.0]
Output:
Result: [1.0 + 2.0, 3.0 + 1.0 + 2.0, 3.0 + 5.0] = [3.0, 6.0, 8.0]
So element i
in the output is the sum of all the input values whose corresponding index is i
.
TensorFlow has a scatter_add operation which can be used to do this, but I can't find anything in the ArrayFire docs which seems to fit the bill. The ArrayFire scanByKey function gets halfway to what I need, and would give the cumulative scan output:
[1.0, 3.0, 3.0, 4.0, 6.0, 3.0, 8.0]
But I still have to extract just the maximum value for each index (positions 1, 4 and 6) to give me the array I need for the next step, and again I can't find a function to do that.
How can I achieve this using ArrayFire?