Use jitclass field to store single Record (structured-array-element) instance

I want to create a field in a Jitclass to store a single Record object.
As I understand it, a numba Record object represents a single element from a structured numpy array. Please correct me if I am wrong.

I have tried to achieve this with the following code:

dt = np.dtype([(‘a’, np.bool_),(‘b’, np.bool_)])
arr = np.array([(True, False)], dt)

spec={‘field1’: numba.typeof(arr[0])}
class Testclass:
def init(self, signals) → None:
self.signals = signals

Testclass = jitclass(Testclass, spec)

Testclass(arr[0])

However, this produces the following error:

How can this be achieved? And is there a place in the documentation where I should have been able to find a solution for this?

Thanks in advance.

~Boris

hi @BravoDeltaBD the code looks like something that should work. It must be a bug. Do you need to use a jitclass or could you use a StructRef instead? If I were you I would test this with a StructRef, as this might be a bug with in jitclass. StructRef is the replacement of jitclass.

Luk

I’ve tried this sort of thing before and it seemed the support for single Records is a bit lacking. I always ended up storing it in a length-1 array.

And as @luk-f-a mentioned, jitclass is easy to use but in the end will likely disappoint… go with StructRef, which has a bit more learning curve and boilerplate but is worth it (in my opinion, of course :slight_smile: )