Support for Record type in jitclass
See original GitHub issueFeature request
It would be great if it was possible to have Record type member in jitclass.
import numpy as np
import numba
from numba.experimental import jitclass
my_type = np.dtype([("age", np.int32), ("height", np.int32)])
a = np.zeros(1, dtype=my_type)[0]
spec=[
("_a", numba.typeof(a))
]
@jitclass(spec=spec)
class A:
def __init__(self, a):
self._a = a
A(a) # This throw below exception
Traceback (most recent call last):
File "/opt/test/test.py", line 15, in <module>
A(a) # This throw below exception
File "/opt/python/py3.9/lib/python3.9/site-packages/numba/experimental/jitclass/base.py", line 124, in __call__
return cls._ctor(*bind.args[1:], **bind.kwargs)
File "/opt/python/py3.9/lib/python3.9/site-packages/numba/core/dispatcher.py", line 482, in _compile_for_args
error_rewrite(e, 'typing')
File "/opt/python/py3.9/lib/python3.9/site-packages/numba/core/dispatcher.py", line 423, in error_rewrite
raise e.with_traceback(None)
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Internal error at <numba.core.typeinfer.CallConstraint object at 0x7f42aef1b280>.
Failed in nopython mode pipeline (step: native lowering)
use load_from_data_pointer() instead
File "test.py", line 13:
def __init__(self, a):
self._a = a
^
During: lowering "(self)._a = a" at /opt/test/test.py (13)
During: resolving callee type: jitclass.A#7f4306358400<_a:Record(age[type=int32;offset=0],height[type=int32;offset=4];8;False)>
During: typing of call at <string> (3)
Enable logging at debug level for details.
File "<string>", line 3:
<source missing, REPL/exec in use?>
This was tested on latest numba version (0.54.0)
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Compiling Python classes with @jitclass - Numba
Numba supports code generation for classes via the numba.jitclass() decorator. ... float32 # import the types from numba.experimental import jitclass spec ...
Read more >Compiling Python classes with @jitclass
Here SomeOtherType could be any supported Python type (e.g. bool , typing.Dict[int, typing.Tuple[float, float]] , or another jitclass ). Note ...
Read more >Initilizing a Numpy structured array inside a jitclass constructor ...
This works: from numba.experimental import jitclass from numba import from_dtype ... Cannot cast unaligned array(Record(one[type=[unichr x ...
Read more >Assigning to NumPy structural array using a tuple in `@jitclass`
Yeah, I plan to make this generic using a factory class/function which would mean the record field names could be anything and field-by-field...
Read more >compile python class with numba - Stack Overflow
How can I simply use any python object (of any class type) inside a class that is compiled by a numba.jitclass() ? and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I would appreciate this as well. Can currently set Numpy structured arrays on jitclasses no problem, but can’t set a specific accessed row (with roughly the same error above). Current workaround is to just keep track of the index I want and access the row on the higher ndarray as needed in the methods instead of storing it for easier access.
Removing both the ‘needtriage’ and ‘stale’ labels.