ist es möglich eine Zeilenvertauschung mit numba zu beschleunigen?
Code: Alles auswählen
from numba import jit
import numpy as np
#Nur ein Beispiel
def swap_rows(A):
A[[0, 2]] = A[[2, 0]]
return A
A = np.array([[1,2,3], [4,5,6], [7,8,9]])
t = %timeit -o swap_rows(A)
numba_swap = jit()(swap_rows)
t_numba = %timeit -o numba_swap(A)
3.82 µs ± 14.2 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
und diese Warnung
<ipython-input-4-91659dcd8c37>:5: NumbaWarning:
Compilation is falling back to object mode WITH looplifting enabled because Function "swap_rows" failed type inference due to: No implementation of function Function(<built-in function getitem>) found for signature:
>>> getitem(array(int64, 2d, C), list(int64)<iv=[2, 0]>)
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(int64, 2d, C), list(int64)<iv=None>)':
No match.
- Of which 1 did not match due to:
Overload in function 'GetItemBuffer.generic': File: numba/core/typing/arraydecl.py: Line 162.
With argument(s): '(array(int64, 2d, C), list(int64)<iv=None>)':
Rejected as the implementation raised a specific error:
TypeError: unsupported array index type list(int64)<iv=None> in [list(int64)<iv=None>]
raised from /home/yoflem/anaconda3/lib/python3.8/site-packages/numba/core/typing/arraydecl.py:68
- Of which 1 did not match due to:
Overload in function 'GetItemBuffer.generic': File: numba/core/typing/arraydecl.py: Line 162.
With argument(s): '(array(int64, 2d, C), list(int64)<iv=[2, 0]>)':
Rejected as the implementation raised a specific error:
TypeError: unsupported array index type list(int64)<iv=[2, 0]> in [list(int64)<iv=[2, 0]>]
raised from /home/yoflem/anaconda3/lib/python3.8/site-packages/numba/core/typing/arraydecl.py:68
During: typing of intrinsic-call at <ipython-input-4-91659dcd8c37> (6)
During: typing of static-get-item at <ipython-input-4-91659dcd8c37> (6)
File "<ipython-input-4-91659dcd8c37>", line 6:
def swap_rows(A):
A[[0, 2]] = A[[2, 0]]
^
def swap_rows(A):
/home/yoflem/anaconda3/lib/python3.8/site-packages/numba/core/object_mode_passes.py:151: NumbaWarning: Function "swap_rows" was compiled in object mode without forceobj=True.
File "<ipython-input-4-91659dcd8c37>", line 5:
def swap_rows(A):
^
warnings.warn(errors.NumbaWarning(warn_msg,
/home/yoflem/anaconda3/lib/python3.8/site-packages/numba/core/object_mode_passes.py:161: NumbaDeprecationWarning:
Fall-back from the nopython compilation path to the object mode compilation path has been detected, this is deprecated behaviour.
For more information visit https://numba.pydata.org/numba-doc/late ... -using-jit
File "<ipython-input-4-91659dcd8c37>", line 5:
def swap_rows(A):
^
warnings.warn(errors.NumbaDeprecationWarning(msg,
4.04 µs ± 10.6 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)