Why Numba doesn't improve this recursive function

后端 未结 3 2106
有刺的猬
有刺的猬 2021-01-26 06:28

I have an array of true/false values with a very simple structure:

# the real array has hundreds of thousands of items
pos         


        
3条回答
  •  再見小時候
    2021-01-26 07:23

    The gist is, only the part of logic that uses Python machinery can be accelerated -- by replacing it with some equivalent C logic that strips away most of the complexity (and flexibility) of Python runtime (I presume this is what Numba does).

    All the heavy lifting in NumPy operations is already implemented in C and very simple (since NumPy arrays are contiguous chunks of memory holding regular C types) so Numba can only strip the parts that interface with Python machinery.

    Your "binary search" algorithm does much more work and makes much heavier use of NumPy's vector operations while at it, so less of it can be accelerated this way.

提交回复
热议问题