I am trying to transform a priority queue data structure type I generated to store triangles(entity) with a certain error(float) using numba but I am running into some problems with the specification
Here is the code I have so far for the priority queue (which also allows for deletion of triangles)
import heapq
import numba as nb
from triangle import typeTriangle
from numba.experimental import jitclass
# Define a Priority Queue for Triangles
@jitclass
class PriorityQueuePlus:
queue: nb.typeof([(0, typeTriangle)])
_location_map : nb.typed.Dict.empty(key_type=typeTriangle, value_type=nb.types.int64)
def __init__(self):
self.queue = nb.typed.List.empty_list((0.0, typeTriangle))
# Maps triangles to their locations in the heap
self._location_map = nb.typed.Dict.empty(typeTriangle,0)
def push(self, triangle, error):
heapq.heappush(self.queue, (error, triangle))
self._location_map[triangle] = len(self.queue) - 1
def pop(self):
if self.queue:
error, triangle = heapq.heappop(self.queue)
del self._location_map[triangle]
return error, triangle
else:
raise IndexError("Queue is empty")
def delete(self, triangle):
if triangle in self._location_map:
location = self._location_map[triangle]
# remove the triangle with smallest error
error, first_triangle = self.queue.pop()
if location < len(self.queue):
# subsitute the triangle we want to delete
# by the one we just poped (with smallest error)
self.queue[location] = (error, first_triangle)
self._location_map[first_triangle] = location
del self._location_map[triangle]
heapq.heapify(self.queue)
def is_empty(self):
return len(self.queue) == 0
The error I get seems to be related with how I am specifying the class members. My intention is to have:
queue
to be a list of tuples. Each tuple being a (float, Triangle)._location_map
to be a simple dictionary where the key a Triangle and the value is an integer
Alas I get a very long error which I am only including the first part:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<function new_dict at 0x0000024996E86980>) found for signature:
>>> new_dict(typeref[instance.jitclass.Triangle#249974acf50<id:int64,e01:instance.jitclass.Edge#24997360cd0<id:int64,p0:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,p1:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,next:OptionalType(int64),inv:int64,triangle:int64>,e12:instance.jitclass.Edge#24997360cd0<id:int64,p0:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,p1:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,next:OptionalType(int64),inv:int64,triangle:int64>,e20:instance.jitclass.Edge#24997360cd0<id:int64,p0:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,p1:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,next:OptionalType(int64),inv:int64,triangle:int64>,p0:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,p1:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,p2:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,vertices:ListType[instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>]>], class(int64), n_keys=int64)
There are 2 candidate implementations:
- Of which 1 did not match due to:
Overload in function 'impl_new_dict': File: numba\typed\dictobject.py: Line 653.
With argument(s): '(typeref[instance.jitclass.Triangle#249974acf50<id:int64,e01:instance.jitclass.Edge#24997360cd0<id:int64,p0:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,p1:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,next:OptionalType(int64),inv:int64,triangle:int64>,e12:instance.jitclass.Edge#24997360cd0<id:int64,p0:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,p1:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,next:OptionalType(int64),inv:int64,triangle:int64>,e20:instance.jitclass.Edge#24997360cd0<id:int64,p0:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,p1:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,next:OptionalType(int64),inv:int64,triangle:int64>,p0:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,p1:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,p2:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,vertices:ListType[instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>]>], class(int64), n_keys=int64)':
Rejected as the implementation raised a specific error:
TypingError: Failed in nopython mode pipeline (step: native lowering)
No implementation of function Function(<built-in function eq>) found for signature:
>>> eq(instance.jitclass.Triangle#249974acf50<id:int64,e01:instance.jitclass.Edge#24997360cd0<id:int64,p0:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,p1:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,next:OptionalType(int64),inv:int64,triangle:int64>,e12:instance.jitclass.Edge#24997360cd0<id:int64,p0:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,p1:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,next:OptionalType(int64),inv:int64,triangle:int64>,e20:instance.jitclass.Edge#24997360cd0<id:int64,p0:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,p1:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,next:OptionalType(int64),inv:int64,triangle:int64>,p0:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,p1:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,p2:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,vertices:ListType[instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>]>, instance.jitclass.Triangle#249974acf50<id:int64,e01:instance.jitclass.Edge#24997360cd0<id:int64,p0:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,p1:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,next:OptionalType(int64),inv:int64,triangle:int64>,e12:instance.jitclass.Edge#24997360cd0<id:int64,p0:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,p1:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,next:OptionalType(int64),inv:int64,triangle:int64>,e20:instance.jitclass.Edge#24997360cd0<id:int64,p0:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,p1:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,next:OptionalType(int64),inv:int64,triangle:int64>,p0:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,p1:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,p2:instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>,vertices:ListType[instance.jitclass.Point3D#249951acb10<x:int64,y:int64,z:float64>]>)
There are 32 candidate implementations:
- Of which 28 did not match due to:
[...]
My understanding (please correct me if I am wrong) is that I first need to specify the type of each member and then initiate them???