Hi
Not sure if I am misunderstanding the docs, or if I am doing something wrong, so bear with me please.
Scalar types
Numba supports the following Numpy scalar types:
[...]
Structured scalars: structured scalars made of any of the types above and arrays of the types above
The following scalar types and features are not supported:
[...]
Nested structured scalars the fields of structured scalars may not contain other structured scalars
(from Supported NumPy features — Numba 0.50.1 documentation)
To me this reads as if it should be possible to have a custom numpy dtype, where one or more fields are not themselves scalar but arrays, i.e. something like
import numpy as np
x = np.array([(1, (2,2)), (3, (1,4))], dtype=[('foo', 'i8'), ('bar', 'f4', 2)])
If I try to access the scalar field foo
everything is fine
import numba as nb
@nb.njit
def foo(x):
return x.foo
foo(x)
returns array([1, 3])
.
If I try to access the array field bar
things crash and burn
@nb.njit
def bar(x):
return x.bar
bar(x)
results in
---------------------------------------------------------------------------
TypingError Traceback (most recent call last)
<ipython-input-18-5600b61d894a> in <module>
----> 1 bar(x)
~/anaconda3/lib/python3.7/site-packages/numba/core/dispatcher.py in _compile_for_args(self, *args, **kws)
412 e.patch_message(msg)
413
--> 414 error_rewrite(e, 'typing')
415 except errors.UnsupportedError as e:
416 # Something unsupported is present in the user code, add help info
~/anaconda3/lib/python3.7/site-packages/numba/core/dispatcher.py in error_rewrite(e, issue_type)
355 raise e
356 else:
--> 357 raise e.with_traceback(None)
358
359 argtypes = []
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Internal error at resolving type of attribute "bar" of "x".
Buffer dtype cannot be buffer, have dtype: nestedarray(float32, (2,))
During: typing of get attribute at <ipython-input-17-c963215583c1> (3)
Enable logging at debug level for details.
File "<ipython-input-17-c963215583c1>", line 3:
def bar(x):
return x.bar
^
The error message suggests that I am vioating the nesting mentioned in the docs. However I got the impression that nesting should be fine as long as the nested type is not itself a structured type.
Thanks for any help