Are nested structarrays valid in numba?

Hello friendly people :wink:

The documentation seems to be a bit unclear about this, so thought I’ll double check here:

base_dtype = np.dtype([(f'x', np.uint32), (f'y', np.uint16), (f'z', np.uint8)])
n_types = 5
complex_dtype = np.dtype([('global1', np.uint32), ('global2', np.int64), ('comp', base_dtype, n_types)])
test_var_arr = np.empty(10, dtype=complex_dtype)
@nb.njit()
def test(struct_arr):
    struct_arr.view(np.uint8).fill(0)
    for ix in range(n_types):
        value_offset = ix * 10
        struct_arr[0]['comp'][ix]['x'] = value_offset + 1
        struct_arr[0]['comp'][ix]['y'] = value_offset + 2
        struct_arr[0]['comp'][ix]['z'] = value_offset + 3

This seems to compile just fine - am I good to go, or should I be wary of something here?

I want to rely heavily on this feature so don’t want to encounter a hiccup on the way :slight_smile:

Many thanks in advance - Adrian

Can you point me toward the docs that were unclear? My understanding was that structured arrays were supported in numba.

Many thanks for getting back.

Looking at the docs I’m getting some conflicting messages:

The following scalar types and features are not supported:

  • Arbitrary Python objects
  • Half-precision and extended-precision real and complex numbers
  • Nested structured scalars the fields of structured scalars may not contain other structured scalars

[…]

Array types

NumPy arrays of any of the scalar types above are supported, regardless of the shape or layout.

After doing some digging it seems this has been asked before 4 years ago here, but I think it may be worth getting back to this. Seems the structarrays have later been straightened in this PR .

If structarrays are good, I’d be happy to offer a PR to improve the wording of the documentation, as I believe this is a gotcha for many other users.