Some numpy broadcasting operations fail in numba 0.51
See original GitHub issueMinimal code example:
import numpy as np
from numba import njit
@njit(parallel=True)
def use_numba():
temp = np.ones((3, 5))
temp[1:] *= (2*np.ones(5))
return temp print(use_numba())
(I’m using Python 3.8 but guess this is irrelevant) in numba 0.49.1
this works fine and gives:
[[1. 1. 1. 1. 1.]
[2. 2. 2. 2. 2.]
[2. 2. 2. 2. 2.]]
but in numba 0.51.2
it gives an error, I think it is a broadcasting issue between temp
which is 2D and the other factor which is 1D:
TypingError: Failed in nopython mode pipeline (step: nopython mode backend)
Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<built-in function getitem>) found for signature:
>>> getitem(array(float64, 1d, C), UniTuple(uint64 x 2))
There are 22 candidate implementations:
- Of which 20 did not match due to:
Overload of function 'getitem': File: <numerous>: Line N/A.
With argument(s): '(array(float64, 1d, C), UniTuple(uint64 x 2))':
No match.
- Of which 2 did not match due to:
Overload in function 'GetItemBuffer.generic': File: numba/core/typing/arraydecl.py: Line 162.
With argument(s): '(array(float64, 1d, C), UniTuple(uint64 x 2))':
Rejected as the implementation raised a specific error:
TypeError: cannot index array(float64, 1d, C) with 2 indices: UniTuple(uint64 x 2)
raised from /home/zonca/anaconda/envs/temp/lib/python3.8/site-packages/numba/core/typing/arraydecl.py:84
During: typing of intrinsic-call at /extrahome/software/pysm/minimal.py (7)
File "minimal.py", line 7:
def use_numba():
<source elided>
temp = np.ones((3, 5))
temp[1:] *= (2*np.ones(5))
^
During: lowering "id=3[LoopNest(index_variable = parfor_index.29, range = (0, $22binary_subscr.11_size0.1, 1)), LoopNest(index_variable = parfor_index.30, range = (0, $const_5, 1))]{4: <ir.Block at /extrahome/software/pysm/minimal.py (7)>}Var($parfor_index_tuple_var.31, minimal.py:7)" at /extrahome/software/pysm/minimal.py (7)
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
5 minute guide to Numba
A ~5 minute guide to Numba¶. Numba is a just-in-time compiler for Python that works best on code that uses NumPy arrays and...
Read more >Troubleshooting and tips - Numba documentation
The most common reason for slowness of a compiled JIT function is that compiling in nopython mode has failed and the Numba compiler...
Read more >Faster Python with NumPy broadcasting and Numba
Array Broadcasting's pros: you only write Python code; it is very fast for any array size; there is no compilation overhead; you don't...
Read more >importing numba module shows ImportError - Stack Overflow
from numba import jit import numpy as np x = np.arange(100).reshape(10, 10) @jit(nopython=True) # Set "nopython" mode for best performance, ...
Read more >Dynamic Programming on the GPU via JAX - QuantEcon - Notes
JAX prefers vectorized operations, meaning that loops need to be replaced by operations on arrays. We use some NumPy broadcasting tricks to ...
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
Thanks @zonca, I’ve found it:
the new support for inplace binops on arrays caused this regression.
CC @DrTodd13
@DrTodd13 I also confirm that disabling
inplace_binops
works:works fine.