oneflow icon indicating copy to clipboard operation
oneflow copied to clipboard

numpy advancing indexing behavior changed after 1.23.0

Open wyg1997 opened this issue 2 years ago • 0 comments

Summary

Multidimensional indexing with non-tuple values is not allowed. Previously, code such as arr[ind] where ind = [[0, 1], [0, 1]] produced a FutureWarning and was interpreted as a multidimensional index (i.e., arr[tuple(ind)]). Now this example is treated like an array index over a single dimension (arr[array(ind)]). Multidimensional indexing with anything but a tuple was deprecated in NumPy 1.15. ( referred from: https://numpy.org/doc/stable/release/1.23.0-notes.html#new-functions )

It means advance indexing is not align with numpy and some code will not be compatible with numpy after 1.23.0

Code to reproduce bug

numpy_x = np.arange(0, 60, 1).reshape([3, 4, 5]).astype(np.float32)
print(numpy_x[[[0, 1], [0, 1], [1, 0]]].shape)  # shape is (3, 2, 4, 5)
print(numpy_x[tuple([[0, 1], [0, 1], [1, 0]])].shape)  # shape is (2, )

flow_x = flow.tensor(numpy_x)
print(flow_x[[[0, 1], [0, 1], [1, 0]]].shape)  # shape is (2, )

wyg1997 avatar Sep 16 '22 07:09 wyg1997