Is there a sparse variable update operation in mx.ndarray? Similar to tf.scatter_add() in tensorflow.
Or how to achieve similar results。
For example:
data = mx.nd.array([1,1,1,1])
index = mx.nd.array([1, 1,1])
add = mx.nd.array([1, 2,3])
data[index] += add
the result data is [1,4,1,1],but i want get [1,7,1,1],How can I achieve the cumulative effect?
Unfortunately I don’t have the solution right now
But , I’ve tried to reproduce your snippet and it is not even deterministic: I get 2, 3 or 4 on axis 1 run 2 run.
What you get do here is (not clean, but works):
data = mx.nd.array([1,1,1,1])
index = mx.nd.array([1, 1,1])
add = mx.nd.array([1, 2,3])
indices = np.unique(index.asnumpy()).tolist()
new_add = [mx.nd.sum(mx.nd.where(index == idx, add, mx.nd.zeros_like(add))) for idx in indices]
add = mx.nd.concatenate(new_add)
index = mx.nd.array(indices)
data[index] += add
Thanks for your replay! Your method could solve the problem.
But in this line: new_add = [mx.nd.sum(mx.nd.where(index == idx, add, mx.nd.zeros_like(add))) for idx in indices]
this loop takes too much time because the variable indices always has large shape ,for example (10000)。
Do you have other method to solve this problem?
Thanks for you again and looking forward to your replay !