Jitclass with input of list of jitclass

Say I have a class:

@numba.experimental.jitclass([
    ('foo', numba.int64),
])
class foo(object):
    def __init__(self, foo):
        self.foo = foo

And another class which takes, as input, a list of these classes:

@numba.experimental.jitclass([
    ('bar', numba.types.ListType(foo)),
])
class bar(object):
    def __init__(self, bar):
        self.bar = bar

bar(numba.typed.List([foo(1)]))

Doing the above results in an error. I can fix it by doing:

@numba.experimental.jitclass([
    ('bar', numba.types.ListType(numba.typeof(foo(1)))),
])
class bar(object):
    def __init__(self, bar):
        self.bar = bar

bar(numba.typed.List([foo(1)]))

But I don’t like having to instantiate a class like foo(1) and using numba.typeof. Is there a way to do the above without having to instantiate the class and using typeof?

Hi Justin,

I think your question has been answered here: How do I create a jitclass that takes a list of jitclass objects?

Jitclasses have a field called instance_type that should help you here.

Yep, foo.class_type.instance_type works! Thanks!!!

Great :slight_smile:
If that solves your problem you can mark the thread as answered