Hello community, I am writing the code as follows,
import numba as nb
from collections import OrderedDict
from numba import deferred_type, optional
from numba.experimental import jitclass
from numba import types
node_type = deferred_type()
@jitclass([
('parent', optional(node_type)),
('children', types.DictType(types.int32, node_type)),
])
class TreeNode(object):
def __init__(self, parent=None):
self.parent = parent
self.children = nb.typed.Dict.empty(types.int32, node_type)
node_type.define(TreeNode.class_type.instance_type)
TreeNode(1)
However this is giving me:
python3: /root/miniconda3/conda-bld/llvmdev_1596720471173/work/lib/IR/DataLayout.cpp:705: llvm::Align llvm::DataLayout::getAlignment(llvm::Type*, bool) const: Assertion `Ty->isSized() && “Cannot getTypeInfo() on a type that is unsized!”’ failed.
Am I doing anything wrong or this is not yet supported by numba? If latter is the case would u describe any workaround for this? Thanks in advance!
OK, it turns out that was just a bug in the example - parent is a node type but it was being passed an integer. If we construct two nodes so that one can be the parent of the other, like:
import numba as nb
from numba import deferred_type, optional
from numba.experimental import jitclass
from numba import types
node_type = deferred_type()
@jitclass([
('parent', optional(node_type)),
('children', types.DictType(types.int32, node_type)),
])
class TreeNode(object):
def __init__(self, parent=None):
self.parent = parent
self.children = nb.typed.Dict.empty(types.int32, node_type)
node_type.define(TreeNode.class_type.instance_type)
t = TreeNode()
t2 = TreeNode(t)