question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for Record type in jitclass

See original GitHub issue

Feature 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:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
iyz91commented, Dec 30, 2021

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.

0reactions
esccommented, Oct 18, 2021

Removing both the ‘needtriage’ and ‘stale’ labels.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found