Collections of jitclass instances

0 views
Skip to first unread message

Peter Kucirek

unread,
Sep 21, 2017, 7:06:24 PM9/21/17
to Numba Public Discussion - Public
Hello,

I've been experimenting with the @jitclass decorator and have a small question: is it possible to compile a class that contains a List of another class? 

Perhaps some code will illustrate my example:

```
import numpy as np
import numba as nb
from collections import OrderedDict


arc_type
= nb.deferred_type()


spec
= OrderedDict()
spec
['vertex_id'] = nb.int32
spec
['outgoing_arcs'] = nb.types.List(arc_type)
spec
['incoming_arcs'] = nb.types.List(arc_type)
@nb.jitclass(spec)
class Vertex(object):
   
   
def __init__(self, vertex_id):
       
self.vertex_id = vertex_id
       
self.outgoing_arcs = []
       
self.incoming_arcs = []


spec
= OrderedDict()
spec
['from_vertex'] = Vertex.class_type.instance_type
spec
['to_vertex'] = Vertex.class_type.instance_type
@nb.jitclass(spec)
class Arc(object):
   
def __init__(self, from_vertex, to_vertex):
       
self.from_vertex = from_vertex
       
self.to_vertex = to_vertex
       
        from_vertex
.outgoing_arcs.append(self)
        to_vertex
.incoming_arcs.append(self)


arc_type
.define(Arc.class_type.instance_type)

```

This first bit of code runs,  no trouble. But I cannot instantiate any `Vertex` objects:

```
v0 = Vertex(0)

```

This gives me an error right away :

```
TypingError: Failed at nopython (nopython frontend)
Failed at nopython (nopython frontend)
Can't infer type of variable '$0.3': list(undefined)
[1] During: resolving callee type: jitclass.Vertex#6b54ee8<vertex_id:int32,outgoing_arcs:list(DeferredType#131898280),incoming_arcs:list(DeferredType#131898280)>
[2] During: typing of call at <string> (3)

```
Am I attempting the impossible? Or did I just miss something in my code?Enter code here...

Thanks,

Peter Kucirek


Message has been deleted

J Ello

unread,
Oct 5, 2017, 7:51:13 AM10/5/17
to Numba Public Discussion - Public
This would be really interesting for me as well!


Am Freitag, 22. September 2017 01:06:24 UTC+2 schrieb Peter Kucirek:
Hello,

I've been experimenting with the @jitclass decorator and have a small question: is it possible to compile a class that contains a List of another class? 

Perhaps some code will illustrate my example:
...
Reply all
Reply to author
Forward
0 new messages