New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tuple of functions is not iterable / cannot be accessed by index #7923
Comments
Thanks for the report. From the above, I think a minimal working reproducer is: from numba import njit
@njit
def square(x):
return x ** 2
@njit
def sum(x):
return x + 1
@njit
def foo():
funcs = (sum, square)
for fn in funcs:
print(fn(10.))
foo() and that the error is about iterating over a tuple of functions. The underlying issue is that Numba considers the type of a tuple like There's two ways around this:
Hope this helps. |
@stuartarchibald I see. this is why my impl looks something like this
This works fine as the func tuple is not accessed by a loop. But this takes away any parallelism that prange may provide |
If the index is a compile time constant (like literal 0 or 1) it's possible to work out the type of the dispatcher at that index and so it's not a problem. It's only in the case of the loop difficulties arise, for example, in: @njit
def foo():
funcs = (sum, square)
for fn in funcs:
print(fn(10.)) the type of
You can still use the parallelism from from numba import njit, prange
@njit('float64(float64)')
def square(x):
return x ** 2
@njit('float64(float64)')
def sum(x):
return x + 1
@njit(parallel=True)
def foo():
funcs = (sum, square)
for idx in prange(len(funcs)):
fn = funcs[idx]
print(fn(10.))
foo()
foo.parallel_diagnostics() |
Closing this question as it seems to be resolved. Numba now has a discourse forum https://numba.discourse.group/ which is great for questions like this, please do consider posting there in future :) Thanks! |
I am using numba 0.52.0 and intel sdc for Pandas support
This is what my method looks like
when i try to run
this fails with error
The same also happens when trying to run with
The text was updated successfully, but these errors were encountered: