You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/08/13 06:03:22 UTC

[GitHub] [incubator-mxnet] reminisce commented on a change in pull request #15855: [Numpy] cumprod

reminisce commented on a change in pull request #15855: [Numpy] cumprod
URL: https://github.com/apache/incubator-mxnet/pull/15855#discussion_r313230660
 
 

 ##########
 File path: contrib/tvmop/basic/ufunc.py
 ##########
 @@ -48,3 +51,186 @@ def vadd_gpu(dtype, ndim):
     s[C].bind(bx, tvm.thread_axis("blockIdx.x"))
     s[C].bind(tx, tvm.thread_axis("threadIdx.x"))
     return s, [A, B, C]
+
+
+def cumprod(X, ishape, dtype, ndim, axis):
+    def swapaxis(idx, axis1, axis2):
+        ret = list(idx)
+        if axis1 != axis2:
+            ret[axis1], ret[axis2] = ret[axis2], ret[axis1]
+        return ret
+
+    sshape = swapaxis(ishape, 0, axis)
+    s_state = tvm.placeholder(sshape, dtype=dtype)
+    s_init = tvm.compute([1] + sshape[1:], lambda *idx: X[tuple(swapaxis(idx, 0, axis))])
+    s_update = tvm.compute(sshape, lambda *idx: s_state[(idx[0] - 1, ) + idx[1:]] * X[tuple(swapaxis(idx, 0, axis))])
+    s_scan = tvm.scan(s_init, s_update, s_state)
+    ret = tvm.compute(ishape, lambda *idx: s_scan[tuple(swapaxis(idx, 0, axis))])
+    return ret, [ret], [s_init, s_update]
+
+
+def compute_cumprod(dtype, ndim, axis):
+    ishape = [tvm.var() for _ in range(ndim)]
+    X = tvm.placeholder(ishape, name='X', dtype=dtype)
+    if ndim == 0:
+        tshape = [tvm.var()]
+        ret = tvm.compute(tshape, lambda *idx:X[()])
+        c_list, s_list = [ret], []
+    elif axis is None:
+        tshape = [tvm.var()]
+        Y = topi.reshape(X, tshape)
+        ret, c_list, s_list = cumprod(Y, tshape, dtype, 1, 0)
+        c_list.append(Y)
+    else:
+        ret, c_list, s_list = cumprod(X, ishape, dtype, ndim, axis)
+    s = tvm.create_schedule(ret.op)
+    return s, X, ret, c_list, s_list
+
+
+@defop(name="vcumprod", target="cpu", auto_broadcast=False,
+       dtype=AllTypesButHalf, ndim=list(range(0, 6)), axis=list(range(0, 5)) + [None],
+       attrs=["axis"], attrs_valid=lambda **kwargs: kwargs['axis'] is None or kwargs['axis'] < kwargs['ndim'])
+def vcumprod(dtype, ndim, axis):
 
 Review comment:
   What does `v` mean here? In `vadd`, I think it used to refer to "add two **v**ectors" in the beginning, but that function was later extended to support auto broadcasting. So the prefix `v` may be not appropriate anymore. @yzhliu Could you confirm? Thanks.

----------------------------------------------------------------
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


With regards,
Apache Git Services