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

[Numpy] The argument parser of some operators cannot parse numpy integers or mx.numpy integers correctly. #16855

Open
sxjscience opened this issue Nov 19, 2019 · 2 comments

Comments

@sxjscience
Copy link
Member

import mxnet as mx
import numpy as np
mx.npx.set_np()
a = mx.np.ones((10, 10))
b = mx.np.split(a, np.int32(1))

Error:

ValueError: indices_or_sections must either int, or tuple / list / set of ints

The reason is that we are testing against the python int here:
https://github.com/apache/incubator-mxnet/blob/4f14bf4fe51b586f86a1e7bd38b8282997e6ffbb/python/mxnet/ndarray/numpy/_op.py#L2733

One way to solve the problem is to see if the indices_or_sections belongs to integer_types:
https://github.com/apache/incubator-mxnet/blob/4f14bf4fe51b586f86a1e7bd38b8282997e6ffbb/python/mxnet/base.py#L49

However, this will still be problematic, because the interger_types do not include the mxnet.numpy integers, i.e the following script will still raise the error:

import mxnet as mx
import numpy as np
mx.npx.set_np()
a = mx.np.ones((10, 10))
b = mx.np.split(a, mx.np.int32(1))

We will need some one to look at the problem @reminisce @haojin2 .

@sxjscience sxjscience added the Bug label Nov 19, 2019
@sxjscience
Copy link
Member Author

I'll partially solve the problem for the split/hsplit/vsplit operators by using integer_types in #16621. However, we need a way to support mxnet numpy scalars.

@sxjscience
Copy link
Member Author

After discussion with @junrushao1994, we can try to convert the input to python int first. Also, in JAX and numpy, it supports float32 inputs and automatically detects the float case.

import jax.numpy as np
a = np.ones((10, 10))
b = np.split(a, np.float32(2))
import jax.numpy as np
a = np.ones((10, 10))
b = np.split(a, np.float32(2.2))
# Raises ValueError: array split does not result in an equal division

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

1 participant