Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

[Numpy] different behaviours between numpy and mxnet.numpy #18137

Closed
acphile opened this issue Apr 22, 2020 · 4 comments
Closed

[Numpy] different behaviours between numpy and mxnet.numpy #18137

acphile opened this issue Apr 22, 2020 · 4 comments

Comments

@acphile
Copy link
Contributor

acphile commented Apr 22, 2020

different dtype when calculating division

For example:
in mxnet.numpy
   for two ndarray a,b with dtype='int64', the dtype of result c = a / b is 'float32'
in numpy
   the dtype is 'float64'
Generally, when calculating division, mxnet.numpy often uses float32 while numpy uses float64.
Using float32 will often lead to the loss of floating point precision.

b=mx.np.array(1, dtype='int32')
e=b/3
e.item()
>>> 0.3333333432674408

operator between different types

for example

import mxnet as mx
mx.npx.set_np()
mx.np.arange(5)
array([0., 1., 2., 3., 4.])
b=mx.np.arange(5)
a=b.astype('int32')
a==b

it will raise Error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ubuntu/incubator-mxnet/python/mxnet/numpy/multiarray.py", line 991, in __eq__
    return equal(self, other)
  File "/home/ubuntu/incubator-mxnet/python/mxnet/numpy/multiarray.py", line 8451, in equal
    return _mx_nd_np.equal(x1, x2, out)
  File "/home/ubuntu/incubator-mxnet/python/mxnet/ndarray/numpy/_op.py", line 6622, in equal
    return _api_internal.equal(x1, x2, out)
  File "/home/ubuntu/incubator-mxnet/python/mxnet/_ffi/_ctypes/function.py", line 115, in __call__
    raise get_last_ffi_error()
mxnet.base.MXNetError: MXNetError: Type inconsistent, Provided = float32, inferred type = int32

But numpy supports equal operation between different types

fail to use mxnet.numpy.prod(a.shape)

>>> mx.np.prod(a.shape)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 31, in prod
AssertionError: Argument a must have NDArray type, but got (5,)

while numpy supports that.

mxnet.numpy.ndarray.diagonal() is not supported

@leezu
Copy link
Contributor

leezu commented Apr 23, 2020

I think divergence between numpy and mxnet.numpy should be treated as bug as long as it's not explicitly called out in the documentation?

@leezu leezu added the v2.0 label May 8, 2020
@leezu
Copy link
Contributor

leezu commented May 8, 2020

@acphile can you help to create a separate issue for each problem, to simplify tracking the individual issues?

@leezu leezu mentioned this issue May 8, 2020
7 tasks
@acphile
Copy link
Contributor Author

acphile commented May 13, 2020

@acphile can you help to create a separate issue for each problem, to simplify tracking the individual issues?

Now they are added:
#18297
#18299
#18300
#18301

@yzhliu
Copy link
Member

yzhliu commented Jun 3, 2020

As they have been well tracked by separate issues, I will close this one.

@yzhliu yzhliu closed this as completed Jun 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants