Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dpctl doesn't allow mixing integer dtypes of indices arrays #1482

Closed
antonwolfy opened this issue Dec 4, 2023 · 1 comment
Closed

dpctl doesn't allow mixing integer dtypes of indices arrays #1482

antonwolfy opened this issue Dec 4, 2023 · 1 comment
Assignees

Comments

@antonwolfy
Copy link
Collaborator

The below example causes an exception for dpctl, but works with numpy:

a = numpy.ones((3, 4, 5), dtype='f4')
ai1 = numpy.ones((3, 4, 5), dtype='i4')
ai2 = numpy.reshape(numpy.arange(3, dtype='i8'), ((3, 1, 1)))

# no exception:
a[tuple([ai1, ai2])]

a = dpt.ones((3, 4, 5), dtype='f4')
ai1 = dpt.ones((3, 4, 5), dtype='i4')
ai2 = dpt.reshape(dpt.arange(3, dtype='i8'), ((3, 1, 1)))

a[tuple([ai1, ai2])]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[12], line 1
----> 1 _a[tuple([_ai1, _ai2])]

File dpctl/tensor/_usmarray.pyx:761, in dpctl.tensor._usmarray.usm_ndarray.__getitem__()

File ~/miniconda3/envs/dpnp_dev/lib/python3.9/site-packages/dpctl/tensor/_copy_utils.py:755, in _take_multi_index(ary, inds, p)
    750 res_usm_type = dpctl.utils.get_coerced_usm_type(usm_types_)
    751 res = dpt.empty(
    752     res_shape, dtype=ary.dtype, usm_type=res_usm_type, sycl_queue=exec_q
    753 )
--> 755 hev, _ = ti._take(
    756     src=ary, ind=inds, dst=res, axis_start=p, mode=0, sycl_queue=exec_q
    757 )
    758 hev.wait()
    760 return res

TypeError: Indices array data types are not all the same.
@ndgrigorian
Copy link
Collaborator

In [1]: import dpctl.tensor as dpt, dpctl, numpy as np

In [2]: a = np.ones((3, 4, 5), dtype='f4')
   ...: ai1 = np.ones((3, 4, 5), dtype='i4')
   ...: ai2 = np.reshape(np.arange(3, dtype='i8'), ((3, 1, 1)))
   ...:
   ...: a[tuple([ai1, ai2])]
   ...:
   ...: a = dpt.ones((3, 4, 5), dtype='f4')
   ...: ai1 = dpt.ones((3, 4, 5), dtype='i4')
   ...: ai2 = dpt.reshape(dpt.arange(3, dtype='i8'), ((3, 1, 1)))
   ...:
   ...: a[tuple([ai1, ai2])]
Out[2]:
usm_ndarray([[[[1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.]],

              [[1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.]],

              [[1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.]],

              [[1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.]]],


             [[[1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.]],

              [[1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.]],

              [[1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.]],

              [[1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.]]],


             [[[1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.]],

              [[1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.]],

              [[1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.]],

              [[1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.],
               [1., 1., 1., 1., 1.]]]], dtype=float32)

Indices arrays are now promoted to a common type when possible. Closing this as resolved by #1647

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants