Skip to content

Support structured arrays #2031

@mrocklin

Description

@mrocklin

It looks like cupy supports record arrays, but fails to accept a list dtype that was not properly packed as a dtype object. My guess is that this could

In [1]: import numpy as np

In [2]: import cupy

In [3]: x = cupy.empty(shape=5, dtype=np.dtype([('a', int), ('b', float)]))

In [4]: x
Out[4]:
array([(0, 0.), (0, 0.), (0, 0.), (0, 0.), (0, 0.)],
      dtype=[('a', '<i8'), ('b', '<f8')])

In [5]: x = cupy.empty(shape=5, dtype=[('a', int), ('b', float)])
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-8478cd56259b> in <module>
----> 1 x = cupy.empty(shape=5, dtype=[('a', int), ('b', float)])

~/cupy/cupy/creation/basic.py in empty(shape, dtype, order)
     20
     21     """
---> 22     return cupy.ndarray(shape, dtype, order=order)
     23
     24

~/cupy/cupy/core/core.pyx in cupy.core.core.ndarray.__init__()

~/cupy/cupy/core/_dtype.pyx in cupy.core._dtype.get_dtype_with_itemsize()

TypeError: unhashable type: 'list'

Numpy handles this ok. My guess is that this could be resolved by a quick typecheck, or just always calling np.dtype on the input to any dtype= keyword.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions