While Loop Strange And Unstable Behavior In A Jitted Function
I found that when the index of a
numpy array will go out of bound inside a while-loop in a
njit decorated function, the way the function handles the while loop can quite weird, and I am not sure why it happens.
from numba import njit import numpy as np def func1(v): i= 0 K= v[-1]+1 while v[i] < K: i+=1 return i @njit def func2(v): i= 0 K= v[-1]+1 while v[i] < K: i+=1 return i x= np.arange(2) result2 = func2(x) result1 = func1(x)
Here is a short summary of the results:
func2 won't raise
func2 returns different results(like sometimes it is
12, etc, basically unstable output) every time we run the file in the console (I am using
I am not sure why and how this happens(could be due to
ipython issues or it could be that my cpu is broken beyond repair) which is why I am asking for help here.
Note: I am using:
Anaconda's distribution of python, python version
OS windows 10 64-bit
Numba does not do bounds checking on Numpy arrays for performance reasons. There is currently work to turn it on optionally (https://github.com/numba/numba/pull/4432). When you go outside of the bounds of the array you will get whatever is in memory at the location or possibly seg fault.
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module