You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@mxnet.apache.org by GitBox <gi...@apache.org> on 2021/03/04 04:26:10 UTC
[GitHub] [incubator-mxnet] khaotik commented on issue #6526: Support 'kAddTo' for SwapAxis Op
khaotik commented on issue #6526:
URL: https://github.com/apache/incubator-mxnet/issues/6526#issuecomment-790279925
Hi, I'm looking for simple issues for my first PR. Upon reviewing C++ code, it seems this issue is already resolved, or am I missing anything?
I also made a small test case:
```python
#!/usr/bin/env python
from itertools import product
import numpy as np
import mxnet as mx
CTX_LIST = [mx.gpu(), mx.cpu()]
DTYPE_LIST = ['float16', 'float32', 'float64']
for CTX, DTYPE in product(CTX_LIST, DTYPE_LIST):
with mx.autograd.record():
v_x = mx.nd.random.uniform(
-1., 1., shape=(4,5,6),
dtype=DTYPE, ctx=CTX)
v_x.attach_grad(grad_req='add')
v_x.grad[:] = 0.
v_y = mx.nd.swapaxes(v_x, 1, 2)
v_err = mx.nd.square(v_y)
v_err.backward(retain_graph=True)
v_y = mx.nd.swapaxes(v_x, 0, 1)
v_err = mx.nd.square(v_y)
v_err.backward(retain_graph=True)
v_y = mx.nd.swapaxes(v_x, 0, 2)
v_err = mx.nd.square(v_y)
v_err.backward(retain_graph=True)
assert(np.allclose(v_x.asnumpy()*6, v_x.grad.asnumpy()))
```
----------------------------------------------------------------
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
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@mxnet.apache.org
For additional commands, e-mail: issues-help@mxnet.apache.org