You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2020/07/09 22:08:07 UTC

[GitHub] [incubator-tvm] mbrookhart commented on a change in pull request #6030: [topi][relay] Add operation scatter_add to relay, based on scatter implementation.

mbrookhart commented on a change in pull request #6030:
URL: https://github.com/apache/incubator-tvm/pull/6030#discussion_r452517257



##########
File path: tests/python/relay/test_op_level3.py
##########
@@ -811,6 +811,51 @@ def verify_scatter(dshape, ishape, axis=0):
     verify_scatter((16, 16, 4, 5), (16, 16, 4, 5), 3)
 
 
+def test_scatter_add():
+
+    def ref_scatter_add(data, indices, updates, axis=0):
+        output = np.copy(data)
+        for index in np.ndindex(*indices.shape):
+            new_index = list(index)
+            new_index[axis] = indices[index]
+            output[tuple(new_index)] += updates[index]
+        return output
+
+    def verify_scatter_add(dshape, ishape, axis=0):
+        d = relay.var("d", relay.TensorType(dshape, "float32"))
+        i = relay.var("i", relay.TensorType(ishape, "int64"))
+        u = relay.var("u", relay.TensorType(ishape, "float32"))
+        z = relay.op.scatter_add(d, i, u, axis)
+
+        func = relay.Function([d, i, u], z)
+
+        data_np = np.random.uniform(size=dshape).astype("float32")
+        updates_np = np.random.uniform(size=ishape).astype("float32")
+        indices_np = np.random.randint(-dshape[axis], dshape[axis] - 1, ishape).astype("int64")
+
+        ref_res = ref_scatter_add(data_np, indices_np, updates_np, axis)
+        # TODO(mbrookhart): expand testing when adding more backend schedules

Review comment:
       Any chance you got it to work on cuda? I haven't gotten back to this TODO yet :)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org