I am adding to the thread as it is related but and I cannot edit my previous message above. Still having problems with my classes. My classes are a bit larger than what I show here but I think with the following there is plenty. Here is what I have,
point file
import numba as nb
from collections import namedtuple
Point3D = namedtuple('Point3D','x y z', defaults=(0, 0, 0.0))
Point2D = namedtuple('Point2D','x y', defaults=(0, 0))
# Let Numba infer the type of a Point instance
Point3DType = nb.typeof(Point3D(0, 0, 0.0))
Point2DType = nb.typeof(Point3D(0, 0))
edge file
import numba as nb
from point import Point3D, Point3DType
from numba.experimental import jitclass
spec_edge ={
'id': nb.u8,
'p0': Point3DType,
'p1': Point3DType,
'next': nb.optional(nb.u8),
'inv': nb.optional(nb.u8),
'triangle': nb.optional(nb.u8),
}
EdgeType = nb.deferred_type()
@jitclass(spec_edge)
class Edge:
def __init__(self, id: int, p0: Point3D, p1: Point3D):
self.id = id
self.p0 = p0
self.p1 = p1
self.next = None
self.inv = None
self.triangle = None
EdgeType.define(Edge.class_type.instance_type)
triangle file
import numpy as np
from point import Point3DType, Point3D, Point2D
from edge import EdgeType, Edge
from numba.experimental import jitclass
import numba as nb
spec_triangle = {'e01': EdgeType,
'e12': EdgeType,
'e20': EdgeType,
'id': nb.u8,
'p0': Point3DType,
'p1': Point3DType,
'p2': Point3DType,
'vertices': nb.types.ListType(Point3DType),
}
@jitclass(spec_triangle)
class Triangle:
def __init__(self, id: int, e01: Edge, e12: Edge, e20: Edge):
self.id = id
self.e01 = e01
self.e12 = e12
self.e20 = e20
if not self.closed():
Exception('Triangle not closed!')
self.e01.next = e12.id
self.e12.next = e20.id
self.e20.next = e01.id
self.e01.triangle = id
self.e12.triangle = id
self.e20.triangle = id
self.p0 = e01.p0
self.p1 = e01.p1
self.p2 = e12.p1
self.vertices = [self.p0, self.p1, self.p2]
I tried running the following code
from point import Point3D
from edge import Edge
from triangle import Triangle
p0= Point3D(0, 3, 0.5)
p1= Point3D(1, 0, 1.5)
p2= Point3D(2, 0, 0.5)
t0 = Triangle(0 ,Edge(1, p0, p1), Edge(2, p1,p2), Edge(3, p2, p0))
but got the following error
---------------------------------------------------------------------------
TypingError Traceback (most recent call last)
c:\Python\Notebooks\active\tin\testing.ipynb Cell 12 line 1
----> 1 t0 = Triangle(0 ,Edge(1, p0, p1), Edge(2, p1,p2), Edge(3, p2, p0))
File c:\Python\Miniconda3\envs\tin\Lib\site-packages\numba\experimental\jitclass\base.py:124, in JitClassType.__call__(cls, *args, **kwargs)
122 bind = cls._ctor_sig.bind(None, *args, **kwargs)
123 bind.apply_defaults()
--> 124 return cls._ctor(*bind.args[1:], **bind.kwargs)
File c:\Python\Miniconda3\envs\tin\Lib\site-packages\numba\core\dispatcher.py:468, in _DispatcherBase._compile_for_args(self, *args, **kws)
464 msg = (f"{str(e).rstrip()} \n\nThis error may have been caused "
465 f"by the following argument(s):\n{args_str}\n")
466 e.patch_message(msg)
--> 468 error_rewrite(e, 'typing')
469 except errors.UnsupportedError as e:
470 # Something unsupported is present in the user code, add help info
471 error_rewrite(e, 'unsupported_error')
File c:\Python\Miniconda3\envs\tin\Lib\site-packages\numba\core\dispatcher.py:409, in _DispatcherBase._compile_for_args.<locals>.error_rewrite(e, issue_type)
407 raise e
408 else:
--> 409 raise e.with_traceback(None)
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Internal error at <numba.core.typeinfer.CallConstraint object at 0x000001CEC061BB10>.
Failed in nopython mode pipeline (step: native lowering)
No definition for lowering DeferredType#1987427294352.next = OptionalType(uint64)
File "triangle.py", line 37:
def __init__(self, id: int, e01: Edge, e12: Edge, e20: Edge):
<source elided>
self.e01.next = e12.id
^
During: lowering "($144load_attr.3).next = $132load_attr.1" at c:\Python\Notebooks\active\tin\triangle.py (37)
During: resolving callee type: jitclass.Triangle#1cebe633010<e01:DeferredType#1987427294352,e12:DeferredType#1987427294352,e20:DeferredType#1987427294352,id:uint64,p0:Point3D(int64, int64, float64),p1:Point3D(int64, int64, float64),p2:Point3D(int64, int64, float64),vertices:ListType[Point3D(int64, int64, float64)]>
During: typing of call at <string> (3)
Enable logging at debug level for details.
File "<string>", line 3:
<source missing, REPL/exec in use?>
It seems that it does not recognize self.e01.next
as an attribute of an edge???