Using jitclass with types.List of array results in TypingError
See original GitHub issue- I am using the latest released version of Numba (most recent is visible in the change log (https://github.com/numba/numba/blob/master/CHANGE_LOG).
- I have included below a minimal working reproducer (if you are unsure how to write one see http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports).
Issue
Using jitclass()
on a class with an attribute of type ListType[array(int64, 1d, A)]
leads to a TypingError
. However, this type is correctly printed when calling without a decorator.
Minimal example
from numba import types, typed, typeof
from numba.experimental import jitclass
import numpy as np
spec = [
("b", types.ListType(types.int64[:])),
]
@jitclass(spec)
class ListAttribute:
def __init__(self):
self.b = typed.List.empty_list(types.int64[:])
self.b.append(np.zeros(2, dtype=np.int64))
x = ListAttribute()
print(typeof(x.b))
Trace
Traceback (most recent call last):
File "/home/suthep/.config/JetBrains/PyCharm2020.1/scratches/scratch_1.py", line 16, in <module>
x = ListAttribute()
File "/home/suthep/git/uas/venv/lib/python3.8/site-packages/numba/experimental/jitclass/base.py", line 122, in __call__
return cls._ctor(*bind.args[1:], **bind.kwargs)
File "/home/suthep/git/uas/venv/lib/python3.8/site-packages/numba/core/dispatcher.py", line 401, in _compile_for_args
error_rewrite(e, 'typing')
File "/home/suthep/git/uas/venv/lib/python3.8/site-packages/numba/core/dispatcher.py", line 344, in error_rewrite
reraise(type(e), e, None)
File "/home/suthep/git/uas/venv/lib/python3.8/site-packages/numba/core/utils.py", line 80, in reraise
raise value.with_traceback(tb)
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<built-in function getitem>) with argument(s) of type(s): (class(int64), slice<a:b>)
* parameterized
In definition 0:
All templates rejected with literals.
In definition 1:
All templates rejected without literals.
In definition 2:
All templates rejected with literals.
In definition 3:
All templates rejected without literals.
In definition 4:
All templates rejected with literals.
In definition 5:
All templates rejected without literals.
In definition 6:
All templates rejected with literals.
In definition 7:
All templates rejected without literals.
In definition 8:
All templates rejected with literals.
In definition 9:
All templates rejected without literals.
In definition 10:
All templates rejected with literals.
In definition 11:
All templates rejected without literals.
In definition 12:
All templates rejected with literals.
In definition 13:
All templates rejected without literals.
In definition 14:
All templates rejected with literals.
In definition 15:
All templates rejected without literals.
This error is usually caused by passing an argument of a type that is unsupported by the named function.
[1] During: typing of intrinsic-call at /home/suthep/.config/JetBrains/PyCharm2020.1/scratches/scratch_1.py (12)
[2] During: typing of static-get-item at /home/suthep/.config/JetBrains/PyCharm2020.1/scratches/scratch_1.py (12)
File "scratch_1.py", line 12:
def __init__(self):
self.b = typed.List.empty_list(types.int64[:])
^
[1] During: resolving callee type: jitclass.ListAttribute#7f7dfdb8b910<b:ListType[array(int64, 1d, A)]>
[2] During: typing of call at <string> (3)
[3] During: resolving callee type: jitclass.ListAttribute#7f7dfdb8b910<b:ListType[array(int64, 1d, A)]>
[4] During: typing of call at <string> (3)
File "<string>", line 3:
<source missing, REPL/exec in use?>
Environment:
python==3.8.2
attrs==19.3.0
coverage==5.1
cycler==0.10.0
decorator==4.4.2
imagecodecs==2020.2.18
imageio==2.8.0
joblib==0.14.1
kiwisolver==1.2.0
llvmlite==0.32.1
matplotlib==3.2.1
more-itertools==8.2.0
networkx==2.4
numba==0.49.1
numpy==1.18.4
packaging==20.3
Pillow==7.1.2
pluggy==0.13.1
py==1.8.1
pyparsing==2.4.7
pytest==5.4.2
python-dateutil==2.8.1
PyWavelets==1.1.1
scikit-image==0.17.2
scikit-learn==0.23.0
scipy==1.4.1
six==1.14.0
threadpoolctl==2.0.0
tifffile==2020.5.11
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
How to do nested jitclass array instantiation - Stack Overflow
As the docs say, typed.List is an experimental feature, and it seems that inferring the type from a normal Python list doesn't work....
Read more >Types and signatures - Numba documentation
You will encounter Numba types mainly when trying to inspect the results of Numba's type inference, for debugging or educational purposes. However, you...
Read more >Compiling Python classes with @jitclass - Numba
List as a class member in a jitclass . Methods for using these types and various common patterns are presented in the following:...
Read more >numba/numba - Gitter
@guilhermeleobas I just reviewed the __getitem__ fix for the typed list, ... I can't just use a dictionary because I have values of...
Read more >Typed list of jitted functions in jitclass - Numba Discussion
I am trying to create a jitted class that contains a typed list of jitted functions. I have tried using the following in...
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
@spomjaksilp thanks for asking about this on the Numba issue tracker. Specifying types involving jitclasses, typed-lists and arrays can be a bit quirky at times. Here is a snippet that should get you what you want:
@andreapiso thanks, that’s some very helpful input, we appreciate it!
Perhaps the following could be used to make the type spec for the Array: