import mxnet as mx
mx.npx.set_np()
a = mx.np.ones((10, 10), dtype=mx.np.int32)
b = -a
print(b.dtype)
Output:
float64
@sxjscience
Thanks for your issue, I was able to reproduce this issue on my device, we discovered that the cause of this problem is https://github.com/apache/incubator-mxnet/blob/master/python/mxnet/numpy/multiarray.py#L988, where the origin tensor would be multiplied by -1.0 when calling negation.
I believe this problem could be resolved by changing -1.0 to -1, as the backend is now able to perform type promotion for scalar-tensor binary ops, which should return a value of type int32.
I will create a fix for this issue.
@CassiniXu thanks for finding the root cause. In terms of the solution, I'm not sure if multiply is the right way to go. After all, we don't want int8 number to be promoted to int32 when being negated. How about implementing a negation kernel?
Most helpful comment
@sxjscience
Thanks for your issue, I was able to reproduce this issue on my device, we discovered that the cause of this problem is https://github.com/apache/incubator-mxnet/blob/master/python/mxnet/numpy/multiarray.py#L988, where the origin tensor would be multiplied by
-1.0when calling negation.I believe this problem could be resolved by changing
-1.0to-1, as the backend is now able to perform type promotion for scalar-tensor binary ops, which should return a value of typeint32.I will create a fix for this issue.