Numba: sorting an array in place

Numba has an amazing ability to speed up the cycle with JIT compilation. The key turning point is that when using numpy you cannot create new arrays . Fortunately, most numpy functions include an optional parameter outto write output to - except numpy.sort. The most obvious alternative is numpy.ndarray.sortthat which is in place,

@njit("void(f8[:])")
def sort_inplace(arr):
  arr.sort()

but it does not compile,

...
...
...
/Users/duckworthd/anaconda/lib/python2.7/site-packages/numba/typeinfer.pyc in propagate(self)
    293                 print("propagate".center(80, '-'))
    294             oldtoken = newtoken
--> 295             self.constrains.propagate(self.context, self.typevars)
    296             newtoken = self.get_state_token()
    297             if config.DEBUG:

/Users/duckworthd/anaconda/lib/python2.7/site-packages/numba/typeinfer.pyc in propagate(self, context, typevars)
    112                 raise
    113             except Exception as e:
--> 114                 raise TypingError("Internal error:\n%s" % e, constrain.loc)
    115
    116

TypingError: Internal error:
Attribute 'sort' of array(float64, 1d, A) is not typed

With the exception of reimplementing the sorting algorithm, is there a way to sort the numpy array in a JIT-compiled numba loop?

+4
source share
1 answer

Numba "nopython", , , ndarray.sort(). "python", , python, ndarray.sort(), C, . numba github.

: numba nopython, , python. , ndarray.sort(), , numpy.arange(), , ( ndarray.sort() numpy.arange() , , , , ).

, : jit njit, numba ndarray.sort() nopython, .

+4

Source: https://habr.com/ru/post/1542428/


All Articles